-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdvdprocessor.cpp
118 lines (99 loc) · 2.89 KB
/
dvdprocessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <cctype>
#include <utility>
#include <QString>
#include <QStringList>
#include <QProcess>
#include "dvdprocessor.h"
#include "ptrutil.hpp"
namespace vfg {
DvdProcessor::DvdProcessor(const QString &processorPath, QObject *parent) :
QObject(parent),
processor(processorPath),
proc(vfg::make_unique<QProcess>())
{
connect(proc.get(), &QProcess::readyReadStandardOutput,
this, &DvdProcessor::updateDialog);
connect(proc.get(), static_cast<void(QProcess::*)(int)>(&QProcess::finished),
this, &DvdProcessor::handleProcessFinish);
connect(proc.get(), static_cast<void(QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
this, &DvdProcessor::handleProcessError);
}
void DvdProcessor::process(const QStringList& files)
{
if(files.empty()) {
emit error(tr("Nothing to process."));
return;
}
lastProgress = 0;
QStringList args;
args << "-ia" << "5" << "-fo" << "0" << "-yr" << "1" << "-om" << "0"
<< "-hide" << "-exit" << "-o" << outputPath << "-i" << files;
proc->start(processor, args);
}
void DvdProcessor::setProcessor(const QString &executablePath)
{
processor = executablePath;
}
void DvdProcessor::setOutputPath(const QString &newOutputPath)
{
outputPath = newOutputPath;
}
void DvdProcessor::updateDialog()
{
// Read last integer value from process output
const QByteArray rawOutput = proc->readAllStandardOutput();
QString parsedOutput;
for(int last = rawOutput.size() - 2; last >= 0; --last)
{
const char c = rawOutput.at(last);
if(std::isdigit(c)) {
parsedOutput.prepend(c);
}
else {
break;
}
}
const int currentProgress = parsedOutput.toInt();
if(currentProgress < lastProgress) {
return;
}
lastProgress = currentProgress;
emit progressUpdate(currentProgress);
}
void DvdProcessor::handleProcessFinish(const int exitCode)
{
// Non-zero exit code implies crash / abort
if(exitCode == 0) {
emit finished(savedPath());
}
}
void DvdProcessor::handleAbortProcess()
{
aborted = true;
proc->close();
}
void DvdProcessor::handleProcessError(const QProcess::ProcessError errorCode)
{
proc->close();
switch(errorCode)
{
case QProcess::FailedToStart:
emit error(tr("DGIndex.exe failed to start. Please check that the program filepath is correct and that you have sufficient permissions."));
break;
case QProcess::Crashed:
if(!aborted) {
emit error(tr("DGIndex.exe crashed. Please try again."));
}
else {
aborted = false;
}
break;
default:
emit error(tr("Error occurred while running DGIndex.exe. Error code: %1").arg(errorCode));
}
}
QString DvdProcessor::savedPath() const
{
return QString("%1.d2v").arg(outputPath);
}
} // namespace vfg