MCPcopy Create free account
hub / github.com/amule-project/amule / RenameFile

Method RenameFile

src/SharedFileList.cpp:1248–1307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1246
1247
1248bool CSharedFileList::RenameFile(CKnownFile* file, const CPath& newName)
1249{
1250 if (file->IsPartFile()) {
1251 CPartFile* pfile = dynamic_cast<CPartFile*>(file);
1252
1253 if (file->GetStatus() != PS_COMPLETING) {
1254 pfile->SetFileName(newName);
1255 pfile->SavePartFile();
1256
1257 Notify_SharedFilesUpdateItem(file);
1258 Notify_DownloadCtrlUpdateItem(file);
1259
1260 return true;
1261 }
1262 } else {
1263 CPath oldPath = file->GetFilePath().JoinPaths(file->GetFileName());
1264 CPath newPath = file->GetFilePath().JoinPaths(newName);
1265
1266 if (CPath::RenameFile(oldPath, newPath)) {
1267 // Must create a copy of the word list because:
1268 // 1) it will be reset on SetFileName()
1269 // 2) we will want to edit it
1270 Kademlia::WordList oldwords = file->GetKadKeywords();
1271 file->SetFileName(newName);
1272 theApp->knownfiles->Save();
1273 UpdateItem(file);
1274 RepublishFile(file);
1275
1276 const Kademlia::WordList& newwords = file->GetKadKeywords();
1277 Kademlia::WordList::iterator it_old;
1278 Kademlia::WordList::const_iterator it_new;
1279 // compare keywords in old and new names
1280 for (it_new = newwords.begin(); it_new != newwords.end(); ++it_new) {
1281 for (it_old = oldwords.begin(); it_old != oldwords.end(); ++it_old) {
1282 if (*it_old == *it_new) {
1283 break;
1284 }
1285 }
1286 if (it_old != oldwords.end()) {
1287 // Remove keyword from old name which also exist in new name
1288 oldwords.erase(it_old);
1289 } else {
1290 // This is a new keyword not present in the old name
1291 m_keywords->AddKeyword(*it_new, file);
1292 }
1293 }
1294 // Remove all remaining old keywords not present in the new name
1295 for (it_old = oldwords.begin(); it_old != oldwords.end(); ++it_old) {
1296 m_keywords->RemoveKeyword(*it_old, file);
1297 }
1298
1299 Notify_DownloadCtrlUpdateItem(file);
1300 Notify_SharedFilesUpdateItem(file);
1301
1302 return true;
1303 }
1304 }
1305

Callers 4

OnBnClickedApplyMethod · 0.45
ProcessRequest2Method · 0.45
OnRenameMethod · 0.45
OnKeyPressedMethod · 0.45

Calls 11

SavePartFileMethod · 0.80
JoinPathsMethod · 0.80
eraseMethod · 0.80
RemoveKeywordMethod · 0.80
IsPartFileMethod · 0.45
GetStatusMethod · 0.45
SetFileNameMethod · 0.45
SaveMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
AddKeywordMethod · 0.45

Tested by

no test coverage detected