This commit is contained in:
CWX 2022-05-14 02:58:38 +01:00
parent aceb8cf4e3
commit a0d715cb44
15 changed files with 193 additions and 79 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 420 KiB

View File

@ -2,22 +2,32 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using Installer.Aki.Helper; using SPT_AKI_Installer.Aki.Helper;
using Spectre.Console;
namespace Installer.Aki.Core namespace SPT_AKI_Installer.Aki.Core
{ {
//TODO: //TODO:
// delete patcher zip and aki zip // delete patcher zip and aki zip
// progress for copyDirectory
// move Game/patcher/aki check methods out of core
// add figlet for SPT-AKI INSTALLER
// locales, language selection
public static class SPTinstaller public static class SPTinstaller
{ {
public static string targetPath = Environment.CurrentDirectory;
private static string patchRef; private static string patchRef;
private static string akiRef; private static string akiRef;
private static DirectoryInfo dir; private static DirectoryInfo dir;
private static string gamePath;
static void Main(string[] args) static void Main(string[] args)
{ {
string gamePath = GameHelper.DetectOriginalGamePath(); #if DEBUG
targetPath = @"D:\install";
#endif
GameCheck(out gamePath);
if (PatcherCheck(gamePath, out patchRef)) if (PatcherCheck(gamePath, out patchRef))
{ {
@ -48,14 +58,16 @@ namespace Installer.Aki.Core
Console.ReadKey(); Console.ReadKey();
// copies and pastes EFT to AKI installer test folder // copies and pastes EFT to AKI installer test folder
FileHelper.CopyDirectory(gamePath, Environment.CurrentDirectory, true); #if !DEBUG
FileHelper.CopyDirectory(gamePath, targetPath, true);
LogHelper.User("GAME HAS BEEN COPIED, PRESS ENTER TO EXTRACT PATCHER!"); LogHelper.User("GAME HAS BEEN COPIED, PRESS ENTER TO EXTRACT PATCHER!");
Console.ReadKey(); Console.ReadKey();
#endif
// extracts patcher and moves out inner folders // extracts patcher and moves out inner folders
ZipHelper.Decompress(patchRef, Environment.CurrentDirectory); ZipHelper.Decompress(patchRef, targetPath);
FileHelper.FindFolder(patchRef, out dir); FileHelper.FindFolder(patchRef, out dir);
FileHelper.CopyDirectory(dir.FullName, Environment.CurrentDirectory, true); FileHelper.CopyDirectory(dir.FullName, targetPath, true);
if (dir.Exists) if (dir.Exists)
{ {
dir.Delete(true); dir.Delete(true);
@ -68,9 +80,9 @@ namespace Installer.Aki.Core
} }
// starts patcher and checks for user input to exit patcher and proceed // starts patcher and checks for user input to exit patcher and proceed
LogHelper.User("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!"); LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!");
ProcessHelper patcherProcess = new ProcessHelper(); ProcessHelper patcherProcess = new();
patcherProcess.StartProcess(Path.Join(Environment.CurrentDirectory + "/patcher.exe"), Environment.CurrentDirectory); patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath);
LogHelper.User("PATCHER HAS BEEN STARTED, TYPE YES ONCE THE PATCHER IS COMPLETE!"); LogHelper.User("PATCHER HAS BEEN STARTED, TYPE YES ONCE THE PATCHER IS COMPLETE!");
var complete = Console.ReadLine(); var complete = Console.ReadLine();
@ -87,20 +99,44 @@ namespace Installer.Aki.Core
{ {
patcherProcess.EndProcess(); patcherProcess.EndProcess();
Thread.Sleep(1000); Thread.Sleep(1000);
FileHelper.DeleteFile("file", Environment.CurrentDirectory + "/patcher.exe"); FileHelper.DeleteFile("file", targetPath + "/patcher.exe");
ZipHelper.Decompress(akiRef, Environment.CurrentDirectory); ZipHelper.Decompress(akiRef, targetPath);
LogHelper.Info("AKI HAS BEEN EXTRACTED, RUN THE SERVER AND WAIT TILL YOU SEE HAPPY SERVER THEN LAUNCHER AND ENJOY!"); LogHelper.Info("AKI HAS BEEN EXTRACTED, RUN THE SERVER AND WAIT TILL YOU SEE HAPPY SERVER THEN LAUNCHER AND ENJOY!");
LogHelper.User("PRESS ENTER TO CLOSE THE APP"); LogHelper.User("PRESS ENTER TO CLOSE THE APP");
Console.ReadKey(); Console.ReadKey();
} }
} }
/// <summary>
/// checks the game is installed, out = game directory
/// </summary>
/// <param name="gamePath"></param>
private static void GameCheck(out string gamePath)
{
string Path = GameHelper.DetectOriginalGamePath();
if (Path == null)
{
LogHelper.Error("EFT IS NOT INSTALLED!");
LogHelper.Error("Press enter to close the app");
Console.ReadKey();
Environment.Exit(0);
}
gamePath = Path;
}
/// <summary>
/// checks for patcher zip path, out = patcher path
/// </summary>
/// <param name="gamePath"></param>
/// <param name="patchRef"></param>
/// <returns>bool</returns>
private static bool PatcherCheck(string gamePath, out string patchRef) private static bool PatcherCheck(string gamePath, out string patchRef)
{ {
FileVersionInfo version = FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe")); FileVersionInfo version = FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe"));
string versionCheck = StringHelper.Splitter(version.ProductVersion, '-', '.', 2); string versionCheck = StringHelper.Splitter(version.ProductVersion, '-', '.', 2);
LogHelper.Info($"GAME VERSION IS: {version.ProductVersion}"); LogHelper.Info($"GAME VERSION IS: {version.ProductVersion}");
string patcherRef = FileHelper.FindFile(Environment.CurrentDirectory, versionCheck); string patcherRef = FileHelper.FindFile(targetPath, versionCheck);
if (patcherRef != null) if (patcherRef != null)
{ {
@ -111,9 +147,14 @@ namespace Installer.Aki.Core
return false; return false;
} }
/// <summary>
/// checks for aki zip path, out = aki path
/// </summary>
/// <param name="akiRef"></param>
/// <returns>bool</returns>
private static bool AkiCheck(out string akiRef) private static bool AkiCheck(out string akiRef)
{ {
string aki = FileHelper.FindFile(Environment.CurrentDirectory, "2.3.1"); string aki = FileHelper.FindFile(targetPath, "2.3.1");
if (aki != null) if (aki != null)
{ {

View File

@ -1,12 +1,13 @@
using System; using SPT_AKI_Installer.Aki.Core;
using System;
using System.IO; using System.IO;
namespace Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
public static class FileHelper public static class FileHelper
{ {
/// <summary> /// <summary>
/// CopyDirectory will use old path and copy to new path and /// CopyDirectory will use old path and copy to new path and
/// asks if inner files/folders should be included /// asks if inner files/folders should be included
/// </summary> /// </summary>
/// <exception cref="DirectoryNotFoundException"></exception> /// <exception cref="DirectoryNotFoundException"></exception>
@ -23,7 +24,6 @@ namespace Installer.Aki.Helper
foreach (FileInfo file in dir.GetFiles()) foreach (FileInfo file in dir.GetFiles())
{ {
Console.WriteLine(file.FullName);
string targetFilePath = Path.Combine(newDir, file.Name); string targetFilePath = Path.Combine(newDir, file.Name);
file.CopyTo(targetFilePath, true); file.CopyTo(targetFilePath, true);
} }
@ -39,7 +39,7 @@ namespace Installer.Aki.Helper
} }
/// <summary> /// <summary>
/// DeleteFiles will use a type to look for, the path /// DeleteFiles will use a type to look for, the path
/// and if all inner files/folders should be included /// and if all inner files/folders should be included
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -88,7 +88,7 @@ namespace Installer.Aki.Helper
{ {
var patchInfo = new FileInfo(patchRef); var patchInfo = new FileInfo(patchRef);
var patchName = patchInfo.Name.Replace(patchInfo.Extension, ""); var patchName = patchInfo.Name.Replace(patchInfo.Extension, "");
var path = new DirectoryInfo(Path.Join(Environment.CurrentDirectory, patchName)); var path = new DirectoryInfo(Path.Join(SPTinstaller.targetPath, patchName));
if (path.Exists) if (path.Exists)
{ {
dir = path; dir = path;

View File

@ -2,7 +2,7 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.IO; using System.IO;
namespace Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
public static class GameHelper public static class GameHelper
{ {

View File

@ -1,19 +1,22 @@
using System; using System;
using Spectre.Console;
namespace Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
public static class LogHelper public static class LogHelper
{ {
private static void Log(string tag, string message, string foreground, string background = "black")
{
AnsiConsole.MarkupLine($"[{foreground} on {background}][[{tag}]]: {message.EscapeMarkup()}[/]");
}
/// <summary> /// <summary>
/// Outputs a string to console starting with [USER] with /// Outputs a string to console starting with [USER] with
/// a Green background and Black foreground /// a Green background and Black foreground
/// </summary> /// </summary>
public static void User(string text) public static void User(string text)
{ {
Console.BackgroundColor = ConsoleColor.Green; Log("USER", text, "green");
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine($"[USER]: {text}");
Console.ResetColor();
} }
/// <summary> /// <summary>
@ -22,10 +25,7 @@ namespace Installer.Aki.Helper
/// </summary> /// </summary>
public static void Warning(string text) public static void Warning(string text)
{ {
Console.BackgroundColor = ConsoleColor.Yellow; Log("WARNING", text, "yellow");
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine($"[WARNING]: {text}");
Console.ResetColor();
} }
/// <summary> /// <summary>
@ -34,10 +34,7 @@ namespace Installer.Aki.Helper
/// </summary> /// </summary>
public static void Error(string text) public static void Error(string text)
{ {
Console.BackgroundColor = ConsoleColor.Red; Log("ERROR", text, "red");
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine($"[ERROR]: {text}");
Console.ResetColor();
} }
/// <summary> /// <summary>
@ -46,10 +43,7 @@ namespace Installer.Aki.Helper
/// </summary> /// </summary>
public static void Info(string text) public static void Info(string text)
{ {
Console.BackgroundColor = ConsoleColor.DarkGray; Log("INFO", text, "blue");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"[INFO]: {text}");
Console.ResetColor();
} }
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
namespace Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
public class ProcessHelper public class ProcessHelper
{ {

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SPT_AKI_Installer.Aki.Helper
{
internal class StatusHelper
{
}
}

View File

@ -1,4 +1,4 @@
namespace Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
public static class StringHelper public static class StringHelper
{ {

View File

@ -1,33 +1,57 @@
using SharpCompress.Common; using SharpCompress.Archives;
using SharpCompress.Readers; using SharpCompress.Archives.Zip;
using System; using SharpCompress.Common;
using System.IO; using Spectre.Console;
using System.Linq;
namespace Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
public static class ZipHelper public static class ZipHelper
{ {
/// <summary> /// <summary>
/// will extract Zips in LZMA compression format, using Zips path /// will extract Zips in LZMA compression format, using Zips path
/// to new path /// to new path
/// </summary> /// </summary>
public static void Decompress(string zipPath, string extPath) public static void Decompress(string ArchivePath, string OutputFolderPath)
{ {
Stream stream = File.OpenRead(zipPath); AnsiConsole.Progress().Columns(
var reader = ReaderFactory.Open(stream); new PercentageColumn(),
new TaskDescriptionColumn(),
while (reader.MoveToNextEntry()) new ProgressBarColumn(),
new ElapsedTimeColumn()
).Start((ProgressContext context) =>
{ {
if (!reader.Entry.IsDirectory) using var archive = ZipArchive.Open(ArchivePath);
var entries = archive.Entries.Where(entry => !entry.IsDirectory);
var task = context.AddTask("Extracting", true, entries.Count());
foreach (var entry in entries)
{ {
Console.WriteLine(reader.Entry.Key); entry.WriteToDirectory($"{OutputFolderPath}", new ExtractionOptions()
reader.WriteEntryToDirectory(extPath, new ExtractionOptions()
{ {
ExtractFullPath = true, ExtractFullPath = true,
Overwrite = true Overwrite = true
}); });
task.Increment(1);
} }
} });
//Stream stream = File.OpenRead(zipPath);
//var reader = ReaderFactory.Open(stream);
//while (reader.MoveToNextEntry())
//{
// if (!reader.Entry.IsDirectory)
// {
// Console.WriteLine(reader.Entry.Key);
// reader.WriteEntryToDirectory(extPath, new ExtractionOptions()
// {
// ExtractFullPath = true,
// Overwrite = true
// });
// }
//}
} }
} }
} }

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net6.0\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2022-05-14T00:56:09.8410037Z;True|2022-05-14T00:54:24.0683990+01:00;True|2022-05-14T00:53:04.7105427+01:00;True|2022-05-14T00:51:00.6280767+01:00;True|2022-05-14T00:49:19.4630888+01:00;True|2022-05-14T00:47:59.2166156+01:00;</History>
</PropertyGroup>
</Project>

View File

@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishTrimmed>true</PublishTrimmed>
<ApplicationIcon>Aki.Asset\icon.ico</ApplicationIcon>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup>
<Folder Include="Aki.Asset\" />
<Folder Include="Aki.Locales\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpCompress" Version="0.31.0" />
</ItemGroup>
</Project>

34
SPT_AKI Installer.csproj Normal file
View File

@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PackageIcon>icon.ico</PackageIcon>
<ApplicationIcon>Aki.Asset\icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Content Include="Aki.Asset\icon.ico" />
</ItemGroup>
<ItemGroup>
<Folder Include="Aki.Locales\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpCompress" Version="0.31.0" />
<PackageReference Include="Spectre.Console" Version="0.44.0" />
</ItemGroup>
<ItemGroup>
<None Update="Aki.Asset\icon.ico">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Update="Aki.Asset\icon.jpeg">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>C:\Users\craig\source\repos\CWXDEV\CWX-SPTinstaller\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.1.32407.343 VisualStudioVersion = 17.1.32407.343
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SPT-AKI Installer", "SPT-AKI Installer.csproj", "{7B07749A-3BE8-41B5-9B98-9F41C83FA15B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SPT_AKI Installer", "SPT_AKI Installer.csproj", "{7B07749A-3BE8-41B5-9B98-9F41C83FA15B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution