1 // Aseprite 2 // Copyright (C) 2001-2018 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifndef APP_RESOURCE_FINDER_H_INCLUDED 8 #define APP_RESOURCE_FINDER_H_INCLUDED 9 #pragma once 10 11 #include "base/disable_copying.h" 12 #include "base/paths.h" 13 14 #include <string> 15 16 namespace app { 17 18 // Helper class to find configuration files in different directories 19 // in a priority order (e.g. first in the $HOME directory, then in 20 // data/ directory, etc.). 21 class ResourceFinder { 22 public: 23 ResourceFinder(bool log = true); 24 25 // Returns the current possible path. You cannot call this 26 // function if you haven't call first() or next() before. 27 const std::string& filename() const; 28 const std::string& defaultFilename() const; 29 30 // Goes to next possible path. 31 bool next(); 32 33 // Iterates over all possible paths and returns true if the file 34 // is exists. Returns the first existent file. 35 bool findFirst(); 36 37 // These functions add possible full paths to find files. 38 void addPath(const std::string& path); 39 void includeBinDir(const char* filename); 40 void includeDataDir(const char* filename); 41 void includeHomeDir(const char* filename); 42 43 // Tries to add the given filename in these locations: 44 // For Windows: 45 // - If the app is running in portable mode, the filename 46 // will be in the same location as the .exe file. 47 // - If the app is installed, the filename will be inside 48 // %AppData% location 49 // For Unix-like platforms: 50 // - The filename will be in $HOME/.config/aseprite/ 51 void includeUserDir(const char* filename); 52 53 void includeDesktopDir(const char* filename); 54 55 // Returns the first file found or creates the whole directory 56 // structure to create the file in its default location. 57 std::string getFirstOrCreateDefault(); 58 59 private: 60 bool m_log; 61 base::paths m_paths; 62 int m_current; 63 std::string m_default; 64 65 DISABLE_COPYING(ResourceFinder); 66 }; 67 68 } // namespace app 69 70 #endif 71