Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
catapultam-habeo committed Feb 29, 2024
2 parents c5bb2b5 + 5bdeb20 commit de42756
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
11 changes: 6 additions & 5 deletions EQEmu Patcher/EQEmu Patcher/IniLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using System.Windows.Forms;

namespace EQEmu_Patcher
{
Expand All @@ -17,29 +18,29 @@ class IniLibrary
public VersionTypes ClientVersion { get; set; }
public string LastPatchedVersion { get; set; }


public static void Save()
{
var serializerBuilder = new SerializerBuilder().WithNamingConvention(new CamelCaseNamingConvention());
var serializer = serializerBuilder.Build();
string body = serializer.Serialize(instance);

Console.WriteLine(body);
File.WriteAllText(@"eqemupatcher.yml", body);
File.WriteAllText($"{System.IO.Path.GetDirectoryName(Application.ExecutablePath)}\\eqemupatcher.yml", body);
}

public static void Load()
{
try {
using (var input = File.OpenText("eqemupatcher.yml"))
using (var input = File.OpenText($"{System.IO.Path.GetDirectoryName(Application.ExecutablePath)}\\eqemupatcher.yml"))
{
var deserializerBuilder = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention());

var deserializer = deserializerBuilder.Build();

instance = deserializer.Deserialize<IniLibrary>(input);
}

if (instance == null) {
ResetDefaults();
Save();
Expand Down
35 changes: 17 additions & 18 deletions EQEmu Patcher/EQEmu Patcher/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace EQEmu_Patcher
{

public partial class MainForm : Form
{

Expand Down Expand Up @@ -43,7 +43,7 @@ public partial class MainForm : Form
VersionTypes.Rain_Of_Fear, //rof
VersionTypes.Rain_Of_Fear_2 //rof
//VersionTypes.Broken_Mirror, //bro
};
};

private Dictionary<VersionTypes, ClientVersion> clientVersions = new Dictionary<VersionTypes, ClientVersion>();

Expand All @@ -57,7 +57,6 @@ public MainForm()

private async void MainForm_Load(object sender, EventArgs e)
{

isLoading = true;
version = Assembly.GetEntryAssembly().GetName().Version.ToString();
Console.WriteLine($"Initializing {version}");
Expand Down Expand Up @@ -157,7 +156,7 @@ private async void MainForm_Load(object sender, EventArgs e)
bool isSupported = false;
foreach (var ver in supportedClients)
{
if (ver != currentVersion) continue;
if (ver != currentVersion) continue;
isSupported = true;
break;
}
Expand All @@ -177,7 +176,7 @@ private async void MainForm_Load(object sender, EventArgs e)
if (Environment.OSVersion.Version.Major < 6) {
return;
}
var taskbar = TaskbarManager.Instance;
var taskbar = TaskbarManager.Instance;
taskbar.SetProgressValue(value, 10000);
taskbar.SetProgressState((value == 10000) ? TaskbarProgressBarState.NoProgress : TaskbarProgressBarState.Normal);
});
Expand Down Expand Up @@ -209,7 +208,7 @@ private async void MainForm_Load(object sender, EventArgs e)
}));

string webUrl = $"{filelistUrl}{suffix}/filelist_{suffix}.yml";

string response = await DownloadFile(cts, webUrl, "filelist.yml");
if (response != "")
{
Expand Down Expand Up @@ -249,15 +248,15 @@ private async void MainForm_Load(object sender, EventArgs e)

FileList filelist;

using (var input = File.OpenText("filelist.yml"))
using (var input = File.OpenText($"{System.IO.Path.GetDirectoryName(Application.ExecutablePath)}\\filelist.yml"))
{
var deserializerBuilder = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention());

var deserializer = deserializerBuilder.Build();

filelist = deserializer.Deserialize<FileList>(input);
}

if (filelist.version != IniLibrary.instance.LastPatchedVersion)
{
if (!isPendingPatch)
Expand Down Expand Up @@ -339,9 +338,9 @@ private void detectClientVersion()
{
//StatusLibrary.Log($"You seem to have put me in a {clientVersions[currentVersion].FullName} client directory");
}

//MessageBox.Show(""+currentVersion);
//StatusLibrary.Log($"If you wish to help out, press the scan button on the bottom left and wait for it to complete, then copy paste this data as an Issue on github!");
//StatusLibrary.Log($"If you wish to help out, press the scan button on the bottom left and wait for it to complete, then copy paste this data as an Issue on github!");
}
catch (UnauthorizedAccessException err)
{
Expand Down Expand Up @@ -408,7 +407,7 @@ public static async Task<string> DownloadFile(CancellationTokenSource cts, strin
{
path = path.Replace("/", "\\");
if (path.Contains("\\")) { //Make directory if needed.
string dir = Application.StartupPath + "\\" + path.Substring(0, path.LastIndexOf("\\"));
string dir = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\" + path.Substring(0, path.LastIndexOf("\\"));
Directory.CreateDirectory(dir);
}
return await UtilityLibrary.DownloadFile(cts, url, path);
Expand Down Expand Up @@ -454,8 +453,8 @@ private async Task AsyncPatch()
StatusLibrary.Log($"Patching with patcher version {version}...");
StatusLibrary.SetProgress(0);
FileList filelist;
using (var input = File.OpenText("filelist.yml"))

using (var input = File.OpenText($"{System.IO.Path.GetDirectoryName(Application.ExecutablePath)}\\filelist.yml"))
{
var deserializerBuilder = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention());

Expand Down Expand Up @@ -490,7 +489,7 @@ private async Task AsyncPatch()
await w.WriteAsync(data, 0, data.Length, cts.Token);
}
StatusLibrary.Log($"Self update of {generateSize(data.Length)} will be used next run");

} catch (Exception e)
{
StatusLibrary.Log($"Self update failed {url}: {e.Message}");
Expand Down Expand Up @@ -531,7 +530,7 @@ private async Task AsyncPatch()


string url = filelist.downloadprefix + entry.name.Replace("\\", "/");

string resp = await DownloadFile(cts, url, entry.name);
if (resp != "")
{
Expand Down Expand Up @@ -580,11 +579,11 @@ private async Task AsyncPatch()
{
version = version.Substring(0, 8);
}

StatusLibrary.Log($"Up to date with patch {version}.");
return;
}

string elapsed = start.Elapsed.ToString("ss\\.ff");
StatusLibrary.Log($"Complete! Patched {generateSize(patchedBytes)} in {elapsed} seconds. Press Play to begin.");
IniLibrary.instance.LastPatchedVersion = filelist.version;
Expand Down Expand Up @@ -664,7 +663,7 @@ private void pendingPatchTimer_Tick(object sender, EventArgs e)
public class FileList
{
public string version { get; set; }

public List<FileEntry> deletes { get; set; }
public string downloadprefix { get; set; }
public List<FileEntry> downloads { get; set; }
Expand Down
13 changes: 11 additions & 2 deletions EQEmu Patcher/EQEmu Patcher/UtilityLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading;
using YamlDotNet.Core.Tokens;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;

namespace EQEmu_Patcher
{
Expand All @@ -27,7 +28,14 @@ public static async Task<string> DownloadFile(CancellationTokenSource cts, strin
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync())
{
using (var w = File.Create(outFile)) {
var outPath = outFile.Replace("/", "\\");
if (outFile.Contains("\\")) { //Make directory if needed.
string dir = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\" + outFile.Substring(0, outFile.LastIndexOf("\\"));
Directory.CreateDirectory(dir);
}
outPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\" + outFile;

using (var w = File.Create(outPath)) {
await stream.CopyToAsync(w, 81920, cts.Token);
}
}
Expand All @@ -44,6 +52,7 @@ public static async Task<string> DownloadFile(CancellationTokenSource cts, strin
return "";
}

// Download will grab a remote URL's file and return the data as a byte array
public static async Task<byte[]> Download(CancellationTokenSource cts, string url)
{
var client = new HttpClient();
Expand All @@ -66,7 +75,7 @@ public static string GetMD5(string filename)
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);

StringBuilder sb = new StringBuilder();

for (int i = 0; i < hash.Length; i++)
Expand Down

0 comments on commit de42756

Please sign in to comment.