Skip to content

Commit

Permalink
Merge pull request dolphin-emu#11636 from shuffle2/updater-test
Browse files Browse the repository at this point in the history
Add test for Updater
  • Loading branch information
delroth authored Mar 13, 2023
2 parents 019bde6 + 06cb4ff commit a6b2655
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 86 deletions.
11 changes: 11 additions & 0 deletions Source/Core/DolphinQt/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "DolphinQt/Updater.h"

#include <cstdlib>
#include <utility>

#include <QCheckBox>
Expand Down Expand Up @@ -41,6 +42,16 @@ void Updater::CheckForUpdate()

void Updater::OnUpdateAvailable(const NewVersionInformation& info)
{
if (std::getenv("DOLPHIN_UPDATE_SERVER_URL"))
{
TriggerUpdate(info, AutoUpdateChecker::RestartMode::RESTART_AFTER_UPDATE);
RunOnObject(m_parent, [this] {
m_parent->close();
return 0;
});
return;
}

bool later = false;

std::optional<int> choice = RunOnObject(m_parent, [&] {
Expand Down
14 changes: 6 additions & 8 deletions Source/Core/MacUpdater/MacUI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ void run_on_main(std::function<void()> fnc)
}

bool Platform::VersionCheck(const std::vector<TodoList::UpdateOp>& to_update,
const std::string& install_base_path, const std::string& temp_dir,
FILE* log_fp)
const std::string& install_base_path, const std::string& temp_dir)
{
const auto op_it = std::find_if(to_update.cbegin(), to_update.cend(), [&](const auto& op) {
return op.filename == "Dolphin.app/Contents/Info.plist";
Expand All @@ -155,7 +154,7 @@ void run_on_main(std::function<void()> fnc)
NSData* data = [NSData dataWithContentsOfFile:[NSString stringWithCString:plist_path.c_str()]];
if (!data)
{
fprintf(log_fp, "Failed to read %s, skipping platform version check.\n", plist_path.c_str());
LogToFile("Failed to read %s, skipping platform version check.\n", plist_path.c_str());
return true;
}

Expand All @@ -167,23 +166,22 @@ void run_on_main(std::function<void()> fnc)
error:&error];
if (error)
{
fprintf(log_fp, "Failed to parse %s, skipping platform version check.\n", plist_path.c_str());
LogToFile("Failed to parse %s, skipping platform version check.\n", plist_path.c_str());
return true;
}
NSString* min_version_str = info_dict[@"LSMinimumSystemVersion"];
if (!min_version_str)
{
fprintf(log_fp, "LSMinimumSystemVersion key missing, skipping platform version check.\n");
LogToFile("LSMinimumSystemVersion key missing, skipping platform version check.\n");
return true;
}

NSArray* components = [min_version_str componentsSeparatedByString:@"."];
NSOperatingSystemVersion next_version{
[components[0] integerValue], [components[1] integerValue], [components[2] integerValue]};

fprintf(log_fp, "Platform version check: next_version=%ld.%ld.%ld\n",
(long)next_version.majorVersion, (long)next_version.minorVersion,
(long)next_version.patchVersion);
LogToFile("Platform version check: next_version=%ld.%ld.%ld\n", (long)next_version.majorVersion,
(long)next_version.minorVersion, (long)next_version.patchVersion);

if (![[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:next_version])
{
Expand Down
41 changes: 32 additions & 9 deletions Source/Core/UICommon/AutoUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "UICommon/AutoUpdate.h"

#include <cstdlib>
#include <string>

#include <fmt/format.h>
Expand All @@ -19,12 +20,13 @@

#ifdef _WIN32
#include <Windows.h>
#else
#include <sys/types.h>
#include <unistd.h>
#endif

#ifdef __APPLE__
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#endif

#if defined(_WIN32) || defined(__APPLE__)
Expand Down Expand Up @@ -160,6 +162,23 @@ static std::string GetPlatformID()
#endif
}

static std::string GetUpdateServerUrl()
{
auto server_url = std::getenv("DOLPHIN_UPDATE_SERVER_URL");
if (server_url)
return server_url;
return "https://dolphin-emu.org";
}

static u32 GetOwnProcessId()
{
#ifdef _WIN32
return GetCurrentProcessId();
#else
return getpid();
#endif
}

void AutoUpdateChecker::CheckForUpdate(std::string_view update_track,
std::string_view hash_override, const CheckType check_type)
{
Expand All @@ -172,7 +191,7 @@ void AutoUpdateChecker::CheckForUpdate(std::string_view update_track,
#endif

std::string_view version_hash = hash_override.empty() ? Common::GetScmRevGitStr() : hash_override;
std::string url = fmt::format("https://dolphin-emu.org/update/check/v1/{}/{}/{}", update_track,
std::string url = fmt::format("{}/update/check/v1/{}/{}/{}", GetUpdateServerUrl(), update_track,
version_hash, GetPlatformID());

const bool is_manual_check = check_type == CheckType::Manual;
Expand Down Expand Up @@ -215,7 +234,15 @@ void AutoUpdateChecker::CheckForUpdate(std::string_view update_track,
// TODO: generate the HTML changelog from the JSON information.
nvi.changelog_html = GenerateChangelog(obj["changelog"].get<picojson::array>());

OnUpdateAvailable(nvi);
if (std::getenv("DOLPHIN_UPDATE_TEST_DONE"))
{
// We are at end of updater test flow, send a message to server, which will kill us.
req.Get(fmt::format("{}/update-test-done/{}", GetUpdateServerUrl(), GetOwnProcessId()));
}
else
{
OnUpdateAvailable(nvi);
}
}

void AutoUpdateChecker::TriggerUpdate(const AutoUpdateChecker::NewVersionInformation& info,
Expand All @@ -234,11 +261,7 @@ void AutoUpdateChecker::TriggerUpdate(const AutoUpdateChecker::NewVersionInforma
updater_flags["this-manifest-url"] = info.this_manifest_url;
updater_flags["next-manifest-url"] = info.next_manifest_url;
updater_flags["content-store-url"] = info.content_store_url;
#ifdef _WIN32
updater_flags["parent-pid"] = std::to_string(GetCurrentProcessId());
#else
updater_flags["parent-pid"] = std::to_string(getpid());
#endif
updater_flags["parent-pid"] = std::to_string(GetOwnProcessId());
updater_flags["install-base-path"] = File::GetExeDirectory();
updater_flags["log-file"] = File::GetUserPath(D_LOGS_IDX) + UPDATER_LOG_FILE;

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/UpdaterCommon/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
namespace Platform
{
bool VersionCheck(const std::vector<TodoList::UpdateOp>& to_update,
const std::string& install_base_path, const std::string& temp_dir, FILE* log_fp);
const std::string& install_base_path, const std::string& temp_dir);
} // namespace Platform
2 changes: 2 additions & 0 deletions Source/Core/UpdaterCommon/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ void Init();
void Sleep(int seconds);
void WaitForPID(u32 pid);
void LaunchApplication(std::string path);

bool IsTestMode();
} // namespace UI
Loading

0 comments on commit a6b2655

Please sign in to comment.