Skip to content

Commit

Permalink
* Allow downloading the actual update archive.
Browse files Browse the repository at this point in the history
The basic idea works, but the experience is a bit weird.  I'll polish it later.
  • Loading branch information
iProgramMC committed May 12, 2024
1 parent 976f775 commit e701778
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/discord/UpdateChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ void UpdateChecker::StartCheckingForUpdates()
GetHTTPClient()->PerformRequest(true, NetRequest::GET, GetUpdateAPIURL(), 0, 0, "", "", "", OnRequestDone);
}

void UpdateChecker::DownloadUpdate(const std::string& url)
{
DbgPrintF("Downloading update: %s", url.c_str());
}

#ifdef _MSC_VER
#define IS_MINGW false
#else
Expand Down
1 change: 0 additions & 1 deletion src/discord/UpdateChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class UpdateChecker
public:
static std::string GetUpdateAPIURL();
static void StartCheckingForUpdates();
static void DownloadUpdate(const std::string& url);

private:
static void OnRequestDone(NetRequest*);
Expand Down
1 change: 1 addition & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
#define IDS_NEW_VERSION_AVAILABLE 696
#define IDS_FAILED_UPDATE_CHECK 697
#define IDS_FAILED_TO_UPLOAD 698
#define IDS_SAVED_UPDATE 699
#define IDC_OPTIONS_TABS 801
#define IDC_MY_ACCOUNT_BOX 802
#define IDC_MY_ACCOUNT_NAME 803
Expand Down
1 change: 1 addition & 0 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ BEGIN
"Discord Messenger has had a new update!\n\nYour version: %s\nLatest version: %s\n\nWould you like to download the new version?\n\nNote: No web browser window will be opened, the app itself will download the files into a location you choose.\nNote: You won't be bugged again for 3 days."
IDS_FAILED_UPDATE_CHECK "Failed to check for updates! (error %d, message '%s').\n\nTrying again when the app restarts."
IDS_FAILED_TO_UPLOAD "Error! Can't upload file %s, got error %d."
IDS_SAVED_UPDATE "Downloaded update successfully. Go extract it and enjoy!"
END

#endif // English (United States) resources
Expand Down
10 changes: 9 additions & 1 deletion src/windows/Frontend_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ void Frontend_Win32::OnUpdateAvailable(const std::string& url, const std::string
free(tstr2);

if (MessageBox(g_Hwnd, buff, TmGetTString(IDS_PROGRAM_NAME), MB_ICONINFORMATION | MB_YESNO) == IDYES)
UpdateChecker::DownloadUpdate(url);
{
size_t idx = 0, idxsave = 0;
for (; idx != url.size(); idx++) {
if (url[idx] == '/')
idxsave = idx + 1;
}

DownloadFileDialog(g_Hwnd, url, url.substr(idxsave));
}

GetLocalSettings()->StopUpdateCheckTemporarily();
}
Expand Down
11 changes: 11 additions & 0 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,17 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
DismissProfilePopout();
break;
}
case WM_IMAGESAVED:
{
// TODO: Probably should automatically extract and install it or something
MessageBox(
hWnd,
TmGetTString(IDS_SAVED_UPDATE),
TmGetTString(IDS_PROGRAM_NAME),
MB_ICONINFORMATION | MB_OK
);
break;
}

case WM_MOVE:
DismissProfilePopout();
Expand Down
3 changes: 3 additions & 0 deletions src/windows/NetworkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ void NetworkerThread::FulfillRequest(NetRequest& req)
// for now.....
client.enable_server_certificate_verification(false);

// Follow redirects. Used by GitHub auto-update service
client.set_follow_location(true);

Headers headers;
headers.insert(std::make_pair("User-Agent", GetFrontend()->GetUserAgent()));

Expand Down
6 changes: 4 additions & 2 deletions src/windows/WinUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ LPCTSTR GetFilter(const std::string& fileName)
EndsWith(fileName, ".jpeg")) return TEXT("JPG file\0*.jpg\0JPEG file\0*.jpeg\0\0");
if (EndsWith(fileName, ".gif")) return TEXT("GIF file\0*.webp\0\0");
if (EndsWith(fileName, ".webp")) return TEXT("WEBP file\0*.webp\0\0");
if (EndsWith(fileName, ".zip")) return TEXT("ZIP file\0*.zip\0\0");
return TEXT("All files\0*.*\0\0");
}

Expand All @@ -636,9 +637,10 @@ void DownloadFileDialog(HWND hWnd, const std::string& url, const std::string& fi
LPTSTR fileTitle2 = ConvertCppStringToTString(fileName);

LPTSTR buff = (LPTSTR) new TCHAR[MAX_FILE];
_tcscpy(buff, fileTitle2);
free(fileTitle2);
buff[MAX_FILE - 1] = 0;
buff[0] = 0;
_tcsncpy(buff, fileTitle2, MAX_FILE);
free(fileTitle2);

OPENFILENAME ofn{};
ofn.lStructSize = sizeof(ofn);
Expand Down
1 change: 1 addition & 0 deletions vs/DiscordMessenger.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
<Manifest Include="..\res\app.manifest" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\deps\httplib\httplib.h" />
<ClInclude Include="..\src\discord\ActiveStatus.hpp" />
<ClInclude Include="..\src\discord\Attachment.hpp" />
<ClInclude Include="..\src\discord\Channel.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions vs/DiscordMessenger.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<Filter Include="Source Files\Deps\Md5">
<UniqueIdentifier>{8baa4f98-a70c-4417-afbc-c45523d2fb51}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Deps\Httplib">
<UniqueIdentifier>{552415f8-f70b-4d64-9741-f2722deed194}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Image Include="..\res\bmp_banner.bmp">
Expand Down Expand Up @@ -500,6 +503,9 @@
<ClInclude Include="..\src\discord\UpdateChecker.hpp">
<Filter>Header Files\Windows</Filter>
</ClInclude>
<ClInclude Include="..\deps\httplib\httplib.h">
<Filter>Source Files\Deps\Httplib</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\windows\ProfileView.cpp">
Expand Down

0 comments on commit e701778

Please sign in to comment.