//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CDatabaseVersionManager { public: string ReadStoredDbVersion(string versionFilePath) { if(!FileIsExist(versionFilePath, FILE_COMMON)) return "NA"; int fileHandle = INVALID_HANDLE; // Initialize to a safe value int attempts = 0; while(attempts < 5) { fileHandle = FileOpen(versionFilePath, FILE_COMMON | FILE_READ); if(fileHandle != INVALID_HANDLE) { break; // Success, break out of the loop } Print("Retry " + IntegerToString(attempts + 1) + " failed to open file for reading: " + versionFilePath); Sleep(1000); // Wait for a second before retrying attempts++; } if(fileHandle == INVALID_HANDLE) { Print("Failed to open file for reading after retries: " + versionFilePath); return "ERROR"; } string dbVersion = FileReadString(fileHandle); FileClose(fileHandle); return dbVersion; } bool UpdateStoredDbVersion(string versionFilePath, string dbVersion) { int fileHandle = INVALID_HANDLE; // Initialize to a safe value int attempts = 0; while(attempts < 5) { fileHandle = FileOpen(versionFilePath, FILE_COMMON | FILE_WRITE); if(fileHandle != INVALID_HANDLE) { break; // Success, break out of the loop } Print("Retry " + IntegerToString(attempts + 1) + " failed to open file for writing: " + versionFilePath); Sleep(1000); // Wait for a second before retrying attempts++; } if(fileHandle == INVALID_HANDLE) { Print("Failed to open file for writing after retries: " + versionFilePath); return false; } FileWriteString(fileHandle, dbVersion); FileClose(fileHandle); return true; } }; //+------------------------------------------------------------------+