Skip to content

Commit b58cc99

Browse files
committed
Update UpdateCheckAPI.
1 parent e3e8a83 commit b58cc99

File tree

7 files changed

+52
-30
lines changed

7 files changed

+52
-30
lines changed

AMDToolsDownloader/AMDToolsDownloader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func main() {
1212

1313
argCount := len(os.Args[1:])
1414
if (argCount != 2) {
15-
fmt.Printf("Usage: urlDownload url localPath\n")
15+
fmt.Printf("Usage: AMDToolsDownloader url localPath\n")
1616
fmt.Printf("\turl - The url to the file to download\n")
1717
fmt.Printf("\tlocalPath - The path and filename to save the downloaded file\n")
1818
os.Exit(1)
@@ -25,7 +25,6 @@ func main() {
2525
if (err != nil) {
2626
panic(err)
2727
}
28-
2928
}
3029

3130

Include/UpdateCheckApiStrings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const char* const STR_ERROR_DOWNLOAD_URL_NOT_FOUND_IN_ASSET = "The download url
112112
// High Level Error Messages.
113113
const char* const STR_ERROR_URL_MUST_POINT_TO_A_JSON_FILE = "URL must point to a JSON file.";
114114
const char* const STR_ERROR_FAILED_TO_LAUNCH_VERSION_FILE_DOWNLOADER = "Failed to launch the AMD Tools Downloader.";
115+
const char* const STR_ERROR_FAILED_TO_LOAD_LATEST_RELEASE_INFORMATION = "Failed to load latest release information.";
115116
const char* const STR_ERROR_FAILED_TO_DOWNLOAD_VERSION_FILE = "Failed to download version file.";
116117
const char* const STR_ERROR_FAILED_TO_LOAD_VERSION_FILE = "Failed to load version file.";
117118
const char* const STR_ERROR_DOWNLOADED_AN_EMPTY_VERSION_FILE = "Downloaded an empty version file.";

Include/UpdateCheckResultsDialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class UpdateCheckResultsDialog : public QDialog
2626

2727
void SetResults(const UpdateCheck::Results& results);
2828
void SetResults(const UpdateCheck::UpdateInfo& updateInfo);
29+
void SetShowTags(bool showTags);
2930

3031
private:
3132
Ui::UpdateCheckResultsDialog *ui;
33+
bool m_showTags = true;
3234
};

Include/UpdateCheckThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//==============================================================================
99
#pragma once
1010

11-
#include <UpdateCheckApi.h>
11+
#include "UpdateCheckApi.h"
1212
#include <QThread>
1313

1414
namespace UpdateCheck

Source/UpdateCheckApi.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,38 @@ static bool LoadJsonFromLatestRelease(const std::string jsonFileUrl, const std::
235235
}
236236
else
237237
{
238-
std::string latestReleaseJson;
239-
if (LoadJsonFile(latestReleaseApiTempFile, latestReleaseJson, errorMessage))
238+
try
240239
{
241-
json latestReleaseJsonDoc = json::parse(latestReleaseJson);
242-
243-
std::string versionFileUrl;
244-
if (FindAssetDownloadUrl(latestReleaseJsonDoc, jsonFileName, versionFileUrl, errorMessage))
245-
{
246-
wasLoaded = DownloadJsonFile(versionFileUrl, jsonString, errorMessage);
247-
}
248-
else
240+
std::string latestReleaseJson;
241+
if (LoadJsonFile(latestReleaseApiTempFile, latestReleaseJson, errorMessage))
249242
{
250-
// Failed to find the Asset, so check for a "message" tag which may indicate an error from the GitHub Release API.
251-
auto messageElement = latestReleaseJsonDoc.find(TAG_MESSAGE);
243+
// Parsing the json can throw an exception if the string is
244+
// not valid json. This can happen in networks that limit
245+
// internet access, and result in downloading an html page.
246+
json latestReleaseJsonDoc = json::parse(latestReleaseJson);
252247

253-
if (messageElement != latestReleaseJsonDoc.end())
248+
std::string versionFileUrl;
249+
if (FindAssetDownloadUrl(latestReleaseJsonDoc, jsonFileName, versionFileUrl, errorMessage))
250+
{
251+
wasLoaded = DownloadJsonFile(versionFileUrl, jsonString, errorMessage);
252+
}
253+
else
254254
{
255-
errorMessage.append(messageElement->get<std::string>().c_str());
255+
// Failed to find the Asset, so check for a "message" tag which may indicate an error from the GitHub Release API.
256+
auto messageElement = latestReleaseJsonDoc.find(TAG_MESSAGE);
257+
258+
if (messageElement != latestReleaseJsonDoc.end())
259+
{
260+
errorMessage.append(messageElement->get<std::string>().c_str());
261+
}
256262
}
257263
}
258264
}
265+
catch (...)
266+
{
267+
wasLoaded = false;
268+
errorMessage.append(STR_ERROR_FAILED_TO_LOAD_LATEST_RELEASE_INFORMATION);
269+
}
259270
}
260271

261272
return wasLoaded;

Source/UpdateCheckResultsDialog.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,23 @@ void UpdateCheckResultsDialog::SetResults(const UpdateCheck::UpdateInfo& updateI
8585
updateResultHtml.append(releaseIter->m_date.c_str());
8686
updateResultHtml.append(STR_HTML_NEWLINE);
8787

88-
if (!releaseIter->m_tags.empty())
88+
if (m_showTags)
8989
{
90-
updateResultHtml.append(STR_TAGS);
91-
updateResultHtml.append(releaseIter->m_tags[0].c_str());
92-
93-
for (size_t i = 1; i != releaseIter->m_tags.size(); ++i)
90+
if (!releaseIter->m_tags.empty())
9491
{
95-
updateResultHtml.append(STR_TAGS_SEPARATOR);
96-
updateResultHtml.append(releaseIter->m_tags[i].c_str());
92+
updateResultHtml.append(STR_TAGS);
93+
updateResultHtml.append(releaseIter->m_tags[0].c_str());
94+
95+
for (size_t i = 1; i != releaseIter->m_tags.size(); ++i)
96+
{
97+
updateResultHtml.append(STR_TAGS_SEPARATOR);
98+
updateResultHtml.append(releaseIter->m_tags[i].c_str());
99+
}
97100
}
101+
102+
updateResultHtml.append(STR_HTML_NEWLINE);
98103
}
99104

100-
updateResultHtml.append(STR_HTML_NEWLINE);
101105
updateResultHtml.append(STR_HTML_NEWLINE);
102106

103107
// Display download links.
@@ -106,8 +110,8 @@ void UpdateCheckResultsDialog::SetResults(const UpdateCheck::UpdateInfo& updateI
106110
updateResultHtml.append(STR_UPDATES_DOWNLOAD_THIS_RELEASE_FROM);
107111
updateResultHtml.append(STR_HTML_NEWLINE);
108112

109-
// Sample output: "Windows: [MSI] [ZIP] [ZIP]" with the full hyperlink as a tooltip over the MSI, ZIP, ZIP to allow
110-
// users to distinquish between the two ZIP files.
113+
// Sample output: "Windows: [MSI] [ZIP] [ZIP]" with the full hyper link as a tooltip over the MSI, ZIP, ZIP to allow
114+
// users to distinguish between the two ZIP files.
111115
for (auto platformIter = releaseIter->m_targetPlatforms.cbegin(); platformIter != releaseIter->m_targetPlatforms.cend(); ++platformIter)
112116
{
113117
updateResultHtml.append(STR_HTML_DIV_INDENT_40_OPEN);
@@ -134,7 +138,7 @@ void UpdateCheckResultsDialog::SetResults(const UpdateCheck::UpdateInfo& updateI
134138
updateResultHtml.append(STR_HTML_NEWLINE);
135139
}
136140

137-
// Diplay additional info links.
141+
// Display additional info links.
138142
if (!releaseIter->m_infoLinks.empty())
139143
{
140144
updateResultHtml.append(STR_UPDATES_FOR_MORE_INFORMATION_VISIT);
@@ -179,3 +183,8 @@ void UpdateCheckResultsDialog::SetResults(const UpdateCheck::Results& results)
179183
SetResults(results.updateInfo);
180184
}
181185
}
186+
187+
void UpdateCheckResultsDialog::SetShowTags(bool showTags)
188+
{
189+
m_showTags = showTags;
190+
}

Source/UpdateCheckResultsDialog.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>532</width>
10-
<height>360</height>
9+
<width>400</width>
10+
<height>300</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">

0 commit comments

Comments
 (0)