add cleanup task
This commit is contained in:
parent
abb18028f9
commit
d64595e2f9
@ -5,8 +5,8 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyVersion>1.3.6</AssemblyVersion>
|
||||
<FileVersion>1.3.6</FileVersion>
|
||||
<AssemblyVersion>1.3.8</AssemblyVersion>
|
||||
<FileVersion>1.3.8</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
6
EftPatchHelper/EftPatchHelper/Interfaces/ICleanupTask.cs
Normal file
6
EftPatchHelper/EftPatchHelper/Interfaces/ICleanupTask.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace EftPatchHelper.Interfaces
|
||||
{
|
||||
public interface ICleanupTask : ITaskable
|
||||
{
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ namespace EftPatchHelper
|
||||
{
|
||||
ITaskable _settingsTasks;
|
||||
ITaskable _clientSelectionTasks;
|
||||
ITaskable _cleanupTasks;
|
||||
ITaskable _fileProcessingTasks;
|
||||
ITaskable _patchGenTasks;
|
||||
ITaskable _patchTestingTasks;
|
||||
@ -36,6 +37,7 @@ namespace EftPatchHelper
|
||||
public Program(
|
||||
ISettingsTask settingsTasks,
|
||||
IClientSelectionTask clientSelectionTasks,
|
||||
ICleanupTask cleanupTasks,
|
||||
IFileProcessingTasks fileProcessingTasks,
|
||||
IPatchGenTasks patchGenTasks,
|
||||
IPatchTestingTasks patchTestingTasks,
|
||||
@ -45,6 +47,7 @@ namespace EftPatchHelper
|
||||
{
|
||||
_settingsTasks = settingsTasks;
|
||||
_clientSelectionTasks = clientSelectionTasks;
|
||||
_cleanupTasks = cleanupTasks;
|
||||
_fileProcessingTasks = fileProcessingTasks;
|
||||
_patchGenTasks = patchGenTasks;
|
||||
_patchTestingTasks = patchTestingTasks;
|
||||
@ -56,6 +59,7 @@ namespace EftPatchHelper
|
||||
{
|
||||
_settingsTasks.Run();
|
||||
_clientSelectionTasks.Run();
|
||||
_cleanupTasks.Run();
|
||||
_fileProcessingTasks.Run();
|
||||
_patchGenTasks.Run();
|
||||
_patchTestingTasks.Run();
|
||||
@ -79,6 +83,7 @@ namespace EftPatchHelper
|
||||
services.AddScoped<EftClientSelector>();
|
||||
|
||||
services.AddTransient<ISettingsTask, StartupSettingsTask>();
|
||||
services.AddTransient<ICleanupTask, CleanupTask>();
|
||||
services.AddTransient<IClientSelectionTask, ClientSelectionTask>();
|
||||
services.AddTransient<IFileProcessingTasks, FileProcessingTasks>();
|
||||
services.AddTransient<IPatchGenTasks, PatchGenTasks>();
|
||||
|
105
EftPatchHelper/EftPatchHelper/Tasks/CleanupTask.cs
Normal file
105
EftPatchHelper/EftPatchHelper/Tasks/CleanupTask.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using EftPatchHelper.Interfaces;
|
||||
using EftPatchHelper.Model;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EftPatchHelper.Tasks
|
||||
{
|
||||
public class CleanupTask : ICleanupTask
|
||||
{
|
||||
private Settings _settings;
|
||||
private Options _options;
|
||||
|
||||
List<FileSystemInfo> _fileToRemove = new List<FileSystemInfo>();
|
||||
|
||||
public CleanupTask(Settings settings, Options options)
|
||||
{
|
||||
_settings = settings;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
private void GetPathsToRemove()
|
||||
{
|
||||
var prepFolders = Directory.GetDirectories(_settings.PrepFolderPath, "*");
|
||||
|
||||
foreach (var prepFolder in prepFolders)
|
||||
{
|
||||
if (prepFolder == _options.TargetClient.PrepPath)
|
||||
continue;
|
||||
|
||||
_fileToRemove.Add(new DirectoryInfo(prepFolder));
|
||||
}
|
||||
|
||||
var mirrorsPath = Path.Join(Environment.CurrentDirectory, "mirrors.json");
|
||||
var hubentries = Directory.GetFiles(Environment.CurrentDirectory, "hubEntry_*.txt");
|
||||
|
||||
if (File.Exists(mirrorsPath))
|
||||
_fileToRemove.Add(new FileInfo(mirrorsPath));
|
||||
|
||||
_fileToRemove.AddRange(hubentries.Select(x => new FileInfo(x)));
|
||||
|
||||
var patcherDir = new FileInfo(_settings.PatcherEXEPath).Directory;
|
||||
|
||||
_fileToRemove.AddRange(patcherDir.GetFiles().Where(x => x.FullName != _settings.PatcherEXEPath));
|
||||
_fileToRemove.AddRange(patcherDir.GetDirectories("*", SearchOption.TopDirectoryOnly));
|
||||
}
|
||||
|
||||
private void RemoveData(Table table)
|
||||
{
|
||||
AnsiConsole.Live(table).Start(ctx =>
|
||||
{
|
||||
for (int i = 0; i < _fileToRemove.Count; i++)
|
||||
{
|
||||
table.UpdateCell(i, 0, "[white]Removing ...[/]");
|
||||
|
||||
ctx.Refresh();
|
||||
|
||||
var item = _fileToRemove[i];
|
||||
|
||||
if (item is DirectoryInfo dir)
|
||||
dir.Delete(true);
|
||||
|
||||
if (item is FileInfo file)
|
||||
file.Delete();
|
||||
|
||||
|
||||
table.UpdateCell(i, 0, item.Exists ? "[red]Exists[/]" : "[green]Removed[/]");
|
||||
ctx.Refresh();
|
||||
}
|
||||
});
|
||||
|
||||
AnsiConsole.Write(new Rule());
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
GetPathsToRemove();
|
||||
|
||||
if (_fileToRemove.Count == 0)
|
||||
return;
|
||||
|
||||
Table removableFilesTable = new Table()
|
||||
.Alignment(Justify.Center)
|
||||
.AddColumn("Status")
|
||||
.AddColumn("File Name")
|
||||
.AddColumn("Full Path")
|
||||
.BorderStyle(Style.Parse("blue"));
|
||||
|
||||
foreach (var file in _fileToRemove)
|
||||
{
|
||||
removableFilesTable.AddRow("[grey]Exists[/]", file.Name, file.FullName);
|
||||
}
|
||||
|
||||
var cursorPos = Console.GetCursorPosition();
|
||||
|
||||
AnsiConsole.Write(removableFilesTable);
|
||||
|
||||
|
||||
var removeFiles = new ConfirmationPrompt("Run cleanup to remove files shown above?").Show(AnsiConsole.Console);
|
||||
|
||||
Console.SetCursorPosition(cursorPos.Left, cursorPos.Top);
|
||||
|
||||
if (removeFiles)
|
||||
RemoveData(removableFilesTable);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user