source: s10k/Vago/converter.cpp@ 1111

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

Vago 1.4

File size: 4.2 KB
Line 
1#include "converter.h"
2
3Converter::Converter(QString AppDir, QStringList *myData)
4{
5 this->AppDir=AppDir;
6 this->myData=myData;
7}
8
9#ifdef Q_OS_WIN
10Converter::Converter(QString AppDir, QStringList *myData, QWinTaskbarProgress *win7TaskBarProgress)
11 : Converter(AppDir, myData)
12{
13 this->win7TaskBarProgress = win7TaskBarProgress;
14}
15#endif
16
17void Converter::run()
18{
19 this->myProcess = std::make_unique<QProcess>();
20 QString result = QString();
21 QString errorMessage = "";
22 int numErrors=0;
23
24 this->myProcess->setWorkingDirectory(this->AppDir); // Set working directory (for work with AEI2/Mac OS)
25
26 LOG_INFO << "Setting OniSplit process working dir to " + this->AppDir + ".";
27
28#ifdef Q_OS_WIN
29 if(this->win7TaskBarProgress){
30 this->win7TaskBarProgress->reset();
31 this->win7TaskBarProgress->show();
32 }
33#endif
34
35 if(this->myData->size()!=1){
36#ifdef Q_OS_WIN
37 if(this->win7TaskBarProgress){
38 this->win7TaskBarProgress->setRange(0,this->myData->size());
39 }
40#endif
41 emit setupPB(this->myData->size());
42 }
43 else{
44#ifdef Q_OS_WIN
45 if(this->win7TaskBarProgress){
46 this->win7TaskBarProgress->setRange(0,0);
47 }
48#endif
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));
63 this->myProcess->start(UtilVago::getOniSplitExecutable() + " " + commandToExec);
64 this->myProcess->waitForFinished(-1);
65
66 // If the process has killed there's no need to proceed with reading output or process more commands
67 if(this->myProcess == nullptr){
68
69#ifdef Q_OS_WIN
70 if(this->win7TaskBarProgress){
71 this->win7TaskBarProgress->hide();
72 }
73#endif
74
75 this->myProcess.reset(); //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 LOG_ERROR << "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 this->myProcess.reset(); //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
127void Converter::terminateCurrProcess(){
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).";
134}
Note: See TracBrowser for help on using the repository browser.