diff --git a/src/app/ini_file.cpp b/src/app/ini_file.cpp index d73c3791e..b3e406d8b 100644 --- a/src/app/ini_file.cpp +++ b/src/app/ini_file.cpp @@ -24,6 +24,7 @@ #include "app/resource_finder.h" #include "base/fs.h" +#include "base/path.h" #include #include @@ -48,8 +49,13 @@ ConfigModule::ConfigModule() // If the file wasn't found, we will create configuration file // in the first path - if (config_filename[0] == 0 && rf.first()) - config_filename = rf.filename(); + if (config_filename[0] == 0) { + config_filename = rf.defaultFilename(); + + std::string dir = base::get_file_path(config_filename); + if (!base::is_directory(dir)) + base::make_directory(dir); + } override_config_file(config_filename.c_str()); g_configFilename = config_filename; diff --git a/src/app/log.cpp b/src/app/log.cpp index aa2f9971f..7be85e6be 100644 --- a/src/app/log.cpp +++ b/src/app/log.cpp @@ -94,8 +94,7 @@ void verbose_printf(const char* format, ...) std::string filename; ResourceFinder rf; rf.includeBinDir("aseprite.log"); - if (rf.first()) - filename = rf.filename(); + filename = rf.defaultFilename(); if (filename.size() > 0) log_fileptr = fopen(filename.c_str(), "w"); diff --git a/src/app/resource_finder.cpp b/src/app/resource_finder.cpp index 13c5c917f..e3cac9879 100644 --- a/src/app/resource_finder.cpp +++ b/src/app/resource_finder.cpp @@ -26,6 +26,7 @@ #include "app/resource_finder.h" #include "base/fs.h" #include "base/path.h" +#include "base/string.h" namespace app { @@ -40,10 +41,14 @@ const std::string& ResourceFinder::filename() const return m_paths.at(m_current); } -bool ResourceFinder::first() +const std::string& ResourceFinder::defaultFilename() const { - m_current = 0; - return (m_current < (int)m_paths.size()); + if (m_default.empty()) { + // The first path is the default one if nobody specified it. + if (!m_paths.empty()) + return m_paths[0]; + } + return m_default; } bool ResourceFinder::next() @@ -169,6 +174,15 @@ void ResourceFinder::includeHomeDir(const char* filename) #elif defined ALLEGRO_WINDOWS || defined ALLEGRO_DOS + // %AppData%/Aseprite/filename + wchar_t* env = _wgetenv(L"AppData"); + if (env) { + std::string path = base::join_path(base::to_utf8(env), "Aseprite"); + path = base::join_path(path, filename); + addPath(path); + m_default = path; + } + // $PREFIX/data/filename includeDataDir(filename); @@ -187,10 +201,15 @@ void ResourceFinder::includeConfFile() // $HOME/.asepriterc includeHomeDir(".asepriterc"); -#endif +#elif defined ALLEGRO_WINDOWS // $BINDIR/aseprite.ini includeBinDir("aseprite.ini"); + + // %AppData%/Aseprite/aseprite.ini + includeHomeDir("aseprite.ini"); + +#endif } } // namespace app diff --git a/src/app/resource_finder.h b/src/app/resource_finder.h index e05091634..e8a7aa94e 100644 --- a/src/app/resource_finder.h +++ b/src/app/resource_finder.h @@ -35,11 +35,7 @@ namespace app { // Returns the current possible path. You cannot call this // function if you haven't call first() or next() before. const std::string& filename() const; - - // Goes to the first option in the list of possible paths. - // Returns true if there is (at least) one option available - // (m_paths.size() != 0). - bool first(); + const std::string& defaultFilename() const; // Goes to next possible path. bool next(); @@ -64,6 +60,7 @@ namespace app { // Members std::vector m_paths; int m_current; + std::string m_default; }; } // namespace app diff --git a/src/main/main.cpp b/src/main/main.cpp index 0e59355c9..2a34c3691 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -68,8 +68,7 @@ namespace { #ifdef WIN32 app::ResourceFinder rf; rf.includeBinDir("aseprite-memory.dmp"); - if (rf.first()) - filename = rf.filename(); + filename = rf.defaultFilename(); return true; #else return false;