1 #ifndef _Directories_h_
2 #define _Directories_h_
3 
4 #include <boost/filesystem/path.hpp>
5 #include <string>
6 
7 #include "Export.h"
8 #include "../universe/EnumsFwd.h"
9 
10 /** This function must be called before any Get*Dir function is called. It
11   * stores the current working directory as well as creating local
12   * directories if they do not yet exist. */
13 FO_COMMON_API void CompleteXDGMigration();
14 
15 /** This function completes the migration of directories to the XDG
16   * specified location by updating the save.path option to the new location
17   * after the option is loaded from XML files.  It only updates the option
18   * if it is set to the old default option. */
19 FO_COMMON_API void InitDirs(const std::string& argv0);
20 
21 /** Returns the directory where FreeOrion should store user specific
22   * configuration data , like the configuration file.  Under Unix, this
23   * would be <tt>$XDG_CONFIG_HOME/freeorion</tt>, under Windows, this
24   * might be something along the lines of
25   * <tt>C:\\Documents and Settings\\Username\\FreeOrion</tt>
26   * or even <tt>\\\\Gandalf\\Users\\Frodo\\Settings\\FreeOrion</tt>.
27   * \note <ul><li> If the directory does not exist, it will be created.
28   * Under Windows and OSX it is the same as the GetUserDataDir()
29   * <li>This directory can be considered writable!</ul> */
30 FO_COMMON_API const boost::filesystem::path GetUserConfigDir();
31 
32 /** Returns the directory where FreeOrion should store user specific data,
33   * like the savegames.  Under Unix, this would be
34   * <tt>$XDG_DATA_HOME/freeorion</tt>, under Windows, this might be something
35   * along the lines of <tt>C:\\Documents and Settings\\Username\\FreeOrion</tt>
36   * or even <tt>\\\\Gandalf\\Users\\Frodo\\Settings\\FreeOrion</tt>.
37   * \note <ul><li> If the directory does not exist, it will be created.
38   * Under Windows and OSX it is the same as the GetUserConfigDir()
39   * <li>This directory can be considered writable!</ul> */
40 FO_COMMON_API const boost::filesystem::path GetUserDataDir();
41 
42 /** Converts UTF-8 string into a path, doing any required wide-character
43   * conversions as determined by the operating system / filesystem. */
44 FO_COMMON_API boost::filesystem::path FilenameToPath(const std::string& path_str);
45 
46 /** Returns the directory that contains all game content files, such as string
47   * table files, in-game tech, building, special, etc. definition files, and
48   * graphics files. */
49 FO_COMMON_API const boost::filesystem::path GetResourceDir();
50 
51 /** Returns the root data directory of FreeOrion. Under Windows, it is the
52   * directory where FreeOrion is installed, under Linux, this can be
53   * <tt>/usr/local/share/freeorion</tt>, <tt>/opt/share/freorion</tt>, or even
54   * (when FreeOrion was installed locally with autopackage)
55   * <tt>~/.local/share/freeorion</tt>.  \note This directory and everything in
56   * it should be assumed read-only! */
57 FO_COMMON_API const boost::filesystem::path GetRootDataDir();
58 
59 /** Returns the directory where the binaries are located. Under
60   * Unix, it will be something along the lines of <tt>/usr/local/bin</tt>,
61   * under Windows, it will probably be the installation directory. \note This
62   * directory and everything in it should be assumed read-only! */
63 FO_COMMON_API const boost::filesystem::path GetBinDir();
64 
65 #if defined(FREEORION_MACOSX) || defined(FREEORION_WIN32)
66 /** This function returns the Python home directory from where it is embedded
67   * On OSX: within the application bundle
68   * On Windows: same directory where the binaries are located */
69 FO_COMMON_API const boost::filesystem::path GetPythonHome();
70 #endif
71 
72 /** Returns the full path to the configfile. */
73 FO_COMMON_API const boost::filesystem::path GetConfigPath();
74 
75 /** Returns the full path to the configfile. */
76 FO_COMMON_API const boost::filesystem::path GetPersistentConfigPath();
77 
78 /** Returns the directory where save files are located.  This is typically
79   * the directory "save" within the user directory. */
80 FO_COMMON_API const boost::filesystem::path GetSaveDir();
81 
82 /** Returns the directory where server save files are located.  This is typically
83   * the directory "save" within the user directory. */
84 FO_COMMON_API const boost::filesystem::path GetServerSaveDir();
85 
86 /** Returns a utf-8 string from the given filesystem path. */
87 FO_COMMON_API std::string PathToString(const boost::filesystem::path& path);
88 
89 /** Returns current timestamp in a form that can be used in file names */
90 FO_COMMON_API std::string FilenameTimestamp();
91 
92 /** Returns the path to \a to, as it appears from \a from. */
93 FO_COMMON_API boost::filesystem::path RelativePath(const boost::filesystem::path& from, const boost::filesystem::path& to);
94 
95 //! Returns true if the given @p path referrs to a FO content script and false
96 //! otherwise.
97 FO_COMMON_API bool IsFOCScript(const boost::filesystem::path& path);
98 
99 //! Returns a vector of pathes within @p path including a recursive search
100 //! though sub-dirs.  Then passing a @p predicate, the pathes need to match
101 //! this predicate.  If no predicate is given pathes need to refer to files.
102 FO_COMMON_API std::vector<boost::filesystem::path> ListDir(const boost::filesystem::path& path, std::function<bool (const boost::filesystem::path&)> predicate=nullptr);
103 
104 /** Returns true iff the string \a in is valid UTF-8. */
105 FO_COMMON_API bool IsValidUTF8(const std::string& in);
106 
107 /** Returns true iff the \p test_dir is in \p dir and \p dir
108     is existing directory. */
109 FO_COMMON_API bool IsInDir(const boost::filesystem::path& dir, const boost::filesystem::path& test_dir);
110 
111 /** Returns path currently defined for @p path_type */
112 FO_COMMON_API boost::filesystem::path GetPath(PathType path_type);
113 
114 /** Returns path for path type cast from @p path_string */
115 FO_COMMON_API boost::filesystem::path GetPath(const std::string& path_string);
116 
117 /** Returns if path exists and is a regular file */
118 FO_COMMON_API bool IsExistingFile(const boost::filesystem::path& path);
119 #endif
120