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 csPluginPaths; 00040 00046 CS_CSUTIL_EXPORT csRef<iStringArray> csFindSystemRoots(); 00047 00056 CS_CSUTIL_EXPORT csString csGetConfigPath (); 00057 00062 CS_CSUTIL_EXPORT csPluginPaths* csGetPluginPaths (const char* argv0); 00063 00070 CS_CSUTIL_EXPORT char* csExpandPath (const char* path); 00071 00084 CS_CSUTIL_EXPORT csString csGetAppPath (const char* argv0); 00085 00099 CS_CSUTIL_EXPORT csString csGetAppDir (const char* argv0); 00100 00119 CS_CSUTIL_EXPORT csString csGetResourceDir (const char* argv0); 00120 00129 CS_CSUTIL_EXPORT bool csPathsIdentical (const char* path1, const char* path2); 00130 00134 struct CS_CSUTIL_EXPORT csPluginPath 00135 { 00140 char* path; 00142 char* type; 00144 bool scanRecursive; 00145 00146 csPluginPath () : path (0), type(0), scanRecursive (false) {} 00147 csPluginPath (const char* path, const char* type, bool recursive = false) 00148 { 00149 csPluginPath::path = csStrNew (path); 00150 csPluginPath::type = csStrNew (type); 00151 scanRecursive = recursive; 00152 }; 00153 csPluginPath (char* path, char* type, bool recursive = false) 00154 { 00155 csPluginPath::path = path; 00156 csPluginPath::type = type; 00157 scanRecursive = recursive; 00158 }; 00159 csPluginPath (const csPluginPath& src) 00160 { 00161 path = csStrNew (src.path); 00162 type = csStrNew (src.type); 00163 scanRecursive = src.scanRecursive; 00164 }; 00165 ~csPluginPath () { delete[] path; delete[] type; } 00166 }; 00167 00171 class CS_CSUTIL_EXPORT csPluginPaths 00172 { 00173 csArray<csPluginPath> paths; 00174 public: 00175 csPluginPaths () : paths (4, 4) { } 00176 00187 int AddOnce (const char* path, bool scanRecursive = false, 00188 const char* type = 0, bool overrideRecursive = true) 00189 { 00190 if (path == 0) return -1; 00191 char* pathExpanded = csExpandPath (path); 00192 if (pathExpanded == 0) return -1; 00193 00194 int i; 00195 for (i = 0; i < paths.Length(); i++) 00196 { 00197 if (csPathsIdentical (pathExpanded, paths[i].path)) 00198 { 00199 if (overrideRecursive) 00200 { 00201 paths[i].scanRecursive = scanRecursive; 00202 } 00203 delete[] paths[i].type; 00204 paths[i].type = csStrNew (type); 00205 delete[] pathExpanded; 00206 00207 return i; 00208 } 00209 } 00210 00211 csPluginPath pluginPath (pathExpanded, csStrNew (type), scanRecursive); 00212 return (paths.Push (pluginPath)); 00213 } 00214 00215 int GetCount () { return paths.Length(); } 00216 csPluginPath const& operator [] (int n) const 00217 { return paths[n]; } 00218 }; 00219 00223 #endif
Generated for Crystal Space by doxygen 1.2.18