Browse Source

Merge branch 'master' into supporter-pack

Krzysztof Krysiński 2 years ago
parent
commit
2ff7af6864

+ 28 - 2
src/PixiEditor/App.xaml.cs

@@ -6,6 +6,8 @@ using Microsoft.Extensions.DependencyInjection;
 using PixiEditor.Extensions;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Models.AppExtensions;
+using PixiEditor.Helpers.UI;
+using PixiEditor.Localization;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Dialogs;
@@ -46,10 +48,12 @@ internal partial class App : Application
             return;
         }
 
+        #if !STEAM
         if (!HandleNewInstance())
         {
             return;
         }
+        #endif
 
         AddNativeAssets();
 
@@ -90,6 +94,9 @@ internal partial class App : Application
 
         GC.KeepAlive(_mutex);
 
+        if (Current?.Dispatcher == null)
+            return true;
+
         if (isOwned)
         {
             var thread = new Thread(
@@ -107,7 +114,7 @@ internal partial class App : Application
                                     List<string> args = new List<string>();
                                     if (File.Exists(passedArgsFile))
                                     {
-                                        args = File.ReadAllText(passedArgsFile).Split(' ').ToList();
+                                        args = CommandLineHelpers.SplitCommandLine(File.ReadAllText(passedArgsFile)).ToList();
                                         File.Delete(passedArgsFile);
                                     }
                                     
@@ -128,7 +135,7 @@ internal partial class App : Application
         }
 
         // Notify other instance so it could bring itself to foreground.
-        File.WriteAllText(passedArgsFile, string.Join(' ', Environment.GetCommandLineArgs()));
+        File.WriteAllText(passedArgsFile, string.Join(' ', WrapSpaces(Environment.GetCommandLineArgs())));
         _eventWaitHandle.Set();
 
         // Terminate this instance.
@@ -136,6 +143,25 @@ internal partial class App : Application
         return false;
     }
 
+    private string?[] WrapSpaces(string[] args)
+    {
+        string?[] wrappedArgs = new string?[args.Length];
+        for (int i = 0; i < args.Length; i++)
+        {
+            string arg = args[i];
+            if (arg.Contains(' '))
+            {
+                wrappedArgs[i] = $"\"{arg}\"";
+            }
+            else
+            {
+                wrappedArgs[i] = arg;
+            }
+        }
+
+        return wrappedArgs;
+    }
+
     protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
     {
         base.OnSessionEnding(e);

+ 47 - 0
src/PixiEditor/Helpers/UI/CommandLineHelpers.cs

@@ -0,0 +1,47 @@
+namespace PixiEditor.Helpers.UI;
+
+public static class CommandLineHelpers
+{
+    public static IEnumerable<string> SplitCommandLine(string commandLine)
+    {
+        bool inQuotes = false;
+
+        return commandLine.Split(
+            c =>
+            {
+                if (c == '\"')
+                    inQuotes = !inQuotes;
+
+                return !inQuotes && c == ' ';
+            })
+            .Select(arg => arg.Trim().TrimMatchingQuotes('\"'))
+            .Where(arg => !string.IsNullOrEmpty(arg));
+    }
+
+    public static IEnumerable<string> Split(
+        this string str,
+        Func<char, bool> controller)
+    {
+        int nextPiece = 0;
+
+        for (int c = 0; c < str.Length; c++)
+        {
+            if (controller(str[c]))
+            {
+                yield return str.Substring(nextPiece, c - nextPiece);
+                nextPiece = c + 1;
+            }
+        }
+
+        yield return str.Substring(nextPiece);
+    }
+
+    public static string TrimMatchingQuotes(this string input, char quote)
+    {
+        if ((input.Length >= 2) &&
+            (input[0] == quote) && (input[^1] == quote))
+            return input.Substring(1, input.Length - 2);
+
+        return input;
+    }
+}

+ 2 - 2
src/PixiEditor/Properties/AssemblyInfo.cs

@@ -50,5 +50,5 @@ using System.Windows;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.1.0.0")]
-[assembly: AssemblyFileVersion("1.1.0.0")]
+[assembly: AssemblyVersion("1.1.3.0")]
+[assembly: AssemblyFileVersion("1.1.3.0")]

+ 1 - 28
src/PixiEditor/ViewModels/SubViewModels/Main/RegistryViewModel.cs

@@ -16,43 +16,16 @@ internal class RegistryViewModel : SubViewModel<ViewModelMain>
 
     private void OwnerOnStartupEvent(object sender, EventArgs e)
     {
+#if !STEAM // Something is wrong with Steam version of PixiEditor, so we disable this feature for now. Steam will have native association soon.
         // Check if lospec-palette is associated in registry
-
         if (!LospecPaletteIsAssociated())
         {
             // Associate lospec-palette URL protocol
             RegistryHelpers.TryAssociate(AssociateLospecPaletteInRegistry, "FAILED_ASSOCIATE_LOSPEC");
         }
-
-#if STEAM // Only associate .pixi file if it's a steam version, other versions handle it during installation
-        if(!PixiFileIsAssociated())
-        {
-            RegistryHelpers.TryAssociate(AssociatePixiFileInRegistry, "FAILED_ASSOCIATE_PIXI");
-        }
 #endif
     }
 
-    private bool PixiFileIsAssociated()
-    {
-        // Check if HKEY_CLASSES_ROOT\.pixi is present
-        return RegistryHelpers.IsKeyPresentInRoot(".pixi");
-    }
-
-    private void AssociatePixiFileInRegistry()
-    {
-        try
-        {
-            using RegistryKey key = Registry.ClassesRoot.CreateSubKey(".pixi");
-            key.SetValue("", "PixiEditor");
-
-            using RegistryKey shellKey = key.CreateSubKey("OpenWithProgids");
-        }
-        catch
-        {
-            NoticeDialog.Show("FAILED_ASSOCIATE_PIXI", "ERROR");
-        }
-    }
-
     private void AssociateLospecPaletteInRegistry()
     {
         try