added new class for spectre things, added progress to copyDirectory, had to make a duplicate method in current imp for copy progress to not cause issues

This commit is contained in:
CWX 2022-05-14 17:03:24 +01:00
parent 532aba2387
commit 59ffbddf3b
4 changed files with 114 additions and 30 deletions

View File

@ -9,8 +9,6 @@ namespace SPT_AKI_Installer.Aki.Core
{
//TODO:
// delete patcher zip and aki zip
// progress for copyDirectory
// add figlet for SPT-AKI INSTALLER
// locales, language selection
// PreCheckHelper.AkiCheck is currently hardcoded for 2.3.1
// get waffle to add exit code on patcher
@ -24,11 +22,14 @@ namespace SPT_AKI_Installer.Aki.Core
{
static void Main(string[] args)
{
SpectreHelper spectreHelper = new SpectreHelper();
spectreHelper.Figlet("SPT-AKI INSTALLER");
string targetPath = Environment.CurrentDirectory;
PreCheckHelper preCheckHelper = new();
#if DEBUG
//#if DEBUG
targetPath = @"D:\install";
#endif
//#endif
preCheckHelper.GameCheck(out string gamePath);
if (preCheckHelper.PatcherCheck(gamePath,targetPath, out string patchRef))
@ -59,7 +60,7 @@ namespace SPT_AKI_Installer.Aki.Core
LogHelper.User("PLEASE PRESS ENTER TO COPY GAME FILES!");
Console.ReadKey();
GameCopy(gamePath, targetPath, akiRef);
GameCopy(gamePath, targetPath,patchRef, akiRef);
}
/// <summary>
@ -67,26 +68,27 @@ namespace SPT_AKI_Installer.Aki.Core
/// </summary>
/// <param name="gamePath"></param>
/// <param name="targetPath"></param>
static void GameCopy(string gamePath, string targetPath, string akiRef)
static void GameCopy(string gamePath, string targetPath, string patchRef, string akiRef)
{
#if !DEBUG
//#if !DEBUG
FileHelper.CopyDirectory(gamePath, targetPath, true);
#endif
//#endif
LogHelper.User("GAME HAS BEEN COPIED, PRESS ENTER TO EXTRACT PATCHER!");
Console.ReadKey();
PatcherCopy(gamePath, targetPath, akiRef);
PatcherCopy(gamePath, targetPath,patchRef, akiRef);
}
/// <summary>
/// extracts patcher and moves out inner folders
/// </summary>
/// <param name="patchRef"></param>
/// <param name="gamePath"></param>
/// <param name="targetPath"></param>
/// <param name="patchRef"></param>
/// <param name="akiRef"></param>
static void PatcherCopy(string patchRef, string targetPath, string akiRef)
static void PatcherCopy(string gamePath, string targetPath, string patchRef, string akiRef)
{
#if !DEBUG
//#if !DEBUG
ZipHelper.Decompress(patchRef, targetPath);
FileHelper.FindFolder(patchRef, targetPath, out DirectoryInfo dir);
FileHelper.CopyDirectory(dir.FullName, targetPath, true);
@ -100,7 +102,7 @@ namespace SPT_AKI_Installer.Aki.Core
LogHelper.Error($"please delete folder called {dir.FullName}");
}
}
#endif
//#endif
PatcherProcessStart(targetPath, akiRef);
}
@ -111,11 +113,11 @@ namespace SPT_AKI_Installer.Aki.Core
/// <param name="akiRef"></param>
static void PatcherProcessStart(string targetPath, string akiRef)
{
#if !DEBUG
//#if !DEBUG
LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!");
ProcessHelper patcherProcess = new();
patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath);
#endif
//#endif
LogHelper.User("PATCHER HAS BEEN STARTED, TYPE YES ONCE THE PATCHER IS COMPLETE!");
var complete = Console.ReadLine();
@ -130,12 +132,12 @@ namespace SPT_AKI_Installer.Aki.Core
// if user input "yes" kill patcher process, delete patcher.exe, extract aki zip
if (string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase))
{
#if !DEBUG
//#if !DEBUG
patcherProcess.EndProcess();
Thread.Sleep(1000);
FileHelper.DeleteFile("file", targetPath + "/patcher.exe");
ZipHelper.Decompress(akiRef, targetPath);
#endif
//#endif
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");
Console.ReadKey();

View File

@ -1,16 +1,90 @@
using System;
using System.IO;
using Spectre.Console;
using System.Threading;
namespace SPT_AKI_Installer.Aki.Helper
{
public static class FileHelper
{
public static int totalFiles;
/// <summary>
/// CopyDirectory will use old path and copy to new path and
/// asks if inner files/folders should be included
/// </summary>
/// <exception cref="DirectoryNotFoundException"></exception>
public static void CopyDirectory(string oldDir, string newDir, bool recursive)
{
AnsiConsole.Progress().Columns(
new TaskDescriptionColumn(),
new SpinnerColumn(),
new ElapsedTimeColumn()
).Start((ProgressContext context) =>
{
var dir = new DirectoryInfo(oldDir);
if (!dir.Exists)
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
DirectoryInfo[] dirs = dir.GetDirectories();
foreach (FileInfo f in dir.GetFiles())
{
totalFiles++;
}
foreach (DirectoryInfo subD in dirs)
{
foreach (FileInfo f in subD.GetFiles())
{
totalFiles++;
}
}
var task = context.AddTask("Copying files: ", true, totalFiles);
Directory.CreateDirectory(newDir);
foreach (FileInfo file in dir.GetFiles())
{
string targetFilePath = Path.Combine(newDir, file.Name);
file.CopyTo(targetFilePath, true);
}
if (recursive)
{
foreach (DirectoryInfo subDir in dirs)
{
string newDestinationDir = Path.Combine(newDir, subDir.Name);
AltCopyDirectory(subDir.FullName, newDestinationDir, true);
}
}
});
//var dir = new DirectoryInfo(oldDir);
//if (!dir.Exists)
// throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
//DirectoryInfo[] dirs = dir.GetDirectories();
//Directory.CreateDirectory(newDir);
//foreach (FileInfo file in dir.GetFiles())
//{
// string targetFilePath = Path.Combine(newDir, file.Name);
// file.CopyTo(targetFilePath, true);
//}
//if (recursive)
//{
// foreach (DirectoryInfo subDir in dirs)
// {
// string newDestinationDir = Path.Combine(newDir, subDir.Name);
// CopyDirectory(subDir.FullName, newDestinationDir, true);
// }
//}
}
public static void AltCopyDirectory(string oldDir, string newDir, bool recursive)
{
var dir = new DirectoryInfo(oldDir);
@ -32,7 +106,7 @@ namespace SPT_AKI_Installer.Aki.Helper
foreach (DirectoryInfo subDir in dirs)
{
string newDestinationDir = Path.Combine(newDir, subDir.Name);
CopyDirectory(subDir.FullName, newDestinationDir, true);
AltCopyDirectory(subDir.FullName, newDestinationDir, true);
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spectre.Console;
namespace SPT_AKI_Installer.Aki.Helper
{
public class SpectreHelper
{
public void Figlet(string text)
{
AnsiConsole.Write(
new FigletText(text)
.Centered()
.Color(Color.Yellow));
}
}
}

View File

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