-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
185 lines (163 loc) · 5.19 KB
/
mainwindow.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QDialog(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
showCurrent(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::showCurrent(bool updateoption)
{
QString path = qApp->applicationDirPath();
QFile oglbak(QString("%1/opengl32.bak").arg(path));
QFile ogl(QString("%1/opengl32.dll").arg(path));
const char * name;
if (! ogl.exists())
name = "system";
else
name = "software";
ui->currentText->setText(QString("Current: %1 OpenGL").arg(name));
if(updateoption)
{
if (QString(name) == "system")
ui->systemOption->setChecked(true);
if (QString(name) == "software")
ui->softwareOption->setChecked(true);
}
}
void MainWindow::setCurrent(const char *name)
{
QString path = qApp->applicationDirPath();
QFile oglbak(QString("%1/opengl32.bak").arg(path));
QFile ogl(QString("%1/opengl32.dll").arg(path));
if (QString(name) == "software")
{
if (!ogl.exists())
{
if (!oglbak.exists())
{
QMessageBox msgBox;
msgBox.setText("Failed to find opengl files");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setInformativeText(QString("opengl32.bak"));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
else
{
if (ogl.open(QIODevice::WriteOnly|QIODevice::Truncate) == false ||
oglbak.open(QIODevice::ReadOnly) == false)
{
QMessageBox msgBox;
msgBox.setText("Failed to open opengl files");
msgBox.setIcon(QMessageBox::Critical);
if(ogl.error() != QFileDevice::NoError)
msgBox.setInformativeText(ogl.errorString());
else
msgBox.setInformativeText(oglbak.errorString());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
else
{
char buff[1024];
qint64 sz = oglbak.read(buff, sizeof(buff));
qint64 wsz = 0;
while (sz > 0 && wsz >= 0)
{
wsz = ogl.write(buff, sz);
sz = oglbak.read(buff, sizeof(buff));
}
if(wsz < 0)
{
QMessageBox msgBox;
msgBox.setText("Failed to write to opengl file");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setInformativeText(ogl.errorString());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
}
ogl.close();
oglbak.close();
}
}
}
else
{
if (ogl.exists())
{
if (oglbak.open(QIODevice::WriteOnly|QIODevice::Truncate) == false ||
ogl.open(QIODevice::ReadOnly) == false)
{
QMessageBox msgBox;
msgBox.setText("Failed to open opengl32 files");
msgBox.setIcon(QMessageBox::Critical);
if(ogl.error() != QFileDevice::NoError)
msgBox.setInformativeText(ogl.errorString());
else
msgBox.setInformativeText(oglbak.errorString());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
else
{
char buff[1024];
qint64 sz = ogl.read(buff, sizeof(buff));
qint64 wsz = 0;
while (sz > 0 && wsz >= 0)
{
wsz = oglbak.write(buff, sz);
sz = ogl.read(buff, sizeof(buff));
}
if(wsz < 0)
{
QMessageBox msgBox;
msgBox.setText("Failed to write to opengl files");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setInformativeText(oglbak.errorString());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
}
ogl.close();
oglbak.close();
if (! ogl.remove())
{
QMessageBox msgBox;
msgBox.setText("Failed to change opengl files");
msgBox.setIcon(QMessageBox::Critical);
msgBox.setInformativeText(ogl.errorString());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
}
}
showCurrent(true);
}
void MainWindow::on_buttonBox_clicked(QAbstractButton *button)
{
qDebug("pressed %s", button->text().toUtf8().data());
if(ui->buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole)
{
if(ui->systemOption->isChecked())
{
setCurrent("system");
}
else if(ui->softwareOption->isChecked())
{
setCurrent("software");
}
}
else if(ui->buttonBox->buttonRole(button) == QDialogButtonBox::RejectRole)
{
close();
}
}