Refactor C# code to imperative, top-level statements style
Updated the existing C# code into a more modern, imperative and top-level statements style. This involves shortening the code by removing unnecessary parts like additional brackets and explicit namespace declarations. It's done to improve clarity and readability.
This commit is contained in:
parent
d6aaeda28c
commit
a8b91f4ee6
@ -4,10 +4,10 @@ using Avalonia.Markup.Xaml;
|
||||
using SPTInstaller.ViewModels;
|
||||
using SPTInstaller.Views;
|
||||
|
||||
namespace SPTInstaller
|
||||
namespace SPTInstaller;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
@ -25,5 +25,4 @@ namespace SPTInstaller
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SPTInstaller.Behaviors
|
||||
namespace SPTInstaller.Behaviors;
|
||||
|
||||
public class SpanBehavior : AvaloniaObject
|
||||
{
|
||||
public class SpanBehavior : AvaloniaObject
|
||||
{
|
||||
public static readonly AttachedProperty<bool> SpanProperty = AvaloniaProperty.RegisterAttached<SpanBehavior, Interactive, bool>("Span");
|
||||
|
||||
public static void SetSpan(AvaloniaObject element, bool value)
|
||||
@ -16,5 +16,4 @@ namespace SPTInstaller.Behaviors
|
||||
{
|
||||
return element.GetValue(SpanProperty);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
using SharpCompress;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Controllers
|
||||
namespace SPTInstaller.Controllers;
|
||||
|
||||
public class InstallController
|
||||
{
|
||||
public class InstallController
|
||||
{
|
||||
public event EventHandler<IProgressableTask> TaskChanged = delegate { };
|
||||
|
||||
private IPreCheck[] _preChecks { get; set; }
|
||||
@ -40,9 +40,8 @@ namespace SPTInstaller.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var result in requiredResults)
|
||||
if (requiredResults.Any(result => !result.Succeeded))
|
||||
{
|
||||
if (!result.Succeeded)
|
||||
return Result.FromError("Some required checks have failed");
|
||||
}
|
||||
|
||||
@ -64,5 +63,4 @@ namespace SPTInstaller.Controllers
|
||||
|
||||
return Result.FromSuccess("Install Complete. Happy Playing!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace SPTInstaller.Converters
|
||||
namespace SPTInstaller.Converters;
|
||||
|
||||
public class InvertedProgressConverter : IValueConverter
|
||||
{
|
||||
public class InvertedProgressConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if( value is int progress)
|
||||
@ -25,5 +24,4 @@ namespace SPTInstaller.Converters
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using SPTInstaller.Behaviors;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace SPTInstaller.CustomControls
|
||||
namespace SPTInstaller.CustomControls;
|
||||
|
||||
public class DistributedSpacePanel : Panel
|
||||
{
|
||||
public class DistributedSpacePanel : Panel
|
||||
{
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
var children = Children;
|
||||
@ -73,5 +72,4 @@ namespace SPTInstaller.CustomControls
|
||||
|
||||
return finalSize;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,10 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SPTInstaller.CustomControls
|
||||
namespace SPTInstaller.CustomControls;
|
||||
|
||||
public partial class PreCheckItem : UserControl
|
||||
{
|
||||
public partial class PreCheckItem : UserControl
|
||||
{
|
||||
public PreCheckItem()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -58,5 +54,4 @@ namespace SPTInstaller.CustomControls
|
||||
|
||||
public static readonly StyledProperty<bool> IsRequiredProperty =
|
||||
AvaloniaProperty.Register<PreCheckItem, bool>(nameof(IsRequired));
|
||||
}
|
||||
}
|
@ -2,10 +2,10 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SPTInstaller.CustomControls
|
||||
namespace SPTInstaller.CustomControls;
|
||||
|
||||
public partial class ProgressableTaskItem : UserControl
|
||||
{
|
||||
public partial class ProgressableTaskItem : UserControl
|
||||
{
|
||||
public ProgressableTaskItem()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -73,5 +73,4 @@ namespace SPTInstaller.CustomControls
|
||||
|
||||
public static readonly StyledProperty<IBrush> CompletedColorProperty =
|
||||
AvaloniaProperty.Register<ProgressableTaskItem, IBrush>(nameof(PendingColor));
|
||||
}
|
||||
}
|
@ -2,18 +2,16 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.CustomControls
|
||||
namespace SPTInstaller.CustomControls;
|
||||
|
||||
public partial class ProgressableTaskList : UserControl
|
||||
{
|
||||
public partial class ProgressableTaskList : UserControl
|
||||
{
|
||||
public ProgressableTaskList()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -93,5 +91,4 @@ namespace SPTInstaller.CustomControls
|
||||
.Subscribe(x => UpdateTaskProgress());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace SPTInstaller.CustomControls
|
||||
namespace SPTInstaller.CustomControls;
|
||||
|
||||
public partial class TaskDetails : UserControl
|
||||
{
|
||||
public partial class TaskDetails : UserControl
|
||||
{
|
||||
public TaskDetails()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -54,5 +54,4 @@ namespace SPTInstaller.CustomControls
|
||||
|
||||
public static readonly StyledProperty<bool> IndeterminateProgressProperty =
|
||||
AvaloniaProperty.Register<TaskDetails, bool>(nameof(IndeterminateProgress));
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SPTInstaller.CustomControls
|
||||
namespace SPTInstaller.CustomControls;
|
||||
|
||||
public partial class TitleBar : UserControl
|
||||
{
|
||||
public partial class TitleBar : UserControl
|
||||
{
|
||||
public TitleBar()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -73,5 +73,4 @@ namespace SPTInstaller.CustomControls
|
||||
get => GetValue(MinButtonCommandProperty);
|
||||
set => SetValue(MinButtonCommandProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,13 @@
|
||||
using HttpClientProgress;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Aki.Helper
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
public static class DownloadCacheHelper
|
||||
{
|
||||
public static class DownloadCacheHelper
|
||||
{
|
||||
private static HttpClient _httpClient = new HttpClient() { Timeout = TimeSpan.FromHours(1) };
|
||||
private static HttpClient _httpClient = new() { Timeout = TimeSpan.FromHours(1) };
|
||||
|
||||
private static string _cachePath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "spt-installer/cache");
|
||||
|
||||
@ -111,7 +108,7 @@ namespace SPTInstaller.Aki.Helper
|
||||
|
||||
public static async Task<FileInfo?> GetOrDownloadFileAsync(string fileName, string targetLink, IProgress<double> progress, string expectedHash = null)
|
||||
{
|
||||
FileInfo cacheFile = new FileInfo(Path.Join(_cachePath, fileName));
|
||||
var cacheFile = new FileInfo(Path.Join(_cachePath, fileName));
|
||||
|
||||
try
|
||||
{
|
||||
@ -128,7 +125,7 @@ namespace SPTInstaller.Aki.Helper
|
||||
|
||||
public static async Task<FileInfo?> GetOrDownloadFileAsync(string fileName, Stream fileDownloadStream, string expectedHash = null)
|
||||
{
|
||||
FileInfo cacheFile = new FileInfo(Path.Join(_cachePath, fileName));
|
||||
var cacheFile = new FileInfo(Path.Join(_cachePath, fileName));
|
||||
|
||||
try
|
||||
{
|
||||
@ -142,5 +139,4 @@ namespace SPTInstaller.Aki.Helper
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
using Gitea.Model;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
using Gitea.Model;
|
||||
|
||||
namespace SPTInstaller.Aki.Helper
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
public static class FileHashHelper
|
||||
{
|
||||
public static class FileHashHelper
|
||||
{
|
||||
public static string GetGiteaReleaseHash(Release release)
|
||||
public static string? GetGiteaReleaseHash(Release release)
|
||||
{
|
||||
var regex = Regex.Match(release.Body, @"Release Hash: (?<hash>\S+)");
|
||||
|
||||
@ -23,16 +21,14 @@ namespace SPTInstaller.Aki.Helper
|
||||
|
||||
public static bool CheckHash(FileInfo file, string expectedHash)
|
||||
{
|
||||
using (MD5 md5Service = MD5.Create())
|
||||
using (var sourceStream = file.OpenRead())
|
||||
{
|
||||
byte[] sourceHash = md5Service.ComputeHash(sourceStream);
|
||||
byte[] expectedHashBytes = Convert.FromBase64String(expectedHash);
|
||||
using var md5Service = MD5.Create();
|
||||
using var sourceStream = file.OpenRead();
|
||||
|
||||
bool matched = Enumerable.SequenceEqual(sourceHash, expectedHashBytes);
|
||||
var sourceHash = md5Service.ComputeHash(sourceStream);
|
||||
var expectedHashBytes = Convert.FromBase64String(expectedHash);
|
||||
|
||||
var matched = Enumerable.SequenceEqual(sourceHash, expectedHashBytes);
|
||||
|
||||
return matched;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,11 @@
|
||||
using ReactiveUI;
|
||||
using System.Text.RegularExpressions;
|
||||
using Serilog;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SPTInstaller.Aki.Helper
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
public static class FileHelper
|
||||
{
|
||||
public static class FileHelper
|
||||
{
|
||||
private static Result IterateDirectories(DirectoryInfo sourceDir, DirectoryInfo targetDir)
|
||||
{
|
||||
try
|
||||
@ -86,5 +83,4 @@ namespace SPTInstaller.Aki.Helper
|
||||
return Result.FromError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HttpClientProgress
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
public static class HttpClientProgressExtensions
|
||||
{
|
||||
public static class HttpClientProgressExtensions
|
||||
{
|
||||
public static async Task DownloadDataAsync(this HttpClient client, string requestUrl, Stream destination, IProgress<double> progress = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
using (var response = await client.GetAsync(requestUrl, HttpCompletionOption.ResponseHeadersRead))
|
||||
@ -53,5 +51,4 @@ namespace HttpClientProgress
|
||||
progress?.Report(totalBytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
using Microsoft.Win32;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32;
|
||||
using SPTInstaller.Models;
|
||||
|
||||
namespace SPTInstaller.Aki.Helper
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
public static class PreCheckHelper
|
||||
{
|
||||
public static class PreCheckHelper
|
||||
{
|
||||
private const string registryInstall = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov";
|
||||
|
||||
public static string DetectOriginalGamePath()
|
||||
@ -36,5 +34,4 @@ namespace SPTInstaller.Aki.Helper
|
||||
return Result.FromError($"File not found: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
using SPTInstaller.Models;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using SPTInstaller.Models;
|
||||
|
||||
namespace SPTInstaller.Aki.Helper
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
public enum PatcherExitCode
|
||||
{
|
||||
public enum PatcherExitCode
|
||||
{
|
||||
ProgramClosed = 0,
|
||||
Success = 10,
|
||||
EftExeNotFound = 11,
|
||||
@ -13,15 +12,16 @@ namespace SPTInstaller.Aki.Helper
|
||||
MissingFile = 13,
|
||||
MissingDir = 14,
|
||||
PatchFailed = 15
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProcessHelper
|
||||
{
|
||||
public static class ProcessHelper
|
||||
{
|
||||
public static Result PatchClientFiles(FileInfo executable, DirectoryInfo workingDir)
|
||||
{
|
||||
if (!executable.Exists || !workingDir.Exists)
|
||||
{
|
||||
return Result.FromError($"Could not find executable ({executable.Name}) or working directory ({workingDir.Name})");
|
||||
return Result.FromError(
|
||||
$"Could not find executable ({executable.Name}) or working directory ({workingDir.Name})");
|
||||
}
|
||||
|
||||
var process = new Process();
|
||||
@ -57,5 +57,4 @@ namespace SPTInstaller.Aki.Helper
|
||||
return Result.FromError("an unknown error occurred in the patcher");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
using Serilog;
|
||||
using Splat;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SPTInstaller.Helpers
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A helper class to handle simple service registration to Splat with constructor parameter injection
|
||||
/// </summary>
|
||||
/// <remarks>Splat only recognizes the registered types and doesn't account for interfaces :(</remarks>
|
||||
internal static class ServiceHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class to handle simple service registration to Splat with constructor parameter injection
|
||||
/// </summary>
|
||||
/// <remarks>Splat only recognizes the registered types and doesn't account for interfaces :(</remarks>
|
||||
internal static class ServiceHelper
|
||||
{
|
||||
private static bool TryRegisterInstance<T, T2>(object[] parameters = null)
|
||||
{
|
||||
var instance = Activator.CreateInstance(typeof(T2), parameters);
|
||||
@ -125,5 +124,4 @@ namespace SPTInstaller.Helpers
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
using SharpCompress.Archives;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Zip;
|
||||
using SharpCompress.Common;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace SPTInstaller.Aki.Helper
|
||||
namespace SPTInstaller.Helpers;
|
||||
|
||||
public static class ZipHelper
|
||||
{
|
||||
public static class ZipHelper
|
||||
{
|
||||
public static Result Decompress(FileInfo ArchivePath, DirectoryInfo OutputFolderPath, IProgress<double> progress = null)
|
||||
{
|
||||
try
|
||||
@ -20,7 +18,7 @@ namespace SPTInstaller.Aki.Helper
|
||||
|
||||
using var archive = ZipArchive.Open(ArchivePath);
|
||||
var totalEntries = archive.Entries.Where(entry => !entry.IsDirectory);
|
||||
int processedEntries = 0;
|
||||
var processedEntries = 0;
|
||||
|
||||
foreach (var entry in totalEntries)
|
||||
{
|
||||
@ -52,5 +50,4 @@ namespace SPTInstaller.Aki.Helper
|
||||
return Result.FromError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,12 @@
|
||||
using Serilog;
|
||||
using SPTInstaller.Aki.Helper;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using SPTInstaller.Helpers;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
|
||||
public class CopyClientTask : InstallerTaskBase
|
||||
{
|
||||
public class CopyClientTask : InstallerTaskBase
|
||||
{
|
||||
private InternalData _data;
|
||||
|
||||
public CopyClientTask(InternalData data) : base("Copy Client Files")
|
||||
@ -26,5 +23,4 @@ namespace SPTInstaller.Installer_Tasks
|
||||
|
||||
return FileHelper.CopyDirectoryWithProgress(originalGameDirInfo, targetInstallDirInfo, (message, progress) => { SetStatus(null, message, progress, null, true); });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
using CG.Web.MegaApiClient;
|
||||
using Newtonsoft.Json;
|
||||
using SPTInstaller.Aki.Helper;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using SPTInstaller.Helpers;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
|
||||
public class DownloadTask : InstallerTaskBase
|
||||
{
|
||||
public class DownloadTask : InstallerTaskBase
|
||||
{
|
||||
private InternalData _data;
|
||||
|
||||
public DownloadTask(InternalData data) : base("Download Files")
|
||||
@ -122,5 +120,4 @@ namespace SPTInstaller.Installer_Tasks
|
||||
|
||||
return Result.FromSuccess();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
using SPTInstaller.Aki.Helper;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System.Threading.Tasks;
|
||||
using SPTInstaller.Helpers;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
|
||||
public class InitializationTask : InstallerTaskBase
|
||||
{
|
||||
public class InitializationTask : InstallerTaskBase
|
||||
{
|
||||
private InternalData _data;
|
||||
|
||||
public InitializationTask(InternalData data) : base("Startup")
|
||||
@ -55,5 +55,4 @@ namespace SPTInstaller.Installer_Tasks
|
||||
|
||||
return Result.FromSuccess($"Current Game Version: {_data.OriginalGameVersion}");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks.PreChecks
|
||||
namespace SPTInstaller.Installer_Tasks.PreChecks;
|
||||
|
||||
public class NetCore6PreCheck : PreCheckBase
|
||||
{
|
||||
public class NetCore6PreCheck : PreCheckBase
|
||||
{
|
||||
public NetCore6PreCheck() : base(".Net Core 6 Desktop Runtime", false)
|
||||
{
|
||||
}
|
||||
@ -54,5 +53,4 @@ namespace SPTInstaller.Installer_Tasks.PreChecks
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using Microsoft.Win32;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks.PreChecks
|
||||
namespace SPTInstaller.Installer_Tasks.PreChecks;
|
||||
|
||||
public class NetFramework472PreCheck : PreCheckBase
|
||||
{
|
||||
public class NetFramework472PreCheck : PreCheckBase
|
||||
{
|
||||
public NetFramework472PreCheck() : base(".Net Framework 4.7.2", false)
|
||||
{
|
||||
}
|
||||
@ -42,5 +41,4 @@ namespace SPTInstaller.Installer_Tasks.PreChecks
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
using Gitea.Api;
|
||||
using Gitea.Client;
|
||||
using SPTInstaller.Aki.Helper;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using SPTInstaller.Helpers;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
|
||||
public class ReleaseCheckTask : InstallerTaskBase
|
||||
{
|
||||
public class ReleaseCheckTask : InstallerTaskBase
|
||||
{
|
||||
private InternalData _data;
|
||||
|
||||
public ReleaseCheckTask(InternalData data) : base("Release Checks")
|
||||
@ -85,5 +84,4 @@ namespace SPTInstaller.Installer_Tasks
|
||||
return Result.FromError($"Request Failed:\n{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
using SPTInstaller.Aki.Helper;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using SPTInstaller.Helpers;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
|
||||
public class SetupClientTask : InstallerTaskBase
|
||||
{
|
||||
public class SetupClientTask : InstallerTaskBase
|
||||
{
|
||||
private InternalData _data;
|
||||
|
||||
public SetupClientTask(InternalData data) : base("Setup Client")
|
||||
@ -84,5 +82,4 @@ namespace SPTInstaller.Installer_Tasks
|
||||
|
||||
return Result.FromSuccess("SPT is Setup. Happy Playing!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Installer_Tasks
|
||||
namespace SPTInstaller.Installer_Tasks;
|
||||
|
||||
internal class TestTask : InstallerTaskBase
|
||||
{
|
||||
internal class TestTask : InstallerTaskBase
|
||||
{
|
||||
public static TestTask FromRandomName() => new TestTask($"Test Task #{new Random().Next(0, 9999)}");
|
||||
|
||||
public TestTask(string name) : base(name)
|
||||
@ -15,14 +14,14 @@ namespace SPTInstaller.Installer_Tasks
|
||||
|
||||
public async override Task<IResult> TaskOperation()
|
||||
{
|
||||
int total = 4;
|
||||
TimeSpan interval = TimeSpan.FromSeconds(1);
|
||||
var total = 4;
|
||||
var interval = TimeSpan.FromSeconds(1);
|
||||
|
||||
for(int i = 0; i < total; i++)
|
||||
for(var i = 0; i < total; i++)
|
||||
{
|
||||
var count = i + 1;
|
||||
string progressMessage = $"Running Task: {Name}";
|
||||
int progress = (int)Math.Floor((double)count / total * 100);
|
||||
var progressMessage = $"Running Task: {Name}";
|
||||
var progress = (int)Math.Floor((double)count / total * 100);
|
||||
|
||||
SetStatus(progressMessage, $"Details: ({count}/{total})", progress);
|
||||
|
||||
@ -31,5 +30,4 @@ namespace SPTInstaller.Installer_Tasks
|
||||
|
||||
return Result.FromSuccess();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Interfaces
|
||||
namespace SPTInstaller.Interfaces;
|
||||
|
||||
public interface IPreCheck
|
||||
{
|
||||
public interface IPreCheck
|
||||
{
|
||||
public string Id { get; }
|
||||
public string Name { get; }
|
||||
public bool IsRequired { get; }
|
||||
@ -13,5 +13,4 @@ namespace SPTInstaller.Interfaces
|
||||
public bool Passed { get; }
|
||||
|
||||
public Task<IResult> RunCheck();
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Interfaces
|
||||
namespace SPTInstaller.Interfaces;
|
||||
|
||||
public interface IProgressableTask
|
||||
{
|
||||
public interface IProgressableTask
|
||||
{
|
||||
public string Id { get; }
|
||||
public string Name { get; }
|
||||
|
||||
@ -20,5 +20,4 @@ namespace SPTInstaller.Interfaces
|
||||
public bool ShowProgress { get; }
|
||||
|
||||
public Task<IResult> RunAsync();
|
||||
}
|
||||
}
|
@ -1,14 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SPTInstaller.Interfaces;
|
||||
|
||||
namespace SPTInstaller.Interfaces
|
||||
public interface IResult
|
||||
{
|
||||
public interface IResult
|
||||
{
|
||||
public bool Succeeded { get; }
|
||||
public string Message { get; }
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
namespace SPTInstaller.Models
|
||||
namespace SPTInstaller.Models;
|
||||
|
||||
public class DownloadMirror
|
||||
{
|
||||
public class DownloadMirror
|
||||
{
|
||||
public string Link { get; set; }
|
||||
public string Hash { get; set; }
|
||||
}
|
||||
}
|
@ -1,16 +1,12 @@
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI;
|
||||
using Serilog;
|
||||
using Splat;
|
||||
using SPTInstaller.Interfaces;
|
||||
using System;
|
||||
using System.Security;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Models
|
||||
namespace SPTInstaller.Models;
|
||||
|
||||
public abstract class InstallerTaskBase : ReactiveObject, IProgressableTask
|
||||
{
|
||||
public abstract class InstallerTaskBase : ReactiveObject, IProgressableTask
|
||||
{
|
||||
private string _id;
|
||||
public string Id
|
||||
{
|
||||
@ -179,5 +175,4 @@ namespace SPTInstaller.Models
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract Task<IResult> TaskOperation();
|
||||
}
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace SPTInstaller.Models
|
||||
namespace SPTInstaller.Models;
|
||||
|
||||
public class InternalData
|
||||
{
|
||||
public class InternalData
|
||||
{
|
||||
/// <summary>
|
||||
/// The folder to install SPT into
|
||||
/// </summary>
|
||||
@ -54,5 +53,4 @@ namespace SPTInstaller.Models
|
||||
/// Whether or not a patch is needed to downgrade the client files
|
||||
/// </summary>
|
||||
public bool PatchNeeded { get; set; }
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using ReactiveUI;
|
||||
using SPTInstaller.Interfaces;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.Models
|
||||
namespace SPTInstaller.Models;
|
||||
|
||||
public abstract class PreCheckBase : ReactiveObject, IPreCheck
|
||||
{
|
||||
public abstract class PreCheckBase : ReactiveObject, IPreCheck
|
||||
{
|
||||
private string _id;
|
||||
public string Id
|
||||
{
|
||||
@ -72,5 +71,4 @@ namespace SPTInstaller.Models
|
||||
}
|
||||
|
||||
public abstract Task<bool> CheckOperation();
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using SPTInstaller.Interfaces;
|
||||
|
||||
namespace SPTInstaller.Models
|
||||
namespace SPTInstaller.Models;
|
||||
|
||||
public class Result : IResult
|
||||
{
|
||||
public class Result : IResult
|
||||
{
|
||||
public bool Succeeded { get; private set; }
|
||||
|
||||
public string Message { get; private set; }
|
||||
@ -14,7 +14,6 @@ namespace SPTInstaller.Models
|
||||
Succeeded = succeeded;
|
||||
}
|
||||
|
||||
public static Result FromSuccess(string message = "") => new Result(message, true);
|
||||
public static Result FromError(string message) => new Result(message, false);
|
||||
}
|
||||
public static Result FromSuccess(string message = "") => new(message, true);
|
||||
public static Result FromError(string message) => new(message, false);
|
||||
}
|
@ -12,10 +12,10 @@ using SPTInstaller.Models;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SPTInstaller
|
||||
namespace SPTInstaller;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
@ -71,5 +71,4 @@ namespace SPTInstaller
|
||||
.LogToTrace()
|
||||
.UseReactiveUI();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using SPTInstaller.ViewModels;
|
||||
using System;
|
||||
|
||||
namespace SPTInstaller
|
||||
namespace SPTInstaller;
|
||||
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public IControl Build(object data)
|
||||
{
|
||||
var name = data.GetType().FullName!.Replace("ViewModel", "View");
|
||||
@ -24,5 +23,4 @@ namespace SPTInstaller
|
||||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,13 +4,12 @@ using SPTInstaller.Helpers;
|
||||
using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SPTInstaller.ViewModels
|
||||
namespace SPTInstaller.ViewModels;
|
||||
|
||||
public class InstallViewModel : ViewModelBase
|
||||
{
|
||||
public class InstallViewModel : ViewModelBase
|
||||
{
|
||||
private IProgressableTask _currentTask;
|
||||
public IProgressableTask CurrentTask
|
||||
{
|
||||
@ -18,8 +17,7 @@ namespace SPTInstaller.ViewModels
|
||||
set => this.RaiseAndSetIfChanged(ref _currentTask, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<InstallerTaskBase> MyTasks { get; set; }
|
||||
= new ObservableCollection<InstallerTaskBase>(ServiceHelper.GetAll<InstallerTaskBase>());
|
||||
public ObservableCollection<InstallerTaskBase> MyTasks { get; set; } = new(ServiceHelper.GetAll<InstallerTaskBase>());
|
||||
|
||||
public InstallViewModel(IScreen host) : base(host)
|
||||
{
|
||||
@ -34,5 +32,4 @@ namespace SPTInstaller.ViewModels
|
||||
NavigateTo(new MessageViewModel(HostScreen, result));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
using Avalonia;
|
||||
using ReactiveUI;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SPTInstaller.ViewModels
|
||||
namespace SPTInstaller.ViewModels;
|
||||
|
||||
public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScreen
|
||||
{
|
||||
public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScreen
|
||||
{
|
||||
public RoutingState Router { get; } = new RoutingState();
|
||||
public ViewModelActivator Activator { get; } = new ViewModelActivator();
|
||||
public RoutingState Router { get; } = new();
|
||||
public ViewModelActivator Activator { get; } = new();
|
||||
|
||||
private string _title;
|
||||
public string Title
|
||||
@ -46,5 +45,4 @@ namespace SPTInstaller.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ using Serilog;
|
||||
using SPTInstaller.Interfaces;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace SPTInstaller.ViewModels
|
||||
namespace SPTInstaller.ViewModels;
|
||||
|
||||
public class MessageViewModel : ViewModelBase
|
||||
{
|
||||
public class MessageViewModel : ViewModelBase
|
||||
{
|
||||
private bool _HasErrors;
|
||||
public bool HasErrors
|
||||
{
|
||||
@ -43,5 +43,4 @@ namespace SPTInstaller.ViewModels
|
||||
HasErrors = true;
|
||||
Log.Error(Message);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace SPTInstaller.ViewModels
|
||||
namespace SPTInstaller.ViewModels;
|
||||
|
||||
public class ViewModelBase : ReactiveObject, IActivatableViewModel, IRoutableViewModel
|
||||
{
|
||||
public class ViewModelBase : ReactiveObject, IActivatableViewModel, IRoutableViewModel
|
||||
{
|
||||
public ViewModelActivator Activator { get; } = new ViewModelActivator();
|
||||
public ViewModelActivator Activator { get; } = new();
|
||||
|
||||
public string? UrlPathSegment => Guid.NewGuid().ToString().Substring(0, 7);
|
||||
|
||||
@ -56,6 +55,4 @@ namespace SPTInstaller.ViewModels
|
||||
{
|
||||
HostScreen = Host;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.ReactiveUI;
|
||||
using SPTInstaller.ViewModels;
|
||||
|
||||
namespace SPTInstaller.Views
|
||||
namespace SPTInstaller.Views;
|
||||
|
||||
public partial class InstallView : ReactiveUserControl<InstallViewModel>
|
||||
{
|
||||
public partial class InstallView : ReactiveUserControl<InstallViewModel>
|
||||
{
|
||||
public InstallView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace SPTInstaller.Views
|
||||
namespace SPTInstaller.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.ReactiveUI;
|
||||
using SPTInstaller.ViewModels;
|
||||
|
||||
namespace SPTInstaller.Views
|
||||
namespace SPTInstaller.Views;
|
||||
|
||||
public partial class MessageView : ReactiveUserControl<MessageViewModel>
|
||||
{
|
||||
public partial class MessageView : ReactiveUserControl<MessageViewModel>
|
||||
{
|
||||
public MessageView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
using Avalonia.ReactiveUI;
|
||||
using SPTInstaller.ViewModels;
|
||||
|
||||
namespace SPTInstaller.Views
|
||||
namespace SPTInstaller.Views;
|
||||
|
||||
public partial class PreChecksView : ReactiveUserControl<PreChecksViewModel>
|
||||
{
|
||||
public partial class PreChecksView : ReactiveUserControl<PreChecksViewModel>
|
||||
{
|
||||
public PreChecksView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user