Skip to content

Commit

Permalink
Merge pull request #149 from LoadedCamel/dev
Browse files Browse the repository at this point in the history
3.4.6.8 PR
  • Loading branch information
Metalios authored Sep 15, 2022
2 parents d2b4faf + 82c8d73 commit 3dc3350
Show file tree
Hide file tree
Showing 17 changed files with 2,177 additions and 2,055 deletions.
7 changes: 4 additions & 3 deletions MRBUpdater/PatchDecompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class PatchDecompressor
{
public delegate void ProgressEventHandler(object sender, ProgressEventArgs e);
public event ProgressEventHandler? ProgressUpdate;
//public event EventHandler<ProgressEventArgs> ProgressUpdate;
public event EventHandler<ErrorEventArgs>? ErrorUpdate;

public struct FileData
Expand All @@ -33,8 +32,9 @@ public static void CleanOldEntries(string extractPath)
}
}

public void RecompileFileEntries(string patchPath, List<FileData> decompressedData)
public void RecompileFileEntries(string patchPath, List<FileData>? decompressedData)
{
if (decompressedData == null) return;
for (var index = 0; index <= decompressedData.Count; index++)
{
var patchedFile = decompressedData[index];
Expand All @@ -55,13 +55,14 @@ public void RecompileFileEntries(string patchPath, List<FileData> decompressedDa
}


public List<FileData>? DecompressData(string patchFile)
public static List<FileData>? DecompressData(string? patchFile)
{
FileStream fileStream;
MemoryStream decompressed;
InflaterInputStream inflaterStream;
BinaryReader reader;
var patchFiles = new List<FileData>();
if (patchFile == null) throw new ArgumentNullException(patchFile);
try
{
fileStream = new FileStream(patchFile, FileMode.Open, FileAccess.Read);
Expand Down
34 changes: 18 additions & 16 deletions MRBUpdater/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -13,15 +14,15 @@ namespace MRBUpdater
{
public partial class Update : Form
{
private BackgroundWorker UpdateWorker;
private PatchDecompressor PatchDecompressor;
private List<PatchDecompressor.FileData> DecompressedData;
private BackgroundWorker? UpdateWorker;
private PatchDecompressor? PatchDecompressor;
private List<PatchDecompressor.FileData>? DecompressedData;
private string UpdatePath { get; set; }
private string VersionText { get; set; }
private int ParentPid { get; set; }
private string ExtractPath { get; set; }
private static Uri UpdateFile { get; set; }
private static string PackedUpdate { get; set; }
private static Uri? UpdateFile { get; set; }
private static string? PackedUpdate { get; set; }

public Update(IReadOnlyList<string> args)
{
Expand All @@ -35,12 +36,12 @@ public Update(IReadOnlyList<string> args)
InitializeComponent();
}

private void OnLoad(object sender, EventArgs e)
private void OnLoad(object? sender, EventArgs e)
{
CenterToScreen();
}

private void OnShown(object sender, EventArgs e)
private void OnShown(object? sender, EventArgs e)
{
Updater_DownloadUpdate();
}
Expand Down Expand Up @@ -71,7 +72,7 @@ private void Updater_DownloadProgressChanged(object sender, DownloadProgressChan
Thread.Sleep(50);
}

private async void Updater_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
private async void Updater_DownloadFileCompleted(object? sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
Expand Down Expand Up @@ -101,45 +102,46 @@ private void Updater_BeginInstall()
UpdateWorker.RunWorkerAsync();
}

private void UpdateWorker_DoWork(object sender, DoWorkEventArgs e)
private void UpdateWorker_DoWork(object? sender, DoWorkEventArgs e)
{
Process.GetProcessById(ParentPid).Kill();
Process.GetProcessById(ParentPid).WaitForExit();
if (DecompressedData == null)
{
lblStatus.Text = @"Install Error: Aborting";
MessageBox.Show("Decompressed Data is NULL");
MessageBox.Show(@"Decompressed Data is NULL");
}
else
{
//PatchDecompressor.CleanOldEntries(ExtractPath);
if (PatchDecompressor == null) return;
PatchDecompressor.ProgressUpdate += PatchDecompressor_OnProgressUpdate;
PatchDecompressor.ErrorUpdate += PatchDecompressor_OnErrorUpdate;
PatchDecompressor.RecompileFileEntries(ExtractPath, DecompressedData);
}
}

private void PatchDecompressor_OnErrorUpdate(object sender, ErrorEventArgs e)
private void PatchDecompressor_OnErrorUpdate(object? sender, ErrorEventArgs e)
{
lblStatus.Text = @"Decompression Error: Aborting";
MessageBox.Show($"{e.GetException().Message}\r\r\n{e.GetException().StackTrace}");
UpdateWorker.CancelAsync();
UpdateWorker?.CancelAsync();
}

private void PatchDecompressor_OnProgressUpdate(object sender, ProgressEventArgs e)
private void PatchDecompressor_OnProgressUpdate(object? sender, ProgressEventArgs e)
{
lblFileName.Text = e.Name;
ctlProgressBar1.Value = e.PercentComplete;
UpdateWorker.ReportProgress(e.PercentComplete);
UpdateWorker?.ReportProgress(e.PercentComplete);
}

private void UpdateWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
private void UpdateWorker_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
{
ctlProgressBar1.Value = 99;
lblStatus.Text = @"Update Complete!";
lblFileName.Text = string.Empty;
Application.DoEvents();
File.Delete(PackedUpdate);
if (PackedUpdate != null) File.Delete(PackedUpdate);
Thread.Sleep(1000);
lblStatus.Text = @"Restarting...";
Application.DoEvents();
Expand Down
11 changes: 10 additions & 1 deletion MidsReborn/Controls/ctlMultiGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ private int CalcContentHeight()
}

const float nameXPadding = 3;
if (Items.Count == 0)
{
return 0;
}

for (var i = 0; i < Items.Count; i++)
{
if (string.IsNullOrWhiteSpace(Items[i].Name) & string.IsNullOrWhiteSpace(Items[i].Name2))
Expand All @@ -757,7 +762,11 @@ private int CalcContentHeight()
Math.Max(Name2XPadding, NameWidth) - Name2XPadding,
drawArea.Top + ny + PItemHeight + YPadding / 2f);

contentHeight = (int) Math.Ceiling(textRect.Bottom);
var itemScale = PerItemScales.Count == Items.Count && Items.Count > 0 ? PerItemScales[i] : ScaleValue;
var barWidth = (int)Math.Round(drawArea.Width * (Items[i].ValueBase / itemScale));
var barRect = new SKRect(drawArea.Left, drawArea.Top + ny, drawArea.Left + barWidth, drawArea.Top + ny + PItemHeight);

contentHeight = (int)Math.Ceiling(Math.Max(barRect.Bottom, textRect.Bottom));
}

return contentHeight;
Expand Down
4 changes: 2 additions & 2 deletions MidsReborn/Core/Base/Master_Classes/MidsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public static class MidsContext
private const int AppMajorVersion = 3;
private const int AppMinorVersion = 4;
private const int AppBuildVersion = 6;
private const int AppRevisionVersion = 6;
private const int AppRevisionVersion = 8;

public const string AssemblyVersion = "3.4.6";
public const string AssemblyFileVersion = "3.4.6.6";
public const string AssemblyFileVersion = "3.4.6.8";
public static Version AppFileVersion { get; set; } = new(AppMajorVersion, AppMinorVersion, AppBuildVersion, AppRevisionVersion);

public const string AppVersionStatus = "";
Expand Down
44 changes: 33 additions & 11 deletions MidsReborn/Core/Utils/PatchCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
Expand Down Expand Up @@ -31,6 +32,7 @@ public enum EPatchType

private const string PatchFolderName = @"Patches";
private const string HashFileName = @"FileHash.json";
public bool Generating { get; private set; }

private string TopLevelFolder
{
Expand Down Expand Up @@ -84,13 +86,21 @@ private IEnumerable<FileData> CompileList(string? path, EPatchType patchType)
var files = new List<string>();
List<FileHash>? hashes = null;
var fileQueue = new List<FileData>();
var exclusionList = new List<string>();
exclusionList = patchType switch
{
EPatchType.Application => new List<string> { "Patches", "Data", "Updater", "ICSharpCode" },
EPatchType.Database => new List<string> { "Patches" },
_ => exclusionList
};

files = patchType switch
{
EPatchType.Application => Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)
.Where(x => !x.Contains("Patches") && !x.Contains("Data"))
.Where(x => !exclusionList.Any(x.Contains))
.ToList(),
EPatchType.Database => Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)
.Where(x => !x.Contains("Patches"))
.Where(x => !exclusionList.Any(x.Contains))
.ToList(),
_ => files
};
Expand All @@ -104,7 +114,9 @@ private IEnumerable<FileData> CompileList(string? path, EPatchType patchType)
{
var fileInfo = new FileInfo(file);
var name = fileInfo.Name;
var directory = fileInfo.DirectoryName?.Replace(TopLevelFolder, string.Empty);
var directory = fileInfo.DirectoryName?
.Replace(TopLevelFolder, string.Empty)
.Replace(TopLevelFolder.Remove(TopLevelFolder.Length - 1, 1), string.Empty);
var data = File.ReadAllBytes(file);
if (directory == null) continue;
var newFile = new FileHash(directory, fileInfo.Name, FileHash.ComputeHash(file));
Expand Down Expand Up @@ -135,16 +147,26 @@ private IEnumerable<FileData> CompileList(string? path, EPatchType patchType)
return fileQueue;
}

public bool CreatePatchFile(string? path, EPatchType patchType)
public async Task<bool> CreatePatchFile(string? path, EPatchType patchType)
{
var boolReturn = false;
var completionSource = new TaskCompletionSource<bool>();
Generating = true;
var compressedData = CompressData(path, patchType);
if (compressedData == null) return boolReturn;
DeletePriorPatch(path);
var generated = GenerateFile(compressedData);
boolReturn = generated;

return boolReturn;
if (compressedData == null)
{
completionSource.TrySetResult(false);
}
else
{
DeletePriorPatch(path);
var generated = GenerateFile(compressedData);
completionSource.TrySetResult(generated);
Generating = false;
return await completionSource.Task;
}

Generating = false;
return await completionSource.Task;
}

private byte[]? CompressData(string? path, EPatchType patchType)
Expand Down
65 changes: 65 additions & 0 deletions MidsReborn/Forms/Controls/PatchMessenger.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions MidsReborn/Forms/Controls/PatchMessenger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Mids_Reborn.Core.Utils;

namespace Mids_Reborn.Forms.Controls
{
public partial class PatchMessenger : Form
{
private event EventHandler<string>? UpdateText;
private string? _text;

public override string Text
{
get => _text ?? base.Text;
set
{
_text = value;
UpdateText?.Invoke(this, value);
}
}

public PatchMessenger()
{
Load += OnLoad;
UpdateText += OnUpdateText;
InitializeComponent();
}

private void OnLoad(object? sender, EventArgs e)
{
CenterToParent();
}

private void OnUpdateText(object? sender, string e)
{
label1.Text = e;
Refresh();
}

public void Completed()
{
Close();
}
}
}
Loading

0 comments on commit 3dc3350

Please sign in to comment.