source: s10k/Vago/converter.cpp@ 1134

Last change on this file since 1134 was 1093, checked in by s10k, 7 years ago

Vago 1.4

File size: 4.2 KB
RevLine 
[771]1#include "converter.h"
2
[1093]3Converter::Converter(QString AppDir, QStringList *myData)
[771]4{
[815]5 this->AppDir=AppDir;
[771]6 this->myData=myData;
7}
8
[1047]9#ifdef Q_OS_WIN
[1093]10Converter::Converter(QString AppDir, QStringList *myData, QWinTaskbarProgress *win7TaskBarProgress)
11 : Converter(AppDir, myData)
[1047]12{
13 this->win7TaskBarProgress = win7TaskBarProgress;
14}
15#endif
16
[771]17void Converter::run()
18{
[1093]19 this->myProcess = std::make_unique<QProcess>();
[771]20 QString result = QString();
21 QString errorMessage = "";
22 int numErrors=0;
23
[1093]24 this->myProcess->setWorkingDirectory(this->AppDir); // Set working directory (for work with AEI2/Mac OS)
[815]25
[1093]26 LOG_INFO << "Setting OniSplit process working dir to " + this->AppDir + ".";
27
[1047]28#ifdef Q_OS_WIN
29 if(this->win7TaskBarProgress){
30 this->win7TaskBarProgress->reset();
31 this->win7TaskBarProgress->show();
32 }
33#endif
34
[771]35 if(this->myData->size()!=1){
[1047]36#ifdef Q_OS_WIN
37 if(this->win7TaskBarProgress){
38 this->win7TaskBarProgress->setRange(0,this->myData->size());
39 }
40#endif
[771]41 emit setupPB(this->myData->size());
42 }
43 else{
[1047]44#ifdef Q_OS_WIN
45 if(this->win7TaskBarProgress){
46 this->win7TaskBarProgress->setRange(0,0);
47 }
48#endif
[771]49 emit setupPB(0); //Intermitent bar, we don't have any estimation when the task is done
50 }
51
52 for(int i=0; i<this->myData->size(); i++){
53
54 QString commands=this->myData->at(i);
55 QString commandToExec;
56
57 int currentIndex=0, nextIndex=0;
58
59 while(true){
60 nextIndex=commands.indexOf(GlobalVars::OniSplitProcSeparator,currentIndex+1);
61
62 commandToExec=commands.mid(currentIndex,(nextIndex-currentIndex));
[1052]63 this->myProcess->start(UtilVago::getOniSplitExecutable() + " " + commandToExec);
[897]64 this->myProcess->waitForFinished(-1);
[771]65
[1093]66 // If the process has killed there's no need to proceed with reading output or process more commands
67 if(this->myProcess == nullptr){
[1047]68
69#ifdef Q_OS_WIN
70 if(this->win7TaskBarProgress){
71 this->win7TaskBarProgress->hide();
72 }
73#endif
74
[1093]75 this->myProcess.reset(); //delete object and make pointer invalid
[897]76 this->myData->clear(); //clean list
77 emit conversionAborted();
[1047]78
[897]79 return;
80 }
81
[1093]82 result = this->myProcess->readAllStandardError();
[897]83
[771]84 if(!result.isEmpty()){ //if(!result.startsWith("Importing",Qt::CaseSensitive) && !result.startsWith("Importing",Qt::CaseSensitive)){ //case sensitive is faster
85 //catch exception
[1093]86 LOG_ERROR << "Oni Split Error: \n" + this->myData->at(i) + "\n" + result;
[771]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
[1047]97#ifdef Q_OS_WIN
98 if(this->win7TaskBarProgress){
99 this->win7TaskBarProgress->setValue(win7TaskBarProgress->value()+1);
100 }
101#endif
102
[771]103 emit taskDone();
104 }
105
[1047]106#ifdef Q_OS_WIN
107 if(this->win7TaskBarProgress){
108 this->win7TaskBarProgress->hide();
109 }
110#endif
111
[1093]112 this->myProcess.reset(); //delete object and make pointer invalid
[771]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
[897]126// Kill the process if requested
127void Converter::terminateCurrProcess(){
[1093]128 if(this->myProcess != nullptr){
129 this->myProcess->kill();
130 this->myProcess.reset();
131 }
132
133 LOG_INFO << "Received signal to kill current OniSplit operation (user requested).";
[897]134}
Note: See TracBrowser for help on using the repository browser.