Forráskód Böngészése

Linux autoupdate improvements

flabbet 3 hónapja
szülő
commit
91d76134dc

+ 29 - 8
src/PixiEditor.UpdateInstaller.Exe/Program.cs

@@ -41,20 +41,19 @@ finally
         else
         {
             string binaryName = OperatingSystem.IsWindows() ? "PixiEditor.exe" : "PixiEditor";
-            var files = Directory.GetFiles(controller.UpdateDirectory, binaryName);
-            if (files.Length > 0)
+            string path = Path.Join(controller.UpdateDirectory, binaryName);
+            if (File.Exists(path))
             {
-                string pixiEditorExecutablePath = files[0];
-                Process.Start(pixiEditorExecutablePath);
+                log.AppendLine($"{DateTime.Now}: Starting PixiEditor from {path}");
+                StartPixiEditor(path);
             }
             else
             {
                 binaryName = OperatingSystem.IsWindows() ? "PixiEditor.Desktop.exe" : "PixiEditor.Desktop";
-                files = Directory.GetFiles(controller.UpdateDirectory, binaryName);
-                if (files.Length > 0)
+                path = Path.Join(controller.UpdateDirectory, binaryName);
+                if (File.Exists(path))
                 {
-                    string pixiEditorExecutablePath = files[0];
-                    Process.Start(pixiEditorExecutablePath);
+                    StartPixiEditor(path);
                 }
                 else
                 {
@@ -73,6 +72,28 @@ finally
     {
         // probably permissions or disk full, the best we can do is to ignore this
     }
+
+    void StartPixiEditor(string pixiEditorExecutablePath)
+    {
+        if (OperatingSystem.IsWindows())
+        {
+            Process.Start(new ProcessStartInfo(pixiEditorExecutablePath) { UseShellExecute = true });
+        }
+        else if (OperatingSystem.IsLinux())
+        {
+            string display = Environment.GetEnvironmentVariable("DISPLAY");
+            Process.Start(new ProcessStartInfo
+            {
+                FileName = "/bin/bash",
+                Arguments = "-c \"DISPLAY=" + display + " " + pixiEditorExecutablePath + "\" & disown",
+                UseShellExecute = false,
+            });
+        }
+        else
+        {
+            log.AppendLine($"{DateTime.Now}: Unsupported operating system for starting PixiEditor.");
+        }
+    }
 }
 
 void StartPixiEditorOnMacOS(UpdateController controller)

+ 14 - 3
src/PixiEditor.UpdateInstaller/PixiEditor.UpdateInstaller/ViewModels/UpdateController.cs

@@ -17,10 +17,21 @@ public class UpdateController
         {
             updateDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
         }
+        else
+        {
+            string infoPath = Path.Join(Path.GetTempPath(), "PixiEditor", "update-location.txt");
+            if (File.Exists(infoPath))
+            {
+                try
+                {
+                    updateDirectory = File.ReadAllText(infoPath);
+                }
+                catch (Exception ex)
+                {
+                }
+            }
+        }
 
-#if DEBUG
-        updateDirectory = Path.GetDirectoryName(Environment.GetCommandLineArgs().FirstOrDefault());
-#endif
         UpdateDirectory = updateDirectory;
     }
 

+ 27 - 3
src/PixiEditor.UpdateModule/UpdateInstaller.cs

@@ -98,7 +98,7 @@ public class UpdateInstaller
             }
             Directory.Move(appFile, targetAppDirectory);
             
-            DeleteArchive();
+            Cleanup();
             return;
         }
 
@@ -129,13 +129,37 @@ public class UpdateInstaller
         log.AppendLine("Files copied");
         log.AppendLine("Deleting archive and update files");
         
-        DeleteArchive();
+        Cleanup();
     }
 
-    private void DeleteArchive()
+    private void Cleanup()
     {
         File.Delete(ArchiveFileName);
         Directory.Delete(UpdateFilesPath, true);
+        string updateLocationFile = Path.Join(Path.GetTempPath(), "PixiEditor", "update-location.txt");
+        if (File.Exists(updateLocationFile))
+        {
+            try
+            {
+                File.Delete(updateLocationFile);
+            }
+            catch (Exception ex)
+            {
+            }
+        }
+        
+        string updateInstallerFile = Path.Join(Path.GetTempPath(), "PixiEditor", "PixiEditor.UpdateInstaller" + (OperatingSystem.IsWindows() ? ".exe" : ""));
+        if (File.Exists(updateInstallerFile))
+        {
+            try
+            {
+                File.Delete(updateInstallerFile);
+            }
+            catch (Exception ex)
+            {
+                // Ignore errors during cleanup
+            }
+        }
     }
 
     private void CopyFilesToDestination(string sourceDirectory, StringBuilder log)

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

@@ -43,5 +43,5 @@ using System.Runtime.InteropServices;
 // 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("2.0.0.89")]
-[assembly: AssemblyFileVersion("2.0.0.89")]
+[assembly: AssemblyVersion("2.0.0.90")]
+[assembly: AssemblyFileVersion("2.0.0.90")]

+ 12 - 0
src/PixiEditor/ViewModels/SubViewModels/UpdateViewModel.cs

@@ -3,6 +3,7 @@ using System.ComponentModel;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using Avalonia;
@@ -166,6 +167,16 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
             return;
         }
 
+        if (updateAvailable)
+        {
+            if (!IOperatingSystem.Current.IsWindows && UpdateChecker.LatestReleaseInfo.TagName.StartsWith("1."))
+            {
+                // 1.0 is windows only
+                UpdateState = UpdateState.UpToDate;
+                return;
+            }
+        }
+
         UpdateState = updateAvailable ? UpdateState.UpdateAvailable : UpdateState.UpToDate;
     }
 
@@ -288,6 +299,7 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
         {
             File.Copy(updaterPath, Path.Join(UpdateDownloader.DownloadLocation, $"PixiEditor.UpdateInstaller"), true);
             updaterPath = Path.Join(UpdateDownloader.DownloadLocation, $"PixiEditor.UpdateInstaller");
+            File.WriteAllText(Path.Join(UpdateDownloader.DownloadLocation, "update-location.txt"), Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty);
         }
 
         if (updateFileExists && File.Exists(updaterPath))