Skip to content

Commit ad54ecb

Browse files
committed
Merge branch 'configdir'
This PR moves the configuration directory from ~/.emulationstation to the standard config locations (see README). A custom location can be set with the new --config-dir command line option. Based on the original patches by Herdinger, but heavily edited on some places.
2 parents 3596cf1 + a14eaba commit ad54ecb

File tree

12 files changed

+86
-27
lines changed

12 files changed

+86
-27
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ if(DEFINED BCMHOST)
6060
add_definitions(-D_RPI_)
6161
endif()
6262

63+
option(XDG_ON_OSX "Try to store settings in XDG_CONFIG_HOME on OSX" OFF)
64+
if(XDG_ON_OSX)
65+
add_definitions(-DUSE_XDG_OSX)
66+
endif()
67+
6368
#-------------------------------------------------------------------------------
6469

6570
# Require C++11

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cmake .
2929
make
3030
```
3131

32-
- If your problem still isn't gone, the best way to report a bug is to post an issue on GitHub. Try to post the simplest steps possible to reproduce the bug. Include files you think might be related (except for ROMs, of course). If you haven't re-run ES since the crash, the log file `~/.emulationstation/es_log.txt` is also helpful.
32+
- If your problem still isn't gone, the best way to report a bug is to post an issue on GitHub. Try to post the simplest steps possible to reproduce the bug. Include files you think might be related (except for ROMs, of course). If you haven't re-run ES since the crash, the log file `$CONFIG_DIR/es_log.txt` is also helpful.
3333

3434
Building
3535
========
@@ -79,12 +79,21 @@ Complete Raspberry Pi build instructions at [emulationstation.org](http://emulat
7979
Configuring
8080
===========
8181

82-
**~/.emulationstation/es_systems.cfg:**
83-
When first run, an example systems configuration file will be created at `~/.emulationstation/es_systems.cfg`. `~` is `$HOME` on Linux, and `%HOMEPATH%` on Windows. This example has some comments explaining how to write the configuration file. See the "Writing an es_systems.cfg" section for more information.
82+
Configuration files are stored in `$CONFIG_DIR`, which is by default
83+
84+
- on Windows: `My Documents/EmulationStation/`
85+
- on Linux: `$XDG_CONFIG_HOME/emulationstation/` which usually defaults to `~/.config/emulationstation/`
86+
- on OSX: `~/Library/Application Support/org.emulationstation.EmulationStation/` by default, or the same as Linux if EmulationStation is build with the `XDG_ON_OSX` CMake flag.
87+
88+
Alternatively you can specify `$CONFIG_DIR` through the `--config-dir [path]` command line option.
89+
90+
**es_systems.cfg:**
91+
92+
When first run, an example systems configuration file will be created at `$CONFIG_DIR/es_systems.cfg`. This example has some comments explaining how to write the configuration file. See the "Writing an es_systems.cfg" section for more information.
8493

8594
**Keep in mind you'll have to set up your emulator separately from EmulationStation!**
8695

87-
**~/.emulationstation/es_input.cfg:**
96+
**es_input.cfg:**
8897
When you first start EmulationStation, you will be prompted to configure an input device. The process is thus:
8998

9099
1. Hold a button on the device you want to configure. This includes the keyboard.
@@ -95,11 +104,11 @@ When you first start EmulationStation, you will be prompted to configure an inpu
95104

96105
4. Choose "SAVE" to save this device and close the input configuration screen.
97106

98-
The new configuration will be added to the `~/.emulationstation/es_input.cfg` file.
107+
The new configuration will be added to the `es_input.cfg` file.
99108

100109
**Both new and old devices can be (re)configured at any time by pressing the Start button and choosing "CONFIGURE INPUT".** From here, you may unplug the device you used to open the menu and plug in a new one, if necessary. New devices will be appended to the existing input configuration file, so your old devices will remain configured.
101110

102-
**If your controller stops working, you can delete the `~/.emulationstation/es_input.cfg` file to make the input configuration screen re-appear on next run.**
111+
**If your controller stops working, you can delete the `es_input.cfg` file to make the input configuration screen re-appear on next run.**
103112

104113

105114
You can use `--help` or `-h` to view a list of command-line options. Briefly outlined here:
@@ -126,7 +135,7 @@ Complete configuration instructions at [emulationstation.org](http://emulationst
126135
The `es_systems.cfg` file contains the system configuration data for EmulationStation, written in XML. This tells EmulationStation what systems you have, what platform they correspond to (for scraping), and where the games are located.
127136

128137
ES will check two places for an es_systems.cfg file, in the following order, stopping after it finds one that works:
129-
* `~/.emulationstation/es_systems.cfg`
138+
* `$CONFIG_DIR/es_systems.cfg`
130139
* `/etc/emulationstation/es_systems.cfg`
131140

132141
The order EmulationStation displays systems reflects the order you define them in.

es-app/src/SystemManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SystemManager* SystemManager::getInstance()
2121

2222
std::string SystemManager::getDatabasePath()
2323
{
24-
return getHomePath() + "/.emulationstation/gamelist.db";
24+
return getConfigDirectory() + "/gamelist.db";
2525
}
2626

2727
SystemManager::SystemManager() : mDatabase(getDatabasePath())
@@ -199,7 +199,7 @@ void SystemManager::writeExampleConfig(const fs::path& path)
199199

200200
fs::path SystemManager::getConfigPath(bool forWrite)
201201
{
202-
fs::path path = getHomePath() + "/.emulationstation/es_systems.cfg";
202+
fs::path path = getConfigDirectory() + "/es_systems.cfg";
203203
if(forWrite || fs::exists(path))
204204
return path.generic_string();
205205

@@ -268,7 +268,7 @@ fs::path SystemManager::getGamelistXMLPath(const SystemData* sys, bool forWrite)
268268
if(fs::exists(filePath))
269269
return filePath;
270270

271-
filePath = getHomePath() + "/.emulationstation/gamelists/" + sys->getName() + "/gamelist.xml";
271+
filePath = getConfigDirectory() + "/gamelists/" + sys->getName() + "/gamelist.xml";
272272
if(forWrite) // make sure the directory exists if we're going to write to it, or crashes will happen
273273
fs::create_directories(filePath.parent_path());
274274
if(forWrite || fs::exists(filePath))

es-app/src/main.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
5454
}else if(strcmp(argv[i], "--no-exit") == 0)
5555
{
5656
Settings::getInstance()->setBool("ShowExit", false);
57+
}else if(strcmp(argv[i], "--config-dir") == 0)
58+
{
59+
if(i >= argc - 1)
60+
{
61+
std::cerr << "No config directory supplied.";
62+
return false;
63+
}
64+
65+
i++;
66+
auto configDir = std::string(argv[i]);
67+
Settings::getInstance()->setString("ConfigDirectory", configDir);
5768
}else if(strcmp(argv[i], "--debug") == 0)
5869
{
5970
Settings::getInstance()->setBool("Debug", true);
@@ -87,6 +98,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
8798
"--ignore-gamelist ignore the gamelist (useful for troubleshooting)\n"
8899
"--draw-framerate display the framerate\n"
89100
"--no-exit don't show the exit option in the menu\n"
101+
"--config-dir [path] use path as config directory\n"
90102
"--debug more logging, show console on Windows\n"
91103
"--scrape scrape using command line interface\n"
92104
"--windowed not fullscreen, should be used with --resolution\n"
@@ -103,12 +115,11 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
103115
bool verifyHomeFolderExists()
104116
{
105117
// make sure the config directory exists
106-
std::string home = getHomePath();
107-
std::string configDir = home + "/.emulationstation";
118+
std::string configDir = getConfigDirectory();
108119
if(!fs::exists(configDir))
109120
{
110121
std::cout << "Creating config directory \"" << configDir << "\"\n";
111-
fs::create_directory(configDir);
122+
fs::create_directories(configDir);
112123
if(!fs::exists(configDir))
113124
{
114125
std::cerr << "Config directory could not be created!\n";
@@ -203,7 +214,7 @@ int main(int argc, char* argv[])
203214
}
204215
#endif
205216

206-
// if ~/.emulationstation doesn't exist and cannot be created, bail
217+
// if the config dir doesn't exist and cannot be created, bail
207218
if(!verifyHomeFolderExists())
208219
return 1;
209220

@@ -233,6 +244,9 @@ int main(int argc, char* argv[])
233244

234245
window.renderLoadingScreen();
235246

247+
// try to load the settings file, or use defaults
248+
Settings::getInstance()->loadFile();
249+
236250
const char* errorMsg = NULL;
237251
if(!loadSystemConfigFile(&errorMsg))
238252
{

es-app/src/scrapers/GamesDBShaScraper.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ std::map<std::string, std::string> hash_to_name;
1919

2020
boost::filesystem::path get_hash_path()
2121
{
22-
std::string home = getHomePath();
23-
boost::filesystem::path hash_path = home + "/.emulationstation/rom_hashes";
22+
boost::filesystem::path hash_path = getConfigDirectory() + "/rom_hashes";
2423
boost::filesystem::create_directories(hash_path);
2524
hash_path = hash_path / "hash.tsv";
2625
return hash_path;

es-app/src/scrapers/Scraper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ std::string getSaveAsPath(const ScraperSearchParams& params, const std::string&
274274
const std::string subdirectory = params.system->getName();
275275
const std::string name = params.game.getPath().stem().generic_string() + "-" + suffix;
276276

277-
std::string path = getHomePath() + "/.emulationstation/downloaded_images/";
277+
std::string path = getConfigDirectory() + "/downloaded_images/";
278278

279279
if(!boost::filesystem::exists(path))
280280
boost::filesystem::create_directory(path);

es-core/src/InputManager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ void InputManager::writeDeviceConfig(InputConfig* config)
331331

332332
std::string InputManager::getConfigPath()
333333
{
334-
std::string path = getHomePath();
335-
path += "/.emulationstation/es_input.cfg";
336-
return path;
334+
return getConfigDirectory() + "/es_input.cfg";
337335
}
338336

339337
bool InputManager::initialized() const

es-core/src/Log.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ LogLevel Log::getReportingLevel()
1414

1515
std::string Log::getLogPath()
1616
{
17-
std::string home = getHomePath();
18-
return home + "/.emulationstation/es_log.txt";
17+
return getConfigDirectory() + "/es_log.txt";
1918
}
2019

2120
void Log::setReportingLevel(LogLevel level)

es-core/src/Settings.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ std::vector<const char*> settings_dont_save = boost::assign::list_of
1919
("Windowed")
2020
("VSync")
2121
("HideConsole")
22+
("ConfigDirectory")
2223
("IgnoreGamelist");
2324

2425
Settings::Settings()
2526
{
2627
setDefaults();
27-
loadFile();
2828
}
2929

3030
Settings* Settings::getInstance()
@@ -74,6 +74,7 @@ void Settings::setDefaults()
7474
mStringMap["ThemeSet"] = "";
7575
mStringMap["ScreenSaverBehavior"] = "dim";
7676
mStringMap["Scraper"] = "TheGamesDB";
77+
mStringMap["ConfigDirectory"] = "";
7778

7879
mTimeMap["LastXMLImportTime"] = (std::time_t)0;
7980
}
@@ -110,7 +111,7 @@ void saveMap(pugi::xml_document& doc, std::map<std::string, std::time_t>& map, c
110111

111112
void Settings::saveFile()
112113
{
113-
const std::string path = getHomePath() + "/.emulationstation/es_settings.cfg";
114+
const std::string path = getConfigDirectory() + "/es_settings.cfg";
114115

115116
pugi::xml_document doc;
116117

@@ -132,7 +133,7 @@ void Settings::saveFile()
132133

133134
void Settings::loadFile()
134135
{
135-
const std::string path = getHomePath() + "/.emulationstation/es_settings.cfg";
136+
const std::string path = getConfigDirectory() + "/es_settings.cfg";
136137

137138
if(!boost::filesystem::exists(path))
138139
return;

es-core/src/ThemeData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ const std::shared_ptr<ThemeData>& ThemeData::getDefault()
362362
{
363363
theme = std::shared_ptr<ThemeData>(new ThemeData());
364364

365-
const std::string path = getHomePath() + "/.emulationstation/es_theme_default.xml";
365+
const std::string path = getConfigDirectory() + "/es_theme_default.xml";
366366
if(fs::exists(path))
367367
{
368368
try
@@ -432,7 +432,7 @@ std::map<std::string, ThemeSet> ThemeData::getThemeSets()
432432
static const size_t pathCount = 2;
433433
fs::path paths[pathCount] = {
434434
"/etc/emulationstation/themes",
435-
getHomePath() + "/.emulationstation/themes"
435+
getConfigDirectory() + "/themes"
436436
};
437437

438438
fs::directory_iterator end;

0 commit comments

Comments
 (0)