| 40 | |
| 41 | |
| 42 | bool CCanceledFileList::Init() |
| 43 | { |
| 44 | CFile file; |
| 45 | |
| 46 | CPath fullpath = CPath(thePrefs::GetConfigDir() + m_filename); |
| 47 | if (!fullpath.FileExists()) { |
| 48 | // This is perfectly normal. The file was probably either |
| 49 | // deleted, or this is the first time running aMule. |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | if (!file.Open(fullpath)) { |
| 54 | AddLogLineC(CFormat(_("WARNING: %s cannot be opened.")) % m_filename); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | try { |
| 59 | uint8 version = file.ReadUInt8(); |
| 60 | if (version != CANCELEDFILE_VERSION) { |
| 61 | AddLogLineC(_("WARNING: Canceled file list corrupted, contains invalid header.")); |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | uint32 RecordsNumber = file.ReadUInt32(); |
| 66 | AddDebugLogLineN(logKnownFiles, |
| 67 | CFormat("Reading %i canceled files from file format 0x%02x.") |
| 68 | % RecordsNumber % version); |
| 69 | for (uint32 i = 0; i < RecordsNumber; i++) { |
| 70 | CMD4Hash hash; |
| 71 | file.Read(hash.GetHash(), 16); |
| 72 | AddDebugLogLineN(logKnownFiles, CFormat("Canceled file read: %s") % hash.Encode()); |
| 73 | if (!hash.IsEmpty()) { |
| 74 | m_canceledFileList.insert(hash); |
| 75 | } |
| 76 | } |
| 77 | AddDebugLogLineN(logKnownFiles, "Finished reading canceled files"); |
| 78 | |
| 79 | return true; |
| 80 | } catch (const CSafeIOException& e) { |
| 81 | AddLogLineC(CFormat(_("IO error while reading %s file: %s")) % m_filename % e.what()); |
| 82 | } |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | void CCanceledFileList::Save() |
nothing calls this directly
no test coverage detected