Skip to content

Commit

Permalink
Copy AutoUpdater to temporary folder for updating so users can get ne…
Browse files Browse the repository at this point in the history
…wer versions of the updater
  • Loading branch information
Soapwood committed Jul 1, 2024
1 parent e998ff7 commit f171abb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
15 changes: 14 additions & 1 deletion VXAutoUpdater/Core/VXMusicAutoUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand Down Expand Up @@ -37,7 +38,7 @@ public VXMusicAutoUpdater(string repositoryOwner, string repositoryName, string
_repositoryName = repositoryName;
_personalAccessToken = personalAccessToken;

AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VXMusic", "AutoUpdater");
AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VXMusic", "AutoUpdater");
if (!Path.Exists(AppDataPath))
Directory.CreateDirectory(AppDataPath);

Expand Down Expand Up @@ -329,4 +330,16 @@ private void DirectoryCopy(string sourceDirName, string destDirName, bool copySu
}
}
}

static void ScheduleSelfDelete(string filePath)
{
ProcessStartInfo info = new ProcessStartInfo
{
Arguments = $"/C choice /C Y /N /D Y /T 3 & Del \"{filePath}\"",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "cmd.exe"
};
Process.Start(info);
}
}
28 changes: 25 additions & 3 deletions VXMusicDesktop/Update/VXMusicUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ public async Task<bool> CheckForUpdates(string currentVersion)

public static async Task LaunchVXMusicUpdater()
{
string currentDirectory = Directory.GetCurrentDirectory();
string executableName = "VXAutoUpdater.exe"; // Replace with your executable's name
string executablePath = Path.Combine(currentDirectory, "VXAutoUpdater", executableName);
// Prepare AppData folder for temporary copy of VXAutoUpdater
string autoUpdaterPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "VXMusic", "VXAutoUpdater");
string temporaryFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VXMusic", "AutoUpdaterTemp");
// TODO x86 AAAAAAAAAAAAA
CopyDirectory(autoUpdaterPath, temporaryFolder);

string executablePath = Path.Combine(temporaryFolder, "VXAutoUpdater.exe");

try
{
Expand All @@ -90,4 +94,22 @@ public static async Task LaunchVXMusicUpdater()

Environment.Exit(0); // Exit the current application
}

private static void CopyDirectory(string sourceDir, string destDir)
{
if (!Directory.Exists(destDir))
Directory.CreateDirectory(destDir);

foreach (string filePath in Directory.GetFiles(sourceDir))
{
string destFilePath = Path.Combine(destDir, Path.GetFileName(filePath));
File.Copy(filePath, destFilePath, true);
}

foreach (string directoryPath in Directory.GetDirectories(sourceDir))
{
string destDirPath = Path.Combine(destDir, Path.GetFileName(directoryPath));
CopyDirectory(directoryPath, destDirPath);
}
}
}

0 comments on commit f171abb

Please sign in to comment.