-
Notifications
You must be signed in to change notification settings - Fork 3
Add InstallTester command-line app #13
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
CRefice
wants to merge
2
commits into
main
Choose a base branch
from
install-tester
base: main
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
2 commits
Select commit
Hold shift + click to select a range
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,6 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <configuration> | ||
| <startup> | ||
| <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
| </startup> | ||
| </configuration> |
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,39 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
| <PropertyGroup> | ||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
| <ProjectGuid>{9F48A343-5238-4B71-8F2E-6083FFF2DB6E}</ProjectGuid> | ||
| <OutputType>Exe</OutputType> | ||
| <RootNamespace>InstallTester</RootNamespace> | ||
| <AssemblyName>InstallTester</AssemblyName> | ||
| <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
| <FileAlignment>512</FileAlignment> | ||
| <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
| <Deterministic>true</Deterministic> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
| <PlatformTarget>AnyCPU</PlatformTarget> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>full</DebugType> | ||
| <Optimize>false</Optimize> | ||
| <OutputPath>bin\Debug\</OutputPath> | ||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
| <PlatformTarget>AnyCPU</PlatformTarget> | ||
| <DebugType>pdbonly</DebugType> | ||
| <Optimize>true</Optimize> | ||
| <OutputPath>bin\Release\</OutputPath> | ||
| <DefineConstants>TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <None Include="App.config" /> | ||
| </ItemGroup> | ||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
| </Project> |
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
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,188 @@ | ||
| | ||
| using System.ComponentModel; | ||
| using USPInstaller.Models; | ||
| using USPInstaller.ViewModels; | ||
|
|
||
| class TestInstallViewModel : InstallationViewModel | ||
| { | ||
| public TestInstallViewModel() : base() | ||
| { | ||
| PropertyChanged += OnPropertyChanged; | ||
| } | ||
|
|
||
| private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
| { | ||
| if (e.PropertyName == "OverallProgressMessage") | ||
| { | ||
| Console.WriteLine(OverallProgressMessage); | ||
| } | ||
| } | ||
|
|
||
| public override bool AskUserQuestion(string message) | ||
| { | ||
| // Always assume user selected "yes" to questions | ||
| return true; | ||
| } | ||
|
|
||
| public override void LogError(string s) | ||
| { | ||
| // Treat any error log as a hard error | ||
| throw new Exception("Installation script logged an error: rs" + s); | ||
| } | ||
| } | ||
|
|
||
| class Program | ||
| { | ||
| static string? FindApplicationWithName(string directory, string name) | ||
| { | ||
| string attempt = Path.Join(directory, name + ".exe"); | ||
| if (File.Exists(attempt)) | ||
| { | ||
| return attempt; | ||
| } | ||
| attempt = Path.Join(directory, name + ".app"); | ||
| if (Directory.Exists(attempt)) | ||
| { | ||
| return attempt; | ||
| } | ||
| attempt = Path.Join(directory, "run.sh"); | ||
| if (File.Exists(attempt)) | ||
| { | ||
| return attempt; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| static async Task<(string, string)> GetConfig() | ||
| { | ||
| string configPath = Path.Join(AppContext.BaseDirectory, "config.txt"); | ||
| if (File.Exists(configPath)) | ||
| { | ||
| // Read two lines from configPath | ||
| string[] lines = await File.ReadAllLinesAsync(configPath); | ||
| if (lines.Length >= 2) | ||
| { | ||
| Console.WriteLine("Read configuration from: " + configPath); | ||
| Console.WriteLine("Assets path: " + lines[0]); | ||
| Console.WriteLine("Games root path: " + lines[1]); | ||
| return (lines[0], lines[1]); | ||
| } | ||
| } | ||
| string? assetPath = null; | ||
| while (assetPath == null) | ||
| { | ||
| Console.Write("Asset path: "); | ||
| assetPath = Console.ReadLine(); | ||
| } | ||
|
|
||
| string? rootDir = null; | ||
| while (rootDir == null) | ||
| { | ||
| Console.Write("Games root directory: "); | ||
| rootDir = Console.ReadLine(); | ||
| } | ||
| await File.WriteAllLinesAsync(configPath, [assetPath, rootDir]); | ||
| Console.WriteLine("Wrote configuration to: " + configPath); | ||
| return (assetPath, rootDir); | ||
| } | ||
|
|
||
| // See https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories | ||
| static async Task CopyDirectory(string sourceDir, string destinationDir, bool recursive) | ||
| { | ||
| // Get information about the source directory | ||
| var dir = new DirectoryInfo(sourceDir); | ||
|
|
||
| // Check if the source directory exists | ||
| if (!dir.Exists) | ||
| throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}"); | ||
|
|
||
| // Cache directories before we start copying | ||
| DirectoryInfo[] dirs = dir.GetDirectories(); | ||
|
|
||
| // Create the destination directory | ||
| Directory.CreateDirectory(destinationDir); | ||
|
|
||
| // Get the files in the source directory and copy to the destination directory | ||
| foreach (FileInfo file in dir.GetFiles()) | ||
| { | ||
| string targetFilePath = Path.Combine(destinationDir, file.Name); | ||
| file.CopyTo(targetFilePath); | ||
| } | ||
|
|
||
| // If recursive and copying subdirectories, recursively call this method | ||
| if (recursive) | ||
| { | ||
| foreach (DirectoryInfo subDir in dirs) | ||
| { | ||
| string newDestinationDir = Path.Combine(destinationDir, subDir.Name); | ||
| await CopyDirectory(subDir.FullName, newDestinationDir, true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static async Task CopyToFolder(string directory, string tempPath) | ||
| { | ||
| if (Directory.Exists(tempPath)) | ||
| Directory.Delete(tempPath, true); | ||
| await CopyDirectory(directory, tempPath, true); | ||
| } | ||
|
|
||
| static async Task<int> Main(string[] args) | ||
| { | ||
| (string assetPath, string rootDir) = await GetConfig(); | ||
|
|
||
| var patchedRootDir = Path.Combine(rootDir, "Patched"); | ||
| Directory.CreateDirectory(patchedRootDir); | ||
|
|
||
| InstallationViewModel installer = new TestInstallViewModel(); | ||
|
|
||
| bool failed = false; | ||
| foreach (string subDir in Directory.GetDirectories(rootDir)) | ||
| { | ||
| try | ||
| { | ||
| string fileName = Path.GetFileName(subDir); | ||
| string patchedCopyDir = Path.Combine(patchedRootDir, fileName); | ||
|
|
||
| string? undertaleExe = FindApplicationWithName(subDir, "UNDERTALE"); | ||
| if (undertaleExe != null) | ||
| { | ||
| await CopyToFolder(subDir, patchedCopyDir); | ||
| Console.WriteLine($"\nInstalling Undertale patch on {fileName}..."); | ||
| await installer.InstallUndertale(assetPath, FindApplicationWithName(patchedCopyDir, "UNDERTALE")!); | ||
| continue; | ||
| } | ||
| string? deltaruneExe = FindApplicationWithName(subDir, "DELTARUNE"); | ||
| if (deltaruneExe != null) | ||
| { | ||
| await CopyToFolder(subDir, patchedCopyDir); | ||
| Console.WriteLine($"\nInstalling Deltarune patch on {fileName}..."); | ||
| await installer.InstallDeltarune(assetPath, FindApplicationWithName(patchedCopyDir, "DELTARUNE")!); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine($"Installation to {Path.GetFileName(subDir)} failed:"); | ||
| Console.WriteLine(e.Message); | ||
| Console.WriteLine(e.StackTrace); | ||
| failed = true; | ||
| } | ||
| } | ||
|
|
||
| if (!failed) | ||
| { | ||
| if (!Console.IsOutputRedirected) | ||
| { | ||
| Console.WriteLine("\nInstallation completed succesfully :D\nPress any key to exit..."); | ||
| Console.ReadKey(); | ||
| } | ||
| return 0; | ||
| } | ||
| if (!Console.IsOutputRedirected) | ||
| { | ||
| Console.WriteLine("\nThere were some errors during installation :(\nPress any key to exit"); | ||
| Console.ReadKey(); | ||
| } | ||
| return 10; | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
SpaghettiCh2/USPInstallTester/Properties/PublishProfiles/FolderProfile.pubxml
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,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- https://go.microsoft.com/fwlink/?LinkID=208121. --> | ||
| <Project> | ||
| <PropertyGroup> | ||
| <Configuration>Release</Configuration> | ||
| <Platform>Any CPU</Platform> | ||
| <PublishDir>bin\Release\net8.0\publish\</PublishDir> | ||
| <PublishProtocol>FileSystem</PublishProtocol> | ||
| <_TargetId>Folder</_TargetId> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <SelfContained>false</SelfContained> | ||
| </PropertyGroup> | ||
| </Project> |
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,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\SpaghettiCh2\USPInstaller.csproj" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <SatelliteResourceLanguages>en-US;it-IT</SatelliteResourceLanguages> | ||
| </PropertyGroup> | ||
| </Project> |
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
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.
we should sanitize the paths that we get - with proper separators for unix systems and windows and with the whitespace trimmed, since we're gonna read this from a config file afterwards and Path.Combine doesn't sanitize path separators