From 616649e96a7567bd1918700ae8cd589fb5255fc7 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 18 Nov 2021 18:51:18 -0500 Subject: [PATCH] Implement sizeOfResources in Slot Closes #45 --- ProjectLighthouse/Helpers/FileHelper.cs | 2 ++ ProjectLighthouse/Types/Levels/Slot.cs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Helpers/FileHelper.cs b/ProjectLighthouse/Helpers/FileHelper.cs index f519effa..92084b7c 100644 --- a/ProjectLighthouse/Helpers/FileHelper.cs +++ b/ProjectLighthouse/Helpers/FileHelper.cs @@ -78,6 +78,8 @@ namespace LBPUnion.ProjectLighthouse.Helpers public static bool ResourceExists(string hash) => File.Exists(GetResourcePath(hash)); + public static int ResourceSize(string hash) => (int)new FileInfo(GetResourcePath(hash)).Length; + public static void EnsureDirectoryCreated(string path) { if (!Directory.Exists(path)) Directory.CreateDirectory(path ?? throw new ArgumentNullException(nameof(path))); diff --git a/ProjectLighthouse/Types/Levels/Slot.cs b/ProjectLighthouse/Types/Levels/Slot.cs index f21c7240..ff0c580e 100644 --- a/ProjectLighthouse/Types/Levels/Slot.cs +++ b/ProjectLighthouse/Types/Levels/Slot.cs @@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Xml.Serialization; +using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Types.Profiles; @@ -195,7 +196,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels public string SerializeResources() { - return this.Resources.Aggregate("", (current, resource) => current + LbpSerializer.StringElement("resource", resource)); + return this.Resources.Aggregate("", (current, resource) => current + LbpSerializer.StringElement("resource", resource)) + + LbpSerializer.StringElement("sizeOfResources", this.Resources.Sum(FileHelper.ResourceSize)); } public string Serialize(RatedLevel? yourRatingStats = null, VisitedLevel? yourVisitedStats = null)