Skip to content

Commit

Permalink
[Deploy] Fixed building macOS and Linux version
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Mar 29, 2021
1 parent 772ce4b commit 67612c8
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 22 deletions.
18 changes: 10 additions & 8 deletions WDE.Updater.Test/Services/UpdateServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class UpdateServiceTest
private IStandaloneUpdater standaloneUpdate = null!;
private IUpdateClient updateClient = null!;
private IUpdaterSettingsProvider settings = null!;
private IAutoUpdatePlatformService platformService = null!;

[SetUp]
public void Init()
Expand All @@ -33,6 +34,7 @@ public void Init()
standaloneUpdate = Substitute.For<IStandaloneUpdater>();
updateClient = Substitute.For<IUpdateClient>();
settings = Substitute.For<IUpdaterSettingsProvider>();
platformService = Substitute.For<IAutoUpdatePlatformService>();
clientFactory
.Create(Arg.Any<Uri>(), Arg.Any<string>(), Arg.Any<string?>(), Arg.Any<Platforms>())
.Returns(updateClient);
Expand All @@ -44,7 +46,7 @@ public void TestNoUpdateIfNoVersion()
applicationVersion.VersionKnown.Returns(false);

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

Assert.IsFalse(updateService.CanCheckForUpdates());
}
Expand All @@ -55,7 +57,7 @@ public void TestNoUpdateIfNoUpdateData()
data.HasUpdateServerData.Returns(false);

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

Assert.IsFalse(updateService.CanCheckForUpdates());
}
Expand All @@ -67,7 +69,7 @@ public void TestCanCheckForUpdatesIfHaveData()
data.HasUpdateServerData.Returns(true);

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

Assert.IsTrue(updateService.CanCheckForUpdates());
}
Expand All @@ -82,7 +84,7 @@ public async Task TestCheckForUpdatesNoUpdateLink()
.Returns(new CheckVersionResponse() {DownloadUrl = null, LatestVersion = 2});

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

Assert.IsNull(await updateService.CheckForUpdates());
}
Expand All @@ -98,7 +100,7 @@ public async Task TestCheckForUpdatesNoUpdate()
.Returns(new CheckVersionResponse() {DownloadUrl = null, LatestVersion = 1});

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

Assert.IsNull(await updateService.CheckForUpdates());
}
Expand All @@ -113,7 +115,7 @@ public async Task TestCheckForUpdatesHasUpdate()
.Returns(new CheckVersionResponse() {DownloadUrl = "localhost", LatestVersion = 2});

var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

Assert.AreEqual("localhost", await updateService.CheckForUpdates());
}
Expand All @@ -123,7 +125,7 @@ public async Task TestCloseForUpdateAsks()
{
application.CanClose().Returns(Task.FromResult(false));
var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

await updateService.CloseForUpdate();

Expand All @@ -138,7 +140,7 @@ public async Task TestCloseForUpdate()
{
application.CanClose().Returns(Task.FromResult(true));
var updateService = new UpdateService(data, clientFactory, applicationVersion, application, fileSystem,
standaloneUpdate, settings);
standaloneUpdate, settings, platformService);

await updateService.CloseForUpdate();

Expand Down
14 changes: 11 additions & 3 deletions WDE.Updater.Test/ViewModels/UpdateViewModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using NSubstitute;
using NUnit.Framework;
using WDE.Common.Managers;
using WDE.Common.Services;
using WDE.Common.Services.MessageBox;
using WDE.Common.Tasks;
using WDE.Updater.Data;
using WDE.Updater.Services;
Expand All @@ -16,6 +18,9 @@ public class UpdateViewModelTest
private ITaskRunner taskRunner = null!;
private IStatusBar statusBar = null!;
private IUpdaterSettingsProvider settingsProvider = null!;
private IAutoUpdatePlatformService platformService = null!;
private IFileSystem fileSystem = null!;
private IMessageBoxService messageBoxService = null!;

[SetUp]
public void Init()
Expand All @@ -24,13 +29,16 @@ public void Init()
taskRunner = Substitute.For<ITaskRunner>();
statusBar = Substitute.For<IStatusBar>();
settingsProvider = Substitute.For<IUpdaterSettingsProvider>();
platformService = Substitute.For<IAutoUpdatePlatformService>();
fileSystem = Substitute.For<IFileSystem>();
messageBoxService = Substitute.For<IMessageBoxService>();
}

[Test]
public void TestNoAutoUpdate()
{
settingsProvider.Settings.Returns(new UpdaterSettings() {DisableAutoUpdates = true});
new UpdateViewModel(updateService, taskRunner, statusBar, settingsProvider);
new UpdateViewModel(updateService, taskRunner, statusBar, settingsProvider, platformService, fileSystem, messageBoxService);

taskRunner.DidNotReceive().ScheduleTask(Arg.Any<string>(), Arg.Any<Func<Task>>());
}
Expand All @@ -40,7 +48,7 @@ public void TestAutoUpdate()
{
updateService.CanCheckForUpdates().Returns(true);
settingsProvider.Settings.Returns(new UpdaterSettings() {DisableAutoUpdates = false});
new UpdateViewModel(updateService, taskRunner, statusBar, settingsProvider);
new UpdateViewModel(updateService, taskRunner, statusBar, settingsProvider, platformService, fileSystem, messageBoxService);

taskRunner.Received().ScheduleTask(Arg.Any<string>(), Arg.Any<Func<Task>>());
}
Expand All @@ -49,7 +57,7 @@ public void TestAutoUpdate()
public void TestNoUpdateIfCant()
{
updateService.CanCheckForUpdates().Returns(false);
var vm = new UpdateViewModel(updateService, taskRunner, statusBar, settingsProvider);
var vm = new UpdateViewModel(updateService, taskRunner, statusBar, settingsProvider, platformService, fileSystem, messageBoxService);

taskRunner.DidNotReceive().ScheduleTask(Arg.Any<string>(), Arg.Any<Func<Task>>());
Assert.IsFalse(vm.CheckForUpdatesCommand.CanExecute(null));
Expand Down
2 changes: 1 addition & 1 deletion WDE.Updater/Client/UpdateClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IUpdateClient Create(Uri updateServerUrl, string marketplace, string? key
var httpClient = new HttpClient();
var buildVersion = applicationVersion.VersionKnown ? applicationVersion.BuildVersion : -1;
var branch = applicationVersion.VersionKnown ? applicationVersion.Branch! : "(unknown)";
httpClient.DefaultRequestHeaders.Add("User-Agent", $"WoWDatabaseEditor/{buildVersion} (branch: {branch}, marketplace: {marketplace})");
httpClient.DefaultRequestHeaders.Add("User-Agent", $"WoWDatabaseEditor/{buildVersion} (branch: {branch}, marketplace: {marketplace}, platform: {platform.ToString()})");
return new UpdateClient(updateServerUrl, marketplace, key, platform, httpClient);
}
}
Expand Down
20 changes: 20 additions & 0 deletions WDE.Updater/Services/AutoUpdatePlatformService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.IO;
using System.Runtime.InteropServices;
using WDE.Module.Attributes;

namespace WDE.Updater.Services
{
[SingleInstance]
[AutoRegister]
public class AutoUpdatePlatformService : IAutoUpdatePlatformService
{
public bool PlatformSupportsSelfInstall => !RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
public string UpdateZipFilePath => PlatformSupportsSelfInstall ? "update.zip" : "~/update.zip";
}

public interface IAutoUpdatePlatformService
{
bool PlatformSupportsSelfInstall { get; }
string UpdateZipFilePath { get; }
}
}
13 changes: 13 additions & 0 deletions WDE.Updater/Services/StandaloneUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ namespace WDE.Updater.Services
[AutoRegister]
public class StandaloneUpdater : IStandaloneUpdater
{
private readonly IAutoUpdatePlatformService platform;

public StandaloneUpdater(IAutoUpdatePlatformService platform)
{
this.platform = platform;
}

public void RenameIfNeeded()
{
if (!platform.PlatformSupportsSelfInstall)
return;

RenameIfExist("_Updater", "Updater");
RenameIfExist("_Updater.dll", "Updater.dll");
RenameIfExist("_Updater.pdb", "Updater.pdb");
Expand All @@ -28,6 +38,9 @@ private void RenameIfExist(string oldName, string newName)

public bool Launch()
{
if (!platform.PlatformSupportsSelfInstall)
return false;

if (!TryLaunch("Updater.exe"))
return TryLaunch("Updater");

Expand Down
8 changes: 6 additions & 2 deletions WDE.Updater/Services/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class UpdateService : IUpdateService
private readonly IFileSystem fileSystem;
private readonly IStandaloneUpdater standaloneUpdater;
private readonly IUpdaterSettingsProvider settings;
private readonly IAutoUpdatePlatformService platformService;
private IUpdateClient? updateClient;
private CheckVersionResponse? cachedResponse;

Expand All @@ -55,7 +56,8 @@ public UpdateService(IUpdateServerDataProvider data,
IApplication application,
IFileSystem fileSystem,
IStandaloneUpdater standaloneUpdater,
IUpdaterSettingsProvider settings)
IUpdaterSettingsProvider settings,
IAutoUpdatePlatformService platformService)
{
this.data = data;
this.clientFactory = clientFactory;
Expand All @@ -64,6 +66,7 @@ public UpdateService(IUpdateServerDataProvider data,
this.fileSystem = fileSystem;
this.standaloneUpdater = standaloneUpdater;
this.settings = settings;
this.platformService = platformService;
standaloneUpdater.RenameIfNeeded();
}

Expand Down Expand Up @@ -109,7 +112,8 @@ public async Task DownloadLatestVersion(ITaskProgress taskProgress)
(isStatusKnown ? $"{v.downloaded / 1_000_000f:0.00}/{maxProgress / 1_000_000f:0.00}MB" : $"{v.downloaded / 1_000_000f:0.00}MB"));
}
});
await UpdateClient.DownloadUpdate(cachedResponse, "update.zip", progress);
var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);
await UpdateClient.DownloadUpdate(cachedResponse, physPath.FullName, progress);

if (cachedResponse.ChangeLog?.Length > 0)
fileSystem.WriteAllText("~/changelog.json", JsonConvert.SerializeObject(cachedResponse.ChangeLog));
Expand Down
41 changes: 38 additions & 3 deletions WDE.Updater/ViewModels/UpdateViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Input;
using Prism.Commands;
using Prism.Mvvm;
using WDE.Common.Managers;
using WDE.Common.Services;
using WDE.Common.Services.MessageBox;
using WDE.Common.Tasks;
using WDE.Common.Utils;
using WDE.Module.Attributes;
Expand All @@ -19,18 +22,27 @@ public class UpdateViewModel : BindableBase
private readonly ITaskRunner taskRunner;
private readonly IStatusBar statusBar;
private readonly IUpdaterSettingsProvider settingsProvider;

private readonly IAutoUpdatePlatformService platformService;
private readonly IFileSystem fileSystem;
private readonly IMessageBoxService messageBoxService;

public ICommand CheckForUpdatesCommand { get; }

public UpdateViewModel(IUpdateService updateService,
ITaskRunner taskRunner,
IStatusBar statusBar,
IUpdaterSettingsProvider settingsProvider)
IUpdaterSettingsProvider settingsProvider,
IAutoUpdatePlatformService platformService,
IFileSystem fileSystem,
IMessageBoxService messageBoxService)
{
this.updateService = updateService;
this.taskRunner = taskRunner;
this.statusBar = statusBar;
this.settingsProvider = settingsProvider;
this.platformService = platformService;
this.fileSystem = fileSystem;
this.messageBoxService = messageBoxService;

CheckForUpdatesCommand = new DelegateCommand(() =>
{
Expand Down Expand Up @@ -77,7 +89,30 @@ private async Task DownloadUpdateTask(ITaskProgress taskProgress)
await updateService.DownloadLatestVersion(taskProgress);
statusBar.PublishNotification(new PlainNotification(NotificationType.Info,
"Update ready to install. Click here to install",
new AsyncAutoCommand(async () => await updateService.CloseForUpdate())));
new AsyncAutoCommand(async () =>
{
if (platformService.PlatformSupportsSelfInstall)
await updateService.CloseForUpdate();
else
{
await messageBoxService.ShowDialog(new MessageBoxFactory<bool>()
.SetTitle("Your platform doesn't support self updates")
.SetContent("Sadly, self updater is not available on your operating system yet.\n\nA new version of WoW Database Editor has been downloaded, but you have to manually copy new version to the Applications folder")
.Build());
var physPath = fileSystem.ResolvePhysicalPath(platformService.UpdateZipFilePath);

using Process open = new Process
{
StartInfo =
{
FileName = "open",
Arguments = "-R " + physPath.FullName,
UseShellExecute = true
}
};
open.Start();
}
})));
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IFileSystem

Stream OpenRead(string path);
Stream OpenWrite(string path);
FileSystemInfo ResolvePhysicalPath(string path);
}
}
5 changes: 5 additions & 0 deletions WoWDatabaseEditor/Services/FileSystemService/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public Stream OpenWrite(string virtualPath)
path.Directory?.Create();
return path.Open(FileMode.Create, FileAccess.Write);
}

public FileSystemInfo ResolvePhysicalPath(string path)
{
return vfs.ResolvePath(path);
}
}
}
Binary file modified WoWDatabaseEditorCore.Avalonia/Icon.afdesign
Binary file not shown.
19 changes: 17 additions & 2 deletions WoWDatabaseEditorCore.Avalonia/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
Expand All @@ -12,8 +16,19 @@ class Program
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
public static void Main(string[] args)
{
FixCurrentDirectory();
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}

private static void FixCurrentDirectory()
{
var exePath = new FileInfo(Assembly.GetExecutingAssembly().Location);
if (exePath.Directory != null)
Directory.SetCurrentDirectory(exePath.Directory.FullName);
}

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
Expand Down
26 changes: 26 additions & 0 deletions WoWDatabaseEditorCore.Avalonia/Resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>ovh.dbeditor</string>
<key>CFBundleName</key>
<string>WoWDatabaseEditor</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
<key>CFBundleExecutable</key>
<string>WoWDatabaseEditorCore.Avalonia</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
Binary file not shown.
Loading

0 comments on commit 67612c8

Please sign in to comment.