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 #include "NuxCore.h" 00024 00025 namespace nux 00026 { 00027 00028 // Choose the size so it is a power of 2. Example (size-1)= 11111111. 00029 const t_int NGNUSerialFileReader::sBufferSize = 1024; 00030 00031 NGNUSerialFileReader::NGNUSerialFileReader (t_int InFileDescriptor, LogOutputDevice &InError, t_int InSize) 00032 : m_FileDescriptor (InFileDescriptor) 00033 , m_Error (InError) 00034 , m_FileSize (InSize) 00035 , m_FilePos (0) 00036 , m_BufferBase (0) 00037 , m_BufferCount (0) 00038 { 00039 m_Buffer = new BYTE[sBufferSize]; 00040 } 00041 NGNUSerialFileReader::~NGNUSerialFileReader() 00042 { 00043 NUX_SAFE_DELETE_ARRAY (m_Buffer); 00044 00045 if (m_FileDescriptor) 00046 { 00047 Close(); 00048 } 00049 } 00050 00051 bool NGNUSerialFileReader::Precache (t_int PrecacheOffset, t_int PrecacheSize) 00052 { 00053 // Only pre-cache at current position and avoid work if pre-caching same offset twice. 00054 if ( (m_FilePos == PrecacheOffset) && (!m_BufferBase || !m_BufferCount || m_BufferBase != m_FilePos) ) 00055 { 00056 m_BufferBase = m_FilePos; 00057 // (sBufferSize - 1) contains only '1', i.e 1111111111. 00058 // So (m_FilePos & (sBufferSize-1)) is equal to m_FilePos if m_FilePos <= (sBufferSize-1). 00059 m_BufferCount = Min<t_s64> (Min<t_s64> (PrecacheSize, (t_int) (sBufferSize - (m_FilePos & (sBufferSize - 1) ) ) ), m_FileSize - m_FilePos); 00060 t_s64 Count = 0; 00061 //GTotalBytesReadViaFileManager += m_BufferCount; 00062 Count = read (m_FileDescriptor, m_Buffer, m_BufferCount); 00063 00064 if (Count == 0) 00065 { 00066 m_ErrorCode = 1; 00067 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Precache] Reached end of file while attempting to read %i bytes"), m_BufferCount); 00068 } 00069 00070 if (Count == -1) 00071 { 00072 m_ErrorCode = 1; 00073 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Precache] Read error while attempting to read file: ???") ); 00074 } 00075 } 00076 00077 return TRUE; 00078 } 00079 00080 t_s64 NGNUSerialFileReader::Seek (t_s64 InPos, NSerializer::SeekPos seekpos) 00081 { 00082 nuxAssert (InPos >= 0); 00083 nuxAssert (InPos <= m_FileSize); 00084 00085 Flush(); 00086 // Because we precache our reads, we must perform Seek accordingly. 00087 00088 t_s64 pos = m_FilePos; 00089 t_s64 filepos = 0; 00090 00091 // Set the file pointer to m_FilePos. 00092 filepos = lseek (m_FileDescriptor, pos, SEEK_SET); 00093 00094 if (filepos == -1) 00095 { 00096 m_ErrorCode = 1; 00097 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Seek] Seek to %i has failed."), InPos); 00098 } 00099 00100 // Now the file pointer is current with what we have read so far. 00101 pos = InPos; 00102 filepos = lseek (m_FileDescriptor, pos, (seekpos == SeekStart) ? SEEK_SET : (seekpos == SeekCurrent) ? SEEK_CUR : SEEK_END); 00103 00104 if ( filepos == -1) 00105 { 00106 m_ErrorCode = 1; 00107 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Seek] Seek to %i has failed."), InPos); 00108 } 00109 00110 m_FilePos = filepos; 00111 m_BufferBase = 0; 00112 m_BufferCount = 0; 00113 Precache (m_FilePos, sBufferSize); 00114 return filepos; 00115 } 00116 00117 t_s64 NGNUSerialFileReader::Tell() 00118 { 00119 // Flush(); 00120 // LARGE_INTEGER pos; 00121 // LARGE_INTEGER filepos; 00122 // pos.QuadPart = 0; 00123 // ::SetFilePointerEx(m_FileDescriptor, pos, &filepos, FILE_CURRENT); 00124 // return filepos.QuadPart; 00125 00126 return m_FilePos; 00127 } 00128 00129 t_s64 NGNUSerialFileReader::GetFileSize() 00130 { 00131 return m_FileSize; 00132 } 00133 00134 bool NGNUSerialFileReader::Close() 00135 { 00136 if (m_FileDescriptor) 00137 { 00138 int ret = close (m_FileDescriptor); 00139 00140 if (ret == -1) 00141 { 00142 m_ErrorCode = 1; 00143 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Close] Error while closing file") ); 00144 } 00145 } 00146 00147 m_FileDescriptor = 0; 00148 return !m_ErrorCode; 00149 } 00150 00151 void NGNUSerialFileReader::SerializeFinal (void *Dest, t_s64 Length) 00152 { 00153 nuxAssert (Dest); 00154 00155 while (Length > 0) 00156 { 00157 t_int DataSize = Min<t_s64> (Length, m_BufferBase + m_BufferCount - m_FilePos); 00158 00159 if (DataSize == 0) 00160 { 00161 if (Length >= sBufferSize) 00162 { 00163 t_s64 Count = 0; 00164 //GTotalBytesReadViaFileManager += Length; 00165 Count = read (m_FileDescriptor, Dest, Length); 00166 00167 if (Count == 0) 00168 { 00169 m_ErrorCode = 1; 00170 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Serialize] Reached end of file while attempting to read %i bytes"), Length); 00171 } 00172 00173 if (Count == -1) 00174 { 00175 m_ErrorCode = 1; 00176 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Serialize] Read error while attempting to read file: ???") ); 00177 } 00178 00179 m_FilePos += Length; 00180 m_BufferBase += Length; 00181 return; 00182 } 00183 00184 Precache (m_FilePos, t_s32_max); 00185 DataSize = Min<t_s64> (Length, m_BufferBase + m_BufferCount - m_FilePos); 00186 00187 if (DataSize <= 0) 00188 { 00189 m_ErrorCode = 1; 00190 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("ReadFile beyond EOF %i+%i/%i"), m_FilePos, Length, m_FileSize); 00191 } 00192 00193 if (m_ErrorCode) 00194 return; 00195 } 00196 00197 Memcpy (Dest, m_Buffer + m_FilePos - m_BufferBase, DataSize); 00198 m_FilePos += DataSize; 00199 Length -= DataSize; 00200 Dest = (BYTE *) Dest + DataSize; 00201 } 00202 } 00204 // Choose the size so it is a power of 2. Example (size-1)= 11111111. 00205 const t_int NGNUSerialFileWriter::sBufferSize = 32; 00206 00207 NGNUSerialFileWriter::NGNUSerialFileWriter (t_int InFileDescriptor, LogOutputDevice &InError, t_int InPos) 00208 : m_FileDescriptor (InFileDescriptor) 00209 , m_Error (InError) 00210 , m_BufferCount (0) 00211 { 00212 m_Pos = Tell(); 00213 m_Buffer = new BYTE[sBufferSize]; 00214 } 00215 00216 NGNUSerialFileWriter::~NGNUSerialFileWriter() 00217 { 00218 NUX_SAFE_DELETE_ARRAY (m_Buffer); 00219 00220 if (m_FileDescriptor) 00221 Close(); 00222 00223 m_FileDescriptor = 0; 00224 } 00225 00226 t_s64 NGNUSerialFileWriter::Seek (t_s64 InPos, NSerializer::SeekPos seekpos) 00227 { 00228 NScopeLock Scope (&m_CriticalSection); 00229 nuxAssert (m_FileDescriptor); 00230 00231 if (m_FileDescriptor == 0) 00232 return -1; 00233 00234 _Flush(); 00235 t_s64 pos = InPos; 00236 t_s64 filepos = 0; 00237 filepos = lseek (m_FileDescriptor, pos, (seekpos == SeekStart) ? SEEK_SET : (seekpos == SeekCurrent) ? SEEK_CUR : SEEK_END); 00238 00239 if (filepos == -1) 00240 { 00241 m_ErrorCode = 1; 00242 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileWriter::Seek] Seek to %i has failed."), InPos); 00243 } 00244 00245 m_Pos = filepos; 00246 return filepos; 00247 } 00248 00249 t_s64 NGNUSerialFileWriter::Tell() 00250 { 00251 NScopeLock Scope (&m_CriticalSection); 00252 nuxAssert (m_FileDescriptor); 00253 00254 if (m_FileDescriptor == 0) 00255 return -1; 00256 00257 _Flush(); 00258 t_s64 pos = 0; 00259 t_s64 filepos = 0; 00260 filepos = lseek (m_FileDescriptor, pos, SEEK_CUR); 00261 00262 if (filepos == -1) 00263 { 00264 m_ErrorCode = 1; 00265 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileWriter::Tell] Seek to %i has failed."), pos); 00266 } 00267 00268 return filepos; 00269 } 00270 00271 bool NGNUSerialFileWriter::Close() 00272 { 00273 NScopeLock Scope (&m_CriticalSection); 00274 nuxAssert (m_FileDescriptor); 00275 00276 if (m_FileDescriptor == 0) 00277 return true; 00278 00279 _Flush(); 00280 int ret = close (m_FileDescriptor); 00281 00282 if (ret == -1) 00283 { 00284 m_ErrorCode = 1; 00285 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileWriter::Close] Error while closing file") ); 00286 } 00287 00288 m_FileDescriptor = 0; 00289 return !m_ErrorCode; 00290 } 00291 00292 t_s64 NGNUSerialFileWriter::GetFileSize() 00293 { 00294 NScopeLock Scope (&m_CriticalSection); 00295 nuxAssert (m_FileDescriptor); 00296 00297 if (m_FileDescriptor == 0) 00298 return -1; 00299 00300 struct stat sb; 00301 00302 if (fstat (m_FileDescriptor, &sb) != 0) 00303 { 00304 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileWriter::GetFileSize] Can't get file size.") ); 00305 return -1; 00306 } 00307 00308 return sb.st_size; 00309 } 00310 00311 void NGNUSerialFileWriter::SerializeFinal (void *V, t_s64 Length) 00312 { 00313 // This method is not re-entrant by itself. It relies on m_Buffer and other variables 00314 // that belong to this object. Therefore, it is not thread safe. We add a critical section 00315 // to make it thread safe. 00316 00317 NScopeLock Scope (&m_CriticalSection); 00318 nuxAssert (m_FileDescriptor); 00319 nuxAssert (V); 00320 00321 NUX_RETURN_IF_NULL (m_FileDescriptor); 00322 00323 m_Pos += Length; 00324 t_int FreeSpace; 00325 00326 while (Length > (FreeSpace = sBufferSize - m_BufferCount) ) 00327 { 00328 // m_Buffer is Full. Write it to the file. 00329 Memcpy (m_Buffer + m_BufferCount, V, FreeSpace); 00330 m_BufferCount += FreeSpace; 00331 Length -= FreeSpace; 00332 V = (BYTE *) V + FreeSpace; 00333 _Flush(); 00334 } 00335 00336 if (Length) 00337 { 00338 Memcpy (m_Buffer + m_BufferCount, V, Length); 00339 m_BufferCount += Length; // Count the number of Characters stored in m_Buffer. 00340 } 00341 } 00342 00343 void NGNUSerialFileWriter::Flush() 00344 { 00345 NScopeLock Scope (&m_CriticalSection); 00346 nuxAssert (m_FileDescriptor); 00347 00348 if (m_FileDescriptor == 0) 00349 return; 00350 00351 _Flush(); 00352 } 00353 00354 void NGNUSerialFileWriter::_Flush() 00355 { 00356 //GTotalBytesWrittenViaFileManager += m_BufferCount; 00357 if (m_BufferCount) 00358 { 00359 t_s64 Result = 0; 00360 Result = write (m_FileDescriptor, m_Buffer, m_BufferCount); 00361 00362 if (Result == -1) 00363 { 00364 m_ErrorCode = 1; 00365 m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileWriter::Flush] Write error.") ); 00366 } 00367 } 00368 00369 m_BufferCount = 0; 00370 } 00372 NUX_IMPLEMENT_GLOBAL_OBJECT (NFileManagerGNU); 00373 00374 void NFileManagerGNU::Constructor() 00375 { 00376 } 00377 00378 void NFileManagerGNU::Destructor() 00379 { 00380 } 00381 00382 NSerializer *NFileManagerGNU::CreateFileReader (const TCHAR *Filename, DWORD Flags, LogOutputDevice &Error) 00383 { 00384 t_int FileDesc = open (TCHAR_TO_ANSI (Filename), O_RDONLY); 00385 00386 if (FileDesc == -1) 00387 { 00388 nuxDebugMsg (TEXT ("[NFileManagerGNU::CreateFileReader] Can't create file reade for: %s"), Filename); 00389 00390 if (Flags & NSerializer::OutputErrorIfFail) 00391 { 00392 nuxError (TEXT ("[NFileManagerGNU::CreateFileReader] Can't open file: %s"), Filename); 00393 } 00394 00395 return NULL; 00396 } 00397 00398 struct stat sb; 00399 00400 if (fstat (FileDesc, &sb) != 0) 00401 { 00402 int ret = close (FileDesc); 00403 00404 if (ret == -1) 00405 { 00406 Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NFileManagerGNU::CreateFileReader] Error while closing file descriptor: %s"), Filename); 00407 } 00408 00409 nuxDebugMsg (TEXT ("[NFileManagerGNU::CreateFileReader] Can't get file descriptor: %s"), Filename); 00410 Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NFileManagerGNU::CreateFileReader] Can't get file descriptor: %s"), Filename); 00411 return NULL; 00412 } 00413 00414 return new NGNUSerialFileReader (FileDesc, Error, sb.st_size); 00415 } 00416 00417 NSerializer *NFileManagerGNU::CreateFileWriter (const TCHAR *Filename, 00418 DWORD Flags, 00419 LogOutputDevice &Error) 00420 { 00421 if (FileExist (Filename) && (Flags & NSerializer::OverWriteReadOnly) ) 00422 { 00423 int ret = chmod (TCHAR_TO_ANSI (Filename), S_IRUSR | S_IWUSR); 00424 00425 if (ret == -1) 00426 { 00427 Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NFileManagerGNU::CreateFileWriter] Can't change file mode") ); 00428 } 00429 } 00430 00431 DWORD ModeFlags = 0; 00432 00433 if ( (Flags & NSerializer::Read) && (Flags & NSerializer::Write) ) 00434 { 00435 ModeFlags |= O_RDWR; 00436 } 00437 else if (Flags & NSerializer::Read) 00438 { 00439 ModeFlags |= O_RDONLY; 00440 } 00441 else if (Flags & NSerializer::Write) 00442 { 00443 ModeFlags |= O_WRONLY; 00444 } 00445 00446 ModeFlags |= (Flags & NSerializer::Append) ? O_APPEND : O_TRUNC; 00447 ModeFlags |= (Flags & NSerializer::NoOverWrite) ? (O_CREAT | O_EXCL) /*fail if the file already exist*/ : O_CREAT /*create the file if it does not exist*/; 00448 00449 t_int FileDesc = open (TCHAR_TO_ANSI (Filename), ModeFlags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 00450 00451 if (FileDesc == -1) 00452 { 00453 if (Flags & NSerializer::OutputErrorIfFail) 00454 { 00455 nuxError (TEXT ("[NFileManagerGNU::CreateFileWriter] Failed to create file %s."), Filename); 00456 } 00457 00458 return NULL; 00459 } 00460 00461 t_s64 Pos = 0; 00462 00463 if (Flags & NSerializer::Append) 00464 { 00465 Pos = lseek (FileDesc, Pos, SEEK_END); 00466 00467 if (Pos == -1) 00468 { 00469 Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Seek] Seek to %i has failed."), Pos); 00470 } 00471 } 00472 00473 struct stat sb; 00474 00475 if (fstat (FileDesc, &sb) != 0) 00476 { 00477 int ret = close (FileDesc); 00478 00479 if (ret == -1) 00480 { 00481 Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NFileManagerGNU::CreateFileWriter] Error while closing file") ); 00482 } 00483 00484 Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NFileManagerGNU::CreateFileWriter] Can't create file reader.") ); 00485 return NULL; 00486 } 00487 00488 // The third param is never used. 00489 return new NGNUSerialFileWriter (FileDesc, Error, 0); 00490 } 00491 00492 t_s64 NFileManagerGNU::FileSize (const TCHAR *Filename) 00493 { 00494 struct stat sb; 00495 00496 if (stat (TCHAR_TO_ANSI (Filename), &sb) != 0) 00497 { 00498 nuxDebugMsg (TEXT ("[NFileManagerGNU::FileSize] Can't get file size") ); 00499 return 0; 00500 } 00501 00502 if (sb.st_mode & S_IFDIR) 00503 { 00504 // This is a directory 00505 return 0; 00506 } 00507 00508 return sb.st_size; 00509 } 00510 00511 bool NFileManagerGNU::FileExist (const TCHAR *Filename) 00512 { 00513 struct stat sb; 00514 00515 if (stat (TCHAR_TO_ANSI (Filename), &sb) != 0) 00516 { 00517 return false; 00518 } 00519 00520 return true; 00521 } 00522 00523 int NFileManagerGNU::Copy (const TCHAR *DestFile, 00524 const TCHAR *SrcFile, 00525 bool OverWriteExisting, 00526 bool OverWriteReadOnly, 00527 NFileTransferMonitor *Monitor) 00528 { 00529 size_t nmemb; 00530 //int nmemb; 00531 FILE *ifp, *ofp; 00532 char buf[BUFSIZ]; 00533 00534 if (OverWriteExisting) 00535 { 00536 if (access (DestFile, F_OK) == 0) 00537 { 00538 //OUTLOG((FUNC, TRWRN, "file %s already exists\n", DestFile)); 00539 return false; 00540 } 00541 else if (errno != ENOENT) 00542 { 00543 //OUTLOG((FUNC, TRERR, "access(%s, F_OK) failed\n", DestFile)); 00544 return false; 00545 } 00546 } 00547 00548 if ( (ifp = fopen (SrcFile, "r") ) == NULL) 00549 { 00550 //OUTLOG((FUNC, TRERR, "%s doesn't exist\n", SrcFile)); 00551 return false; 00552 } 00553 00554 if ( (ofp = fopen (DestFile, "w+") ) == NULL) 00555 { 00556 //OUTLOG((FUNC, TRERR, "can't create %s\n", DestFile)); 00557 fclose (ifp); 00558 return false; 00559 } 00560 00561 while ( (nmemb = fread (buf, 1, sizeof (buf), ifp) ) > 0) 00562 { 00563 if (fwrite (buf, 1, nmemb, ofp) != nmemb) 00564 { 00565 //OUTLOG((FUNC, TRERR, "fwrite failed\n")); 00566 fclose (ifp); 00567 fclose (ofp); 00568 return false; 00569 } 00570 } 00571 00572 fclose (ifp); 00573 fclose (ofp); 00574 return true; 00575 } 00576 00577 bool NFileManagerGNU::Delete (const TCHAR *Filename, bool OverWriteReadOnly) 00578 { 00579 if (OverWriteReadOnly) 00580 { 00581 chmod (TCHAR_TO_ANSI (Filename), S_IRUSR | S_IWUSR); 00582 } 00583 00584 if (unlink (TCHAR_TO_ANSI (Filename) ) != 0) 00585 { 00586 nuxDebugMsg (TEXT ("[NFileManagerGNU::Delete] Error deleting file '%s'."), Filename); 00587 return false; 00588 } 00589 00590 return true; 00591 } 00592 00593 bool NFileManagerGNU::IsReadOnly (const TCHAR *Filename) 00594 { 00595 struct stat sb; 00596 00597 if (stat (TCHAR_TO_ANSI (Filename), &sb) != 0) 00598 { 00599 nuxDebugMsg (TEXT ("[NFileManagerGNU::IsReadOnly] Error reading file status '%s'."), Filename); 00600 return false; 00601 } 00602 00603 if ( (sb.st_mode & S_IRUSR) && ! (sb.st_mode & S_IWUSR) ) 00604 { 00605 return true; 00606 } 00607 00608 return false; 00609 } 00610 00611 bool NFileManagerGNU::IsDirectory (const TCHAR *DirectoryName) 00612 { 00613 struct stat sb; 00614 00615 if (stat (TCHAR_TO_ANSI (DirectoryName), &sb) != 0) 00616 { 00617 nuxDebugMsg (TEXT ("[NFileManagerGNU::IsDirectory] Error reading file status '%s'."), DirectoryName); 00618 return false; 00619 } 00620 00621 if (sb.st_mode & S_IFDIR) 00622 { 00623 return true; 00624 } 00625 00626 return false; 00627 } 00628 00629 bool NFileManagerGNU::IsHidden (const TCHAR *Filename) 00630 { 00631 return false; 00632 } 00633 00637 bool NFileManagerGNU::GetFileAttribute (const TCHAR *Filename, bool &isDirectory, bool &isReadOnly, bool &isHidden, t_s64 &Size) 00638 { 00639 isDirectory = false; 00640 isReadOnly = false; 00641 isHidden = false; 00642 Size = 0; 00643 00644 struct stat sb; 00645 00646 if (stat (TCHAR_TO_ANSI (Filename), &sb) != 0) 00647 { 00648 return false; 00649 } 00650 00651 if (sb.st_mode & S_IFDIR) 00652 { 00653 isDirectory = true; 00654 } 00655 00656 if ( (sb.st_mode & S_IRUSR) && ! (sb.st_mode & S_IWUSR) ) 00657 { 00658 isReadOnly = true; 00659 } 00660 00661 Size = sb.st_mode; 00662 return true; 00663 } 00664 00665 bool NFileManagerGNU::Move (const TCHAR *Dest, const TCHAR *Src, bool OverWriteExisting, bool OverWriteReadOnly, NFileTransferMonitor *Monitor) 00666 { 00667 nuxAssert (0); 00668 return false; 00669 } 00670 00671 bool NFileManagerGNU::MakeDirectory (const TCHAR *Path, bool CreateCompletePath) 00672 { 00673 if (CreateCompletePath) 00674 { 00675 return NFileManagerGeneric::MakeDirectory (Path, CreateCompletePath); 00676 } 00677 00678 mkdir (TCHAR_TO_ANSI (Path), 00679 S_IRUSR | S_IWUSR | S_IXUSR | 00680 S_IRGRP | S_IWGRP | S_IXGRP | 00681 S_IROTH | S_IWOTH | S_IXOTH); 00682 00683 // EEXIST = -2147418092 = 0x80010014 00684 // if((errno != 0) && (errno != EEXIST)) 00685 // { 00686 // nuxDebugMsg(TEXT("[NFileManagerGNU::MakeDirectory] Error creating directory '%s'."), Path); 00687 // return NUX_ERROR; 00688 // } 00689 return NUX_OK; 00690 } 00691 00692 bool NFileManagerGNU::DeleteDirectory (const TCHAR *Path, bool DeleteContentFirst) 00693 { 00694 // if(DeleteContentFirst) 00695 // { 00696 // return NFileManagerGeneric::DeleteDirectory(Path, DeleteContentFirst); 00697 // } 00698 // if((::RemoveDirectory(Path) == 0) && (::GetLastError() != ERROR_FILE_NOT_FOUND)) 00699 // { 00700 // nuxDebugMsg(TEXT("[NFileManagerWindows::DeleteDirectory] Error deleting directory '%s' (GetLastError: %d)"), Path, ::GetLastError()); 00701 // return false; 00702 // } 00703 return true; 00704 } 00705 00706 } 00707