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:
parent
532aba2387
commit
59ffbddf3b
@ -9,8 +9,6 @@ namespace SPT_AKI_Installer.Aki.Core
|
|||||||
{
|
{
|
||||||
//TODO:
|
//TODO:
|
||||||
// delete patcher zip and aki zip
|
// delete patcher zip and aki zip
|
||||||
// progress for copyDirectory
|
|
||||||
// add figlet for SPT-AKI INSTALLER
|
|
||||||
// locales, language selection
|
// locales, language selection
|
||||||
// PreCheckHelper.AkiCheck is currently hardcoded for 2.3.1
|
// PreCheckHelper.AkiCheck is currently hardcoded for 2.3.1
|
||||||
// get waffle to add exit code on patcher
|
// get waffle to add exit code on patcher
|
||||||
@ -24,11 +22,14 @@ namespace SPT_AKI_Installer.Aki.Core
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
SpectreHelper spectreHelper = new SpectreHelper();
|
||||||
|
spectreHelper.Figlet("SPT-AKI INSTALLER");
|
||||||
|
|
||||||
string targetPath = Environment.CurrentDirectory;
|
string targetPath = Environment.CurrentDirectory;
|
||||||
PreCheckHelper preCheckHelper = new();
|
PreCheckHelper preCheckHelper = new();
|
||||||
#if DEBUG
|
//#if DEBUG
|
||||||
targetPath = @"D:\install";
|
targetPath = @"D:\install";
|
||||||
#endif
|
//#endif
|
||||||
preCheckHelper.GameCheck(out string gamePath);
|
preCheckHelper.GameCheck(out string gamePath);
|
||||||
|
|
||||||
if (preCheckHelper.PatcherCheck(gamePath,targetPath, out string patchRef))
|
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!");
|
LogHelper.User("PLEASE PRESS ENTER TO COPY GAME FILES!");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|
||||||
GameCopy(gamePath, targetPath, akiRef);
|
GameCopy(gamePath, targetPath,patchRef, akiRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -67,26 +68,27 @@ namespace SPT_AKI_Installer.Aki.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="gamePath"></param>
|
/// <param name="gamePath"></param>
|
||||||
/// <param name="targetPath"></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);
|
FileHelper.CopyDirectory(gamePath, targetPath, true);
|
||||||
#endif
|
//#endif
|
||||||
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();
|
||||||
|
|
||||||
PatcherCopy(gamePath, targetPath, akiRef);
|
PatcherCopy(gamePath, targetPath,patchRef, akiRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// extracts patcher and moves out inner folders
|
/// extracts patcher and moves out inner folders
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patchRef"></param>
|
/// <param name="gamePath"></param>
|
||||||
/// <param name="targetPath"></param>
|
/// <param name="targetPath"></param>
|
||||||
|
/// <param name="patchRef"></param>
|
||||||
/// <param name="akiRef"></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);
|
ZipHelper.Decompress(patchRef, targetPath);
|
||||||
FileHelper.FindFolder(patchRef, targetPath, out DirectoryInfo dir);
|
FileHelper.FindFolder(patchRef, targetPath, out DirectoryInfo dir);
|
||||||
FileHelper.CopyDirectory(dir.FullName, targetPath, true);
|
FileHelper.CopyDirectory(dir.FullName, targetPath, true);
|
||||||
@ -100,7 +102,7 @@ namespace SPT_AKI_Installer.Aki.Core
|
|||||||
LogHelper.Error($"please delete folder called {dir.FullName}");
|
LogHelper.Error($"please delete folder called {dir.FullName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
//#endif
|
||||||
PatcherProcessStart(targetPath, akiRef);
|
PatcherProcessStart(targetPath, akiRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,11 +113,11 @@ namespace SPT_AKI_Installer.Aki.Core
|
|||||||
/// <param name="akiRef"></param>
|
/// <param name="akiRef"></param>
|
||||||
static void PatcherProcessStart(string targetPath, string akiRef)
|
static void PatcherProcessStart(string targetPath, string akiRef)
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
//#if !DEBUG
|
||||||
LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!");
|
LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!");
|
||||||
ProcessHelper patcherProcess = new();
|
ProcessHelper patcherProcess = new();
|
||||||
patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath);
|
patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath);
|
||||||
#endif
|
//#endif
|
||||||
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();
|
||||||
|
|
||||||
@ -130,12 +132,12 @@ namespace SPT_AKI_Installer.Aki.Core
|
|||||||
// if user input "yes" kill patcher process, delete patcher.exe, extract aki zip
|
// if user input "yes" kill patcher process, delete patcher.exe, extract aki zip
|
||||||
if (string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
//#if !DEBUG
|
||||||
patcherProcess.EndProcess();
|
patcherProcess.EndProcess();
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
FileHelper.DeleteFile("file", targetPath + "/patcher.exe");
|
FileHelper.DeleteFile("file", targetPath + "/patcher.exe");
|
||||||
ZipHelper.Decompress(akiRef, targetPath);
|
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.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();
|
||||||
|
@ -1,16 +1,90 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Spectre.Console;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace SPT_AKI_Installer.Aki.Helper
|
namespace SPT_AKI_Installer.Aki.Helper
|
||||||
{
|
{
|
||||||
public static class FileHelper
|
public static class FileHelper
|
||||||
{
|
{
|
||||||
|
public static int totalFiles;
|
||||||
/// <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>
|
||||||
public static void CopyDirectory(string oldDir, string newDir, bool recursive)
|
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);
|
var dir = new DirectoryInfo(oldDir);
|
||||||
|
|
||||||
@ -32,7 +106,7 @@ namespace SPT_AKI_Installer.Aki.Helper
|
|||||||
foreach (DirectoryInfo subDir in dirs)
|
foreach (DirectoryInfo subDir in dirs)
|
||||||
{
|
{
|
||||||
string newDestinationDir = Path.Combine(newDir, subDir.Name);
|
string newDestinationDir = Path.Combine(newDir, subDir.Name);
|
||||||
CopyDirectory(subDir.FullName, newDestinationDir, true);
|
AltCopyDirectory(subDir.FullName, newDestinationDir, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
Aki.Helper/SpectreHelper.cs
Normal file
20
Aki.Helper/SpectreHelper.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user