diff --git a/Aki.Core/Program.cs b/Aki.Core/Program.cs index 101e465..bfc5b42 100644 --- a/Aki.Core/Program.cs +++ b/Aki.Core/Program.cs @@ -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); } /// @@ -67,26 +68,27 @@ namespace SPT_AKI_Installer.Aki.Core /// /// /// - 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); } /// /// extracts patcher and moves out inner folders /// - /// + /// /// + /// /// - 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 /// 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(); diff --git a/Aki.Helper/FileHelper.cs b/Aki.Helper/FileHelper.cs index 23769b9..9f9c2df 100644 --- a/Aki.Helper/FileHelper.cs +++ b/Aki.Helper/FileHelper.cs @@ -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; /// /// CopyDirectory will use old path and copy to new path and /// asks if inner files/folders should be included /// /// 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); } } } diff --git a/Aki.Helper/SpectreHelper.cs b/Aki.Helper/SpectreHelper.cs new file mode 100644 index 0000000..6d74f03 --- /dev/null +++ b/Aki.Helper/SpectreHelper.cs @@ -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)); + } + } +} diff --git a/Aki.Helper/StatusHelper.cs b/Aki.Helper/StatusHelper.cs deleted file mode 100644 index 0ec6210..0000000 --- a/Aki.Helper/StatusHelper.cs +++ /dev/null @@ -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 - { - } -}