| 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 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 11 | Converter::Converter(QString AppDir, Logger *myLogger, QStringList *myData, QWinTaskbarProgress *win7TaskBarProgress) | 
 
 
 
 
 | 12 | : Converter(AppDir, myLogger, myData) | 
 
 
 
 
 | 13 | { | 
 
 
 
 
 | 14 | this->win7TaskBarProgress = win7TaskBarProgress; | 
 
 
 
 
 | 15 | } | 
 
 
 
 
 | 16 | #endif | 
 
 
 
 
 | 17 |  | 
 
 
 
 
 | 18 | void Converter::run() | 
 
 
 
 
 | 19 | { | 
 
 
 
 
 | 20 | this->processHasKilled=false; | 
 
 
 
 
 | 21 | this->myProcess = new QProcess(); | 
 
 
 
 
 | 22 | QString result = QString(); | 
 
 
 
 
 | 23 | QString errorMessage = ""; | 
 
 
 
 
 | 24 | int numErrors=0; | 
 
 
 
 
 | 25 |  | 
 
 
 
 
 | 26 | this->myLogger->writeString("Setting OniSplit process working dir to "+this->AppDir+"."); | 
 
 
 
 
 | 27 | myProcess->setWorkingDirectory(this->AppDir); // Set working directory (for work with AEI2/Mac OS) | 
 
 
 
 
 | 28 |  | 
 
 
 
 
 | 29 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 30 | if(this->win7TaskBarProgress){ | 
 
 
 
 
 | 31 | this->win7TaskBarProgress->reset(); | 
 
 
 
 
 | 32 | this->win7TaskBarProgress->show(); | 
 
 
 
 
 | 33 | } | 
 
 
 
 
 | 34 | #endif | 
 
 
 
 
 | 35 |  | 
 
 
 
 
 | 36 | if(this->myData->size()!=1){ | 
 
 
 
 
 | 37 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 38 | if(this->win7TaskBarProgress){ | 
 
 
 
 
 | 39 | this->win7TaskBarProgress->setRange(0,this->myData->size()); | 
 
 
 
 
 | 40 | } | 
 
 
 
 
 | 41 | #endif | 
 
 
 
 
 | 42 | emit setupPB(this->myData->size()); | 
 
 
 
 
 | 43 | } | 
 
 
 
 
 | 44 | else{ | 
 
 
 
 
 | 45 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 46 | if(this->win7TaskBarProgress){ | 
 
 
 
 
 | 47 | this->win7TaskBarProgress->setRange(0,0); | 
 
 
 
 
 | 48 | } | 
 
 
 
 
 | 49 | #endif | 
 
 
 
 
 | 50 | emit setupPB(0); //Intermitent bar, we don't have any estimation when the task is done | 
 
 
 
 
 | 51 | } | 
 
 
 
 
 | 52 |  | 
 
 
 
 
 | 53 | for(int i=0; i<this->myData->size(); i++){ | 
 
 
 
 
 | 54 |  | 
 
 
 
 
 | 55 | QString commands=this->myData->at(i); | 
 
 
 
 
 | 56 | QString commandToExec; | 
 
 
 
 
 | 57 |  | 
 
 
 
 
 | 58 | int currentIndex=0, nextIndex=0; | 
 
 
 
 
 | 59 |  | 
 
 
 
 
 | 60 | while(true){ | 
 
 
 
 
 | 61 | nextIndex=commands.indexOf(GlobalVars::OniSplitProcSeparator,currentIndex+1); | 
 
 
 
 
 | 62 |  | 
 
 
 
 
 | 63 | commandToExec=commands.mid(currentIndex,(nextIndex-currentIndex)); | 
 
 
 
 
 | 64 | this->myProcess->start(UtilVago::getOniSplitExecutable() + " " + commandToExec); | 
 
 
 
 
 | 65 | this->myProcess->waitForFinished(-1); | 
 
 
 
 
 | 66 |  | 
 
 
 
 
 | 67 | if(this->processHasKilled){ // If the process has killed there's no need to proceed with reading output or process more commands | 
 
 
 
 
 | 68 |  | 
 
 
 
 
 | 69 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 70 | if(this->win7TaskBarProgress){ | 
 
 
 
 
 | 71 | this->win7TaskBarProgress->hide(); | 
 
 
 
 
 | 72 | } | 
 
 
 
 
 | 73 | #endif | 
 
 
 
 
 | 74 |  | 
 
 
 
 
 | 75 | delete this->myProcess; //delete object and make pointer invalid | 
 
 
 
 
 | 76 | this->myData->clear(); //clean list | 
 
 
 
 
 | 77 | emit conversionAborted(); | 
 
 
 
 
 | 78 |  | 
 
 
 
 
 | 79 | return; | 
 
 
 
 
 | 80 | } | 
 
 
 
 
 | 81 |  | 
 
 
 
 
 | 82 | result=this->myProcess->readAllStandardError(); | 
 
 
 
 
 | 83 |  | 
 
 
 
 
 | 84 | if(!result.isEmpty()){ //if(!result.startsWith("Importing",Qt::CaseSensitive) && !result.startsWith("Importing",Qt::CaseSensitive)){ //case sensitive is faster | 
 
 
 
 
 | 85 | //catch exception | 
 
 
 
 
 | 86 | myLogger->writeString("Oni Split Error: \n"+this->myData->at(i)+"\n"+result); | 
 
 
 
 
 | 87 | errorMessage=result; | 
 
 
 
 
 | 88 | numErrors++; | 
 
 
 
 
 | 89 | } | 
 
 
 
 
 | 90 |  | 
 
 
 
 
 | 91 | if(nextIndex==-1){ //we got to the end, stop proccessing commands | 
 
 
 
 
 | 92 | break; | 
 
 
 
 
 | 93 | } | 
 
 
 
 
 | 94 | currentIndex=nextIndex+1; //update currentIndex +1 for start after the separator | 
 
 
 
 
 | 95 | } | 
 
 
 
 
 | 96 |  | 
 
 
 
 
 | 97 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 98 | if(this->win7TaskBarProgress){ | 
 
 
 
 
 | 99 | this->win7TaskBarProgress->setValue(win7TaskBarProgress->value()+1); | 
 
 
 
 
 | 100 | } | 
 
 
 
 
 | 101 | #endif | 
 
 
 
 
 | 102 |  | 
 
 
 
 
 | 103 | emit taskDone(); | 
 
 
 
 
 | 104 | } | 
 
 
 
 
 | 105 |  | 
 
 
 
 
 | 106 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 107 | if(this->win7TaskBarProgress){ | 
 
 
 
 
 | 108 | this->win7TaskBarProgress->hide(); | 
 
 
 
 
 | 109 | } | 
 
 
 
 
 | 110 | #endif | 
 
 
 
 
 | 111 |  | 
 
 
 
 
 | 112 | delete this->myProcess; //delete object and make pointer invalid | 
 
 
 
 
 | 113 | this->myData->clear(); //clean list | 
 
 
 
 
 | 114 |  | 
 
 
 
 
 | 115 | //let's cut it a bit, complete error is in log file. | 
 
 
 
 
 | 116 | if(errorMessage.size()>600){ | 
 
 
 
 
 | 117 | //limit it at 400 characters (not counting the warning at the begin) | 
 
 
 
 
 | 118 | errorMessage.remove(299,errorMessage.size()-600); | 
 
 
 
 
 | 119 | errorMessage.insert(299,"\n \t ... \n"); | 
 
 
 
 
 | 120 | errorMessage.insert(0,"This error was been shortened. \nSee the complete error at Vago log file.\n\n"); | 
 
 
 
 
 | 121 | } | 
 
 
 
 
 | 122 |  | 
 
 
 
 
 | 123 | emit resultConversion(errorMessage,numErrors); | 
 
 
 
 
 | 124 | } | 
 
 
 
 
 | 125 |  | 
 
 
 
 
 | 126 | // Kill the process if requested | 
 
 
 
 
 | 127 | void Converter::terminateCurrProcess(){ | 
 
 
 
 
 | 128 | this->myProcess->kill(); | 
 
 
 
 
 | 129 | this->processHasKilled=true; | 
 
 
 
 
 | 130 | this->myLogger->writeString("Received signal to kill current OniSplit operation (user requested)."); | 
 
 
 
 
 | 131 | } |