Skip to content

Commit

Permalink
Merge pull request #163 from LoadedCamel/dev
Browse files Browse the repository at this point in the history
3.5.5.7 - Priority PR
  • Loading branch information
Metalios authored May 7, 2023
2 parents 1be9529 + a60ab9b commit 7c40e0b
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 104 deletions.
8 changes: 4 additions & 4 deletions MidsReborn/Core/Base/Master_Classes/MidsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public static class MidsContext
public const string AppName = "Mids' Reborn";
private const int AppMajorVersion = 3;
private const int AppMinorVersion = 5;
private const int AppBuildVersion = 4;
private const int AppRevisionVersion = 12;
private const int AppBuildVersion = 5;
private const int AppRevisionVersion = 7;

public const string AssemblyVersion = "3.5.4";
public const string AssemblyFileVersion = "3.5.4.12";
public const string AssemblyVersion = "3.5.5";
public const string AssemblyFileVersion = "3.5.5.7";
public static Version AppFileVersion { get; set; } = new(AppMajorVersion, AppMinorVersion, AppBuildVersion, AppRevisionVersion);

public const string AppVersionStatus = "";
Expand Down
75 changes: 58 additions & 17 deletions MidsReborn/Core/BuildFile/CharacterBuildFile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
Expand Down Expand Up @@ -504,23 +505,66 @@ public static bool Load(string fileName)
var metaData = _instance.BuiltWith;
if (metaData == null) throw new NullReferenceException(nameof(metaData));

// Compare App Version
var appVerResult = Helpers.CompareVersions(MidsContext.AppFileVersion, metaData.Version);
if (appVerResult)

// Compare App Version if Enabled
if (MidsContext.Config.WarnOnOldAppMbd)
{
var appVerMsg = new MessageBoxEx(@"Version Warning", $"This build was created with an older version of {MidsContext.AppName}, some features may not be available.", MessageBoxEx.MessageBoxButtons.Okay, MessageBoxEx.MessageBoxIcon.Warning, true);
appVerMsg.ShowDialog(Application.OpenForms["frmMain"]);
var outDatedApp = Helpers.CompareVersions(MidsContext.AppFileVersion, metaData.Version);
var newerApp = Helpers.CompareVersions(metaData.Version, MidsContext.AppFileVersion);

if (outDatedApp)
{
var appVerMsg = new MessageBoxEx(@"Version Warning", $"This build was created with an older version of {MidsContext.AppName}, some features may not be available.", MessageBoxEx.MessageBoxButtons.Okay, MessageBoxEx.MessageBoxIcon.Warning, true);
appVerMsg.ShowDialog(Application.OpenForms["frmMain"]);
}

if (newerApp)
{
var appVerMsg = new MessageBoxEx(@"Version Warning", $"This build was created with an newer version of {MidsContext.AppName}.\r\nIt is recommended that you update the application.", MessageBoxEx.MessageBoxButtons.Okay, MessageBoxEx.MessageBoxIcon.Warning, true);
appVerMsg.ShowDialog(Application.OpenForms["frmMain"]);
}
}


var fileInfo = new FileInfo(fileName);
if (DatabaseAPI.DatabaseName == metaData.Database)
{
// Compare Database Version
var dbVerResult = Helpers.CompareVersions(metaData.DatabaseVersion, DatabaseAPI.Database.Version);
if (dbVerResult)
// Compare Database Version if Enabled
if (MidsContext.Config.WarnOnOldDbMbd)
{
var dbVerMsg = new MessageBoxEx(fileInfo.Name, $"This build was created in an older version of the {metaData.Database} database.\r\nPlease update the database and try again.", MessageBoxEx.MessageBoxButtons.Okay, MessageBoxEx.MessageBoxIcon.Warning, true);
dbVerMsg.ShowDialog(Application.OpenForms["frmMain"]);

var outDatedDb = Helpers.CompareVersions(DatabaseAPI.Database.Version, metaData.DatabaseVersion);
var newerDb = Helpers.CompareVersions(metaData.DatabaseVersion, DatabaseAPI.Database.Version);

if (outDatedDb)
{
var dbVerMsg = new MessageBoxEx(fileInfo.Name, $"This build was created in an older version of the {metaData.Database} database.\r\nSome powers may have changed, you may need to rebuild some of it.\r\n\r\nDo you wish to load it anyway?", MessageBoxEx.MessageBoxButtons.YesNo, MessageBoxEx.MessageBoxIcon.Warning, true);
dbVerMsg.ShowDialog(Application.OpenForms["frmMain"]);
if (dbVerMsg.DialogResult == DialogResult.Yes)
{
returnedVal = LoadBuild();
}
else
{
return false;
}
}

if (newerDb)
{
var dbVerMsg = new MessageBoxEx(fileInfo.Name, $"This build was created in an newer version of the {metaData.Database} database.\r\nIt is recommended that you update the database.\r\n\r\nDo you wish to load it anyway?", MessageBoxEx.MessageBoxButtons.YesNo, MessageBoxEx.MessageBoxIcon.Warning, true);
dbVerMsg.ShowDialog(Application.OpenForms["frmMain"]);
if (dbVerMsg.DialogResult == DialogResult.Yes)
{
returnedVal = LoadBuild();
}
else
{
return false;
}
}

if (!outDatedDb && !newerDb) returnedVal = LoadBuild();
}
else
{
Expand All @@ -543,13 +587,10 @@ public static bool Load(string fileName)
return false;
}

if (MidsContext.Config != null)
{
MidsContext.Config.LastFileName = fileName;
MidsContext.Config.DataPath = selected;
MidsContext.Config.SavePath = selected;
MidsContext.Config.SaveConfig(Serializer.GetSerializer());
}
MidsContext.Config.LastFileName = fileName;
MidsContext.Config.DataPath = selected;
MidsContext.Config.SavePath = selected;
MidsContext.Config.SaveConfig(Serializer.GetSerializer());
Application.Restart();
break;
case DialogResult.No:
Expand Down
6 changes: 5 additions & 1 deletion MidsReborn/Core/ConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public enum ETotalsWindowTitleStyle

public ConfigData()
{
CheckForUpdates = true;
Authorized = false;
Registered = false;
DamageMath.Calculate = EDamageMath.Average;
Expand All @@ -73,6 +74,8 @@ public ConfigData()
CompOverride = Array.Empty<Enums.CompOverride>();
TeamMembers = new Dictionary<string, int>();
ShowSelfBuffsAny = false;
WarnOnOldAppMbd = true;
WarnOnOldDbMbd = true;
InitializeComponent();
}

Expand Down Expand Up @@ -149,7 +152,8 @@ public ConfigData()
public bool MasterMode { get; set; }
public bool IsLcAdmin { get; set; }
public bool ShrinkFrmSets { get; set; }

public bool WarnOnOldAppMbd { get; set; }
public bool WarnOnOldDbMbd { get; set; }

private string _buildsPath = Files.FDefaultBuildsPath;

Expand Down
2 changes: 1 addition & 1 deletion MidsReborn/Core/Utils/PatchCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private IEnumerable<FileData> CompileList(string? path, EPatchType patchType)
var exclusionList = new List<string>();
exclusionList = patchType switch
{
EPatchType.Application => new List<string> { "Patches", "Data", "Updater", "ICSharpCode" },
EPatchType.Application => new List<string> { "Patches", "Data", "Updater", "ICSharpCode", ".pdb" },
EPatchType.Database => new List<string> { "Patches" },
_ => exclusionList
};
Expand Down
Binary file modified MidsReborn/Data/Homecoming/I12.mhd
Binary file not shown.
69 changes: 55 additions & 14 deletions MidsReborn/Forms/Controls/FileMover.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

Expand All @@ -14,7 +16,21 @@ public partial class FileMover : Form
private bool _moveExceptionRequested;
private readonly string _sourceDirectory;
private readonly string _destinationDirectory;
private List<string> Items { get; set; }
private readonly List<Item> _items = new();

private struct Item
{
public string Source;
public string Directory;
public string Destination;

public Item(string source, string directory, string destination)
{
Source = source;
Directory = directory;
Destination = destination;
}
}

public FileMover(string source, string destination)
{
Expand All @@ -25,13 +41,13 @@ public FileMover(string source, string destination)

}

private void OnLoad(object sender, EventArgs e)
private void OnLoad(object? sender, EventArgs e)
{
CenterToParent();
sourceLabel.Text = _sourceDirectory;
destLabel.Text = _destinationDirectory;
Items = Directory.GetFiles(_sourceDirectory).ToList();
ctlProgressBar1.Maximum = Items.Count;
ExecuteDiscovery();
ctlProgressBar1.Maximum = _items.Count;
ctlProgressBar1.Value = 0;
ctlProgressBar1.Step = 1;
_progressWorker.WorkerReportsProgress = true;
Expand All @@ -41,40 +57,65 @@ private void OnLoad(object sender, EventArgs e)
Start();
}

private void ExecuteDiscovery()
{
var files = Directory.GetFiles(_sourceDirectory, "*.*", SearchOption.AllDirectories).ToList();
foreach (var file in files)
{
var fileInfo = new FileInfo(file);
if (!fileInfo.Exists) continue;
var dirInfo = fileInfo.Directory;
if (dirInfo == null) continue;
_items.Add(_sourceDirectory.Contains(dirInfo.Name)
? new Item(fileInfo.FullName, string.Empty, Path.Combine(_destinationDirectory, fileInfo.Name))
: new Item(fileInfo.FullName, dirInfo.Name,
Path.Combine(_destinationDirectory, dirInfo.Name, fileInfo.Name)));
}
}

private bool DestinationHasStructure => _items.Any(x => !string.IsNullOrWhiteSpace(x.Directory));

private void Start()
{
_progressWorker.RunWorkerAsync();
}

private void ProgressWorker_DoWork(object sender, DoWorkEventArgs e)
private void ProgressWorker_DoWork(object? sender, DoWorkEventArgs e)
{
ctlProgressBar1.StatusText = @"Moving...";
ctlProgressBar1.ItemCount = Items.Count;
for (var index = 0; index < Items.Count; index++)
if (DestinationHasStructure)
{
ctlProgressBar1.StatusText = @"Recreating Directory Structure...";
foreach (var path in from item in _items where !string.IsNullOrWhiteSpace(item.Directory) select Path.Combine(_destinationDirectory, item.Directory) into path where !Directory.Exists(path) select path)
{
Directory.CreateDirectory(path);
}
}
ctlProgressBar1.StatusText = @"Moving Builds...";
ctlProgressBar1.ItemCount = _items.Count;
for (var itemIndex = 0; itemIndex < _items.Count; itemIndex++)
{
var item = Items[index];
var fInfo = new FileInfo(item);
var item = _items[itemIndex];
try
{
File.Move(fInfo.FullName, Path.Combine(_destinationDirectory, fInfo.Name));
File.Move(item.Source, item.Destination);
}
catch (Exception)
{
_moveExceptionRequested = true;
}

var percentage = (index * ctlProgressBar1.Maximum) / Items.Count;
var percentage = (itemIndex * ctlProgressBar1.Maximum) / _items.Count;
_progressWorker.ReportProgress(percentage);
Thread.Sleep(50);
}
}

private void ProgressWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
private void ProgressWorker_ProgressChanged(object? sender, ProgressChangedEventArgs e)
{
ctlProgressBar1.Value = e.ProgressPercentage;
}

private void ProgressWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
private void ProgressWorker_RunWorkerCompleted(object? sender, RunWorkerCompletedEventArgs e)
{
ctlProgressBar1.StatusText = string.Empty;
if (!_moveExceptionRequested)
Expand Down
Loading

0 comments on commit 7c40e0b

Please sign in to comment.