Skip to content

Instantly share code, notes, and snippets.

@Smenus
Last active December 11, 2015 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Smenus/4576230 to your computer and use it in GitHub Desktop.
Save Smenus/4576230 to your computer and use it in GitHub Desktop.
--- libpar2-0.2-original/par2repairer.cpp 2006-01-20 17:25:00.000000000 +0000
+++ libpar2-0.2/par2repairer.cpp 2013-01-20 03:54:30.000000000 +0000
@@ -50,10 +50,12 @@
outputbuffer = 0;
noiselevel = CommandLine::nlNormal;
headers = new ParHeaders;
alreadyloaded = false;
+
+ cancelled = false;
}
Par2Repairer::~Par2Repairer(void)
{
delete [] (u8*)inputbuffer;
@@ -76,10 +78,11 @@
++sf;
}
delete mainpacket;
delete creatorpacket;
+ delete headers;
}
Result Par2Repairer::PreProcess(const CommandLine &commandline)
{
@@ -401,12 +404,16 @@
u32 newfraction = (u32)(1000 * offset / filesize);
if (oldfraction != newfraction)
{
cout << "Loading: " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush;
progress = offset;
- sig_progress.emit(newfraction);
+ sig_progress.emit(newfraction);
+ if (cancelled)
+ {
+ break;
+ }
}
}
// Attempt to read the next packet header
PACKET_HEADER header;
@@ -580,10 +587,15 @@
{
if (noiselevel > CommandLine::nlQuiet)
cout << "No new packets found" << endl;
delete diskfile;
}
+
+ if (cancelled)
+ {
+ return false;
+ }
return true;
}
// Finish loading a recovery packet
@@ -830,26 +842,42 @@
// Load packets from each file that was found
for (list<string>::const_iterator s=files->begin(); s!=files->end(); ++s)
{
LoadPacketsFromFile(*s);
+ if (cancelled)
+ {
+ break;
+ }
}
delete files;
+ if (cancelled)
+ {
+ return false;
+ }
}
{
string wildcard = name.empty() ? "*.PAR2" : name + ".*.PAR2";
list<string> *files = DiskFile::FindFiles(path, wildcard);
// Load packets from each file that was found
for (list<string>::const_iterator s=files->begin(); s!=files->end(); ++s)
{
LoadPacketsFromFile(*s);
+ if (cancelled)
+ {
+ break;
+ }
}
delete files;
+ if (cancelled)
+ {
+ return false;
+ }
}
return true;
}
@@ -863,13 +891,22 @@
// If the filename contains ".par2" anywhere
if (string::npos != filename.find(".par2") ||
string::npos != filename.find(".PAR2"))
{
LoadPacketsFromFile(filename);
+ if (cancelled)
+ {
+ break;
+ }
}
}
+ if (cancelled)
+ {
+ return false;
+ }
+
return true;
}
// Check that the packets are consistent and discard any that are not
bool Par2Repairer::CheckPacketConsistency(void)
@@ -1207,10 +1244,15 @@
// Start verifying the files
sf = sortedfiles.begin();
while (sf != sortedfiles.end())
{
+ if (cancelled)
+ {
+ return false;
+ }
+
// Do we have a source file
Par2RepairerSourceFile *sourcefile = *sf;
// What filename does the file use
string filename = sourcefile->TargetFileName();
@@ -1259,11 +1301,11 @@
string path;
string name;
DiskFile::SplitFilename(filename, path, name);
cout << "Target: \"" << name << "\" - missing." << endl;
- sig_done.emit(name, 0, sourcefile->GetVerificationPacket()->BlockCount());
+ sig_done.emit(name, 0, sourcefile->GetVerificationPacket() ? sourcefile->GetVerificationPacket()->BlockCount() : 0);
}
}
++sf;
}
@@ -1557,12 +1599,16 @@
u32 oldfraction = (u32)(1000 * progress / diskfile->FileSize());
u32 newfraction = (u32)(1000 * (progress = filechecksummer.Offset()) / diskfile->FileSize());
if (oldfraction != newfraction)
{
cout << "Scanning: \"" << shortname << "\": " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush;
- sig_progress.emit(newfraction);
+ sig_progress.emit(newfraction);
+ if (cancelled)
+ {
+ break;
+ }
}
}
// If we fail to find a match, it might be because it was a duplicate of a block
// that we have already found.
@@ -1648,10 +1694,15 @@
return false;
}
}
}
+ if (cancelled)
+ {
+ return false;
+ }
+
// Get the Full and 16k hash values of the file
filechecksummer.GetFileHashes(hashfull, hash16k);
// Did we make any matches at all
if (count > 0)
@@ -1802,11 +1853,11 @@
<< "\" - no data found."
<< endl;
}
}
}
- sig_done.emit(name,count,sourcefile->GetVerificationPacket()->BlockCount());
+ sig_done.emit(name,count, count>0 && sourcefile->GetVerificationPacket() ? sourcefile->GetVerificationPacket()->BlockCount() : 0);
sig_progress.emit(1000.0);
return true;
}
// Find out how much data we have found
@@ -2286,16 +2337,25 @@
u32 newfraction = (u32)(1000 * progress / totaldata);
if (oldfraction != newfraction)
{
cout << "Repairing: " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush;
- sig_progress.emit(newfraction);
+ sig_progress.emit(newfraction);
+ if (cancelled)
+ {
+ break;
+ }
}
}
}
+ if (cancelled)
+ {
+ break;
+ }
+
++inputblock;
++inputindex;
}
}
else
@@ -2343,15 +2403,24 @@
u32 newfraction = (u32)(1000 * progress / totaldata);
if (oldfraction != newfraction)
{
cout << "Processing: " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush;
- sig_progress.emit(newfraction);
+ sig_progress.emit(newfraction);
+ if (cancelled)
+ {
+ break;
+ }
}
}
+ if (cancelled)
+ {
+ break;
+ }
+
++copyblock;
++inputblock;
}
}
@@ -2359,10 +2428,15 @@
if (lastopenfile != NULL)
{
lastopenfile->Close();
}
+ if (cancelled)
+ {
+ return false;
+ }
+
if (noiselevel > CommandLine::nlQuiet)
cout << "Writing recovered data\r";
// For each output block that has been recomputed
vector<DataBlock*>::iterator outputblock = outputblocks.begin();
--- libpar2-0.2-original/par2repairer.h 2006-01-19 23:38:00.000000000 +0000
+++ libpar2-0.2/par2repairer.h 2013-01-20 03:55:03.000000000 +0000
@@ -34,10 +34,15 @@
sigc::signal<void, std::string> sig_filename;
sigc::signal<void, double> sig_progress;
sigc::signal<void, ParHeaders*> sig_headers;
sigc::signal<void, std::string, int, int> sig_done;
+ // This method allows to determine whether libpar2 includes the patches
+ // ("libpar2-0.2-bugfixes.patch") submitted to libpar2 project.
+ // Use the method in configure scripts for detection.
+ void BugfixesPatchVersion2() { }
+
protected:
// Steps in verifying and repairing files:
// Load packets from the specified file
bool LoadPacketsFromFile(string filename);
@@ -181,8 +186,9 @@
u64 progress; // How much data has been processed.
u64 totaldata; // Total amount of data to be processed.
u64 totalsize; // Total data size
+ bool cancelled; // repair cancelled
};
#endif // __PAR2REPAIRER_H__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment