Skip to content

Commit

Permalink
Allow loading more custom configs via search prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dest1yo committed Jan 9, 2024
1 parent a4a15af commit 83e998a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 39 deletions.
10 changes: 5 additions & 5 deletions src/Parasyte.CLI/Parasyte.CLI.rc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,4,0,0
PRODUCTVERSION 2,4,0,0
FILEVERSION 2,4,0,1
PRODUCTVERSION 2,4,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Scob Crew"
VALUE "FileDescription", "Cordycep - Call of Duty Fast File Loader"
VALUE "FileVersion", "2.4.0.0"
VALUE "FileVersion", "2.4.0.1"
VALUE "InternalName", "Cordycep.CLI"
VALUE "LegalCopyright", "Copyright (C) Scobalula 2023"
VALUE "LegalCopyright", "Copyright (C) Scobalula & dest1yo 2024"
VALUE "OriginalFilename", "Cordycep.CLI"
VALUE "ProductName", "Cordycep - Call of Duty Fast File Loader"
VALUE "ProductVersion", "2.4.0.0"
VALUE "ProductVersion", "2.4.0.1"
END
END
BLOCK "VarFileInfo"
Expand Down
6 changes: 5 additions & 1 deletion src/Parasyte/CoDIWHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ bool ps::CoDIWHandler::Initialize(const std::string& gameDirectory)
Configs.clear();
GameDirectory = gameDirectory;

LoadConfigs("CoDIWHandler.toml");
if (!LoadConfigs("CoDIWHandler"))
{
return false;
}

SetConfig();
CopyDependencies();
OpenGameDirectory(GameDirectory);
Expand Down
7 changes: 5 additions & 2 deletions src/Parasyte/CoDMW4Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ bool ps::CoDMW4Handler::Initialize(const std::string& gameDirectory)
Configs.clear();
GameDirectory = gameDirectory;

// LoadConfigs("Data\\Configs\\CoDMW4Handler.json");
LoadConfigs("CoDMW4Handler.toml");
if (!LoadConfigs("CoDMW4Handler"))
{
return false;
}

SetConfig();
CopyDependencies();
OpenGameDirectory(GameDirectory);
Expand Down
8 changes: 5 additions & 3 deletions src/Parasyte/CoDMW5Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,11 @@ bool ps::CoDMW5Handler::Initialize(const std::string& gameDirectory)
Configs.clear();
GameDirectory = gameDirectory;

// LoadConfigs("Data\\Configs\\CoDMW5Handler.json");
LoadConfigs("CoDMW5Handler.toml");
LoadConfigs("CoDMW5HandlerSP.toml");
if (!LoadConfigs("CoDMW5Handler"))
{
return false;
}

SetConfig();
CopyDependencies();
OpenGameDirectory(GameDirectory);
Expand Down
8 changes: 5 additions & 3 deletions src/Parasyte/CoDMW6Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,11 @@ bool ps::CoDMW6Handler::Initialize(const std::string& gameDirectory)
Configs.clear();
GameDirectory = gameDirectory;

// LoadConfigs("Data\\Configs\\CoDMW6Handler.json");
LoadConfigs("CoDMW6Handler.toml");
LoadConfigs("CoDMW6HandlerSP.toml");
if (!LoadConfigs("CoDMW6Handler"))
{
return false;
}

SetConfig();
CopyDependencies();
OpenGameDirectory(GameDirectory);
Expand Down
7 changes: 5 additions & 2 deletions src/Parasyte/CoDVGHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ bool ps::CoDVGHandler::Initialize(const std::string& gameDirectory)
Configs.clear();
GameDirectory = gameDirectory;

// LoadConfigs("Data\\Configs\\CoDVGHandler.json");
LoadConfigs("CoDVGHandler.toml");
if (!LoadConfigs("CoDVGHandler"))
{
return false;
}

SetConfig();
CopyDependencies();
OpenGameDirectory(GameDirectory);
Expand Down
53 changes: 31 additions & 22 deletions src/Parasyte/GameHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,34 +355,43 @@ std::string ps::GameHandler::GetFileName(const std::string& name)
return name;
}

bool ps::GameHandler::LoadConfigs(const std::string& fileName)
bool ps::GameHandler::LoadConfigs(const std::string& prefix)
{
const auto configPath = std::filesystem::path("Data/Configs/" + fileName);
auto ext = configPath.extension().string();

// Failed to find the file or it has no extension
if (!exists(configPath) || ext.empty())
const std::string relativePath = "Data/Configs/";
const std::string extension = ".toml";
const auto configFolder = std::filesystem::current_path() / relativePath;
auto _prefix = prefix;
std::ranges::transform(_prefix, _prefix.begin(), tolower);
bool canFoundConfig = false;

for (const auto& entry : std::filesystem::directory_iterator(configFolder))
{
// TODO: Log
return false;
}
auto entry_filename = entry.path().filename().string();
auto entry_ext = entry.path().extension().string();

// Clear the configs of handler
// Configs.clear();
// Transform to lower
std::ranges::transform(entry_filename, entry_filename.begin(), tolower);
std::ranges::transform(entry_ext, entry_ext.begin(), tolower);

// Check if the extension is supported
std::ranges::transform(ext, ext.begin(), tolower);
if (ext == ".toml")
{
GameConfig::LoadConfigsToml(configPath.string(), Configs);
}
else if (ext == ".json")
{
GameConfig::LoadConfigsJson(configPath.string(), Configs);
// Load the config file if we found
if (entry.is_regular_file() &&
entry_filename.find(_prefix) == 0 &&
entry_ext == extension)
{
GameConfig::LoadConfigsToml(entry.path().string(), Configs);
ps::log::Log(ps::LogType::Normal, "Loaded config: %s", entry.path().filename().string().c_str());
// ps::log::Print("MAIN", "Loaded config: %s", entry.path().filename().string().c_str());

if (!canFoundConfig)
canFoundConfig = true;
}
}
else

// Failed to find any config;
if (!canFoundConfig)
{
// TODO: Log if the file is unsupported
ps::log::Print("ERROR", "Failed to find any current game handler config in \"Data/Configs\".");

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parasyte/GameHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace ps
// Gets a file path for the provided fast file name with the current flags and directory.
virtual std::string GetFileName(const std::string& name);
// Loads a game configs file.
virtual bool LoadConfigs(const std::string& fileName);
virtual bool LoadConfigs(const std::string& prefix);
// Calculates the config if the required flag is set. If no flag is set, the first config is used.
virtual bool SetConfig();
// Resolves patterns within the game module.
Expand Down

0 comments on commit 83e998a

Please sign in to comment.