Permalink
Browse files

Add a "Portable" config mode

Having a file called 'portable.txt' in the working directory when
running an executable now causes the config file path to default to
${PROGRAM_NAME}_settings.conf instead of a system-wide location.

Adding a portable.txt in the root of the source repository means that
programs invoked by the build should use that 'portable' mode, instead
of messing around with the user config.
  • Loading branch information...
JonnyH committed Sep 8, 2017
1 parent 9598997 commit 18067a2a8a431be646e5a09042f0b338e74d9b0a
Showing with 27 additions and 1 deletion.
  1. +15 −1 framework/configfile.cpp
  2. +12 −0 portable.txt
View
@@ -82,7 +82,21 @@ class ConfigFileImpl
{
PHYSFS_init(programName.cStr());
}
UString settingsPath(PHYSFS_getPrefDir("OpenApoc", programName.cStr()));
UString settingsPath;
// If a file called 'portable.txt' exists in $(PWD), use a local config folder instead of a
// system one.
// This can't go through the normal settings system, as it's used by the normal settings
// system...
std::ifstream portableFile("./portable.txt");
if (portableFile)
{
LogInfo("portable mode set");
settingsPath = programName + "_";
}
else
{
settingsPath = PHYSFS_getPrefDir("OpenApoc", programName.cStr());
}
settingsPath += "settings.conf";
// Setup some config-related options
this->addOption("", "help", "h", "Show help text and exit");
View
@@ -0,0 +1,12 @@
A file called "portable.txt" in the working directory when running any
executable causes the settings path to default to the current working
directory, instead of a system-wide location.
This file can have any contents, or be completely empty. It simple must be
successfully opened.
The config files are then stored in ./${PROGRAM_NAME}_settings.conf - e.g.
"OpenApoc_settings.conf".
This file ensures that files ran as part of the build, or tests invoked from
the buildsystem, default to the portable mode.

0 comments on commit 18067a2

Please sign in to comment.