mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
feat: enhance asset extraction and configuration file handling in ControlSystem
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System;
|
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -579,23 +578,40 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
var zipFiles = applicationDirectory.GetFiles("assets*.zip");
|
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];
|
var zipFile = zipFiles[0];
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Found assets zip file: {zipFile:l}... Unzipping...", zipFile.FullName);
|
Debug.LogMessage(LogEventLevel.Information, "Found assets zip file: {zipFile:l}... Unzipping...", zipFile.FullName);
|
||||||
|
using (var archive = ZipFile.OpenRead(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);
|
foreach (var entry in archive.Entries)
|
||||||
Directory.Delete(Global.FilePathPrefix, true);
|
{
|
||||||
}
|
var destinationPath = Path.Combine(Global.FilePathPrefix, entry.FullName);
|
||||||
|
|
||||||
// recreating the directory
|
// If the entry is a directory, ensure it exists and skip extraction
|
||||||
Directory.CreateDirectory(Global.FilePathPrefix);
|
if (string.IsNullOrEmpty(entry.Name))
|
||||||
ZipFile.ExtractToDirectory(zipFile.FullName, Global.FilePathPrefix);
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Unzipped assets to: {Destination}", Global.FilePathPrefix);
|
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
|
// cleaning up zip files
|
||||||
@@ -606,11 +622,16 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
var jsonFiles = applicationDirectory.GetFiles("*configurationFile*.json");
|
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 jsonFile = jsonFiles[0];
|
||||||
var finalPath = Path.Combine(Global.FilePathPrefix, jsonFile.Name);
|
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))
|
if (File.Exists(finalPath))
|
||||||
{
|
{
|
||||||
@@ -620,13 +641,6 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
jsonFile.MoveTo(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 4.7.2|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 4.7.2|AnyCPU'">
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<DocumentationFile>bin\$(Configuration)\PepperDashEssentials.xml</DocumentationFile>
|
<DocumentationFile>bin\$(Configuration)\PepperDashEssentials.xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Example Configuration\EssentialsHuddleSpaceRoom\configurationFile-HuddleSpace-2-Source.json">
|
<None Include="Example Configuration\EssentialsHuddleSpaceRoom\configurationFile-HuddleSpace-2-Source.json">
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Crestron.SimplSharp.SDK.Program" Version="2.21.90" />
|
<PackageReference Include="Crestron.SimplSharp.SDK.Program" Version="2.21.90" />
|
||||||
|
<PackageReference Include="System.IO.Compression" Version="4.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PepperDash.Core\PepperDash.Core.csproj" />
|
<ProjectReference Include="..\PepperDash.Core\PepperDash.Core.csproj" />
|
||||||
|
|||||||
Reference in New Issue
Block a user