csutil/syspath.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Frank Richter 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSSYS_SYSPATH_H__ 00020 #define __CS_CSSYS_SYSPATH_H__ 00021 00022 #include "csextern.h" 00023 #include "array.h" 00024 #include "csstring.h" 00025 #include "ref.h" 00026 #include "util.h" 00027 #include "iutil/stringarray.h" 00028 00039 class csPathsList; 00040 00049 CS_CRYSTALSPACE_EXPORT csString csGetConfigPath (); 00050 00055 CS_CRYSTALSPACE_EXPORT csPathsList* csGetPluginPaths (const char* argv0); 00056 00062 class CS_CRYSTALSPACE_EXPORT csPathsList 00063 { 00064 public: 00068 struct CS_CRYSTALSPACE_EXPORT Entry 00069 { 00073 csString path; 00075 csString type; 00077 bool scanRecursive; 00078 00079 void FixSeparators(); 00080 00081 Entry () : scanRecursive (false) {} 00082 Entry (const char* path, const char* type, bool recursive = false) 00083 { 00084 Entry::path = path; 00085 FixSeparators(); 00086 Entry::type = type; 00087 scanRecursive = recursive; 00088 }; 00089 Entry (const Entry& src) 00090 { 00091 path = src.path; 00092 type = src.type; 00093 scanRecursive = src.scanRecursive; 00094 }; 00095 }; 00096 private: 00097 csArray<Entry> paths; 00098 public: 00100 csPathsList () : paths (4, 4) {} 00102 csPathsList (csPathsList const& o) : paths(o.paths) {} 00104 csPathsList (const char* pathList); 00109 csPathsList (const char* pathList[]); 00111 ~csPathsList() {} 00113 csPathsList& operator= (csPathsList const& o) 00114 { if (&o != this) paths = o.paths; return *this; } 00115 00127 size_t AddUnique (const char* path, bool scanRecursive = false, 00128 const char* type = 0, bool overrideRecursive = true); 00134 size_t AddUniqueExpanded (const char* path, bool scanRecursive = false, 00135 const char* type = 0, bool overrideRecursive = true); 00144 size_t AddUnique (const Entry& path, bool overrideRecursive = true); 00150 size_t AddUniqueExpanded (const Entry& path, bool overrideRecursive = true); 00154 void AddUnique (const csPathsList& list, bool overrideRecursive = true) 00155 { 00156 for (size_t i = 0; i < list.Length(); i++) 00157 { 00158 AddUnique (list[i], overrideRecursive); 00159 } 00160 } 00166 void AddUniqueExpanded (const csPathsList& list, 00167 bool overrideRecursive = true) 00168 { 00169 for (size_t i = 0; i < list.Length(); i++) 00170 { 00171 AddUniqueExpanded (list[i], overrideRecursive); 00172 } 00173 } 00175 void DeleteIndex (size_t index) 00176 { paths.DeleteIndex (index); } 00177 00179 size_t Length () const { return paths.Length(); } 00180 CS_DEPRECATED_METHOD size_t GetCount () const { return Length(); } 00182 Entry const& operator [] (size_t n) const { return paths[n]; } 00183 00185 00190 friend csPathsList operator* (const csPathsList& left, 00191 const csPathsList& right); 00192 inline csPathsList operator*= (const csPathsList& right) 00193 { return (*this = *this * right); } 00194 inline friend csPathsList operator* (const Entry& left, 00195 const csPathsList& right) 00196 { 00197 csPathsList newPaths; 00198 newPaths.paths.Push (left); 00199 return newPaths * right; 00200 } 00201 inline friend csPathsList operator* (const char* left, 00202 const csPathsList& right) 00203 { return Entry (left, 0) * right; } 00204 inline friend csPathsList operator* (const csPathsList& left, 00205 const Entry& right) 00206 { 00207 csPathsList newPaths; 00208 newPaths.paths.Push (right); 00209 return left * newPaths; 00210 } 00211 inline friend csPathsList operator* (const csPathsList& left, 00212 const char* right) 00213 { return left * Entry (right, 0); } 00214 inline csPathsList operator*= (const Entry& right) 00215 { return (*this = *this * right); } 00216 inline csPathsList operator*= (const char* right) 00217 { return (*this = *this * right); } 00219 }; 00220 00224 class CS_CRYSTALSPACE_EXPORT csPathsUtilities 00225 { 00226 public: 00235 static bool PathsIdentical (const char* path1, const char* path2); 00242 static char* ExpandPath (const char* path); 00243 00251 static csPathsList LocateFile (const csPathsList& paths, 00252 const char* file, bool thorough = false); 00253 00255 static void FilterInvalid (csPathsList& paths); 00256 00258 static csPathsList ExpandAll (const csPathsList& paths); 00259 }; 00260 00265 class CS_CRYSTALSPACE_EXPORT csInstallationPathsHelper 00266 { 00267 public: 00276 static csPathsList* GetPlatformInstallationPaths (); 00282 static csRef<iStringArray> FindSystemRoots(); 00295 static csString GetAppPath (const char* argv0); 00296 00310 static csString GetAppDir (const char* argv0); 00311 00330 static csString GetResourceDir (const char* argv0); 00335 static csPathsList* GetPluginPaths (const char* argv0); 00339 static csString GetAppFilename (const char* basename); 00340 }; 00341 00343 00345 CS_DEPRECATED_METHOD inline bool csPathsIdentical (const char* path1, 00346 const char* path2) 00347 { return csPathsUtilities::PathsIdentical (path1, path2); } 00348 CS_DEPRECATED_METHOD inline csRef<iStringArray> csFindSystemRoots() 00349 { return csInstallationPathsHelper::FindSystemRoots (); } 00350 CS_DEPRECATED_METHOD inline char* csExpandPath (const char* path) 00351 { return csPathsUtilities::ExpandPath (path); } 00352 CS_DEPRECATED_METHOD inline csString csGetAppPath (const char* argv0) 00353 { return csInstallationPathsHelper::GetAppPath (argv0); } 00354 CS_DEPRECATED_METHOD inline csString csGetAppDir (const char* argv0) 00355 { return csInstallationPathsHelper::GetAppDir (argv0); } 00356 CS_DEPRECATED_METHOD inline csString csGetResourceDir (const char* argv0) 00357 { return csInstallationPathsHelper::GetResourceDir (argv0); } 00359 00363 #endif
Generated for Crystal Space by doxygen 1.4.6