Minor fixes

This commit is contained in:
pointfeev 2021-07-29 17:19:59 -05:00
parent 5742df304e
commit 2f2e99f746
3 changed files with 71 additions and 28 deletions

View file

@ -6,7 +6,23 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>ini.ico</ApplicationIcon> <ApplicationIcon>ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>1.0.0</Version> <Version>1.0.1</Version>
<PackageIcon>ini.ico</PackageIcon>
<PackageIconUrl />
<Description>Automatically downloads and installs CreamAPI files for programs/games.</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/pointfeev/CreamInstaller</PackageProjectUrl>
<RepositoryUrl>https://github.com/pointfeev/CreamInstaller</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>Automatically downloads and installs CreamAPI files for programs/games.</PackageReleaseNotes>
<PackageTags>steam, dlc</PackageTags>
<AssemblyName>CreamInstaller v$(Version)</AssemblyName>
<Company>CreamInstaller</Company>
<Product>CreamAPI Downloader &amp; Installer</Product>
<Authors>pointfeev</Authors>
<PackageId>pointfeev.creaminstaller</PackageId>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@ -47,4 +63,15 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="ini.ico">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project> </Project>

View file

@ -48,7 +48,7 @@ namespace CreamInstaller
GithubPackageResolver resolver = new GithubPackageResolver("pointfeev", "CreamInstaller", "CreamInstaller.zip"); GithubPackageResolver resolver = new GithubPackageResolver("pointfeev", "CreamInstaller", "CreamInstaller.zip");
ZipPackageExtractor extractor = new ZipPackageExtractor(); 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) if (latestVersion is null)
{ {

View file

@ -1,8 +1,11 @@
using CG.Web.MegaApiClient; using CG.Web.MegaApiClient;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -13,9 +16,37 @@ namespace CreamInstaller
{ {
public static string ApplicationName = "CreamInstaller v" + Application.ProductVersion + ": CreamAPI Downloader & Installer"; 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] [STAThread]
static void Main() 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 = new MegaApiClient();
MegaApiClient.Login(); MegaApiClient.Login();
@ -60,39 +91,24 @@ namespace CreamInstaller
progressBar.Maximum--; 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) public static void Cleanup(bool cancel = true, bool logout = true)
{ {
Canceled = cancel; Canceled = cancel;
if (OutputArchive != null || CancellationTokenSource != null || OutputTask != null || OutputFile != null) if (OutputArchive != null || CancellationTokenSource != null || OutputTask != null || OutputFile != null)
{ {
UpdateProgress(0); InstallForm?.UpdateProgress(0);
UpdateUser("Cleaning up . . . "); InstallForm?.UpdateUser("Cleaning up . . . ");
} }
if (OutputArchive != null) if (OutputArchive != null)
{ {
OutputArchive.Dispose(); OutputArchive.Dispose();
OutputArchive = null; OutputArchive = null;
UpdateProgress(25); InstallForm?.UpdateProgress(25);
} }
if (CancellationTokenSource != null) if (CancellationTokenSource != null)
{ {
CancellationTokenSource.Cancel(); CancellationTokenSource.Cancel();
UpdateProgress(40); InstallForm?.UpdateProgress(40);
} }
if (OutputTask != null) if (OutputTask != null)
{ {
@ -103,13 +119,13 @@ namespace CreamInstaller
catch (AggregateException) { } catch (AggregateException) { }
OutputTask.Dispose(); OutputTask.Dispose();
OutputTask = null; OutputTask = null;
UpdateProgress(50); InstallForm?.UpdateProgress(50);
} }
if (CancellationTokenSource != null) if (CancellationTokenSource != null)
{ {
CancellationTokenSource.Dispose(); CancellationTokenSource.Dispose();
CancellationTokenSource = null; CancellationTokenSource = null;
UpdateProgress(75); InstallForm?.UpdateProgress(75);
} }
if (OutputFile != null && File.Exists(OutputFile)) if (OutputFile != null && File.Exists(OutputFile))
{ {
@ -119,17 +135,17 @@ namespace CreamInstaller
} }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {
UpdateUser($"WARNING: Couldn't clean up downloaded archive ({OutputFile})"); InstallForm?.UpdateUser($"WARNING: Couldn't clean up downloaded archive ({OutputFile})");
} }
OutputFile = null; OutputFile = null;
} }
UpdateProgress(100); InstallForm?.UpdateProgress(100);
if (logout && MegaApiClient != null && MegaApiClient.IsLoggedIn) if (logout && MegaApiClient != null && MegaApiClient.IsLoggedIn)
{ {
UpdateProgress(0); InstallForm?.UpdateProgress(0);
UpdateUser("Logging out of MEGA . . . "); InstallForm?.UpdateUser("Logging out of MEGA . . . ");
MegaApiClient.Logout(); MegaApiClient.Logout();
UpdateProgress(100); InstallForm?.UpdateProgress(100);
} }
} }