Skip to content

Commit

Permalink
Merge pull request #24 from LavaGang/development
Browse files Browse the repository at this point in the history
Installer v4.0.0
  • Loading branch information
HerpDerpinstine authored Nov 16, 2024
2 parents e8e1af8 + e73bab8 commit eab98a6
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 128 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build-final.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build Installer Final

run-name: Final Build

on:
push:
branches: [ master ]

jobs:
build:
name: Build Installer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Build
run: dotnet publish

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: MelonLoader.Installer
path: Output/win-x64/
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build Installer

run-name: 4.0.0-ci.${{ github.run_number }} | ${{ github.event_name != 'workflow_dispatch' && (github.event.head_commit.message || format('`[PR]` {0}', github.event.pull_request.title)) || 'Manual Build' }}

env:
DEVVERSION: "4.0.0"

on:
push:
branches: [ development ]
pull_request:
branches: [ development ]
workflow_dispatch:

jobs:
build:
name: Build Installer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Build
run: dotnet publish -p:Version="${{ env.DEVVERSION }}.${{ github.run_number }}"

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: MelonLoader.Installer
path: Output/win-x64/
12 changes: 7 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<AvaloniaVersion>11.2.1</AvaloniaVersion>
</PropertyGroup>
</Project>
<PropertyGroup>
<Version>4.0.0</Version>

<Nullable>enable</Nullable>
<AvaloniaVersion>11.2.1</AvaloniaVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion MelonLoader.Installer/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MelonLoader.Installer;

public partial class App : Application
public class App : Application
{
public override void Initialize()
{
Expand Down
2 changes: 1 addition & 1 deletion MelonLoader.Installer/InstallerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class InstallerUtils
static InstallerUtils()
{
Http = new();
Http.DefaultRequestHeaders.Add("User-Agent", $"MelonLoader Installer v{Program.Version.ToString(3)}");
Http.DefaultRequestHeaders.Add("User-Agent", $"MelonLoader Installer v{Program.VersionName}");
}

public static async Task<string?> DownloadFileAsync(string url, Stream destination, InstallProgressEventHandler? onProgress)
Expand Down
6 changes: 3 additions & 3 deletions MelonLoader.Installer/MLManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static async Task<bool> GetVersionsAsync(List<MLVersion> versions)

try
{
resp = await InstallerUtils.Http.GetAsync(run!["artifacts_url"]!.ToString()).ConfigureAwait(false);
resp = await InstallerUtils.Http.GetAsync(run["artifacts_url"]!.ToString()).ConfigureAwait(false);
}
catch
{
Expand Down Expand Up @@ -387,7 +387,7 @@ void SetProgress(double progress, string? newStatus = null)
onProgress?.Invoke(currentTask / (double)tasks + progress / tasks, newStatus);
}

SetProgress(0, "Downloading MelonLoader " + version.ToString());
SetProgress(0, "Downloading MelonLoader " + version);

using var bufferStr = new MemoryStream();
var result = await InstallerUtils.DownloadFileAsync(downloadUrl, bufferStr, SetProgress);
Expand All @@ -400,7 +400,7 @@ void SetProgress(double progress, string? newStatus = null)

currentTask++;

SetProgress(0, "Installing " + version.ToString());
SetProgress(0, "Installing " + version);

var extRes = InstallerUtils.Extract(bufferStr, gameDir, SetProgress);
if (extRes != null)
Expand Down
4 changes: 1 addition & 3 deletions MelonLoader.Installer/MelonLoader.Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>Assets/icon.ico</ApplicationIcon>
<PublishDir>../Output/win-x64</PublishDir>
<PublishDir>../Output/$(RuntimeIdentifier)</PublishDir>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<DebugType>embedded</DebugType>
Expand All @@ -21,8 +21,6 @@

<Authors>Lava Gang</Authors>
<Company>discord.gg/2Wn3N2P</Company>

<Version>4.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions MelonLoader.Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ internal static class Program

public static event Action? Exiting;

public static Version Version { get; private set; } = typeof(Program).Assembly.GetName().Version!;
public static Version Version { get; } = typeof(Program).Assembly.GetName().Version!;

public static string VersionName { get; } =
$"v{Version.Major}.{Version.Minor}.{Version.Build}{(Version.Revision > 0 ? $"-ci.{Version.Revision}" : string.Empty)}";

// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
Expand Down Expand Up @@ -69,11 +72,8 @@ private static bool CheckProcessLock()

var procId = BitConverter.ToInt32(procIdRaw);
var proc = Process.GetProcessById(procId);
if (proc != null)
{
GrabAttention(proc);
return false;
}
GrabAttention(proc);
return false;
}
catch { return false; }
}
Expand Down
14 changes: 7 additions & 7 deletions MelonLoader.Installer/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public static class Updater

public static bool UpdateIfPossible()
{
// Don't auto-update on CI builds
if (Program.Version.Revision > 0)
return false;

var downloadUrl = CheckForUpdateAsync().GetAwaiter().GetResult();
if (downloadUrl == null)
return false;
Expand Down Expand Up @@ -87,11 +91,7 @@ private static async Task UpdateAsync(string downloadUrl)
}
}

if (Process.Start(newPath, ["-handleupdate", Environment.ProcessPath!, Environment.ProcessId.ToString()]) == null)
{
Finish("Failed to start the new installer.");
return;
}
Process.Start(newPath, ["-handleupdate", Environment.ProcessPath!, Environment.ProcessId.ToString()]);

Finish(null);
}
Expand All @@ -101,8 +101,8 @@ public static bool CheckLegacyUpdate()
if (!Environment.ProcessPath!.EndsWith(".tmp.exe", StringComparison.OrdinalIgnoreCase))
return false;

var dir = Path.GetDirectoryName(Environment.ProcessPath!)!;
var name = Path.GetFileNameWithoutExtension(Environment.ProcessPath!);
var dir = Path.GetDirectoryName(Environment.ProcessPath)!;
var name = Path.GetFileNameWithoutExtension(Environment.ProcessPath);
name = name.Remove(name.Length - 4) + ".exe";

var final = Path.Combine(dir, name);
Expand Down
18 changes: 2 additions & 16 deletions MelonLoader.Installer/ViewModels/DetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class DetailsViewModel(GameModel game) : ViewModelBase
{
private bool _installing;
private bool _confirmation;
private bool _offline;

public GameModel Game => game;
Expand All @@ -14,34 +13,21 @@ public bool Installing
set
{
_installing = value;
OnPropertyChanged(nameof(Installing));
OnPropertyChanged(nameof(CanInstall));
OnPropertyChanged();
OnPropertyChanged(nameof(EnableSettings));
}
}

public bool Confirmation
{
get => _confirmation;
set
{
_confirmation = value;
OnPropertyChanged(nameof(Confirmation));
OnPropertyChanged(nameof(CanInstall));
}
}

public bool Offline
{
get => _offline;
set
{
_offline = value;
OnPropertyChanged(nameof(Confirmation));
OnPropertyChanged();
OnPropertyChanged(nameof(EnableSettings));
}
}

public bool CanInstall => !Installing && !Confirmation;
public bool EnableSettings => !Offline && !Installing;
}
10 changes: 10 additions & 0 deletions MelonLoader.Installer/ViewModels/DialogBoxModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MelonLoader.Installer.ViewModels;

public class DialogBoxModel : ViewModelBase
{
public required string Message { get; init; }
public string ConfirmText { get; init; } = "YES";
public string CancelText { get; init; } = "NO";
public bool IsError { get; init; }
public bool IsConfirmation { get; init; }
}
2 changes: 1 addition & 1 deletion MelonLoader.Installer/ViewModels/GameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public SemVersion? MLVersion
set
{
mlVersion = value;
OnPropertyChanged(nameof(MLVersion));
OnPropertyChanged();
OnPropertyChanged(nameof(MLVersionText));
OnPropertyChanged(nameof(MLStatusText));
OnPropertyChanged(nameof(MLInstalled));
Expand Down
6 changes: 3 additions & 3 deletions MelonLoader.Installer/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MelonLoader.Installer.ViewModels;

public partial class MainViewModel : ViewModelBase
public class MainViewModel : ViewModelBase
{
private static bool _ready;

Expand All @@ -12,11 +12,11 @@ public bool Ready
set
{
_ready = value;
OnPropertyChanged(nameof(Ready));
OnPropertyChanged();
}
}

public ObservableCollection<GameModel> Games => GameManager.Games;

public string Version => 'v' + Program.Version.ToString(3);
public string Version => Program.VersionName;
}
6 changes: 2 additions & 4 deletions MelonLoader.Installer/Views/DetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:MelonLoader.Installer.ViewModels"
xmlns:views="clr-namespace:MelonLoader.Installer.Views"
xmlns:root="clr-namespace:MelonLoader.Installer"
mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="650"
x:Class="MelonLoader.Installer.Views.DetailsView"
x:DataType="vm:DetailsViewModel">
Expand Down Expand Up @@ -42,7 +40,7 @@
IsVisible="{Binding Game.MLInstalled}" IsChecked="True">Keep mods and settings</CheckBox>
</StackPanel>
<Grid Grid.Row="13" Margin="10" Width="300" HorizontalAlignment="Center">
<Grid IsVisible="{Binding CanInstall}" ColumnDefinitions="*, auto">
<Grid IsVisible="{Binding !Installing}" ColumnDefinitions="*, auto">
<Button Click="InstallHandler" IsEnabled="{Binding !Offline}" Name="InstallButton" Grid.Column="0"
HorizontalAlignment="Stretch" Background="#383" Height="40"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Expand All @@ -52,7 +50,7 @@
Background="#833" Height="40" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" FontSize="18">Uninstall</Button>
</Grid>
<Grid IsVisible="{Binding !CanInstall}">
<Grid IsVisible="{Binding Installing}">
<ProgressBar Name="Progress" Height="40" Background="#4383" Foreground="#383" />
<TextBlock Name="InstallStatus" HorizontalAlignment="Center"
VerticalAlignment="Center" Opacity="0.7" FontSize="14" />
Expand Down
19 changes: 11 additions & 8 deletions MelonLoader.Installer/Views/DetailsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void OnDataContextChanged(EventArgs e)
if (!MLManager.Init())
{
Model.Offline = true;
ErrorBox.Open("Failed to fetch MelonLoader releases. Ensure you're online.");
DialogBox.ShowError("Failed to fetch MelonLoader releases. Ensure you're online.");
}
}

Expand Down Expand Up @@ -89,8 +89,6 @@ public void UpdateVersionInfo()
if (Model == null || VersionCombobox.SelectedItem == null)
return;

Model.Confirmation = false;

MelonIcon.Opacity = Model.Game.MLInstalled ? 1 : 0.3;

if (Model.Game.MLVersion == null)
Expand Down Expand Up @@ -139,18 +137,20 @@ private void OnInstallFinished(string? errorMessage)
if (Model == null)
return;

var wasReinstall = Model.Game.MLInstalled;
Model.Game.ValidateGame();

Model.Installing = false;
NightlyCheck.IsEnabled = true;
VersionCombobox.IsEnabled = true;

if (errorMessage != null)
{
ErrorBox.Open(errorMessage);
DialogBox.ShowError(errorMessage);
return;
}

InstallStatus.Text = "Done!";
Model.Confirmation = true;
DialogBox.ShowNotice("Success!", $"{(wasReinstall ? "Reinstall" : "Install")} was Successful!");
}

private void OpenDirHandler(object sender, RoutedEventArgs args)
Expand All @@ -174,10 +174,13 @@ private void UninstallHandler(object sender, RoutedEventArgs args)

if (!MLManager.Uninstall(Path.GetDirectoryName(Model.Game.Path)!, !KeepFilesCheck.IsChecked!.Value, out var error))
{
ErrorBox.Open(error);
DialogBox.ShowError(error);
Model.Game.ValidateGame();
return;
}

Model.Game.ValidateGame();
DialogBox.ShowNotice("Success!", "Uninstall was Successful!");
}

private async void SelectZipHandler(object sender, TappedEventArgs args)
Expand Down Expand Up @@ -215,7 +218,7 @@ private async void SelectZipHandler(object sender, TappedEventArgs args)
var ver = MLManager.Versions[0];
if ((Model.Game.Is32Bit ? ver.DownloadX86Url : ver.DownloadUrl) == null)
{
ErrorBox.Open($"The selected version does not support the architechture of the current game: {(Model.Game.Is32Bit ? "x86" : "x64")}");
DialogBox.ShowError($"The selected version does not support the architechture of the current game: {(Model.Game.Is32Bit ? "x86" : "x64")}");
}
}

Expand Down
Loading

0 comments on commit eab98a6

Please sign in to comment.