| 105 | |
| 106 | |
| 107 | void CDownloadQueue::LoadMetFiles(const CPath& path) |
| 108 | { |
| 109 | AddLogLineNS(CFormat(_("Loading temp files from %s.")) % path.GetPrintable()); |
| 110 | |
| 111 | std::vector<CPath> files; |
| 112 | |
| 113 | // Locate part-files to be loaded |
| 114 | CDirIterator TempDir(path); |
| 115 | CPath fileName = TempDir.GetFirstFile(CDirIterator::File, "*.part.met"); |
| 116 | while (fileName.IsOk()) { |
| 117 | files.push_back(path.JoinPaths(fileName)); |
| 118 | |
| 119 | fileName = TempDir.GetNextFile(); |
| 120 | } |
| 121 | |
| 122 | // Loading in order makes it easier to figure which |
| 123 | // file is broken in case of crashes, or the like. |
| 124 | std::sort(files.begin(), files.end()); |
| 125 | |
| 126 | // Load part-files |
| 127 | for ( size_t i = 0; i < files.size(); i++ ) { |
| 128 | AddLogLineNS(CFormat(_("Loading PartFile %u of %u")) % (i + 1) % files.size()); |
| 129 | fileName = files[i].GetFullName(); |
| 130 | CPartFile *toadd = new CPartFile(); |
| 131 | bool result = toadd->LoadPartFile(path, fileName) != 0; |
| 132 | if (!result) { |
| 133 | // Try from backup |
| 134 | result = toadd->LoadPartFile(path, fileName, true) != 0; |
| 135 | } |
| 136 | if (result && !IsFileExisting(toadd->GetFileHash())) { |
| 137 | { |
| 138 | wxMutexLocker lock(m_mutex); |
| 139 | m_filelist.push_back(toadd); |
| 140 | } |
| 141 | NotifyObservers(EventType(EventType::INSERTED, toadd)); |
| 142 | Notify_DownloadCtrlAddFile(toadd); |
| 143 | } else { |
| 144 | wxString msg; |
| 145 | if (result) { |
| 146 | msg << CFormat("WARNING: Duplicate partfile with hash '%s' found, skipping: %s") |
| 147 | % toadd->GetFileHash().Encode() % fileName; |
| 148 | } else { |
| 149 | // If result is false, then reading of both the primary and the backup .met failed |
| 150 | AddLogLineN(_("ERROR: Failed to load backup file. Search https://github.com/amule-org/amule/discussions for .part.met recovery solutions.")); |
| 151 | msg << CFormat("ERROR: Failed to load PartFile '%s'") % fileName; |
| 152 | } |
| 153 | AddLogLineCS(msg); |
| 154 | |
| 155 | // Delete the partfile object in the end. |
| 156 | delete toadd; |
| 157 | } |
| 158 | } |
| 159 | AddLogLineNS(_("All PartFiles Loaded.")); |
| 160 | |
| 161 | if ( GetFileCount() == 0 ) { |
| 162 | AddLogLineN(_("No part files found")); |
| 163 | } else { |
| 164 | AddLogLineN(CFormat(wxPLURAL("Found %u part file", "Found %u part files", GetFileCount())) % GetFileCount()); |
no test coverage detected