00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef __UT_PathSearch__
00047 #define __UT_PathSearch__
00048
00049 #include "UT_API.h"
00050 #include "UT_WorkBuffer.h"
00051 #include "UT_StringArray.h"
00052
00053 enum UT_KnownPath {
00054 UT_HOUDINI_PATH = 0,
00055
00056 UT_HOUDINI_DSO_PATH,
00057 UT_HOUDINI_IMAGE_DSO_PATH,
00058 UT_HOUDINI_AUDIO_DSO_PATH,
00059 UT_HOUDINI_OTL_PATH,
00060 UT_HOUDINI_OPLIBRARIES_PATH,
00061 UT_HOUDINI_OTLSCAN_PATH,
00062 UT_HOUDINI_SCRIPT_PATH,
00063 UT_HOUDINI_SOHO_PATH,
00064 UT_HOUDINI_GALLERY_PATH,
00065
00066 UT_HOUDINI_TEXTURE_PATH,
00067 UT_HOUDINI_GEOMETRY_PATH,
00068 UT_HOUDINI_CLIP_PATH,
00069
00070 UT_VEX_DISPLACE_PATH,
00071 UT_VEX_FOG_PATH,
00072 UT_VEX_LIGHT_PATH,
00073 UT_VEX_SHADOW_PATH,
00074 UT_VEX_SURFACE_PATH,
00075 UT_VEX_PHOTON_PATH,
00076 UT_VEX_BSDF_PATH,
00077
00078 UT_VEX_CHOP_PATH,
00079 UT_VEX_COP2_PATH,
00080 UT_VEX_IMAGE3D_PATH,
00081 UT_VEX_SOP_PATH,
00082 UT_VEX_POP_PATH,
00083 UT_VEX_CVEX_PATH,
00084
00085 UT_GLSL_PATH,
00086
00087 UT_HOUDINI_UI_PATH,
00088 UT_HOUDINI_UI_APP_PATH,
00089 UT_HOUDINI_UI_AUDIO_PATH,
00090 UT_HOUDINI_UI_CURSOR_PATH,
00091 UT_HOUDINI_UI_ICON_PATH,
00092
00093
00094 UT_PATHFILE_DESK,
00095 UT_PATHFILE_MACRO,
00096 UT_PATHFILE_TOOLBAR,
00097 UT_PATHFILE_CUSTOM,
00098
00099 UT_OUTLINEFONT_PATH,
00100
00101 UT_MAX_KNOWN_PATHS
00102 };
00103
00104 class UT_API UT_PathSearch {
00105 public:
00106 UT_PathSearch(const char *defpath,
00107 int var_id,
00108 const char *carat_expand = "",
00109 int at_expand = UT_HOUDINI_PATH);
00110 UT_PathSearch(const UT_PathSearch © );
00111 ~UT_PathSearch();
00112
00113 static const UT_PathSearch *getInstance(UT_KnownPath path_type);
00114
00115
00116
00117
00118 static UT_PathSearch *getHardPath(UT_KnownPath path_type);
00119
00120
00121 static void rehashAll();
00122 static void rehashSpecific(UT_KnownPath pathid);
00123 void rehash();
00124
00125
00126
00127 static void getHomeHoudini(UT_String &str);
00128
00129
00130
00131
00132 void extendPath(const char *defpath = 0,
00133 int var_id = -1,
00134 const char *carat_expand = 0,
00135 int at_expand = -1);
00136
00137
00138 void appendPath(const char *path);
00139
00140
00141 int findFile(UT_String &result, const char *search) const;
00142 int findDirectory(UT_String &result, const char *search) const;
00143
00144
00145
00146 bool findFileFromList(UT_String &result,
00147 const UT_StringArray &search_list) const;
00148 bool findDirectoryFromList(UT_String &result,
00149 const UT_StringArray &search_list) const;
00150
00151
00152
00153
00154 int findAllFiles(const char *search,
00155 UT_StringArray &list) const;
00156
00157 int findAllDirectories(const char *search,
00158 UT_StringArray &list) const;
00159
00160
00161
00162
00163 int matchAllFiles(const char *extension,
00164 bool returnfullpaths,
00165 UT_StringArray &list,
00166 bool recurse=false) const;
00167 int matchAllFilesInSubdirectory(const char *extension,
00168 const char *subdirectory,
00169 bool returnfullpaths,
00170 UT_StringArray &list,
00171 bool recurse=false) const;
00172
00173
00174
00175
00176 int houdiniFindFile(const char *find, UT_String &result) const;
00177 int houdiniFindFile(const char *find, UT_WorkBuffer &result) const;
00178
00179 int houdiniFindDirectory(const char *find, UT_String &result) const;
00180 int houdiniFindDirectory(const char *find, UT_WorkBuffer &r) const;
00181
00182 int getEntries() const { return myPaths.entries(); }
00183 const char *getPathComponent(int i) const { return myPaths(i); }
00184
00185
00186
00187 int getBaseEntries() const { return myBasePaths.entries(); }
00188 const char *getBaseComponent(int i) const { return myBasePaths(i); }
00189 const char *getCondensedComponent(int i) const
00190 { return myCondensedPaths(i); }
00191
00192 const char *getDefaultPath() const { return myDefaultPath; }
00193 const char *getCaratExpand() const { return myCaratExpand; }
00194
00195 int getVariableId() const { return myVariableId; }
00196 int getAtExpand() const { return myAtExpand; }
00197
00198
00199 static int condenseHip(UT_String &path);
00200
00201
00202 static int condenseJob(UT_String &path);
00203
00204
00205
00206 static int condenseCommon(UT_String &path);
00207
00208
00209
00210
00211
00212 static int condensePath(UT_String &path,
00213 const char *paths[],
00214 const char *condensedPaths[],
00215 int npaths);
00216
00217
00218
00219
00220
00221
00222 static int stripLeadPath(UT_String &path, UT_KnownPath pathvar);
00223
00224
00225
00226 static int stripMaxLeadPath(UT_String &path, UT_KnownPath pathvar);
00227
00228
00229
00230
00231 static bool resolveAbsolutePath(const char *filename,
00232 UT_String &absolute_path);
00233
00234 private:
00235 UT_PathSearch & operator=( const UT_PathSearch © );
00236
00237 private:
00238 void initialize(const char *def,
00239 int var_id,
00240 const char *carat,
00241 int at_expand);
00242 void clearPath();
00243
00244
00245 void matchAllFilesInPath(const char *extension,
00246 const char *path,
00247 bool returnfullpaths,
00248 bool recurse,
00249 UT_StringArray &list)const;
00250
00251 int myVariableId;
00252 UT_String myDefaultPath;
00253 UT_String myCaratExpand;
00254 int myAtExpand;
00255 int myMaxPath;
00256
00257 UT_StringArray myPaths;
00258 UT_StringArray myBasePaths;
00259 UT_StringArray myCondensedPaths;
00260 };
00261
00262 inline int
00263 HoudiniFindFile(const char *find, UT_String &result)
00264 {
00265 if (!UT_PathSearch::getInstance(UT_HOUDINI_PATH)->
00266 houdiniFindFile(find, result))
00267 result = 0;
00268 return result.isstring();
00269 }
00270
00271 inline int
00272 HoudiniFindFile(const char *find, UT_WorkBuffer &result)
00273 {
00274 if (!UT_PathSearch::getInstance(UT_HOUDINI_PATH)->
00275 houdiniFindFile(find, result))
00276 result.clear();
00277 return result.length() != 0;
00278 }
00279
00280 inline int
00281 HoudiniFindMulti(const char *find, UT_StringArray &result)
00282 {
00283 result.clear();
00284 UT_PathSearch::getInstance(UT_HOUDINI_PATH)->
00285 findAllFiles(find, result);
00286 return result.entries();
00287 }
00288
00289 inline int
00290 HoudiniFindDir(const char *find, UT_String &result)
00291 {
00292 if (!UT_PathSearch::getInstance(UT_HOUDINI_PATH)->
00293 houdiniFindDirectory(find, result))
00294 result = 0;
00295 return result.isstring();
00296 }
00297
00298 inline int
00299 HoudiniFindDir(const char *find, UT_WorkBuffer &result)
00300 {
00301 if (!UT_PathSearch::getInstance(UT_HOUDINI_PATH)->
00302 houdiniFindDirectory(find, result))
00303 result.clear();
00304 return result.length() != 0;
00305 }
00306
00307 inline int
00308 HoudiniFindDirMulti(const char *find, UT_StringArray &result)
00309 {
00310 result.clear();
00311 UT_PathSearch::getInstance(UT_HOUDINI_PATH)->
00312 findAllDirectories(find, result);
00313 return result.entries();
00314 }
00315
00316 #endif