ran code cleanup

This commit is contained in:
IsWaffle 2022-07-09 13:14:03 -04:00
parent b999f3cb4c
commit 96b6964165
16 changed files with 82 additions and 183 deletions

View File

@ -1,9 +1,5 @@
using Spectre.Console; using Spectre.Console;
using SPT_AKI_Installer.Aki.Core.Model; using SPT_AKI_Installer.Aki.Core.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SPT_AKI_Installer.Aki.Core.Interfaces namespace SPT_AKI_Installer.Aki.Core.Interfaces

View File

@ -1,10 +1,4 @@
using System; namespace SPT_AKI_Installer.Aki.Core.Interfaces
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SPT_AKI_Installer.Aki.Core.Interfaces
{ {
internal interface IProgressableTask internal interface IProgressableTask
{ {

View File

@ -1,7 +1,6 @@
using Spectre.Console; using Spectre.Console;
using SPT_AKI_Installer.Aki.Core.Interfaces; using SPT_AKI_Installer.Aki.Core.Interfaces;
using System; using System;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -62,11 +62,11 @@ namespace SPT_AKI_Installer.Aki.Core.Model
var result = await RunAllTasksAsync(tasks, context, table); var result = await RunAllTasksAsync(tasks, context, table);
// if a task failed and returned early, set any remaining task status to cancelled // if a task failed and returned early, set any remaining task status to cancelled
if(!result.Item1) if (!result.Item1)
{ {
var cancelledTasks = tasks.Take(new Range(tasks.IndexOf(result.Item2)+1, tasks.Count)); var cancelledTasks = tasks.Take(new Range(tasks.IndexOf(result.Item2) + 1, tasks.Count));
foreach(var task in cancelledTasks) foreach (var task in cancelledTasks)
{ {
task.SetStatus("[grey]Cancelled[/]"); task.SetStatus("[grey]Cancelled[/]");
} }

View File

@ -1,12 +1,12 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;
using Spectre.Console; using Spectre.Console;
using System.IO;
using SPT_AKI_Installer.Aki.Core.Model; using SPT_AKI_Installer.Aki.Core.Model;
using SPT_AKI_Installer.Aki.Core.Tasks; using SPT_AKI_Installer.Aki.Core.Tasks;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace SPT_AKI_Installer.Aki.Core namespace SPT_AKI_Installer.Aki.Core
{ {

View File

@ -1,11 +1,11 @@
using Newtonsoft.Json; using CG.Web.MegaApiClient;
using Newtonsoft.Json;
using SPT_AKI_Installer.Aki.Core.Model; using SPT_AKI_Installer.Aki.Core.Model;
using SPT_AKI_Installer.Aki.Helper; using SPT_AKI_Installer.Aki.Helper;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using CG.Web.MegaApiClient;
namespace SPT_AKI_Installer.Aki.Core.Tasks namespace SPT_AKI_Installer.Aki.Core.Tasks
{ {
@ -70,7 +70,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
return GenericResult.FromSuccess(); return GenericResult.FromSuccess();
} }
catch(Exception) catch (Exception)
{ {
//most likely a 509 (Bandwidth limit exceeded) due to mega's user quotas. //most likely a 509 (Bandwidth limit exceeded) due to mega's user quotas.
continue; continue;
@ -79,7 +79,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
var result = await DownloadHelper.DownloadFile(_data.PatcherZipInfo, mirror, progress); var result = await DownloadHelper.DownloadFile(_data.PatcherZipInfo, mirror, progress);
if(result.Succeeded) if (result.Succeeded)
{ {
return GenericResult.FromSuccess(); return GenericResult.FromSuccess();
} }
@ -91,7 +91,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
public override async Task<GenericResult> RunAsync() public override async Task<GenericResult> RunAsync()
{ {
_data.PatcherZipInfo = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.zip")); _data.PatcherZipInfo = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.zip"));
_data.AkiZipInfo= new FileInfo(Path.Join(_data.TargetInstallPath, "sptaki.zip")); _data.AkiZipInfo = new FileInfo(Path.Join(_data.TargetInstallPath, "sptaki.zip"));
if (_data.PatchNeeded) if (_data.PatchNeeded)
{ {

View File

@ -1,6 +1,5 @@
using SPT_AKI_Installer.Aki.Core.Model; using SPT_AKI_Installer.Aki.Core.Model;
using SPT_AKI_Installer.Aki.Helper; using SPT_AKI_Installer.Aki.Helper;
using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -67,7 +67,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
string status = $"Current Release: {latestAkiVersion}"; string status = $"Current Release: {latestAkiVersion}";
if(_data.PatchNeeded) if (_data.PatchNeeded)
{ {
status += " - Patch Available"; status += " - Patch Available";
} }

View File

@ -27,7 +27,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
var extractPatcherResult = ZipHelper.Decompress(_data.PatcherZipInfo, patcherOutputDir, extractPatcherProgress); var extractPatcherResult = ZipHelper.Decompress(_data.PatcherZipInfo, patcherOutputDir, extractPatcherProgress);
if(!extractPatcherResult.Succeeded) if (!extractPatcherResult.Succeeded)
{ {
return extractPatcherResult; return extractPatcherResult;
} }
@ -42,7 +42,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
var copyPatcherResult = FileHelper.CopyDirectoryWithProgress(patcherDirInfo, targetInstallDirInfo, copyPatcherProgress); var copyPatcherResult = FileHelper.CopyDirectoryWithProgress(patcherDirInfo, targetInstallDirInfo, copyPatcherProgress);
if(!copyPatcherResult.Succeeded) if (!copyPatcherResult.Succeeded)
{ {
return copyPatcherResult; return copyPatcherResult;
} }
@ -55,7 +55,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
var patchingResult = ProcessHelper.PatchClientFiles(patcherEXE, targetInstallDirInfo); var patchingResult = ProcessHelper.PatchClientFiles(patcherEXE, targetInstallDirInfo);
if(!patchingResult.Succeeded) if (!patchingResult.Succeeded)
{ {
return patchingResult; return patchingResult;
} }
@ -68,7 +68,7 @@ namespace SPT_AKI_Installer.Aki.Core.Tasks
var extractReleaseResult = ZipHelper.Decompress(_data.AkiZipInfo, targetInstallDirInfo, extractReleaseProgress); var extractReleaseResult = ZipHelper.Decompress(_data.AkiZipInfo, targetInstallDirInfo, extractReleaseProgress);
if(!extractReleaseResult.Succeeded) if (!extractReleaseResult.Succeeded)
{ {
return extractPatcherResult; return extractPatcherResult;
} }

View File

@ -1,9 +1,9 @@
using System; using HttpClientProgress;
using SPT_AKI_Installer.Aki.Core.Model;
using System;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using HttpClientProgress;
using SPT_AKI_Installer.Aki.Core.Model;
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
@ -25,14 +25,14 @@ namespace SPT_AKI_Installer.Aki.Helper
outputFile.Refresh(); outputFile.Refresh();
if(!outputFile.Exists) if (!outputFile.Exists)
{ {
return GenericResult.FromError($"Failed to download {outputFile.Name}"); return GenericResult.FromError($"Failed to download {outputFile.Name}");
} }
return GenericResult.FromSuccess(); return GenericResult.FromSuccess();
} }
catch(Exception ex) catch (Exception ex)
{ {
return GenericResult.FromError(ex.Message); return GenericResult.FromError(ex.Message);
} }

View File

@ -1,7 +1,6 @@
using System; using SPT_AKI_Installer.Aki.Core.Model;
using System;
using System.IO; using System.IO;
using Spectre.Console;
using SPT_AKI_Installer.Aki.Core.Model;
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
@ -29,73 +28,10 @@ namespace SPT_AKI_Installer.Aki.Helper
return GenericResult.FromSuccess(); return GenericResult.FromSuccess();
} }
catch(Exception ex) catch (Exception ex)
{ {
return GenericResult.FromError(ex.Message); return GenericResult.FromError(ex.Message);
} }
} }
public static void DeleteFiles(string filePath, bool allFolders = false)
{
if (File.Exists(filePath) || Directory.Exists(filePath))
{
if (filePath.Contains('.'))
{
File.Delete(filePath);
}
else
{
Directory.Delete(filePath, allFolders);
}
}
}
public static string FindFile(string path, string name)
{
string[] filePaths = Directory.GetFiles(path);
foreach (string file in filePaths)
{
if (file.Contains(name, StringComparison.OrdinalIgnoreCase))
{
return file;
}
}
return null;
}
public static string FindFile(string path, string name, string altName)
{
string[] filePaths = Directory.GetFiles(path);
foreach (string file in filePaths)
{
if (file.Contains(name, StringComparison.OrdinalIgnoreCase) &&
file.Contains(altName, StringComparison.OrdinalIgnoreCase))
{
return file;
}
}
return null;
}
public static bool FindFolder(string patchRef, string targetPath, out DirectoryInfo dir)
{
var dirInfo = new DirectoryInfo(targetPath).GetDirectories();
string patchInner = null;
foreach (var file in dirInfo)
{
if (file.FullName.Contains("patcher", StringComparison.OrdinalIgnoreCase))
{
patchInner = file.FullName;
}
}
var path = new DirectoryInfo(patchInner);
if (path.Exists)
{
dir = path;
return true;
}
dir = null;
return false;
}
} }
} }

View File

@ -1,7 +1,7 @@
using Microsoft.Win32; using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
@ -26,30 +26,5 @@ namespace SPT_AKI_Installer.Aki.Helper
{ {
return FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe")).ProductVersion.Replace('-', '.').Split('.')[^2]; return FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe")).ProductVersion.Replace('-', '.').Split('.')[^2];
} }
//public static string GetPatcherZipPath(string gameVersion, string targetPath)
//{
// // example patch name - Patcher.12.12.15.17861.to.12.12.15.17349.zip
// var patchZip = FileHelper.FindFile(targetPath, gameVersion, "Patcher");
// if (patchZip == null)
// {
// patchZip = FileHelper.FindFile(targetPath, "PATCHERZIP");
// }
// return patchZip;
//}
//public static string GetAkiZipPath(string targetPath)
//{
// // example aki name - RELEASE-SPT-2.3.1-17349.zip
// var akiZip = FileHelper.FindFile(targetPath, "SPT", "RELEASE");
// if (akiZip == null)
// {
// akiZip = FileHelper.FindFile(targetPath, "AKIZIP");
// }
// return akiZip;
//}
} }
} }

View File

@ -1,6 +1,6 @@
using System.Diagnostics; using SPT_AKI_Installer.Aki.Core.Model;
using System.Diagnostics;
using System.IO; using System.IO;
using SPT_AKI_Installer.Aki.Core.Model;
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
@ -19,7 +19,7 @@ namespace SPT_AKI_Installer.Aki.Helper
{ {
public static GenericResult PatchClientFiles(FileInfo executable, DirectoryInfo workingDir) public static GenericResult PatchClientFiles(FileInfo executable, DirectoryInfo workingDir)
{ {
if(!executable.Exists || !workingDir.Exists) if (!executable.Exists || !workingDir.Exists)
{ {
return GenericResult.FromError($"Could not find executable ({executable.Name}) or working directory ({workingDir.Name})"); return GenericResult.FromError($"Could not find executable ({executable.Name}) or working directory ({workingDir.Name})");
} }

View File

@ -40,14 +40,14 @@ namespace SPT_AKI_Installer.Aki.Helper
OutputFolderPath.Refresh(); OutputFolderPath.Refresh();
if(!OutputFolderPath.Exists) if (!OutputFolderPath.Exists)
{ {
return GenericResult.FromError($"Failed to extract files: {ArchivePath.Name}"); return GenericResult.FromError($"Failed to extract files: {ArchivePath.Name}");
} }
return GenericResult.FromSuccess(); return GenericResult.FromSuccess();
} }
catch(Exception ex) catch (Exception ex)
{ {
return GenericResult.FromError(ex.Message); return GenericResult.FromError(ex.Message);
} }