Skip to content

Commit

Permalink
- launchher: complete installation with DLL copying
Browse files Browse the repository at this point in the history
  • Loading branch information
SoapyMan committed Sep 5, 2021
1 parent 853adfa commit f7153e1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions AlcatrazLauncher/AlcatrazLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Dialogs\SignInToAlcatrazDialog.Designer.cs">
<DependentUpon>SignInToAlcatrazDialog.cs</DependentUpon>
</Compile>
<Compile Include="Helpers\FileChecksumHelper.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
4 changes: 3 additions & 1 deletion AlcatrazLauncher/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ public class Constants
public static string ConfigFilename =>"Alcatraz.json";
public static string NoProfile => "None";
public static string OfficialProfileKey => "UbiOfficial";
}
public static string OrbitLoaderFilename => "ubiorbitapi_r2_loader.dll";
public static string OrbitLoaderSHA1 => "8F7CC25567F8996C0A5D082024E751EAD9430FF2"; // original checksum
}
}
28 changes: 28 additions & 0 deletions AlcatrazLauncher/Helpers/FileChecksumHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace AlcatrazLauncher.Helpers
{
public static class FileChecksumHelper
{
public static string GetFileSHA1(string FileName)
{
using (FileStream fs = new FileStream(FileName, FileMode.Open))
using (BufferedStream bs = new BufferedStream(fs))
{
using (SHA1Managed sha1 = new SHA1Managed())
{
byte[] hash = sha1.ComputeHash(bs);
StringBuilder formatted = new StringBuilder(2 * hash.Length);
foreach (byte b in hash)
{
formatted.AppendFormat("{0:X2}", b);
}

return formatted.ToString();
}
}
}
}
}
26 changes: 24 additions & 2 deletions AlcatrazLauncher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Win32;
using AlcatrazLauncher.Helpers;
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
Expand Down Expand Up @@ -83,9 +84,30 @@ static void Main()
}
}

if(GameInstallPath.Length > 0)
if (GameInstallPath.Length > 0)
{
var AlcatrazLoaderFullPath = Path.GetFullPath(Constants.OrbitLoaderFilename);
var OrbitLoaderFullPath = Path.Combine(GameInstallPath, Constants.OrbitLoaderFilename);
var OrbitLoaderBackupPath = Path.Combine(GameInstallPath, Constants.OrbitLoaderFilename + ".bak");

var orbitSha1 = File.Exists(OrbitLoaderFullPath) ? FileChecksumHelper.GetFileSHA1(OrbitLoaderFullPath) : "";

Directory.SetCurrentDirectory(GameInstallPath);

// check orbit loader
if(FileChecksumHelper.GetFileSHA1(AlcatrazLoaderFullPath) != orbitSha1)
{
if (File.Exists(OrbitLoaderFullPath) && orbitSha1 == Constants.OrbitLoaderSHA1)
{
File.Move(OrbitLoaderFullPath, OrbitLoaderBackupPath);
MessageBox.Show($"Backup created:\n\n{OrbitLoaderBackupPath}", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

// copy new loader file to game folder
File.Copy(AlcatrazLoaderFullPath, OrbitLoaderFullPath);
}
}

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Formatting = Formatting.Indented,
Expand Down

0 comments on commit f7153e1

Please sign in to comment.