|
@@ -3,6 +3,7 @@ using System.Diagnostics;
|
|
using System.Formats.Tar;
|
|
using System.Formats.Tar;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.IO.Compression;
|
|
|
|
+using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
|
|
namespace PixiEditor.UpdateModule;
|
|
namespace PixiEditor.UpdateModule;
|
|
@@ -17,7 +18,8 @@ public class UpdateInstaller
|
|
TargetDirectory = targetDirectory;
|
|
TargetDirectory = targetDirectory;
|
|
}
|
|
}
|
|
|
|
|
|
- public static string UpdateFilesPath { get; set; } = Path.Join(UpdateDownloader.DownloadLocation, TargetDirectoryName);
|
|
|
|
|
|
+ public static string UpdateFilesPath { get; set; } =
|
|
|
|
+ Path.Join(UpdateDownloader.DownloadLocation, TargetDirectoryName);
|
|
|
|
|
|
public string ArchiveFileName { get; set; }
|
|
public string ArchiveFileName { get; set; }
|
|
|
|
|
|
@@ -26,34 +28,81 @@ public class UpdateInstaller
|
|
public void Install(StringBuilder log)
|
|
public void Install(StringBuilder log)
|
|
{
|
|
{
|
|
var processes = Process.GetProcessesByName("PixiEditor.Desktop");
|
|
var processes = Process.GetProcessesByName("PixiEditor.Desktop");
|
|
|
|
+ processes = processes.Concat(Process.GetProcessesByName("PixiEditor")).ToArray();
|
|
log.AppendLine($"Found {processes.Length} PixiEditor processes running.");
|
|
log.AppendLine($"Found {processes.Length} PixiEditor processes running.");
|
|
if (processes.Length > 0)
|
|
if (processes.Length > 0)
|
|
{
|
|
{
|
|
log.AppendLine("Killing PixiEditor processes...");
|
|
log.AppendLine("Killing PixiEditor processes...");
|
|
- processes[0].WaitForExit();
|
|
|
|
|
|
+ foreach (var process in processes)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ log.AppendLine($"Killing process {process.ProcessName} with ID {process.Id}");
|
|
|
|
+ process.Kill();
|
|
|
|
+ process.WaitForExit();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ log.AppendLine($"Failed to kill process {process.ProcessName} with ID {process.Id}: {ex.Message}");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
log.AppendLine("Processes killed.");
|
|
log.AppendLine("Processes killed.");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
log.AppendLine("Extracting files");
|
|
log.AppendLine("Extracting files");
|
|
-
|
|
|
|
- if(Directory.Exists(UpdateFilesPath))
|
|
|
|
|
|
+
|
|
|
|
+ if (Directory.Exists(UpdateFilesPath))
|
|
{
|
|
{
|
|
Directory.Delete(UpdateFilesPath, true);
|
|
Directory.Delete(UpdateFilesPath, true);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Directory.CreateDirectory(UpdateFilesPath);
|
|
Directory.CreateDirectory(UpdateFilesPath);
|
|
-
|
|
|
|
|
|
+
|
|
bool isZip = ArchiveFileName.EndsWith(".zip");
|
|
bool isZip = ArchiveFileName.EndsWith(".zip");
|
|
if (isZip)
|
|
if (isZip)
|
|
{
|
|
{
|
|
|
|
+ log.AppendLine($"Extracting {ArchiveFileName} to {UpdateFilesPath}");
|
|
ZipFile.ExtractToDirectory(ArchiveFileName, UpdateFilesPath, true);
|
|
ZipFile.ExtractToDirectory(ArchiveFileName, UpdateFilesPath, true);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+ log.AppendLine($"Extracting {ArchiveFileName} to {UpdateFilesPath} using GZipStream");
|
|
using FileStream fs = new(ArchiveFileName, FileMode.Open, FileAccess.Read);
|
|
using FileStream fs = new(ArchiveFileName, FileMode.Open, FileAccess.Read);
|
|
using GZipStream gz = new(fs, CompressionMode.Decompress, leaveOpen: true);
|
|
using GZipStream gz = new(fs, CompressionMode.Decompress, leaveOpen: true);
|
|
|
|
|
|
- TarFile.ExtractToDirectory(gz, UpdateFilesPath, overwriteFiles: false);
|
|
|
|
|
|
+ TarFile.ExtractToDirectory(gz, UpdateFilesPath, overwriteFiles: true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (OperatingSystem.IsMacOS())
|
|
|
|
+ {
|
|
|
|
+ string appFile = Directory.GetDirectories(UpdateFilesPath, "PixiEditor.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;
|
|
}
|
|
}
|
|
|
|
|
|
string[] extractedFiles = Directory.GetFiles(UpdateFilesPath, "*", SearchOption.AllDirectories);
|
|
string[] extractedFiles = Directory.GetFiles(UpdateFilesPath, "*", SearchOption.AllDirectories);
|
|
@@ -66,16 +115,7 @@ public class UpdateInstaller
|
|
{
|
|
{
|
|
dirWithFiles = Directory.GetDirectories(UpdateFilesPath)[0];
|
|
dirWithFiles = Directory.GetDirectories(UpdateFilesPath)[0];
|
|
}
|
|
}
|
|
-
|
|
|
|
- string updaterFile = Path.Combine(dirWithFiles, "PixiEditor.UpdateInstaller" + (OperatingSystem.IsWindows() ? ".exe" : ""));
|
|
|
|
|
|
|
|
- if (File.Exists(updaterFile))
|
|
|
|
- {
|
|
|
|
- string newName = Path.Combine(dirWithFiles, "PixiEditor.UpdateInstaller-update" + (OperatingSystem.IsWindows() ? ".exe" : ""));
|
|
|
|
- File.Move(updaterFile, newName);
|
|
|
|
- log.AppendLine($"Renamed {updaterFile} to {newName}");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
log.AppendLine($"Copying files from {dirWithFiles} to {TargetDirectory}");
|
|
log.AppendLine($"Copying files from {dirWithFiles} to {TargetDirectory}");
|
|
|
|
|
|
try
|
|
try
|
|
@@ -91,14 +131,44 @@ public class UpdateInstaller
|
|
|
|
|
|
log.AppendLine("Files copied");
|
|
log.AppendLine("Files copied");
|
|
log.AppendLine("Deleting archive and update files");
|
|
log.AppendLine("Deleting archive and update files");
|
|
-
|
|
|
|
- DeleteArchive();
|
|
|
|
|
|
+
|
|
|
|
+ Cleanup(log);
|
|
}
|
|
}
|
|
|
|
|
|
- private void DeleteArchive()
|
|
|
|
|
|
+ private void Cleanup(StringBuilder logger)
|
|
{
|
|
{
|
|
File.Delete(ArchiveFileName);
|
|
File.Delete(ArchiveFileName);
|
|
Directory.Delete(UpdateFilesPath, true);
|
|
Directory.Delete(UpdateFilesPath, true);
|
|
|
|
+ string updateLocationFile = Path.Join(Path.GetTempPath(), "PixiEditor", "update-location.txt");
|
|
|
|
+ logger.AppendLine($"Looking for: {updateLocationFile}");
|
|
|
|
+ if (File.Exists(updateLocationFile))
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ logger.AppendLine($"Deleting update location file: {updateLocationFile}");
|
|
|
|
+ File.Delete(updateLocationFile);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ logger.AppendLine($"Failed to delete update location file: {ex.Message}");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ string updateInstallerFile = Path.Join(Path.GetTempPath(), "PixiEditor",
|
|
|
|
+ "PixiEditor.UpdateInstaller" + (OperatingSystem.IsWindows() ? ".exe" : ""));
|
|
|
|
+ logger.AppendLine($"Looking for: {updateInstallerFile}");
|
|
|
|
+ if (File.Exists(updateInstallerFile))
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ logger.AppendLine($"Deleting update installer file: {updateInstallerFile}");
|
|
|
|
+ File.Delete(updateInstallerFile);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ logger.AppendLine($"Failed to delete update installer file: {ex.Message}");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void CopyFilesToDestination(string sourceDirectory, StringBuilder log)
|
|
private void CopyFilesToDestination(string sourceDirectory, StringBuilder log)
|
|
@@ -123,12 +193,12 @@ public class UpdateInstaller
|
|
{
|
|
{
|
|
string[] subDirs = Directory.GetDirectories(originDirectory);
|
|
string[] subDirs = Directory.GetDirectories(originDirectory);
|
|
log.AppendLine($"Found {subDirs.Length} subdirectories to copy.");
|
|
log.AppendLine($"Found {subDirs.Length} subdirectories to copy.");
|
|
- if(subDirs.Length == 0) return;
|
|
|
|
|
|
+ if (subDirs.Length == 0) return;
|
|
|
|
|
|
foreach (string subDir in subDirs)
|
|
foreach (string subDir in subDirs)
|
|
{
|
|
{
|
|
string targetDirPath = Path.Join(targetDirectory, Path.GetFileName(subDir));
|
|
string targetDirPath = Path.Join(targetDirectory, Path.GetFileName(subDir));
|
|
-
|
|
|
|
|
|
+
|
|
log.AppendLine($"Copying {subDir} to {targetDirPath}");
|
|
log.AppendLine($"Copying {subDir} to {targetDirPath}");
|
|
|
|
|
|
CopySubDirectories(subDir, targetDirPath, log);
|
|
CopySubDirectories(subDir, targetDirPath, log);
|