Skip to content

Commit

Permalink
Automatic Updates Fully Working
Browse files Browse the repository at this point in the history
  • Loading branch information
TrinityDevelopers committed May 28, 2020
1 parent 1d7067c commit 6415e5f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 37 deletions.
64 changes: 36 additions & 28 deletions ZenovaLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public static void Main()
if (SingleInstance<App>.InitializeAsFirstInstance(AppID))
{
var application = new App();
splash = new SplashScreen("Assets/zenova_splash.png");
splash.Show(false);
application.InitializeComponent();
application.Run();
// Allow single instance code to perform cleanup operations
Expand Down Expand Up @@ -63,13 +61,17 @@ public void ReadCommandArgs(IList<string> args)

public void AppStart(object sender, StartupEventArgs e)
{
sw = Stopwatch.StartNew();
SetupEnvironment();
Trace.Listeners.Add(new TextWriterTraceListener(new FileStream(Path.Combine(DataDirectory, "log.txt"), FileMode.Create)));
Trace.AutoFlush = true;
Trace.WriteLine("AppStart " + sw.ElapsedMilliseconds + " ms");
sw = Stopwatch.StartNew();
ZenovaUpdater.instance = new ZenovaUpdater();
Trace.WriteLine("ZenovaUpdater.instance " + sw.ElapsedMilliseconds + " ms");
bool exit = false;
Task updateTask = Task.Run(async () => {
exit = await ZenovaUpdater.instance.CheckUpdate();
});
SetupEnvironment();
Trace.WriteLine("AppStart " + sw.ElapsedMilliseconds + " ms");
VersionDownloader.standard = new VersionDownloader();
Trace.WriteLine("VersionDownloader.standard " + sw.ElapsedMilliseconds + " ms");
VersionDownloader.user = new VersionDownloader();
Expand All @@ -84,30 +86,36 @@ public void AppStart(object sender, StartupEventArgs e)
Trace.WriteLine("AccountManager.instance " + sw.ElapsedMilliseconds + " ms");
ModManager.instance = new ModManager(ModsDirectory);
Trace.WriteLine("ModManager.instance " + sw.ElapsedMilliseconds + " ms");
Task updateTask = Task.Run(async () => {
await ZenovaUpdater.instance.CheckUpdate();
});
Task loadTask = Task.Run(async () =>
{
await AccountManager.instance.AddAccounts();
Trace.WriteLine("AccountManager.AddAccounts " + sw.ElapsedMilliseconds + " ms");
await VersionManager.instance.LoadMinecraftVersions();
Trace.WriteLine("VersionManager.LoadMinecraftVersions " + sw.ElapsedMilliseconds + " ms");
ModManager.instance.LoadMods();
Trace.WriteLine("ModManager.LoadMods " + sw.ElapsedMilliseconds + " ms");
ProfileManager.instance.ImportProfiles();
Trace.WriteLine("ProfileManager.ImportProfiles " + sw.ElapsedMilliseconds + " ms");
Preferences.LoadPreferences(DataDirectory);
Trace.WriteLine("Preferences.LoadPreferences " + sw.ElapsedMilliseconds + " ms");
VersionManager.instance.RemoveUnusedVersions();
Trace.WriteLine("VersionManager.RemoveUnusedVersions " + sw.ElapsedMilliseconds + " ms");
});
loadTask.Wait();
updateTask.Wait();
ReadCommandArgs(Environment.GetCommandLineArgs());
Trace.WriteLine("AppStart Finished " + sw.ElapsedMilliseconds + " ms");
sw.Stop();
splash.Close(TimeSpan.FromSeconds(1));
if (!exit)
{
splash = new SplashScreen("Assets/zenova_splash.png");
splash.Show(false);
Task loadTask = Task.Run(async () =>
{
await AccountManager.instance.AddAccounts();
Trace.WriteLine("AccountManager.AddAccounts " + sw.ElapsedMilliseconds + " ms");
await VersionManager.instance.LoadMinecraftVersions();
Trace.WriteLine("VersionManager.LoadMinecraftVersions " + sw.ElapsedMilliseconds + " ms");
ModManager.instance.LoadMods();
Trace.WriteLine("ModManager.LoadMods " + sw.ElapsedMilliseconds + " ms");
ProfileManager.instance.ImportProfiles();
Trace.WriteLine("ProfileManager.ImportProfiles " + sw.ElapsedMilliseconds + " ms");
Preferences.LoadPreferences(DataDirectory);
Trace.WriteLine("Preferences.LoadPreferences " + sw.ElapsedMilliseconds + " ms");
VersionManager.instance.RemoveUnusedVersions();
Trace.WriteLine("VersionManager.RemoveUnusedVersions " + sw.ElapsedMilliseconds + " ms");
});
loadTask.Wait();
ReadCommandArgs(Environment.GetCommandLineArgs());
Trace.WriteLine("AppStart Finished " + sw.ElapsedMilliseconds + " ms");
sw.Stop();
splash.Close(TimeSpan.FromSeconds(1));
}
else
{
Shutdown();
}
}

public void AppExit(object sender, ExitEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions ZenovaLauncher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.2")]
11 changes: 4 additions & 7 deletions ZenovaLauncher/Utils/ZenovaUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ZenovaUpdater
{
public static ZenovaUpdater instance;

public async Task CheckUpdate()
public async Task<bool> CheckUpdate()
{
try
{
Expand All @@ -30,25 +30,22 @@ public async Task CheckUpdate()
if (latestVersion > installedVersion)
{
var response = await client.Connection.Get<object>(new Uri(latest.Assets[0].Url), new Dictionary<string, string>(), "application/octet-stream");
byte[] bytes = Encoding.ASCII.GetBytes(response.HttpResponse.Body.ToString());
string path = Path.GetTempFileName();
string dlPath = path.Replace(".tmp", "_" + latest.Assets[0].Name);
File.Move(path, dlPath);
File.WriteAllBytes(dlPath, bytes);
File.WriteAllBytes(dlPath, (byte[]) response.Body);
ProcessStartInfo psi = new ProcessStartInfo(dlPath, "/verysilent");
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
await System.Windows.Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate ()
{
System.Windows.Application.Current.MainWindow.Close();
});
return true;
}
}
catch (Exception e)
{
Trace.WriteLine("Check for update failed:\n" + e.ToString());
}
return false;
}

public void DeleteInstaller(string path)
Expand Down

0 comments on commit 6415e5f

Please sign in to comment.