void ChunkManager::savePriorityInfo() { if (during_load) return; //save priority info and call saveFileInfo saveFileInfo(); File fptr; if (!fptr.open(file_priority_file,"wb")) { Out(SYS_DIO|LOG_IMPORTANT) << "Warning : Can't save chunk_info file : " << fptr.errorString() << endl; return; } try { // first write the number of excluded ones // don't know this yet, so write 0 for the time being Uint32 tmp = 0; fptr.write(&tmp,sizeof(Uint32)); Uint32 i = 0; Uint32 cnt = 0; while (i < tor.getNumFiles()) { const TorrentFile & tf = tor.getFile(i); if (tf.getPriority() != NORMAL_PRIORITY) { tmp = tf.getPriority(); fptr.write(&i,sizeof(Uint32)); fptr.write(&tmp,sizeof(Uint32)); cnt+=2; } i++; } // go back to the beginning and write the number of items fptr.seek(File::BEGIN,0); fptr.write(&cnt,sizeof(Uint32)); fptr.flush(); } catch (bt::Error & err) { Out(SYS_DIO|LOG_IMPORTANT) << "Failed to save priority file " << err.toString() << endl; bt::Delete(file_priority_file,true); } }
void ChunkManager::Private::savePriorityInfo() { if (during_load) return; //save priority info and call saveFileInfo saveFileInfo(); File fptr; if (!fptr.open(file_priority_file,"wb")) { Out(SYS_DIO|LOG_IMPORTANT) << "Warning : Can not save chunk_info file : " << fptr.errorString() << endl; return; } try { QList<Uint32> dnd; Torrent & tor = p->tor; Uint32 i = 0; for ( ; i < tor.getNumFiles(); i++) { if(tor.getFile(i).getPriority() != NORMAL_PRIORITY) { dnd.append(i); dnd.append(tor.getFile(i).getPriority()); } } Uint32 tmp = dnd.count(); fptr.write(&tmp,sizeof(Uint32)); // write all the non-default priority ones for (i = 0;i < (Uint32)dnd.count();i++) { tmp = dnd[i]; fptr.write(&tmp,sizeof(Uint32)); } fptr.flush(); } catch (bt::Error & err) { Out(SYS_DIO|LOG_IMPORTANT) << "Failed to save priority file " << err.toString() << endl; bt::Delete(file_priority_file,true); } }