-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcartconv.cpp
167 lines (140 loc) · 4.59 KB
/
cartconv.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "cartconv.h"
#include "ui_cartconv.h"
CartConv::CartConv(QWidget *parent) :
QDialog(parent),
ui(new Ui::CartConv)
{
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
ui->setupUi(this);
QFile fType(":/res/data/types.txt");
if(fType.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&fType);
while(!stream.atEnd())
ui->cTypes->addItem(stream.readLine());
fType.close();
ui->cTypes->setCurrentIndex(0);
}
}
CartConv::~CartConv()
{
delete ui;
}
void CartConv::setCartConvFilename(QString &value)
{
cartconvFilename = value;
}
void CartConv::setPrgFilePath(QString prgFilePath)
{
ui->lPrgFilePath->setText(prgFilePath);
}
void CartConv::setCartName(QString name)
{
ui->lCrtCartName->setText(name);
}
void CartConv::clear()
{
ui->lPrgFilePath->clear();
ui->lCrtCartName->clear();
ui->tOutput->clear();
ui->bConvert->setFocus();
}
void CartConv::on_bPrgFilePath_clicked()
{
prgFileNames = QFileDialog::getOpenFileNames(this, tr("Select input file(s)"),
Common::appLocalDir(),
tr("Input File(s) (*.prg;*.bin;*.crt)"
));
int t = prgFileNames.count();
if (t == 0)
{
ui->lPrgFilePath->clear();
return;
}
QString strPrgFileNames = "";
for (int i=0;i<t;i++) {
strPrgFileNames += prgFileNames[i] + "|";
}
strPrgFileNames.remove(strPrgFileNames.length()-1,1);
ui->lPrgFilePath->setText(strPrgFileNames);
}
void CartConv::on_bConvert_clicked()
{
ui->tOutput->clear();
if(ui->lCrtCartName->text().isEmpty())
{
ui->tOutput->appendPlainText("Please enter CRT cart name");
ui->lCrtCartName->setFocus();
return;
}
if(ui->lPrgFilePath->text().isEmpty())
{
ui->tOutput->appendPlainText("Please browse input file(s)");
ui->lPrgFilePath->setFocus();
return;
}
QStringList inputFilenames;
inputFilenames = ui->lPrgFilePath->text().split("|");
QString firstFile;
if(ui->lPrgFilePath->text().contains('|'))
firstFile = inputFilenames[0];
else
firstFile = ui->lPrgFilePath->text();
QFileInfo fi(firstFile);
QProcess cartconvProcess;
QString cartconvOutput = QDir::cleanPath(Common::appConfigDir() + QDir::separator() + "cartconvoutput.txt");
cartconvProcess.setStandardOutputFile(cartconvOutput);
cartconvProcess.setStandardErrorFile(cartconvOutput, QIODevice::Append);
cartconvProcess.setWorkingDirectory(fi.absolutePath());
QString opFileWithoutExt = QDir::cleanPath(fi.absolutePath() + QDir::separator() + ui->lCrtCartName->text().trimmed() + ".");
// cartconv.exe -t normal -name "cartname" -i input.prg -o output.crt
QStringList parameters;
parameters << "-t"
<< ui->cTypes->currentText().split(" - ")[0]
<< "-name"
<< ui->lCrtCartName->text().trimmed();
if(ui->lPrgFilePath->text().contains('|'))
{
for (int i=0; i<prgFileNames.count();i++) {
parameters << "-i" << prgFileNames[i];
}
}
else
{
parameters << "-i" << firstFile;
}
parameters << "-o"
<< opFileWithoutExt + "crt";
cartconvProcess.start(cartconvFilename, parameters);
cartconvProcess.waitForFinished();
QFile output(cartconvOutput);
if(output.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&output);
ui->tOutput->appendPlainText(stream.readAll());
output.close();
}
if(cartconvProcess.exitCode()!=0) return;
if(ui->cConvertToBinary->isChecked())
{
// cartconv -i input.crt -o output.bin
cartconvProcess.start(cartconvFilename, QStringList() << "-i" << opFileWithoutExt + "crt" << "-o" << opFileWithoutExt + "bin");
cartconvProcess.waitForFinished();
if(output.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&output);
ui->tOutput->appendPlainText(stream.readAll());
output.close();
}
if(cartconvProcess.exitCode()!=0) return;
}
// cartconv -f input.crt
cartconvProcess.start(cartconvFilename, QStringList() << "-f" << opFileWithoutExt + "crt");
cartconvProcess.waitForFinished();
if(output.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&output);
ui->tOutput->appendPlainText(stream.readAll());
output.close();
}
}