| 63 | |
| 64 | |
| 65 | void CClientCreditsList::LoadList() |
| 66 | { |
| 67 | CFile file; |
| 68 | CPath fileName = CPath(thePrefs::GetConfigDir() + CLIENTS_MET_FILENAME); |
| 69 | |
| 70 | if (!fileName.FileExists()) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | try { |
| 75 | file.Open(fileName, CFile::read); |
| 76 | |
| 77 | if (file.ReadUInt8() != CREDITFILE_VERSION) { |
| 78 | AddDebugLogLineC( logCredits, "Creditfile is outdated and will be replaced" ); |
| 79 | file.Close(); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | // everything is ok, lets see if the backup exist... |
| 84 | CPath bakFileName = CPath(thePrefs::GetConfigDir() + CLIENTS_MET_BAK_FILENAME); |
| 85 | |
| 86 | bool bCreateBackup = TRUE; |
| 87 | if (bakFileName.FileExists()) { |
| 88 | // Ok, the backup exist, get the size |
| 89 | CFile hBakFile(bakFileName); |
| 90 | if ( hBakFile.GetLength() > file.GetLength()) { |
| 91 | // the size of the backup was larger then the |
| 92 | // org. file, something is wrong here, don't |
| 93 | // overwrite old backup.. |
| 94 | bCreateBackup = FALSE; |
| 95 | } |
| 96 | // else: backup is smaller or the same size as org. |
| 97 | // file, proceed with copying of file |
| 98 | } |
| 99 | |
| 100 | //else: the backup doesn't exist, create it |
| 101 | if (bCreateBackup) { |
| 102 | file.Close(); // close the file before copying |
| 103 | if (!CPath::CloneFile(fileName, bakFileName, true)) { |
| 104 | AddDebugLogLineC(logCredits, |
| 105 | CFormat("Could not create backup file '%s'") % fileName); |
| 106 | } |
| 107 | // reopen file |
| 108 | if (!file.Open(fileName, CFile::read)) { |
| 109 | AddDebugLogLineC( logCredits, |
| 110 | "Failed to load creditfile" ); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | file.Seek(1); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | uint32 count = file.ReadUInt32(); |
| 119 | |
| 120 | const uint32 dwExpired = time(NULL) - 12960000; // today - 150 day |
| 121 | uint32 cDeleted = 0; |
| 122 | for (uint32 i = 0; i < count; i++){ |
nothing calls this directly
no test coverage detected