Formatting

This commit is contained in:
CWX
2025-02-07 22:47:47 +00:00
parent ed2ddc9526
commit efd8b360de
8 changed files with 48 additions and 37 deletions
+10 -8
View File
@@ -486,14 +486,16 @@ public class GameController(
continue;
}
fullProfile.SptData.Mods.Add(new ModDetails()
{
Author = mod.PackageJson.Author,
Version = mod.PackageJson.Version,
Name = mod.PackageJson.Name,
Url = mod.PackageJson.Url,
DateAdded = _timeUtil.GetTimeStamp()
});
fullProfile.SptData.Mods.Add(
new ModDetails
{
Author = mod.PackageJson.Author,
Version = mod.PackageJson.Version,
Name = mod.PackageJson.Name,
Url = mod.PackageJson.Url,
DateAdded = _timeUtil.GetTimeStamp()
}
);
}
}
@@ -223,7 +223,8 @@ public class LauncherController(
{
var profile = _profileHelper.GetFullProfile(sessionId);
if (profile?.SptData?.Mods is not null) {
if (profile?.SptData?.Mods is not null)
{
return getProfileModsGroupedByModName(profile?.SptData?.Mods);
}
@@ -234,8 +235,10 @@ public class LauncherController(
{
// Group all mods used by profile by name
var modsGroupedByName = new Dictionary<string, List<ModDetails>>();
foreach (var mod in profileMods) {
if (!modsGroupedByName.ContainsKey(mod.Name)) {
foreach (var mod in profileMods)
{
if (!modsGroupedByName.ContainsKey(mod.Name))
{
modsGroupedByName[mod.Name] = [];
}
@@ -244,13 +247,15 @@ public class LauncherController(
// Find the highest versioned mod and add to results array
var result = new List<ModDetails>();
foreach (var modName in modsGroupedByName) {
foreach (var modName in modsGroupedByName)
{
var modDatas = modsGroupedByName[modName.Key];
var modVersions = modDatas.Select((x) => x.Version);
var modVersions = modDatas.Select(x => x.Version);
// var highestVersion = MaxSatisfying(modVersions, "*"); ?? TODO: Node used SemVer here
var chosenVersion = modDatas.FirstOrDefault((x) => x.Name == modName.Key ); // && x.Version == highestVersion
if (chosenVersion is null) {
var chosenVersion = modDatas.FirstOrDefault(x => x.Name == modName.Key); // && x.Version == highestVersion
if (chosenVersion is null)
{
continue;
}
@@ -14,7 +14,7 @@ public record HealthTreatmentRequestData : InventoryBaseActionRequestData
}
/**
* Id of stack to take money from
* Id of stack to take money from
* Amount of money to take off player for treatment
*/
[JsonPropertyName("items")]
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;
namespace Core.Models.Spt.Mod;
namespace Core.Models.Spt.Mod;
public record PackageJsonData
{
+10 -2
View File
@@ -6,8 +6,16 @@ namespace Core.Models.Spt.Mod;
public class SptMod
{
[JsonPropertyName("PackageJson")]
public PackageJsonData PackageJson { get; set; }
public PackageJsonData PackageJson
{
get;
set;
}
[JsonPropertyName("Assembly")]
public Assembly Assembly { get; set; }
public Assembly Assembly
{
get;
set;
}
}
+14 -14
View File
@@ -15,6 +15,7 @@ public class BackupService
protected const string _profileDir = "./user/profiles";
protected readonly List<string> _activeServerMods;
protected ApplicationContext _applicationContext;
protected BackupConfig _backupConfig;
// Runs Init() every x minutes
@@ -23,7 +24,6 @@ public class BackupService
protected JsonUtil _jsonUtil;
protected ISptLogger<BackupService> _logger;
protected TimeUtil _timeUtil;
protected ApplicationContext _applicationContext;
public BackupService(
ISptLogger<BackupService> logger,
@@ -32,7 +32,7 @@ public class BackupService
ConfigServer configServer,
FileUtil fileUtil,
ApplicationContext applicationContext
)
)
{
_logger = logger;
_jsonUtil = jsonUtil;
@@ -77,10 +77,10 @@ public class BackupService
/**
* Initializes the backup process.
*
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
*
* @returns A promise that resolves when the backup process is complete.
*/
public void Init()
@@ -148,7 +148,7 @@ public class BackupService
/**
* Check to see if the backup service is enabled via the config.
*
*
* @returns True if enabled, false otherwise.
*/
protected bool IsEnabled()
@@ -169,7 +169,7 @@ public class BackupService
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
*
* @returns The target directory path for the backup.
*/
protected string GenerateBackupTargetDir()
@@ -180,7 +180,7 @@ public class BackupService
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
*
* @returns The formatted backup date string.
*/
protected string GenerateBackupDate()
@@ -192,10 +192,10 @@ public class BackupService
/**
* Cleans up old backups in the backup directory.
*
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected void CleanBackups()
@@ -232,7 +232,7 @@ public class BackupService
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to a List of sorted backup file paths.
*/
@@ -246,7 +246,7 @@ public class BackupService
/**
* Compares two backup folder names based on their extracted dates.
*
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
@@ -266,7 +266,7 @@ public class BackupService
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A DateTime object if the folder name is in the correct format, otherwise null.
*/
@@ -292,7 +292,7 @@ public class BackupService
/**
* Removes excess backups from the backup directory.
*
*
* @param backups - A List of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
@@ -312,7 +312,7 @@ public class BackupService
/**
* Get a List of active server mod details.
*
*
* @returns A List of mod names.
*/
protected List<string> GetActiveServerMods()
-1
View File
@@ -1,7 +1,6 @@
using System.Reflection;
using System.Text.Json;
using Core.Models.Spt.Mod;
using Core.Models.Utils;
namespace Server;
-1
View File
@@ -1,6 +1,5 @@
using System.Runtime;
using Core.Context;
using Core.Models.Enums;
using Core.Models.External;
using Core.Models.Spt.Config;
using Core.Servers;