1 //  This file is part of par2cmdline (a PAR 2.0 compatible file verification and
2 //  repair tool). See http://parchive.sourceforge.net for details of PAR 2.0.
3 //
4 //  Copyright (c) 2003 Peter Brian Clements
5 //  Copyright (c) 2011 Andreas Moog
6 //
7 //  par2cmdline is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 2 of the License, or
10 //  (at your option) any later version.
11 //
12 //  par2cmdline is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20 
21 #include "libpar2.h"
22 
LibPar2(CommandLine * commandline)23 LibPar2::LibPar2(CommandLine* commandline) {
24   commandLine = commandline;
25 
26   switch (commandLine->GetVersion())
27     {
28     case CommandLine::verPar1:
29       {
30 	par1Repairer = new Par1Repairer;
31 	/*  repairer->sig_filename.connect( sigc::mem_fun(*this,&MainWindow::signal_filename));
32 	    repairer->sig_progress.connect( sigc::mem_fun(*this,&MainWindow::signal_progress));*/
33       }
34       break;
35     case CommandLine::verPar2:
36       {
37 	par2Repairer = new Par2Repairer;
38 	par2Repairer->sig_filename.
39 	  connect( sigc::mem_fun(*this, &LibPar2::signal_filename));
40 	par2Repairer->sig_progress.
41 	  connect( sigc::mem_fun(*this,&LibPar2::signal_progress));
42 	par2Repairer->sig_headers.
43 	  connect( sigc::mem_fun(*this,&LibPar2::signal_headers));
44 	par2Repairer->sig_done.
45 	  connect( sigc::mem_fun(*this,&LibPar2::signal_done));
46 	//par2Repairer->
47       }
48       break;
49     case CommandLine::opNone:
50       break;
51     }
52 }
53 
~LibPar2(void)54 LibPar2::~LibPar2(void) {
55   delete par1Repairer;
56   delete par2Repairer;
57 }
58 
59 
PreProcess()60 Result LibPar2::PreProcess() {
61   Result result = eSuccess;
62   switch (commandLine->GetVersion())
63     {
64     case CommandLine::verPar1:
65       {
66 	//result = par1Repairer->PreProcess(*commandLine);
67       }
68       break;
69     case CommandLine::verPar2:
70       {
71 	result = par2Repairer->PreProcess(*commandLine);
72       }
73       break;
74     case CommandLine::opNone:
75       break;
76     }
77   return result;
78 }
79 
Process(bool dorepair)80 Result LibPar2::Process(bool dorepair) {
81   Result result = eSuccess;
82   switch (commandLine->GetVersion())
83     {
84     case CommandLine::verPar1:
85       {
86 	result = par1Repairer->Process(*commandLine, dorepair);
87       }
88       break;
89     case CommandLine::verPar2:
90       {
91 	result = par2Repairer->Process(*commandLine, dorepair);
92       }
93       break;
94     case CommandLine::opNone:
95       break;
96     }
97   return result;
98 }
99 
signal_filename(std::string str)100 void LibPar2::signal_filename(std::string str) {
101   sig_filename.emit(str);
102 };
signal_progress(double value)103 void LibPar2::signal_progress(double value) {
104   sig_progress.emit(value);
105 };
106 
signal_headers(ParHeaders * headers)107 void LibPar2::signal_headers(ParHeaders* headers) {
108   sig_headers.emit(headers);
109 }
110 
signal_done(std::string filename,int blocks_available,int blocks_total)111 void LibPar2::signal_done(std::string filename, int blocks_available,
112 			  int blocks_total) {
113   sig_done.emit(filename, blocks_available, blocks_total);
114 }
115