ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/converter.cpp
(Generate patch)

Comparing:
Vago/trunk/Vago/converter.cpp (file contents), Revision 771 by s10k, Sun Mar 31 19:02:16 2013 UTC vs.
s10k/Vago/converter.cpp (file contents), Revision 1093 by s10k, Sat Dec 30 13:57:32 2017 UTC

# Line 1 | Line 1
1   #include "converter.h"
2  
3 < Converter::Converter(Logger *myLogger, QStringList *myData)
3 > Converter::Converter(QString AppDir, QStringList *myData)
4   {
5 <    this->myLogger=myLogger;
5 >    this->AppDir=AppDir;
6      this->myData=myData;
7   }
8  
9 + #ifdef Q_OS_WIN
10 + Converter::Converter(QString AppDir, QStringList *myData, QWinTaskbarProgress *win7TaskBarProgress)
11 +    : Converter(AppDir, myData)
12 + {
13 +    this->win7TaskBarProgress = win7TaskBarProgress;
14 + }
15 + #endif
16 +
17   void Converter::run()
18   {
19 <    QProcess *myProcess = new QProcess();
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  
23    //myProcess->setProcessChannelMode(QProcess::MergedChannels); //we want both stdout and stderr
24
52      for(int i=0; i<this->myData->size(); i++){
53  
54          QString commands=this->myData->at(i);
# Line 33 | Line 60 | void Converter::run()
60              nextIndex=commands.indexOf(GlobalVars::OniSplitProcSeparator,currentIndex+1);
61  
62              commandToExec=commands.mid(currentIndex,(nextIndex-currentIndex));
63 <            myProcess->start(GlobalVars::OniSplitExeName+" "+commandToExec);
64 <            myProcess->waitForFinished(-1);
65 <            result=myProcess->readAllStandardError();
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 <                myLogger->writeString("Oni Split Error: \n"+this->myData->at(i)+"\n"+result);
86 >                LOG_ERROR << "Oni Split Error: \n" + this->myData->at(i) + "\n" + result;
87                  errorMessage=result;
88                  numErrors++;
89              }
# Line 50 | Line 94 | void Converter::run()
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 <    delete myProcess; //delete object and make pointer invalid
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.
# Line 67 | Line 123 | void Converter::run()
123      emit resultConversion(errorMessage,numErrors);
124   }
125  
126 + // Kill the process if requested
127 + void 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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)