- Do not check versions when switching streams.
- Manually restore execute bit on Unix. - Use full paths everywhere instead of relying on current working directory. - Less early returns on update operations. - Formatting.master
parent
6a15c0ddb8
commit
0f00baae39
|
@ -24,7 +24,7 @@ namespace DotN64.Desktop
|
|||
}
|
||||
}
|
||||
|
||||
public static string ReleaseStream { get; } = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyReleaseStreamAttribute>().Stream;
|
||||
public static string ReleaseStream => Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyReleaseStreamAttribute>().Stream;
|
||||
|
||||
public static Uri Website { get; } = new Uri("https://nabile.duckdns.org/DotN64");
|
||||
#endregion
|
||||
|
@ -32,7 +32,6 @@ namespace DotN64.Desktop
|
|||
#region Methods
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
var options = new Options();
|
||||
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
|
@ -65,16 +64,19 @@ namespace DotN64.Desktop
|
|||
return;
|
||||
case "stream":
|
||||
case "s":
|
||||
Update(args[++i]);
|
||||
return;
|
||||
arg = args[++i];
|
||||
|
||||
Update(arg, arg != ReleaseStream);
|
||||
break;
|
||||
default:
|
||||
Update();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "--repair":
|
||||
case "-r":
|
||||
Repair();
|
||||
return;
|
||||
break;
|
||||
case "--help":
|
||||
case "-h":
|
||||
ShowHelp();
|
||||
|
@ -93,6 +95,8 @@ namespace DotN64.Desktop
|
|||
|
||||
private static bool Check(string releaseStream = null)
|
||||
{
|
||||
Console.Write("Checking for updates... ");
|
||||
|
||||
var newVersion = Updater.Check(releaseStream);
|
||||
|
||||
if (newVersion == null)
|
||||
|
@ -148,23 +152,24 @@ namespace DotN64.Desktop
|
|||
var version = assembly.GetName().Version;
|
||||
var description = assembly.GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
|
||||
|
||||
Console.WriteLine($"{title} v{version} ({BuildDate}){(description != null ? $": {description}" : string.Empty)} ({Website})");
|
||||
Console.WriteLine($"{title} v{version} ({BuildDate}){(description != null ? $": {description}" : string.Empty)}");
|
||||
Console.WriteLine(Website);
|
||||
}
|
||||
|
||||
private static void ShowHelp()
|
||||
{
|
||||
ShowInfo();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Usage: {Path.GetFileName(Assembly.GetEntryAssembly().Location)} [Options] <ROM image>");
|
||||
Console.WriteLine($"Usage: {Path.GetFileName(Assembly.GetEntryAssembly().Location)} [Options] [ROM image]");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("ROM image: Opens the file as a game cartridge.");
|
||||
Console.WriteLine("Options:");
|
||||
Console.WriteLine("\t--pif-rom <path>: Loads the PIF's boot ROM into the machine.");
|
||||
Console.WriteLine("\t-d, --debug: Launches the debugger for the Nintendo 64's CPU.");
|
||||
Console.WriteLine("\t-u, --update [action]: Updates the program.");
|
||||
Console.WriteLine("\t[action = 'check', 'c']: Checks for a new update.");
|
||||
Console.WriteLine("\t[action = 'list', 'l']: Lists the release streams available for download.");
|
||||
Console.WriteLine("\t[action = 'stream', 's'] <stream>: Downloads an update from the specified release stream.");
|
||||
Console.WriteLine("\t\t[action = 'check', 'c']: Checks for a new update.");
|
||||
Console.WriteLine("\t\t[action = 'list', 'l']: Lists the release streams available for download.");
|
||||
Console.WriteLine("\t\t[action = 'stream', 's'] <stream>: Downloads an update from the specified release stream.");
|
||||
Console.WriteLine("\t-r, --repair: Repairs the installation by redownloading the full program.");
|
||||
Console.WriteLine("\t-h, --help: Shows this help.");
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace DotN64.Desktop
|
|||
using (var client = new WebClient())
|
||||
{
|
||||
var remoteVersion = new Version(client.DownloadString(new Uri(Program.Website, $"{ProjectName}/Download/{releaseStream}/version")));
|
||||
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
var currentVersion = Assembly.GetEntryAssembly().GetName().Version;
|
||||
|
||||
return remoteVersion > currentVersion ? remoteVersion : null;
|
||||
}
|
||||
|
@ -97,19 +97,24 @@ namespace DotN64.Desktop
|
|||
{
|
||||
var updateDirectory = new DirectoryInfo(Path.Combine(InstallDirectory, StagingDirectory));
|
||||
var executableName = Path.GetFileName(Assembly.GetEntryAssembly().Location);
|
||||
var isWindow = Environment.OSVersion.Platform == PlatformID.Win32NT;
|
||||
var shouldRestart = false;
|
||||
var platform = Environment.OSVersion.Platform;
|
||||
|
||||
foreach (var file in updateDirectory.GetFiles())
|
||||
{
|
||||
var destination = Path.Combine(InstallDirectory, file.Name);
|
||||
|
||||
if (isWindow && file.Name == executableName)
|
||||
if (file.Name == executableName)
|
||||
{
|
||||
file.MoveTo(destination + NewFileExtension);
|
||||
|
||||
shouldRestart = true;
|
||||
continue;
|
||||
switch (platform)
|
||||
{
|
||||
case PlatformID.Unix:
|
||||
case PlatformID.MacOSX:
|
||||
Process.Start(new ProcessStartInfo("chmod", $"+x {file.FullName}")).WaitForExit(); // ZipArchive does not preserve permission bits, so we fix it.
|
||||
break;
|
||||
case PlatformID.Win32NT:
|
||||
file.MoveTo(destination + NewFileExtension);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
File.Delete(destination);
|
||||
|
@ -118,14 +123,14 @@ namespace DotN64.Desktop
|
|||
|
||||
updateDirectory.Delete(true);
|
||||
|
||||
if (isWindow && shouldRestart)
|
||||
if (platform == PlatformID.Win32NT)
|
||||
ApplyWindowsUpdate(executableName);
|
||||
}
|
||||
|
||||
private static void ApplyWindowsUpdate(string executableName)
|
||||
{
|
||||
var newExecutableName = executableName + NewFileExtension;
|
||||
var scriptFile = new FileInfo("CompleteUpdate.cmd");
|
||||
var scriptFile = new FileInfo(Path.Combine(InstallDirectory, "CompleteUpdate.cmd"));
|
||||
var processID = Process.GetCurrentProcess().Id;
|
||||
|
||||
using (var writer = scriptFile.CreateText())
|
||||
|
@ -149,7 +154,8 @@ namespace DotN64.Desktop
|
|||
Process.Start(new ProcessStartInfo(scriptFile.FullName)
|
||||
{
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
CreateNoWindow = true,
|
||||
WorkingDirectory = InstallDirectory
|
||||
});
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue