Skip to content

Commit

Permalink
添加更新功能
Browse files Browse the repository at this point in the history
  • Loading branch information
GengGode committed Aug 7, 2021
1 parent c1b0d2a commit 6e7c71b
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 48 deletions.
1 change: 1 addition & 0 deletions GenshinImpactNaturalLaw/GenshinImpactNaturalLaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void GenshinImpactNaturalLaw::NewWidgetsSetting()
WidgetsSetting = new QtWidgetsSetting();
connect(WidgetsSetting, SIGNAL(SendSettingToMainWidgets()), this, SLOT(ReceiveSettingFromWidgetsSetting()));
connect(WidgetsSetting, SIGNAL(SendCloseSelfSignalToMainWidgets()), this, SLOT(ReceiveCloseSelfSignalFromWidgetsSetting()));
connect(WidgetsSetting, SIGNAL(SendCloseAllSignalToMainWidgets()), this, SLOT(close()));
WidgetsSetting->SetSetting(&setting);
WidgetsSetting->SetModules(&modules);

Expand Down
2 changes: 2 additions & 0 deletions GenshinImpactNaturalLaw/GenshinImpactNaturalLaw.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<TargetName>原神天理</TargetName>
<IncludePath>D:\Qt\5.14.2\msvc2017_64\include;D:\Qt\5.14.2\msvc2017_64\include\QtCore;D:\Qt\5.14.2\msvc2017_64\include\QtWidgets;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<TargetName>天理系统</TargetName>
<IncludePath>D:\Qt\5.14.2\msvc2017_64\include;D:\Qt\5.14.2\msvc2017_64\include\QtCore;D:\Qt\5.14.2\msvc2017_64\include\QtWidgets;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand Down
65 changes: 62 additions & 3 deletions GenshinImpactNaturalLaw/QtWidgetsSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ QtWidgetsSetting::QtWidgetsSetting(QWidget *parent)
connect(ui.pushButton_Check_5, SIGNAL(clicked()), this, SLOT(CheckOptions_UpdataLauncher()));
connect(ui.pushButton_Check_6, SIGNAL(clicked()), this, SLOT(CheckOptions_UpdataGameLauncher()));
connect(ui.pushButton_Check_7, SIGNAL(clicked()), this, SLOT(CheckOptions_UpdataGame()));

QString myVersionFilePath = QApplication::applicationDirPath() + "/version.tag";

QFile myVersionFile(myVersionFilePath);
if (!myVersionFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
}
else
{
QString line = myVersionFile.readLine();
myVersion = VersionNumber(line);
ui.label_Label_5->setText("当前版本:" + myVersion);
}
}

QtWidgetsSetting::~QtWidgetsSetting()
Expand Down Expand Up @@ -245,6 +258,50 @@ void QtWidgetsSetting::BarMove_ChangeButton()
}
}

void QtWidgetsSetting::UpdataLauncher_GetUrlVersion()
{
QString filePath = QApplication::applicationDirPath() + "/download/";
QString fileName = "version.tag";
QString savePath = filePath + fileName;

QString line = "0.0.0";
QFile readVer(savePath);
if (!readVer.open(QIODevice::ReadOnly | QIODevice::Text))
{

}
else
{
line = readVer.readLine();
}

VersionNumber newVer(line);

if (newVer > myVersion)
{
QString command = "\"" + QApplication::applicationDirPath() +"/update/UpdateProgram.exe" + "\"";
TCHAR szCmdLine[1024] = {};

command.toWCharArray(szCmdLine);
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
PROCESS_INFORMATION pi;

bool res = CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

if (res != true)
{
int k = GetLastError();
}

emit SendCloseAllSignalToMainWidgets();
this->OK();
}
}

void QtWidgetsSetting::ShowMessageBox()
{
if (WidgetsMessageBox == nullptr)
Expand Down Expand Up @@ -432,10 +489,12 @@ void QtWidgetsSetting::CheckOptions_RefreshModule()

void QtWidgetsSetting::CheckOptions_UpdataLauncher()
{
updata.setData(QUrl("https://github.com/GengGode/GenshinImpact_AutoTrack_DLL/releases/latest/download/version.tag"), "123");
updata = new UpdataModule();
updata->setData(QUrl(QString("https://github.com/GengGode/GenshinImpactNaturalLaw/releases/latest/download/version.tag")));
//updata.setData(QUrl("https://github.com/GengGode/GenshinImpact_AutoTrack_DLL/releases/latest/download/cvAutoTrack.7z"), "123");
updata.getFile();

connect(updata, &UpdataModule::finish, this, &QtWidgetsSetting::UpdataLauncher_GetUrlVersion);

updata->getFile();
}

void QtWidgetsSetting::CheckOptions_UpdataGameLauncher()
Expand Down
8 changes: 7 additions & 1 deletion GenshinImpactNaturalLaw/QtWidgetsSetting.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <windows.h>
#include <vector>
#include <QUrl>
#include <QFileInfo>
Expand Down Expand Up @@ -29,7 +30,7 @@ class QtWidgetsSetting : public QWidget
public:
SettingData *setting = nullptr;
ModulesManager *modules = nullptr;
UpdataModule updata;
UpdataModule *updata;
private:
QPoint m_Press;
QPoint m_Move;
Expand All @@ -41,6 +42,7 @@ class QtWidgetsSetting : public QWidget

QVBoxLayout *ModulesSubVBoxLayout = nullptr;
std::vector<QCheckBox*> ModulesItemCheckBoxList;
VersionNumber myVersion;
private:
std::vector<QPushButton*> UIButtonList;
std::vector<QLabel*> ScrollLabelList;
Expand All @@ -64,6 +66,9 @@ private slots:
void SwitchOptions();
void BarMove_ChangeButton();

void UpdataLauncher_GetUrlVersion();


void ShowMessageBox();

void CheckBox_SettingAutoRun(int arg);
Expand All @@ -87,4 +92,5 @@ private slots:
signals:
void SendSettingToMainWidgets();
void SendCloseSelfSignalToMainWidgets();
void SendCloseAllSignalToMainWidgets();
};
43 changes: 18 additions & 25 deletions GenshinImpactNaturalLaw/UpdataModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ UpdataModule::~UpdataModule()
cancel();
}

void UpdataModule::setData(QUrl url, QString pathtoSave)
void UpdataModule::setData(QUrl url)
{
QString sd = QSslSocket::sslLibraryBuildVersionString();
bool is= QSslSocket::supportsSsl();
downloadUrl = url;
bool is = QSslSocket::supportsSsl();

QString srte= url.toString();
downloadUrl = QUrl(url.toString());

QDir dir;
QString filePath = QApplication::applicationDirPath() + "/download/";
if (!dir.exists(filePath)) {
dir.mkpath(filePath);
}
fileName= downloadUrl.fileName();
fileName = downloadUrl.fileName();
savePath = filePath + fileName;
}

Expand All @@ -47,6 +49,7 @@ void UpdataModule::getFile()
return;
}
allBits = downloadFile->size();

httpRequestAborted = false;
//尝试获取文件
startRequest(downloadUrl);
Expand All @@ -70,6 +73,7 @@ void UpdataModule::startRequest(QUrl url)
connect(downloadReply, SIGNAL(readyRead()), this, SLOT(downloadReadyRead()));
connect(downloadReply, SIGNAL(finished()), this, SLOT(downloadFinished()));
connect(downloadReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(downloadReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
}
}

Expand Down Expand Up @@ -97,7 +101,7 @@ void UpdataModule::downloadReadyRead()
//如果文件可以访问,下载
if (downloadFile)
downloadFile->write(downloadReply->readAll());
FileBuff = FileBuff + QString(downloadReply->readAll());
FileBuff = FileBuff + QString(downloadReply->readAll());
}
void UpdataModule::downloadFinished()
{
Expand All @@ -109,14 +113,12 @@ void UpdataModule::downloadFinished()
downloadFile->flush();
downloadFile->close();



QVariant redirectionTarget = downloadReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (downloadReply->error())
{//299提示RANGE错误
//DEBUG_LOG(qsl("downloadReply error code:") + QString::number(downloadReply->error()));
//downloadFile->remove();
//emit downloadResult(-1);
{

}
else if (!redirectionTarget.isNull())
{
Expand All @@ -133,22 +135,12 @@ void UpdataModule::downloadFinished()
else
{

QString fileName = QFileInfo(downloadUrl.path()).fileName();
delete downloadFile;
downloadFile = 0;
bisFinished = true;

QString line;
QFile readVer(savePath);
if (!readVer.open(QIODevice::ReadOnly | QIODevice::Text))
if (bisFinished == false)
{
bisFinished = true;

emit finish();
}
else
{
line = readVer.readLine();
}

emit downloadResult(0);
}

Expand All @@ -158,9 +150,10 @@ void UpdataModule::downloadFinished()

void UpdataModule::downloadError(QNetworkReply::NetworkError errorCode)
{
emit downloadResult(-1);
emit downloadResult(errorCode);
}

void UpdataModule::downloadProgress(qint64, qint64)
void UpdataModule::downloadProgress(qint64 bytesSent, qint64 bytesTotal)
{
emit updateProgress(bytesSent, bytesTotal);
}
7 changes: 4 additions & 3 deletions GenshinImpactNaturalLaw/UpdataModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UpdataModule :public QObject


// 设置要下载的url和文件名
void setData(QUrl url, QString pathtoSave);
void setData(QUrl url);
//开始下载
void getFile();
void startRequest(QUrl url);
Expand Down Expand Up @@ -64,10 +64,11 @@ class UpdataModule :public QObject
//当错误发生时向外抛出错误信息
void error(QNetworkReply::NetworkError);
//抛出下载进度(更新进度条)
void updateProgress(qint64, qint64);
void updateProgress(qint64 bytesSent, qint64 bytesTotal);
//下载结果 0成功 其他失败
void downloadResult(int retCode);

void finish();

private slots:

Expand All @@ -78,6 +79,6 @@ private slots:
//下载过程中发生错误
void downloadError(QNetworkReply::NetworkError errorCode);
//下载过程进度条
void downloadProgress(qint64, qint64);
void downloadProgress(qint64 bytesSent, qint64 bytesTotal);
};

51 changes: 38 additions & 13 deletions GenshinImpactNaturalLaw/VersionNumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@ VersionNumber::VersionNumber()
{
}

VersionNumber::VersionNumber(int Major, int Minor, int Revision)
{
Major_Version_Number = Major;
Minor_Version_Number = Minor;
Revision_Number = Revision;
}

VersionNumber::VersionNumber(QString versionString)
{
VersionString = versionString;
tryToNumber(versionString);
}

VersionNumber::~VersionNumber()
{
}

VersionNumber::operator QString()
{
return QString::number(Major_Version_Number) + "." +
QString::number(Minor_Version_Number)+ "." +
QString::number(Minor_Version_Number) + "." +
QString::number(Revision_Number);
}

Expand Down Expand Up @@ -50,13 +63,19 @@ bool VersionNumber::operator>(const VersionNumber & version)
{
return true;
}
if (Minor_Version_Number > version.Minor_Version_Number)
else if (Major_Version_Number == version.Major_Version_Number)
{
return true;
}
if (Revision_Number > version.Revision_Number)
{
return true;
if (Minor_Version_Number > version.Minor_Version_Number)
{
return true;
}
else if (Minor_Version_Number == version.Minor_Version_Number)
{
if (Revision_Number > version.Revision_Number)
{
return true;
}
}
}
return false;
}
Expand All @@ -67,13 +86,19 @@ bool VersionNumber::operator<(const VersionNumber & version)
{
return true;
}
if (Minor_Version_Number < version.Minor_Version_Number)
else if (Major_Version_Number == version.Major_Version_Number)
{
return true;
}
if (Revision_Number < version.Revision_Number)
{
return true;
if (Minor_Version_Number < version.Minor_Version_Number)
{
return true;
}
else if (Minor_Version_Number == version.Minor_Version_Number)
{
if (Revision_Number < version.Revision_Number)
{
return true;
}
}
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions GenshinImpactNaturalLaw/VersionNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class VersionNumber

public:
VersionNumber();
VersionNumber(int Major, int Minor, int Revision);
VersionNumber(QString versionString);
~VersionNumber();
operator QString();
VersionNumber& operator=(const QString & versionString);
Expand Down
4 changes: 2 additions & 2 deletions GenshinImpactNaturalLaw/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ game_start_name=YuanShen.exe

[Module]
is_first_exit=false
mods_number=0
mods_0=true
mods_number=4
mods_0=false
mods_1=false
mods_2=false
mods_3=false
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# GenshinImpactNaturalLaw
原神天理启动器

[![Build status](https://ci.appveyor.com/api/projects/status/wom1ku4voacif3p3?svg=true)](https://ci.appveyor.com/project/GengGode/GenshinImpactNaturalLaw)
[![Build status](https://ci.appveyor.com/api/projects/status/wom1ku4voacif3p3?svg=true)](https://ci.appveyor.com/project/GengGode/GenshinImpactNaturalLaw)

0 comments on commit 6e7c71b

Please sign in to comment.