From 385e64bdc5bf16718feab058fe3383630eb2951d Mon Sep 17 00:00:00 2001 From: Seweryn Presnal Date: Sat, 15 Jul 2023 23:17:47 +0200 Subject: [PATCH 1/8] TargetPlaysetPickerView --- Fronter.NET.sln.DotSettings | 3 ++- .../Models/Configuration/Configuration.cs | 24 +++++++---------- Fronter.NET/Models/Configuration/Mod.cs | 18 ------------- .../Models/Configuration/RequiredFolder.cs | 4 --- .../Configuration/converter_l_english.yml | 1 + Fronter.NET/ViewModels/MainWindowViewModel.cs | 6 ++--- Fronter.NET/ViewModels/ModsPickerViewModel.cs | 27 ------------------- .../TargetPlaysetPickerViewModel.cs | 27 +++++++++++++++++++ Fronter.NET/Views/MainWindow.axaml | 4 +-- ...ew.axaml => TargetPlaysetPickerView.axaml} | 21 +++++++-------- ...ml.cs => TargetPlaysetPickerView.axaml.cs} | 4 +-- 11 files changed, 55 insertions(+), 84 deletions(-) delete mode 100644 Fronter.NET/Models/Configuration/Mod.cs delete mode 100644 Fronter.NET/ViewModels/ModsPickerViewModel.cs create mode 100644 Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs rename Fronter.NET/Views/{ModsPickerView.axaml => TargetPlaysetPickerView.axaml} (77%) rename Fronter.NET/Views/{ModsPickerView.axaml.cs => TargetPlaysetPickerView.axaml.cs} (65%) diff --git a/Fronter.NET.sln.DotSettings b/Fronter.NET.sln.DotSettings index 4f9723e9..12e5ec2c 100644 --- a/Fronter.NET.sln.DotSettings +++ b/Fronter.NET.sln.DotSettings @@ -16,4 +16,5 @@ True True True - True \ No newline at end of file + True + True \ No newline at end of file diff --git a/Fronter.NET/Models/Configuration/Configuration.cs b/Fronter.NET/Models/Configuration/Configuration.cs index c3401f0e..be2da80b 100644 --- a/Fronter.NET/Models/Configuration/Configuration.cs +++ b/Fronter.NET/Models/Configuration/Configuration.cs @@ -18,8 +18,8 @@ public class Configuration { public string DisplayName { get; private set; } = string.Empty; public string SourceGame { get; private set; } = string.Empty; public string TargetGame { get; private set; } = string.Empty; - public string? ModAutoGenerationSource { get; private set; } = null; - public ObservableCollection AutoLocatedMods { get; } = new(); + public string? TargetPlaysetsSource { get; private set; } = null; + public ObservableCollection AutoLocatedMods { get; } = new(); public bool CopyToTargetGameModDirectory { get; set; } = true; public ushort ProgressOnCopyingComplete { get; set; } = 109; public bool OverwritePlayset { get; set; } = false; @@ -98,8 +98,8 @@ private void RegisterKeys(Parser parser) { parser.RegisterKeyword("targetGame", reader => { TargetGame = reader.GetString(); }); - parser.RegisterKeyword("autoGenerateModsFrom", reader => { - ModAutoGenerationSource = reader.GetString(); + parser.RegisterKeyword("targetPlaysetsSource", reader => { + TargetPlaysetsSource = reader.GetString(); }); parser.RegisterKeyword("copyToTargetGameModDirectory", reader => { CopyToTargetGameModDirectory = reader.GetString() == "true"; @@ -206,10 +206,6 @@ public void InitializePaths() { if (Directory.Exists(initialValue)) { folder.Value = initialValue; } - - if (folder.Name == ModAutoGenerationSource) { - AutoLocateMods(); - } } foreach (var file in RequiredFiles) { @@ -281,15 +277,13 @@ public bool ExportConfiguration() { writer.WriteLine($"{file.Name} = \"{file.Value}\""); } - if (ModAutoGenerationSource is not null) { - writer.WriteLine("selectedMods = {"); - foreach (var mod in AutoLocatedMods) { - if (mod.Enabled) { - writer.WriteLine($"\t\"{mod.FileName}\""); - } + writer.WriteLine("selectedMods = {"); + foreach (var mod in AutoLocatedMods) { + if (mod.Enabled) { + writer.WriteLine($"\t\"{mod.FileName}\""); } - writer.WriteLine("}"); } + writer.WriteLine("}"); foreach (var option in Options) { if (option.CheckBoxSelector is not null) { diff --git a/Fronter.NET/Models/Configuration/Mod.cs b/Fronter.NET/Models/Configuration/Mod.cs deleted file mode 100644 index 9c3a71de..00000000 --- a/Fronter.NET/Models/Configuration/Mod.cs +++ /dev/null @@ -1,18 +0,0 @@ -using commonItems; -using Fronter.ViewModels; - -namespace Fronter.Models.Configuration; - -public class Mod : ViewModelBase { - public Mod(string modPath) { - var parser = new Parser(); - parser.RegisterKeyword("name", reader => Name = reader.GetString()); - parser.IgnoreUnregisteredItems(); - - parser.ParseFile(modPath); - FileName = CommonFunctions.TrimPath(modPath); - } - public string Name { get; private set; } = string.Empty; - public string FileName { get; private set; } - public bool Enabled { get; set; } = false; -} \ No newline at end of file diff --git a/Fronter.NET/Models/Configuration/RequiredFolder.cs b/Fronter.NET/Models/Configuration/RequiredFolder.cs index d5ca560a..9d4fac81 100644 --- a/Fronter.NET/Models/Configuration/RequiredFolder.cs +++ b/Fronter.NET/Models/Configuration/RequiredFolder.cs @@ -44,10 +44,6 @@ public override string Value { base.Value = value; logger.Info($"{TranslationSource.Instance[DisplayName]} set to: {value}"); - - if (Name == config.ModAutoGenerationSource) { - config.AutoLocateMods(); - } } } diff --git a/Fronter.NET/Resources/Configuration/converter_l_english.yml b/Fronter.NET/Resources/Configuration/converter_l_english.yml index 84add363..edd9d1f8 100644 --- a/Fronter.NET/Resources/Configuration/converter_l_english.yml +++ b/Fronter.NET/Resources/Configuration/converter_l_english.yml @@ -30,6 +30,7 @@ l_english: OPTIONSTAB: "Options" CONVERTTAB: "Convert" MODSTAB: "Mods" + TARGET_PLAYSET_TAB: "Target Playset" MODSDISABLED: "Mod autodetection disabled by configuration/not required." MODSNOTFOUND: "Mods not found in mod directory." MODSFOUND: "Mods autodetected:" diff --git a/Fronter.NET/ViewModels/MainWindowViewModel.cs b/Fronter.NET/ViewModels/MainWindowViewModel.cs index 35ee63c6..f30aa467 100644 --- a/Fronter.NET/ViewModels/MainWindowViewModel.cs +++ b/Fronter.NET/ViewModels/MainWindowViewModel.cs @@ -54,8 +54,8 @@ public class MainWindowViewModel : ViewModelBase { public Configuration Config { get; } public PathPickerViewModel PathPicker { get; } - public ModsPickerViewModel ModsPicker { get; } - public bool ModsPickerTabVisible => Config.ModAutoGenerationSource is not null; + public TargetPlaysetPickerViewModel TargetPlaysetPicker { get; } + public bool TargetPlaysetPickerTabVisible => Config.TargetPlaysetsSource is not null; public OptionsViewModel Options { get; } public bool OptionsTabVisible => Options.Items.Any(); @@ -99,7 +99,7 @@ public MainWindowViewModel(DataGrid logGrid) { LogGridAppender.LogGrid = logGrid; PathPicker = new PathPickerViewModel(Config); - ModsPicker = new ModsPickerViewModel(Config); + TargetPlaysetPicker = new TargetPlaysetPickerViewModel(Config); Options = new OptionsViewModel(Config.Options); // Create reactive commands. diff --git a/Fronter.NET/ViewModels/ModsPickerViewModel.cs b/Fronter.NET/ViewModels/ModsPickerViewModel.cs deleted file mode 100644 index adc8138f..00000000 --- a/Fronter.NET/ViewModels/ModsPickerViewModel.cs +++ /dev/null @@ -1,27 +0,0 @@ -using DynamicData; -using DynamicData.Binding; -using Fronter.Models.Configuration; -using System; -using System.Collections.ObjectModel; - -namespace Fronter.ViewModels; - -/// -/// The ModsPickerViewModel lets the user select paths to various stuff the converter needs to know where to find. -/// -public class ModsPickerViewModel : ViewModelBase { - public ModsPickerViewModel(Configuration config) { - config.AutoLocatedMods.ToObservableChangeSet() - .Bind(out autoLocatedMods) - .Subscribe(); - - if (config.ModAutoGenerationSource is null) { - ModsDisabled = true; - } - } - - private readonly ReadOnlyObservableCollection autoLocatedMods; - public ReadOnlyObservableCollection AutoLocatedMods => autoLocatedMods; - - public bool ModsDisabled { get; } = false; -} \ No newline at end of file diff --git a/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs b/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs new file mode 100644 index 00000000..7b4f9400 --- /dev/null +++ b/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs @@ -0,0 +1,27 @@ +using DynamicData; +using DynamicData.Binding; +using Fronter.Models.Configuration; +using System; +using System.Collections.ObjectModel; + +namespace Fronter.ViewModels; + +/// +/// The TargetPlaysetPickerViewModel lets the user select paths to various stuff the converter needs to know where to find. +/// +public class TargetPlaysetPickerViewModel : ViewModelBase { + public TargetPlaysetPickerViewModel(Configuration config) { + config.TargetPlaysets.ToObservableChangeSet() + .Bind(out targetPlaysets) + .Subscribe(); + + if (config.TargetPlaysetsSource is null) { + TabDisabled = true; + } + } + + private readonly ReadOnlyObservableCollection targetPlaysets; + public ReadOnlyObservableCollection TargetPlaysets => targetPlaysets; + + public bool TabDisabled { get; } = false; +} \ No newline at end of file diff --git a/Fronter.NET/Views/MainWindow.axaml b/Fronter.NET/Views/MainWindow.axaml index 6afa0c1f..ced90b2a 100644 --- a/Fronter.NET/Views/MainWindow.axaml +++ b/Fronter.NET/Views/MainWindow.axaml @@ -71,9 +71,9 @@ - + - + diff --git a/Fronter.NET/Views/ModsPickerView.axaml b/Fronter.NET/Views/TargetPlaysetPickerView.axaml similarity index 77% rename from Fronter.NET/Views/ModsPickerView.axaml rename to Fronter.NET/Views/TargetPlaysetPickerView.axaml index 02dd8114..86fc298d 100644 --- a/Fronter.NET/Views/ModsPickerView.axaml +++ b/Fronter.NET/Views/TargetPlaysetPickerView.axaml @@ -4,13 +4,13 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:viewModels="clr-namespace:Fronter.ViewModels" xmlns:ns="clr-namespace:Fronter.Extensions" - x:Class="Fronter.Views.ModsPickerView" - x:DataType="viewModels:ModsPickerViewModel" + x:Class="Fronter.Views.TargetPlaysetPickerView" + x:DataType="viewModels:TargetPlaysetPickerViewModel" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> - + @@ -43,17 +43,14 @@ - - + + + - + - - + + diff --git a/Fronter.NET/Views/ModsPickerView.axaml.cs b/Fronter.NET/Views/TargetPlaysetPickerView.axaml.cs similarity index 65% rename from Fronter.NET/Views/ModsPickerView.axaml.cs rename to Fronter.NET/Views/TargetPlaysetPickerView.axaml.cs index a05f7e54..b6e9d74b 100644 --- a/Fronter.NET/Views/ModsPickerView.axaml.cs +++ b/Fronter.NET/Views/TargetPlaysetPickerView.axaml.cs @@ -3,8 +3,8 @@ namespace Fronter.Views; -public partial class ModsPickerView : UserControl { - public ModsPickerView() { +public partial class TargetPlaysetPickerView : UserControl { + public TargetPlaysetPickerView() { InitializeComponent(); } From 7fdba15117c6ad4b8ab6615e575c4d42e49ba445 Mon Sep 17 00:00:00 2001 From: Seweryn Presnal Date: Thu, 20 Jul 2023 00:21:52 +0200 Subject: [PATCH 2/8] TargetPlaylist class --- Fronter.NET/Models/Configuration/Configuration.cs | 13 ++++--------- Fronter.NET/Models/Configuration/RequiredFolder.cs | 4 ++++ Fronter.NET/Models/Configuration/TargetPlaylist.cs | 6 ++++++ 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 Fronter.NET/Models/Configuration/TargetPlaylist.cs diff --git a/Fronter.NET/Models/Configuration/Configuration.cs b/Fronter.NET/Models/Configuration/Configuration.cs index be2da80b..d2111ea5 100644 --- a/Fronter.NET/Models/Configuration/Configuration.cs +++ b/Fronter.NET/Models/Configuration/Configuration.cs @@ -316,9 +316,9 @@ private static void SetSavingStatus(string locKey) { } } - public void AutoLocateMods() { - logger.Debug("Clearing previously located mods..."); - AutoLocatedMods.Clear(); + public void AutoLocatePlaylists() { + logger.Debug("Clearing previously located playlists..."); + AutoLocatedPlaylists.Clear(); logger.Debug("Autolocating mods..."); // Do we have a mod path? @@ -339,12 +339,7 @@ public void AutoLocateMods() { return; } - // Are we looking at documents directory? - var combinedPath = Path.Combine(modPath, "mod"); - if (Directory.Exists(combinedPath)) { - modPath = combinedPath; - } - logger.Debug($"Mods autolocation path set to: \"{modPath}\""); + logger.Debug($"Mods autolocation path set to: \"{modPath}\"."); // Are there mods inside? var validModFiles = new List(); diff --git a/Fronter.NET/Models/Configuration/RequiredFolder.cs b/Fronter.NET/Models/Configuration/RequiredFolder.cs index 9d4fac81..b623a9b8 100644 --- a/Fronter.NET/Models/Configuration/RequiredFolder.cs +++ b/Fronter.NET/Models/Configuration/RequiredFolder.cs @@ -44,6 +44,10 @@ public override string Value { base.Value = value; logger.Info($"{TranslationSource.Instance[DisplayName]} set to: {value}"); + + if (Name == config.TargetPlaysetsSource) { + config.AutoLocatePlaylists(); + } } } diff --git a/Fronter.NET/Models/Configuration/TargetPlaylist.cs b/Fronter.NET/Models/Configuration/TargetPlaylist.cs new file mode 100644 index 00000000..8ecd4323 --- /dev/null +++ b/Fronter.NET/Models/Configuration/TargetPlaylist.cs @@ -0,0 +1,6 @@ +namespace Fronter.Models.Configuration; + +public class TargetPlaylist { + public required string Id { get; init; } + public required string Name { get; init; } +} \ No newline at end of file From 777b8362334cc80680e042d2027b146b82a2029a Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Wed, 20 Dec 2023 18:12:23 +0100 Subject: [PATCH 3/8] TargetDbManager --- Fronter.NET/Models/Configuration/Config.cs | 114 ++++++------------ .../Models/Configuration/RequiredFolder.cs | 4 +- .../Models/Configuration/TargetPlaylist.cs | 6 - .../Models/Configuration/TargetPlayset.cs | 8 ++ Fronter.NET/Services/ModCopier.cs | 18 +-- Fronter.NET/Services/TargetDbManager.cs | 37 ++++++ Fronter.NET/ViewModels/MainWindowViewModel.cs | 2 +- .../TargetPlaysetPickerViewModel.cs | 10 +- Fronter.NET/Views/MainWindow.axaml | 2 +- .../Views/TargetPlaysetPickerView.axaml | 7 +- 10 files changed, 98 insertions(+), 110 deletions(-) delete mode 100644 Fronter.NET/Models/Configuration/TargetPlaylist.cs create mode 100644 Fronter.NET/Models/Configuration/TargetPlayset.cs create mode 100644 Fronter.NET/Services/TargetDbManager.cs diff --git a/Fronter.NET/Models/Configuration/Config.cs b/Fronter.NET/Models/Configuration/Config.cs index 2722751e..cfa05ab1 100644 --- a/Fronter.NET/Models/Configuration/Config.cs +++ b/Fronter.NET/Models/Configuration/Config.cs @@ -1,6 +1,7 @@ using Avalonia.Controls.ApplicationLifetimes; using commonItems; using Fronter.Models.Configuration.Options; +using Fronter.Services; using Fronter.ViewModels; using log4net; using Sentry; @@ -20,8 +21,9 @@ public class Config { public string SourceGame { get; private set; } = string.Empty; public string TargetGame { get; private set; } = string.Empty; public string? SentryDsn { get; private set; } - public string? TargetPlaysetsSource { get; private set; } = null; - public ObservableCollection AutoLocatedMods { get; } = new(); + public bool TargetPlaysetSelectionEnabled { get; private set; } = false; + public ObservableCollection AutoLocatedPlaysets { get; } = []; + public TargetPlayset? SelectedPlayset { get; set; } public bool CopyToTargetGameModDirectory { get; set; } = true; public ushort ProgressOnCopyingComplete { get; set; } = 109; public bool UpdateCheckerEnabled { get; private set; } = false; @@ -92,8 +94,8 @@ private void RegisterKeys(Parser parser) { parser.RegisterKeyword("displayName", reader => DisplayName = reader.GetString()); parser.RegisterKeyword("sourceGame", reader => SourceGame = reader.GetString()); parser.RegisterKeyword("targetGame", reader => TargetGame = reader.GetString()); - parser.RegisterKeyword("targetPlaysetsSource", reader => { - TargetPlaysetsSource = reader.GetString(); + parser.RegisterKeyword("targetPlaysetSelectionEnabled", reader => { + TargetPlaysetSelectionEnabled = reader.GetBool(); }); parser.RegisterKeyword("copyToTargetGameModDirectory", reader => { CopyToTargetGameModDirectory = reader.GetString() == "true"; @@ -164,8 +166,8 @@ private void InitSentry(string dsn) { private void RegisterPreloadKeys(Parser parser) { parser.RegisterRegex(CommonRegexes.String, (reader, incomingKey) => { - var valueStringOfItem = reader.GetStringOfItem(); - var valueStr = valueStringOfItem.ToString().RemQuotes(); + StringOfItem valueStringOfItem = reader.GetStringOfItem(); + string valueStr = valueStringOfItem.ToString().RemQuotes(); var valueReader = new BufferedReader(valueStr); foreach (var folder in RequiredFolders) { @@ -189,13 +191,6 @@ private void RegisterPreloadKeys(Parser parser) { option.SetCheckBoxSelectorPreloaded(); } } - if (incomingKey == "selectedMods") { - var theList = valueReader.GetStrings(); - var matchingMods = AutoLocatedMods.Where(m => theList.Contains(m.FileName)); - foreach (var mod in matchingMods) { - mod.Enabled = true; - } - } }); parser.RegisterRegex(CommonRegexes.Catchall, ParserHelpers.IgnoreAndLogItem); } @@ -316,14 +311,10 @@ public bool ExportConfiguration() { } writer.WriteLine($"{file.Name} = \"{file.Value}\""); } - - writer.WriteLine("selectedMods = {"); - foreach (var mod in AutoLocatedMods) { - if (mod.Enabled) { - writer.WriteLine($"\t\"{mod.FileName}\""); - } + + if (SelectedPlayset is not null) { + writer.WriteLine($"selectedPlayset = {SelectedPlayset.Id}"); } - writer.WriteLine("}"); foreach (var option in Options) { if (option.CheckBoxSelector is not null) { @@ -356,67 +347,34 @@ private static void SetSavingStatus(string locKey) { } } - public void AutoLocatePlaylists() { - logger.Debug("Clearing previously located playlists..."); - AutoLocatedPlaylists.Clear(); - logger.Debug("Autolocating mods..."); - - // Do we have a mod path? - string? modPath = null; - foreach (var folder in RequiredFolders) { - if (folder.Name == ModAutoGenerationSource) { - modPath = folder.Value; - } - } - if (modPath is null) { - logger.Warn("No folder found as source for mods autolocation."); - return; - } - - // Does it exist? - if (!Directory.Exists(modPath)) { - logger.Warn($"Mod path \"{modPath}\" does not exist or can not be accessed!"); - return; - } - - logger.Debug($"Mods autolocation path set to: \"{modPath}\"."); - - // Are there mods inside? - var validModFiles = new List(); - foreach (var file in SystemUtils.GetAllFilesInFolder(modPath)) { - var lastDot = file.LastIndexOf('.'); - if (lastDot == -1) { - continue; - } - - var extension = CommonFunctions.GetExtension(file); - if (extension != "mod") { - continue; - } - - validModFiles.Add(file); - } - - if (validModFiles.Count == 0) { - logger.Debug($"No mod files could be found in \"{modPath}\""); - return; + public string? TargetGameModsPath { + get { + var targetGameModPath = RequiredFolders + .FirstOrDefault(f => f?.Name == "targetGameModPath", defaultValue: null); + return targetGameModPath?.Value; } + } - foreach (var modFile in validModFiles) { - var path = Path.Combine(modPath, modFile); - Mod theMod; - try { - theMod = new Mod(path); - } catch (IOException ex) { - logger.Warn($"Failed to parse mod file {modFile}: {ex.Message}"); - continue; - } - if (string.IsNullOrEmpty(theMod.Name)) { - logger.Warn($"Mod at \"{path}\" has no defined name, skipping."); - continue; + public void AutoLocatePlaysets() { + logger.Debug("Clearing previously located playsets..."); + AutoLocatedPlaysets.Clear(); + logger.Debug("Autolocating playsets..."); + + var destModsFolder = TargetGameModsPath; + logger.Error(destModsFolder); + var locatedPlaysetsCount = 0; + if (destModsFolder is not null) { + var dbContext = TargetDbManager.GetLauncherDbContext(this); + if (dbContext is not null) { + foreach (var playset in dbContext.Playsets) { + AutoLocatedPlaysets.Add(new TargetPlayset(playset)); + logger.Error($"New playset: {playset.Name}"); + } } - AutoLocatedMods.Add(theMod); + + locatedPlaysetsCount = AutoLocatedPlaysets.Count; } - logger.Debug($"Autolocated {AutoLocatedMods.Count} mods"); + + logger.Debug($"Autolocated {locatedPlaysetsCount} playsets."); } } \ No newline at end of file diff --git a/Fronter.NET/Models/Configuration/RequiredFolder.cs b/Fronter.NET/Models/Configuration/RequiredFolder.cs index aee92c36..5cccd839 100644 --- a/Fronter.NET/Models/Configuration/RequiredFolder.cs +++ b/Fronter.NET/Models/Configuration/RequiredFolder.cs @@ -45,8 +45,8 @@ public override string Value { base.Value = value; logger.Info($"{TranslationSource.Instance[DisplayName]} set to: {value}"); - if (Name == config.TargetPlaysetsSource) { - config.AutoLocatePlaylists(); + if (config.TargetPlaysetSelectionEnabled) { + config.AutoLocatePlaysets(); } } } diff --git a/Fronter.NET/Models/Configuration/TargetPlaylist.cs b/Fronter.NET/Models/Configuration/TargetPlaylist.cs deleted file mode 100644 index 8ecd4323..00000000 --- a/Fronter.NET/Models/Configuration/TargetPlaylist.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Fronter.Models.Configuration; - -public class TargetPlaylist { - public required string Id { get; init; } - public required string Name { get; init; } -} \ No newline at end of file diff --git a/Fronter.NET/Models/Configuration/TargetPlayset.cs b/Fronter.NET/Models/Configuration/TargetPlayset.cs new file mode 100644 index 00000000..e4388797 --- /dev/null +++ b/Fronter.NET/Models/Configuration/TargetPlayset.cs @@ -0,0 +1,8 @@ +using Fronter.Models.Database; + +namespace Fronter.Models.Configuration; + +public class TargetPlayset(Playset playset) { + public string Id => playset.Id; + public string Name => playset.Name; +} \ No newline at end of file diff --git a/Fronter.NET/Services/ModCopier.cs b/Fronter.NET/Services/ModCopier.cs index 36f70fcb..a4f5c035 100644 --- a/Fronter.NET/Services/ModCopier.cs +++ b/Fronter.NET/Services/ModCopier.cs @@ -32,13 +32,11 @@ public bool CopyMod() { return false; } - var requiredFolders = config.RequiredFolders; - var targetGameModPath = requiredFolders.FirstOrDefault(f => f?.Name == "targetGameModPath", null); - if (targetGameModPath is null) { + string? destModsFolder = config.TargetGameModsPath; + if (destModsFolder is null) { logger.Error("Copy failed - Target Folder isn't loaded!"); return false; } - var destModsFolder = targetGameModPath.Value; if (!Directory.Exists(destModsFolder)) { logger.Error("Copy failed - Target Folder does not exist!"); return false; @@ -144,7 +142,7 @@ private void CreatePlayset(string targetModsDirectory, string modName, string de logger.Warn($"Couldn't get parent directory of \"{targetModsDirectory}\"."); return; } - var latestDbFilePath = GetLastUpdatedLauncherDbPath(gameDocsDirectory); + var latestDbFilePath = TargetDbManager.GetLastUpdatedLauncherDbPath(gameDocsDirectory); if (latestDbFilePath is null) { logger.Debug("Launcher's database not found."); return; @@ -234,16 +232,6 @@ private void CreatePlayset(string targetModsDirectory, string modName, string de } } - private static string? GetLastUpdatedLauncherDbPath(string gameDocsDirectory) { - var possibleDbFileNames = new List { "launcher-v2.sqlite", "launcher-v2_openbeta.sqlite" }; - var latestDbFilePath = possibleDbFileNames - .Select(name => Path.Join(gameDocsDirectory, name)) - .Where(File.Exists) - .OrderByDescending(File.GetLastWriteTimeUtc) - .FirstOrDefault(defaultValue: null); - return latestDbFilePath; - } - // Returns saved mod. private Mod AddModToDb(LauncherDbContext dbContext, string modName, string gameRegistryId, string dirPath) { logger.Debug($"Saving mod \"{modName}\" to DB..."); diff --git a/Fronter.NET/Services/TargetDbManager.cs b/Fronter.NET/Services/TargetDbManager.cs new file mode 100644 index 00000000..835c39c4 --- /dev/null +++ b/Fronter.NET/Services/TargetDbManager.cs @@ -0,0 +1,37 @@ +using Fronter.Models.Configuration; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Fronter.Services; + +public class TargetDbManager { + public static string? GetLastUpdatedLauncherDbPath(string gameDocsDirectory) { + var possibleDbFileNames = new List { "launcher-v2.sqlite", "launcher-v2_openbeta.sqlite" }; + var latestDbFilePath = possibleDbFileNames + .Select(name => Path.Join(gameDocsDirectory, name)) + .Where(File.Exists) + .OrderByDescending(File.GetLastWriteTimeUtc) + .FirstOrDefault(defaultValue: null); + return latestDbFilePath; + } + + public static LauncherDbContext? GetLauncherDbContext(Config config) { + var targetGameModsPath = config.TargetGameModsPath; + if (string.IsNullOrWhiteSpace(targetGameModsPath)) { + return null; + } + var gameDocsDirectory = Directory.GetParent(targetGameModsPath)?.FullName; + if (gameDocsDirectory is null) { + return null; + } + + var dbPath = GetLastUpdatedLauncherDbPath(gameDocsDirectory); + if (dbPath is null) { + return null; + } + + string connectionString = $"Data Source={dbPath};"; + return new LauncherDbContext(connectionString); + } +} \ No newline at end of file diff --git a/Fronter.NET/ViewModels/MainWindowViewModel.cs b/Fronter.NET/ViewModels/MainWindowViewModel.cs index c43ab9ab..827313e3 100644 --- a/Fronter.NET/ViewModels/MainWindowViewModel.cs +++ b/Fronter.NET/ViewModels/MainWindowViewModel.cs @@ -55,7 +55,7 @@ public sealed class MainWindowViewModel : ViewModelBase { internal PathPickerViewModel PathPicker { get; } internal TargetPlaysetPickerViewModel TargetPlaysetPicker { get; } - public bool TargetPlaysetPickerTabVisible => Config.TargetPlaysetsSource is not null; + public bool TargetPlaysetPickerTabVisible => Config.TargetPlaysetSelectionEnabled; public OptionsViewModel Options { get; } public bool OptionsTabVisible => Options.Items.Any(); diff --git a/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs b/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs index 7b4f9400..52e4c734 100644 --- a/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs +++ b/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs @@ -10,12 +10,16 @@ namespace Fronter.ViewModels; /// The TargetPlaysetPickerViewModel lets the user select paths to various stuff the converter needs to know where to find. /// public class TargetPlaysetPickerViewModel : ViewModelBase { - public TargetPlaysetPickerViewModel(Configuration config) { - config.TargetPlaysets.ToObservableChangeSet() + private Config _config; + + public TargetPlaysetPickerViewModel(Config config) { + _config = config; + + config.AutoLocatedPlaysets.ToObservableChangeSet() .Bind(out targetPlaysets) .Subscribe(); - if (config.TargetPlaysetsSource is null) { + if (!config.TargetPlaysetSelectionEnabled) { TabDisabled = true; } } diff --git a/Fronter.NET/Views/MainWindow.axaml b/Fronter.NET/Views/MainWindow.axaml index ced90b2a..d7e3df07 100644 --- a/Fronter.NET/Views/MainWindow.axaml +++ b/Fronter.NET/Views/MainWindow.axaml @@ -71,7 +71,7 @@ - + diff --git a/Fronter.NET/Views/TargetPlaysetPickerView.axaml b/Fronter.NET/Views/TargetPlaysetPickerView.axaml index 86fc298d..1e398e43 100644 --- a/Fronter.NET/Views/TargetPlaysetPickerView.axaml +++ b/Fronter.NET/Views/TargetPlaysetPickerView.axaml @@ -37,9 +37,8 @@ - - - + + @@ -47,7 +46,7 @@ - + From 3e183c6fef6821f8e46b2579a315850065c63916 Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Wed, 20 Dec 2023 18:28:29 +0100 Subject: [PATCH 4/8] Button for reloading the mods --- Fronter.NET/Models/Configuration/Config.cs | 4 +--- .../TargetPlaysetPickerViewModel.cs | 4 ++++ .../Views/TargetPlaysetPickerView.axaml | 22 ++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Fronter.NET/Models/Configuration/Config.cs b/Fronter.NET/Models/Configuration/Config.cs index cfa05ab1..4734b889 100644 --- a/Fronter.NET/Models/Configuration/Config.cs +++ b/Fronter.NET/Models/Configuration/Config.cs @@ -361,14 +361,12 @@ public void AutoLocatePlaysets() { logger.Debug("Autolocating playsets..."); var destModsFolder = TargetGameModsPath; - logger.Error(destModsFolder); var locatedPlaysetsCount = 0; if (destModsFolder is not null) { var dbContext = TargetDbManager.GetLauncherDbContext(this); if (dbContext is not null) { - foreach (var playset in dbContext.Playsets) { + foreach (var playset in dbContext.Playsets.Where(p => p.IsRemoved == null || p.IsRemoved == false )) { AutoLocatedPlaysets.Add(new TargetPlayset(playset)); - logger.Error($"New playset: {playset.Name}"); } } diff --git a/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs b/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs index 52e4c734..313fed7c 100644 --- a/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs +++ b/Fronter.NET/ViewModels/TargetPlaysetPickerViewModel.cs @@ -28,4 +28,8 @@ public TargetPlaysetPickerViewModel(Config config) { public ReadOnlyObservableCollection TargetPlaysets => targetPlaysets; public bool TabDisabled { get; } = false; + + public void ReloadPlaysets() { + _config.AutoLocatePlaysets(); + } } \ No newline at end of file diff --git a/Fronter.NET/Views/TargetPlaysetPickerView.axaml b/Fronter.NET/Views/TargetPlaysetPickerView.axaml index 1e398e43..146026e3 100644 --- a/Fronter.NET/Views/TargetPlaysetPickerView.axaml +++ b/Fronter.NET/Views/TargetPlaysetPickerView.axaml @@ -38,18 +38,20 @@ - - - + + - - - - - - - + + + + + + + + +