-
Notifications
You must be signed in to change notification settings - Fork 101
Add a user-friendly OpenKH launcher #1271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yokimitsuro
wants to merge
5
commits into
OpenKH:master
Choose a base branch
from
Yokimitsuro:feature/user-friendly-experience
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5935f94
Add user-friendly launcher and organized release layout
Yokimitsuro 8876e3f
Support automatic migration to the organized release layout
Yokimitsuro 6cbd97d
Fix release archive validation
Yokimitsuro fab1911
Preserve updates and shortcuts in launcher layout
Yokimitsuro 2df7655
Run update flow inside launcher
Yokimitsuro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| param ( | ||
| [string] $BuildDirectory = "bin", | ||
| [string] $ReleaseDirectory = "openkh", | ||
| [string] $Configuration = "Release" | ||
| ) | ||
|
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| if (-not (Test-Path -LiteralPath $BuildDirectory -PathType Container)) { | ||
| throw "Build directory '$BuildDirectory' does not exist." | ||
| } | ||
|
|
||
| if (Test-Path -LiteralPath $ReleaseDirectory) { | ||
| throw "Release directory '$ReleaseDirectory' already exists." | ||
| } | ||
|
|
||
| New-Item -ItemType Directory -Path $ReleaseDirectory | Out-Null | ||
|
|
||
| $applicationsDirectory = Join-Path $ReleaseDirectory "Apps" | ||
| $modManagerDirectory = Join-Path $applicationsDirectory "ModManager" | ||
| New-Item -ItemType Directory -Path $modManagerDirectory -Force | Out-Null | ||
|
|
||
| $legacyFileManifest = Join-Path $applicationsDirectory "legacy-release-files.txt" | ||
| $legacyDirectoryManifest = Join-Path $applicationsDirectory "legacy-release-directories.txt" | ||
| Get-ChildItem -LiteralPath $BuildDirectory -File | | ||
| Select-Object -ExpandProperty Name | | ||
| Sort-Object | | ||
| Set-Content -LiteralPath $legacyFileManifest -Encoding UTF8 | ||
| Get-ChildItem -LiteralPath $BuildDirectory -Directory | | ||
| Select-Object -ExpandProperty Name | | ||
| Sort-Object | | ||
| Set-Content -LiteralPath $legacyDirectoryManifest -Encoding UTF8 | ||
|
|
||
| dotnet publish ` | ||
| "OpenKh.Tools.Launcher/OpenKh.Tools.Launcher.csproj" ` | ||
| --configuration $Configuration ` | ||
| --runtime win-x64 ` | ||
| --self-contained false ` | ||
| --output $ReleaseDirectory ` | ||
| /p:PublishSingleFile=true ` | ||
| /p:DebugType=None ` | ||
| /p:DebugSymbols=false | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Publishing OpenKH Launcher failed with exit code $LASTEXITCODE." | ||
| } | ||
|
|
||
| $compatibilityExecutable = Join-Path $ReleaseDirectory "OpenKh.Tools.ModsManager.exe" | ||
| Copy-Item ` | ||
| -LiteralPath (Join-Path $ReleaseDirectory "OpenKh.Launcher.exe") ` | ||
| -Destination $compatibilityExecutable | ||
| (Get-Item -LiteralPath $compatibilityExecutable).Attributes += "Hidden" | ||
|
|
||
| dotnet publish ` | ||
| "OpenKh.Tools.ModsManager/OpenKh.Tools.ModsManager.csproj" ` | ||
| --configuration $Configuration ` | ||
| --output $modManagerDirectory ` | ||
| /p:DebugType=None ` | ||
| /p:DebugSymbols=false | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Publishing Mods Manager failed with exit code $LASTEXITCODE." | ||
| } | ||
|
|
||
| $referencedCommandArtifacts = Get-ChildItem -LiteralPath $modManagerDirectory -File | Where-Object { | ||
| $_.Name -like "OpenKh.Command.*" -and $_.Extension -ne ".dll" | ||
| } | ||
|
|
||
| foreach ($referencedCommandArtifact in $referencedCommandArtifacts) { | ||
| Remove-Item -LiteralPath $referencedCommandArtifact.FullName | ||
| } | ||
|
|
||
| $panaceaFiles = @( | ||
| "OpenKH.Panacea.dll", | ||
| "avcodec-vgmstream-59.dll", | ||
| "avformat-vgmstream-59.dll", | ||
| "avutil-vgmstream-57.dll", | ||
| "bass.dll", | ||
| "bass_vgmstream.dll", | ||
| "libatrac9.dll", | ||
| "libcelt-0061.dll", | ||
| "libcelt-0110.dll", | ||
| "libg719_decode.dll", | ||
| "libmpg123-0.dll", | ||
| "libspeex-1.dll", | ||
| "libvorbis.dll", | ||
| "swresample-vgmstream-4.dll" | ||
| ) | ||
|
|
||
| foreach ($fileName in $panaceaFiles) { | ||
| $sourcePath = Join-Path $BuildDirectory $fileName | ||
| if (-not (Test-Path -LiteralPath $sourcePath -PathType Leaf)) { | ||
| throw "Required Panacea file '$sourcePath' does not exist." | ||
| } | ||
|
|
||
| Copy-Item -LiteralPath $sourcePath -Destination $modManagerDirectory | ||
| } | ||
|
|
||
| Copy-Item -LiteralPath "distribution/README-FIRST.txt" -Destination $ReleaseDirectory | ||
| Copy-Item -LiteralPath "LICENSE" -Destination $ReleaseDirectory | ||
| Copy-Item -LiteralPath "NOTICE" -Destination $ReleaseDirectory | ||
|
|
||
| $advancedToolsDirectory = Join-Path $ReleaseDirectory "AdvancedTools" | ||
| Move-Item -LiteralPath $BuildDirectory -Destination $advancedToolsDirectory | ||
|
|
||
| $duplicateApplicationFiles = Get-ChildItem -LiteralPath $advancedToolsDirectory -File | Where-Object { | ||
| $_.Name -like "OpenKh.Launcher.*" -or | ||
| $_.Name -like "OpenKh.Tools.ModsManager.*" | ||
| } | ||
|
|
||
| foreach ($duplicateFile in $duplicateApplicationFiles) { | ||
| Remove-Item -LiteralPath $duplicateFile.FullName | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using OpenKh.Tools.ModsManager.Services; | ||
| using Xunit; | ||
|
|
||
| namespace OpenKh.Tests.ModsManager | ||
| { | ||
| public class OpenkhInstallationTest | ||
| { | ||
| [Theory] | ||
| [InlineData(@"C:\OpenKh", @"C:\OpenKh")] | ||
| [InlineData(@"C:\OpenKh\Apps\ModManager", @"C:\OpenKh")] | ||
| [InlineData(@"C:\OpenKh\apps\modmanager", @"C:\OpenKh")] | ||
| public void GetDirectoryReturnsInstallationRoot(string applicationDirectory, string expectedDirectory) | ||
| { | ||
| Assert.Equal( | ||
| Path.GetFullPath(expectedDirectory), | ||
| OpenkhInstallation.GetDirectory(applicationDirectory), | ||
| ignoreCase: true | ||
| ); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <Application x:Class="OpenKh.Tools.Launcher.App" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
| <Application.Resources> | ||
| </Application.Resources> | ||
| </Application> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Windows; | ||
|
|
||
| namespace OpenKh.Tools.Launcher; | ||
|
|
||
| public partial class App : Application | ||
| { | ||
| protected override void OnStartup(StartupEventArgs e) | ||
| { | ||
| base.OnStartup(e); | ||
|
|
||
| if (LegacyInstallationMigration.TryStartModManager()) | ||
| { | ||
| Shutdown(); | ||
| return; | ||
| } | ||
|
|
||
| LegacyInstallationMigration.ScheduleCleanupIfNeeded(); | ||
| new MainWindow().Show(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace OpenKh.Tools.Launcher; | ||
|
|
||
| internal static class DesktopShortcutService | ||
| { | ||
| public static string CreateModManagerShortcut(string targetPath, string? shortcutDirectory = null) | ||
| { | ||
| shortcutDirectory ??= Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); | ||
| var shortcutPath = Path.Combine(shortcutDirectory, "OpenKH Mod Manager.lnk"); | ||
| var shellType = Type.GetTypeFromProgID("WScript.Shell") | ||
| ?? throw new InvalidOperationException("Windows Script Host is not available."); | ||
| object? shell = null; | ||
| object? shortcut = null; | ||
|
|
||
| try | ||
| { | ||
| shell = Activator.CreateInstance(shellType) | ||
| ?? throw new InvalidOperationException("Windows Script Host could not be started."); | ||
| shortcut = shellType.InvokeMember( | ||
| "CreateShortcut", | ||
| System.Reflection.BindingFlags.InvokeMethod, | ||
| null, | ||
| shell, | ||
| new object[] { shortcutPath } | ||
| ) ?? throw new InvalidOperationException("The shortcut could not be created."); | ||
|
|
||
| var shortcutType = shortcut.GetType(); | ||
| shortcutType.InvokeMember("TargetPath", System.Reflection.BindingFlags.SetProperty, null, shortcut, new object[] { targetPath }); | ||
| shortcutType.InvokeMember("WorkingDirectory", System.Reflection.BindingFlags.SetProperty, null, shortcut, new object[] { Path.GetDirectoryName(targetPath)! }); | ||
| shortcutType.InvokeMember("Description", System.Reflection.BindingFlags.SetProperty, null, shortcut, new object[] { "Open OpenKH Mod Manager" }); | ||
| shortcutType.InvokeMember("IconLocation", System.Reflection.BindingFlags.SetProperty, null, shortcut, new object[] { $"{targetPath},0" }); | ||
| shortcutType.InvokeMember("Save", System.Reflection.BindingFlags.InvokeMethod, null, shortcut, null); | ||
| } | ||
| finally | ||
| { | ||
| if (shortcut != null && Marshal.IsComObject(shortcut)) | ||
| Marshal.FinalReleaseComObject(shortcut); | ||
| if (shell != null && Marshal.IsComObject(shell)) | ||
| Marshal.FinalReleaseComObject(shell); | ||
| } | ||
|
|
||
| return shortcutPath; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: OpenKH/OpenKh
Length of output: 11456
🏁 Script executed:
Repository: OpenKH/OpenKh
Length of output: 13616
🏁 Script executed:
Repository: OpenKH/OpenKh
Length of output: 9568
🏁 Script executed:
Repository: OpenKH/OpenKh
Length of output: 195
🏁 Script executed:
Repository: OpenKH/OpenKh
Length of output: 220
🏁 Script executed:
Repository: OpenKH/OpenKh
Length of output: 223
Guard startup cleanup and keep the launcher launchable.
ScheduleCleanupIfNeeded()is called unconditionally and can generate a migration batch that deletes top-level files matching the legacy file selector, including.dllfiles, and theFallbackLegacyResourceDirectoriesbefore the launcher has checked the new packaged layout. Add a guard that runs cleanup only when the legacy layout is present and newer paths likeApps/ModManager,AdvancedTools, oropenkh-releaseare absent.TryStartModManager()throws outside the existingProcess.Start()block, or if later startup throws,OnStartupexits beforeMainWindowopens. Catch migration-related exceptions, record an error, and continue to createMainWindow.🤖 Prompt for AI Agents