nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef NFILEMANAGERGENERIC_H 00024 #define NFILEMANAGERGENERIC_H 00025 00026 namespace nux 00027 { 00028 00029 class NString; 00030 class NFileManagerWindows; 00031 00032 class NFileTransferMonitor 00033 { 00034 public: 00035 NFileTransferMonitor() 00036 { 00037 m_bCancel = false; 00038 } 00039 virtual ~NFileTransferMonitor() {} 00040 void Cancel() 00041 { 00042 m_bCancel = true; 00043 } 00044 virtual bool Progress (float Fraction) = 0; 00045 00046 #ifdef _WIN32 00047 static DWORD CALLBACK CopyProgressRoutine ( 00048 NUX_IN LARGE_INTEGER TotalFileSize, 00049 NUX_IN LARGE_INTEGER TotalBytesTransferred, 00050 NUX_IN LARGE_INTEGER StreamSize, 00051 NUX_IN LARGE_INTEGER StreamBytesTransferred, 00052 NUX_IN DWORD dwStreamNumber, 00053 NUX_IN DWORD dwCallbackReason, 00054 NUX_IN HANDLE hSourceFile, 00055 NUX_IN HANDLE hDestinationFile, 00056 NUX_IN LPVOID lpData 00057 ) 00058 { 00059 NFileTransferMonitor *filetransfer = NUX_STATIC_CAST (NFileTransferMonitor *, lpData); 00060 00061 if (filetransfer) 00062 { 00063 if (filetransfer->Progress (100.0 * double (TotalBytesTransferred.QuadPart) / double (TotalFileSize.QuadPart) ) == false) 00064 { 00065 return PROGRESS_CANCEL; 00066 } 00067 } 00068 00069 return PROGRESS_CONTINUE; 00070 } 00071 00072 //private: 00073 #endif 00074 BOOL m_bCancel; 00075 friend class NFileManagerWindows; 00076 }; 00077 00078 class NFileManager 00079 { 00080 public: 00081 00082 NFileManager() {} 00083 virtual ~NFileManager() {} 00085 struct FileTimeStamp 00086 { 00087 // Time is in UTC 00088 INT Year; /* year */ 00089 INT Month; /* months since January - [0,11] */ 00090 INT Day; /* day of the month - [1,31] */ 00091 INT Hour; /* hours since midnight - [0,23] */ 00092 INT Minute; /* minutes after the hour - [0,59] */ 00093 INT Second; /* seconds after the minute - [0,59]*/ 00094 INT DayOfWeek; /* days since Sunday - [0,6] */ 00095 INT DayOfYear; /* days since January 1 - [0,365] */ 00096 00097 INT GetJulian ( void ) const; 00098 INT GetSecondOfDay ( void ) const; 00099 bool operator == ( FileTimeStamp &Other ) const; 00100 bool operator != ( FileTimeStamp &Other ) const; 00101 bool operator < ( FileTimeStamp &Other ) const; 00102 bool operator > ( FileTimeStamp &Other ) const; 00103 bool operator >= ( FileTimeStamp &Other ) const; 00104 bool operator <= ( FileTimeStamp &Other ) const; 00105 }; 00106 00107 virtual void Init (bool Startup) {} 00108 virtual NSerializer *CreateFileReader ( const TCHAR *Filename, DWORD ReadFlags = 0, LogOutputDevice &Error = GNullDevice ) = 0; 00109 virtual NSerializer *CreateFileWriter ( const TCHAR *Filename, DWORD WriteFlags = 0, LogOutputDevice &Error = GNullDevice ) = 0; 00111 00116 virtual t_s64 FileSize (const TCHAR *Filename) = 0; // Max file size is 16 terabytes minus 64 KB on NTFS. 4 gigabytes on Fat32. 00117 virtual bool FileExist (const TCHAR *Filename) = 0; 00118 virtual int Copy (const TCHAR *Dest, const TCHAR *Src, bool OverWriteExisting = true, bool OverWriteReadOnly = false, NFileTransferMonitor *Progress = NULL) = 0; 00119 virtual bool Move (const TCHAR *Dest, const TCHAR *Src, bool OverWriteExisting = true, bool OverWriteReadOnly = false, NFileTransferMonitor *Monitor = NULL) = 0; 00120 virtual bool Delete (const TCHAR *Filename, bool OverWriteReadOnly = false) = 0; 00121 virtual bool IsReadOnly (const TCHAR *Filename) = 0; 00122 virtual bool IsDirectory (const TCHAR *DirectoryName) = 0; 00123 virtual bool IsHidden (const TCHAR *Filename) = 0; 00124 00125 virtual bool GetFileAttribute (const TCHAR *Filename, bool &isDirectory, bool &IsReadOnly, bool &IsHidden, t_s64 &Size) = 0; 00126 virtual bool MakeDirectory (const TCHAR *Path, bool CreateCompletePath = false) = 0; 00128 00135 virtual bool DeleteDirectory (const TCHAR *Path, bool DeleteContentFirst = false) = 0; 00136 00152 virtual int CreateUniqueFileName (const TCHAR *Filename, const TCHAR *Extension, NString &OutputFilename, unsigned int BaseIndex = 0xffffffff) = 0; 00153 00154 00155 virtual void FindFiles ( std::vector<NString>& FileNames, const TCHAR *Filename, bool Files, bool Directories ) = 0; 00156 virtual void ListFilesInDirectory ( std::vector<NString>& Result, const TCHAR *DirName) = 0; 00157 virtual time_t GetFileLastModified (const TCHAR *Filename) = 0; 00158 virtual double GetFileAgeSeconds (const TCHAR *Filename) = 0; 00159 virtual bool SetDefaultDirectory() = 0; 00160 virtual NString GetCurrentDirectory() = 0; 00161 virtual bool GetTimeStamp ( const TCHAR *Path, FileTimeStamp &Timestamp ) = 0; 00162 00163 00164 protected: 00165 00166 }; 00167 00168 class NFileManagerGeneric : public NFileManager 00169 { 00170 public: 00171 int Copy (const TCHAR *InDestFile, const TCHAR *InSrcFile, bool OverWriteExisting, bool OverWriteReadOnly, NFileTransferMonitor *Monitor); 00172 bool MakeDirectory (const TCHAR *Path, bool CreateCompletePath = false); 00173 bool DeleteDirectory (const TCHAR *Path, bool DeleteContentFirst = false); 00174 bool Move (const TCHAR *Dest, const TCHAR *Src, bool OverWriteExisting = true, bool OverWriteReadOnly = false, NFileTransferMonitor *Monitor = NULL); 00175 int CreateUniqueFileName (const TCHAR *Filename, const TCHAR *Extension, NString &OutputFilename, unsigned int BaseIndex = 0xffffffff); 00176 00177 bool IsDrive (const TCHAR *Path); 00178 }; 00179 00180 } 00181 00182 #endif // NFILEMANAGERGENERIC_H 00183