Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Mar 18, 2022
2 parents c37bb99 + 69ba5b8 commit 1f558b5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ public void Dispose()
AppDomain.Unload(_domain);
}
}
}
}
126 changes: 64 additions & 62 deletions src/Bannerlord.BUTRLoader.LauncherEx/Helpers/ModuleListHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,83 +73,84 @@ static IEnumerable<string> ReadAllLines(TextReader reader)
}
}

var thread = new Thread(() => {
var dialog = new OpenFileDialog
var thread = new Thread(() =>
{
FileName = "MyList.bmlist",
Filter = "Bannerlord Module List (*.bmlist)|*.bmlist",
Title = "Open a Bannerlord Module List File",

CheckFileExists = true,
CheckPathExists = true,
ReadOnlyChecked = true,
Multiselect = false,
ValidateNames = true
};

if (dialog.ShowDialog() == DialogResult.OK)
{
var wrapper = LauncherVMWrapper.Create(_launcherVM);
var dialog = new OpenFileDialog
{
FileName = "MyList.bmlist",
Filter = "Bannerlord Module List (*.bmlist)|*.bmlist",
Title = "Open a Bannerlord Module List File",

try
CheckFileExists = true,
CheckPathExists = true,
ReadOnlyChecked = true,
Multiselect = false,
ValidateNames = true
};

if (dialog.ShowDialog() == DialogResult.OK)
{
using var fs = dialog.OpenFile();
using var reader = new StreamReader(fs);
var modules = Deserialize(ReadAllLines(reader)).ToArray();
var moduleIds = modules.Select(x => x.Id).ToHashSet();
var wrappedModules = wrapper.ModsData.Modules
.Where(x => moduleIds.Contains(x.Info.Id))
.ToArray();
var wrappedModuleIds = wrappedModules.Select(x => x.Info?.Id).ToHashSet();
if (modules.Length != wrappedModules.Length)
var wrapper = LauncherVMWrapper.Create(_launcherVM);

try
{
var missingModules = moduleIds.Except(wrappedModuleIds);
HintManager.ShowHint(@$"Cancelled Import!
using var fs = dialog.OpenFile();
using var reader = new StreamReader(fs);
var modules = Deserialize(ReadAllLines(reader)).ToArray();
var moduleIds = modules.Select(x => x.Id).ToHashSet();
var wrappedModules = wrapper.ModsData.Modules
.Where(x => moduleIds.Contains(x.Info.Id))
.ToArray();
var wrappedModuleIds = wrappedModules.Select(x => x.Info?.Id).ToHashSet();
if (modules.Length != wrappedModules.Length)
{
var missingModules = moduleIds.Except(wrappedModuleIds);
HintManager.ShowHint(@$"Cancelled Import!
Missing modules:
{string.Join(Environment.NewLine, missingModules)}");
return;
}
return;
}

foreach (var launcherModuleVM in wrapper.ModsData.Modules)
{
launcherModuleVM.IsSelected = false;
}
var mismatchedVersions = new List<ModuleMismatch>();
foreach (var (id, version) in modules)
{
var wrappedModule = wrapper.ModsData.Modules
.FirstOrDefault(x => x.Info.Id == id);
if (wrappedModule?.Object is not null)
foreach (var launcherModuleVM in wrapper.ModsData.Modules)
{
var launcherModuleVersion = ToString(wrappedModule.Info?.Version ?? ApplicationVersion.Empty);
if (launcherModuleVersion == version)
{
wrappedModule.IsSelected = true;
continue;
}
else
launcherModuleVM.IsSelected = false;
}
var mismatchedVersions = new List<ModuleMismatch>();
foreach (var (id, version) in modules)
{
var wrappedModule = wrapper.ModsData.Modules
.FirstOrDefault(x => x.Info.Id == id);
if (wrappedModule?.Object is not null)
{
mismatchedVersions.Add(new ModuleMismatch(id, version, launcherModuleVersion));
var launcherModuleVersion = ToString(wrappedModule.Info?.Version ?? ApplicationVersion.Empty);
if (launcherModuleVersion == version)
{
wrappedModule.IsSelected = true;
continue;
}
else
{
mismatchedVersions.Add(new ModuleMismatch(id, version, launcherModuleVersion));
}
}
}
}
if (mismatchedVersions.Count > 0)
{
HintManager.ShowHint(@$"Warning!
if (mismatchedVersions.Count > 0)
{
HintManager.ShowHint(@$"Warning!
Mismatched module versions:
{string.Join(Environment.NewLine, mismatchedVersions)}");
}
else
{
HintManager.ShowHint("Successfully imported list!");
}
}
else
{
HintManager.ShowHint("Successfully imported list!");
}

LauncherVMPatch.UpdateAndSaveUserModsData(_launcherVM, false);
LauncherVMPatch.UpdateAndSaveUserModsData(_launcherVM, false);
}
catch (Exception) { }
}
catch (Exception) { }
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Expand All @@ -158,7 +159,8 @@ static IEnumerable<string> ReadAllLines(TextReader reader)

public void Export()
{
var thread = new Thread(() => {
var thread = new Thread(() =>
{
var dialog = new SaveFileDialog
{
FileName = "MyList.bmlist",
Expand Down Expand Up @@ -201,4 +203,4 @@ public void Export()
thread.Join();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class LauncherExData
public LauncherExData() { }
public LauncherExData(
bool extendedSorting, bool automaticallyCheckForUpdates,
bool unblockFiles, bool fixCommonIssues, bool compactModuleList,
bool unblockFiles, bool fixCommonIssues, bool compactModuleList,
bool resetModuleList, bool disableBinaryCheck)
{
ExtendedSorting = extendedSorting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal sealed class LauncherModsVMWrapper

public bool IsDisabledOnMultiplayer
{
get => Object is not null ? GetIsDisabledOnMultiplayer?.Invoke(Object) ?? false : false;
get => Object is not null ? GetIsDisabledOnMultiplayer?.Invoke(Object) ?? false : false;
set { if (Object is not null && SetIsDisabledOnMultiplayer is not null) SetIsDisabledOnMultiplayer(Object, value); }
}

Expand All @@ -56,4 +56,4 @@ private LauncherModsVMWrapper(object? @object)
Object = vm;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static bool OnAssemblyResolvePrefix(ref Assembly? __result, object sende
}
}

var name = args.Name.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
var name = args.Name.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
__result = Assembly.LoadFrom(name[0]);
return false;
}
Expand Down

0 comments on commit 1f558b5

Please sign in to comment.