| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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, bool expand = false);
    00109   csPathsList (const char* const pathList[], bool expand = false);
    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
    00180   size_t Length () const { return paths.Length(); }
    00181   size_t GetSize () const { return paths.Length(); }
    00183   CS_DEPRECATED_METHOD_MSG("Use Length() instead")
    00184   size_t GetCount () const { return Length(); }
    00186
    00187   Entry const& operator [] (size_t n) const { return paths[n]; }
    00188   Entry& operator [] (size_t n) { return paths[n]; }
    00190
    00192
    00197   CS_CRYSTALSPACE_EXPORT friend csPathsList operator* (const csPathsList& left,
    00198     const csPathsList& right);
    00199   inline csPathsList operator*= (const csPathsList& right)
    00200   { return (*this = *this * right); }
    00201   inline friend csPathsList operator* (const Entry& left,
    00202     const csPathsList& right)
    00203   {
    00204     csPathsList newPaths;
    00205     newPaths.paths.Push (left);
    00206     return newPaths * right;
    00207   }
    00208   inline friend csPathsList operator* (const char* left,
    00209     const csPathsList& right)
    00210   { return Entry (left, 0) * right; }
    00211   inline friend csPathsList operator* (const csPathsList& left,
    00212     const Entry& right)
    00213   {
    00214     csPathsList newPaths;
    00215     newPaths.paths.Push (right);
    00216     return left * newPaths;
    00217   }
    00218   inline friend csPathsList operator* (const csPathsList& left,
    00219     const char* right)
    00220   { return left * Entry (right, 0); }
    00221   inline csPathsList operator*= (const Entry& right)
    00222   { return (*this = *this * right); }
    00223   inline csPathsList operator*= (const char* right)
    00224   { return (*this = *this * right); }
    00226 };
    00227
    00231 class CS_CRYSTALSPACE_EXPORT csPathsUtilities
    00232 {
    00233 public:
    00242   static bool PathsIdentical (const char* path1, const char* path2);
    00249   static char* ExpandPath (const char* path);
    00250
    00258   static csPathsList LocateFile (const csPathsList& paths,
    00259     const char* file, bool thorough = false);
    00260
    00262   static void FilterInvalid (csPathsList& paths);
    00263
    00265   static csPathsList ExpandAll (const csPathsList& paths);
    00266 };
    00267
    00272 class CS_CRYSTALSPACE_EXPORT csInstallationPathsHelper
    00273 {
    00274 public:
    00283   static csPathsList* GetPlatformInstallationPaths ();
    00289   static csRef<iStringArray> FindSystemRoots();
    00302   static csString GetAppPath (const char* argv0);
    00303
    00317   static csString GetAppDir (const char* argv0);
    00318
    00337   static csString GetResourceDir (const char* argv0);
    00342   static csPathsList* GetPluginPaths (const char* argv0);
    00346   static csString GetAppFilename (const char* basename);
    00347 };
    00348
    00350
    00352 CS_DEPRECATED_METHOD inline bool csPathsIdentical (const char* path1,
    00353   const char* path2)
    00354 { return csPathsUtilities::PathsIdentical (path1, path2); }
    00355 CS_DEPRECATED_METHOD inline csRef<iStringArray> csFindSystemRoots()
    00356 { return csInstallationPathsHelper::FindSystemRoots (); }
    00357 CS_DEPRECATED_METHOD inline char* csExpandPath (const char* path)
    00358 { return csPathsUtilities::ExpandPath (path); }
    00359 CS_DEPRECATED_METHOD inline csString csGetAppPath (const char* argv0)
    00360 { return csInstallationPathsHelper::GetAppPath (argv0); }
    00361 CS_DEPRECATED_METHOD inline csString csGetAppDir (const char* argv0)
    00362 { return csInstallationPathsHelper::GetAppDir (argv0); }
    00363 CS_DEPRECATED_METHOD inline csString csGetResourceDir (const char* argv0)
    00364 { return csInstallationPathsHelper::GetResourceDir (argv0); }
    00366
    00370 #endif