Explorar o código

Fixed OS initialization after crash and fixed debug paths

Krzysztof Krysiński hai 7 meses
pai
achega
85c615555c

+ 3 - 1
src/PixiEditor.Linux/LinuxOperatingSystem.cs

@@ -12,7 +12,9 @@ public sealed class LinuxOperatingSystem : IOperatingSystem
     public string AnalyticsName => LinuxOSInformation.FromReleaseFile().ToString();
     public IInputKeys InputKeys { get; }
     public IProcessUtility ProcessUtility { get; }
-    
+
+    public string ExecutableExtension { get; } = string.Empty;
+
     public void OpenUri(string uri)
     {
         throw new NotImplementedException();

+ 3 - 1
src/PixiEditor.MacOs/MacOperatingSystem.cs

@@ -15,7 +15,9 @@ public sealed class MacOperatingSystem : IOperatingSystem
     public IProcessUtility ProcessUtility { get; } = new MacOsProcessUtility();
 
     private List<Uri> activationUris;
-    
+
+    public string ExecutableExtension { get; } = string.Empty;
+
     public void OpenUri(string uri)
     {
         ProcessUtility.ShellExecute(uri);

+ 5 - 0
src/PixiEditor.MacOs/MacOsProcessUtility.cs

@@ -44,6 +44,11 @@ internal class MacOsProcessUtility : IProcessUtility
     {
         ShellExecute(url);
     }
+    
+    void IProcessUtility.ShellExecute(string url, string args)
+    {
+        ShellExecute(url, args);
+    }
 
     public static void ShellExecute(string url, string args)
     {

+ 3 - 3
src/PixiEditor.MacOs/todo.md

@@ -1,13 +1,13 @@
 - [x] Input keys
 - [x] Default shortcuts
-- [ ] Package - builder
+- [x] Package - builder
 - [ ] FFmpeg
 - [x] Single instance
 - [ ] File associations (pixi, other formats, lospec protocol)
 - [ ] Autoupdates
 - [x] Process handling
-- [ ] Check if extensions work
+- [x] Check if extensions work
 - [x] Native menu
-- [ ] Crash dialog
+- [x] Crash dialog
 - [ ] Deploy pipelines
 - [x] OpenGL fixes

+ 1 - 0
src/PixiEditor.OperatingSystem/IOperatingSystem.cs

@@ -17,6 +17,7 @@ public interface IOperatingSystem
     public bool IsWindows => Name == "Windows";
     public bool IsLinux => Name == "Linux";
     public bool IsMiscellaneous => !IsMacOs && !IsWindows && !IsLinux;
+    public string ExecutableExtension { get; }
 
     public static void RegisterOS(IOperatingSystem operatingSystem)
     {

+ 1 - 0
src/PixiEditor.OperatingSystem/IProcessUtility.cs

@@ -8,4 +8,5 @@ public interface IProcessUtility
     public Process RunAsAdmin(string path, bool createWindow);
     public bool IsRunningAsAdministrator();
     public void ShellExecute(string toExecute);
+    public void ShellExecute(string toExecute, string args);
 }

+ 2 - 0
src/PixiEditor.Windows/WindowsOperatingSystem.cs

@@ -27,6 +27,8 @@ public sealed class WindowsOperatingSystem : IOperatingSystem
         Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
         "PixiEditor", ".passedArgs");
 
+    public string ExecutableExtension { get; } = ".exe";
+
     public void OpenUri(string uri)
     {
         WindowsProcessUtility.ShellExecute(uri);

+ 5 - 0
src/PixiEditor.Windows/WindowsProcessUtility.cs

@@ -50,6 +50,11 @@ public class WindowsProcessUtility : IProcessUtility
     {
         ShellExecute(url);
     }
+    
+    void IProcessUtility.ShellExecute(string url, string args)
+    {
+        ShellExecute(url, args);
+    }
 
     public static void ShellExecute(string url, string args)
     {

+ 10 - 5
src/PixiEditor/Helpers/ThemeResources.cs

@@ -8,15 +8,20 @@ namespace PixiEditor.Helpers;
 
 public static class ThemeResources
 {
+    public static string? ThemeFontFamilyName { get; } = "FiraSans";
+
     public static Font ThemeFont =>
-        Font.FromFamilyName("FiraSans") ?? Font.CreateDefault();
+        Font.FromFamilyName(ThemeFontFamilyName) ?? Font.CreateDefault();
 
     public static Color ForegroundColor =>
-        ResourceLoader.GetResource<SolidColorBrush>("ThemeForegroundBrush", Application.Current.ActualThemeVariant).Color.ToColor();
-    
+        ResourceLoader.GetResource<SolidColorBrush>("ThemeForegroundBrush", Application.Current.ActualThemeVariant)
+            .Color.ToColor();
+
     public static Color BackgroundColor =>
-        ResourceLoader.GetResource<SolidColorBrush>("ThemeBackgroundBrush", Application.Current.ActualThemeVariant).Color.ToColor();
+        ResourceLoader.GetResource<SolidColorBrush>("ThemeBackgroundBrush", Application.Current.ActualThemeVariant)
+            .Color.ToColor();
 
     public static Color BorderMidColor =>
-        ResourceLoader.GetResource<SolidColorBrush>("ThemeBorderMidBrush", Application.Current.ActualThemeVariant).Color.ToColor();
+        ResourceLoader.GetResource<SolidColorBrush>("ThemeBorderMidBrush", Application.Current.ActualThemeVariant).Color
+            .ToColor();
 }

+ 5 - 4
src/PixiEditor/Initialization/ClassicDesktopEntry.cs

@@ -37,6 +37,7 @@ internal class ClassicDesktopEntry
         {
             activable.Activated += ActivableOnActivated;
         }
+
         desktop.Startup += Start;
         desktop.ShutdownRequested += ShutdownRequested;
     }
@@ -47,7 +48,7 @@ internal class ClassicDesktopEntry
         {
             IOperatingSystem.Current.HandleActivatedWithFile(fileActivatedEventArgs);
         }
-        else if(e.Kind == ActivationKind.OpenUri && e is ProtocolActivatedEventArgs openUriEventArgs)
+        else if (e.Kind == ActivationKind.OpenUri && e is ProtocolActivatedEventArgs openUriEventArgs)
         {
             IOperatingSystem.Current.HandleActivatedWithUri(openUriEventArgs);
         }
@@ -58,6 +59,9 @@ internal class ClassicDesktopEntry
         StartupArgs.Args = e.Args.ToList();
         string arguments = string.Join(' ', e.Args);
 
+        Dispatcher dispatcher = Dispatcher.UIThread;
+        InitOperatingSystem();
+
         if (ParseArgument("--crash (\"?)([A-z0-9:\\/\\ -_.]+)\\1", arguments, out Group[] groups))
         {
             try
@@ -82,9 +86,6 @@ internal class ClassicDesktopEntry
             return;
         }
 
-        Dispatcher dispatcher = Dispatcher.UIThread;
-        InitOperatingSystem();
-
 #if !STEAM
         if (!HandleNewInstance(dispatcher))
         {

+ 4 - 13
src/PixiEditor/Models/ExceptionHandling/CrashReport.cs

@@ -472,23 +472,14 @@ internal class CrashReport : IDisposable
 
     public void RestartToCrashReport()
     {
-        // TODO: IOperatingSystem interface
-        Process process = new();
-
-        //TODO: Handle different name for the executable, .Desktop.exe
-        string fileName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location) + ".exe";
+        string fileName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location) +
+                          IOperatingSystem.Current.ExecutableExtension;
 #if DEBUG
         if(!File.Exists(fileName))
-            fileName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location) + ".Desktop.exe";
+            fileName = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location) + $".Desktop{IOperatingSystem.Current.ExecutableExtension}";
 #endif
 
-        process.StartInfo = new()
-        {
-            FileName = fileName,
-            Arguments = $"--crash \"{Path.GetFullPath(FilePath)}\""
-        };
-
-        process.Start();
+        IOperatingSystem.Current.ProcessUtility.ShellExecute(fileName, $"--crash \"{Path.GetFullPath(FilePath)}\"");
     }
 
     public bool TrySave(IEnumerable<DocumentViewModel> documents)

+ 9 - 0
src/PixiEditor/Models/IO/Paths.cs

@@ -24,4 +24,13 @@ public static class Paths
     public static string TempRenderingPath { get; } = Path.Combine(Path.GetTempPath(), "PixiEditor", "Rendering");
     
     public static string TempFilesPath { get; } = Path.Combine(Path.GetTempPath(), "PixiEditor");
+
+    public static string ParseSpecialPathOrDefault(string path)
+    {
+        path = path.Replace("%appdata%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
+        path = path.Replace("%localappdata%", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
+        path = path.Replace("%temp%", Path.GetTempPath());
+        
+        return path;
+    }
 }

+ 13 - 5
src/PixiEditor/ViewModels/SubViewModels/DebugViewModel.cs

@@ -17,6 +17,7 @@ using PixiEditor.Helpers;
 using PixiEditor.Models.Commands.Attributes.Commands;
 using PixiEditor.Models.Commands.Templates.Providers.Parsers;
 using PixiEditor.Models.Dialogs;
+using PixiEditor.Models.IO;
 using PixiEditor.OperatingSystem;
 using PixiEditor.UI.Common.Fonts;
 using PixiEditor.Views;
@@ -313,22 +314,29 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
         }
     }
 
-    [Command.Debug("PixiEditor.Debug.DeleteUserPreferences", @"%appdata%\PixiEditor\user_preferences.json", "DELETE_USR_PREFS", "DELETE_USR_PREFS",
+    [Command.Debug("PixiEditor.Debug.DeleteUserPreferences", @"%appdata%/PixiEditor/user_preferences.json", "DELETE_USR_PREFS", "DELETE_USR_PREFS",
         MenuItemPath = "DEBUG/DELETE/USER_PREFS", MenuItemOrder = 11, AnalyticsTrack = true)]
-    [Command.Debug("PixiEditor.Debug.DeleteShortcutFile", @"%appdata%\PixiEditor\shortcuts.json", "DELETE_SHORTCUT_FILE", "DELETE_SHORTCUT_FILE",
+    [Command.Debug("PixiEditor.Debug.DeleteShortcutFile", @"%appdata%/PixiEditor/shortcuts.json", "DELETE_SHORTCUT_FILE", "DELETE_SHORTCUT_FILE",
         MenuItemPath = "DEBUG/DELETE/SHORTCUT_FILE", MenuItemOrder = 12, AnalyticsTrack = true)]
-    [Command.Debug("PixiEditor.Debug.DeleteEditorData", @"%localappdata%\PixiEditor\editor_data.json", "DELETE_EDITOR_DATA", "DELETE_EDITOR_DATA",
+    [Command.Debug("PixiEditor.Debug.DeleteEditorData", @"%localappdata%/PixiEditor/editor_data.json", "DELETE_EDITOR_DATA", "DELETE_EDITOR_DATA",
         MenuItemPath = "DEBUG/DELETE/EDITOR_DATA", MenuItemOrder = 13, AnalyticsTrack = true)]
     public static async Task DeleteFile(string path)
     {
         if (MainWindow.Current is null)
             return;
+        string[] parts = path.Split('/');
+        path = Path.Combine(parts); // os specific path
         
         string file = Environment.ExpandEnvironmentVariables(path);
         if (!File.Exists(file))
         {
-            NoticeDialog.Show(new LocalizedString("File {0} does not exist\n(Full Path: {1})", path, file), "FILE_NOT_FOUND");
-            return;
+            file = Paths.ParseSpecialPathOrDefault(file);
+            if (!File.Exists(file))
+            {
+                NoticeDialog.Show(string.Format("File {0} does not exist\n(Full Path: {1})", path, file),
+                    "FILE_NOT_FOUND");
+                return;
+            }
         }
 
         OptionsDialog<string> dialog = new("ARE_YOU_SURE", new LocalizedString("ARE_YOU_SURE_PATH_FULL_PATH", path, file), MainWindow.Current)