Skip to content

Commit

Permalink
Pakファイルリネーム
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhiel committed Sep 6, 2022
1 parent 66df38e commit 3c45a91
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 12 deletions.
27 changes: 27 additions & 0 deletions MHRiseModManager/Models/ModListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
55 changes: 43 additions & 12 deletions MHRiseModManager/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -91,7 +88,7 @@ public MainViewModel()
{
_NowSelectModInfo = modInfo;

NowModPath.Value = modInfo.Name;
NowModPath.Value = modInfo.ArchiveFilePath;

NowModSize.Value = modInfo.FileSize;

Expand Down Expand Up @@ -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 =>
{
Expand Down Expand Up @@ -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 =>
Expand All @@ -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 =>
Expand All @@ -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 =>
{
Expand Down Expand Up @@ -955,6 +952,10 @@ 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();

Expand All @@ -965,9 +966,39 @@ public async void OnRowEdit(ModInfo modInfo)

_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);
}
}
}

0 comments on commit 3c45a91

Please sign in to comment.