This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
forked from imchillin/Anamnesis
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update extractor target net5 for the initial 5-> 6 update
- Loading branch information
1 parent
6b9f76a
commit 5f72c59
Showing
2 changed files
with
105 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,138 @@ | ||
// © Anamnesis. | ||
// Licensed under the MIT license. | ||
|
||
namespace UpdateExtractor; | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading; | ||
|
||
public class Program | ||
namespace UpdateExtractor | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
string processName = "Unknown"; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading; | ||
|
||
try | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
if (args.Length != 2) | ||
throw new Exception("Invalid arguments. Update Extractor must be run with the following arguments: 1) destination directory, 2) name of orignal process."); | ||
|
||
string? destDir = args[0]; | ||
processName = args[1]; | ||
Console.WriteLine($"{processName} Updater"); | ||
string processName = "Unknown"; | ||
|
||
Console.Write($"Waiting for {processName} to terminate"); | ||
while (true) | ||
try | ||
{ | ||
Process[] procs = Process.GetProcessesByName(processName); | ||
if (procs.Length <= 0) | ||
{ | ||
break; | ||
} | ||
else | ||
{ | ||
Thread.Sleep(100); | ||
Console.Write("."); | ||
} | ||
} | ||
if (args.Length != 2) | ||
throw new Exception("Invalid arguments. Update Extractor must be run with the following arguments: 1) destination directory, 2) name of orignal process."); | ||
|
||
Console.WriteLine(" done."); | ||
string? destDir = args[0]; | ||
processName = args[1]; | ||
Console.WriteLine($"{processName} Updater"); | ||
|
||
string sourceDir = Path.GetTempPath() + "/AnamnesisUpdateLatest/"; | ||
Console.Write($"Waiting for {processName} to terminate"); | ||
while (true) | ||
{ | ||
Process[] procs = Process.GetProcessesByName(processName); | ||
if (procs.Length <= 0) | ||
{ | ||
break; | ||
} | ||
else | ||
{ | ||
Thread.Sleep(100); | ||
Console.Write("."); | ||
} | ||
} | ||
|
||
if (!Directory.Exists(sourceDir)) | ||
throw new Exception("Unable to determine current process path"); | ||
Console.WriteLine(" done."); | ||
|
||
if (string.IsNullOrEmpty(sourceDir)) | ||
throw new Exception("Unable to determine source directory"); | ||
string sourceDir = Path.GetTempPath() + "/AnamnesisUpdateLatest/"; | ||
|
||
if (string.IsNullOrEmpty(destDir)) | ||
throw new Exception("Unable to determine destination directory"); | ||
if (!Directory.Exists(sourceDir)) | ||
throw new Exception("Unable to determine current process path"); | ||
|
||
// Is destDir actually a file path, get a directory instead. | ||
if (File.Exists(destDir)) | ||
{ | ||
destDir = Path.GetDirectoryName(destDir); | ||
if (string.IsNullOrEmpty(sourceDir)) | ||
throw new Exception("Unable to determine source directory"); | ||
|
||
if (string.IsNullOrEmpty(destDir)) | ||
{ | ||
throw new Exception("Unable to determine destination directory"); | ||
|
||
// Is destDir actually a file path, get a directory instead. | ||
if (File.Exists(destDir)) | ||
{ | ||
destDir = Path.GetDirectoryName(destDir); | ||
|
||
if (string.IsNullOrEmpty(destDir)) | ||
{ | ||
throw new Exception("Unable to determine destination directory"); | ||
} | ||
} | ||
} | ||
|
||
destDir = destDir.Replace('/', '\\'); | ||
destDir = destDir.Trim('\\'); | ||
destDir += "\\"; | ||
destDir = destDir.Replace('/', '\\'); | ||
destDir = destDir.Trim('\\'); | ||
destDir += "\\"; | ||
|
||
string oldExe = destDir + "Anamnesis.exe"; | ||
string oldExe = destDir + "Anamnesis.exe"; | ||
|
||
if (!File.Exists(oldExe)) | ||
throw new Exception($"No Anamnesis executable found at: {oldExe}"); | ||
if (!File.Exists(oldExe)) | ||
throw new Exception($"No Anamnesis executable found at: {oldExe}"); | ||
|
||
Console.WriteLine("Cleaning old version"); | ||
DeleteFileIfExists(destDir + "Anamnesis.exe"); | ||
DeleteFileIfExists(destDir + "AnamnesisLauncher.exe"); | ||
DeleteFileIfExists(destDir + "Anamnesis.pdb"); | ||
DeleteFileIfExists(destDir + "Anamnesis.xml"); | ||
DeleteFileIfExists(destDir + "Version.txt"); | ||
Console.WriteLine("Cleaning old version"); | ||
DeleteFileIfExists(destDir + "Anamnesis.exe"); | ||
DeleteFileIfExists(destDir + "AnamnesisLauncher.exe"); | ||
DeleteFileIfExists(destDir + "Anamnesis.pdb"); | ||
DeleteFileIfExists(destDir + "Anamnesis.xml"); | ||
DeleteFileIfExists(destDir + "Version.txt"); | ||
|
||
DeleteDirectoryIfExists(destDir + "Data"); | ||
DeleteDirectoryIfExists(destDir + "Languages"); | ||
DeleteDirectoryIfExists(destDir + "Updater"); | ||
DeleteDirectoryIfExists(destDir + "bin"); | ||
DeleteDirectoryIfExists(destDir + "Data"); | ||
DeleteDirectoryIfExists(destDir + "Languages"); | ||
DeleteDirectoryIfExists(destDir + "Updater"); | ||
DeleteDirectoryIfExists(destDir + "bin"); | ||
|
||
Console.WriteLine("Copying Update Files"); | ||
Console.WriteLine("Copying Update Files"); | ||
|
||
string[] files = Directory.GetFiles(sourceDir, "*.*", SearchOption.AllDirectories); | ||
foreach (string sourceFile in files) | ||
{ | ||
string destFile = sourceFile.Replace(sourceDir, destDir); | ||
Console.WriteLine(" > " + destFile); | ||
string[] files = Directory.GetFiles(sourceDir, "*.*", SearchOption.AllDirectories); | ||
foreach (string sourceFile in files) | ||
{ | ||
string destFile = sourceFile.Replace(sourceDir, destDir); | ||
Console.WriteLine(" > " + destFile); | ||
|
||
string? directory = Path.GetDirectoryName(destFile); | ||
if (directory != null && !Directory.Exists(directory)) | ||
Directory.CreateDirectory(directory); | ||
string? directory = Path.GetDirectoryName(destFile); | ||
if (directory != null && !Directory.Exists(directory)) | ||
Directory.CreateDirectory(directory); | ||
|
||
File.Copy(sourceFile, destFile, true); | ||
} | ||
File.Copy(sourceFile, destFile, true); | ||
} | ||
|
||
Console.WriteLine("Restarting application"); | ||
Console.WriteLine("Restarting application"); | ||
|
||
string launch = destDir + "AnamnesisSetup.exe"; | ||
Console.WriteLine(" > " + launch); | ||
ProcessStartInfo start = new ProcessStartInfo(launch); | ||
Process.Start(start); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine($"Failed to update {processName}"); | ||
Console.WriteLine(ex.Message); | ||
Console.WriteLine(); | ||
Console.WriteLine("Please download the update manually."); | ||
Console.WriteLine(); | ||
Console.WriteLine("Press any key to close this window."); | ||
Console.ReadKey(); | ||
string launch = destDir + "AnamnesisSetup.exe"; | ||
Console.WriteLine(" > " + launch); | ||
ProcessStartInfo start = new ProcessStartInfo(launch); | ||
Process.Start(start); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine($"Failed to update {processName}"); | ||
Console.WriteLine(ex.Message); | ||
Console.WriteLine(); | ||
Console.WriteLine("Please download the update manually."); | ||
Console.WriteLine(); | ||
Console.WriteLine("Press any key to close this window."); | ||
Console.ReadKey(); | ||
} | ||
} | ||
} | ||
|
||
private static void DeleteFileIfExists(string path) | ||
{ | ||
if (!File.Exists(path)) | ||
return; | ||
private static void DeleteFileIfExists(string path) | ||
{ | ||
if (!File.Exists(path)) | ||
return; | ||
|
||
File.Delete(path); | ||
} | ||
File.Delete(path); | ||
} | ||
|
||
private static void DeleteDirectoryIfExists(string path) | ||
{ | ||
if (!Directory.Exists(path)) | ||
return; | ||
private static void DeleteDirectoryIfExists(string path) | ||
{ | ||
if (!Directory.Exists(path)) | ||
return; | ||
|
||
Directory.Delete(path, true); | ||
Directory.Delete(path, true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters