From f0e0fb8219a5af37cd7139002d6ce802d5db13ae Mon Sep 17 00:00:00 2001 From: FernandoRApud Date: Sat, 15 Jun 2024 01:10:27 -0300 Subject: [PATCH] Fixing Not Available Steam Files for Mod Manager --- .../Services/ConfigurationService.cs | 30 + .../ViewModels/MainViewModel.cs | 1919 +++++++++-------- .../ViewModels/SetupWizardViewModel.cs | 274 ++- .../Views/SetupWizardWindow.xaml | 38 + .../Views/SetupWizardWindow.xaml.cs | 3 + 5 files changed, 1285 insertions(+), 979 deletions(-) diff --git a/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs b/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs index 5ab5c2d09..2a67b552e 100644 --- a/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs +++ b/OpenKh.Tools.ModsManager/Services/ConfigurationService.cs @@ -35,7 +35,10 @@ private class Config public string Pcsx2Location { get; internal set; } public string PcReleaseLocation { get; internal set; } public string PcReleaseLocationKH3D { get; internal set; } + public string PcReleaseSteamLocation { get; internal set; } + public string PcReleaseSteamLocationKH3D { get; internal set; } public string PcReleaseLanguage { get; internal set; } = "en"; + public string PcReleaseLanguageDT { get; internal set; } = "dt"; public int RegionId { get; internal set; } public bool PanaceaInstalled { get; internal set; } public bool ShowConsole { get; internal set; } = false; @@ -267,6 +270,24 @@ public static string PcReleaseLocationKH3D _config.Save(ConfigPath); } } + public static string PcReleaseSteamLocation + { + get => _config.PcReleaseSteamLocation; + set + { + _config.PcReleaseSteamLocation = value; + _config.Save(ConfigPath); + } + } + public static string PcReleaseSteamLocationKH3D + { + get => _config.PcReleaseSteamLocationKH3D; + set + { + _config.PcReleaseSteamLocationKH3D = value; + _config.Save(ConfigPath); + } + } public static string PcReleaseLanguage { @@ -277,6 +298,15 @@ public static string PcReleaseLanguage _config.Save(ConfigPath); } } + public static string PcReleaseLanguageDT + { + get => _config.PcReleaseLanguageDT; + set + { + _config.PcReleaseLanguageDT = value; + _config.Save(ConfigPath); + } + } public static int RegionId { diff --git a/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs b/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs index 563f1fd17..a46a9bf86 100644 --- a/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs +++ b/OpenKh.Tools.ModsManager/ViewModels/MainViewModel.cs @@ -1,180 +1,183 @@ -using OpenKh.Common; -using OpenKh.Tools.Common.Wpf; -using OpenKh.Tools.ModsManager.Models; -using OpenKh.Tools.ModsManager.Services; -using OpenKh.Tools.ModsManager.Views; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using System.Windows; -using Xe.Tools; -using Xe.Tools.Wpf.Commands; -using static OpenKh.Tools.ModsManager.Helpers; - -namespace OpenKh.Tools.ModsManager.ViewModels -{ - public interface IChangeModEnableState - { - void ModEnableStateChanged(); - } - - public class MainViewModel : BaseNotifyPropertyChanged, IChangeModEnableState +using OpenKh.Common; +using OpenKh.Tools.Common.Wpf; +using OpenKh.Tools.ModsManager.Models; +using OpenKh.Tools.ModsManager.Services; +using OpenKh.Tools.ModsManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using System.Windows; +using Xe.Tools; +using Xe.Tools.Wpf.Commands; +using static OpenKh.Tools.ModsManager.Helpers; + +namespace OpenKh.Tools.ModsManager.ViewModels +{ + public interface IChangeModEnableState + { + void ModEnableStateChanged(); + } + + public class MainViewModel : BaseNotifyPropertyChanged, IChangeModEnableState { - public ColorThemeService ColorTheme => ColorThemeService.Instance; - private static Version _version = Assembly.GetEntryAssembly()?.GetName()?.Version; - private static string ApplicationName = Utilities.GetApplicationName(); - private static string ApplicationVersion = Utilities.GetApplicationVersion(); + public ColorThemeService ColorTheme => ColorThemeService.Instance; + private static Version _version = Assembly.GetEntryAssembly()?.GetName()?.Version; + private static string ApplicationName = Utilities.GetApplicationName(); + private static string ApplicationVersion = Utilities.GetApplicationVersion(); private Window Window => Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); private GetActiveWindowService _getActiveWindowService = new GetActiveWindowService(); - - private DebuggingWindow _debuggingWindow = new DebuggingWindow(); - private ModViewModel _selectedValue; - private Pcsx2Injector _pcsx2Injector; - private Process _runningProcess; - private bool _isBuilding; - private bool _pc; - private bool _panaceaInstalled; - private bool _panaceaConsoleEnabled; - private bool _panaceaDebugLogEnabled; - private bool _panaceaCacheEnabled; - private bool _panaceaQuickMenuEnabled; - private bool _devView; - private bool _autoUpdateMods = false; + + private DebuggingWindow _debuggingWindow = new DebuggingWindow(); + private ModViewModel _selectedValue; + private Pcsx2Injector _pcsx2Injector; + private Process _runningProcess; + private bool _isBuilding; + private bool _pc; + private bool _panaceaInstalled; + private bool _panaceaConsoleEnabled; + private bool _panaceaDebugLogEnabled; + private bool _panaceaCacheEnabled; + private bool _panaceaQuickMenuEnabled; + private bool _devView; + private bool _autoUpdateMods = false; private string _launchGame = "kh2"; - private List _supportedGames = new List() - { - "kh2", - "kh1", - "bbs", - "Recom", - "kh3d" - }; - private int _wizardVersionNumber = 1; - private string[] executable = new string[] - { - "KINGDOM HEARTS II FINAL MIX.exe", - "KINGDOM HEARTS FINAL MIX.exe", - "KINGDOM HEARTS Birth by Sleep FINAL MIX.exe", - "KINGDOM HEARTS Re_Chain of Memories.exe", - "KINGDOM HEARTS Dream Drop Distance.exe" - }; - private int launchExecutable = 0; - - private const string RAW_FILES_FOLDER_NAME = "raw"; - private const string ORIGINAL_FILES_FOLDER_NAME = "original"; + private List _supportedGames = new List() + { + "kh2", + "kh1", + "bbs", + "Recom", + "kh3d" + }; + private int _wizardVersionNumber = 1; + private string[] executable = new string[] + { + "KINGDOM HEARTS II FINAL MIX.exe", + "KINGDOM HEARTS FINAL MIX.exe", + "KINGDOM HEARTS Birth by Sleep FINAL MIX.exe", + "KINGDOM HEARTS Re_Chain of Memories.exe", + "KINGDOM HEARTS Dream Drop Distance.exe" + }; + private int launchExecutable = 0; + + private const string RAW_FILES_FOLDER_NAME = "raw"; + private const string ORIGINAL_FILES_FOLDER_NAME = "original"; private const string REMASTERED_FILES_FOLDER_NAME = "remastered"; - public static bool overwriteMod = false; - public string Title => ApplicationName; + const int EpicGamesPC = 2; + const int Steam = 3; + + public static bool overwriteMod = false; + public string Title => ApplicationName; public string CurrentVersion => ApplicationVersion; public ObservableCollection ModsList { get; set; } - public ObservableCollection PresetList { get; set; } - public RelayCommand ExitCommand { get; set; } - public RelayCommand AddModCommand { get; set; } - public RelayCommand RemoveModCommand { get; set; } - public RelayCommand OpenModFolderCommand { get; set; } - public RelayCommand MoveTop { get; set; } - public RelayCommand MoveUp { get; set; } - public RelayCommand MoveDown { get; set; } - public RelayCommand BuildCommand { get; set; } - public RelayCommand PatchCommand { get; set; } - public RelayCommand RestoreCommand { get; set; } - public RelayCommand RunCommand { get; set; } - public RelayCommand BuildAndRunCommand { get; set; } - public RelayCommand StopRunningInstanceCommand { get; set; } - public RelayCommand WizardCommand { get; set; } - public RelayCommand OpenLinkCommand { get; set; } + public ObservableCollection PresetList { get; set; } + public RelayCommand ExitCommand { get; set; } + public RelayCommand AddModCommand { get; set; } + public RelayCommand RemoveModCommand { get; set; } + public RelayCommand OpenModFolderCommand { get; set; } + public RelayCommand MoveTop { get; set; } + public RelayCommand MoveUp { get; set; } + public RelayCommand MoveDown { get; set; } + public RelayCommand BuildCommand { get; set; } + public RelayCommand PatchCommand { get; set; } + public RelayCommand RestoreCommand { get; set; } + public RelayCommand RunCommand { get; set; } + public RelayCommand BuildAndRunCommand { get; set; } + public RelayCommand StopRunningInstanceCommand { get; set; } + public RelayCommand WizardCommand { get; set; } + public RelayCommand OpenLinkCommand { get; set; } public RelayCommand CheckOpenkhUpdateCommand { get; set; } public RelayCommand OpenPresetMenuCommand { get; set; } - public RelayCommand CheckForModUpdatesCommand { get; set; } - public RelayCommand YamlGeneratorCommand { get; set; } - - public ModViewModel SelectedValue - { - get => _selectedValue; - set - { - _selectedValue = value; - OnPropertyChanged(); - OnPropertyChanged(nameof(IsModSelected)); - OnPropertyChanged(nameof(IsModInfoVisible)); - OnPropertyChanged(nameof(IsModUnselectedMessageVisible)); - OnPropertyChanged(nameof(MoveUp)); - OnPropertyChanged(nameof(MoveDown)); - OnPropertyChanged(nameof(AddModCommand)); - OnPropertyChanged(nameof(RemoveModCommand)); - OnPropertyChanged(nameof(OpenModFolderCommand)); - } - } - - public bool IsModSelected => SelectedValue != null; - - public Visibility IsModInfoVisible => IsModSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility IsModUnselectedMessageVisible => !IsModSelected ? Visibility.Visible : Visibility.Collapsed; - public Visibility PatchVisible => PC && !PanaceaInstalled || PC && DevView ? Visibility.Visible : Visibility.Collapsed; - public Visibility ModLoader => !PC || PanaceaInstalled ? Visibility.Visible : Visibility.Collapsed; - public Visibility notPC => !PC ? Visibility.Visible : Visibility.Collapsed; - public Visibility isPC => PC ? Visibility.Visible : Visibility.Collapsed; - public Visibility PanaceaSettings => PC && PanaceaInstalled ? Visibility.Visible : Visibility.Collapsed; - - public bool PanaceaConsoleEnabled - { - get => _panaceaConsoleEnabled; - set + public RelayCommand CheckForModUpdatesCommand { get; set; } + public RelayCommand YamlGeneratorCommand { get; set; } + + public ModViewModel SelectedValue + { + get => _selectedValue; + set + { + _selectedValue = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsModSelected)); + OnPropertyChanged(nameof(IsModInfoVisible)); + OnPropertyChanged(nameof(IsModUnselectedMessageVisible)); + OnPropertyChanged(nameof(MoveUp)); + OnPropertyChanged(nameof(MoveDown)); + OnPropertyChanged(nameof(AddModCommand)); + OnPropertyChanged(nameof(RemoveModCommand)); + OnPropertyChanged(nameof(OpenModFolderCommand)); + } + } + + public bool IsModSelected => SelectedValue != null; + + public Visibility IsModInfoVisible => IsModSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility IsModUnselectedMessageVisible => !IsModSelected ? Visibility.Visible : Visibility.Collapsed; + public Visibility PatchVisible => PC && !PanaceaInstalled || PC && DevView ? Visibility.Visible : Visibility.Collapsed; + public Visibility ModLoader => !PC || PanaceaInstalled ? Visibility.Visible : Visibility.Collapsed; + public Visibility notPC => !PC ? Visibility.Visible : Visibility.Collapsed; + public Visibility isPC => PC ? Visibility.Visible : Visibility.Collapsed; + public Visibility PanaceaSettings => PC && PanaceaInstalled ? Visibility.Visible : Visibility.Collapsed; + + public bool PanaceaConsoleEnabled + { + get => _panaceaConsoleEnabled; + set { - _panaceaConsoleEnabled = value; - ConfigurationService.ShowConsole = _panaceaConsoleEnabled; + _panaceaConsoleEnabled = value; + ConfigurationService.ShowConsole = _panaceaConsoleEnabled; if (_panaceaDebugLogEnabled) - PanaceaDebugLogEnabled = false; - OnPropertyChanged(nameof(PanaceaConsoleEnabled)); - UpdatePanaceaSettings(); - } + PanaceaDebugLogEnabled = false; + OnPropertyChanged(nameof(PanaceaConsoleEnabled)); + UpdatePanaceaSettings(); + } } - public bool PanaceaDebugLogEnabled - { - get => _panaceaDebugLogEnabled; - set + public bool PanaceaDebugLogEnabled + { + get => _panaceaDebugLogEnabled; + set + { + _panaceaDebugLogEnabled = value; + ConfigurationService.DebugLog = _panaceaDebugLogEnabled; + OnPropertyChanged(nameof(PanaceaDebugLogEnabled)); + UpdatePanaceaSettings(); + } + } + public bool PanaceaCacheEnabled + { + get => _panaceaCacheEnabled; + set { - _panaceaDebugLogEnabled = value; - ConfigurationService.DebugLog = _panaceaDebugLogEnabled; - OnPropertyChanged(nameof(PanaceaDebugLogEnabled)); - UpdatePanaceaSettings(); - } + _panaceaCacheEnabled = value; + ConfigurationService.EnableCache = _panaceaCacheEnabled; + UpdatePanaceaSettings(); + } } - public bool PanaceaCacheEnabled - { - get => _panaceaCacheEnabled; - set + public bool PanaceaQuickMenuEnabled + { + get => _panaceaQuickMenuEnabled; + set { - _panaceaCacheEnabled = value; - ConfigurationService.EnableCache = _panaceaCacheEnabled; - UpdatePanaceaSettings(); - } + _panaceaQuickMenuEnabled = value; + ConfigurationService.QuickMenu = _panaceaQuickMenuEnabled; + UpdatePanaceaSettings(); + } } - public bool PanaceaQuickMenuEnabled - { - get => _panaceaQuickMenuEnabled; - set + public bool DevView + { + get => _devView; + set { - _panaceaQuickMenuEnabled = value; - ConfigurationService.QuickMenu = _panaceaQuickMenuEnabled; - UpdatePanaceaSettings(); - } - } - public bool DevView - { - get => _devView; - set - { - _devView = value; - ConfigurationService.DevView = DevView; - OnPropertyChanged(nameof(PatchVisible)); - } + _devView = value; + ConfigurationService.DevView = DevView; + OnPropertyChanged(nameof(PatchVisible)); + } } public bool AutoUpdateMods { @@ -184,149 +187,149 @@ public bool AutoUpdateMods _autoUpdateMods = value; ConfigurationService.AutoUpdateMods = _autoUpdateMods; } - } - public bool PanaceaInstalled - { - get => _panaceaInstalled; - set - { - _panaceaInstalled = value; - OnPropertyChanged(nameof(PatchVisible)); + } + public bool PanaceaInstalled + { + get => _panaceaInstalled; + set + { + _panaceaInstalled = value; + OnPropertyChanged(nameof(PatchVisible)); + OnPropertyChanged(nameof(ModLoader)); + OnPropertyChanged(nameof(PanaceaSettings)); + } + } + + public bool PC + { + get => _pc; + set + { + _pc = value; + OnPropertyChanged(nameof(PC)); OnPropertyChanged(nameof(ModLoader)); - OnPropertyChanged(nameof(PanaceaSettings)); - } - } - - public bool PC - { - get => _pc; - set - { - _pc = value; - OnPropertyChanged(nameof(PC)); - OnPropertyChanged(nameof(ModLoader)); - OnPropertyChanged(nameof(PatchVisible)); - OnPropertyChanged(nameof(notPC)); + OnPropertyChanged(nameof(PatchVisible)); + OnPropertyChanged(nameof(notPC)); OnPropertyChanged(nameof(isPC)); - OnPropertyChanged(nameof(PanaceaSettings)); - } + OnPropertyChanged(nameof(PanaceaSettings)); + } + } + + public int GametoLaunch + { + get + { + switch (_launchGame) + { + case "kh2": + launchExecutable = 0; + return 0; + case "kh1": + launchExecutable = 1; + return 1; + case "bbs": + launchExecutable = 2; + return 2; + case "Recom": + launchExecutable = 3; + return 3; + case "kh3d": + launchExecutable = 4; + return 4; + default: + launchExecutable = 0; + return 0; + } + } + set + { + launchExecutable = value; + switch (value) + { + case 0: + _launchGame = "kh2"; + ConfigurationService.LaunchGame = "kh2"; + break; + case 1: + _launchGame = "kh1"; + ConfigurationService.LaunchGame = "kh1"; + break; + case 2: + _launchGame = "bbs"; + ConfigurationService.LaunchGame = "bbs"; + break; + case 3: + _launchGame = "Recom"; + ConfigurationService.LaunchGame = "Recom"; + break; + case 4: + _launchGame = "kh3d"; + ConfigurationService.LaunchGame = "kh3d"; + break; + default: + _launchGame = "kh2"; + ConfigurationService.LaunchGame = "kh2"; + break; + } + ReloadModsList(); + if (ModsList.Count > 0) + FetchUpdates(); + } } - public int GametoLaunch - { - get - { - switch (_launchGame) - { - case "kh2": - launchExecutable = 0; - return 0; - case "kh1": - launchExecutable = 1; - return 1; - case "bbs": - launchExecutable = 2; - return 2; - case "Recom": - launchExecutable = 3; - return 3; - case "kh3d": - launchExecutable = 4; - return 4; - default: - launchExecutable = 0; - return 0; - } - } - set - { - launchExecutable = value; - switch (value) - { - case 0: - _launchGame = "kh2"; - ConfigurationService.LaunchGame = "kh2"; - break; - case 1: - _launchGame = "kh1"; - ConfigurationService.LaunchGame = "kh1"; - break; - case 2: - _launchGame = "bbs"; - ConfigurationService.LaunchGame = "bbs"; - break; - case 3: - _launchGame = "Recom"; - ConfigurationService.LaunchGame = "Recom"; - break; - case 4: - _launchGame = "kh3d"; - ConfigurationService.LaunchGame = "kh3d"; - break; - default: - _launchGame = "kh2"; - ConfigurationService.LaunchGame = "kh2"; - break; - } - ReloadModsList(); - if (ModsList.Count > 0) - FetchUpdates(); - } - } - - public bool IsBuilding - { - get => _isBuilding; - set - { - _isBuilding = value; + public bool IsBuilding + { + get => _isBuilding; + set + { + _isBuilding = value; Application.Current.Dispatcher.Invoke(() => - { - OnPropertyChanged(nameof(BuildCommand)); - OnPropertyChanged(nameof(BuildAndRunCommand)); - }); - } - } - - public bool IsRunning => _runningProcess != null; - - public MainViewModel() - { - if (ConfigurationService.GameEdition == 2) - { - PC = true; - PanaceaInstalled = ConfigurationService.PanaceaInstalled; - DevView = ConfigurationService.DevView; - _panaceaConsoleEnabled = ConfigurationService.ShowConsole; - _panaceaDebugLogEnabled = ConfigurationService.DebugLog; - _panaceaCacheEnabled = ConfigurationService.EnableCache; - _panaceaQuickMenuEnabled = ConfigurationService.QuickMenu; - } - else - PC = false; - if (_supportedGames.Contains(ConfigurationService.LaunchGame) && PC) - _launchGame = ConfigurationService.LaunchGame; - else + { + OnPropertyChanged(nameof(BuildCommand)); + OnPropertyChanged(nameof(BuildAndRunCommand)); + }); + } + } + + public bool IsRunning => _runningProcess != null; + + public MainViewModel() + { + if (ConfigurationService.GameEdition == EpicGamesPC || ConfigurationService.GameEdition == Steam) + { + PC = true; + PanaceaInstalled = ConfigurationService.PanaceaInstalled; + DevView = ConfigurationService.DevView; + _panaceaConsoleEnabled = ConfigurationService.ShowConsole; + _panaceaDebugLogEnabled = ConfigurationService.DebugLog; + _panaceaCacheEnabled = ConfigurationService.EnableCache; + _panaceaQuickMenuEnabled = ConfigurationService.QuickMenu; + } + else + PC = false; + if (_supportedGames.Contains(ConfigurationService.LaunchGame) && PC) + _launchGame = ConfigurationService.LaunchGame; + else ConfigurationService.LaunchGame = _launchGame; - AutoUpdateMods = ConfigurationService.AutoUpdateMods; - - Log.OnLogDispatch += (long ms, string tag, string message) => - _debuggingWindow.Log(ms, tag, message); - - ReloadModsList(); + AutoUpdateMods = ConfigurationService.AutoUpdateMods; + + Log.OnLogDispatch += (long ms, string tag, string message) => + _debuggingWindow.Log(ms, tag, message); + + ReloadModsList(); SelectedValue = ModsList.FirstOrDefault(); - ReloadPresetList(); - - ExitCommand = new RelayCommand(_ => Window.Close()); - AddModCommand = new RelayCommand(_ => - { - var view = new InstallModView(); - if (view.ShowDialog() != true) - return; - - Task.Run(async () => - { + ReloadPresetList(); + + ExitCommand = new RelayCommand(_ => Window.Close()); + AddModCommand = new RelayCommand(_ => + { + var view = new InstallModView(); + if (view.ShowDialog() != true) + return; + + Task.Run(async () => + { InstallModProgressWindow progressWindow = null; try { @@ -364,152 +367,168 @@ await ModsService.InstallMod(name, isZipFile, isLuaFile, progress => overwriteMod = false; } ModsList.Insert(0, Map(mod)); - SelectedValue = ModsList[0]; - }); - } - catch (Exception ex) - { - Log.Warn("Unable to install the mod `{0}`: {1}\n" - , view.RepositoryName - , Log.FormatSecondaryLinesWithIndent(ex.ToString(), " ") - ); + SelectedValue = ModsList[0]; + }); + } + catch (Exception ex) + { + Log.Warn("Unable to install the mod `{0}`: {1}\n" + , view.RepositoryName + , Log.FormatSecondaryLinesWithIndent(ex.ToString(), " ") + ); Handle(ex); - } - finally - { + } + finally + { Application.Current.Dispatcher.Invoke(() => progressWindow?.Close()); - } - }); - }, _ => true); - RemoveModCommand = new RelayCommand(_ => - { - var mod = SelectedValue; - if (Question($"Do you want to delete the mod '{mod.Source}'?", $"Remove mod {mod.Source}")) - { - Handle(() => - { - foreach (var filePath in Directory.GetFiles(mod.Path, "*", SearchOption.AllDirectories)) - { - var attributes = File.GetAttributes(filePath); - if (attributes.HasFlag(FileAttributes.ReadOnly)) - File.SetAttributes(filePath, attributes & ~FileAttributes.ReadOnly); - } - - Directory.Delete(mod.Path, true); - ModsList.RemoveAt(ModsList.IndexOf(SelectedValue)); - }); - } - }, _ => IsModSelected); - OpenModFolderCommand = new RelayCommand(_ => - { - using var process = Process.Start(new ProcessStartInfo - { - FileName = SelectedValue.Path, - UseShellExecute = true - }); - }, _ => IsModSelected); - MoveTop = new RelayCommand(_ => MoveSelectedModTop(), _ => CanSelectedModMoveUp()); - MoveUp = new RelayCommand(_ => MoveSelectedModUp(), _ => CanSelectedModMoveUp()); - MoveDown = new RelayCommand(_ => MoveSelectedModDown(), _ => CanSelectedModMoveDown()); - BuildCommand = new RelayCommand(async _ => - { - ResetLogWindow(); - await BuildPatches(false); - CloseAllWindows(); - }, _ => !IsBuilding); - - PatchCommand = new RelayCommand(async (fastMode) => - { - ResetLogWindow(); - await BuildPatches(Convert.ToBoolean(fastMode)); - await PatchGame(Convert.ToBoolean(fastMode)); - CloseAllWindows(); - }, _ => !IsBuilding); - - RunCommand = new RelayCommand(async _ => - { - CloseRunningProcess(); - ResetLogWindow(); - await RunGame(); - }); - - RestoreCommand = new RelayCommand(async (patched) => - { - ResetLogWindow(); - await RestoreGame(Convert.ToBoolean(patched)); - CloseAllWindows(); - }); - BuildAndRunCommand = new RelayCommand(async _ => - { - CloseRunningProcess(); - ResetLogWindow(); - if (await BuildPatches(false)) - await RunGame(); - }, _ => !IsBuilding); - StopRunningInstanceCommand = new RelayCommand(_ => - { - CloseRunningProcess(); - ResetLogWindow(); - }, _ => IsRunning); - WizardCommand = new RelayCommand(_ => - { - var dialog = new SetupWizardWindow() - { - ConfigGameEdition = ConfigurationService.GameEdition, - ConfigGameDataLocation = ConfigurationService.GameDataLocation, - ConfigIsoLocation = ConfigurationService.IsoLocation, - ConfigOpenKhGameEngineLocation = ConfigurationService.OpenKhGameEngineLocation, - ConfigPcsx2Location = ConfigurationService.Pcsx2Location, - ConfigPcReleaseLocation = ConfigurationService.PcReleaseLocation, - ConfigPcReleaseLocationKH3D = ConfigurationService.PcReleaseLocationKH3D, - ConfigPcReleaseLanguage = ConfigurationService.PcReleaseLanguage, - ConfigRegionId = ConfigurationService.RegionId, - ConfigPanaceaInstalled = ConfigurationService.PanaceaInstalled, + } + }); + }, _ => true); + RemoveModCommand = new RelayCommand(_ => + { + var mod = SelectedValue; + if (Question($"Do you want to delete the mod '{mod.Source}'?", $"Remove mod {mod.Source}")) + { + Handle(() => + { + foreach (var filePath in Directory.GetFiles(mod.Path, "*", SearchOption.AllDirectories)) + { + var attributes = File.GetAttributes(filePath); + if (attributes.HasFlag(FileAttributes.ReadOnly)) + File.SetAttributes(filePath, attributes & ~FileAttributes.ReadOnly); + } + + Directory.Delete(mod.Path, true); + ModsList.RemoveAt(ModsList.IndexOf(SelectedValue)); + }); + } + }, _ => IsModSelected); + OpenModFolderCommand = new RelayCommand(_ => + { + using var process = Process.Start(new ProcessStartInfo + { + FileName = SelectedValue.Path, + UseShellExecute = true + }); + }, _ => IsModSelected); + MoveTop = new RelayCommand(_ => MoveSelectedModTop(), _ => CanSelectedModMoveUp()); + MoveUp = new RelayCommand(_ => MoveSelectedModUp(), _ => CanSelectedModMoveUp()); + MoveDown = new RelayCommand(_ => MoveSelectedModDown(), _ => CanSelectedModMoveDown()); + BuildCommand = new RelayCommand(async _ => + { + ResetLogWindow(); + await BuildPatches(false); + CloseAllWindows(); + }, _ => !IsBuilding); + + PatchCommand = new RelayCommand(async (fastMode) => + { + ResetLogWindow(); + await BuildPatches(Convert.ToBoolean(fastMode)); + await PatchGame(Convert.ToBoolean(fastMode)); + CloseAllWindows(); + }, _ => !IsBuilding); + + RunCommand = new RelayCommand(async _ => + { + CloseRunningProcess(); + ResetLogWindow(); + await RunGame(); + }); + + RestoreCommand = new RelayCommand(async (patched) => + { + ResetLogWindow(); + await RestoreGame(Convert.ToBoolean(patched)); + CloseAllWindows(); + }); + BuildAndRunCommand = new RelayCommand(async _ => + { + CloseRunningProcess(); + ResetLogWindow(); + if (await BuildPatches(false)) + await RunGame(); + }, _ => !IsBuilding); + StopRunningInstanceCommand = new RelayCommand(_ => + { + CloseRunningProcess(); + ResetLogWindow(); + }, _ => IsRunning); + WizardCommand = new RelayCommand(_ => + { + var dialog = new SetupWizardWindow() + { + ConfigGameEdition = ConfigurationService.GameEdition, + ConfigGameDataLocation = ConfigurationService.GameDataLocation, + ConfigIsoLocation = ConfigurationService.IsoLocation, + ConfigOpenKhGameEngineLocation = ConfigurationService.OpenKhGameEngineLocation, + ConfigPcsx2Location = ConfigurationService.Pcsx2Location, + ConfigPcReleaseLocation = ConfigurationService.PcReleaseLocation, + ConfigPcReleaseLocationKH3D = ConfigurationService.PcReleaseLocationKH3D, + ConfigPcReleaseLanguage = ConfigurationService.PcReleaseLanguage, + ConfigPcReleaseSteamLocation = ConfigurationService.PcReleaseSteamLocation, + ConfigPcReleaseSteamLocationKH3D = ConfigurationService.PcReleaseSteamLocationKH3D, + ConfigPcReleaseLanguageDT = ConfigurationService.PcReleaseLanguageDT, + ConfigRegionId = ConfigurationService.RegionId, + ConfigPanaceaInstalled = ConfigurationService.PanaceaInstalled, ConfigIsEGSVersion = ConfigurationService.IsEGSVersion, - }; - if (dialog.ShowDialog() == true) - { - ConfigurationService.GameEdition = dialog.ConfigGameEdition; - ConfigurationService.GameDataLocation = dialog.ConfigGameDataLocation; - ConfigurationService.IsoLocation = dialog.ConfigIsoLocation; - ConfigurationService.OpenKhGameEngineLocation = dialog.ConfigOpenKhGameEngineLocation; - ConfigurationService.Pcsx2Location = dialog.ConfigPcsx2Location; - ConfigurationService.PcReleaseLocation = dialog.ConfigPcReleaseLocation; - ConfigurationService.PcReleaseLocationKH3D = dialog.ConfigPcReleaseLocationKH3D; - ConfigurationService.RegionId = dialog.ConfigRegionId; - ConfigurationService.PanaceaInstalled = dialog.ConfigPanaceaInstalled; - ConfigurationService.IsEGSVersion = dialog.ConfigIsEGSVersion; + }; + if (dialog.ShowDialog() == true) + { + ConfigurationService.GameEdition = dialog.ConfigGameEdition; + ConfigurationService.GameDataLocation = dialog.ConfigGameDataLocation; + ConfigurationService.IsoLocation = dialog.ConfigIsoLocation; + ConfigurationService.OpenKhGameEngineLocation = dialog.ConfigOpenKhGameEngineLocation; + ConfigurationService.Pcsx2Location = dialog.ConfigPcsx2Location; + ConfigurationService.PcReleaseLocation = dialog.ConfigPcReleaseLocation; + ConfigurationService.PcReleaseLocationKH3D = dialog.ConfigPcReleaseLocationKH3D; + ConfigurationService.PcReleaseSteamLocation = dialog.ConfigPcReleaseSteamLocation; + ConfigurationService.PcReleaseSteamLocationKH3D = dialog.ConfigPcReleaseSteamLocationKH3D; + ConfigurationService.PcReleaseLanguageDT = dialog.ConfigPcReleaseLanguageDT; + ConfigurationService.RegionId = dialog.ConfigRegionId; + ConfigurationService.PanaceaInstalled = dialog.ConfigPanaceaInstalled; + ConfigurationService.IsEGSVersion = dialog.ConfigIsEGSVersion; ConfigurationService.WizardVersionNumber = _wizardVersionNumber; - - const int EpicGamesPC = 2; - if (ConfigurationService.GameEdition == EpicGamesPC && - Directory.Exists(ConfigurationService.PcReleaseLocation)) - { - File.WriteAllLines(Path.Combine(ConfigurationService.PcReleaseLocation, "panacea_settings.txt"), - new string[] - { - $"mod_path={ConfigurationService.GameModPath}", - $"show_console={false}", - }); - } - if (ConfigurationService.GameEdition == EpicGamesPC && - Directory.Exists(ConfigurationService.PcReleaseLocationKH3D)) - { - File.WriteAllLines(Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "panacea_settings.txt"), - new string[] - { - $"mod_path={ConfigurationService.GameModPath}", - $"show_console={false}", - }); - } - if (ConfigurationService.GameEdition == 2) - { - PC = true; - PanaceaInstalled = ConfigurationService.PanaceaInstalled; - } - else - PC = false; - } + + string path = (ConfigurationService.PcReleaseLocation ?? ConfigurationService.PcReleaseSteamLocation); + string path3D = (ConfigurationService.PcReleaseLocationKH3D ?? ConfigurationService.PcReleaseSteamLocationKH3D); + + if ( + ConfigurationService.GameEdition == EpicGamesPC && + Directory.Exists(ConfigurationService.PcReleaseLocation) || + (ConfigurationService.GameEdition == Steam && + Directory.Exists(ConfigurationService.PcReleaseSteamLocation)) + ) + { + File.WriteAllLines(Path.Combine(path, "panacea_settings.txt"), + new string[] + { + $"mod_path={ConfigurationService.GameModPath}", + $"show_console={false}", + }); + } + if ( + (ConfigurationService.GameEdition == EpicGamesPC && + Directory.Exists(ConfigurationService.PcReleaseLocationKH3D)) || + (ConfigurationService.GameEdition == Steam && + Directory.Exists(ConfigurationService.PcReleaseSteamLocationKH3D)) + ) + { + File.WriteAllLines(Path.Combine(path3D, "panacea_settings.txt"), + new string[] + { + $"mod_path={ConfigurationService.GameModPath}", + $"show_console={false}", + }); + } + if (ConfigurationService.GameEdition == EpicGamesPC || ConfigurationService.GameEdition == Steam) + { + PC = true; + PanaceaInstalled = ConfigurationService.PanaceaInstalled; + } + else + PC = false; + } }); OpenPresetMenuCommand = new RelayCommand(_ => @@ -528,11 +547,11 @@ await ModsService.InstallMod(name, isZipFile, isLuaFile, progress => UseShellExecute = true })); - CheckOpenkhUpdateCommand = new RelayCommand( + CheckOpenkhUpdateCommand = new RelayCommand( _ => UpdateOpenkhAsync() - ); - - YamlGeneratorCommand = new RelayCommand( + ); + + YamlGeneratorCommand = new RelayCommand( _ => { var window = new YamlGeneratorWindow() @@ -547,113 +566,127 @@ await ModsService.InstallMod(name, isZipFile, isLuaFile, progress => } }; window.Show(); - } - ); - - _pcsx2Injector = new Pcsx2Injector(new OperationDispatcher()); - FetchUpdates(); - - if (ConfigurationService.WizardVersionNumber < _wizardVersionNumber) - WizardCommand.Execute(null); - } - - public void CloseAllWindows() - { - CloseRunningProcess(); + } + ); + + _pcsx2Injector = new Pcsx2Injector(new OperationDispatcher()); + FetchUpdates(); + + if (ConfigurationService.WizardVersionNumber < _wizardVersionNumber) + WizardCommand.Execute(null); + } + + public void CloseAllWindows() + { + CloseRunningProcess(); Application.Current.Dispatcher.Invoke(_debuggingWindow.Close); - } - - public void CloseRunningProcess() - { - if (_runningProcess == null) - return; - - _pcsx2Injector.Stop(); - _runningProcess.CloseMainWindow(); - _runningProcess.Kill(); - _runningProcess.Dispose(); - _runningProcess = null; - OnPropertyChanged(nameof(StopRunningInstanceCommand)); - } - - private void ResetLogWindow() - { - if (_debuggingWindow != null) + } + + public void CloseRunningProcess() + { + if (_runningProcess == null) + return; + + _pcsx2Injector.Stop(); + _runningProcess.CloseMainWindow(); + _runningProcess.Kill(); + _runningProcess.Dispose(); + _runningProcess = null; + OnPropertyChanged(nameof(StopRunningInstanceCommand)); + } + + private void ResetLogWindow() + { + if (_debuggingWindow != null) Application.Current.Dispatcher.Invoke(_debuggingWindow.Close); - _debuggingWindow = new DebuggingWindow(); + _debuggingWindow = new DebuggingWindow(); Application.Current.Dispatcher.Invoke(_debuggingWindow.Show); - _debuggingWindow.ClearLogs(); - } - - private async Task BuildPatches(bool fastMode) - { - IsBuilding = true; - var result = await ModsService.RunPacherAsync(fastMode); - IsBuilding = false; - - return result; - } - - private Task RunGame() - { - ProcessStartInfo processStartInfo; - bool isPcsx2 = false; - switch (ConfigurationService.GameEdition) - { - case 0: - Log.Info("Starting OpenKH Game Engine"); - processStartInfo = new ProcessStartInfo - { - FileName = ConfigurationService.OpenKhGameEngineLocation, - WorkingDirectory = Path.GetDirectoryName(ConfigurationService.OpenKhGameEngineLocation), - Arguments = $"--data \"{ConfigurationService.GameDataLocation}\" --modpath \"{ConfigurationService.GameModPath}\"", - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - }; - break; - case 1: - Log.Info("Starting PCSX2"); - _pcsx2Injector.RegionId = ConfigurationService.RegionId; - _pcsx2Injector.Region = Kh2.Constants.Regions[_pcsx2Injector.RegionId]; - _pcsx2Injector.Language = Kh2.Constants.Languages[_pcsx2Injector.RegionId]; - - processStartInfo = new ProcessStartInfo - { - FileName = ConfigurationService.Pcsx2Location, - WorkingDirectory = Path.GetDirectoryName(ConfigurationService.Pcsx2Location), - Arguments = $"\"{ConfigurationService.IsoLocation}\"", - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - }; - isPcsx2 = true; - break; - case 2: - if (ConfigurationService.IsEGSVersion && !(_launchGame == "kh3d")) + _debuggingWindow.ClearLogs(); + } + + private async Task BuildPatches(bool fastMode) + { + IsBuilding = true; + var result = await ModsService.RunPacherAsync(fastMode); + IsBuilding = false; + + return result; + } + + private Task RunGame() + { + ProcessStartInfo processStartInfo; + bool isPcsx2 = false; + switch (ConfigurationService.GameEdition) + { + case 0: + Log.Info("Starting OpenKH Game Engine"); + processStartInfo = new ProcessStartInfo + { + FileName = ConfigurationService.OpenKhGameEngineLocation, + WorkingDirectory = Path.GetDirectoryName(ConfigurationService.OpenKhGameEngineLocation), + Arguments = $"--data \"{ConfigurationService.GameDataLocation}\" --modpath \"{ConfigurationService.GameModPath}\"", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + }; + break; + case 1: + Log.Info("Starting PCSX2"); + _pcsx2Injector.RegionId = ConfigurationService.RegionId; + _pcsx2Injector.Region = Kh2.Constants.Regions[_pcsx2Injector.RegionId]; + _pcsx2Injector.Language = Kh2.Constants.Languages[_pcsx2Injector.RegionId]; + + processStartInfo = new ProcessStartInfo { - if (ConfigurationService.PcReleaseLocation != null) + FileName = ConfigurationService.Pcsx2Location, + WorkingDirectory = Path.GetDirectoryName(ConfigurationService.Pcsx2Location), + Arguments = $"\"{ConfigurationService.IsoLocation}\"", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + }; + isPcsx2 = true; + break; + case 2: + case 3: + string path = (ConfigurationService.PcReleaseLocation ?? ConfigurationService.PcReleaseSteamLocation); + string path3D = (ConfigurationService.PcReleaseLocationKH3D ?? ConfigurationService.PcReleaseSteamLocationKH3D); + if ((ConfigurationService.IsEGSVersion) && !(_launchGame == "kh3d")) + { + if (ConfigurationService.PcReleaseLocation != null || ConfigurationService.PcReleaseSteamLocation != null) { if (ConfigurationService.PanaceaInstalled) { - string panaceaSettings = Path.Combine(ConfigurationService.PcReleaseLocation, "panacea_settings.txt"); + string panaceaSettings = Path.Combine(path, "panacea_settings.txt"); if (!File.Exists(panaceaSettings)) { - File.WriteAllLines(Path.Combine(ConfigurationService.PcReleaseLocation, "panacea_settings.txt"), + File.WriteAllLines(Path.Combine(path, "panacea_settings.txt"), new string[] - { - $"mod_path={ConfigurationService.GameModPath}", + { + $"mod_path={ConfigurationService.GameModPath}", $"show_console={false}", }); } File.AppendAllText(panaceaSettings, "\nquick_launch=" + _launchGame); } - processStartInfo = new ProcessStartInfo + if(ConfigurationService.PcReleaseLocation != null) { - FileName = "com.epicgames.launcher://apps/4158b699dd70447a981fee752d970a3e%3A5aac304f0e8948268ddfd404334dbdc7%3A68c214c58f694ae88c2dab6f209b43e4?action=launch&silent=true", - UseShellExecute = true, - }; - } + processStartInfo = new ProcessStartInfo + { + FileName = "com.epicgames.launcher://apps/4158b699dd70447a981fee752d970a3e%3A5aac304f0e8948268ddfd404334dbdc7%3A68c214c58f694ae88c2dab6f209b43e4?action=launch&silent=true", + UseShellExecute = true, + }; + } else + { + processStartInfo = new ProcessStartInfo + { + FileName = "steam://rungameid/2552430", + UseShellExecute = true, + }; + + } + } else { MessageBox.Show( @@ -661,23 +694,23 @@ private Task RunGame() "Run error", MessageBoxButton.OK, MessageBoxImage.Error); CloseAllWindows(); return Task.CompletedTask; - } - } + } + } else if (ConfigurationService.IsEGSVersion && _launchGame == "kh3d") { - if (ConfigurationService.PcReleaseLocationKH3D != null) + if (ConfigurationService.PcReleaseLocationKH3D != null || ConfigurationService.PcReleaseSteamLocationKH3D != null) { - string panaceaSettings = Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "panacea_settings.txt"); + string panaceaSettings = Path.Combine(path3D, "panacea_settings.txt"); if (ConfigurationService.PanaceaInstalled) { if (!File.Exists(panaceaSettings)) { - if (Directory.Exists(ConfigurationService.PcReleaseLocationKH3D)) + if (Directory.Exists(path3D)) { - File.WriteAllLines(Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "panacea_settings.txt"), + File.WriteAllLines(Path.Combine(path3D, "panacea_settings.txt"), new string[] - { - $"mod_path={ConfigurationService.GameModPath}", + { + $"mod_path={ConfigurationService.GameModPath}", $"show_console={false}", }); } @@ -686,12 +719,22 @@ private Task RunGame() } File.AppendAllText(panaceaSettings, "\nquick_launch=" + _launchGame); } - processStartInfo = new ProcessStartInfo + if(ConfigurationService.PcReleaseLocation != null) { - FileName = "com.epicgames.launcher://apps/c8ff067c1c984cd7ab1998e8a9afc8b6%3Aaa743b9f52e84930b0ba1b701951e927%3Ad1a8f7c478d4439b8c60a5808715dc05?action=launch&silent=true", - UseShellExecute = true, - }; - } + processStartInfo = new ProcessStartInfo + { + FileName = "com.epicgames.launcher://apps/c8ff067c1c984cd7ab1998e8a9afc8b6%3Aaa743b9f52e84930b0ba1b701951e927%3Ad1a8f7c478d4439b8c60a5808715dc05?action=launch&silent=true", + UseShellExecute = true, + }; + } else + { + processStartInfo = new ProcessStartInfo + { + FileName = "steam://rungameid/2552440", + UseShellExecute = true, + }; + } + } else { MessageBox.Show( @@ -700,8 +743,8 @@ private Task RunGame() CloseAllWindows(); return Task.CompletedTask; } - } - else + } + else { string filename = ""; @@ -709,21 +752,21 @@ private Task RunGame() { if (!(_launchGame == "kh3d")) { - filename = Path.Combine(ConfigurationService.PcReleaseLocation, executable[launchExecutable]); + filename = Path.Combine(path, executable[launchExecutable]); } else { - filename = Path.Combine(ConfigurationService.PcReleaseLocationKH3D, executable[launchExecutable]); + filename = Path.Combine(path3D, executable[launchExecutable]); } - processStartInfo = new ProcessStartInfo - { - FileName = filename, - WorkingDirectory = Path.GetDirectoryName(filename), - UseShellExecute = false, - }; + processStartInfo = new ProcessStartInfo + { + FileName = filename, + WorkingDirectory = Path.GetDirectoryName(filename), + UseShellExecute = false, + }; Process.Start(processStartInfo); CloseAllWindows(); - return Task.CompletedTask; + return Task.CompletedTask; } catch (Exception ex) { @@ -737,386 +780,404 @@ private Task RunGame() "Run error", MessageBoxButton.OK, MessageBoxImage.Error); CloseAllWindows(); return Task.CompletedTask; - } + } } Process.Start(processStartInfo); CloseAllWindows(); return Task.CompletedTask; - default: - return Task.CompletedTask; - } - - if (processStartInfo == null || !File.Exists(processStartInfo.FileName)) - { - MessageBox.Show( - "Unable to locate the executable. Please run the Wizard by going to the Settings menu.", - "Run error", MessageBoxButton.OK, MessageBoxImage.Error); - CloseAllWindows(); - return Task.CompletedTask; - } - - _runningProcess = new Process() { StartInfo = processStartInfo }; - _runningProcess.OutputDataReceived += (sender, e) => CaptureLog(e.Data); - _runningProcess.ErrorDataReceived += (sender, e) => CaptureLog(e.Data); - _runningProcess.Start(); - _runningProcess.BeginOutputReadLine(); - _runningProcess.BeginErrorReadLine(); - if (isPcsx2) - _pcsx2Injector.Run(_runningProcess, _debuggingWindow); - - OnPropertyChanged(nameof(StopRunningInstanceCommand)); - return Task.Run(() => - { - _runningProcess.WaitForExit(); - CloseAllWindows(); - }); - } - - private void CaptureLog(string data) - { - if (data == null) - return; - else if (data.Contains("err", StringComparison.InvariantCultureIgnoreCase)) - Log.Err(data); - else if (data.Contains("wrn", StringComparison.InvariantCultureIgnoreCase)) - Log.Warn(data); - else if (data.Contains("warn", StringComparison.InvariantCultureIgnoreCase)) - Log.Warn(data); - else - Log.Info(data); - } - - private void ReloadModsList() - { - ModsList = new ObservableCollection( - ModsService.GetMods(ModsService.Mods).Select(Map)); - OnPropertyChanged(nameof(ModsList)); - } - - private ModViewModel Map(ModModel mod) => new ModViewModel(mod, this); - - public void ModEnableStateChanged() - { - ConfigurationService.EnabledMods = ModsList - .Where(x => x.Enabled) - .Select(x => x.Source) - .ToList(); - OnPropertyChanged(nameof(BuildAndRunCommand)); - } - - private void MoveSelectedModDown() - { - var selectedIndex = ModsList.IndexOf(SelectedValue); - if (selectedIndex < 0) - return; - - var item = ModsList[selectedIndex]; - ModsList.RemoveAt(selectedIndex); - ModsList.Insert(++selectedIndex, item); - SelectedValue = ModsList[selectedIndex]; - ModEnableStateChanged(); - } - - private void MoveSelectedModUp() - { - var selectedIndex = ModsList.IndexOf(SelectedValue); - if (selectedIndex < 0) - return; - - var item = ModsList[selectedIndex]; - ModsList.RemoveAt(selectedIndex); - ModsList.Insert(--selectedIndex, item); - SelectedValue = ModsList[selectedIndex]; - ModEnableStateChanged(); - } - private void MoveSelectedModTop() - { - var selectedIndex = ModsList.IndexOf(SelectedValue); - if (selectedIndex < 0) - return; - - var item = ModsList[selectedIndex]; - ModsList.RemoveAt(selectedIndex); - ModsList.Insert(selectedIndex = 0, item); - SelectedValue = ModsList[selectedIndex]; - ModEnableStateChanged(); - } - - private async Task PatchGame(bool fastMode) - { - await Task.Run(() => - { - if (ConfigurationService.GameEdition == 2) - { - // Use the package map file to rearrange the files in the structure needed by the patcher - var packageMapLocation = Path.Combine(ConfigurationService.GameModPath, _launchGame, "patch-package-map.txt"); - var packageMap = File - .ReadLines(packageMapLocation) - .Select(line => line.Split(" $$$$ ")) - .ToDictionary(array => array[0], array => array[1]); - - var patchStagingDir = Path.Combine(ConfigurationService.GameModPath, _launchGame, "patch-staging"); - if (Directory.Exists(patchStagingDir)) - Directory.Delete(patchStagingDir, true); - Directory.CreateDirectory(patchStagingDir); - foreach (var entry in packageMap) - { - var sourceFile = Path.Combine(ConfigurationService.GameModPath, _launchGame, entry.Key); - var destFile = Path.Combine(patchStagingDir, entry.Value); - Directory.CreateDirectory(Path.GetDirectoryName(destFile)); - File.Move(sourceFile, destFile); - } - - foreach (var directory in Directory.GetDirectories(Path.Combine(ConfigurationService.GameModPath, _launchGame))) - if (!"patch-staging".Equals(Path.GetFileName(directory))) - Directory.Delete(directory, true); - - var stagingDirs = Directory.GetDirectories(patchStagingDir).Select(directory => Path.GetFileName(directory)).ToHashSet(); - - string[] specialDirs = Array.Empty(); - var specialStagingDir = Path.Combine(patchStagingDir, "special"); - if (Directory.Exists(specialStagingDir)) - specialDirs = Directory.GetDirectories(specialStagingDir).Select(directory => Path.GetFileName(directory)).ToArray(); - - foreach (var packageName in stagingDirs) - Directory.Move(Path.Combine(patchStagingDir, packageName), Path.Combine(ConfigurationService.GameModPath, _launchGame, packageName)); - foreach (var specialDir in specialDirs) - Directory.Move(Path.Combine(ConfigurationService.GameModPath, _launchGame, "special", specialDir), Path.Combine(ConfigurationService.GameModPath, _launchGame, specialDir)); - - stagingDirs.Remove("special"); // Since it's not actually a real game package - Directory.Delete(patchStagingDir, true); - - var specialModDir = Path.Combine(ConfigurationService.GameModPath, _launchGame, "special"); - if (Directory.Exists(specialModDir)) - Directory.Delete(specialModDir, true); - - foreach (var directory in stagingDirs.Select(packageDir => Path.Combine(ConfigurationService.GameModPath, _launchGame, packageDir))) - { - if (specialDirs.Contains(Path.GetDirectoryName(directory))) - continue; - - var patchFiles = new List(); - var _dirPart = new DirectoryInfo(directory).Name; - - var _orgPath = Path.Combine(directory, ORIGINAL_FILES_FOLDER_NAME); - var _rawPath = Path.Combine(directory, RAW_FILES_FOLDER_NAME); - - if (Directory.Exists(_orgPath)) - patchFiles = OpenKh.Egs.Helpers.GetAllFiles(_orgPath).ToList(); - - if (Directory.Exists(_rawPath)) - patchFiles.AddRange(OpenKh.Egs.Helpers.GetAllFiles(_rawPath).ToList()); - - string _pkgSoft; - switch (_launchGame) - { - case "kh1": - _pkgSoft = fastMode ? "kh1_first" : _dirPart; - break; - case "bbs": - _pkgSoft = fastMode ? "bbs_first" : _dirPart; - break; - case "Recom": - _pkgSoft = "Recom"; - break; - case "kh3d": - _pkgSoft = fastMode ? "kh3d_first" : _dirPart; - break; - default: - _pkgSoft = fastMode ? "kh2_first" : _dirPart; - break; - - } - string _pkgName = null; - string _backupDir = null; - if (_launchGame != "kh3d" && ConfigurationService.PcReleaseLocation != null) + default: + return Task.CompletedTask; + } + + if (processStartInfo == null || !File.Exists(processStartInfo.FileName)) + { + MessageBox.Show( + "Unable to locate the executable. Please run the Wizard by going to the Settings menu.", + "Run error", MessageBoxButton.OK, MessageBoxImage.Error); + CloseAllWindows(); + return Task.CompletedTask; + } + + _runningProcess = new Process() { StartInfo = processStartInfo }; + _runningProcess.OutputDataReceived += (sender, e) => CaptureLog(e.Data); + _runningProcess.ErrorDataReceived += (sender, e) => CaptureLog(e.Data); + _runningProcess.Start(); + _runningProcess.BeginOutputReadLine(); + _runningProcess.BeginErrorReadLine(); + if (isPcsx2) + _pcsx2Injector.Run(_runningProcess, _debuggingWindow); + + OnPropertyChanged(nameof(StopRunningInstanceCommand)); + return Task.Run(() => + { + _runningProcess.WaitForExit(); + CloseAllWindows(); + }); + } + + private void CaptureLog(string data) + { + if (data == null) + return; + else if (data.Contains("err", StringComparison.InvariantCultureIgnoreCase)) + Log.Err(data); + else if (data.Contains("wrn", StringComparison.InvariantCultureIgnoreCase)) + Log.Warn(data); + else if (data.Contains("warn", StringComparison.InvariantCultureIgnoreCase)) + Log.Warn(data); + else + Log.Info(data); + } + + private void ReloadModsList() + { + ModsList = new ObservableCollection( + ModsService.GetMods(ModsService.Mods).Select(Map)); + OnPropertyChanged(nameof(ModsList)); + } + + private ModViewModel Map(ModModel mod) => new ModViewModel(mod, this); + + public void ModEnableStateChanged() + { + ConfigurationService.EnabledMods = ModsList + .Where(x => x.Enabled) + .Select(x => x.Source) + .ToList(); + OnPropertyChanged(nameof(BuildAndRunCommand)); + } + + private void MoveSelectedModDown() + { + var selectedIndex = ModsList.IndexOf(SelectedValue); + if (selectedIndex < 0) + return; + + var item = ModsList[selectedIndex]; + ModsList.RemoveAt(selectedIndex); + ModsList.Insert(++selectedIndex, item); + SelectedValue = ModsList[selectedIndex]; + ModEnableStateChanged(); + } + + private void MoveSelectedModUp() + { + var selectedIndex = ModsList.IndexOf(SelectedValue); + if (selectedIndex < 0) + return; + + var item = ModsList[selectedIndex]; + ModsList.RemoveAt(selectedIndex); + ModsList.Insert(--selectedIndex, item); + SelectedValue = ModsList[selectedIndex]; + ModEnableStateChanged(); + } + private void MoveSelectedModTop() + { + var selectedIndex = ModsList.IndexOf(SelectedValue); + if (selectedIndex < 0) + return; + + var item = ModsList[selectedIndex]; + ModsList.RemoveAt(selectedIndex); + ModsList.Insert(selectedIndex = 0, item); + SelectedValue = ModsList[selectedIndex]; + ModEnableStateChanged(); + } + + private async Task PatchGame(bool fastMode) + { + await Task.Run(() => + { + if (ConfigurationService.GameEdition == EpicGamesPC || ConfigurationService.GameEdition == Steam) + { + // Use the package map file to rearrange the files in the structure needed by the patcher + var packageMapLocation = Path.Combine(ConfigurationService.GameModPath, _launchGame, "patch-package-map.txt"); + var packageMap = File + .ReadLines(packageMapLocation) + .Select(line => line.Split(" $$$$ ")) + .ToDictionary(array => array[0], array => array[1]); + + var patchStagingDir = Path.Combine(ConfigurationService.GameModPath, _launchGame, "patch-staging"); + if (Directory.Exists(patchStagingDir)) + Directory.Delete(patchStagingDir, true); + Directory.CreateDirectory(patchStagingDir); + foreach (var entry in packageMap) + { + var sourceFile = Path.Combine(ConfigurationService.GameModPath, _launchGame, entry.Key); + var destFile = Path.Combine(patchStagingDir, entry.Value); + Directory.CreateDirectory(Path.GetDirectoryName(destFile)); + File.Move(sourceFile, destFile); + } + + foreach (var directory in Directory.GetDirectories(Path.Combine(ConfigurationService.GameModPath, _launchGame))) + if (!"patch-staging".Equals(Path.GetFileName(directory))) + Directory.Delete(directory, true); + + var stagingDirs = Directory.GetDirectories(patchStagingDir).Select(directory => Path.GetFileName(directory)).ToHashSet(); + + string[] specialDirs = Array.Empty(); + var specialStagingDir = Path.Combine(patchStagingDir, "special"); + if (Directory.Exists(specialStagingDir)) + specialDirs = Directory.GetDirectories(specialStagingDir).Select(directory => Path.GetFileName(directory)).ToArray(); + + foreach (var packageName in stagingDirs) + Directory.Move(Path.Combine(patchStagingDir, packageName), Path.Combine(ConfigurationService.GameModPath, _launchGame, packageName)); + foreach (var specialDir in specialDirs) + Directory.Move(Path.Combine(ConfigurationService.GameModPath, _launchGame, "special", specialDir), Path.Combine(ConfigurationService.GameModPath, _launchGame, specialDir)); + + stagingDirs.Remove("special"); // Since it's not actually a real game package + Directory.Delete(patchStagingDir, true); + + var specialModDir = Path.Combine(ConfigurationService.GameModPath, _launchGame, "special"); + if (Directory.Exists(specialModDir)) + Directory.Delete(specialModDir, true); + + foreach (var directory in stagingDirs.Select(packageDir => Path.Combine(ConfigurationService.GameModPath, _launchGame, packageDir))) + { + if (specialDirs.Contains(Path.GetDirectoryName(directory))) + continue; + + var patchFiles = new List(); + var _dirPart = new DirectoryInfo(directory).Name; + + var _orgPath = Path.Combine(directory, ORIGINAL_FILES_FOLDER_NAME); + var _rawPath = Path.Combine(directory, RAW_FILES_FOLDER_NAME); + + if (Directory.Exists(_orgPath)) + patchFiles = OpenKh.Egs.Helpers.GetAllFiles(_orgPath).ToList(); + + if (Directory.Exists(_rawPath)) + patchFiles.AddRange(OpenKh.Egs.Helpers.GetAllFiles(_rawPath).ToList()); + + string _pkgSoft; + switch (_launchGame) + { + case "kh1": + _pkgSoft = fastMode ? "kh1_first" : _dirPart; + break; + case "bbs": + _pkgSoft = fastMode ? "bbs_first" : _dirPart; + break; + case "Recom": + _pkgSoft = "Recom"; + break; + case "kh3d": + _pkgSoft = fastMode ? "kh3d_first" : _dirPart; + break; + default: + _pkgSoft = fastMode ? "kh2_first" : _dirPart; + break; + + } + string _pkgName = null; + string _backupDir = null; + + string path = (ConfigurationService.PcReleaseLocation ?? ConfigurationService.PcReleaseSteamLocation); + string path3D = (ConfigurationService.PcReleaseLocationKH3D ?? ConfigurationService.PcReleaseSteamLocationKH3D); + + if (_launchGame != "kh3d" && (ConfigurationService.PcReleaseLocation != null || ConfigurationService.PcReleaseSteamLocation != null)) { - _pkgName = Path.Combine(ConfigurationService.PcReleaseLocation, "Image", ConfigurationService.PcReleaseLanguage, _pkgSoft + ".pkg"); - _backupDir = Path.Combine(ConfigurationService.PcReleaseLocation, "BackupImage"); - } - else if (ConfigurationService.PcReleaseLocationKH3D != null) + string languagePath = Path.Combine(path, "Image", ConfigurationService.PcReleaseLanguage); + string availableLanguage = Directory.Exists(languagePath) ? ConfigurationService.PcReleaseLanguage : ConfigurationService.PcReleaseLanguageDT; + _pkgName = Path.Combine(path, "Image", availableLanguage, _pkgSoft + ".pkg"); + _backupDir = Path.Combine(path, "BackupImage"); + } + else if (ConfigurationService.PcReleaseLocationKH3D != null || ConfigurationService.PcReleaseSteamLocationKH3D != null) { - _pkgName = Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "Image", ConfigurationService.PcReleaseLanguage, _pkgSoft + ".pkg"); - _backupDir = Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "BackupImage"); - } - else + string languagePath = Path.Combine(path3D, "Image", ConfigurationService.PcReleaseLanguage); + string availableLanguage = Directory.Exists(languagePath) ? ConfigurationService.PcReleaseLanguage : ConfigurationService.PcReleaseLanguageDT; + _pkgName = Path.Combine(path3D, "Image", availableLanguage, _pkgSoft + ".pkg"); + _backupDir = Path.Combine(path3D, "BackupImage"); + } + else { Log.Warn("Game Location for selected game cannot be found! Re-run th setup wizard to confirm the path is correct and/or confirm launchgame in the top right is correct."); break; - } - - if (!Directory.Exists(_backupDir)) - Directory.CreateDirectory(_backupDir); - - var outputDir = "patchedpkgs"; - var hedFile = Path.ChangeExtension(_pkgName, "hed"); - - if (!File.Exists(_backupDir + "/" + _pkgSoft + ".pkg")) - { - Log.Info($"Backing Up Package File {_pkgSoft}"); - - File.Copy(_pkgName, _backupDir + "/" + _pkgSoft + ".pkg"); - File.Copy(hedFile, _backupDir + "/" + _pkgSoft + ".hed"); - } - - else - { - Log.Info($"Restoring Package File {_pkgSoft}"); - - File.Delete(hedFile); - File.Delete(_pkgName); - - File.Copy(_backupDir + "/" + _pkgSoft + ".pkg", _pkgName); - File.Copy(_backupDir + "/" + _pkgSoft + ".hed", hedFile); - } - - using var hedStream = File.OpenRead(hedFile); - using var pkgStream = File.OpenRead(_pkgName); - var hedHeaders = OpenKh.Egs.Hed.Read(hedStream).ToList(); - - if (!Directory.Exists(outputDir)) - Directory.CreateDirectory(outputDir); - - using var patchedHedStream = File.Create(Path.Combine(outputDir, Path.GetFileName(hedFile))); - using var patchedPkgStream = File.Create(Path.Combine(outputDir, Path.GetFileName(_pkgName))); - - foreach (var hedHeader in hedHeaders) - { - var hash = OpenKh.Egs.Helpers.ToString(hedHeader.MD5); - - // We don't know this filename, we ignore it - if (!OpenKh.Egs.EgsTools.Names.TryGetValue(hash, out var filename)) - continue; - - var asset = new OpenKh.Egs.EgsHdAsset(pkgStream.SetPosition(hedHeader.Offset)); - - if (patchFiles.Contains(filename)) - { - patchFiles.Remove(filename); - - if (hedHeader.DataLength > 0) - { - OpenKh.Egs.EgsTools.ReplaceFile(directory, filename, patchedHedStream, patchedPkgStream, asset, hedHeader); - Log.Info($"Replacing File {filename} in {_pkgSoft}"); - } - } - - else - { - OpenKh.Egs.EgsTools.ReplaceFile(directory, filename, patchedHedStream, patchedPkgStream, asset, hedHeader); - Log.Info($"Skipped File {filename} in {_pkgSoft}"); - } - } - - // Add all files that are not in the original HED file and inject them in the PKG stream too - foreach (var filename in patchFiles) - { - OpenKh.Egs.EgsTools.AddFile(directory, filename, patchedHedStream, patchedPkgStream); - Log.Info($"Adding File {filename} to {_pkgSoft}"); - } - - hedStream.Close(); - pkgStream.Close(); - - patchedHedStream.Close(); - patchedPkgStream.Close(); - - File.Delete(hedFile); + } + + if (!Directory.Exists(_backupDir)) + Directory.CreateDirectory(_backupDir); + + var outputDir = "patchedpkgs"; + var hedFile = Path.ChangeExtension(_pkgName, "hed"); + + if (!File.Exists(_backupDir + "/" + _pkgSoft + ".pkg")) + { + Log.Info($"Backing Up Package File {_pkgSoft}"); + + File.Copy(_pkgName, _backupDir + "/" + _pkgSoft + ".pkg"); + File.Copy(hedFile, _backupDir + "/" + _pkgSoft + ".hed"); + } + + else + { + Log.Info($"Restoring Package File {_pkgSoft}"); + + File.Delete(hedFile); + File.Delete(_pkgName); + + File.Copy(_backupDir + "/" + _pkgSoft + ".pkg", _pkgName); + File.Copy(_backupDir + "/" + _pkgSoft + ".hed", hedFile); + } + + using var hedStream = File.OpenRead(hedFile); + using var pkgStream = File.OpenRead(_pkgName); + var hedHeaders = OpenKh.Egs.Hed.Read(hedStream).ToList(); + + if (!Directory.Exists(outputDir)) + Directory.CreateDirectory(outputDir); + + using var patchedHedStream = File.Create(Path.Combine(outputDir, Path.GetFileName(hedFile))); + using var patchedPkgStream = File.Create(Path.Combine(outputDir, Path.GetFileName(_pkgName))); + + foreach (var hedHeader in hedHeaders) + { + var hash = OpenKh.Egs.Helpers.ToString(hedHeader.MD5); + + // We don't know this filename, we ignore it + if (!OpenKh.Egs.EgsTools.Names.TryGetValue(hash, out var filename)) + continue; + + var asset = new OpenKh.Egs.EgsHdAsset(pkgStream.SetPosition(hedHeader.Offset)); + + if (patchFiles.Contains(filename)) + { + patchFiles.Remove(filename); + + if (hedHeader.DataLength > 0) + { + OpenKh.Egs.EgsTools.ReplaceFile(directory, filename, patchedHedStream, patchedPkgStream, asset, hedHeader); + Log.Info($"Replacing File {filename} in {_pkgSoft}"); + } + } + + else + { + OpenKh.Egs.EgsTools.ReplaceFile(directory, filename, patchedHedStream, patchedPkgStream, asset, hedHeader); + Log.Info($"Skipped File {filename} in {_pkgSoft}"); + } + } + + // Add all files that are not in the original HED file and inject them in the PKG stream too + foreach (var filename in patchFiles) + { + OpenKh.Egs.EgsTools.AddFile(directory, filename, patchedHedStream, patchedPkgStream); + Log.Info($"Adding File {filename} to {_pkgSoft}"); + } + + hedStream.Close(); + pkgStream.Close(); + + patchedHedStream.Close(); + patchedPkgStream.Close(); + + File.Delete(hedFile); File.Delete(_pkgName); - File.Move(Path.Combine(outputDir, Path.GetFileName(hedFile)), hedFile); - File.Move(Path.Combine(outputDir, Path.GetFileName(_pkgName)), _pkgName); - } - } - }); - } - - private async Task RestoreGame(bool patched) - { - await Task.Run(() => - { - if (ConfigurationService.GameEdition == 2) + File.Move(Path.Combine(outputDir, Path.GetFileName(hedFile)), hedFile); + File.Move(Path.Combine(outputDir, Path.GetFileName(_pkgName)), _pkgName); + } + } + }); + } + + private async Task RestoreGame(bool patched) + { + await Task.Run(() => + { + if (ConfigurationService.GameEdition == EpicGamesPC || ConfigurationService.GameEdition == Steam) { - if (patched && _launchGame != "kh3d") - { - if (ConfigurationService.PcReleaseLocation == null || !Directory.Exists(Path.Combine(ConfigurationService.PcReleaseLocation, "BackupImage"))) - { - Log.Warn("backup folder cannot be found! Cannot restore the game."); - } - else - { - foreach (var file in Directory.GetFiles(Path.Combine(ConfigurationService.PcReleaseLocation, "BackupImage")).Where(x => x.Contains(".pkg") && (x.Contains(_launchGame)))) - { - Log.Info($"Restoring Package File {file.Replace(".pkg", "")}"); - - var _fileBare = Path.GetFileName(file); - var _trueName = Path.Combine(ConfigurationService.PcReleaseLocation, "Image", ConfigurationService.PcReleaseLanguage, _fileBare); - - File.Delete(Path.ChangeExtension(_trueName, "hed")); - File.Delete(_trueName); - - File.Copy(file, _trueName); - File.Copy(Path.ChangeExtension(file, "hed"), Path.ChangeExtension(_trueName, "hed")); - } - } - - } - else if (patched) - { - if (ConfigurationService.PcReleaseLocationKH3D == null || !Directory.Exists(Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "BackupImage"))) - { - Log.Warn("backup folder cannot be found! Cannot restore the game."); - } - else - { - foreach (var file in Directory.GetFiles(Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "BackupImage")).Where(x => x.Contains(".pkg") && (x.Contains(_launchGame)))) - { - Log.Info($"Restoring Package File {file.Replace(".pkg", "")}"); - - var _fileBare = Path.GetFileName(file); - var _trueName = Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "Image", ConfigurationService.PcReleaseLanguage, _fileBare); - - File.Delete(Path.ChangeExtension(_trueName, "hed")); - File.Delete(_trueName); - - File.Copy(file, _trueName); - File.Copy(Path.ChangeExtension(file, "hed"), Path.ChangeExtension(_trueName, "hed")); - } - } - - } - if (Directory.Exists(ConfigurationService.GameModPath)) - { - try - { - Directory.Delete(Path.Combine(ConfigurationService.GameModPath, _launchGame), true); - } - catch (Exception ex) - { - Log.Warn("Unable to fully clean the mod directory:\n{0}", ex.Message); - } - } - } - }); - } - - private bool CanSelectedModMoveDown() => - SelectedValue != null && ModsList.IndexOf(SelectedValue) < ModsList.Count - 1; - - private bool CanSelectedModMoveUp() => - SelectedValue != null && ModsList.IndexOf(SelectedValue) > 0; - - private async Task FetchUpdates() - { - await Task.Delay(50); // fixes a bug where the UI wanted to refresh too soon - await foreach (var modUpdate in ModsService.FetchUpdates()) - { - var mod = ModsList.FirstOrDefault(x => x.Source == modUpdate.Name); - if (mod == null) - continue; - + if (patched && _launchGame != "kh3d") + { + string path = (ConfigurationService.PcReleaseLocation ?? ConfigurationService.PcReleaseSteamLocation); + string languagePath = Path.Combine(path, "Image", ConfigurationService.PcReleaseLanguage); + string availableLanguage = Directory.Exists(languagePath) ? ConfigurationService.PcReleaseLanguage : ConfigurationService.PcReleaseLanguageDT; + + if ( + ConfigurationService.PcReleaseLocation == null || !Directory.Exists(Path.Combine(ConfigurationService.PcReleaseLocation, "BackupImage")) || + ConfigurationService.PcReleaseSteamLocation == null || !Directory.Exists(Path.Combine(ConfigurationService.PcReleaseSteamLocation, "BackupImage")) + ) + { + Log.Warn("backup folder cannot be found! Cannot restore the game."); + } + else + { + foreach (var file in Directory.GetFiles(Path.Combine(path, "BackupImage")).Where(x => x.Contains(".pkg") && (x.Contains(_launchGame)))) + { + Log.Info($"Restoring Package File {file.Replace(".pkg", "")}"); + + var _fileBare = Path.GetFileName(file); + var _trueName = Path.Combine(path, "Image", availableLanguage, _fileBare); + + File.Delete(Path.ChangeExtension(_trueName, "hed")); + File.Delete(_trueName); + + File.Copy(file, _trueName); + File.Copy(Path.ChangeExtension(file, "hed"), Path.ChangeExtension(_trueName, "hed")); + } + } + + } + else if (patched) + { + string path3D = (ConfigurationService.PcReleaseLocationKH3D ?? ConfigurationService.PcReleaseSteamLocationKH3D); + string languagePath = Path.Combine(path3D, "Image", ConfigurationService.PcReleaseLanguage); + string availableLanguage = Directory.Exists(languagePath) ? ConfigurationService.PcReleaseLanguage : ConfigurationService.PcReleaseLanguageDT; + if (ConfigurationService.PcReleaseLocationKH3D == null || !Directory.Exists(Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "BackupImage"))) + { + Log.Warn("backup folder cannot be found! Cannot restore the game."); + } + else + { + foreach (var file in Directory.GetFiles(Path.Combine(path3D, "BackupImage")).Where(x => x.Contains(".pkg") && (x.Contains(_launchGame)))) + { + Log.Info($"Restoring Package File {file.Replace(".pkg", "")}"); + + var _fileBare = Path.GetFileName(file); + var _trueName = Path.Combine(path3D, "Image", availableLanguage, _fileBare); + + File.Delete(Path.ChangeExtension(_trueName, "hed")); + File.Delete(_trueName); + + File.Copy(file, _trueName); + File.Copy(Path.ChangeExtension(file, "hed"), Path.ChangeExtension(_trueName, "hed")); + } + } + + } + if (Directory.Exists(ConfigurationService.GameModPath)) + { + try + { + Directory.Delete(Path.Combine(ConfigurationService.GameModPath, _launchGame), true); + } + catch (Exception ex) + { + Log.Warn("Unable to fully clean the mod directory:\n{0}", ex.Message); + } + } + } + }); + } + + private bool CanSelectedModMoveDown() => + SelectedValue != null && ModsList.IndexOf(SelectedValue) < ModsList.Count - 1; + + private bool CanSelectedModMoveUp() => + SelectedValue != null && ModsList.IndexOf(SelectedValue) > 0; + + private async Task FetchUpdates() + { + await Task.Delay(50); // fixes a bug where the UI wanted to refresh too soon + await foreach (var modUpdate in ModsService.FetchUpdates()) + { + var mod = ModsList.FirstOrDefault(x => x.Source == modUpdate.Name); + if (mod == null) + continue; + Application.Current.Dispatcher.Invoke(() => - mod.UpdateCount = modUpdate.UpdateCount); + mod.UpdateCount = modUpdate.UpdateCount); } if (AutoUpdateMods) { @@ -1127,8 +1188,8 @@ private async Task FetchUpdates() } ReloadModsList(); } - } - + } + private async Task UpdateOpenkhAsync() { var progressWindowService = new ProgressWindowService(); @@ -1179,9 +1240,11 @@ public void UpdatePanaceaSettings() { if (PanaceaInstalled) { - if (_launchGame != "kh3d" && ConfigurationService.PcReleaseLocation != null) + string path = (ConfigurationService.PcReleaseLocation ?? ConfigurationService.PcReleaseSteamLocation); + string path3D = (ConfigurationService.PcReleaseLocationKH3D ?? ConfigurationService.PcReleaseSteamLocationKH3D); + if (_launchGame != "kh3d" && ConfigurationService.PcReleaseLocation != null || _launchGame != "kh3d" && ConfigurationService.PcReleaseSteamLocation != null) { - string panaceaSettings = Path.Combine(ConfigurationService.PcReleaseLocation, "panacea_settings.txt"); + string panaceaSettings = Path.Combine(path, "panacea_settings.txt"); string[] lines = File.ReadAllLines(panaceaSettings); string textToWrite = $"mod_path={ConfigurationService.GameModPath}\r\n"; foreach (string entry in lines) @@ -1196,9 +1259,9 @@ public void UpdatePanaceaSettings() $"debug_log={_panaceaDebugLogEnabled}\r\nenable_cache={_panaceaCacheEnabled}\r\nquick_menu={_panaceaQuickMenuEnabled}"; File.WriteAllText(panaceaSettings, textToWrite); } - else if (ConfigurationService.PcReleaseLocationKH3D != null) + else if (ConfigurationService.PcReleaseLocationKH3D != null || ConfigurationService.PcReleaseSteamLocationKH3D != null) { - string panaceaSettings = Path.Combine(ConfigurationService.PcReleaseLocationKH3D, "panacea_settings.txt"); + string panaceaSettings = Path.Combine(path3D, "panacea_settings.txt"); string[] lines = File.ReadAllLines(panaceaSettings); string textToWrite = $"mod_path={ConfigurationService.GameModPath}\r\n"; foreach (string entry in lines) diff --git a/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs b/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs index 69a4cc09d..7945e4b6d 100644 --- a/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs +++ b/OpenKh.Tools.ModsManager/ViewModels/SetupWizardViewModel.cs @@ -17,6 +17,8 @@ using Xe.Tools.Wpf.Dialogs; using Ionic.Zip; using System.Diagnostics; +using Newtonsoft.Json.Linq; +using System.Text.RegularExpressions; namespace OpenKh.Tools.ModsManager.ViewModels { @@ -39,6 +41,7 @@ public class SetupWizardViewModel : BaseNotifyPropertyChanged const int OpenKHGameEngine = 0; const int PCSX2 = 1; const int EpicGames = 2; + const int Steam = 3; private int _gameEdition; private string _isoLocation; @@ -46,11 +49,15 @@ public class SetupWizardViewModel : BaseNotifyPropertyChanged private string _pcsx2Location; private string _pcReleaseLocation; private string _pcReleaseLocationKH3D; + private string _pcReleaseSteamLocation; + private string _pcReleaseSteamLocationKH3D; private string _pcReleasesSelected; private int _gameCollection = 0; private string _pcReleaseLanguage; + private string _pcReleaseLanguageDT; private string _gameDataLocation; private bool _isEGSVersion; + private bool _isSteamVersion; private List LuaScriptPaths = new List(); private bool _overrideGameDataFound = false; @@ -142,6 +149,10 @@ public bool IsGameSelected (!string.IsNullOrEmpty(PcReleaseLocationKH3D) && Directory.Exists(PcReleaseLocationKH3D) && File.Exists(Path.Combine(PcReleaseLocationKH3D, "EOSSDK-Win64-Shipping.dll"))), + Steam => (!string.IsNullOrEmpty(PcReleaseSteamLocation) && + Directory.Exists(PcReleaseSteamLocation) || + (!string.IsNullOrEmpty(PcReleaseSteamLocationKH3D) && + Directory.Exists(PcReleaseSteamLocationKH3D))), _ => false, }; } @@ -158,6 +169,7 @@ public int GameEdition OpenKHGameEngine => LastPage, PCSX2 => PageIsoSelection, EpicGames => PageEosInstall, + Steam => PageEosInstall, _ => null, }; WizardPageAfterGameData = GameEdition switch @@ -165,6 +177,7 @@ public int GameEdition OpenKHGameEngine => LastPage, PCSX2 => PageRegion, EpicGames => LastPage, + Steam => LastPage, _ => null, }; @@ -173,6 +186,7 @@ public int GameEdition OnPropertyChanged(nameof(OpenKhGameEngineConfigVisibility)); OnPropertyChanged(nameof(Pcsx2ConfigVisibility)); OnPropertyChanged(nameof(PcReleaseConfigVisibility)); + OnPropertyChanged(nameof(PcReleaseSteamConfigVisibility)); } } public RelayCommand SelectOpenKhGameEngineCommand { get; } @@ -202,7 +216,10 @@ public string Pcsx2Location } public RelayCommand SelectPcReleaseCommand { get; } + + public RelayCommand SelectPcSteamReleaseCommand { get; } public Visibility PcReleaseConfigVisibility => GameEdition == EpicGames ? Visibility.Visible : Visibility.Collapsed; + public Visibility PcReleaseSteamConfigVisibility => GameEdition == Steam ? Visibility.Visible : Visibility.Collapsed; public Visibility BothPcReleaseSelected => PcReleaseSelections == "both" ? Visibility.Visible : Visibility.Collapsed; public Visibility PcRelease1525Selected => PcReleaseSelections == "1.5+2.5" ? Visibility.Visible: Visibility.Collapsed; public Visibility PcRelease28Selected => PcReleaseSelections == "2.8" ? Visibility.Visible : Visibility.Collapsed; @@ -228,22 +245,55 @@ public string PcReleaseLocation OnPropertyChanged(nameof(InstallForPc1525)); } } + public string PcReleaseSteamLocation + { + get => _pcReleaseSteamLocation; + set + { + _pcReleaseSteamLocation = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsLastPanaceaVersionInstalled)); + OnPropertyChanged(nameof(PanaceaInstalledVisibility)); + OnPropertyChanged(nameof(PanaceaNotInstalledVisibility)); + OnPropertyChanged(nameof(IsGameSelected)); + OnPropertyChanged(nameof(IsGameDataFound)); + OnPropertyChanged(nameof(LuaBackendFoundVisibility)); + OnPropertyChanged(nameof(LuaBackendNotFoundVisibility)); + OnPropertyChanged(nameof(BothPcReleaseSelected)); + OnPropertyChanged(nameof(PcRelease1525Selected)); + OnPropertyChanged(nameof(PcRelease28Selected)); + OnPropertyChanged(nameof(InstallForPc1525)); + } + } public string PcReleaseSelections { get { - if (Directory.Exists(PcReleaseLocation) && File.Exists(Path.Combine(PcReleaseLocation, "EOSSDK-Win64-Shipping.dll")) && - Directory.Exists(PcReleaseLocationKH3D) && File.Exists(Path.Combine(PcReleaseLocationKH3D, "EOSSDK-Win64-Shipping.dll"))) + if ( + Directory.Exists(PcReleaseLocation) && + File.Exists(Path.Combine(PcReleaseLocation = "", "EOSSDK-Win64-Shipping.dll")) && + Directory.Exists(PcReleaseLocationKH3D) && + File.Exists(Path.Combine(PcReleaseLocationKH3D = "", "EOSSDK-Win64-Shipping.dll")) || + Directory.Exists(PcReleaseSteamLocation) && Directory.Exists(PcReleaseSteamLocationKH3D) + ) { return _pcReleasesSelected = "both"; } - else if (Directory.Exists(PcReleaseLocation) && File.Exists(Path.Combine(PcReleaseLocation, "EOSSDK-Win64-Shipping.dll"))) + else if ( + Directory.Exists(PcReleaseLocation) && + File.Exists(Path.Combine(PcReleaseLocation = "", "EOSSDK-Win64-Shipping.dll")) || + Directory.Exists(PcReleaseSteamLocation) + ) { return _pcReleasesSelected = "1.5+2.5"; } - else if (Directory.Exists(PcReleaseLocationKH3D) && File.Exists(Path.Combine(PcReleaseLocationKH3D, "EOSSDK-Win64-Shipping.dll"))) + else if ( + Directory.Exists(PcReleaseLocationKH3D) && + File.Exists(Path.Combine(PcReleaseLocationKH3D = "", "EOSSDK-Win64-Shipping.dll")) || + Directory.Exists(PcReleaseSteamLocationKH3D) + ) { return _pcReleasesSelected = "2.8"; @@ -291,6 +341,29 @@ public string PcReleaseLocationKH3D OnPropertyChanged(nameof(InstallForPc28)); } } + + public RelayCommand SelectPcSteamReleaseKH3DCommand { get; } + + public string PcReleaseSteamLocationKH3D + { + get => _pcReleaseSteamLocationKH3D; + set + { + _pcReleaseSteamLocationKH3D = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(IsLastPanaceaVersionInstalled)); + OnPropertyChanged(nameof(PanaceaInstalledVisibility)); + OnPropertyChanged(nameof(PanaceaNotInstalledVisibility)); + OnPropertyChanged(nameof(IsGameSelected)); + OnPropertyChanged(nameof(IsGameDataFound)); + OnPropertyChanged(nameof(LuaBackendFoundVisibility)); + OnPropertyChanged(nameof(LuaBackendNotFoundVisibility)); + OnPropertyChanged(nameof(BothPcReleaseSelected)); + OnPropertyChanged(nameof(PcRelease1525Selected)); + OnPropertyChanged(nameof(PcRelease28Selected)); + OnPropertyChanged(nameof(InstallForPc28)); + } + } public bool IsEGSVersion { get => _isEGSVersion; @@ -299,6 +372,14 @@ public bool IsEGSVersion _isEGSVersion = value; } } + public bool IsSteamVersion + { + get => _isSteamVersion; + set + { + _isSteamVersion = value; + } + } public bool Extractkh1 { get => ConfigurationService.Extractkh1; @@ -427,6 +508,21 @@ public string PcReleaseLanguage OnPropertyChanged(nameof(IsGameDataFound)); } } + public string PcReleaseLanguageDT + { + get => _pcReleaseLanguageDT; + set + { + _pcReleaseLanguageDT = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(PcReleaseLanguageDT)); + OnPropertyChanged(nameof(IsLastPanaceaVersionInstalled)); + OnPropertyChanged(nameof(PanaceaInstalledVisibility)); + OnPropertyChanged(nameof(PanaceaNotInstalledVisibility)); + OnPropertyChanged(nameof(IsGameSelected)); + OnPropertyChanged(nameof(IsGameDataFound)); + } + } public RelayCommand SelectGameDataLocationCommand { get; } public string GameDataLocation @@ -444,7 +540,7 @@ public string GameDataLocation public bool IsNotExtracting { get; private set; } public bool IsGameDataFound => (IsNotExtracting && GameService.FolderContainsUniqueFile(GameId, Path.Combine(GameDataLocation, "kh2")) || - (GameEdition == EpicGames && (GameService.FolderContainsUniqueFile("kh2", Path.Combine(GameDataLocation, "kh2")) || + ((GameEdition == EpicGames || GameEdition == Steam) && (GameService.FolderContainsUniqueFile("kh2", Path.Combine(GameDataLocation, "kh2")) || GameService.FolderContainsUniqueFile("kh1", Path.Combine(GameDataLocation, "kh1")) || Directory.Exists(Path.Combine(GameDataLocation, "bbs", "message")) || Directory.Exists(Path.Combine(GameDataLocation, "Recom", "SYS"))))|| @@ -473,6 +569,7 @@ public bool IsLuaBackendInstalled File.Exists(Path.Combine(PcReleaseLocationKH3D, "lua54.dll")) && File.Exists(Path.Combine(PcReleaseLocationKH3D, "LuaBackend.toml")); } + // TODO: How steam works here? else return false; } @@ -581,6 +678,10 @@ public SetupWizardViewModel() FileDialog.OnFolder(path => PcReleaseLocation = path)); SelectPcReleaseKH3DCommand = new RelayCommand(_ => FileDialog.OnFolder(path => PcReleaseLocationKH3D = path)); + SelectPcSteamReleaseCommand = new RelayCommand(_ => + FileDialog.OnFolder(path => PcReleaseSteamLocation = path)); + SelectPcSteamReleaseKH3DCommand = new RelayCommand(_ => + FileDialog.OnFolder(path => PcReleaseSteamLocationKH3D = path)); SelectGameDataLocationCommand = new RelayCommand(_ => FileDialog.OnFolder(path => GameDataLocation = path)); ExtractGameDataCommand = new RelayCommand(async _ => @@ -607,18 +708,24 @@ public SetupWizardViewModel() { // Get ProgramData Folder Location string programDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); + string programSteamDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); string directoryPath = Path.Combine(programDataFolder, "Epic\\EpicGamesLauncher\\Data\\Manifests"); - - if (!Directory.Exists(directoryPath)) + string directorySteamPath = Path.Combine(programSteamDataFolder, "Steam\\steamapps"); + IEnumerable itemFiles = Enumerable.Empty(); + if (!Directory.Exists(directoryPath) && !Directory.Exists(directorySteamPath)) { MessageBox.Show("No Game Install Locations Found\nPlease Manually Browse To Your Game Install Directory", "Failure", MessageBoxButton.OK); return; } // Get List of .item Files in C:\ProgramData\Epic\EpicGamesLauncher\Data\Manifests\ - IEnumerable itemFiles = Directory.EnumerateFiles(directoryPath, "*.item"); + if (Directory.Exists(directoryPath)) + { + itemFiles = Directory.EnumerateFiles(directoryPath, "*.item"); + } + - if (!itemFiles.Any()) + if ((!itemFiles.Any() && Directory.Exists(directoryPath)) || !Directory.Exists(directorySteamPath)) { MessageBox.Show("No Game Install Locations Found\nPlease Manually Browse To Your Game Install Directory", "Failure", MessageBoxButton.OK); return; @@ -626,44 +733,86 @@ public SetupWizardViewModel() bool installLocationFoundRemix = false; bool installLocationFound3D = false; - foreach (string itemFile in itemFiles) + + + // Read the entire content of the VDF file + string vdfContent = File.ReadAllText(Path.Combine(directorySteamPath, "libraryfolders.vdf")); + + // Define a regular expression to match "path" values + Regex regex = new Regex(@"""path""\s*""([^""]*)""", RegexOptions.IgnoreCase); + + // MatchCollection to store all matches found + MatchCollection matches = regex.Matches(vdfContent); + + // Iterate through matches and print out the "path" values + if (Directory.Exists(directorySteamPath)) { - // Read Each .item File and Locate Install Location For Games - using StreamReader sr = new StreamReader(itemFile); - string line; - if (sr != null) + foreach (Match match in matches) { - while ((line = sr.ReadLine()) is not null) + string pathValue = match.Groups[1].Value; // Group 1 is the path raw, without the key + Console.WriteLine($"Path: {pathValue}"); + + string parsedText = pathValue.Replace(@"\\", @"\"); + + string commonGamesDirectory = Path.Combine(parsedText, "steamapps\\common"); + if (Directory.Exists(commonGamesDirectory)) { - if (line.Contains("\"LaunchExecutable\": \"KINGDOM HEARTS HD 1.5+2.5 ReMIX.exe\",")) + string kH1525Path = Path.Combine(commonGamesDirectory, @"KINGDOM HEARTS -HD 1.5+2.5 ReMIX-"); + string kH28Path = Path.Combine(commonGamesDirectory, @"KINGDOM HEARTS HD 2.8 Final Chapter Prologue"); + if (Directory.Exists(kH1525Path)) { - while ((line = sr.ReadLine()) is not null) + installLocationFoundRemix = true; + PcReleaseSteamLocation = kH1525Path; + } + if (Directory.Exists(kH28Path)) + { + installLocationFound3D = true; + PcReleaseSteamLocationKH3D = kH28Path; + } + } + } + } + if (Directory.Exists(directoryPath)) + { + foreach (string itemFile in itemFiles) + { + // Read Each .item File and Locate Install Location For Games + using StreamReader sr = new StreamReader(itemFile); + string line; + if (sr != null) + { + while ((line = sr.ReadLine()) is not null) + { + if (line.Contains("\"LaunchExecutable\": \"KINGDOM HEARTS HD 1.5+2.5 ReMIX.exe\",")) { - if (line.Contains("\"InstallLocation\": \"")) + while ((line = sr.ReadLine()) is not null) { - installLocationFoundRemix = true; - int startIndex = line.IndexOf("\": \"") + 4; - int endIndex = line.IndexOf("\","); - string parsedText = line[startIndex..endIndex]; - parsedText = parsedText.Replace("\\\\", "\\"); - PcReleaseLocation = parsedText; + if (line.Contains("\"InstallLocation\": \"")) + { + installLocationFoundRemix = true; + int startIndex = line.IndexOf("\": \"") + 4; + int endIndex = line.IndexOf("\","); + string parsedText = line[startIndex..endIndex]; + parsedText = parsedText.Replace("\\\\", "\\"); + PcReleaseLocation = parsedText; + } } } - } - else if (line.Contains("\"LaunchExecutable\": \"KINGDOM HEARTS HD 2.8 Final Chapter Prologue.exe\",")) - { - while ((line = sr.ReadLine()) is not null) + else if (line.Contains("\"LaunchExecutable\": \"KINGDOM HEARTS HD 2.8 Final Chapter Prologue.exe\",")) { - if (line.Contains("\"InstallLocation\": \"")) + while ((line = sr.ReadLine()) is not null) { - installLocationFound3D = true; - int startIndex = line.IndexOf("\": \"") + 4; - int endIndex = line.IndexOf("\","); - string parsedText = line[startIndex..endIndex]; - parsedText = parsedText.Replace("\\\\", "\\"); - PcReleaseLocationKH3D = parsedText; + if (line.Contains("\"InstallLocation\": \"")) + { + installLocationFound3D = true; + int startIndex = line.IndexOf("\": \"") + 4; + int endIndex = line.IndexOf("\","); + string parsedText = line[startIndex..endIndex]; + parsedText = parsedText.Replace("\\\\", "\\"); + PcReleaseLocationKH3D = parsedText; + } } - } + } } } } @@ -1192,6 +1341,7 @@ await Task.Run(() => } break; + case Steam: case EpicGames: { IsNotExtracting = false; @@ -1239,11 +1389,33 @@ await Task.Run(() => var _totalFiles = 0; var _procTotalFiles = 0; + string path = (_pcReleaseLocation ?? _pcReleaseSteamLocation); + string path3D = (_pcReleaseLocationKH3D ?? _pcReleaseSteamLocationKH3D); + string releaseLenguage = null; + string releaseLenguage3D = null; + + if (Directory.Exists(Path.Combine(path, "Image", _pcReleaseLanguage))) { + releaseLenguage = _pcReleaseLanguage; + } + else + { + releaseLenguage = _pcReleaseLanguageDT; + } + + if (Directory.Exists(Path.Combine(path3D, "Image", _pcReleaseLanguage))) + { + releaseLenguage3D = _pcReleaseLanguage; + } + else + { + releaseLenguage3D = _pcReleaseLanguageDT; + } + if (ConfigurationService.Extractkh1) { for (int i = 0; i < 5; i++) { - using var _stream = new FileStream(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "kh1_" + _nameListkh1[i] + ".hed"), System.IO.FileMode.Open); + using var _stream = new FileStream(Path.Combine(path, "Image", releaseLenguage, "kh1_" + _nameListkh1[i] + ".hed"), System.IO.FileMode.Open); var _hedFile = OpenKh.Egs.Hed.Read(_stream); _totalFiles += _hedFile.Count(); } @@ -1252,7 +1424,7 @@ await Task.Run(() => { for (int i = 0; i < 6; i++) { - using var _stream = new FileStream(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "kh2_" + _nameListkh2[i] + ".hed"), System.IO.FileMode.Open); + using var _stream = new FileStream(Path.Combine(path, "Image", releaseLenguage, "kh2_" + _nameListkh2[i] + ".hed"), System.IO.FileMode.Open); var _hedFile = OpenKh.Egs.Hed.Read(_stream); _totalFiles += _hedFile.Count(); } @@ -1261,14 +1433,14 @@ await Task.Run(() => { for (int i = 0; i < 4; i++) { - using var _stream = new FileStream(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "bbs_" + _nameListbbs[i] + ".hed"), System.IO.FileMode.Open); + using var _stream = new FileStream(Path.Combine(path, "Image", releaseLenguage, "bbs_" + _nameListbbs[i] + ".hed"), System.IO.FileMode.Open); var _hedFile = OpenKh.Egs.Hed.Read(_stream); _totalFiles += _hedFile.Count(); } } if (ConfigurationService.Extractrecom) { - using var _stream = new FileStream(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "Recom.hed"), System.IO.FileMode.Open); + using var _stream = new FileStream(Path.Combine(path, "Image", releaseLenguage, "Recom.hed"), System.IO.FileMode.Open); var _hedFile = OpenKh.Egs.Hed.Read(_stream); _totalFiles += _hedFile.Count(); } @@ -1276,7 +1448,7 @@ await Task.Run(() => { for (int i = 0; i < 4; i++) { - using var _stream = new FileStream(Path.Combine(_pcReleaseLocationKH3D, "Image", _pcReleaseLanguage, "kh3d_" + _nameListbbs[i] + ".hed"), System.IO.FileMode.Open); + using var _stream = new FileStream(Path.Combine(path3D, "Image", releaseLenguage3D, "kh3d_" + _nameListbbs[i] + ".hed"), System.IO.FileMode.Open); var _hedFile = OpenKh.Egs.Hed.Read(_stream); _totalFiles += _hedFile.Count(); } @@ -1287,8 +1459,8 @@ await Task.Run(() => for (int i = 0; i < 5; i++) { var outputDir = Path.Combine(gameDataLocation, "kh1"); - using var hedStream = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "kh1_" + _nameListkh1[i] + ".hed")); - using var img = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "kh1_" + _nameListkh1[i] + ".pkg")); + using var hedStream = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "kh1_" + _nameListkh1[i] + ".hed")); + using var img = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "kh1_" + _nameListkh1[i] + ".pkg")); foreach (var entry in OpenKh.Egs.Hed.Read(hedStream)) { @@ -1326,8 +1498,8 @@ await Task.Run(() => for (int i = 0; i < 6; i++) { var outputDir = Path.Combine(gameDataLocation, "kh2"); - using var hedStream = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "kh2_" + _nameListkh2[i] + ".hed")); - using var img = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "kh2_" + _nameListkh2[i] + ".pkg")); + using var hedStream = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "kh2_" + _nameListkh2[i] + ".hed")); + using var img = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "kh2_" + _nameListkh2[i] + ".pkg")); foreach (var entry in OpenKh.Egs.Hed.Read(hedStream)) { @@ -1365,8 +1537,8 @@ await Task.Run(() => for (int i = 0; i < 4; i++) { var outputDir = Path.Combine(gameDataLocation, "bbs"); - using var hedStream = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "bbs_" + _nameListbbs[i] + ".hed")); - using var img = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "bbs_" + _nameListbbs[i] + ".pkg")); + using var hedStream = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "bbs_" + _nameListbbs[i] + ".hed")); + using var img = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "bbs_" + _nameListbbs[i] + ".pkg")); foreach (var entry in OpenKh.Egs.Hed.Read(hedStream)) { @@ -1404,8 +1576,8 @@ await Task.Run(() => for (int i = 0; i < 1; i++) { var outputDir = Path.Combine(gameDataLocation, "Recom"); - using var hedStream = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "Recom.hed")); - using var img = File.OpenRead(Path.Combine(_pcReleaseLocation, "Image", _pcReleaseLanguage, "Recom.pkg")); + using var hedStream = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "Recom.hed")); + using var img = File.OpenRead(Path.Combine(path, "Image", releaseLenguage, "Recom.pkg")); foreach (var entry in OpenKh.Egs.Hed.Read(hedStream)) { @@ -1443,8 +1615,8 @@ await Task.Run(() => for (int i = 0; i < 4; i++) { var outputDir = Path.Combine(gameDataLocation, "kh3d"); - using var hedStream = File.OpenRead(Path.Combine(_pcReleaseLocationKH3D, "Image", _pcReleaseLanguage, "kh3d_" + _nameListkh3d[i] + ".hed")); - using var img = File.OpenRead(Path.Combine(_pcReleaseLocationKH3D, "Image", _pcReleaseLanguage, "kh3d_" + _nameListkh3d[i] + ".pkg")); + using var hedStream = File.OpenRead(Path.Combine(path3D, "Image", releaseLenguage3D, "kh3d_" + _nameListkh3d[i] + ".hed")); + using var img = File.OpenRead(Path.Combine(path3D, "Image", releaseLenguage3D, "kh3d_" + _nameListkh3d[i] + ".pkg")); foreach (var entry in OpenKh.Egs.Hed.Read(hedStream)) { diff --git a/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml b/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml index aba71e966..b0bf96215 100644 --- a/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml +++ b/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml @@ -54,6 +54,7 @@ OpenKH Game Engine PlayStation 2 using PCSX2 emulator PC Release via Epic Game Store + PC Release via Steam Please select the location of OpenKH Game Engine @@ -112,6 +113,35 @@ NOTE: Always be sure to use a supported version or risk breaking compatibility + + + Mod Manager supports both the 1.5+2.5 collection and KH3D from the 2.8 collection choose the filepath for at least one of the collections. + + + Folder location of the PC release of 1.5+2.5 + + + + + + + + + Folder location of the PC release of 2.8 + + + + + + + + + NOTE: Always be sure to use a supported version or risk breaking compatibility + + + + You do not have any extracted data from a supported game. + + + You already have extracted data from a supported game. + + Press the button below to initialize the game extraction. It will take between 5 and 15 minutes based on the speed of your hard drive. diff --git a/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs b/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs index f0cb317d1..dc6d97e91 100644 --- a/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs +++ b/OpenKh.Tools.ModsManager/Views/SetupWizardWindow.xaml.cs @@ -34,7 +34,10 @@ public SetupWizardWindow() public string ConfigPcsx2Location { get => _vm.Pcsx2Location; set => _vm.Pcsx2Location = value; } public string ConfigPcReleaseLocation { get => _vm.PcReleaseLocation; set => _vm.PcReleaseLocation = value; } public string ConfigPcReleaseLocationKH3D { get => _vm.PcReleaseLocationKH3D; set => _vm.PcReleaseLocationKH3D = value; } + public string ConfigPcReleaseSteamLocation { get => _vm.PcReleaseSteamLocation; set => _vm.PcReleaseSteamLocation = value; } + public string ConfigPcReleaseSteamLocationKH3D { get => _vm.PcReleaseSteamLocationKH3D; set => _vm.PcReleaseSteamLocationKH3D = value; } public string ConfigPcReleaseLanguage { get => _vm.PcReleaseLanguage; set => _vm.PcReleaseLanguage = value; } + public string ConfigPcReleaseLanguageDT { get => _vm.PcReleaseLanguageDT; set => _vm.PcReleaseLanguageDT = value; } public string ConfigGameDataLocation { get => _vm.GameDataLocation; set => _vm.GameDataLocation = value; } public int ConfigRegionId { get => _vm.RegionId; set => _vm.RegionId = value; } public bool ConfigPanaceaInstalled { get => _vm.PanaceaInstalled; set => _vm.PanaceaInstalled = value; }