CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 "array.h"
00023 #include "csstring.h"
00024 #include "ref.h"
00025 #include "util.h"
00026 #include "iutil/stringarray.h"
00027 
00038 class csPluginPaths;
00039 
00045 csRef<iStringArray> csFindSystemRoots();
00046 
00055 csString csGetConfigPath ();
00056 
00061 csPluginPaths* csGetPluginPaths (const char* argv0);
00062 
00069 char* csExpandPath (const char* path);
00070 
00081 csString csGetAppPath (const char* argv0);
00082 
00097 csString csGetAppDir (const char* argv0);
00098 
00113 csString csGetResourceDir (const char* argv0);
00114 
00123 bool csPathsIdentical (const char* path1, const char* path2);
00124 
00128 struct csPluginPath
00129 {
00134   char* path;
00136   char* type;
00138   bool scanRecursive;
00139   
00140   csPluginPath () : path (0), type(0), scanRecursive (false) {}
00141   csPluginPath (const char* path, const char* type, bool recursive = false)
00142   {
00143     csPluginPath::path = csStrNew (path);
00144     csPluginPath::type = csStrNew (type);
00145     scanRecursive = recursive;
00146   };
00147   csPluginPath (char* path, char* type, bool recursive = false)
00148   {
00149     csPluginPath::path = path;
00150     csPluginPath::type = type;
00151     scanRecursive = recursive;
00152   };
00153   csPluginPath (const csPluginPath& src)
00154   {
00155     path = csStrNew (src.path);
00156     type = csStrNew (src.type);
00157     scanRecursive = src.scanRecursive;
00158   };
00159   ~csPluginPath () { delete[] path; delete[] type; }
00160 };
00161 
00165 class csPluginPaths
00166 {
00167   csArray<csPluginPath> paths;
00168 public:
00169   csPluginPaths () : paths (4, 4) { }
00170 
00181   int AddOnce (const char* path, bool scanRecursive = false, 
00182     const char* type = 0, bool overrideRecursive = true)
00183   {
00184     if (path == 0) return -1;
00185     char* pathExpanded = csExpandPath (path);
00186     if (pathExpanded == 0) return -1;
00187   
00188     int i;
00189     for (i = 0; i < paths.Length(); i++)
00190     {
00191       if (csPathsIdentical (pathExpanded, paths[i].path))
00192       {
00193         if (overrideRecursive)
00194         {
00195           paths[i].scanRecursive = scanRecursive;
00196         }
00197         delete[] paths[i].type;
00198         paths[i].type = csStrNew (type);
00199         delete[] pathExpanded;
00200   
00201         return i;
00202       }
00203     }
00204   
00205     csPluginPath pluginPath (pathExpanded, csStrNew (type), scanRecursive);
00206     return (paths.Push (pluginPath));
00207   }
00208   
00209   int GetCount () { return paths.Length(); }
00210   csPluginPath const& operator [] (int n) const
00211   { return paths[n]; }
00212 };
00213 
00217 #endif

Generated for Crystal Space by doxygen 1.2.18