Skip to content

Add initial options file implementation #56

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Patcher/Patcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>

<ItemGroup>
<None Update="options.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions Patcher/PatcherOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Patcher
{
public class PatcherOptions
{
public string ThemeName { get; set; }

public string FileLocation { get; set; }

public string Version { get; set; }

public OperatingSystem? OperatingSystem { get; set; }

public bool? Force { get; set; }
}
}
25 changes: 15 additions & 10 deletions Patcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
using System.Linq;
using NDesk.Options;
using System.Runtime.InteropServices;
using System.Text.Json;

namespace Patcher
{
internal static class Program
{
internal static void Main(string[] args)
{
var themeName = string.Empty;
var options = new PatcherOptions();
var optionsFile = new FileInfo("options.json");
if (optionsFile.Exists)
options = JsonSerializer.Deserialize<PatcherOptions>(File.ReadAllText(optionsFile.FullName));

var themeName = options.ThemeName ?? string.Empty;
var help = false;
var fileLocation = string.Empty;
var os = OperatingSystem.Unknown;
var version = string.Empty;
var force = false;
var fileLocation = options.FileLocation ?? string.Empty;
var os = options.OperatingSystem ?? OperatingSystem.Unknown;
var version = options.Version ?? string.Empty;
var force = options.Force ?? false;

var optionSet = new OptionSet
{
Expand Down Expand Up @@ -186,10 +192,9 @@ private static void CreateBackup(FileSystemInfo fileInfo, MemoryStream ms)
backupFileInfo.Delete();

using var backupWriteStream = backupFileInfo.OpenWrite();

backupWriteStream.Write(ms.ToArray(), 0, (int)ms.Length);


backupWriteStream.Write(ms.ToArray(), 0, (int)ms.Length);

if (backupFileInfo.Exists)
Console.WriteLine($"Backup '{backupFileInfo.Name}' created.");
}
Expand Down Expand Up @@ -230,13 +235,13 @@ private static void PatchExecutable(MemoryStream ms, FileStream fs, PatchInfo pa
Console.WriteLine($"Patching to {themeName}...");

foreach (var offset in offsets)

for (var i = 0; i < themeBytes.Length; i++)
{
fs.Position = offset + i;
fs.WriteByte(themeBytes[i]);
}


Console.WriteLine("Unity was successfully patched. Enjoy!");
}
Expand Down
7 changes: 7 additions & 0 deletions Patcher/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ThemeName": "dark",
"FileLocation": "",
"Version": "",
"OperatingSystem": null,
"Force": false
}