From 1a366790e74cf461a0e95ec7614beddafc98b7fb Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Mon, 11 Aug 2025 16:23:31 -0400 Subject: [PATCH 1/2] feat: add LoadAssets method to manage asset loading and configuration file cleanup --- src/PepperDash.Essentials/ControlSystem.cs | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 3da56d8b..2fbcb091 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -1,5 +1,6 @@  using System; +using System.IO.Compression; using System.Linq; using System.Reflection; using Crestron.SimplSharp; @@ -267,6 +268,8 @@ namespace PepperDash.Essentials // _ = new ProcessorExtensionDeviceFactory(); // _ = new MobileControlFactory(); + LoadAssets(); + Debug.LogMessage(LogEventLevel.Information, "Starting Essentials load from configuration"); var filesReady = SetupFilesystem(); @@ -568,5 +571,62 @@ namespace PepperDash.Essentials return false; } } + + private static void LoadAssets() + { + var applicationDirectory = new DirectoryInfo(Global.ApplicationDirectoryPathPrefix); + Debug.LogMessage(LogEventLevel.Information, "Searching: {applicationDirectory:l} for embedded assets - {Destination}", applicationDirectory.FullName, Global.FilePathPrefix); + + var zipFiles = applicationDirectory.GetFiles("assets*.zip"); + + if (zipFiles.Length > 0) + { + var zipFile = zipFiles[0]; + Debug.LogMessage(LogEventLevel.Information, "Found assets zip file: {zipFile:l}... Unzipping...", zipFile.FullName); + + // deleting the directory here as the net472 version of unzip doesn't have an overwrite capability + // this is the most deterministic mvp + if (Directory.Exists(Global.FilePathPrefix)) + { + Debug.LogMessage(LogEventLevel.Information, "Removing existing config directory: {Destination}", Global.FilePathPrefix); + Directory.Delete(Global.FilePathPrefix, true); + } + + // recreating the directory + Directory.CreateDirectory(Global.FilePathPrefix); + ZipFile.ExtractToDirectory(zipFile.FullName, Global.FilePathPrefix); + Debug.LogMessage(LogEventLevel.Information, "Unzipped assets to: {Destination}", Global.FilePathPrefix); + } + + // cleaning up zip files + foreach (var file in zipFiles) + { + File.Delete(file.FullName); + } + + var jsonFiles = applicationDirectory.GetFiles("*configurationFile*.json"); + + if (jsonFiles.Length > 0) + { + var jsonFile = jsonFiles[0]; + var finalPath = Path.Combine(Global.FilePathPrefix, jsonFile.Name); + Debug.LogMessage(LogEventLevel.Information, "Found configuration file: {jsonFile:l}... Moving to: {Destination}", jsonFile, finalPath); + + if (File.Exists(finalPath)) + { + Debug.LogMessage(LogEventLevel.Information, "Removing existing configuration file: {Destination}", finalPath); + File.Delete(finalPath); + } + + jsonFile.MoveTo(finalPath); + } + + // Remove any old configuration files that weren't moved + foreach (var file in Directory.GetFiles(Global.ApplicationDirectoryPathPrefix, "configurationFile*.json")) + { + Debug.LogMessage(LogEventLevel.Information, "Removing old configuration file: {file:l}", file); + File.Delete(file); + } + } } } From 033aa1f3dddafa97925277664c3786cd0b9a2979 Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Tue, 12 Aug 2025 12:17:58 -0400 Subject: [PATCH 2/2] feat: enhance asset extraction and configuration file handling in ControlSystem --- src/PepperDash.Essentials/ControlSystem.cs | 60 ++++++++++++------- .../PepperDash.Essentials.csproj | 7 ++- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 2fbcb091..9e97767c 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -1,5 +1,4 @@ - -using System; +using System; using System.IO.Compression; using System.Linq; using System.Reflection; @@ -579,23 +578,40 @@ namespace PepperDash.Essentials var zipFiles = applicationDirectory.GetFiles("assets*.zip"); - if (zipFiles.Length > 0) + if (zipFiles.Length > 1) + { + throw new Exception("Multiple assets zip files found. Cannot continue."); + } + + if (zipFiles.Length == 1) { var zipFile = zipFiles[0]; Debug.LogMessage(LogEventLevel.Information, "Found assets zip file: {zipFile:l}... Unzipping...", zipFile.FullName); - - // deleting the directory here as the net472 version of unzip doesn't have an overwrite capability - // this is the most deterministic mvp - if (Directory.Exists(Global.FilePathPrefix)) + using (var archive = ZipFile.OpenRead(zipFile.FullName)) { - Debug.LogMessage(LogEventLevel.Information, "Removing existing config directory: {Destination}", Global.FilePathPrefix); - Directory.Delete(Global.FilePathPrefix, true); - } + foreach (var entry in archive.Entries) + { + var destinationPath = Path.Combine(Global.FilePathPrefix, entry.FullName); - // recreating the directory - Directory.CreateDirectory(Global.FilePathPrefix); - ZipFile.ExtractToDirectory(zipFile.FullName, Global.FilePathPrefix); - Debug.LogMessage(LogEventLevel.Information, "Unzipped assets to: {Destination}", Global.FilePathPrefix); + // If the entry is a directory, ensure it exists and skip extraction + if (string.IsNullOrEmpty(entry.Name)) + { + Directory.CreateDirectory(destinationPath); + continue; + } + + // If a directory exists where a file should go, delete it + if (Directory.Exists(destinationPath)) + Directory.Delete(destinationPath, true); + + // Ensure the parent directory exists + Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)); + + entry.ExtractToFile(destinationPath, true); + + Debug.LogMessage(LogEventLevel.Information, "Extracted: {entry:l} to {Destination}", entry.FullName, destinationPath); + } + } } // cleaning up zip files @@ -606,11 +622,16 @@ namespace PepperDash.Essentials var jsonFiles = applicationDirectory.GetFiles("*configurationFile*.json"); - if (jsonFiles.Length > 0) + if (jsonFiles.Length > 1) + { + throw new Exception("Multiple configuration files found. Cannot continue."); + } + + if (jsonFiles.Length == 1) { var jsonFile = jsonFiles[0]; var finalPath = Path.Combine(Global.FilePathPrefix, jsonFile.Name); - Debug.LogMessage(LogEventLevel.Information, "Found configuration file: {jsonFile:l}... Moving to: {Destination}", jsonFile, finalPath); + Debug.LogMessage(LogEventLevel.Information, "Found configuration file: {jsonFile:l}... Moving to: {Destination}", jsonFile.FullName, finalPath); if (File.Exists(finalPath)) { @@ -620,13 +641,6 @@ namespace PepperDash.Essentials jsonFile.MoveTo(finalPath); } - - // Remove any old configuration files that weren't moved - foreach (var file in Directory.GetFiles(Global.ApplicationDirectoryPathPrefix, "configurationFile*.json")) - { - Debug.LogMessage(LogEventLevel.Information, "Removing old configuration file: {file:l}", file); - File.Delete(file); - } } } } diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index 1ddd8e54..20a42ffd 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -20,9 +20,9 @@ full - - pdbonly - bin\$(Configuration)\PepperDashEssentials.xml + + pdbonly + bin\$(Configuration)\PepperDashEssentials.xml @@ -49,6 +49,7 @@ +