diff --git a/MHRiseModManager/App.xaml b/MHRiseModManager/App.xaml index ffdb0b7..97ce66c 100644 --- a/MHRiseModManager/App.xaml +++ b/MHRiseModManager/App.xaml @@ -4,7 +4,9 @@ xmlns:local="clr-namespace:MHRiseModManager" xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls" StartupUri="Views/MainWindow.xaml" - xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"> + xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" + Startup="Application_Startup" + Exit="Application_Exit"> diff --git a/MHRiseModManager/App.xaml.cs b/MHRiseModManager/App.xaml.cs index 7a01299..971a731 100644 --- a/MHRiseModManager/App.xaml.cs +++ b/MHRiseModManager/App.xaml.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; +using System.Threading; namespace MHRiseModManager { @@ -13,5 +14,28 @@ namespace MHRiseModManager /// public partial class App : Application { + private Mutex _mutex = new Mutex(false, "MHRiseModManager"); + + private void Application_Startup(object sender, StartupEventArgs e) + { + if(_mutex.WaitOne(0, false)) + { + return; + } + + MessageBox.Show("二重起動できません", "情報", MessageBoxButton.OK, MessageBoxImage.Information); + _mutex.Close(); + _mutex = null; + Shutdown(); + } + + private void Application_Exit(object sender, ExitEventArgs e) + { + if(_mutex != null) + { + _mutex.ReleaseMutex(); + _mutex.Close(); + } + } } } diff --git a/MHRiseModManager/Models/Category.cs b/MHRiseModManager/Models/Category.cs index f63edfa..d0b7b95 100644 --- a/MHRiseModManager/Models/Category.cs +++ b/MHRiseModManager/Models/Category.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace MHRiseModManager.Models { public enum Category : int { REFramework = 0, Lua = 1, - その他 = 2 + Pak = 2, + その他 = 3 } } diff --git a/MHRiseModManager/Models/ModInfo.cs b/MHRiseModManager/Models/ModInfo.cs index f7ea8c1..1cca937 100644 --- a/MHRiseModManager/Models/ModInfo.cs +++ b/MHRiseModManager/Models/ModInfo.cs @@ -127,6 +127,11 @@ public string ExtractArchivePath File.WriteAllBytes(archiveFile, ModFileBinary); } + if(archiveFile.EndsWith("pak")) + { + return archiveFile; + } + var targetDir = Path.Combine(Path.GetDirectoryName(archiveFile), Path.GetFileNameWithoutExtension(archiveFile)); if (!Directory.Exists(targetDir)) @@ -154,6 +159,11 @@ public Category GetNewCategory() category = Category.REFramework; break; } + if (item.Name.EndsWith("pak")) + { + category = Category.Pak; + break; + } } return category; @@ -240,7 +250,20 @@ private IEnumerable GetElements(ModFileTree node) private List Search(string path) { - var chiled = new List(); + var child = new List(); + + if(path.EndsWith("pak")) + { + FileInfo f = new FileInfo(path); + ModFileTree tree = new ModFileTree(); + tree.Name = f.Name; + tree.Path = f.Name; + tree.IsFile = true; + child.Add(tree); + return child; + } + + var di = new DirectoryInfo(path); foreach (var f in di.GetFiles()) { @@ -248,7 +271,7 @@ private List Search(string path) tree.Name = f.Name; tree.Path = f.FullName.Substring(ExtractArchivePath.Length + 1); tree.IsFile = true; - chiled.Add(tree); + child.Add(tree); } foreach (var d in di.GetDirectories()) @@ -258,10 +281,10 @@ private List Search(string path) tree.Path = d.FullName.Substring(ExtractArchivePath.Length + 1); tree.Child = Search(d.FullName); tree.IsFile = false; - chiled.Add(tree); + child.Add(tree); } - return chiled; + return child; } diff --git a/MHRiseModManager/Models/ModListManager.cs b/MHRiseModManager/Models/ModListManager.cs index 9765636..cf8eae9 100644 --- a/MHRiseModManager/Models/ModListManager.cs +++ b/MHRiseModManager/Models/ModListManager.cs @@ -241,5 +241,32 @@ public ModInfo UpdateLatestVersion(int id, string latestversion) return SelectAll().Where(x => x.Id == id).First(); } + public void UpdateArchivePath(int id, string archivefilepath) + { + // コネクションを開いてテーブル作成して閉じる + using (var con = new SQLiteConnection($"Data Source={Settings.Default.DataBaseFileName}")) + { + con.Open(); + string sql = $"update modinfo set archivefilepath = '{archivefilepath}' where id = {id}"; + var com = new SQLiteCommand(sql, con); + com.ExecuteNonQuery(); + + con.Close(); + } + + } + + public void UpdateDetailPath(int id, string path) + { + using (var con = new SQLiteConnection($"Data Source={Settings.Default.DataBaseFileName}")) + { + con.Open(); + string sql = $"update modinfodetail set path = '{path}' where id = {id}"; + var com = new SQLiteCommand(sql, con); + com.ExecuteNonQuery(); + + con.Close(); + } + } } } diff --git a/MHRiseModManager/ViewModels/InstallDialogViewModel.cs b/MHRiseModManager/ViewModels/InstallDialogViewModel.cs index 1b0994b..25e6312 100644 --- a/MHRiseModManager/ViewModels/InstallDialogViewModel.cs +++ b/MHRiseModManager/ViewModels/InstallDialogViewModel.cs @@ -10,13 +10,27 @@ namespace MHRiseModManager.ViewModels public class InstallDialogViewModel { public ReactiveCommand CloseWindow { get; } = new ReactiveCommand(); + public ReactiveCommand CloseWindowCancel { get; } = new ReactiveCommand(); public ReactiveProperty Name { get; } = new ReactiveProperty(); public ReactiveProperty URL { get; } = new ReactiveProperty(); public ReactiveProperty Version { get; } = new ReactiveProperty(); public ReactiveProperty Memo { get; } = new ReactiveProperty(); + public ReactiveProperty PakMode { get; } = new ReactiveProperty(false); + public ReactiveProperty PakFileName { get; } = new ReactiveProperty(); + public bool Result { get; set; } + public InstallDialogViewModel() { - CloseWindow.Subscribe(x => ((System.Windows.Window)x).Close()); + CloseWindow.Subscribe(x => + { + Result = true; + ((System.Windows.Window)x).Close(); + }); + CloseWindowCancel.Subscribe(x => + { + Result = false; + ((System.Windows.Window)x).Close(); + }); } } } diff --git a/MHRiseModManager/ViewModels/MainViewModel.cs b/MHRiseModManager/ViewModels/MainViewModel.cs index 35a8718..8166d57 100644 --- a/MHRiseModManager/ViewModels/MainViewModel.cs +++ b/MHRiseModManager/ViewModels/MainViewModel.cs @@ -19,11 +19,8 @@ using System.Globalization; using System.Text; using CsvHelper.Configuration; -using System.Net; -using System.Text.RegularExpressions; using System.Net.Http; using ControlzEx.Theming; -using System.Threading; namespace MHRiseModManager.ViewModels { @@ -91,7 +88,7 @@ public MainViewModel() { _NowSelectModInfo = modInfo; - NowModPath.Value = modInfo.Name; + NowModPath.Value = modInfo.ArchiveFilePath; NowModSize.Value = modInfo.FileSize; @@ -270,9 +267,9 @@ await Task.Run(() => Delete(_NowSelectModInfo); - await MahAppsDialogCoordinator.ShowMessageAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modの登録を削除しました。"); - ModFileListReflesh(); + + await MahAppsDialogCoordinator.ShowMessageAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modの登録を削除しました。"); }); CSVTemplateOutPutCommand.Subscribe(e => { @@ -377,11 +374,11 @@ await Task.Run(() => } }); + ModFileListReflesh(); + await controller.CloseAsync(); await MahAppsDialogCoordinator.ShowMessageAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modの登録を削除しました。"); - - ModFileListReflesh(); }); AllInstallCommand.Subscribe(async e => @@ -404,11 +401,11 @@ await Task.Run(() => } }); + ModFileListReflesh(); + await controller.CloseAsync(); await MahAppsDialogCoordinator.ShowMessageAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modを一括インストールしました。"); - - ModFileListReflesh(); }); AllUnInstallCommand.Subscribe(async e => @@ -431,11 +428,11 @@ await Task.Run(() => } }); + ModFileListReflesh(); + await controller.CloseAsync(); await MahAppsDialogCoordinator.ShowMessageAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modを一括アンインストールしました。"); - - ModFileListReflesh(); }); ShownCommand.Subscribe(async e => { @@ -643,19 +640,28 @@ private async void OnFileDrop(DragEventArgs e) return; } + var dropFile = dropFiles[0]; + var dialog = new InstallDialog(); - dialog.ShowDialog(); + var returnModel = dialog.DataContext as InstallDialogViewModel; - var controller = await MahAppsDialogCoordinator.ShowProgressAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modの新規登録中..."); + returnModel.PakMode.Value = dropFile.EndsWith("pak"); - var returnModel = dialog.DataContext as InstallDialogViewModel; + returnModel.PakFileName.Value = Path.GetFileName(dropFile); - var dropFile = dropFiles[0]; + dialog.ShowDialog(); + + if(!returnModel.Result) + { + return; + } + + var controller = await MahAppsDialogCoordinator.ShowProgressAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modの新規登録中..."); var modName = string.IsNullOrEmpty(returnModel.Name.Value) ? null : returnModel.Name.Value; - await ModRegist(modName: modName, url: returnModel.URL.Value, memo: returnModel.Memo.Value, version: returnModel.Version.Value, dropFile: dropFile); + await ModRegist(modName: modName, url: returnModel.URL.Value, memo: returnModel.Memo.Value, version: returnModel.Version.Value, dropFile: dropFile, pakFileName:returnModel.PakFileName.Value); Utility.CleanDirectory(Path.Combine(Path.GetTempPath(), Settings.Default.TempDirectoryName)); @@ -689,9 +695,9 @@ private void ModRegistSync(string modName, string url, string memo, string versi _ModListManager.Insert(name: targetFileName, targetFile: targetFile, url: url, memo: memo, modName: modName, version: version); } - private async Task ModRegist(string modName, string url, string memo, string version, string dropFile) + private async Task ModRegist(string modName, string url, string memo, string version, string dropFile, string pakFileName = null) { - dropFile = PreProcess(dropFile); + dropFile = PreProcess(dropFile, pakFileName); if (dropFile == null) { @@ -710,10 +716,20 @@ private async Task ModRegist(string modName, string url, string memo, string ver _ModListManager.Insert(name: targetFileName, targetFile: targetFile, url: url, memo: memo, modName: modName, version: version); } - private string PreProcess(string dropFile) + private string PreProcess(string dropFile, string pakFileName = null) { var resultFile = dropFile; + // pakファイル対応 + if (!string.IsNullOrEmpty(pakFileName)) + { + var dir = Path.GetDirectoryName(dropFile); + resultFile = Path.Combine(dir, pakFileName); + File.Move(dropFile, resultFile); + + return resultFile; + } + var tempDir = Utility.GetOrCreateDirectory(Path.Combine(Path.GetTempPath(), Settings.Default.TempDirectoryName)); var targetFile = Path.Combine(tempDir, Path.GetFileName(dropFile)); @@ -802,7 +818,7 @@ private void Install(ModInfo modInfo) var targetDir = Utility.GetOrCreateDirectory(Path.Combine(Settings.Default.GameDirectoryPath, dir)); - var srcFile = Path.Combine(modInfo.ExtractArchivePath, itemPath); + var srcFile = modInfo.Category == Category.Pak ? modInfo.ExtractArchivePath : Path.Combine(modInfo.ExtractArchivePath, itemPath); var targetFile = string.Empty; @@ -880,6 +896,11 @@ public async void OnRowUpdate(ModInfo modInfo) dialog.ShowDialog(); + if (!returnModel.Result) + { + return; + } + // アンインストール Uninstall(modInfo); @@ -931,14 +952,53 @@ public async void OnRowEdit(ModInfo modInfo) returnModel.Name.Value = modInfo.ModName; returnModel.Memo.Value = modInfo.Memo; returnModel.Version.Value = modInfo.Version; + returnModel.PakMode.Value = modInfo.Category == Category.Pak; + returnModel.PakFileName.Value = Path.GetFileName(modInfo.ArchiveFilePath); + + var oldFilePakName = Path.GetFileName(modInfo.ArchiveFilePath); dialog.ShowDialog(); + if (!returnModel.Result) + { + return; + } + _ModListManager.Update(id: modInfo.Id, name: returnModel.Name.Value, url: returnModel.URL.Value, memo: returnModel.Memo.Value, version: returnModel.Version.Value); + if(modInfo.Category == Category.Pak && !oldFilePakName.Equals(returnModel.PakFileName.Value)) + { + RenamePakFile(modInfo, returnModel.PakFileName.Value); + } + ModFileListReflesh(); await MahAppsDialogCoordinator.ShowMessageAsync(this, Assembly.GetEntryAssembly().GetName().Name, "Modを更新しました。"); } + + private void RenamePakFile(ModInfo modInfo, string newFileName) + { + var oldArchiveFilePath = modInfo.ArchiveFilePath; + + var detail = _ModListManager.SelectModFile(modInfo.Id).First(); + + var oldFileName = detail.Path; + + var gameDir = GameDirectoryPath.Value; + + var newArchiveFilePath = Path.Combine(Path.GetDirectoryName(oldArchiveFilePath), newFileName); + + var newArchiveFullPath = Path.Combine(Environment.CurrentDirectory, newArchiveFilePath); + + var oldArchiveFullPath = Path.Combine(Environment.CurrentDirectory, oldArchiveFilePath); + + File.Move(Path.Combine(gameDir, oldFileName), Path.Combine(gameDir, newFileName)); + + File.Move(oldArchiveFullPath, newArchiveFullPath); + + _ModListManager.UpdateDetailPath(detail.Id, newFileName); + + _ModListManager.UpdateArchivePath(modInfo.Id, newArchiveFilePath); + } } } diff --git a/MHRiseModManager/Views/InstallDialog.xaml b/MHRiseModManager/Views/InstallDialog.xaml index 7304cc5..a6dfb4f 100644 --- a/MHRiseModManager/Views/InstallDialog.xaml +++ b/MHRiseModManager/Views/InstallDialog.xaml @@ -15,6 +15,9 @@ + + + @@ -30,6 +33,7 @@ + @@ -38,11 +42,14 @@ - - + + + + - +