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 NFILEMANAGERGNU_H 00024 #define NFILEMANAGERGNU_H 00025 00026 #include <time.h> 00027 00028 /*----------------------------------------------------------------------------- 00029 File Manager. 00030 -----------------------------------------------------------------------------*/ 00031 namespace nux 00032 { 00033 // File manager. 00034 class NGNUSerialFileReader : public NSerializer 00035 { 00036 public: 00037 NGNUSerialFileReader (t_int InFileDescriptor, LogOutputDevice &InError, t_int InSize); 00038 ~NGNUSerialFileReader(); 00039 00040 virtual bool Precache (t_int PrecacheOffset, t_int PrecacheSize); 00041 virtual t_s64 Seek (t_s64 InPos, NSerializer::SeekPos seekpos); 00042 virtual t_s64 Tell(); 00043 virtual t_s64 GetFileSize(); 00044 virtual bool Close(); 00045 virtual void SerializeFinal (void *V, t_s64 Length); 00046 virtual bool isReader() 00047 { 00048 return true; 00049 } 00050 virtual bool isWriter() 00051 { 00052 return false; 00053 } 00054 00055 protected: 00056 t_int m_FileDescriptor; 00057 LogOutputDevice &m_Error; 00058 t_s64 m_FileSize; 00059 t_s64 m_FilePos; 00060 t_s64 m_BufferBase; 00061 t_int m_BufferCount; 00062 BYTE *m_Buffer; 00063 static const t_int sBufferSize; 00064 }; 00065 00066 class NGNUSerialFileWriter : public NSerializer 00067 { 00068 public: 00069 NGNUSerialFileWriter (t_int InFileDescriptor, LogOutputDevice &InError, t_int InPos); 00070 ~NGNUSerialFileWriter(); 00071 00072 virtual t_s64 Seek (t_s64 InPos, NSerializer::SeekPos seekpos); 00073 virtual t_s64 Tell(); 00074 virtual bool Close(); 00075 virtual void SerializeFinal (void *V, t_s64 Length); 00076 virtual void Flush(); 00077 virtual t_s64 GetFileSize(); 00078 virtual bool isReader() 00079 { 00080 return false; 00081 } 00082 virtual bool isWriter() 00083 { 00084 return true; 00085 } 00086 00087 protected: 00088 void _Flush(); 00089 t_int m_FileDescriptor; 00090 LogOutputDevice &m_Error; 00091 t_s64 m_Pos; 00092 t_int m_BufferCount; 00093 BYTE *m_Buffer; 00094 static const t_int sBufferSize; 00095 NCriticalSection m_CriticalSection; 00096 }; 00097 00098 class NFileManagerGNU : public NFileManagerGeneric 00099 { 00100 NUX_DECLARE_GLOBAL_OBJECT (NFileManagerGNU, GlobalSingletonInitializer); 00101 public: 00102 // Flags is a combination of 00103 // NSerializer::OutputErrorIfFail 00104 // NSerializer::NoOverWrite 00105 // NSerializer::OverWriteReadOnly 00106 // NSerializer::Unbuffered 00107 // NSerializer::Append 00108 // NSerializer::Read 00109 virtual NSerializer *CreateFileReader (const TCHAR *Filename, DWORD Flags, LogOutputDevice &Error = GNullDevice); 00110 virtual NSerializer *CreateFileWriter (const TCHAR *Filename, DWORD Flags, LogOutputDevice &Error = GNullDevice); 00114 t_s64 FileSize (const TCHAR *Filename); 00115 bool FileExist (const TCHAR *Filename); 00116 int Copy (const TCHAR *DestFile, const TCHAR *SrcFile, bool OverWriteExisting, bool OverWriteReadOnly, NFileTransferMonitor *Monitor); 00117 bool Move (const TCHAR *Dest, const TCHAR *Src, bool OverWriteExisting = true, bool OverWriteReadOnly = false, NFileTransferMonitor *Monitor = NULL); 00118 bool Delete (const TCHAR *Filename, bool OverWriteReadOnly = false); 00119 bool IsReadOnly (const TCHAR *Filename); 00120 bool IsDirectory (const TCHAR *DirectoryName); 00121 bool IsHidden (const TCHAR *Filename); 00125 bool GetFileAttribute (const TCHAR *Filename, bool &isDirectory, bool &isReadOnly, bool &isHidden, t_s64 &Size); 00126 bool MakeDirectory (const TCHAR *Path, bool CreateCompletePath = false); 00127 bool DeleteDirectory (const TCHAR *Path, bool DeleteContentFirst = false); 00128 00129 00130 void FindFiles (std::vector<NString>& Result, const TCHAR *Filename, bool Files, bool Directories) {}; 00131 void ListFilesInDirectory (std::vector<NString>& Result, const TCHAR *DirName) {}; 00132 double GetFileAgeSeconds (const TCHAR *Filename) 00133 { 00134 return 0; 00135 }; 00136 time_t GetFileLastModified (const TCHAR *Filename) 00137 { 00138 return 0; 00139 }; 00140 bool SetDefaultDirectory() 00141 { 00142 return false; 00143 }; 00144 NString GetCurrentDirectory() 00145 { 00146 return NString(); 00147 }; 00148 bool GetTimeStamp (const TCHAR *Filename, FileTimeStamp &Timestamp) 00149 { 00150 return false; 00151 }; 00152 }; 00153 00154 00155 } 00156 00157 #endif // NFILEMANAGERGNU_H