1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//============================================================================
17
18#include <cstdlib>
19
20#include "FSNode.hxx"
21#include "Version.hxx"
22#include "OSystemUNIX.hxx"
23
24// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25void OSystemUNIX::getBaseDirAndConfig(string& basedir, string& cfgfile,
26 string& savedir, string& loaddir,
27 bool useappdir, const string& usedir)
28{
29 // Use XDG_CONFIG_HOME if defined, otherwise use the default
30 const char* configDir = getenv("XDG_CONFIG_HOME");
31 if(configDir == nullptr) configDir = "~/.config";
32 basedir = string(configDir) + "/stella";
33 savedir = loaddir = "~/";
34
35 // Check to see if basedir overrides are active
36 if(useappdir)
37 cout << "ERROR: base dir in app folder not supported" << endl;
38 else if(usedir != "")
39 {
40 basedir = FilesystemNode(usedir).getPath();
41 savedir = loaddir = basedir;
42 }
43
44 // (Currently) non-documented alternative for using version-specific
45 // config file
46 ostringstream buf;
47 buf << basedir << "/stellarc" << "-" << STELLA_VERSION;
48
49 // Use version-specific config file only if it already exists
50 FilesystemNode altConfigFile(buf.str());
51 if(altConfigFile.exists() && altConfigFile.isWritable())
52 cfgfile = altConfigFile.getPath();
53 else
54 cfgfile = basedir + "/stellarc";
55}
56