Added a simple MD5 hash check to determine whether Q3A data is up to date. This determines how the install wizard selects the next page.

This commit is contained in:
Jonathan Young 2014-05-12 19:35:28 +10:00
parent 558d673ef0
commit 0e96fa145e
11 changed files with 164 additions and 5 deletions

View file

@ -2,6 +2,8 @@
#include "ui_installwizard.h"
#include "installwizard_installtype.h"
#include "installwizard_locatepage.h"
#include "installwizard_patch.h"
#include "installwizard_finished.h"
#include "settings.h"
InstallWizard::InstallWizard(QWidget *parent, Settings *settings) :
@ -15,6 +17,9 @@ InstallWizard::InstallWizard(QWidget *parent, Settings *settings) :
#ifdef Q_OS_WIN32
setPage(Page_Locate, new InstallWizard_LocatePage(this, settings));
#endif
setPage(Page_Patch, new InstallWizard_Patch());
setPage(Page_Finished, new InstallWizard_Finished());
}
InstallWizard::~InstallWizard()

View file

@ -20,7 +20,9 @@ public:
enum
{
Page_InstallType,
Page_Locate
Page_Locate,
Page_Patch,
Page_Finished
};
private slots:

View file

@ -0,0 +1,14 @@
#include "installwizard_finished.h"
#include "ui_installwizard_finished.h"
InstallWizard_Finished::InstallWizard_Finished(QWidget *parent) :
QWizardPage(parent),
ui(new Ui::InstallWizard_Finished)
{
ui->setupUi(this);
}
InstallWizard_Finished::~InstallWizard_Finished()
{
delete ui;
}

22
installwizard_finished.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef INSTALLWIZARD_FINISHED_H
#define INSTALLWIZARD_FINISHED_H
#include <QWizardPage>
namespace Ui {
class InstallWizard_Finished;
}
class InstallWizard_Finished : public QWizardPage
{
Q_OBJECT
public:
explicit InstallWizard_Finished(QWidget *parent = 0);
~InstallWizard_Finished();
private:
Ui::InstallWizard_Finished *ui;
};
#endif // INSTALLWIZARD_FINISHED_H

22
installwizard_finished.ui Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InstallWizard_Finished</class>
<widget class="QWizardPage" name="InstallWizard_Finished">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>WizardPage</string>
</property>
<property name="title">
<string>Installation Complete</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -1,13 +1,16 @@
#include <QCryptographicHash>
#include <QFileDialog>
#include <QMessageBox>
#include "installwizard_locatepage.h"
#include "ui_installwizard_locatepage.h"
#include "installwizard.h"
#include "settings.h"
InstallWizard_LocatePage::InstallWizard_LocatePage(QWidget *parent, Settings *settings) :
QWizardPage(parent),
ui(new Ui::InstallWizard_LocatePage),
settings(settings)
settings(settings),
isQuake3PatchRequired(false)
{
ui->setupUi(this);
registerField("quake3Path*", ui->txtLocation);
@ -46,5 +49,30 @@ bool InstallWizard_LocatePage::validatePage()
return false;
}
// Check if the Quake 3 installation needs patching.
const QString pakFilename(ui->txtLocation->text() + "/baseq3/pak1.pk3");
QFile file(pakFilename);
if (!file.open(QIODevice::ReadOnly))
{
QMessageBox::warning(this, "Missing file", QString("Unable to open file '%1'").arg(pakFilename));
return false;
}
const QByteArray hash = QCryptographicHash::hash(file.readAll(), QCryptographicHash::Md5).toHex();
isQuake3PatchRequired = (hash != "48911719d91be25adb957f2d325db4a0");
return true;
}
int InstallWizard_LocatePage::nextId() const
{
if (isQuake3PatchRequired)
{
return InstallWizard::Page_Patch;
}
else
{
return InstallWizard::Page_Finished;
}
}

View file

@ -23,10 +23,12 @@ private slots:
protected:
virtual bool validatePage();
virtual int nextId() const;
private:
Ui::InstallWizard_LocatePage *ui;
Settings *settings;
bool isQuake3PatchRequired;
};
#endif // INSTALLWIZARD_LOCATEPAGE_H

14
installwizard_patch.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "installwizard_patch.h"
#include "ui_installwizard_patch.h"
InstallWizard_Patch::InstallWizard_Patch(QWidget *parent) :
QWizardPage(parent),
ui(new Ui::InstallWizard_Patch)
{
ui->setupUi(this);
}
InstallWizard_Patch::~InstallWizard_Patch()
{
delete ui;
}

22
installwizard_patch.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef INSTALLWIZARD_PATCH_H
#define INSTALLWIZARD_PATCH_H
#include <QWizardPage>
namespace Ui {
class InstallWizard_Patch;
}
class InstallWizard_Patch : public QWizardPage
{
Q_OBJECT
public:
explicit InstallWizard_Patch(QWidget *parent = 0);
~InstallWizard_Patch();
private:
Ui::InstallWizard_Patch *ui;
};
#endif // INSTALLWIZARD_PATCH_H

22
installwizard_patch.ui Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InstallWizard_Patch</class>
<widget class="QWizardPage" name="InstallWizard_Patch">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>WizardPage</string>
</property>
<property name="title">
<string>Installing Patch...</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -17,18 +17,24 @@ SOURCES += main.cpp\
settings.cpp \
installwizard.cpp \
installwizard_locatepage.cpp \
installwizard_installtype.cpp
installwizard_installtype.cpp \
installwizard_finished.cpp \
installwizard_patch.cpp
HEADERS += mainwindow.h \
settings.h \
installwizard.h \
installwizard_locatepage.h \
installwizard_installtype.h
installwizard_installtype.h \
installwizard_finished.h \
installwizard_patch.h
FORMS += mainwindow.ui \
installwizard.ui \
installwizard_locatepage.ui \
installwizard_installtype.ui
installwizard_installtype.ui \
installwizard_finished.ui \
installwizard_patch.ui
OTHER_FILES += \
README.md \