1 |
#include "converter.h" |
2 |
|
3 |
Converter::Converter(QString AppDir, Logger *myLogger, QStringList *myData) |
4 |
{ |
5 |
this->AppDir=AppDir; |
6 |
this->myLogger=myLogger; |
7 |
this->myData=myData; |
8 |
} |
9 |
|
10 |
void Converter::run() |
11 |
{ |
12 |
this->processHasKilled=false; |
13 |
this->myProcess = new QProcess(); |
14 |
QString result = QString(); |
15 |
QString errorMessage = ""; |
16 |
int numErrors=0; |
17 |
|
18 |
myProcess->setWorkingDirectory(this->AppDir); // Set working directory (for work with AEI2/Mac OS) |
19 |
|
20 |
if(this->myData->size()!=1){ |
21 |
emit setupPB(this->myData->size()); |
22 |
} |
23 |
else{ |
24 |
emit setupPB(0); //Intermitent bar, we don't have any estimation when the task is done |
25 |
} |
26 |
|
27 |
for(int i=0; i<this->myData->size(); i++){ |
28 |
|
29 |
QString commands=this->myData->at(i); |
30 |
QString commandToExec; |
31 |
|
32 |
int currentIndex=0, nextIndex=0; |
33 |
|
34 |
while(true){ |
35 |
nextIndex=commands.indexOf(GlobalVars::OniSplitProcSeparator,currentIndex+1); |
36 |
|
37 |
commandToExec=commands.mid(currentIndex,(nextIndex-currentIndex)); |
38 |
this->myProcess->start(GlobalVars::OniSplitExeName+" "+commandToExec); |
39 |
this->myProcess->waitForFinished(-1); |
40 |
|
41 |
if(this->processHasKilled){ // If the process has killed there's no need to proceed with reading output or process more commands |
42 |
delete this->myProcess; //delete object and make pointer invalid |
43 |
this->myData->clear(); //clean list |
44 |
emit conversionAborted(); |
45 |
return; |
46 |
} |
47 |
|
48 |
result=this->myProcess->readAllStandardError(); |
49 |
|
50 |
if(!result.isEmpty()){ //if(!result.startsWith("Importing",Qt::CaseSensitive) && !result.startsWith("Importing",Qt::CaseSensitive)){ //case sensitive is faster |
51 |
//catch exception |
52 |
myLogger->writeString("Oni Split Error: \n"+this->myData->at(i)+"\n"+result); |
53 |
errorMessage=result; |
54 |
numErrors++; |
55 |
} |
56 |
|
57 |
if(nextIndex==-1){ //we got to the end, stop proccessing commands |
58 |
break; |
59 |
} |
60 |
currentIndex=nextIndex+1; //update currentIndex +1 for start after the separator |
61 |
} |
62 |
|
63 |
emit taskDone(); |
64 |
} |
65 |
|
66 |
delete this->myProcess; //delete object and make pointer invalid |
67 |
this->myData->clear(); //clean list |
68 |
|
69 |
//let's cut it a bit, complete error is in log file. |
70 |
if(errorMessage.size()>600){ |
71 |
//limit it at 400 characters (not counting the warning at the begin) |
72 |
errorMessage.remove(299,errorMessage.size()-600); |
73 |
errorMessage.insert(299,"\n \t ... \n"); |
74 |
errorMessage.insert(0,"This error was been shortened. \nSee the complete error at Vago log file.\n\n"); |
75 |
} |
76 |
|
77 |
emit resultConversion(errorMessage,numErrors); |
78 |
} |
79 |
|
80 |
// Kill the process if requested |
81 |
void Converter::terminateCurrProcess(){ |
82 |
this->myProcess->kill(); |
83 |
this->processHasKilled=true; |
84 |
this->myLogger->writeString("Received signal to kill current OniSplit operation (user requested)."); |
85 |
} |