diff --git a/DirectPackageInstaller/DirectPackageInstaller/App.axaml.cs b/DirectPackageInstaller/DirectPackageInstaller/App.axaml.cs index 8395f88..ee621e8 100644 --- a/DirectPackageInstaller/DirectPackageInstaller/App.axaml.cs +++ b/DirectPackageInstaller/DirectPackageInstaller/App.axaml.cs @@ -209,7 +209,7 @@ public static async Task RunInNewThread(Action Function) return Failed; } - internal static Settings Config; + internal static Settings Config = new Settings(); internal static WebClientWithCookies HttpClient = new WebClientWithCookies(); internal static bool IsRunningOnMono => Type.GetType("Mono.Runtime") != null; @@ -255,8 +255,19 @@ public enum OS public static bool UseSDCard = false; public static string? CacheBaseDirectory => (UseSDCard ? AndroidSDCacheDir : AndroidCacheDir) ?? AndroidCacheDir; - public static string WorkingDirectory => _WorkingDir ??= Environment.GetEnvironmentVariable("CD") ?? Directory.GetCurrentDirectory(); - + public static string WorkingDirectory + { + get + { + var Result = _WorkingDir ??= Environment.GetEnvironmentVariable("CD") ?? Directory.GetCurrentDirectory(); + + if (string.IsNullOrWhiteSpace(Result.Trim('/', '\\'))) + throw new Exception("FAILED TO GET THE WORKING DIRECTORY PATH"); + + return Result; + } + } + public static Func GetFreeStorageSpace = () => { if (CurrentPlatform == OS.Windows) diff --git a/DirectPackageInstaller/DirectPackageInstaller/Host/PS4Server.cs b/DirectPackageInstaller/DirectPackageInstaller/Host/PS4Server.cs index a9c6a67..f2d20e5 100644 --- a/DirectPackageInstaller/DirectPackageInstaller/Host/PS4Server.cs +++ b/DirectPackageInstaller/DirectPackageInstaller/Host/PS4Server.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.Configuration; using System.IO; using System.Linq; using System.Text; @@ -23,10 +24,8 @@ public class PS4Server public Dictionary JSONs = new Dictionary(); Dictionary Instances = new Dictionary(); - -#if DEBUG - static TextWriter LOGWRITER = System.IO.File.CreateText(Path.Combine(App.WorkingDirectory, "DPIServer.log")); -#endif + + static TextWriter? LOGWRITER = null; public int Connections { get; private set; } = 0; public string LastRequestMode = null; @@ -37,6 +36,9 @@ public class PS4Server public string IP { get => Server.Settings.Hostname; } public PS4Server(string IP, int Port = 9898) { + if (App.Config.ShowError) + LOGWRITER = System.IO.File.CreateText(Path.Combine(App.WorkingDirectory, "DPIServer.log")); + Server = new Webserver(new WebserverSettings(IP, Port) { IO = new WebserverSettings.IOSettings() @@ -50,14 +52,17 @@ public PS4Server(string IP, int Port = 9898) LOG("Server Address: {0}:{1}", IP, Port); } - public void LOG(string Message, params object[] Format) { -#if DEBUG + private static void LOG(string Message, params object[] Format) + { + if (!App.Config.ShowError || LOGWRITER == null) + return; + lock (LOGWRITER) { - LOGWRITER.WriteLine(string.Format(Message, Format)); + LOGWRITER.WriteLine(Message, Format); LOGWRITER.Flush(); } -#endif + } public void Start() diff --git a/DirectPackageInstaller/DirectPackageInstaller/SelfUpdate.cs b/DirectPackageInstaller/DirectPackageInstaller/SelfUpdate.cs index 1bc10bf..6df0bcf 100644 --- a/DirectPackageInstaller/DirectPackageInstaller/SelfUpdate.cs +++ b/DirectPackageInstaller/DirectPackageInstaller/SelfUpdate.cs @@ -46,7 +46,7 @@ public static string? MainExecutable const string UpdateList = "Update.ini"; - public static Version CurrentVersion = new Version("6.1.10"); + public static Version CurrentVersion = new Version("6.1.11"); public static Version? LastVersion = null; diff --git a/DirectPackageInstaller/DirectPackageInstaller/Tasks/Installer.cs b/DirectPackageInstaller/DirectPackageInstaller/Tasks/Installer.cs index e3bc65a..a19c451 100644 --- a/DirectPackageInstaller/DirectPackageInstaller/Tasks/Installer.cs +++ b/DirectPackageInstaller/DirectPackageInstaller/Tasks/Installer.cs @@ -258,6 +258,7 @@ public static async Task PushRPI(string URL, Settings Config, bool Silent) catch { } } + await File.WriteAllTextAsync(Path.Combine(App.WorkingDirectory, "DPI-ERROR.log"), ex.ToString()); await MessageBox.ShowAsync("Failed:\n" + Result == null ? ex.ToString() : Result, "DirectPackageInstaller", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } diff --git a/DirectPackageInstaller/DirectPackageInstaller/Views/MainView.axaml.cs b/DirectPackageInstaller/DirectPackageInstaller/Views/MainView.axaml.cs index 841c5a6..ff58474 100644 --- a/DirectPackageInstaller/DirectPackageInstaller/Views/MainView.axaml.cs +++ b/DirectPackageInstaller/DirectPackageInstaller/Views/MainView.axaml.cs @@ -167,18 +167,20 @@ public async Task OnShown(MainWindow? Parent) { _ = PS4Finder.StartFinder((PS4IP, PCIP) => { - Dispatcher.UIThread.InvokeAsync(() => + Dispatcher.UIThread.InvokeAsync(async () => { - if (string.IsNullOrEmpty(Model.PS4IP)) + if (!string.IsNullOrEmpty(Model.PS4IP)) { - Model.PS4IP = PS4IP.ToString(); - - var NewPCIP = PCIP?.ToString() ?? IPHelper.FindLocalIP(PS4IP.ToString()) ?? ""; - if (!string.IsNullOrWhiteSpace(NewPCIP) && NewPCIP != "0.0.0.0") - Model.PCIP = NewPCIP; - - RestartServer_OnClick(null, null); + if (Model.PS4IP == PS4IP.ToString() || await MessageBox.ShowAsync($"A new PS4 IP has been found ({PS4IP}), Update the PS4 IP?", "DirectPackageInstaller", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + return; } + Model.PS4IP = PS4IP.ToString(); + + var NewPCIP = PCIP?.ToString() ?? IPHelper.FindLocalIP(PS4IP.ToString()) ?? ""; + if (!string.IsNullOrWhiteSpace(NewPCIP) && NewPCIP != "0.0.0.0") + Model.PCIP = NewPCIP; + + RestartServer_OnClick(null, null); }); }); } @@ -469,6 +471,8 @@ private async void BtnLoadOnClick(object? sender, RoutedEventArgs e) } catch (Exception ex) { + await File.WriteAllTextAsync(Path.Combine(App.WorkingDirectory, "DPI-ERROR.log"), ex.ToString()); + if (ex is not AbortException) await MessageBox.ShowAsync(ex.ToString(), "DirectPackageInstaller - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else if (App.Config.ShowError) @@ -1067,4 +1071,4 @@ protected override Size MeasureCore(Size availableSize) return base.MeasureCore(availableSize); } } -} \ No newline at end of file +}