Skip to content

Commit

Permalink
MAKE UPDATER GREAT AGAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Mar 18, 2019
1 parent 0a12763 commit 0753d21
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ReOsuStoryboardPlayer/MainProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ private static Parameters ParseProgramCommands(string[] argv, out string beatmap
Exit("");
}

if (args.TryGetSwitch("program_update"))
if (args.TryGetArg("program_update",out var update_dest_path))
{
int id = 0;
var x = int.TryParse(args.FreeArgs.FirstOrDefault(), out id);

ProgramUpdater.ApplyUpdate(x ? id : 0);
ProgramUpdater.ApplyUpdate(x ? id : 0, update_dest_path);
}

if (args.FreeArgs!=null)
Expand Down
4 changes: 2 additions & 2 deletions ReOsuStoryboardPlayer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.4.0.0")]
[assembly: AssemblyFileVersion("2.4.0.0")]
[assembly: AssemblyVersion("2.4.1.0")]
[assembly: AssemblyFileVersion("2.4.1.0")]
36 changes: 25 additions & 11 deletions ReOsuStoryboardPlayer/Utils/ProgramUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.IO.Compression;
using System.Diagnostics;
using System.Threading;
using ReOsuStoryboardPlayer.ProgramCommandParser;

namespace ReOsuStoryboardPlayer.Utils
{
Expand All @@ -32,6 +33,9 @@ public static async void UpdateCheck()
{
try
{
if (Directory.Exists(TEMP_DIR_NAME))
Directory.Delete(TEMP_DIR_NAME);

var asm = Assembly.GetExecutingAssembly();
var program_version = asm.GetName().Version;

Expand Down Expand Up @@ -107,21 +111,24 @@ await Task.Run(() =>
archive.ExtractToDirectory(TEMP_DIR_NAME);
}

var exe_file = Directory.EnumerateFiles(TEMP_DIR_NAME, EXE_NAME).First();
var exe_file_path = Directory.EnumerateFiles(TEMP_DIR_NAME, EXE_NAME,SearchOption.AllDirectories).FirstOrDefault();
var exe_path = Path.GetDirectoryName(exe_file_path);

if (!File.Exists(exe_file))
if (!File.Exists(exe_file_path))
{
Log.Error($"Can't find the exe file \"{EXE_NAME}\" as program updater,please redownload or manually copy files/directories of folder \"{TEMP_DIR_NAME}\" to current program folder");
return;
}

var updater_exe_file = Path.Combine(TEMP_DIR_NAME, UPDATE_EXE_NAME);
File.Copy(exe_file, updater_exe_file, true);
var updater_exe_file = Path.Combine(exe_path, UPDATE_EXE_NAME);
File.Copy(exe_file_path, updater_exe_file, true);

if (File.Exists(DOWNLOAD_ZIP))
File.Delete(DOWNLOAD_ZIP);

var current_path = AppDomain.CurrentDomain.BaseDirectory;

Process.Start(new ProcessStartInfo(updater_exe_file, $"\"{Process.GetCurrentProcess().Id}\" -program_update -disable_update_check"));
Process.Start(new ProcessStartInfo(updater_exe_file, $"\"{Process.GetCurrentProcess().Id}\" -program_update \"{current_path}\" -disable_update_check"));

MainProgram.Exit();
}
Expand Down Expand Up @@ -150,7 +157,7 @@ internal static void CleanTemp()
}
}

public static void ApplyUpdate(int raw_proc_id)
public static void ApplyUpdate(int raw_proc_id, string dest_path)
{
try
{
Expand All @@ -162,14 +169,19 @@ public static void ApplyUpdate(int raw_proc_id)
try
{
Log.User($"Waiting for all players were shutdown....");

while (Process.GetProcessesByName("ReOsuStoryBoardPlayer").Any())
Thread.Sleep(500);

var current_exe_name = Path.GetFileName(Process.GetCurrentProcess().Modules[0].FileName);
var current_path = AppDomain.CurrentDomain.BaseDirectory;

var prev_path = new DirectoryInfo(current_path).Parent.FullName;
if(!Directory.Exists(dest_path))
{
MainProgram.Exit("program_update must set a directory path.");
}

Log.User($"Copy files to {dest_path}");

bool success_fully = true;
var files = Directory.EnumerateFiles(current_path).Where(x => Path.GetFileName(x)!=current_exe_name).ToArray();
Expand All @@ -182,8 +194,8 @@ public static void ApplyUpdate(int raw_proc_id)
try
{
display_file_path=RelativePath(current_path, source_file);
Log.User($"Copy file({i}/{files.Length}):{display_file_path}");
CopyRelativeFile(source_file, current_path, prev_path);
Log.User($"Copy file({i+1}/{files.Length}):{display_file_path}");
CopyRelativeFile(source_file, current_path, dest_path);
}
catch (Exception e)
{
Expand All @@ -193,7 +205,9 @@ public static void ApplyUpdate(int raw_proc_id)
}

if (success_fully)
{
Log.User("Program update successfully!");
}
else
Log.Warn("Program update isn't successful even failed,but you can copy the files/directories of \"update_temp\" folder to current program folder");

Expand Down

0 comments on commit 0753d21

Please sign in to comment.