CrystalSpace

Public API Reference

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

syspath.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 1998-2003 by Jorrit Tyberghein
00003               (C) 2003 by Frank Richter
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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

Generated for Crystal Space by doxygen 1.2.14