Skip to content

Commit

Permalink
Replaced xdelta3 lib with exe
Browse files Browse the repository at this point in the history
  • Loading branch information
TekkaGB committed Mar 28, 2023
1 parent ba92352 commit bcb367f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
Binary file added PizzaOven/Dependencies/xdelta.exe
Binary file not shown.
29 changes: 22 additions & 7 deletions PizzaOven/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using System.Reflection;
using System.Text.Json;
using xdelta3.net;

namespace PizzaOven
{
Expand Down Expand Up @@ -39,6 +38,13 @@ public static bool Build(string mod)
var successes = 0;
var FilesToPatch = Directory.GetFiles($"{Global.config.ModsFolder}{Global.s}sound{Global.s}Desktop").ToList();
FilesToPatch.Insert(0, $"{Global.config.ModsFolder}{Global.s}data.win");
var xdelta = $"{Global.assemblyLocation}{Global.s}Dependencies{Global.s}xdelta.exe";
if (!File.Exists(xdelta))
{

Global.logger.WriteLine($"{xdelta} is not found. Please try redownloading Pizza Oven", LoggerType.Error);
return false;
}
foreach (var modFile in Directory.GetFiles(mod, "*", SearchOption.AllDirectories))
{
var extension = Path.GetExtension(modFile);
Expand All @@ -57,7 +63,7 @@ public static bool Build(string mod)
{
// Attempt to patch file
Global.logger.WriteLine($"Attempting to patch {file} with {modFile}...", LoggerType.Info);
Patch(file, modFile, $"{Path.GetDirectoryName(file)}{Global.s}temp");
Patch(file, modFile, $"{Path.GetDirectoryName(file)}{Global.s}temp", xdelta);
if (Path.GetFileName(file).Equals("data.win", StringComparison.InvariantCultureIgnoreCase))
File.Move($"{Path.GetDirectoryName(file)}{Global.s}temp", $"{Path.GetDirectoryName(file)}{Global.s}PizzaOven.win", true);
else
Expand Down Expand Up @@ -142,12 +148,21 @@ public static bool Build(string mod)
return errors == 0 && successes > 0;
}

private static void Patch(string file, string patch, string output)
private static void Patch(string file, string patch, string output, string xdelta)
{
var fileBytes = File.ReadAllBytes(file);
var patchBytes = File.ReadAllBytes(patch);
var decoded = Xdelta3Lib.Decode(fileBytes, patchBytes);
File.WriteAllBytes(output, decoded.ToArray());
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.FileName = xdelta;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.WorkingDirectory = Path.GetDirectoryName(xdelta);
startInfo.Arguments = $@"-d -s ""{file}"" ""{patch}"" ""{output}""";
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
Global.logger.WriteLine($"Applied {patch} to {file}.", LoggerType.Info);
}
private static void RestoreDirectory(string path)
Expand Down
13 changes: 7 additions & 6 deletions PizzaOven/PizzaOven.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>Assets\PizzaOvenIcon.ico</ApplicationIcon>
<AssemblyName>PizzaOven</AssemblyName>
<AssemblyVersion>1.0.2.0</AssemblyVersion>
<AssemblyVersion>1.0.3.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,7 +28,6 @@
<PackageReference Include="SharpCompress" Version="0.28.1" />
<PackageReference Include="WindowsAPICodePack-Core" Version="1.1.2" />
<PackageReference Include="WindowsAPICodePack-Shell" Version="1.1.1" />
<PackageReference Include="xdelta3.net" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -44,6 +43,12 @@
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Dependencies\xdelta.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Page Update="UI\ChoiceWindow.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
Expand All @@ -58,8 +63,4 @@
</Page>
</ItemGroup>

<ItemGroup>
<Folder Include="Dependencies\" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion PizzaOven/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using xdelta3.net;
using Microsoft.WindowsAPICodePack.Dialogs;
using System.Windows;

Expand Down
1 change: 0 additions & 1 deletion PizzaOven/UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Windows.Controls.Primitives;
using System.Security.Cryptography;
using Microsoft.Win32;
using xdelta3.net;
using System.Windows.Input;
using System.Windows.Data;
using SharpCompress.Archives.SevenZip;
Expand Down

0 comments on commit bcb367f

Please sign in to comment.