small code refactoring

This commit is contained in:
Schedel Pascal
2024-06-19 08:10:16 +02:00
parent 20770bed31
commit c9216ac79b
93 changed files with 2753 additions and 5835 deletions

View File

@@ -1,52 +1,51 @@
using global::System.IO;
using global::System.IO.Compression;
using System.IO;
using System.IO.Compression;
using Pilz.Updating.UpdateInstaller;
using Z.IO.Extensions;
namespace Pilz.Updating.Administration.Packaging
namespace Pilz.Updating.Administration.Packaging;
public class UpdatePackagePackager
{
public class UpdatePackagePackager
public UpdatePackageTemplate UpdatePackageTemplate { get; set; }
public UpdatePackagePackager(UpdatePackageTemplate updatePackageTemplate)
{
public UpdatePackageTemplate UpdatePackageTemplate { get; set; }
UpdatePackageTemplate = updatePackageTemplate;
}
public UpdatePackagePackager(UpdatePackageTemplate updatePackageTemplate)
{
UpdatePackageTemplate = updatePackageTemplate;
}
public void Export(string exportPath)
{
string tempPath = MyPaths.GetMyAppDataPath();
var packageDir = new DirectoryInfo(Path.Combine(tempPath, "UpdatePackageCreation"));
public void Export(string exportPath)
{
string tempPath = MyPaths.GetMyAppDataPath();
var packageDir = new DirectoryInfo(Path.Combine(tempPath, "UpdatePackageCreation"));
// Ensure package directory exists and is empty
if (packageDir.Exists)
packageDir.Delete(true);
packageDir.Create();
// Copy local data to temp data directory
var dataDir = packageDir.CreateSubdirectory(PackageFileNameDefinations.ZIP_APP_DATA_FILES_DIRECTORY);
var localDataDir = new DirectoryInfo(UpdatePackageTemplate.FilesToCopyPath);
localDataDir.CopyTo(dataDir.FullName, SearchOption.AllDirectories);
// Copy all UpdateInstaller AddOns
var addOnsDir = packageDir.CreateSubdirectory(PackageFileNameDefinations.ZIP_UPDATE_INSTALLER_ADDONS_DIRECTORY);
uint curAddOnID = 0;
foreach (string fAddOn in UpdatePackageTemplate.UpdateInstallerAddOns)
{
File.Copy(fAddOn, Path.Combine(addOnsDir.FullName, $"installer_addon_{curAddOnID}.dll"));
curAddOnID += 1;
}
// Ensure destination file doesn't exist
if (File.Exists(exportPath))
File.Delete(exportPath);
// Export to ZIP
ZipFile.CreateFromDirectory(packageDir.FullName, exportPath);
// Delete temp directory
// Ensure package directory exists and is empty
if (packageDir.Exists)
packageDir.Delete(true);
packageDir.Create();
// Copy local data to temp data directory
var dataDir = packageDir.CreateSubdirectory(PackageFileNameDefinations.ZIP_APP_DATA_FILES_DIRECTORY);
var localDataDir = new DirectoryInfo(UpdatePackageTemplate.FilesToCopyPath);
localDataDir.CopyTo(dataDir.FullName, SearchOption.AllDirectories);
// Copy all UpdateInstaller AddOns
var addOnsDir = packageDir.CreateSubdirectory(PackageFileNameDefinations.ZIP_UPDATE_INSTALLER_ADDONS_DIRECTORY);
uint curAddOnID = 0;
foreach (string fAddOn in UpdatePackageTemplate.UpdateInstallerAddOns)
{
File.Copy(fAddOn, Path.Combine(addOnsDir.FullName, $"installer_addon_{curAddOnID}.dll"));
curAddOnID += 1;
}
// Ensure destination file doesn't exist
if (File.Exists(exportPath))
File.Delete(exportPath);
// Export to ZIP
ZipFile.CreateFromDirectory(packageDir.FullName, exportPath);
// Delete temp directory
packageDir.Delete(true);
}
}