Skip to content

Commit

Permalink
If cfg.ini doesn't exist, save a default config file on startup so us…
Browse files Browse the repository at this point in the history
…ers have a chance to edit it even if we crash.
  • Loading branch information
dscharrer committed Mar 16, 2012
1 parent 4be6da9 commit 978f982
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/core/Application.cpp
Expand Up @@ -204,6 +204,8 @@ bool Application::InitConfig() {
}
}

config.setOutputFile(configFile);

if(!config.init(configFile)) {
fs::path defaultUserConfigFile = config.paths.user / "cfg_default.ini";
if(!config.init(defaultUserConfigFile)) {
Expand All @@ -219,10 +221,11 @@ bool Application::InitConfig() {
}
}
}

// Save a default config file so users have a chance to edit it even if we crash.
config.save();
}

config.set_output_file(configFile);

Logger::configure(config.misc.debug);

if(!migrated && config.misc.migration < Config::CaseSensitiveFilenames) {
Expand Down
7 changes: 5 additions & 2 deletions src/core/Config.cpp
Expand Up @@ -347,6 +347,11 @@ bool Config::setActionKey(ControlAction actionId, int index, InputKeyId key) {
return true;
}

void Config::setOutputFile(const fs::path & _file) {
file = _file;
CrashHandler::addAttachedFile(file);
}

bool Config::save() {

// Finally save it all to file/stream
Expand Down Expand Up @@ -439,8 +444,6 @@ static Vec2i parseResolution(const string & resolution) {

bool Config::init(const fs::path & file) {

CrashHandler::addAttachedFile(file);

fs::ifstream ifs;
ifs.open(file);
bool loaded = ifs.is_open();
Expand Down
5 changes: 1 addition & 4 deletions src/core/Config.h
Expand Up @@ -197,14 +197,11 @@ class Config {

bool init(const fs::path & file);

void set_output_file(const fs::path & _file) { file = _file; }
void setOutputFile(const fs::path & _file);

private:

fs::path file;

InputKeyId GetDIKWithASCII( const std::string& _pcTouch) const;

};

extern Config config;
Expand Down

0 comments on commit 978f982

Please sign in to comment.