00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_CSSYS_SYSPATH_H__
00021 #define __CS_CSSYS_SYSPATH_H__
00022
00023 #include "csutil/array.h"
00024 #include "csutil/ref.h"
00025 #include "csutil/util.h"
00026 #include "iutil/stringarray.h"
00027
00038 class csPluginPaths;
00039
00045 csRef<iStringArray> csFindSystemRoots();
00046
00055 char* csGetConfigPath ();
00056
00061 csPluginPaths* csGetPluginPaths (const char* argv0);
00062
00069 char* csExpandPath (const char* path);
00070
00083 char* csGetAppPath (const char* argv0);
00084
00099 char* csGetAppDir (const char* argv0);
00100
00115 char* csGetResourceDir (const char* argv0);
00116
00125 bool csPathsIdentical (const char* path1, const char* path2);
00126
00130 struct csPluginPath
00131 {
00136 char* path;
00138 char* type;
00140 bool scanRecursive;
00141
00142 csPluginPath () : path (0), type(0), scanRecursive (false) {}
00143 csPluginPath (const char* path, const char* type, bool recursive = false)
00144 {
00145 csPluginPath::path = csStrNew (path);
00146 csPluginPath::type = csStrNew (type);
00147 scanRecursive = recursive;
00148 };
00149 csPluginPath (char* path, char* type, bool recursive = false)
00150 {
00151 csPluginPath::path = path;
00152 csPluginPath::type = type;
00153 scanRecursive = recursive;
00154 };
00155 csPluginPath (const csPluginPath& src)
00156 {
00157 path = csStrNew (src.path);
00158 type = csStrNew (src.type);
00159 scanRecursive = src.scanRecursive;
00160 };
00161 ~csPluginPath () { delete[] path; delete[] type; }
00162 };
00163
00167 class csPluginPaths
00168 {
00169 csArray<csPluginPath> paths;
00170 public:
00171 csPluginPaths () : paths (4, 4) { }
00172
00183 int AddOnce (const char* path, bool scanRecursive = false,
00184 const char* type = 0, bool overrideRecursive = true)
00185 {
00186 if (path == 0) return -1;
00187 char* pathExpanded = csExpandPath (path);
00188 if (pathExpanded == 0) return -1;
00189
00190 int i;
00191 for (i = 0; i < paths.Length(); i++)
00192 {
00193 if (csPathsIdentical (pathExpanded, paths[i].path))
00194 {
00195 if (overrideRecursive)
00196 {
00197 paths[i].scanRecursive = scanRecursive;
00198 }
00199 delete[] paths[i].type;
00200 paths[i].type = csStrNew (type);
00201 delete[] pathExpanded;
00202
00203 return i;
00204 }
00205 }
00206
00207 csPluginPath pluginPath (pathExpanded, csStrNew (type), scanRecursive);
00208 return (paths.Push (pluginPath));
00209 }
00210
00211 int GetCount () { return paths.Length(); }
00212 csPluginPath const& operator [] (int n) const
00213 { return paths[n]; }
00214 };
00215
00219 #endif