1 // =========================================================================== 2 // Purpose: wxFile, wxDir, wxFileName and file functions 3 // Author: J Winwood, John Labenski 4 // Created: 14/11/2001 5 // Copyright: (c) 2001-2002 Lomtick Software. All rights reserved. 6 // Licence: wxWidgets licence 7 // wxWidgets: Updated to 2.8.4 8 // =========================================================================== 9 10 #include "wx/filefn.h" 11 #include "sys/stat.h" 12 13 // global functions from the wxWindow's functions docs 14 15 bool wxDirExists(const wxString& dirname); 16 bool wxFileExists(const wxString& filename); 17 18 // %override [new Lua string] wxDos2UnixFilename(Lua string); 19 // C++ Func: void wxDos2UnixFilename(wxChar *s); 20 !%wxchkver_2_9_0 wxString wxDos2UnixFilename(const wxString& s); 21 // %override wxDateTime wxFileModificationTime(const wxString& filename) (not overridden, just return wxDateTime); 22 // C++ Func: time_t wxFileModificationTime(const wxString& filename); 23 wxDateTime wxFileModificationTime(const wxString& filename); 24 //wxString wxFileNameFromPath(const wxString& path); // obsolete use wxFileName::SplitPath 25 wxString wxFindFirstFile(const wxString& spec, int flags = 0); 26 wxString wxFindNextFile(); 27 // bool wxGetDiskSpace(const wxString& path, wxLongLong *total = NULL, wxLongLong *free = NULL); 28 //wxFileKind wxGetFileKind(FILE* fd); 29 wxString wxGetOSDirectory(); 30 bool wxIsAbsolutePath(const wxString& filename); 31 wxString wxPathOnly(const wxString& path); 32 // %override [new Lua string] wxUnix2DosFilename(Lua string); 33 // C++ Func: void wxUnix2DosFilename(wxChar *s); 34 !%wxchkver_2_9 wxString wxUnix2DosFilename(const wxString& s); 35 bool wxConcatFiles(const wxString& file1, const wxString& file2,const wxString& file3); 36 bool wxCopyFile(const wxString& file1, const wxString& file2, bool overwrite = true); 37 wxString wxGetCwd(); 38 bool wxIsWild(const wxString& pattern); 39 bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special); 40 bool wxMkdir(const wxString& dir, int perm = 0777); 41 //int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters); 42 !%wxchkver_2_9 || %wxcompat_2_8 wxString wxRealPath(const wxString& path); 43 bool wxRemoveFile(const wxString& file); 44 !%wxchkver_2_8 bool wxRenameFile(const wxString& file1, const wxString& file2); 45 %wxchkver_2_8 bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true); 46 bool wxRmdir(const wxString& dir, int flags=0); 47 bool wxSetWorkingDirectory(const wxString& dir); 48 49 %wxchkver_2_8 bool wxIsWritable(const wxString &path); 50 %wxchkver_2_8 bool wxIsReadable(const wxString &path); 51 %wxchkver_2_8 bool wxIsExecutable(const wxString &path); 52 53 // These two methods are for wxLua 54 // %override long wxFileSize(const wxString& fileName) - gets the filesize 55 long wxFileSize(const wxString& fileName); 56 57 // wxLua only has storage for wxChar* in bindings, wxFILE_SEP_XXX are #defined 58 // as wxChar wxT('.'), so we just redefine them to be wxT(".") or wxChar* 59 #define_wxstring wxFILE_SEP_EXT wxT("."); 60 #define_wxstring wxFILE_SEP_DSK wxT(":"); 61 #define_wxstring wxFILE_SEP_PATH_DOS wxT("\\"); 62 #define_wxstring wxFILE_SEP_PATH_UNIX wxT("/"); 63 #define_wxstring wxFILE_SEP_PATH_MAC wxT(":"); 64 #define_wxstring wxFILE_SEP_PATH_VMS wxT("."); // VMS also uses '[' and ']' 65 66 #define_wxstring wxFILE_SEP_PATH wxLua_FILE_SEP_PATH // hack to convert from wxChar wxT('') to wxChar* wxT(""); 67 68 #define_wxstring wxPATH_SEP_DOS // wxT(";"); 69 #define_wxstring wxPATH_SEP_UNIX // wxT(":"); 70 #define_wxstring wxPATH_SEP_MAC // wxT(";"); 71 #define_wxstring wxPATH_SEP // wxPATH_SEP_XXX 72 73 #define wxARE_FILENAMES_CASE_SENSITIVE // bool 1/0 74 75 //bool wxIsPathSeparator(wxChar c) FIXME 76 bool wxEndsWithPathSeparator(const wxString& pszFileName); 77 78 79 // --------------------------------------------------------------------------- 80 // wxStandardPaths 81 82 #if %wxchkver_2_8 && wxLUA_USE_wxStandardPaths 83 84 #include "wx/stdpaths.h" 85 86 #if %wxchkver_3_1_0 87 enum wxStandardPaths::Dir 88 { 89 /** 90 Directory containing user documents. 91 92 Example return values: 93 - Unix/Mac: @c ~/Documents 94 - Windows: @c "C:\Users\username\Documents" 95 */ 96 Dir_Documents, 97 98 /** 99 Directory containing files on the users desktop. 100 101 Example return values: 102 - Unix/Mac: @c ~/Desktop 103 - Windows: @c "C:\Users\username\Desktop" 104 */ 105 Dir_Desktop, 106 107 /** 108 Directory for downloaded files 109 110 Example return values: 111 - Unix/Mac: @c ~/Downloads 112 - Windows: @c "C:\Users\username\Downloads" (Only available on Vista and newer) 113 */ 114 Dir_Downloads, 115 116 /** 117 Directory containing music files. 118 119 Example return values: 120 - Unix/Mac: @c ~/Music 121 - Windows: @c "C:\Users\username\Music" 122 */ 123 Dir_Music, 124 125 /** 126 Directory containing picture files. 127 128 Example return values: 129 - Unix/Mac: @c ~/Pictures 130 - Windows: @c "C:\Users\username\Pictures" 131 */ 132 Dir_Pictures, 133 134 /** 135 Directory containing video files. 136 137 Example return values: 138 - Unix: @c ~/Videos 139 - Windows: @c "C:\Users\username\Videos" 140 - Mac: @c ~/Movies 141 */ 142 Dir_Videos 143 }; 144 #endif // %wxchkver_3_1_0 145 146 #if %wxchkver_3_1_1 147 enum wxStandardPaths::FileLayout 148 { 149 /** 150 Use the classic file layout. 151 152 User configuration and data files are located directly in the home 153 directory. 154 155 This is the default behaviour for compatibility reasons. 156 */ 157 FileLayout_Classic, 158 159 /** 160 Use a XDG styled file layout. 161 162 File layout follows the XDG Base Directory Specification (see 163 https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). 164 165 This is the recommended layout for new applications. 166 */ 167 FileLayout_XDG 168 }; 169 #endif // %wxchkver_3_1_1 170 171 #if %wxchkver_3_1_1 172 enum wxStandardPaths::ConfigFileConv 173 { 174 /** 175 Use the class Unix dot-file convention. 176 177 Prepend the dot to the file base name. 178 179 This value is ignored when in XDG mode, where MakeConfigFileName() 180 always behaves as if ConfigFileConv_Ext was specified. 181 */ 182 ConfigFileConv_Dot, 183 184 /** 185 Use @c .conf extension for the file names. 186 187 This convention is always used in XDG mode. 188 */ 189 ConfigFileConv_Ext 190 }; 191 #endif // %wxchkver_3_1_1 192 193 194 enum wxStandardPaths::ResourceCat 195 { 196 ResourceCat_None, // no special category 197 ResourceCat_Messages, // message catalog resources 198 !%wxchkver_3_1_1 ResourceCat_Max // end of enum marker 199 }; 200 201 class wxStandardPaths // ignore wxStandardPathsBase 202 { 203 %wxchkver_3_0_0 && %win void DontIgnoreAppSubDir(); 204 static wxStandardPaths& Get(); 205 %wxchkver_3_0_0 wxString GetAppDocumentsDir() const; 206 virtual wxString GetConfigDir() const; 207 virtual wxString GetDataDir() const; 208 virtual wxString GetDocumentsDir() const; 209 virtual wxString GetExecutablePath() const; 210 %wxchkver_3_0_0 && %gtk wxString GetInstallPrefix() const; 211 virtual wxString GetLocalDataDir() const; 212 virtual wxString GetPluginsDir() const; 213 virtual wxString GetResourcesDir() const; 214 virtual wxString GetTempDir() const; 215 virtual wxString GetUserConfigDir() const; 216 virtual wxString GetUserDataDir() const; 217 virtual wxString GetUserLocalDataDir() const; 218 %wxchkver_3_0_0 && %win void IgnoreAppSubDir(const wxString& subdirPattern); 219 %wxchkver_3_0_0 && %win void IgnoreAppBuildSubDirs(); 220 %wxchkver_3_0_0 && %win static wxString MSWGetShellDir(int csidl); 221 %wxchkver_3_0_0 && %gtk void SetInstallPrefix(const wxString& prefix); 222 %wxchkver_3_0_0 void UseAppInfo(int info); 223 %wxchkver_3_1_1 wxStandardPaths::FileLayout GetFileLayout() const; // %override return type 224 %wxchkver_3_1_0 wxString GetUserDir(wxStandardPaths::Dir userDir) const; // %override parameter type 225 %wxchkver_3_1_1 void SetFileLayout(wxStandardPaths::FileLayout layout); // %override parameter type 226 %wxchkver_3_1_1 wxString MakeConfigFileName(const wxString& basename, wxStandardPaths::ConfigFileConv conv = wxStandardPaths::ConfigFileConv_Ext) const; // %override parameter type 227 wxString GetLocalizedResourcesDir(const wxString& lang, wxStandardPaths::ResourceCat category = wxStandardPaths::ResourceCat_None) const; // %override parameter types 228 }; 229 230 #endif // %wxchkver_2_8 && wxLUA_USE_wxStandardPaths 231 232 233 // --------------------------------------------------------------------------- 234 // wxPathList 235 236 #include "wx/filefn.h" 237 238 class %delete wxPathList : public wxArrayString 239 { 240 wxPathList(); 241 //wxPathList(const wxArrayString &arr); 242 243 // Adds all paths in environment variable 244 void AddEnvList(const wxString& envVariable); 245 // Adds given path to this list 246 !%wxchkver_2_8 void Add(const wxString& path); 247 %wxchkver_2_8 bool Add(const wxString& path); 248 %wxchkver_2_8 void Add(const wxArrayString& paths); 249 // Find the first full path for which the file exists 250 wxString FindValidPath(const wxString& filename) const; 251 // Find the first full path for which the file exists; ensure it's an 252 // absolute path that gets returned. 253 wxString FindAbsoluteValidPath(const wxString& filename) const; 254 // Given full path and filename, add path to list 255 %not_overload !%wxchkver_2_8 void EnsureFileAccessible(const wxString& path); 256 %not_overload %wxchkver_2_8 bool EnsureFileAccessible(const wxString& path); 257 }; 258 259 // --------------------------------------------------------------------------- 260 // wxFileName 261 262 #if wxLUA_USE_wxFileName 263 264 #include "wx/filename.h" 265 266 #define wxPATH_GET_VOLUME 267 #define wxPATH_GET_SEPARATOR 268 #define wxPATH_MKDIR_FULL 269 270 #define wxFILE 271 #define wxDIR 272 273 enum wxPathFormat 274 { 275 wxPATH_NATIVE, 276 wxPATH_UNIX, 277 wxPATH_MAC, 278 wxPATH_DOS, 279 wxPATH_VMS, 280 wxPATH_BEOS, 281 wxPATH_WIN, 282 wxPATH_OS2, 283 wxPATH_MAX 284 }; 285 286 enum wxPathNormalize 287 { 288 wxPATH_NORM_ENV_VARS, 289 wxPATH_NORM_DOTS, 290 wxPATH_NORM_TILDE, 291 wxPATH_NORM_CASE, 292 wxPATH_NORM_ABSOLUTE, 293 wxPATH_NORM_LONG, 294 wxPATH_NORM_SHORTCUT, 295 wxPATH_NORM_ALL 296 }; 297 298 #if %wxchkver_3_1_1 299 enum wxSizeConvention 300 { 301 wxSIZE_CONV_TRADITIONAL, /// 1024 bytes = 1KB. 302 wxSIZE_CONV_IEC, /// 1024 bytes = 1KiB. 303 wxSIZE_CONV_SI /// 1000 bytes = 1KB. 304 }; 305 #endif // %wxchkver_3_1_1 306 307 class %delete wxFileName 308 { 309 wxFileName(); 310 wxFileName(const wxFileName& filename); 311 wxFileName(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); 312 wxFileName(const wxString& path, const wxString& name, wxPathFormat format = wxPATH_NATIVE); 313 %wxchkver_3_0_0 wxFileName(const wxString& path, const wxString& name, const wxString& ext, wxPathFormat format = wxPATH_NATIVE); 314 wxFileName(const wxString& volume, const wxString& path, const wxString& name, const wxString& ext, wxPathFormat format = wxPATH_NATIVE); 315 void AppendDir(const wxString& dir); 316 void Assign(const wxFileName& filepath); 317 void Assign(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); 318 %wxchkver_3_0_0 void Assign(const wxString& volume, const wxString& path, const wxString& name, const wxString& ext, bool hasExt, wxPathFormat format = wxPATH_NATIVE); 319 void Assign(const wxString& volume, const wxString& path, const wxString& name, const wxString& ext, wxPathFormat format = wxPATH_NATIVE); 320 void Assign(const wxString& path, const wxString& name, wxPathFormat format = wxPATH_NATIVE); 321 void Assign(const wxString& path, const wxString& name, const wxString& ext, wxPathFormat format = wxPATH_NATIVE); 322 void AssignCwd(const wxString& volume = ""); 323 void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE); 324 void AssignHomeDir(); 325 %wxchkver_2_8 && (wxUSE_FILE||wxUSE_FFILE) void AssignTempFileName(const wxString& prefix); 326 %wxchkver_2_8 && wxUSE_FILE void AssignTempFileName(const wxString& prefix, wxFile *fileTemp); 327 // %wxchkver_2_8 && wxUSE_FFILE void AssignTempFileName(const wxString& prefix, wxFFile *fileTemp); // wxFFile no available in wxlua 328 void Clear(); 329 void ClearExt(); 330 %wxchkver_2_8 && wxUSE_FILE static wxString CreateTempFileName(const wxString& prefix, wxFile *fileTemp); 331 // %wxchkver_2_8 && wxUSE_FFILE static wxString CreateTempFileName(const wxString& prefix, wxFFile *fileTemp); // wxFFile no available in wxlua 332 bool DirExists(); 333 static bool DirExists(const wxString& dir); 334 %wxchkver_3_0_0 static wxFileName DirName(const wxString& dir, wxPathFormat format = wxPATH_NATIVE); 335 %wxchkver_3_0_0 void DontFollowLink(); 336 %wxchkver_3_0_0 bool Exists(int flags = wxFILE_EXISTS_ANY) const; 337 %wxchkver_3_0_0 static bool Exists(const wxString& path, int flags = wxFILE_EXISTS_ANY); 338 bool FileExists(); 339 static bool FileExists(const wxString& file); 340 %wxchkver_3_0_0 static wxFileName FileName(const wxString& file, wxPathFormat format = wxPATH_NATIVE); 341 static wxString GetCwd(const wxString& volume = ""); 342 int GetDirCount() const; 343 const wxArrayString& GetDirs() const; // %override [Lua string table] wxFileName::GetDirs(); 344 wxString GetExt() const; 345 static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE); 346 static wxPathFormat GetFormat(wxPathFormat format = wxPATH_NATIVE); 347 wxString GetFullName() const; 348 wxString GetFullPath(wxPathFormat format = wxPATH_NATIVE) const; 349 static wxString GetHomeDir(); 350 wxString GetLongPath() const; 351 wxDateTime GetModificationTime() const; 352 wxString GetName() const; 353 wxString GetPath(int flags = 0, wxPathFormat format = wxPATH_NATIVE) const; 354 static int GetPathSeparator(wxPathFormat format = wxPATH_NATIVE); 355 static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE); 356 static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE); 357 wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE) const; 358 wxString GetShortPath() const; 359 %wxchkver_2_8 wxULongLong GetSize() const; 360 %wxchkver_2_8 static wxULongLong GetSize(const wxString &file); 361 %wxchkver_3_0_0 static wxString GetTempDir(); 362 wxString GetVolume() const; 363 static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE); 364 %wxchkver_3_0_0 && %win static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR); // %override as it's win-only 365 bool HasExt() const; 366 bool HasName() const; 367 bool HasVolume() const; 368 %wxchkver_3_0_0 bool InsertDir(size_t before, const wxString& dir); 369 bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE); 370 static bool IsCaseSensitive(wxPathFormat format = wxPATH_NATIVE); 371 bool IsDir() const; 372 %wxchkver_2_8 bool IsDirReadable() const; 373 %wxchkver_2_8 static bool IsDirReadable(const wxString &path); 374 %wxchkver_2_8 bool IsDirWritable() const; 375 %wxchkver_2_8 static bool IsDirWritable(const wxString &path); 376 %wxchkver_2_8 bool IsFileExecutable() const; 377 %wxchkver_2_8 static bool IsFileExecutable(const wxString &path); 378 %wxchkver_2_8 bool IsFileReadable() const; 379 %wxchkver_2_8 static bool IsFileReadable(const wxString &path); 380 %wxchkver_2_8 bool IsFileWritable() const; 381 %wxchkver_2_8 static bool IsFileWritable(const wxString &path); 382 bool IsOk() const; 383 %wxchkver_3_0_0 static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE); 384 %wxchkver_3_0_0 && %win static bool IsMSWUniqueVolumeNamePath(const wxString& path, wxPathFormat format = wxPATH_NATIVE); 385 bool IsRelative(wxPathFormat format = wxPATH_NATIVE); 386 bool MakeAbsolute(const wxString& cwd = "", wxPathFormat format = wxPATH_NATIVE); 387 bool MakeRelativeTo(const wxString& pathBase = "", wxPathFormat format = wxPATH_NATIVE); 388 bool Mkdir(int perm = 4095, int flags = 0); 389 static bool Mkdir(const wxString& dir, int perm = 4095, int flags = 0); 390 bool Normalize(int flags = wxPATH_NORM_ALL, const wxString& cwd = wxEmptyString, wxPathFormat format = wxPATH_NATIVE); 391 void PrependDir(const wxString& dir); 392 %wxchkver_3_0_0 void RemoveDir(size_t pos); 393 void RemoveLastDir(); 394 %wxchkver_3_0_0 bool ReplaceEnvVariable(const wxString& envname, const wxString& replacementFmtString = "$%s", wxPathFormat format = wxPATH_NATIVE); 395 %wxchkver_3_0_0 bool ReplaceHomeDir(wxPathFormat format = wxPATH_NATIVE); 396 %wxchkver_3_0_0 bool Rmdir(int flags = 0) const; 397 %wxchkver_3_0_0 static bool Rmdir(const wxString& dir, int flags = 0); 398 bool SameAs(const wxFileName& filepath, wxPathFormat format = wxPATH_NATIVE) const; 399 bool SetCwd(); 400 static bool SetCwd(const wxString& cwd); 401 void SetEmptyExt(); 402 void SetExt(const wxString& ext); 403 void SetFullName(const wxString& fullname); 404 void SetName(const wxString& name); 405 %wxchkver_3_0_0 void SetPath(const wxString& path, wxPathFormat format = wxPATH_NATIVE); 406 %wxchkver_3_0_0 bool SetPermissions(int permissions); 407 %wxchkver_3_1_3 static wxFileName URLToFileName(const wxString& url); 408 %wxchkver_3_1_3 static wxString FileNameToURL(const wxFileName& filename); 409 bool SetTimes(const wxDateTime* dtAccess, const wxDateTime* dtMod, const wxDateTime* dtCreate); 410 void SetVolume(const wxString& volume); 411 %wxchkver_3_0_0 bool ShouldFollowLink() const; 412 %wxchkver_3_0_0 static wxString StripExtension(const wxString& fullname); 413 bool Touch(); 414 %wxchkver_3_0_0 bool operator!=(const wxFileName& filename) const; 415 %wxchkver_3_0_0 bool operator!=(const wxString& filename) const; 416 bool operator==(const wxFileName& filename) const; 417 %wxchkver_3_0_0 bool operator==(const wxString& filename) const; 418 wxFileName& operator=(const wxFileName& filename); 419 %wxchkver_3_0_0 wxFileName& operator=(const wxString& filename); 420 !%wxchkver_3_0_0 && %wxchkver_2_8 && (wxUSE_FILE||wxUSE_FFILE) static wxString CreateTempFileName(const wxString& prefix); 421 !%wxchkver_3_0_0 && %wxchkver_2_8 static wxString GetHumanReadableSize(const wxULongLong &sz, const wxString &nullsize = "Not available", int precision = 1); 422 !%wxchkver_3_0_0 && %wxchkver_2_8 wxString GetHumanReadableSize(const wxString &nullsize = "Not available", int precision = 1) const; 423 !%wxchkver_3_0_0 bool Rmdir(); 424 !%wxchkver_3_0_0 static bool IsPathSeparator(int ch, wxPathFormat format = wxPATH_NATIVE); 425 !%wxchkver_3_0_0 static bool Rmdir(const wxString& dir); 426 !%wxchkver_3_0_0 static wxFileName DirName(const wxString& dir); 427 !%wxchkver_3_0_0 static wxFileName FileName(const wxString& file); 428 !%wxchkver_3_0_0 void InsertDir(int before, const wxString& dir); 429 !%wxchkver_3_0_0 void RemoveDir(int pos); 430 %rename SplitPathVolume static void SplitPath(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); // %override [wxString volume, wxString path, wxString name, wxString ext] wxFileName::SplitPathVolume(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); 431 %wxchkver_3_0_0 static wxString GetHumanReadableSize(const wxULongLong& bytes, const wxString& nullsize = "Not available", int precision = 1, wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL); // %override to remote _() as it's not handled by wxlua 432 %wxchkver_3_0_0 wxString GetHumanReadableSize(const wxString& failmsg = "Not available", int precision = 1, wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL) const; // %override to remote _() as it's not handled by wxlua 433 // bool MacSetDefaultTypeAndCreator(); 434 // static bool MacFindDefaultTypeAndCreator(const wxString& ext, wxUint32* type, wxUint32* creator); 435 bool GetTimes() const; // %override [bool, wxDateTime dtAccess, wxDateTime dtMod, wxDateTime dtCreate] wxFileName::GetTimes(); 436 static void SplitPath(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); // %override [wxString path, wxString name, wxString ext] wxFileName::SplitPath(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); 437 static void SplitVolume(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); // %override [wxString volume, wxString path] wxFileName::SplitVolume(const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE); 438 }; 439 440 #endif //wxLUA_USE_wxFileName 441 442 // --------------------------------------------------------------------------- 443 // wxFile 444 445 #if wxLUA_USE_wxFile && wxUSE_FILE 446 447 #include "wx/file.h" 448 449 enum wxFile::OpenMode 450 { 451 read, 452 write, 453 read_write, 454 write_append, 455 write_excl 456 }; 457 458 enum wxFile::dummy 459 { 460 fd_invalid, // = -1 461 fd_stdin, 462 fd_stdout, 463 fd_stderr 464 }; 465 466 enum wxSeekMode 467 { 468 wxFromStart, 469 wxFromCurrent, 470 wxFromEnd, 471 wxInvalidOffset 472 }; 473 474 enum wxFileKind 475 { 476 wxFILE_KIND_UNKNOWN, 477 wxFILE_KIND_DISK, 478 wxFILE_KIND_TERMINAL, 479 wxFILE_KIND_PIPE 480 }; 481 482 enum wxPosixPermissions 483 { 484 wxS_IRUSR, 485 wxS_IWUSR, 486 wxS_IXUSR, 487 wxS_IRGRP, 488 wxS_IWGRP, 489 wxS_IXGRP, 490 wxS_IROTH, 491 wxS_IWOTH, 492 wxS_IXOTH, 493 494 wxPOSIX_USER_READ, 495 wxPOSIX_USER_WRITE, 496 wxPOSIX_USER_EXECUTE, 497 wxPOSIX_GROUP_READ, 498 wxPOSIX_GROUP_WRITE, 499 wxPOSIX_GROUP_EXECUTE, 500 wxPOSIX_OTHERS_READ, 501 wxPOSIX_OTHERS_WRITE, 502 wxPOSIX_OTHERS_EXECUTE, 503 504 wxS_DEFAULT, 505 wxS_DIR_DEFAULT 506 }; 507 508 class %delete wxFile 509 { 510 wxFile(); 511 wxFile(const wxString& filename, wxFile::OpenMode mode = wxFile::read); 512 513 static bool Access(const wxString& name, wxFile::OpenMode mode); 514 void Attach(int fd); 515 void Close(); 516 bool Create(const wxString& filename, bool overwrite = false, int access = wxS_DEFAULT); 517 void Detach(); 518 int fd() const; 519 bool Eof() const; 520 static bool Exists(const wxString& name); 521 bool Flush(); 522 wxFileKind GetKind() const; 523 bool IsOpened() const; 524 wxFileOffset Length() const; 525 bool Open(const wxString& filename, wxFile::OpenMode mode = wxFile::read); 526 527 // %override [size_t count, Lua string] wxFile::Read(unsigned int count); 528 // C++ Func: size_t Read(void* buffer, unsigned int count); 529 size_t Read(unsigned int count); 530 531 wxFileOffset Seek(wxFileOffset offset, wxSeekMode mode = wxFromStart); 532 wxFileOffset SeekEnd(wxFileOffset offset = 0); 533 wxFileOffset Tell() const; 534 535 // %override size_t wxFile::Write(Lua string, unsigned int count); 536 // C++ Func: size_t Write(const void* buffer, unsigned int count); 537 size_t Write(const wxString& buffer, unsigned int count); 538 539 size_t Write(const wxString &str); //, const wxMBConv& conv = wxConvUTF8); 540 }; 541 542 // --------------------------------------------------------------------------- 543 // wxTempFile 544 545 #include "wx/file.h" 546 547 class %delete wxTempFile 548 { 549 wxTempFile(); 550 // associates the temp file with the file to be replaced and opens it 551 wxTempFile(const wxString& strName); 552 553 // open the temp file (strName is the name of file to be replaced); 554 bool Open(const wxString& strName); 555 556 // is the file opened? 557 bool IsOpened() const; 558 // get current file length 559 wxFileOffset Length() const; 560 // move ptr ofs bytes related to start/current offset/end of file 561 wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart); 562 // get current offset 563 wxFileOffset Tell() const; 564 565 // I/O (both functions return true on success, false on failure); 566 //bool Write(const void *p, size_t n); 567 bool Write(const wxString& str); //, const wxMBConv& conv = wxConvUTF8); 568 569 // validate changes and delete the old file of name m_strName 570 bool Commit(); 571 // discard changes 572 void Discard(); 573 }; 574 575 #endif //wxLUA_USE_wxFile && wxUSE_FILE 576 577 // --------------------------------------------------------------------------- 578 // wxDir 579 580 #if wxLUA_USE_wxDir 581 582 #include "wx/dir.h" 583 584 #define wxDIR_FILES 585 #define wxDIR_DIRS 586 #define wxDIR_HIDDEN 587 #define wxDIR_DOTDOT 588 %wxchkver_2_9_5 #define wxDIR_NO_FOLLOW 589 #define wxDIR_DEFAULT 590 591 592 #if %wxchkver_2_9_4 593 594 // these constants are possible return value of wxDirTraverser::OnDir() 595 enum wxDirTraverseResult 596 { 597 wxDIR_IGNORE, // ignore this directory but continue with others 598 wxDIR_STOP, // stop traversing 599 wxDIR_CONTINUE // continue into this directory 600 }; 601 602 #endif //%wxchkver_2_9_4 603 604 605 class %delete wxDir 606 { 607 wxDir(); 608 wxDir(const wxString& dir); 609 %wxchkver_3_0_0 void Close(); 610 static bool Exists(const wxString& dir); 611 %wxchkver_2_8 static wxString FindFirst(const wxString& dirname, const wxString& filespec, int flags = wxDIR_DEFAULT); 612 wxString GetName() const; 613 %wxchkver_3_0_0 wxString GetNameWithSep() const; 614 bool HasFiles(const wxString& filespec = ""); 615 bool HasSubDirs(const wxString& dirspec = ""); 616 bool IsOpened() const; 617 %wxchkver_3_0_0 static bool Make(const wxString &dir, int perm = wxS_DIR_DEFAULT, int flags = 0); 618 bool Open(const wxString& dir); 619 %wxchkver_3_0_0 static bool Remove(const wxString &dir, int flags = 0); 620 // size_t Traverse(wxDirTraverser& sink, const wxString& filespec = wxEmptyString, int flags = wxDIR_DEFAULT); 621 %wxchkver_2_8 static wxULongLong GetTotalSize(const wxString &dir); // %override ..., wxArrayString *filesSkipped = NULL) 622 bool GetFirst(const wxString& filespec = "", int flags = wxDIR_DEFAULT) const; // %override return [bool, string filename] 623 bool GetNext() const; // %override return [bool, string filename] 624 static unsigned int GetAllFiles(const wxString& dirname, const wxString& filespec = "", int flags = wxDIR_DEFAULT); // %override return [unsigned int, Lua string table] 625 }; 626 627 #endif //wxLUA_USE_wxDir 628 629 // --------------------------------------------------------------------------- 630 // wxFileTypeInfo 631 632 #include "wx/mimetype.h" 633 634 class %delete wxFileTypeInfo 635 { 636 // the ... parameters form a NULL terminated list of extensions 637 //wxFileTypeInfo(const wxChar *mimeType, const wxChar *openCmd, const wxChar *printCmd, const wxChar *desc, ...); 638 // the array elements correspond to the parameters of the ctor above in the same order 639 wxFileTypeInfo(const wxArrayString& sArray); 640 641 // invalid item - use this to terminate the array passed to wxMimeTypesManager::AddFallbacks 642 wxFileTypeInfo(); 643 644 bool IsValid() const; 645 646 void SetIcon(const wxString& iconFile, int iconIndex = 0); 647 void SetShortDesc(const wxString& shortDesc); 648 649 wxString GetMimeType() const; 650 wxString GetOpenCommand() const; 651 wxString GetPrintCommand() const; 652 wxString GetShortDesc() const; 653 wxString GetDescription() const; 654 wxArrayString GetExtensions() const; 655 size_t GetExtensionsCount() const; 656 wxString GetIconFile() const; 657 int GetIconIndex() const; 658 }; 659 660 // --------------------------------------------------------------------------- 661 // wxIconLocation 662 663 #include "wx/iconloc.h" 664 665 class %delete wxIconLocation 666 { 667 // ctor takes the name of the file where the icon is 668 !%msw wxIconLocation(const wxString& filename = ""); 669 %msw wxIconLocation(const wxString& file = "", int num = 0); 670 671 // returns true if this object is valid/initialized 672 bool IsOk() const; 673 674 // set/get the icon file name 675 void SetFileName(const wxString& filename); 676 const wxString& GetFileName() const; 677 678 // set/get the icon index 679 %msw void SetIndex(int num); 680 %msw int GetIndex() const; 681 }; 682 683 // --------------------------------------------------------------------------- 684 // wxFileType::MessageParameters 685 686 class %delete wxFileType::MessageParameters 687 { 688 //wxFileType::MessageParameters(); 689 wxFileType::MessageParameters(const wxString& filename, const wxString& mimetype = ""); 690 691 // accessors (called by GetOpenCommand); 692 wxString GetFileName() const; 693 wxString GetMimeType() const; 694 695 // override this function in derived class 696 virtual wxString GetParamValue(const wxString& name) const; 697 }; 698 699 // --------------------------------------------------------------------------- 700 // wxFileType 701 702 class %delete wxFileType 703 { 704 wxFileType(const wxFileTypeInfo& ftInfo); 705 706 // accessors: all of them return true if the corresponding information 707 // could be retrieved/found, false otherwise (and in this case all [out] parameters are unchanged); 708 709 // return the MIME type for this file type 710 //bool GetMimeType(wxString *mimeType) const; 711 bool GetMimeTypes(wxArrayString& mimeTypes) const; 712 713 bool GetExtensions(wxArrayString& extensions); 714 715 // get the icon corresponding to this file type and of the given size 716 bool GetIcon(wxIconLocation *iconloc) const; 717 //bool GetIcon(wxIconLocation *iconloc, const wxFileType::MessageParameters& params) const; 718 719 // get a brief file type description ("*.txt" => "text document"); 720 // %override [bool Lua string] wxFileType::GetDescription() const; 721 // C++ Func: bool GetDescription(wxString *desc) const; 722 bool GetDescription() const; 723 724 // get the command to be used to open/print the given file. 725 //bool GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters& params) const; 726 // a simpler to use version of GetOpenCommand() -- it only takes the 727 // filename and returns an empty string on failure 728 wxString GetOpenCommand(const wxString& filename) const; 729 730 // get the command to print the file of given type 731 // %override [bool Lua string] wxFileType::GetPrintCommand(const wxFileType::MessageParameters& params) const; 732 // C++ Func: bool GetPrintCommand(wxString *printCmd, const wxFileType::MessageParameters& params) const; 733 bool GetPrintCommand(const wxFileType::MessageParameters& params) const; 734 735 // return the number of commands defined for this file type, 0 if none 736 size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, const wxFileType::MessageParameters& params) const; 737 738 // set an arbitrary command, ask confirmation if it already exists and overwriteprompt is true 739 bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = true); 740 741 bool SetDefaultIcon(const wxString& cmd = "", int index = 0); 742 743 // remove the association for this filetype from the system MIME database: 744 // notice that it will only work if the association is defined in the user 745 // file/registry part, we will never modify the system-wide settings 746 bool Unassociate(); 747 748 // expand a string in the format of GetOpenCommand (which may contain 749 // '%s' and '%t' format specificators for the file name and mime type 750 // and %{param} constructions). 751 static wxString ExpandCommand(const wxString& command, const wxFileType::MessageParameters& params); 752 }; 753 754 // --------------------------------------------------------------------------- 755 // wxMimeTypesManager 756 757 class wxMimeTypesManager 758 { 759 #define_pointer wxTheMimeTypesManager 760 761 // wxMimeTypesManager(); - Use pointer wxTheMimeTypesManager 762 763 // check if the given MIME type is the same as the other one: the 764 // second argument may contain wildcards ('*'), but not the first. If 765 // the types are equal or if the mimeType matches wildcard the function 766 // returns true, otherwise it returns false 767 static bool IsOfType(const wxString& mimeType, const wxString& wildcard); 768 769 // NB: the following 2 functions are for Unix only and don't do anything elsewhere 770 771 // loads data from standard files according to the mailcap styles 772 // specified: this is a bitwise OR of wxMailcapStyle values 773 // 774 // use the extraDir parameter if you want to look for files in another 775 // directory 776 void Initialize(int mailcapStyle = wxMAILCAP_ALL, const wxString& extraDir = ""); 777 // and this function clears all the data from the manager 778 void ClearData(); 779 780 // Database lookup: all functions return a pointer to wxFileType object 781 // whose methods may be used to query it for the information you're 782 // interested in. If the return value is !NULL, caller is responsible for 783 // deleting it. 784 // get file type from file extension 785 wxFileType *GetFileTypeFromExtension(const wxString& ext); 786 // get file type from MIME type (in format <category>/<format>); 787 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); 788 789 !%wxchkver_2_9 bool ReadMailcap(const wxString& filename, bool fallback = false); 790 // read in additional file in mime.types format 791 !%wxchkver_2_9 bool ReadMimeTypes(const wxString& filename); 792 793 // enumerate all known MIME types returns the number of retrieved file types 794 size_t EnumAllFileTypes(wxArrayString& mimetypes); 795 796 // The filetypes array should be terminated by either NULL entry or an 797 // invalid wxFileTypeInfo (i.e. the one created with default ctor); 798 //void AddFallbacks(const wxFileTypeInfo *filetypes); 799 void AddFallback(const wxFileTypeInfo& ft); 800 801 // create a new association using the fields of wxFileTypeInfo (at least 802 // the MIME type and the extension should be set); 803 // if the other fields are empty, the existing values should be left alone 804 wxFileType *Associate(const wxFileTypeInfo& ftInfo); 805 806 // undo Associate(); 807 bool Unassociate(wxFileType *ft); 808 }; 809 810 // --------------------------------------------------------------------------- 811 // wxStreamBase 812 813 #if wxUSE_STREAMS 814 815 #include "wx/stream.h" 816 #include "wx/txtstrm.h" 817 818 enum wxEOL 819 { 820 wxEOL_NATIVE, 821 wxEOL_UNIX, 822 wxEOL_MAC, 823 wxEOL_DOS 824 }; 825 826 enum wxStreamError 827 { 828 wxSTREAM_NO_ERROR, 829 wxSTREAM_EOF, 830 wxSTREAM_WRITE_ERROR, 831 wxSTREAM_READ_ERROR 832 }; 833 834 // --------------------------------------------------------------------------- 835 // wxStreamBase 836 837 class wxStreamBase 838 { 839 // wxStreamBase() this is only a base class 840 841 %wxchkver_2_6 wxFileOffset GetLength() const; 842 wxStreamError GetLastError() const; 843 size_t GetSize() const; 844 bool IsOk() const; 845 bool IsSeekable() const; 846 void Reset(); 847 }; 848 849 // --------------------------------------------------------------------------- 850 // wxInputStream 851 852 class wxInputStream : public wxStreamBase 853 { 854 // wxInputStream() this is only a base class 855 856 bool CanRead() const; 857 char GetC(); 858 bool Eof(); 859 size_t LastRead() const; 860 char Peek(); 861 862 // %override [Lua string] wxInputStream::Read(size_t size); 863 // C++ Func: wxInputStream& Read(void *buffer, size_t size); 864 wxString Read(size_t size); 865 866 wxInputStream& Read(wxOutputStream& stream_in); 867 wxFileOffset SeekI(wxFileOffset pos, wxSeekMode mode = wxFromStart); 868 wxFileOffset TellI() const; 869 870 // %override size_t wxInputStream::Ungetch(Lua string, size_t size); 871 // C++ Func: size_t Ungetch(const char* buffer, size_t size); 872 %override_name wxLua_wxInputStream_UngetchString size_t Ungetch(const wxString& str, size_t size); 873 874 bool Ungetch(char c); 875 }; 876 877 // --------------------------------------------------------------------------- 878 // wxOutputStream 879 880 class wxOutputStream : public wxStreamBase 881 { 882 // wxOutputStream() this is only a base class 883 884 bool Close(); 885 size_t LastWrite() const; 886 void PutC(char c); 887 wxFileOffset SeekO(wxFileOffset pos, wxSeekMode mode = wxFromStart); 888 wxFileOffset TellO() const; 889 890 // %override wxOutputStream& wxOutputStream::Write(Lua string, size_t size); 891 // C++ Func: wxOutputStream& Write(const void *buffer, size_t size); 892 wxOutputStream& Write(const wxString& buffer, size_t size); 893 894 wxOutputStream& Write(wxInputStream& stream_in); 895 }; 896 897 // --------------------------------------------------------------------------- 898 // wxFileInputStream 899 900 #include "wx/wfstream.h" 901 902 class %delete wxFileInputStream : public wxInputStream 903 { 904 wxFileInputStream(const wxString& fileName); 905 wxFileInputStream(wxFile& file); 906 //wxFileInputStream(int fd); 907 908 bool Ok() const; 909 }; 910 911 // --------------------------------------------------------------------------- 912 // wxFileOutputStream 913 914 class %delete wxFileOutputStream : public wxOutputStream 915 { 916 wxFileOutputStream(const wxString& fileName); 917 wxFileOutputStream(wxFile& file); 918 //wxFileOutputStream(int fd); 919 920 bool Ok() const; 921 }; 922 923 // --------------------------------------------------------------------------- 924 // wxMemoryInputStream 925 926 #include "wx/mstream.h" 927 928 class %delete wxMemoryInputStream : public wxInputStream 929 { 930 wxMemoryInputStream(const char *data, size_t length); 931 //wxMemoryInputStream(const wxMemoryOutputStream& stream); 932 933 }; 934 935 // --------------------------------------------------------------------------- 936 // wxMemoryOutputStream 937 938 //%include "wx/mstream.h" 939 940 //class %delete wxMemoryInputStream : public wxInputStream 941 //{ 942 // wxMemoryOutputStream(void *data, size_t length); 943 // wxMemoryInputStream(const wxMemoryOutputStream& stream); 944 //}; 945 946 // --------------------------------------------------------------------------- 947 // wxDataInputStream 948 949 #include "wx/datstrm.h" 950 951 class %delete wxDataInputStream 952 { 953 // wxDataInputStream(wxInputStream& s, const wxMBConv& conv = wxConvAuto()); 954 wxDataInputStream(wxInputStream& s); 955 956 bool IsOk(); 957 958 //#if wxHAS_INT64 959 // wxUint64 Read64(); 960 //#endif 961 //#if wxUSE_LONGLONG 962 // wxLongLong ReadLL(); 963 //#endif 964 wxUint32 Read32(); 965 wxUint16 Read16(); 966 wxUint8 Read8(); 967 double ReadDouble(); 968 wxString ReadString(); 969 970 //#if wxHAS_INT64 971 // void Read64(wxUint64 *buffer, size_t size); 972 // void Read64(wxInt64 *buffer, size_t size); 973 //#endif 974 //#if defined(wxLongLong_t) && wxUSE_LONGLONG 975 // void Read64(wxULongLong *buffer, size_t size); 976 // void Read64(wxLongLong *buffer, size_t size); 977 //#endif 978 //#if wxUSE_LONGLONG 979 // void ReadLL(wxULongLong *buffer, size_t size); 980 // void ReadLL(wxLongLong *buffer, size_t size); 981 //#endif 982 //void Read32(wxUint32 *buffer, size_t size); 983 //void Read16(wxUint16 *buffer, size_t size); 984 //void Read8(wxUint8 *buffer, size_t size); 985 //void ReadDouble(double *buffer, size_t size); 986 987 void BigEndianOrdered(bool be_order); 988 }; 989 990 // --------------------------------------------------------------------------- 991 // wxText{Input,Output}Stream 992 993 #include "wx/txtstrm.h" 994 995 class %delete wxTextInputStream 996 { 997 wxTextInputStream(wxInputStream& s); 998 999 const wxInputStream& GetInputStream(); 1000 1001 // base may be between 2 and 36, inclusive, or the special 0 (= C format) 1002 %wxchkver_3_1_0 wxUint64 Read64(int base = 10); 1003 wxUint32 Read32(int base = 10); 1004 wxUint16 Read16(int base = 10); 1005 wxUint8 Read8(int base = 10); 1006 %wxchkver_3_1_0 wxInt64 Read64S(int base = 10); 1007 wxInt32 Read32S(int base = 10); 1008 wxInt16 Read16S(int base = 10); 1009 wxInt8 Read8S(int base = 10); 1010 double ReadDouble(); 1011 wxString ReadLine(); 1012 wxString ReadWord(); 1013 wxChar GetChar(); 1014 1015 wxString GetStringSeparators() const; 1016 void SetStringSeparators(const wxString &c); 1017 }; 1018 1019 class %delete wxTextOutputStream 1020 { 1021 wxTextOutputStream(wxOutputStream& s); 1022 1023 const wxOutputStream& GetOutputStream(); 1024 1025 void SetMode( wxEOL mode = wxEOL_NATIVE ); 1026 wxEOL GetMode(); 1027 1028 %wxchkver_3_1_0 void Write64(wxUint64 i); 1029 void Write32(wxUint32 i); 1030 void Write16(wxUint16 i); 1031 void Write8(wxUint8 i); 1032 virtual void WriteDouble(double d); 1033 virtual void WriteString(const wxString& string); 1034 1035 wxTextOutputStream& PutChar(wxChar c); 1036 1037 void Flush(); 1038 }; 1039 1040 // --------------------------------------------------------------------------- 1041 // wxDataOutputStream 1042 1043 #include "wx/datstrm.h" 1044 1045 class %delete wxDataOutputStream 1046 { 1047 // wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv = wxConvAuto()); 1048 wxDataOutputStream(wxOutputStream& s); 1049 1050 bool IsOk(); 1051 1052 //#if wxHAS_INT64 1053 // void Write64(wxUint64 i); 1054 // void Write64(wxInt64 i); 1055 //#endif 1056 //#if wxUSE_LONGLONG 1057 // void WriteLL(const wxLongLong &ll); 1058 // void WriteLL(const wxULongLong &ll); 1059 //#endif 1060 void Write32(wxUint32 i); 1061 void Write16(wxUint16 i); 1062 void Write8(wxUint8 i); 1063 void WriteDouble(double d); 1064 void WriteString(const wxString& string); 1065 1066 //#if wxHAS_INT64 1067 // void Write64(const wxUint64 *buffer, size_t size); 1068 // void Write64(const wxInt64 *buffer, size_t size); 1069 //#endif 1070 //#if defined(wxLongLong_t) && wxUSE_LONGLONG 1071 // void Write64(const wxULongLong *buffer, size_t size); 1072 // void Write64(const wxLongLong *buffer, size_t size); 1073 //#endif 1074 //#if wxUSE_LONGLONG 1075 // void WriteLL(const wxULongLong *buffer, size_t size); 1076 // void WriteLL(const wxLongLong *buffer, size_t size); 1077 //#endif 1078 //void Write32(const wxUint32 *buffer, size_t size); 1079 //void Write16(const wxUint16 *buffer, size_t size); 1080 //void Write8(const wxUint8 *buffer, size_t size); 1081 //void WriteDouble(const double *buffer, size_t size); 1082 1083 void BigEndianOrdered(bool be_order); 1084 }; 1085 1086 1087 1088 // --------------------------------------------------------------------------- 1089 // --------------------------------------------------------------------------- 1090 // wxFSFile 1091 1092 #if wxUSE_FILESYSTEM // already has wxUSE_STREAMS 1093 1094 #include "wx/filesys.h" 1095 1096 1097 class %delete wxFSFile : public wxObject 1098 { 1099 wxFSFile(%ungc wxInputStream *stream, const wxString& loc, const wxString& mimetype, const wxString& anchor, wxDateTime modif); 1100 1101 // returns stream. This doesn't give away ownership of the stream object. 1102 wxInputStream *GetStream() const; 1103 // gives away the ownership of the current stream. 1104 %gc wxInputStream *DetachStream(); 1105 // deletes the current stream and takes ownership of another. 1106 void SetStream(%ungc wxInputStream *stream); 1107 1108 // returns file's mime type 1109 wxString GetMimeType() const; 1110 // returns the original location (aka filename) of the file 1111 wxString GetLocation() const; 1112 wxString GetAnchor() const; 1113 wxDateTime GetModificationTime() const; 1114 }; 1115 1116 1117 // --------------------------------------------------------------------------- 1118 // wxFileSystemHandler 1119 1120 class %delete wxFileSystemHandler : public wxObject 1121 { 1122 // wxFileSystemHandler(); // no constructor since it has abstract functions 1123 1124 // returns true if this handler is able to open given location 1125 virtual bool CanOpen(const wxString& location); //= 0; 1126 1127 // opens given file and returns pointer to input stream. 1128 // Returns NULL if opening failed. 1129 // The location is always absolute path. 1130 virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location); //= 0; 1131 1132 // Finds first/next file that matches spec wildcard. flags can be wxDIR for restricting 1133 // the query to directories or wxFILE for files only or 0 for either. 1134 // Returns filename or empty string if no more matching file exists 1135 virtual wxString FindFirst(const wxString& spec, int flags = 0); 1136 virtual wxString FindNext(); 1137 }; 1138 1139 1140 // --------------------------------------------------------------------------- 1141 // wxLocalFSHandler 1142 1143 1144 class %delete wxLocalFSHandler : public wxFileSystemHandler 1145 { 1146 wxLocalFSHandler(); 1147 1148 // wxLocalFSHandler will prefix all filenames with 'root' before accessing 1149 // files on disk. This effectively makes 'root' the top-level directory 1150 // and prevents access to files outside this directory. 1151 // (This is similar to Unix command 'chroot'.); 1152 static void Chroot(const wxString& root); 1153 }; 1154 1155 1156 // --------------------------------------------------------------------------- 1157 // wxFileSystem 1158 1159 enum 1160 { 1161 wxFS_READ, // Open for reading 1162 wxFS_SEEKABLE // Returned stream will be seekable 1163 }; 1164 1165 class %delete wxFileSystem : public wxObject 1166 { 1167 wxFileSystem(); 1168 1169 // sets the current location. Every call to OpenFile is 1170 // relative to this location. 1171 // NOTE !! 1172 // unless is_dir = true 'location' is *not* the directory but 1173 // file contained in this directory 1174 // (so ChangePathTo("dir/subdir/xh.htm") sets m_Path to "dir/subdir/"); 1175 void ChangePathTo(const wxString& location, bool is_dir = false); 1176 1177 wxString GetPath() const; 1178 1179 // opens given file and returns pointer to input stream. 1180 // Returns NULL if opening failed. 1181 // It first tries to open the file in relative scope 1182 // (based on ChangePathTo()'s value) and then as an absolute 1183 // path. 1184 %gc wxFSFile* OpenFile(const wxString& location, int flags = wxFS_READ); 1185 1186 // Finds first/next file that matches spec wildcard. flags can be wxDIR for restricting 1187 // the query to directories or wxFILE for files only or 0 for either. 1188 // Returns filename or empty string if no more matching file exists 1189 wxString FindFirst(const wxString& spec, int flags = 0); 1190 wxString FindNext(); 1191 1192 // find a file in a list of directories, returns false if not found 1193 // %override [bool, Lua string full_path] bool FindFileInPath(const wxString& path, const wxString& file); 1194 // C++ Func: bool FindFileInPath(wxString *pStr, const wxChar *path, const wxChar *file); 1195 bool FindFileInPath(const wxString& path, const wxString& file); 1196 1197 // Adds FS handler. 1198 // In fact, this class is only front-end to the FS handlers :-); 1199 static void AddHandler(%ungc wxFileSystemHandler *handler); 1200 1201 // Removes FS handler 1202 static %gc wxFileSystemHandler* RemoveHandler(wxFileSystemHandler *handler); 1203 1204 // Returns true if there is a handler which can open the given location. 1205 static bool HasHandlerForPath(const wxString& location); 1206 1207 // remove all items from the m_Handlers list 1208 static void CleanUpHandlers(); 1209 1210 // Returns the native path for a file URL 1211 static wxFileName URLToFileName(const wxString& url); 1212 1213 // Returns the file URL for a native path 1214 static wxString FileNameToURL(const wxFileName& filename); 1215 }; 1216 1217 1218 // --------------------------------------------------------------------------- 1219 // wxArchiveFSHandler 1220 1221 #include "wx/fs_arc.h" 1222 1223 class %delete wxArchiveFSHandler : public wxFileSystemHandler 1224 { 1225 wxArchiveFSHandler(); 1226 }; 1227 1228 // --------------------------------------------------------------------------- 1229 // wxZipFSHandler - is just a typedef to wxArchiveFSHandler 1230 1231 //%include "wx/fs_zip.h" 1232 1233 //#if wxUSE_FS_ZIP 1234 // typedef wxArchiveFSHandler wxZipFSHandler; 1235 //#endif 1236 1237 // --------------------------------------------------------------------------- 1238 // wxFilterFSHandler 1239 1240 #include "wx/fs_filter.h" 1241 1242 class %delete wxFilterFSHandler : public wxFileSystemHandler 1243 { 1244 wxFilterFSHandler(); 1245 }; 1246 1247 // --------------------------------------------------------------------------- 1248 // wxInternetFSHandler 1249 1250 #if wxUSE_FS_INET && wxUSE_SOCKETS // already has wxUSE_STREAMS && wxUSE_FILESYSTEM 1251 #include "wx/fs_inet.h" 1252 1253 class %delete wxInternetFSHandler : public wxFileSystemHandler 1254 { 1255 wxInternetFSHandler(); 1256 }; 1257 #endif //wxUSE_FS_INET && wxUSE_SOCKETS 1258 1259 // --------------------------------------------------------------------------- 1260 // wxMemoryFSHandler - See wxcore_core.i for this since it requires wxImage & wxBitmap. 1261 1262 1263 #endif // wxUSE_FILESYSTEM 1264 1265 1266 #endif // wxUSE_STREAMS 1267 1268 // --------------------------------------------------------------------------- 1269 // wxFileSystemWatcher classes 1270 1271 #if wxUSE_FSWATCHER && %wxchkver_2_9_4 1272 1273 #include "wx/fswatcher.h" 1274 1275 enum 1276 { 1277 wxFSW_EVENT_CREATE, // = 0x01, 1278 wxFSW_EVENT_DELETE, // = 0x02, 1279 wxFSW_EVENT_RENAME, // = 0x04, 1280 wxFSW_EVENT_MODIFY, // = 0x08, 1281 wxFSW_EVENT_ACCESS, // = 0x10, 1282 wxFSW_EVENT_ATTRIB, // = 0x20, // Currently this is wxGTK-only 1283 1284 // error events 1285 wxFSW_EVENT_WARNING, // = 0x40, 1286 wxFSW_EVENT_ERROR, // = 0x80, 1287 wxFSW_EVENT_ALL, // = wxFSW_EVENT_CREATE | wxFSW_EVENT_DELETE | 1288 // wxFSW_EVENT_RENAME | wxFSW_EVENT_MODIFY | 1289 // wxFSW_EVENT_ACCESS | wxFSW_EVENT_ATTRIB | 1290 // wxFSW_EVENT_WARNING | wxFSW_EVENT_ERROR 1291 #if defined(wxHAS_INOTIFY) || defined(wxHAVE_FSEVENTS_FILE_NOTIFICATIONS) 1292 wxFSW_EVENT_UNMOUNT, // = 0x2000 1293 #endif 1294 }; 1295 1296 // Type of the path watched, used only internally for now. 1297 enum wxFSWPathType 1298 { 1299 wxFSWPath_None, // Invalid value for an initialized watch. 1300 wxFSWPath_File, // Plain file. 1301 wxFSWPath_Dir, // Watch a directory and the files in it. 1302 wxFSWPath_Tree // Watch a directory and all its children recursively. 1303 }; 1304 1305 #if %wxchkver_3_0 1306 // Type of the warning for the events notifying about them. 1307 enum wxFSWWarningType 1308 { 1309 wxFSW_WARNING_NONE, 1310 wxFSW_WARNING_GENERAL, 1311 wxFSW_WARNING_OVERFLOW 1312 }; 1313 #endif // %wxchkver_3_0 1314 1315 // --------------------------------------------------------------------------- 1316 // wxFileSystemWatcherEvent 1317 1318 class %delete wxFileSystemWatcherEvent: public wxEvent 1319 { 1320 public: 1321 %wxEventType wxEVT_FSWATCHER // EVT_FSWATCHER(winid, func); 1322 1323 wxFileSystemWatcherEvent(int changeType = 0, int watchid = wxID_ANY); 1324 wxFileSystemWatcherEvent(int changeType, wxFSWWarningType warningType, const wxString& errorMsg = "", int watchid = wxID_ANY); 1325 wxFileSystemWatcherEvent(int changeType, const wxFileName& path, const wxFileName& newPath, int watchid = wxID_ANY); 1326 1327 const wxFileName& GetPath() const; 1328 void SetPath(const wxFileName& path); 1329 const wxFileName& GetNewPath() const; 1330 void SetNewPath(const wxFileName& path); 1331 int GetChangeType() const; 1332 //virtual wxEvent* Clone() const; 1333 //virtual wxEventCategory GetEventCategory() const; 1334 bool IsError() const; 1335 wxString GetErrorDescription() const; 1336 %wxchkver_3_0 wxFSWWarningType GetWarningType() const; 1337 wxString ToString() const; 1338 }; 1339 1340 // --------------------------------------------------------------------------- 1341 // wxFileSystemWatcher 1342 1343 class wxFileSystemWatcher : public wxEvtHandler 1344 { 1345 public: 1346 wxFileSystemWatcher(); 1347 1348 virtual bool Add(const wxFileName& path, int events = wxFSW_EVENT_ALL); 1349 bool AddAny(const wxFileName& path, int events, wxFSWPathType type, const wxString& filespec = ""); 1350 virtual bool AddTree(const wxFileName& path, int events = wxFSW_EVENT_ALL, const wxString& filespec = wxEmptyString); 1351 virtual bool Remove(const wxFileName& path); 1352 virtual bool RemoveTree(const wxFileName& path); 1353 virtual bool RemoveAll(); 1354 int GetWatchedPathsCount() const; 1355 int GetWatchedPaths(wxArrayString* paths) const; 1356 wxEvtHandler* GetOwner() const; 1357 void SetOwner(wxEvtHandler* handler); 1358 }; 1359 1360 #endif // wxUSE_FSWATCHER && %wxchkver_2_9_4 1361