mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2024-11-22 13:55:38 +00:00
Changed pathType from string var to enum
This commit is contained in:
parent
df7787f040
commit
d11efb8553
|
@ -32,8 +32,9 @@
|
|||
|
||||
namespace FileSystemPath
|
||||
{
|
||||
enum fsPathType { Analysis, Config, Log, NVRAM, Saves, Screenshots }; // Filesystem path types
|
||||
bool PathExists(std::string fileSystemPath); // Checks if a directory exists (returns true if exists, false if it doesn't)
|
||||
std::string GetPath(std::string pathType); // Generates a path to be used by Supermodel files
|
||||
std::string GetPath(fsPathType pathType); // Generates a path to be used by Supermodel files
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -476,7 +476,7 @@ void Screenshot()
|
|||
time_t now = std::time(nullptr);
|
||||
tm* ltm = std::localtime(&now);
|
||||
|
||||
sprintf(file, "%sScreenshot %.4d-%.2d-%.2d (%.2d-%.2d-%.2d).bmp", FileSystemPath::GetPath("Screenshots").c_str(), 1900 + ltm->tm_year, 1 + ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
|
||||
sprintf(file, "%sScreenshot %.4d-%.2d-%.2d (%.2d-%.2d-%.2d).bmp", FileSystemPath::GetPath(FileSystemPath::Screenshots).c_str(), 1900 + ltm->tm_year, 1 + ltm->tm_mon, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
|
||||
|
||||
info += file;
|
||||
puts(info.c_str());
|
||||
|
@ -616,7 +616,7 @@ static void SaveState(IEmulator *Model3)
|
|||
{
|
||||
CBlockFile SaveState;
|
||||
|
||||
std::string file_path = Util::Format() << FileSystemPath::GetPath("Saves") << Model3->GetGame().name << ".st" << s_saveSlot;
|
||||
std::string file_path = Util::Format() << FileSystemPath::GetPath(FileSystemPath::Saves) << Model3->GetGame().name << ".st" << s_saveSlot;
|
||||
if (OKAY != SaveState.Create(file_path, "Supermodel Save State", "Supermodel Version " SUPERMODEL_VERSION))
|
||||
{
|
||||
ErrorLog("Unable to save state to '%s'.", file_path.c_str());
|
||||
|
@ -641,7 +641,7 @@ static void LoadState(IEmulator *Model3, std::string file_path = std::string())
|
|||
|
||||
// Generate file path
|
||||
if (file_path.empty())
|
||||
file_path = Util::Format() << FileSystemPath::GetPath("Saves") << Model3->GetGame().name << ".st" << s_saveSlot;
|
||||
file_path = Util::Format() << FileSystemPath::GetPath(FileSystemPath::Saves) << Model3->GetGame().name << ".st" << s_saveSlot;
|
||||
|
||||
// Open and check to make sure format is correct
|
||||
if (OKAY != SaveState.Load(file_path))
|
||||
|
@ -675,7 +675,7 @@ static void SaveNVRAM(IEmulator *Model3)
|
|||
{
|
||||
CBlockFile NVRAM;
|
||||
|
||||
std::string file_path = Util::Format() << FileSystemPath::GetPath("NVRAM") << Model3->GetGame().name << ".nv";
|
||||
std::string file_path = Util::Format() << FileSystemPath::GetPath(FileSystemPath::NVRAM) << Model3->GetGame().name << ".nv";
|
||||
if (OKAY != NVRAM.Create(file_path, "Supermodel NVRAM State", "Supermodel Version " SUPERMODEL_VERSION))
|
||||
{
|
||||
ErrorLog("Unable to save NVRAM to '%s'. Make sure directory exists!", file_path.c_str());
|
||||
|
@ -698,7 +698,7 @@ static void LoadNVRAM(IEmulator *Model3)
|
|||
CBlockFile NVRAM;
|
||||
|
||||
// Generate file path
|
||||
std::string file_path = Util::Format() << FileSystemPath::GetPath("NVRAM") << Model3->GetGame().name << ".nv";
|
||||
std::string file_path = Util::Format() << FileSystemPath::GetPath(FileSystemPath::NVRAM) << Model3->GetGame().name << ".nv";
|
||||
|
||||
// Open and check to make sure format is correct
|
||||
if (OKAY != NVRAM.Load(file_path))
|
||||
|
@ -1449,10 +1449,10 @@ QuitError:
|
|||
Entry Point and Command Line Procesing
|
||||
******************************************************************************/
|
||||
|
||||
static const std::string s_analysisPath = Util::Format() << FileSystemPath::GetPath("Analysis");
|
||||
static const std::string s_configFilePath = Util::Format() << FileSystemPath::GetPath("Config") << "Supermodel.ini";
|
||||
static const std::string s_gameXMLFilePath = Util::Format() << FileSystemPath::GetPath("Config") << "Games.xml";
|
||||
static const std::string s_logFilePath = Util::Format() << FileSystemPath::GetPath("Log") << "Supermodel.log";
|
||||
static const std::string s_analysisPath = Util::Format() << FileSystemPath::GetPath(FileSystemPath::Analysis);
|
||||
static const std::string s_configFilePath = Util::Format() << FileSystemPath::GetPath(FileSystemPath::Config) << "Supermodel.ini";
|
||||
static const std::string s_gameXMLFilePath = Util::Format() << FileSystemPath::GetPath(FileSystemPath::Config) << "Games.xml";
|
||||
static const std::string s_logFilePath = Util::Format() << FileSystemPath::GetPath(FileSystemPath::Log) << "Supermodel.log";
|
||||
|
||||
// Create and configure inputs
|
||||
static bool ConfigureInputs(CInputs *Inputs, Util::Config::Node *fileConfig, Util::Config::Node *runtimeConfig, const Game &game, bool configure)
|
||||
|
|
|
@ -45,12 +45,36 @@ namespace FileSystemPath
|
|||
}
|
||||
|
||||
// Generates a path to be used by Supermodel files
|
||||
std::string GetPath(std::string pathType)
|
||||
std::string GetPath(fsPathType pathType)
|
||||
{
|
||||
std::string finalPath = "";
|
||||
std::string homePath = "";
|
||||
std::string strPathType = "";
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
|
||||
// Resolve pathType to string for later use
|
||||
switch (pathType)
|
||||
{
|
||||
case Analysis:
|
||||
strPathType = "Analysis";
|
||||
break;
|
||||
case Config:
|
||||
strPathType = "Config";
|
||||
break;
|
||||
case Log:
|
||||
strPathType = "Log";
|
||||
break;
|
||||
case NVRAM:
|
||||
strPathType = "NVRAM";
|
||||
break;
|
||||
case Saves:
|
||||
strPathType = "Saves";
|
||||
break;
|
||||
case Screenshots:
|
||||
strPathType = "Screenshots";
|
||||
break;
|
||||
}
|
||||
|
||||
// Get user's HOME directory
|
||||
if (pwd)
|
||||
{
|
||||
|
@ -65,15 +89,15 @@ namespace FileSystemPath
|
|||
if (FileSystemPath::PathExists("Config") || homePath.empty())
|
||||
{
|
||||
// Use current directory
|
||||
if (pathType == "Screenshots" || pathType == "Log")
|
||||
if (pathType == Screenshots || pathType == Log)
|
||||
{
|
||||
finalPath = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// If directory doesn't exist, create it
|
||||
if (!FileSystemPath::PathExists(pathType)) mkdir(pathType.c_str(), 0775);
|
||||
finalPath = pathType;
|
||||
if (!FileSystemPath::PathExists(strPathType)) mkdir(strPathType.c_str(), 0775);
|
||||
finalPath = strPathType;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -81,7 +105,7 @@ namespace FileSystemPath
|
|||
else if (FileSystemPath::PathExists(Util::Format() << homePath << "/.supermodel"))
|
||||
{
|
||||
// Use $HOME/.supermodel
|
||||
finalPath = Util::Format() << homePath << "/.supermodel/" << pathType;
|
||||
finalPath = Util::Format() << homePath << "/.supermodel/" << strPathType;
|
||||
// If directory doesn't exist, create it
|
||||
if (!FileSystemPath::PathExists(finalPath))
|
||||
{
|
||||
|
@ -92,7 +116,7 @@ namespace FileSystemPath
|
|||
else
|
||||
{
|
||||
// Use $HOME/.config/supermodel or $HOME/.local/share/supermodel depending on the file type
|
||||
if (pathType == "Config")
|
||||
if (pathType == Config)
|
||||
{
|
||||
finalPath = Util::Format() << homePath << "/.config/supermodel";
|
||||
// If directory doesn't exist, create it
|
||||
|
@ -108,7 +132,7 @@ namespace FileSystemPath
|
|||
// If directory doesn't exist, create it
|
||||
if (!FileSystemPath::PathExists(finalPath)) mkdir(finalPath.c_str(), 0775);
|
||||
// If directory doesn't exist, create it
|
||||
finalPath = Util::Format() << homePath << "/.local/share/supermodel/" << pathType;
|
||||
finalPath = Util::Format() << homePath << "/.local/share/supermodel/" << strPathType;
|
||||
if (!FileSystemPath::PathExists(finalPath)) mkdir(finalPath.c_str(), 0775);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,13 +25,22 @@
|
|||
namespace FileSystemPath
|
||||
{
|
||||
// Generates a path to be used by Supermodel files
|
||||
std::string GetPath(std::string pathType)
|
||||
std::string GetPath(fsPathType pathType)
|
||||
{
|
||||
if (pathType == "Config") return "Config/";
|
||||
if (pathType == "Screenshots") return "";
|
||||
if (pathType == "Saves") return "Saves/";
|
||||
if (pathType == "NVRAM") return "NVRAM/";
|
||||
if (pathType == "Log") return "";
|
||||
if (pathType == "Analysis") return "Analysis/";
|
||||
switch (pathType)
|
||||
{
|
||||
case Analysis:
|
||||
return "Analysis/";
|
||||
case Config:
|
||||
return "Config/";
|
||||
case Log:
|
||||
return "";
|
||||
case NVRAM:
|
||||
return "NVRAM/";
|
||||
case Saves:
|
||||
return "Saves/";
|
||||
case Screenshots:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue