Skip to content

Commit

Permalink
feat(updater): add backup download link, if update server are not ava…
Browse files Browse the repository at this point in the history
…liable
  • Loading branch information
Rooty committed Dec 1, 2023
1 parent e474657 commit 3e7f115
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
10 changes: 8 additions & 2 deletions Updater/Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void CreateUninstallEntryIfNeeded(std::wstring filename)
setUninstallDword(L"NoRepair", 1);
}

bool PerformInstallation()
bool PerformInstallation(bool updateServerAvaliable)
{
auto rootPath = GetRootPath();

Expand All @@ -78,9 +78,15 @@ bool PerformInstallation()
CreateDirectory(installPath.c_str(), nullptr);
}

std::string downloadUrl = API_URL DOWNLOAD;
if (!updateServerAvaliable)
{
downloadUrl = BACKUP_DOWNLOAD_URL;
}

SetWindowData(L"Downloading app...", 0);

DownloadFile(installPath + L"\\ToolKitV.zip", API_URL DOWNLOAD, L"ToolKitV.zip");
DownloadFile(installPath + L"\\ToolKitV.zip", downloadUrl, L"ToolKitV.zip");

SetWindowData(L"Unpacking app...", 0);

Expand Down
10 changes: 6 additions & 4 deletions Updater/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using namespace std::filesystem;

#define MAX_LOADSTRING 100
#define VERSION "1.1.0"
#define VERSION "1.2.0"

HINSTANCE hInst;
HWND hWnd;
Expand Down Expand Up @@ -252,6 +252,10 @@ void InstallOrProceed() {
DeleteFile((rootPath + L"\\" PRODUCT_NAME L"_old.exe").c_str());
}

SetWindowData(L"Checking update server...", 0);

bool updateServerAvaliable = IsUrlValid(API_URL GET_CACHES);

if (DirOrFileExists(appPath) && DirOrFileExists(appPath + exeName) && DirOrFileExists(rootPath + exeName))
{
if (ExePath() != rootPath)
Expand All @@ -275,8 +279,6 @@ void InstallOrProceed() {
return;
}

bool updateServerAvaliable = IsUrlValid(API_URL GET_CACHES);

if (updateServerAvaliable) {
std::string data = GetUrl(API_URL GET_CACHES);

Expand Down Expand Up @@ -312,7 +314,7 @@ void InstallOrProceed() {
}
else
{
if (PerformInstallation())
if (PerformInstallation(updateServerAvaliable))
{
InstallOrProceed();
}
Expand Down
1 change: 1 addition & 0 deletions Updater/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
#define DOWNLOAD_FILE "/toolkitv/files/"
#define GET_UPDATER "/toolkitv/updater"
#define GET_CACHES "/toolkitv/getCurrentFileCaches"
#define BACKUP_DOWNLOAD_URL "https://github.com/UmbrellaRE/ToolKitV/releases/latest/download/ToolKitV.zip"
#define PRODUCT_NAME L"ToolKitV"
2 changes: 1 addition & 1 deletion Updater/installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

std::wstring GetRootPath();
bool Uninstall(const wchar_t* directory);
bool PerformInstallation();
bool PerformInstallation(bool updateServerAvaliable);

0 comments on commit 3e7f115

Please sign in to comment.