void fill_in_default_path() { HANDLE find_handle; WIN32_FIND_DATA find_data; WCHAR best_path[MAX_PATH+1]; int best_path_has_haggle_folder; ULARGE_INTEGER best_avail, best_size; long i; // Start with the application data folder, as a fallback: if (!SHGetSpecialFolderPath(NULL, best_path, CSIDL_APPDATA, FALSE)) { best_path[0] = 0; best_avail.QuadPart = 0; best_size.QuadPart = 0; best_path_has_haggle_folder = 0; } else { GetDiskFreeSpaceEx(best_path, &best_avail, &best_size, NULL); best_path_has_haggle_folder = has_haggle_folder(best_path); } LIBHAGGLE_DBG("Found data card path: \"%ls\" (size: %I64d/%I64d, haggle folder: %s)\n", best_path, best_avail, best_size, best_path_has_haggle_folder ? "Yes" : "No"); find_handle = FindFirstFlashCard(&find_data); if (find_handle != INVALID_HANDLE_VALUE) { do { // Ignore the root directory (this has been checked for above) if (find_data.cFileName[0] != 0) { ULARGE_INTEGER avail, size, free; int haggle_folder; GetDiskFreeSpaceEx(find_data.cFileName, &avail, &size, &free); haggle_folder = has_haggle_folder(find_data.cFileName); LIBHAGGLE_DBG("Found data card path: \"%ls\" (size: %I64d/%I64d, haggle folder: %s)\n", find_data.cFileName, avail, size, haggle_folder ?" Yes" : "No"); // is this a better choice than the previous one? // FIXME: should there be any case when a memory card is not used? if (1) { // Yes. // Save this as the path to use: for (i = 0; i < MAX_PATH; i++) best_path[i] = find_data.cFileName[i]; best_avail = avail; best_size = size; best_path_has_haggle_folder = haggle_folder; } } } while(FindNextFlashCard(find_handle, &find_data)); FindClose(find_handle); } // Convert the path to normal characters. for (i = 0; i < MAX_PATH; i++) path[i] = (char) best_path[i]; }
void RefreshStorageCards () { g_dCards.Clear (); WIN32_FIND_DATA tData; HANDLE hCard = FindFirstFlashCard ( &tData ); if ( hCard != INVALID_HANDLE_VALUE ) { do { if ( tData.cFileName [0] != L'\0' ) g_dCards.Add ( tData ); } while ( FindNextFlashCard ( hCard, &tData ) ); } }
bool IsStorageCard ( const Str_c & sFile ) { WIN32_FIND_DATA tData; HANDLE hCard = FindFirstFlashCard ( &tData ); int iCard = 0; if ( hCard != INVALID_HANDLE_VALUE ) { do { if ( sFile == tData.cFileName ) return true; } while ( FindNextFlashCard ( hCard, &tData ) ); } return false; }
bool AreFilesOnDifferentVolumes ( const Str_c & sFile1, const Str_c & sFile2 ) { Str_c sFileToTest1 = sFile1; sFileToTest1.ToLower (); Str_c sFileToTest2 = sFile2; sFileToTest2.ToLower (); WIN32_FIND_DATA tData; HANDLE hCard = FindFirstFlashCard ( &tData ); int iFile1Card = -1; int iFile2Card = -1; int iCard = 0; wchar_t szFileNameToTest [ MAX_PATH ]; if ( hCard != INVALID_HANDLE_VALUE ) { do { wcscpy ( szFileNameToTest, tData.cFileName ); _wcslwr ( szFileNameToTest ); int iFindRes1 = sFileToTest1.Find ( szFileNameToTest ); if ( iFile1Card == -1 && iFindRes1 != -1 && iFindRes1 <= 1 ) iFile1Card = iCard; int iFindRes2 = sFileToTest2.Find ( szFileNameToTest ); if ( iFile2Card == -1 && iFindRes2 != -1 && iFindRes2 <= 1 ) iFile2Card = iCard; ++iCard; } while ( FindNextFlashCard ( hCard, &tData ) && ( iFile1Card == -1 || iFile2Card == -1 ) ); } return iFile1Card != iFile2Card; }