home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / h / vd2 / system / filesys.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  5.7 KB  |  171 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    System library component
  3. //    Copyright (C) 1998-2004 Avery Lee, All Rights Reserved.
  4. //
  5. //    Beginning with 1.6.0, the VirtualDub system library is licensed
  6. //    differently than the remainder of VirtualDub.  This particular file is
  7. //    thus licensed as follows (the "zlib" license):
  8. //
  9. //    This software is provided 'as-is', without any express or implied
  10. //    warranty.  In no event will the authors be held liable for any
  11. //    damages arising from the use of this software.
  12. //
  13. //    Permission is granted to anyone to use this software for any purpose,
  14. //    including commercial applications, and to alter it and redistribute it
  15. //    freely, subject to the following restrictions:
  16. //
  17. //    1.    The origin of this software must not be misrepresented; you must
  18. //        not claim that you wrote the original software. If you use this
  19. //        software in a product, an acknowledgment in the product
  20. //        documentation would be appreciated but is not required.
  21. //    2.    Altered source versions must be plainly marked as such, and must
  22. //        not be misrepresented as being the original software.
  23. //    3.    This notice may not be removed or altered from any source
  24. //        distribution.
  25.  
  26. #ifndef f_VD2_SYSTEM_FILESYS_H
  27. #define f_VD2_SYSTEM_FILESYS_H
  28.  
  29. #include <ctype.h>
  30. #include <vector>
  31.  
  32. #include <vd2/system/vdtypes.h>
  33. #include <vd2/system/VDString.h>
  34.  
  35. // VDFileSplitPath returns a pointer to the first character of the filename,
  36. // or the beginning of the string if the path only contains one component.
  37.  
  38. const char *VDFileSplitFirstDir(const char *s);
  39. const wchar_t *VDFileSplitFirstDir(const wchar_t *s);
  40.  
  41. static inline char *VDFileSplitFirstDir(char *s) {
  42.     return const_cast<char *>(VDFileSplitFirstDir(const_cast<const char *>(s)));
  43. }
  44.  
  45. static inline wchar_t *VDFileSplitFirstDir(wchar_t *s) {
  46.     return const_cast<wchar_t *>(VDFileSplitFirstDir(const_cast<const wchar_t *>(s)));
  47. }
  48.  
  49. const char *VDFileSplitPath(const char *);
  50. const wchar_t *VDFileSplitPath(const wchar_t *);
  51.  
  52. static inline char *VDFileSplitPath(char *s) {
  53.     return const_cast<char *>(VDFileSplitPath(const_cast<const char *>(s)));
  54. }
  55.  
  56. static inline wchar_t *VDFileSplitPath(wchar_t *s) {
  57.     return const_cast<wchar_t *>(VDFileSplitPath(const_cast<const wchar_t *>(s)));
  58. }
  59.  
  60. VDString VDFileSplitPathLeft(const VDString&);
  61. VDString VDFileSplitPathRight(const VDString&);
  62. VDStringW VDFileSplitPathLeft(const VDStringW&);
  63. VDStringW VDFileSplitPathRight(const VDStringW&);
  64.  
  65. // VDSplitRoot returns a pointer to the second component of the filename,
  66. // or the beginning of the string if there is no second component.
  67.  
  68. const char *VDFileSplitRoot(const char *);
  69. const wchar_t *VDFileSplitRoot(const wchar_t *);
  70.  
  71. static inline char *VDFileSplitRoot(char *s) {
  72.     return const_cast<char *>(VDFileSplitRoot(const_cast<const char *>(s)));
  73. }
  74.  
  75. static inline wchar_t *VDFileSplitRoot(wchar_t *s) {
  76.     return const_cast<wchar_t *>(VDFileSplitRoot(const_cast<const wchar_t *>(s)));
  77. }
  78.  
  79. VDString VDFileSplitRoot(const VDString&);
  80. VDStringW VDFileSplitRoot(const VDStringW&);
  81.  
  82. // VDSplitExtension returns a pointer to the extension, including the period.
  83. // The ending null terminator is returned if there is no extension.
  84.  
  85. const char *VDFileSplitExt(const char *);
  86. const wchar_t *VDFileSplitExt(const wchar_t *);
  87.  
  88. static inline char *VDFileSplitExt(char *s) {
  89.     return const_cast<char *>(VDFileSplitExt(const_cast<const char *>(s)));
  90. }
  91.  
  92. static inline wchar_t *VDFileSplitExt(wchar_t *s) {
  93.     return const_cast<wchar_t *>(VDFileSplitExt(const_cast<const wchar_t *>(s)));
  94. }
  95.  
  96. VDString VDFileSplitExtLeft(const VDString&);
  97. VDStringW VDFileSplitExtLeft(const VDStringW&);
  98. VDString VDFileSplitExtRight(const VDString&);
  99. VDStringW VDFileSplitExtRight(const VDStringW&);
  100.  
  101. /////////////////////////////////////////////////////////////////////////////
  102.  
  103. /// Perform a case-insensitive wildcard match against a filename; returns
  104. /// true if the pattern matches, false otherwise. '?' matches any single
  105. /// character, and '*' matches zero or more characters.
  106. ///
  107. /// NOTE: This is not guaranteed or intended to perfectly match the
  108. /// underlying OS wildcard mechanism. In particular, we don't try to
  109. /// emulate MSDOS or Windows goofiness.
  110. bool VDFileWildMatch(const char *pattern, const char *path);
  111. bool VDFileWildMatch(const wchar_t *pattern, const wchar_t *path);
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114.  
  115. sint64 VDGetDiskFreeSpace(const wchar_t *path);
  116. void VDCreateDirectory(const wchar_t *path);
  117.  
  118. extern bool (*VDRemoveFile)(const wchar_t *path);
  119.  
  120. bool VDDoesPathExist(const wchar_t *fileName);
  121.  
  122. uint64 VDFileGetLastWriteTime(const wchar_t *path);
  123. VDStringW VDFileGetRootPath(const wchar_t *partialPath);
  124. VDStringW VDGetFullPath(const wchar_t *partialPath);
  125.  
  126. VDStringW VDMakePath(const wchar_t *base, const wchar_t *file);
  127. void VDFileFixDirPath(VDStringW& path);
  128. VDStringW VDGetLocalModulePath();
  129. VDStringW VDGetProgramPath();
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132.  
  133. class VDDirectoryIterator {
  134.     VDDirectoryIterator(const VDDirectoryIterator&);
  135.     VDDirectoryIterator& operator=(VDDirectoryIterator&);
  136. public:
  137.     VDDirectoryIterator(const wchar_t *path);
  138.     ~VDDirectoryIterator();
  139.  
  140.     bool Next();
  141.  
  142.     bool IsDirectory() const {
  143.         return mbDirectory;
  144.     }
  145.  
  146.     const wchar_t *GetName() const {
  147.         return mFilename.c_str();
  148.     }
  149.  
  150.     const VDStringW GetFullPath() const {
  151.         return mBasePath + mFilename;
  152.     }
  153.  
  154.     const sint64 GetSize() const {
  155.         return mFileSize;
  156.     }
  157.  
  158. protected:
  159.     void *mpHandle;
  160.     bool mbSearchComplete;
  161.  
  162.     VDStringW    mSearchPath;
  163.     VDStringW    mBasePath;
  164.  
  165.     VDStringW    mFilename;
  166.     sint64        mFileSize;
  167.     bool        mbDirectory;
  168. };
  169.  
  170. #endif
  171.