Skip to content

Commit

Permalink
aegea: Expose FileSystem cache so prefix can be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceManiac committed Dec 28, 2024
1 parent adff112 commit 21af527
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
12 changes: 12 additions & 0 deletions source/aegea/include/aegea.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ class ArchipelagoCache
virtual std::string read(std::string_view key) = 0;
// Write contents to a cache key.
virtual void write(std::string_view key, std::string_view data) = 0;

class FileSystem;
};

class ArchipelagoCache::FileSystem : public ArchipelagoCache
{
std::string_view prefix;
public:
explicit FileSystem(std::string_view prefix) : prefix(prefix) {}

std::string read(std::string_view key);
void write(std::string_view key, std::string_view data);
};

class ArchipelagoClient
Expand Down
26 changes: 9 additions & 17 deletions source/aegea/src/aegea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace
{
const jt::Json json_null;

ArchipelagoCache::FileSystem default_cache { "archipelago/" };

namespace IncomingCmd
{
constexpr std::string_view RoomInfo = "RoomInfo";
Expand Down Expand Up @@ -70,21 +72,10 @@ namespace

// ------------------------------------------------------------------------

namespace
{
class DefaultArchipelagoCache : public ArchipelagoCache
{
public:
std::string read(std::string_view key);
void write(std::string_view key, std::string_view data);
};

DefaultArchipelagoCache default_cache;
}

std::string DefaultArchipelagoCache::read(std::string_view key)
std::string ArchipelagoCache::FileSystem::read(std::string_view key)
{
std::string filename = "archipelago/";
std::string filename { prefix };
filename.append("/");
filename.append(key);
filename.append(".cache");

Expand All @@ -101,12 +92,13 @@ std::string DefaultArchipelagoCache::read(std::string_view key)
return buffer;
}

void DefaultArchipelagoCache::write(std::string_view key, std::string_view data)
void ArchipelagoCache::FileSystem::write(std::string_view key, std::string_view data)
{
std::error_code ec;
std::filesystem::create_directories("archipelago/", ec);
std::filesystem::create_directories(prefix, ec);

std::string filename = "archipelago/";
std::string filename { prefix };
filename.append("/");
filename.append(key);
filename.append(".cache");

Expand Down
5 changes: 4 additions & 1 deletion source/loonyland/loonyArchipelago.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,14 @@ std::unordered_map<int, chatData> chat_table = {
};


int ArchipelagoConnect(std::string IPAddress, std::string SlotName, std::string Password) {
int ArchipelagoConnect(std::string IPAddress, std::string SlotName, std::string Password)
{
static ArchipelagoCache::FileSystem cache { "appdata/archipelago/" };
for (int i = 0; i < 40; i++) {
opt.meritBadge[i] = MERIT_NO;
}
ap = std::make_unique<ArchipelagoClient>("Loonyland", IPAddress, SlotName, Password);
ap->use_cache(&cache);
//AP_SetLocationCheckedCallback(SetLocationChecked);
ap->death_link_enable();

Expand Down
2 changes: 2 additions & 0 deletions source/mystic/archipelago.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ ArchipelagoMenu(MGLDraw* mgl)
}
else if (cursor == 4)
{
static ArchipelagoCache::FileSystem cache { "appdata/archipelago/" };
ap = std::make_unique<ArchipelagoClient>("Kid Mystic", serverAddress, slotName, password);
ap->use_cache(&cache);
}
else if (cursor == 5 || cursor == 6 || cursor == 7 || cursor == 8)
{
Expand Down

0 comments on commit 21af527

Please sign in to comment.