Browse Source

Removed non-windows code from installer

Krzysztof Krysiński 2 months ago
parent
commit
f193fb46cd

+ 13 - 36
src/PixiEditor.UpdateInstaller.Exe/Program.cs

@@ -27,7 +27,8 @@ catch (Exception ex)
 {
 {
     log.AppendLine($"{DateTime.Now}: Error during update installation: {ex.Message}");
     log.AppendLine($"{DateTime.Now}: Error during update installation: {ex.Message}");
     string errorLogPath = Path.Combine(logDirectory, "ErrorLog.txt");
     string errorLogPath = Path.Combine(logDirectory, "ErrorLog.txt");
-    File.AppendAllText(errorLogPath, $"Error PixiEditor.UpdateInstaller: {DateTime.Now}\n{ex.Message}\n{ex.StackTrace}\n-----\n");
+    File.AppendAllText(errorLogPath,
+        $"Error PixiEditor.UpdateInstaller: {DateTime.Now}\n{ex.Message}\n{ex.StackTrace}\n-----\n");
 }
 }
 finally
 finally
 {
 {
@@ -36,32 +37,24 @@ finally
         if (startAfterUpdate)
         if (startAfterUpdate)
         {
         {
             log.AppendLine($"{DateTime.Now}: Starting PixiEditor after update.");
             log.AppendLine($"{DateTime.Now}: Starting PixiEditor after update.");
-            if (OperatingSystem.IsMacOS())
+            string binaryName = "PixiEditor.exe";
+            string path = Path.Join(controller.UpdateDirectory, binaryName);
+            if (File.Exists(path))
             {
             {
-                // Handled by elevator.sh script, I couldn't get Process.Start to work correctly under osascript environment
-                //StartPixiEditorOnMacOS(controller);
+                log.AppendLine($"{DateTime.Now}: Starting PixiEditor from {path}");
+                StartPixiEditor(path);
             }
             }
             else
             else
             {
             {
-                string binaryName = OperatingSystem.IsWindows() ? "PixiEditor.exe" : "PixiEditor";
-                string path = Path.Join(controller.UpdateDirectory, binaryName);
+                binaryName = "PixiEditor.Desktop.exe";
+                path = Path.Join(controller.UpdateDirectory, binaryName);
                 if (File.Exists(path))
                 if (File.Exists(path))
                 {
                 {
-                    log.AppendLine($"{DateTime.Now}: Starting PixiEditor from {path}");
                     StartPixiEditor(path);
                     StartPixiEditor(path);
                 }
                 }
                 else
                 else
                 {
                 {
-                    binaryName = OperatingSystem.IsWindows() ? "PixiEditor.Desktop.exe" : "PixiEditor.Desktop";
-                    path = Path.Join(controller.UpdateDirectory, binaryName);
-                    if (File.Exists(path))
-                    {
-                        StartPixiEditor(path);
-                    }
-                    else
-                    {
-                        log.AppendLine("PixiEditor executable not found.");
-                    }
+                    log.AppendLine("PixiEditor executable not found.");
                 }
                 }
             }
             }
         }
         }
@@ -70,7 +63,8 @@ finally
     {
     {
         log.AppendLine($"{DateTime.Now}: Error starting PixiEditor: {ex.Message}");
         log.AppendLine($"{DateTime.Now}: Error starting PixiEditor: {ex.Message}");
         string errorLogPath = Path.Combine(logDirectory, "ErrorLog.txt");
         string errorLogPath = Path.Combine(logDirectory, "ErrorLog.txt");
-        File.AppendAllText(errorLogPath, $"Error starting PixiEditor: {DateTime.Now}\n{ex.Message}\n{ex.StackTrace}\n-----\n");
+        File.AppendAllText(errorLogPath,
+            $"Error starting PixiEditor: {DateTime.Now}\n{ex.Message}\n{ex.StackTrace}\n-----\n");
     }
     }
 
 
     try
     try
@@ -85,24 +79,7 @@ finally
 
 
     void StartPixiEditor(string pixiEditorExecutablePath)
     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.");
-        }
+        Process.Start(new ProcessStartInfo(pixiEditorExecutablePath) { UseShellExecute = true });
     }
     }
 }
 }
 
 

+ 1 - 2
src/PixiEditor.UpdateInstaller/PixiEditor.UpdateInstaller/ViewModels/UpdateController.cs

@@ -44,8 +44,7 @@ public class UpdateController
 
 
     public void InstallUpdate(StringBuilder log)
     public void InstallUpdate(StringBuilder log)
     {
     {
-        string extension = OperatingSystem.IsLinux() ? "tar.gz" : ".zip";
-        string[] files = Directory.GetFiles(UpdateDownloader.DownloadLocation, $"update-*{extension}");
+        string[] files = Directory.GetFiles(UpdateDownloader.DownloadLocation, $"update-*.zip");
         log.AppendLine($"Found {files.Length} update files.");
         log.AppendLine($"Found {files.Length} update files.");
 
 
         if (files.Length > 0)
         if (files.Length > 0)

+ 4 - 47
src/PixiEditor.UpdateModule/UpdateInstaller.cs

@@ -59,58 +59,15 @@ public class UpdateInstaller
 
 
         Directory.CreateDirectory(UpdateFilesPath);
         Directory.CreateDirectory(UpdateFilesPath);
 
 
-        bool isZip = ArchiveFileName.EndsWith(".zip");
-        if (isZip)
-        {
-            log.AppendLine($"Extracting {ArchiveFileName} to {UpdateFilesPath}");
-            ZipFile.ExtractToDirectory(ArchiveFileName, UpdateFilesPath, true);
-        }
-        else
-        {
-            log.AppendLine($"Extracting {ArchiveFileName} to {UpdateFilesPath} using GZipStream");
-            using FileStream fs = new(ArchiveFileName, FileMode.Open, FileAccess.Read);
-            using GZipStream gz = new(fs, CompressionMode.Decompress, leaveOpen: true);
-
-            TarFile.ExtractToDirectory(gz, UpdateFilesPath, overwriteFiles: true);
-        }
-
-        if (OperatingSystem.IsMacOS())
-        {
-            string appFile = Directory.GetDirectories(UpdateFilesPath, "*.app", SearchOption.TopDirectoryOnly)
-                .FirstOrDefault();
-            if (string.IsNullOrEmpty(appFile))
-            {
-                log.AppendLine("PixiEditor.app not found in the update files. Installation failed.");
-                string[] allFiles = Directory.GetFiles(UpdateFilesPath, "*.*", SearchOption.TopDirectoryOnly);
-                foreach (string file in allFiles)
-                {
-                    log.AppendLine($"Found file: {file}");
-                }
-
-                throw new FileNotFoundException("PixiEditor.app not found in the update files.");
-            }
-
-
-            log.AppendLine($"Moving {appFile} to {TargetDirectory}");
-            string targetAppDirectory = Path.Combine(TargetDirectory, "PixiEditor.app");
-            if (Directory.Exists(targetAppDirectory))
-            {
-                log.AppendLine($"Removing existing PixiEditor.app at {targetAppDirectory}");
-                Directory.Delete(targetAppDirectory, true);
-            }
-
-            Directory.Move(appFile, targetAppDirectory);
-
-            Cleanup(log);
-            return;
-        }
+        log.AppendLine($"Extracting {ArchiveFileName} to {UpdateFilesPath}");
+        ZipFile.ExtractToDirectory(ArchiveFileName, UpdateFilesPath, true);
 
 
         string[] extractedFiles = Directory.GetFiles(UpdateFilesPath, "*", SearchOption.AllDirectories);
         string[] extractedFiles = Directory.GetFiles(UpdateFilesPath, "*", SearchOption.AllDirectories);
         log.AppendLine($"Extracted {extractedFiles.Length} files to {UpdateFilesPath}");
         log.AppendLine($"Extracted {extractedFiles.Length} files to {UpdateFilesPath}");
         log.AppendLine("Files extracted");
         log.AppendLine("Files extracted");
 
 
         string dirWithFiles = UpdateFilesPath;
         string dirWithFiles = UpdateFilesPath;
-        string binName = OperatingSystem.IsWindows() ? "PixiEditor.exe" : "PixiEditor";
+        string binName = "PixiEditor.exe";
         if (!File.Exists(Path.Combine(UpdateFilesPath, binName)))
         if (!File.Exists(Path.Combine(UpdateFilesPath, binName)))
         {
         {
             dirWithFiles = Directory.GetDirectories(UpdateFilesPath)[0];
             dirWithFiles = Directory.GetDirectories(UpdateFilesPath)[0];
@@ -155,7 +112,7 @@ public class UpdateInstaller
         }
         }
 
 
         string updateInstallerFile = Path.Join(Path.GetTempPath(), "PixiEditor",
         string updateInstallerFile = Path.Join(Path.GetTempPath(), "PixiEditor",
-            "PixiEditor.UpdateInstaller" + (OperatingSystem.IsWindows() ? ".exe" : ""));
+            "PixiEditor.UpdateInstaller.exe");
         logger.AppendLine($"Looking for: {updateInstallerFile}");
         logger.AppendLine($"Looking for: {updateInstallerFile}");
         if (File.Exists(updateInstallerFile))
         if (File.Exists(updateInstallerFile))
         {
         {