Skip to content

Commit

Permalink
Merge pull request #74 from geefr/development
Browse files Browse the repository at this point in the history
Switch to using library version of IPA-Linux
  • Loading branch information
geefr authored Dec 28, 2020
2 parents dfa8867 + d2de1ee commit 28af979
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 115 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- image: mcr.microsoft.com/dotnet/sdk:5.0
steps:
- checkout
- run: git submodule update --init --recursive
- run: cd Beataroni && ./build/publish-linux-x64.sh
- run: tar -C Beataroni/Beataroni/bin/Release/net5.0/publish-Linux64/ -cvzf Beataroni-linux64.tar.gz .
- store_artifacts:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "BSIPA-Linux"]
path = BSIPA-Linux
url = https://github.com/geefr/BSIPA-Linux.git
1 change: 1 addition & 0 deletions BSIPA-Linux
Submodule BSIPA-Linux added at 1f7add
14 changes: 14 additions & 0 deletions Beataroni/Beataroni.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Beataroni", "Beataroni\Beat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Beataroni.Tests", "Beataroni.Tests\Beataroni.Tests.csproj", "{8B48C1CD-69A2-465A-8E37-D9146DABF96B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPA-lib", "..\BSIPA-Linux\IPA-lib\IPA-lib.csproj", "{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -44,5 +46,17 @@ Global
{8B48C1CD-69A2-465A-8E37-D9146DABF96B}.Release|x64.Build.0 = Release|Any CPU
{8B48C1CD-69A2-465A-8E37-D9146DABF96B}.Release|x86.ActiveCfg = Release|Any CPU
{8B48C1CD-69A2-465A-8E37-D9146DABF96B}.Release|x86.Build.0 = Release|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Debug|x64.ActiveCfg = Debug|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Debug|x64.Build.0 = Debug|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Debug|x86.ActiveCfg = Debug|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Debug|x86.Build.0 = Debug|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Release|Any CPU.Build.0 = Release|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Release|x64.ActiveCfg = Release|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Release|x64.Build.0 = Release|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Release|x86.ActiveCfg = Release|Any CPU
{88E1BFB8-83C1-42DD-8102-BCD47A498DE4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions Beataroni/Beataroni/Beataroni.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@
<DependentUpon>ModInstallView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\BSIPA-Linux\IPA-lib\IPA-lib.csproj" />
</ItemGroup>
</Project>
81 changes: 21 additions & 60 deletions Beataroni/Beataroni/Services/modinstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using IPA;

namespace Beataroni.Services
{
Expand Down Expand Up @@ -130,80 +131,40 @@ public bool PatchBeatSaber(string bsInstall, InstallLogLine log)
//log("Patching Beat Saber");

var runningOnLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
var ipaExe = runningOnLinux ? "IPA-Minimal" : "IPA.exe";

if (runningOnLinux)
{
if (!PatchSteamProtonPrefix(bsInstall, log))
{
Console.WriteLine("PatchBeatSaber: Failed to patch steam's proton prefix");
return false;
}

// Copy the Linux build of IPA into bsInstall
// TODO: The packaging/build setup for this binary isn't great, consider
// pulling it in directly as a library?
try
{
var roniDir = "";
if (Debugger.IsAttached)
{
// This is quite annoying. When running under the debugger the executing process
// is in /usr/share/dotnet, which sadly isn't where the Beataroni install is
// Under a debugger however we're not packaged as a single executable,
// so can look up the current assembly to work out where we are
// TODO: Using the dev copy for now, this won't be especially reliable
// roniDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
// roniDir = $"{roniDir}/../../../../../IPA/bin-minimal-linux64/";
}
else
{
// When not debugging we have to assume we're running in a packaged form
// So get the Beataroni dir based on the current root process.
// In this case we can't use the current assembly as this is actually a copy
// in a temporary dir one the single-file executable has been unpacked
// TODO: Need some kind of preprocessor dance here to specify if we're
// packaged as a single-file or not, because if we're not then the
// executing assembly is the system dotnet runtime again, like under
// debug
roniDir = System.AppContext.BaseDirectory;
// roniDir = Path.GetDirectoryName(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
}

log($"INFO: Linux Patching: roniDir: {roniDir}");
File.Copy($"{roniDir}/{ipaExe}", $"{bsInstall}/{ipaExe}", true);
}
catch (Exception e)
{
log($"PatchBeatSaber: Failed to install IPA-Minimal: {e.Message}");
return false;
}
}

try
{
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = $"{bsInstall}/{ipaExe}";
proc.StartInfo.WorkingDirectory = $"{bsInstall}";
// Don't wait for user input
// IPA-Minimal doesn't work unless the executable is specified
// (Due to order of executables in dir it finds some other file if left to its own devices)
proc.StartInfo.Arguments = "-n \"Beat Saber.exe\"";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.Start();
// Assuming proc will kill itself here, if not we'll hang, or need to use the Kill method
proc.WaitForExit();
if (proc.ExitCode != 0)
{
log($"PatchBeatSaber: IPA.exe returned non-zero({proc.ExitCode}):\n StdOut: {proc.StandardOutput.ReadToEnd()} \n StdErr: {proc.StandardError.ReadToEnd()}");
return false;
}
log($"PatchBeatSaber: Running IPA installation");

// TODO: Should rework IPA-Minimal lib to return status code, need to detect if things fail
// TODO: Should capture stdout/stderr from IPA-Minimal lib, can we do that without major rework?
var origPwd = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(bsInstall);
string[] args = {"IPA-Minimal", "-n", "-f", "Beat Saber.exe", "--relativeToPwd"};
IPA.Program.Main(args);
Directory.SetCurrentDirectory(origPwd);

// if (proc.ExitCode != 0)
// {
// log($"PatchBeatSaber: IPA returned non-zero({proc.ExitCode}):\n StdOut: {proc.StandardOutput.ReadToEnd()} \n StdErr: {proc.StandardError.ReadToEnd()}");
// return false;
// }
// } else {
// log("PatchBeatSaber: Failed to start IPA process, don't know why...");
// }
}
catch (Exception e)
{
log(e.Message);
log(e.ToString());
return false;
}
return true;
Expand Down
3 changes: 0 additions & 3 deletions Beataroni/build/publish-linux-x64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
buildDir=$(dirname $0)
dotnet publish /p:PublishProfile=${buildDir}/../Beataroni/Properties/PublishProfiles/Linux64.pubxml
cp ${buildDir}/Beataroni-Linux.sh ${buildDir}/../Beataroni/bin/Release/net5.0/publish-Linux64/
cp ${buildDir}/../../IPA/bin-minimal-linux64/IPA-Minimal ${buildDir}/../Beataroni/bin/Release/net5.0/publish-Linux64/
cp ${buildDir}/../../IPA/bin-minimal-linux64/IPA-Minimal-Licence.txt ${buildDir}/../Beataroni/bin/Release/net5.0/publish-Linux64/

31 changes: 0 additions & 31 deletions IPA/README.md

This file was deleted.

Binary file removed IPA/bin-minimal-linux64/IPA-Minimal
Binary file not shown.
21 changes: 0 additions & 21 deletions IPA/bin-minimal-linux64/IPA-Minimal-Licence.txt

This file was deleted.

Binary file removed IPA/bin-minimal-linux64/IPA-Minimal.pdb
Binary file not shown.

0 comments on commit 28af979

Please sign in to comment.