#include <fileutil.h>
Static Public Member Functions | |
static BOOL | FindResourceFile (TCHAR *SearchFile, TCHAR *FoundFile) |
The function searches for a matching file in the following directories in the following sequence: 1. The directory from which the application loaded. 2. The current directory. 3. Windows 95: The Windows system directory. Windows NT: The 32-bit Windows system directory. 4. Windows NT only: The 16-bit Windows system directory. 5. The Windows directory. 6. The directories that are listed in the PATH environment variable. | |
static BOOL | StartFindingFiles (String_256 *FileSpecifier) |
Scans a given directory for files matching a particular name. | |
static BOOL | FindNextFile (String_256 *FoundFile) |
Finds the next file, if any. See StartFindingFiles for example search code. | |
static void | StopFindingFiles (void) |
Stops a directory scan. | |
static BOOL | GetLongFileName (LPTSTR lpszPath, LPTSTR lpszOutput, size_t cchMaxOutLen) |
Given a full 8.3 pathname, extract the full filename. | |
static UINT32 | GetTemporaryFileName (const TCHAR *PathName, const TCHAR *Prefix, UINT32 Unique, TCHAR *FileName) |
Creates a unique file name to be used as temporary file. The format of the file name is path.TMP, where 'path' is specified by PathName, 'pre' are the first three characters pointed by Prefix, 'uuuu' is the hexadecimal Unique parameter. Pass 0 for Unique to be certain the temp file name is really unique. | |
static DWORD | GetTemporaryPath (UINT32 BufferLength, TCHAR *Buffer) |
Gets the temporary directory. | |
static PathName | GetTemporaryPathName () |
Simplified interface to GetTempFileName(). | |
static BOOL | GetTemporaryPathName (const TCHAR *pExt, PathName *pTempPath) |
Simplified interface to GetTempFileName(). Call this function when you want to create a new temporary file with a particular extension. | |
static BOOL | DeleteFile (PathName *FileToRemove) |
Removes a file. | |
static BOOL | GetCurrentDirectory (String_256 *pCurrentPath) |
Set up the operating system current directory. | |
static BOOL | SetCurrentDirectory (const PathName &NewCurrentPath) |
Set up the operating system current directory. | |
static BOOL | SetCurrentDirectory (const String_256 &NewCurrentPath) |
Set up the operating system current directory. | |
static BOOL | RecursiveCreateDirectory (const String_256 &strDirPath) |
Recursivly create directory path. | |
static DWORD | FindFileAttributes (LPCTSTR lpFileName) |
Static Private Attributes | |
static BOOL | SearchActive = FALSE |
static bool | s_fStarted = false |
static String_256 | SearchPath = TEXT("") |
static wxDir | s_dirSearch |
Definition at line 123 of file fileutil.h.
|
Removes a file.
Definition at line 573 of file fileutil.cpp. 00574 { 00575 if (FileToRemove == NULL) 00576 return FALSE; 00577 00578 BOOL Exists = TRUE; 00579 BOOL status = TRUE; 00580 00581 // check if the file exists 00582 Exists = SGLibOil::FileExists(FileToRemove); 00583 00584 // remove it 00585 if (Exists) 00586 status = wxRemoveFile( FileToRemove->GetPath() ); 00587 00588 return !status; 00589 }
|
|
Definition at line 150 of file fileutil.h. 00151 { 00152 TRACE( wxT("Warning - FileUtil::FindFileAttributes called\n") ); 00153 #if defined(__WXMSW__) 00154 return GetFileAttributes( lpFileName ); 00155 #else 00156 return 0; 00157 #endif 00158 }
|
|
Finds the next file, if any. See StartFindingFiles for example search code.
Definition at line 268 of file fileutil.cpp. 00269 { 00270 ERROR3IF(FoundFile == NULL, "Illegal NULL param"); 00271 00272 if (!SearchActive) 00273 { 00274 ERROR3("FindNextFile called when StartFindingFiles not called/failed"); 00275 return(FALSE); 00276 } 00277 00278 BOOL result = TRUE; 00279 00280 while (result) 00281 { 00282 wxString strFileName; 00283 00284 if( !s_fStarted ) 00285 { 00286 // find first 00287 PathName path( SearchPath ); 00288 result = wxDir::Exists( path.GetLocation() ); 00289 result = result && s_dirSearch.Open( path.GetLocation() ); 00290 result = result && s_dirSearch.GetFirst( &strFileName, (PCTSTR)path.GetFileName(), wxDIR_FILES ); 00291 s_fStarted = result; 00292 } 00293 else 00294 { 00295 // find next 00296 result = s_dirSearch.GetNext( &strFileName ); 00297 } 00298 00299 if (result) 00300 { 00301 PORTNOTE("other", "This is part of initial GetFirst" ) 00302 #if !defined(EXCLUDE_FROM_XARALX) 00303 // Only return "files" which are not system or hidden, and which aren't directories! 00304 const DWORD AttrMask = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM; 00305 00306 if ((SearchData.dwFileAttributes & AttrMask) == 0) 00307 #endif 00308 { 00309 // OK, it's a safe file to return, so return it 00310 *FoundFile = (PCTSTR)strFileName; 00311 return(TRUE); 00312 } 00313 } 00314 } 00315 00316 *FoundFile = TEXT(""); 00317 return(FALSE); 00318 }
|
|
The function searches for a matching file in the following directories in the following sequence: 1. The directory from which the application loaded. 2. The current directory. 3. Windows 95: The Windows system directory. Windows NT: The 32-bit Windows system directory. 4. Windows NT only: The 16-bit Windows system directory. 5. The Windows directory. 6. The directories that are listed in the PATH environment variable.
Definition at line 142 of file fileutil.cpp. 00143 { 00144 // Try to find the printer.cms file 00145 BOOL Found = FALSE; 00146 00147 #if WIN16 00148 00149 // 16 bit Windows - look in the PATH variable and current 00150 // directory using _searchenv. 00151 _tsearchenv((char*)SearchFile, "PATH", (char*)FoundFile); 00152 Found = (FoundFile[0] != '\0'); 00153 00154 #else 00155 00156 // 32-bit Windows - use Win32 API SearchPath, which will look in all kinds 00157 // of places, and hopefully should find the 16-bit Windows directory if it's 00158 // on the user's path, and use the ini file in there. 00159 LPTSTR FirstChar; 00160 DWORD BytesRead = ::SearchPath(NULL, // Use default search paths (see help file) 00161 SearchFile, 00162 NULL, // Filename already has an extension 00163 _MAX_PATH - 1, // Destination buffer size 00164 FoundFile, // Destination buffer 00165 &FirstChar); 00166 00167 Found = (BytesRead > 0) && (BytesRead < _MAX_PATH); 00168 00169 #endif 00170 00171 return Found; 00172 }
|
|
Set up the operating system current directory.
Definition at line 645 of file fileutil.cpp. 00646 { 00647 ERROR2IF(pCurrentPath == NULL,FALSE,"FileUtil::GetCurrentDirectory Bad params"); 00648 00649 // Call the OS to get the new current directory 00650 // DWORD nBufferLength size, in characters, of directory buffer 00651 // LPTSTR lpBuffer address of buffer for current directory 00652 // If the function succeeds, the return value specifies the number of characters 00653 // written to the buffer, not including the terminating null character. 00654 // If the function fails, the return value is zero. 00655 const INT32 MaxSize = 256; 00656 TCHAR Buffer[MaxSize]; 00657 DWORD chars = ::GetCurrentDirectory( MaxSize, Buffer); 00658 if (chars > 0) 00659 { 00660 *pCurrentPath = Buffer; 00661 } 00662 else 00663 pCurrentPath->Empty(); 00664 00665 return (chars > 0); 00666 }
|
|
Given a full 8.3 pathname, extract the full filename.
Definition at line 371 of file fileutil.cpp. 00372 { 00373 if(lpszPath == NULL || lpszOutput == NULL || cchMaxOutLen < 1) 00374 { 00375 ERROR3("FileUtil::GetLongFileName given dodgy params - come on, play the game..."); 00376 return FALSE; 00377 } 00378 00379 WIN32_FIND_DATA FileData; 00380 00381 // Perform a search for the specified file 00382 HANDLE hSearch = ::FindFirstFile(lpszPath, &FileData); 00383 if (hSearch == INVALID_HANDLE_VALUE) 00384 { 00385 //ERROR3_PF(("FileUtil::GetLongFileName Corresponding long filename version of %s not found", lpszPath)); 00386 return FALSE; 00387 } 00388 00389 // The find_data structure will hopefully now contain the long filename for the file 00390 if(camStrlen(FileData.cFileName) < (INT32)cchMaxOutLen) 00391 { 00392 camStrcpy(lpszOutput, FileData.cFileName); 00393 return TRUE; 00394 } 00395 00396 return FALSE; 00397 }
|
|
Creates a unique file name to be used as temporary file. The format of the file name is path.TMP, where 'path' is specified by PathName, 'pre' are the first three characters pointed by Prefix, 'uuuu' is the hexadecimal Unique parameter. Pass 0 for Unique to be certain the temp file name is really unique.
Definition at line 515 of file fileutil.cpp. 00516 { 00517 if(PathName == NULL || Prefix == NULL || FileName == NULL) 00518 { 00519 ERROR3("FileUtil::GetTempFileName given dodgy params - come on, play the game..."); 00520 return FALSE; 00521 } 00522 00523 wxString str( PathName ); 00524 // str += Prefix; 00525 00526 str = wxFileName::CreateTempFileName( str ); 00527 camStrcpy( FileName, str.c_str() ); 00528 return Unique != 0 ? Unique : 0xD7334; // Random non-zero value 00529 }
|
|
Gets the temporary directory.
Definition at line 547 of file fileutil.cpp. 00548 { 00549 if(Buffer == NULL || BufferLength == 0) 00550 { 00551 ERROR3("FileUtil::GetTempPath given dodgy params - come on, play the game..."); 00552 return FALSE; 00553 } 00554 00555 return ::GetTempPath(BufferLength, Buffer); 00556 }
|
|
Simplified interface to GetTempFileName(). Call this function when you want to create a new temporary file with a particular extension.
Definition at line 460 of file fileutil.cpp. 00461 { 00462 ERROR3IF((pTempPath == NULL) || (pExt == NULL), "NULL param passed to FileUtil::GetTemporaryPathName"); 00463 if ((pTempPath == NULL) || (pExt == NULL)) 00464 return FALSE; 00465 00466 // create a new temp file 00467 *pTempPath = FileUtil::GetTemporaryPathName(); 00468 00469 // if tmp extension is asked - call the relevant function 00470 if (camStricmp(pExt, (const TCHAR *)"tmp") == 0) 00471 return TRUE; 00472 00473 // remember the current name 00474 String_256 pInFile = pTempPath->GetPath(); 00475 00476 // change the extension 00477 pTempPath->SetType(pExt); 00478 00479 // check if the file exists 00480 if (SGLibOil::FileExists(pTempPath)) 00481 { 00482 // make a recursive call 00483 BOOL ok = GetTemporaryPathName(pExt, pTempPath); 00484 00485 // remove our .tmp file 00486 wxRemoveFile( (PCTSTR)pInFile ); 00487 00488 return ok; 00489 } 00490 00491 // try to rename the file 00492 wxString path = (PCTSTR)pTempPath->GetPath(); 00493 return wxRenameFile( (PCTSTR)pInFile, path ); 00494 }
|
|
Simplified interface to GetTempFileName().
The pathname that this function returns will be unique (i.e. will not point to an existing file), will begin with 'xar' and will be in the system's temporary directory.
Definition at line 423 of file fileutil.cpp. 00424 { 00425 //First get the directory in which to put our temporary files 00426 TCHAR pcPath[MAX_PATH] = _T(""); 00427 00428 PORTNOTE("other", "This call is not needed, wxFileName::CreateTempFileName does the right thing" ) 00429 // FileUtil::GetTemporaryPath(MAX_PATH, pcPath); 00430 00431 //Now get a temporary file name 00432 TCHAR pcFileName[MAX_PATH]; 00433 00434 FileUtil::GetTemporaryFileName(pcPath, _T("xar"), 0, pcFileName); 00435 00436 //And convert the file name into a PathName 00437 String_256 strFileName=pcFileName; 00438 PathName pthFileName(strFileName); 00439 00440 //And return it 00441 return pthFileName; 00442 00443 }
|
|
Recursivly create directory path.
Definition at line 604 of file fileutil.cpp. 00605 { 00606 // Go down path making sure each directory exists (and creating if needed), we 00607 // start from the second character becuase we don't want to deal with '/' 00608 UINT32 ord = 1; 00609 while( _T('\0') != strDirPath[ord] ) 00610 { 00611 if( _T('/') == strDirPath[ord] ) 00612 { 00613 String_256 strPath; 00614 strDirPath.Left( &strPath, ord ); 00615 if( !wxDir::Exists( (PCTSTR)strPath ) ) 00616 wxMkdir( (PCTSTR)strPath ); 00617 } 00618 00619 ++ord; 00620 } 00621 00622 // Make sure the path as a whole exists 00623 if( !wxDir::Exists( (PCTSTR)strDirPath ) ) 00624 wxMkdir( (PCTSTR)strDirPath ); 00625 00626 return TRUE; 00627 }
|
|
Set up the operating system current directory.
Definition at line 701 of file fileutil.cpp. 00702 { 00703 // Call the OS to set the new current directory 00704 String_256 CurrentPath = NewCurrentPath; 00705 BOOL ok = ::SetCurrentDirectory( (TCHAR *)CurrentPath ); 00706 return ok; 00707 }
|
|
Set up the operating system current directory.
Definition at line 680 of file fileutil.cpp. 00681 { 00682 String_256 CurrentPath = NewCurrentPath.GetPath(); 00683 00684 // Call the OS to set the new current directory 00685 BOOL ok = ::SetCurrentDirectory( (TCHAR *)CurrentPath ); 00686 return ok; 00687 }
|
|
Scans a given directory for files matching a particular name.
PathName SearchPath("c:\\Directory\\*.*") if (FileUtil::StartFindingFiles(&SearchPath)) { String_256 LeafName; while (TRUE) { if (!FileUtilFindNextFile(&LeafName)) break; Do something with file "LeafName" String_256 FullPathName = "c:\\Directory\"; FullPathName += LeafName; TRACE( _T("Full file path name is %s\n"), (TCHAR *)FullPathName); } FileUtil::StopFindingFiles(); } Notes: This search is non-"re-entrant". Between calls to Start & Stop, any calls to start another search will give an Error3 and return failure.
Definition at line 221 of file fileutil.cpp. 00222 { 00223 ERROR3IF(FileSpecifier == NULL, "Duff FileSpecifier param"); 00224 00225 if (SearchActive) 00226 { 00227 ERROR3("StartFindingFiles called while already finding files! Call returns failure"); 00228 return(FALSE); 00229 } 00230 00231 SearchActive = TRUE; 00232 s_fStarted = false; 00233 SearchPath = *FileSpecifier; 00234 00235 return(TRUE); 00236 }
|
|
Stops a directory scan.
Notes: This code is non-re-entrant. Between calls to Start & Stop, any calls to start another search will give an Error3 and return failure. DO NOT CALL THIS FUNCTION if StartFindingFiles failed. Call this function exactly once for each call to StartFindingFiles.
Definition at line 344 of file fileutil.cpp. 00345 { 00346 ERROR3IF(!SearchActive, "StopFindingFiles called when StartFindingFiles not called/failed"); 00347 00348 s_fStarted = false; 00349 SearchActive = FALSE; 00350 }
|
|
Definition at line 164 of file fileutil.h. |
|
Definition at line 162 of file fileutil.h. |
|
Definition at line 161 of file fileutil.h. |
|
Definition at line 163 of file fileutil.h. |