diff --git a/VPet.ModMaker/Models/ModMakeHistory.cs b/VPet.ModMaker/Models/ModMakeHistory.cs deleted file mode 100644 index 909e988..0000000 --- a/VPet.ModMaker/Models/ModMakeHistory.cs +++ /dev/null @@ -1,20 +0,0 @@ -using LinePutScript.Converter; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VPet.ModMaker.Models; - -public class ModMakeHistory -{ - [Line(ignoreCase: true)] - public string Name { get; set; } - - [Line(ignoreCase: true)] - public string Path { get; set; } - - [Line(ignoreCase: true)] - public DateTime LastOpenTime { get; set; } -} diff --git a/VPet.ModMaker/Models/ModMakerHistory.cs b/VPet.ModMaker/Models/ModMakerHistory.cs new file mode 100644 index 0000000..3319f6f --- /dev/null +++ b/VPet.ModMaker/Models/ModMakerHistory.cs @@ -0,0 +1,38 @@ +using LinePutScript.Converter; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace VPet.ModMaker.Models; + +public class ModMakerHistory +{ + public BitmapImage Image { get; set; } + + [Line(ignoreCase: true)] + public string Name { get; set; } + + private string _path; + + [Line(ignoreCase: true)] + public string SourcePath + { + get => _path; + set + { + _path = value; + var imagePath = Path.Combine(_path, "icon.png"); + if (File.Exists(imagePath)) + Image = Utils.LoadImageToMemoryStream(imagePath); + } + } + + public string LastTimeString => LastTime.ToString("yyyy/MM/dd HH:mm:ss"); + + [Line(ignoreCase: true)] + public DateTime LastTime { get; set; } +} diff --git a/VPet.ModMaker/Models/ModMakerInfo.cs b/VPet.ModMaker/Models/ModMakerInfo.cs index 139da23..88264fd 100644 --- a/VPet.ModMaker/Models/ModMakerInfo.cs +++ b/VPet.ModMaker/Models/ModMakerInfo.cs @@ -8,7 +8,6 @@ namespace VPet.ModMaker.Models; public static class ModMakerInfo { - // TODO: 可修改的主要文化 ? - public const string MainCulture = "zh-Hans"; public const string BaseDirectory = nameof(ModMaker); + public const string HistoryFile = $"{BaseDirectory}\\history.lps"; } diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index c49c3d2..1e9c85b 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -97,7 +97,7 @@ - + diff --git a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs index 49affcb..9ff91a0 100644 --- a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs @@ -1,4 +1,6 @@ using HKW.HKWViewModels.SimpleObservable; +using LinePutScript; +using LinePutScript.Converter; using LinePutScript.Localization.WPF; using Microsoft.Win32; using System; @@ -26,6 +28,8 @@ public class ModMakerWindowVM public ObservableCollection ShowMods { get; set; } public ObservableCollection Mods { get; } = new(); + + public ObservableCollection Histories { get; } = new(); #endregion #region Command public ObservableCommand CreateNewModCommand { get; } = new(); @@ -35,7 +39,7 @@ public class ModMakerWindowVM public ModMakerWindowVM(ModMakerWindow window) { - LoadMods(); + LoadHistories(); ModMakerWindow = window; ShowMods = Mods; CreateNewModCommand.ExecuteAction = CreateNewMod; @@ -43,16 +47,49 @@ public class ModMakerWindowVM ModFilterText.ValueChanged += ModFilterText_ValueChanged; } - private void LoadMods() + private void LoadHistories() { - var dic = Directory.CreateDirectory(ModMakerInfo.BaseDirectory); - foreach (var modDic in dic.EnumerateDirectories()) + if (File.Exists(ModMakerInfo.HistoryFile) is false) + return; + var lps = new LPS(File.ReadAllText(ModMakerInfo.HistoryFile)); + foreach (var line in lps) + Histories.Add(LPSConvert.DeserializeObject(line)); + } + + private void SaveHistories() + { + if (File.Exists(ModMakerInfo.HistoryFile) is false) + File.Create(ModMakerInfo.HistoryFile).Close(); + var lps = new LPS(); + foreach (var history in Histories) + lps.Add( + new Line(nameof(history)) + { + new Sub("Name", history.Name), + new Sub("SourcePath", history.SourcePath), + new Sub("LastTime", history.LastTimeString) + } + ); + File.WriteAllText(ModMakerInfo.HistoryFile, lps.ToString()); + } + + private void AddHistories(ModInfoModel modInfo) + { + if (Histories.FirstOrDefault(h => h.Name == modInfo.Name.Value) is ModMakerHistory history) { - var mod = new ModLoader(modDic); - if (mod.SuccessLoad is false) - continue; - var modModel = new ModInfoModel(mod); - Mods.Add(modModel); + history.SourcePath = modInfo.SourcePath.Value; + history.LastTime = DateTime.Now; + } + else + { + Histories.Add( + new() + { + Name = modInfo.Name.Value, + SourcePath = modInfo.SourcePath.Value, + LastTime = DateTime.Now, + } + ); } } @@ -67,12 +104,15 @@ public class ModMakerWindowVM public void CreateNewMod() { ModInfoModel.Current ??= new(); - // I18nHelper.Current = new(); ModEditWindow = new(); ModEditWindow.Show(); ModMakerWindow.Hide(); ModEditWindow.Closed += (s, e) => { + var modInfo = ModInfoModel.Current; + if (string.IsNullOrEmpty(modInfo.SourcePath.Value) is false) + AddHistories(modInfo); + SaveHistories(); ModMakerWindow.Close(); }; } diff --git a/VPet.ModMaker/Views/ModMakerWindow.xaml b/VPet.ModMaker/Views/ModMakerWindow.xaml index 4302548..9519b42 100644 --- a/VPet.ModMaker/Views/ModMakerWindow.xaml +++ b/VPet.ModMaker/Views/ModMakerWindow.xaml @@ -32,7 +32,7 @@