2009-09-07 19:23:46 +00:00
|
|
|
#include "AppConfig.h"
|
|
|
|
#include "PathUtils.h"
|
2023-08-28 16:55:00 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <filesystem> // For file system operations
|
2009-09-07 19:23:46 +00:00
|
|
|
|
2019-10-17 12:04:25 -04:00
|
|
|
#define CONFIG_FILENAME ("config.xml")
|
2023-08-28 16:55:00 +02:00
|
|
|
#define PORTABLE_BASE_DATA_PATH ("Play Data Files")
|
|
|
|
#define BASE_DATA_PATH ("Play Data Files")
|
2009-09-07 19:23:46 +00:00
|
|
|
|
2012-08-23 01:49:03 +00:00
|
|
|
CAppConfig::CAppConfig()
|
2018-04-30 21:01:23 +01:00
|
|
|
: CConfig(BuildConfigPath())
|
2009-09-07 19:23:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:49:03 +00:00
|
|
|
Framework::CConfig::PathType CAppConfig::GetBasePath()
|
2009-09-07 19:23:46 +00:00
|
|
|
{
|
2023-08-28 16:55:00 +02:00
|
|
|
// Check for the presence of the "portable.txt" file
|
|
|
|
if(std::filesystem::exists("portable.txt"))
|
|
|
|
{
|
|
|
|
//delete "read content portable.txt"
|
|
|
|
|
|
|
|
// If "portable.txt" is present, simply use the path specified in PORTABLE_BASE_DATA_PATH
|
|
|
|
auto basePath = PORTABLE_BASE_DATA_PATH;
|
|
|
|
|
|
|
|
// Create the "Play Data Files" directory if it doesn't already exist
|
|
|
|
std::filesystem::create_directories(basePath);
|
|
|
|
|
|
|
|
return basePath; // Return the base path without the complete path
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If "portable.txt" is absent, use the original code for the base directory path
|
|
|
|
auto result = Framework::PathUtils::GetPersonalDataPath() / BASE_DATA_PATH;
|
|
|
|
|
|
|
|
// Create the "Play Data Files" directory if it doesn't already exist
|
|
|
|
Framework::PathUtils::EnsurePathExists(result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2009-09-07 19:23:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 01:49:03 +00:00
|
|
|
Framework::CConfig::PathType CAppConfig::BuildConfigPath()
|
2009-09-07 19:23:46 +00:00
|
|
|
{
|
2023-08-28 16:55:00 +02:00
|
|
|
auto basePath(GetBasePath());
|
|
|
|
// "config.xml" is located in the directory of the base path
|
|
|
|
return basePath / CONFIG_FILENAME;
|
2009-09-07 19:23:46 +00:00
|
|
|
}
|