From 2f2e99f746557f7f1dcb2acc89cabb55fe7d18cc Mon Sep 17 00:00:00 2001 From: pointfeev Date: Thu, 29 Jul 2021 17:19:59 -0500 Subject: [PATCH] Minor fixes --- CreamInstaller/CreamInstaller.csproj | 29 +++++++++++- CreamInstaller/MainForm.cs | 2 +- CreamInstaller/Program.cs | 68 +++++++++++++++++----------- 3 files changed, 71 insertions(+), 28 deletions(-) diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 6fcf43f..9678685 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -6,7 +6,23 @@ true ini.ico true - 1.0.0 + 1.0.1 + ini.ico + + Automatically downloads and installs CreamAPI files for programs/games. + LICENSE + 2021, pointfeev (https://github.com/pointfeev) + true + https://github.com/pointfeev/CreamInstaller + https://github.com/pointfeev/CreamInstaller + git + Automatically downloads and installs CreamAPI files for programs/games. + steam, dlc + CreamInstaller v$(Version) + CreamInstaller + CreamAPI Downloader & Installer + pointfeev + pointfeev.creaminstaller @@ -47,4 +63,15 @@ + + + True + + + + True + + + + \ No newline at end of file diff --git a/CreamInstaller/MainForm.cs b/CreamInstaller/MainForm.cs index bdecae8..4bb4345 100644 --- a/CreamInstaller/MainForm.cs +++ b/CreamInstaller/MainForm.cs @@ -48,7 +48,7 @@ namespace CreamInstaller GithubPackageResolver resolver = new GithubPackageResolver("pointfeev", "CreamInstaller", "CreamInstaller.zip"); ZipPackageExtractor extractor = new ZipPackageExtractor(); - updateManager = new UpdateManager(AssemblyMetadata.FromAssembly(Assembly.GetEntryAssembly(), Process.GetCurrentProcess().MainModule.FileName), resolver, extractor); + updateManager = new UpdateManager(AssemblyMetadata.FromAssembly(Program.EntryAssembly, Program.CurrentProcessFilePath), resolver, extractor); if (latestVersion is null) { diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index b241965..48fcc6b 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -1,8 +1,11 @@ using CG.Web.MegaApiClient; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.IO.Compression; +using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -13,9 +16,37 @@ namespace CreamInstaller { public static string ApplicationName = "CreamInstaller v" + Application.ProductVersion + ": CreamAPI Downloader & Installer"; + public static Assembly EntryAssembly = Assembly.GetEntryAssembly(); + public static Process CurrentProcess = Process.GetCurrentProcess(); + public static string CurrentProcessFilePath = CurrentProcess.MainModule.FileName; + public static string CurrentProcessDirectory = CurrentProcessFilePath.Substring(0, CurrentProcessFilePath.LastIndexOf("\\")); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool AllocConsole(); + [STAThread] static void Main() { + Console.WriteLine(CurrentProcessDirectory); + DirectoryInfo directoryInfo = new DirectoryInfo(CurrentProcessDirectory); + FileInfo[] files = directoryInfo.GetFiles("CreamInstaller*.exe"); + if (files.Length > 0) + { + foreach (FileInfo file in files) + { + if (file.FullName != CurrentProcessFilePath) + { + try + { + File.Delete(file.FullName); + } + catch { } + } + + } + } + MegaApiClient = new MegaApiClient(); MegaApiClient.Login(); @@ -60,39 +91,24 @@ namespace CreamInstaller progressBar.Maximum--; } - private static void UpdateProgress(int progress) - { - if (InstallForm != null) - { - InstallForm.UpdateProgress(progress); - } - } - private static void UpdateUser(string text) - { - if (InstallForm != null) - { - InstallForm.UpdateUser(text); - } - } - public static void Cleanup(bool cancel = true, bool logout = true) { Canceled = cancel; if (OutputArchive != null || CancellationTokenSource != null || OutputTask != null || OutputFile != null) { - UpdateProgress(0); - UpdateUser("Cleaning up . . . "); + InstallForm?.UpdateProgress(0); + InstallForm?.UpdateUser("Cleaning up . . . "); } if (OutputArchive != null) { OutputArchive.Dispose(); OutputArchive = null; - UpdateProgress(25); + InstallForm?.UpdateProgress(25); } if (CancellationTokenSource != null) { CancellationTokenSource.Cancel(); - UpdateProgress(40); + InstallForm?.UpdateProgress(40); } if (OutputTask != null) { @@ -103,13 +119,13 @@ namespace CreamInstaller catch (AggregateException) { } OutputTask.Dispose(); OutputTask = null; - UpdateProgress(50); + InstallForm?.UpdateProgress(50); } if (CancellationTokenSource != null) { CancellationTokenSource.Dispose(); CancellationTokenSource = null; - UpdateProgress(75); + InstallForm?.UpdateProgress(75); } if (OutputFile != null && File.Exists(OutputFile)) { @@ -119,17 +135,17 @@ namespace CreamInstaller } catch (UnauthorizedAccessException) { - UpdateUser($"WARNING: Couldn't clean up downloaded archive ({OutputFile})"); + InstallForm?.UpdateUser($"WARNING: Couldn't clean up downloaded archive ({OutputFile})"); } OutputFile = null; } - UpdateProgress(100); + InstallForm?.UpdateProgress(100); if (logout && MegaApiClient != null && MegaApiClient.IsLoggedIn) { - UpdateProgress(0); - UpdateUser("Logging out of MEGA . . . "); + InstallForm?.UpdateProgress(0); + InstallForm?.UpdateUser("Logging out of MEGA . . . "); MegaApiClient.Logout(); - UpdateProgress(100); + InstallForm?.UpdateProgress(100); } }