2019-01-18 14:31:14 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-01-18 14:31:14 +00:00
|
|
|
|
|
|
|
#include "MacUpdater/ViewController.h"
|
|
|
|
|
2022-09-11 06:21:12 +00:00
|
|
|
#include "UpdaterCommon/Platform.h"
|
2019-02-25 22:08:03 +00:00
|
|
|
#include "UpdaterCommon/UI.h"
|
2022-10-27 20:24:36 +00:00
|
|
|
#include "UpdaterCommon/UpdaterCommon.h"
|
2019-02-25 22:08:03 +00:00
|
|
|
|
2019-01-18 14:31:14 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2019-03-03 12:56:54 +00:00
|
|
|
#include <unistd.h>
|
2019-01-18 14:31:14 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
// When we call from the main thread, we are not allowed to use
|
|
|
|
// dispatch_sync(dispatch_get_main_queue() as it will cause crashes) To prevent this check if we're
|
|
|
|
// already on the main thread first
|
|
|
|
void run_on_main(std::function<void()> fnc)
|
|
|
|
{
|
|
|
|
if (![NSThread isMainThread])
|
2019-01-20 01:24:26 +00:00
|
|
|
{
|
2019-01-18 14:31:14 +00:00
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
|
|
fnc();
|
|
|
|
});
|
2019-01-20 01:24:26 +00:00
|
|
|
}
|
2019-01-18 14:31:14 +00:00
|
|
|
else
|
2019-01-20 01:24:26 +00:00
|
|
|
{
|
2019-01-18 14:31:14 +00:00
|
|
|
fnc();
|
2019-01-20 01:24:26 +00:00
|
|
|
}
|
2019-01-18 14:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSWindow* GetWindow()
|
|
|
|
{
|
|
|
|
return [[[NSApplication sharedApplication] windows] objectAtIndex:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewController* GetView()
|
|
|
|
{
|
|
|
|
return (ViewController*)GetWindow().contentViewController;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::Error(const std::string& text)
|
|
|
|
{
|
|
|
|
run_on_main([&] {
|
|
|
|
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
|
|
|
|
|
|
|
|
[alert setMessageText:@"Fatal error"];
|
2019-05-05 23:48:12 +00:00
|
|
|
[alert setInformativeText:[NSString stringWithCString:text.c_str()
|
|
|
|
encoding:NSUTF8StringEncoding]];
|
2019-01-18 14:31:14 +00:00
|
|
|
[alert setAlertStyle:NSAlertStyleCritical];
|
|
|
|
|
|
|
|
[alert beginSheetModalForWindow:GetWindow()
|
|
|
|
completionHandler:^(NSModalResponse) {
|
|
|
|
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::SetVisible(bool visible)
|
|
|
|
{
|
|
|
|
run_on_main([&] {
|
|
|
|
if (visible)
|
|
|
|
{
|
|
|
|
[NSApp unhide:nil];
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[NSApp hide:nil];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::SetDescription(const std::string& text)
|
|
|
|
{
|
|
|
|
run_on_main([&] {
|
2019-05-05 23:48:12 +00:00
|
|
|
[GetView() SetDescription:[NSString stringWithCString:text.c_str()
|
|
|
|
encoding:NSUTF8StringEncoding]];
|
2019-01-18 14:31:14 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::SetTotalMarquee(bool marquee)
|
|
|
|
{
|
|
|
|
run_on_main([marquee] { [GetView() SetTotalMarquee:marquee]; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::SetCurrentMarquee(bool marquee)
|
|
|
|
{
|
|
|
|
run_on_main([&] { [GetView() SetCurrentMarquee:marquee]; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::ResetTotalProgress()
|
|
|
|
{
|
|
|
|
run_on_main([] { SetTotalProgress(0, 1); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::ResetCurrentProgress()
|
|
|
|
{
|
|
|
|
run_on_main([] { SetCurrentProgress(0, 1); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::SetCurrentProgress(int current, int total)
|
|
|
|
{
|
|
|
|
run_on_main([&] { [GetView() SetCurrentProgress:(double)current total:(double)total]; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::SetTotalProgress(int current, int total)
|
|
|
|
{
|
|
|
|
run_on_main([&] { [GetView() SetTotalProgress:(double)current total:(double)total]; });
|
|
|
|
}
|
2019-02-25 22:08:03 +00:00
|
|
|
|
2019-03-03 12:56:54 +00:00
|
|
|
void UI::Sleep(int seconds)
|
|
|
|
{
|
|
|
|
[NSThread sleepForTimeInterval:static_cast<float>(seconds)];
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::WaitForPID(u32 pid)
|
|
|
|
{
|
|
|
|
for (int res = kill(pid, 0); res == 0 || (res < 0 && errno == EPERM); res = kill(pid, 0))
|
|
|
|
{
|
|
|
|
UI::Sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::LaunchApplication(std::string path)
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace]
|
|
|
|
launchApplication:[NSString stringWithCString:path.c_str()
|
|
|
|
encoding:[NSString defaultCStringEncoding]]];
|
|
|
|
}
|
|
|
|
|
2019-03-21 12:47:23 +00:00
|
|
|
void UI::Stop()
|
2019-03-03 12:56:54 +00:00
|
|
|
{
|
2019-03-21 12:47:23 +00:00
|
|
|
run_on_main([] { [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0]; });
|
2019-03-03 12:56:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 12:47:23 +00:00
|
|
|
// Stub. Only needed on Windows
|
|
|
|
void UI::Init()
|
2019-02-25 22:08:03 +00:00
|
|
|
{
|
|
|
|
}
|
2022-09-11 06:21:12 +00:00
|
|
|
|
2023-03-16 06:44:14 +00:00
|
|
|
// test-updater.py only works on Windows.
|
|
|
|
bool UI::IsTestMode()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-27 20:24:36 +00:00
|
|
|
bool Platform::VersionCheck(const std::vector<TodoList::UpdateOp>& to_update,
|
2023-03-10 02:18:09 +00:00
|
|
|
const std::string& install_base_path, const std::string& temp_dir)
|
2022-09-11 06:21:12 +00:00
|
|
|
{
|
2022-10-27 20:24:36 +00:00
|
|
|
const auto op_it = std::find_if(to_update.cbegin(), to_update.cend(), [&](const auto& op) {
|
|
|
|
return op.filename == "Dolphin.app/Contents/Info.plist";
|
|
|
|
});
|
|
|
|
if (op_it == to_update.cend())
|
|
|
|
return true;
|
2022-09-11 06:21:12 +00:00
|
|
|
|
2022-10-27 20:24:36 +00:00
|
|
|
const auto op = *op_it;
|
|
|
|
std::string plist_path = temp_dir + "/" + HexEncode(op.new_hash.data(), op.new_hash.size());
|
|
|
|
|
|
|
|
NSData* data = [NSData dataWithContentsOfFile:[NSString stringWithCString:plist_path.c_str()]];
|
|
|
|
if (!data)
|
|
|
|
{
|
2023-03-10 02:18:09 +00:00
|
|
|
LogToFile("Failed to read %s, skipping platform version check.\n", plist_path.c_str());
|
2022-10-27 20:24:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSError* error = nil;
|
|
|
|
NSDictionary* info_dict =
|
|
|
|
[NSPropertyListSerialization propertyListWithData:data
|
|
|
|
options:NSPropertyListImmutable
|
|
|
|
format:nil
|
|
|
|
error:&error];
|
|
|
|
if (error)
|
|
|
|
{
|
2023-03-10 02:18:09 +00:00
|
|
|
LogToFile("Failed to parse %s, skipping platform version check.\n", plist_path.c_str());
|
2022-10-27 20:24:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
NSString* min_version_str = info_dict[@"LSMinimumSystemVersion"];
|
|
|
|
if (!min_version_str)
|
|
|
|
{
|
2023-03-10 02:18:09 +00:00
|
|
|
LogToFile("LSMinimumSystemVersion key missing, skipping platform version check.\n");
|
2022-10-27 20:24:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray* components = [min_version_str componentsSeparatedByString:@"."];
|
|
|
|
NSOperatingSystemVersion next_version{
|
|
|
|
[components[0] integerValue], [components[1] integerValue], [components[2] integerValue]};
|
|
|
|
|
2023-03-10 02:18:09 +00:00
|
|
|
LogToFile("Platform version check: next_version=%ld.%ld.%ld\n", (long)next_version.majorVersion,
|
|
|
|
(long)next_version.minorVersion, (long)next_version.patchVersion);
|
2022-10-27 20:24:36 +00:00
|
|
|
|
|
|
|
if (![[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:next_version])
|
|
|
|
{
|
|
|
|
UI::Error("Please update macOS in order to update Dolphin.");
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-11 06:21:12 +00:00
|
|
|
return true;
|
|
|
|
}
|