add project
This commit is contained in:
107
Pilz.Administration/Packaging/UpdatePackageManager.cs
Normal file
107
Pilz.Administration/Packaging/UpdatePackageManager.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System.Collections.Generic;
|
||||
using global::System.IO;
|
||||
using global::System.Reflection;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
using Z.Collections.Extensions;
|
||||
using SM64_ROM_Manager.Updating.UpdateInstaller;
|
||||
|
||||
namespace SM64_ROM_Manager.Updating.Administration.Packaging
|
||||
{
|
||||
internal class UpdatePackageManager
|
||||
{
|
||||
|
||||
// F i e l d s
|
||||
|
||||
private UpdatePackageTemplate template;
|
||||
|
||||
// P r o p e r t i e s
|
||||
|
||||
public string FilesToCopyPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return template.FilesToCopyPath;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
template.FilesToCopyPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
// C o n s t r u c o t r s
|
||||
|
||||
public UpdatePackageManager()
|
||||
{
|
||||
NewTemplate();
|
||||
}
|
||||
|
||||
// F e a t u r e s
|
||||
|
||||
public void LoadTemplate(string filePath)
|
||||
{
|
||||
template = JObject.Parse(File.ReadAllText(filePath)).ToObject<UpdatePackageTemplate>();
|
||||
}
|
||||
|
||||
public void SaveTemplate(string filePath)
|
||||
{
|
||||
File.WriteAllText(filePath, JObject.FromObject(template).ToString());
|
||||
}
|
||||
|
||||
public void NewTemplate()
|
||||
{
|
||||
template = new UpdatePackageTemplate();
|
||||
}
|
||||
|
||||
public void ExportPackage(string path)
|
||||
{
|
||||
var exporter = new UpdatePackagePackager(template);
|
||||
exporter.Export(path);
|
||||
}
|
||||
|
||||
private bool CheckUpdateInstallerAddOn(string path)
|
||||
{
|
||||
var asm = Assembly.ReflectionOnlyLoadFrom(path);
|
||||
var t = asm.GetType($"{UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_NAMESPACE}.{UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_TYPE}", false);
|
||||
bool isSupported = false;
|
||||
if (t is object)
|
||||
{
|
||||
var mi = t.GetMethod(UpdateInstallerAddOnNameDefinitions.UPDATE_INSTALLER_ADDON_METHOD, BindingFlags.Static | BindingFlags.Public);
|
||||
if (mi is object)
|
||||
{
|
||||
var @params = mi.GetParameters();
|
||||
if (@params.Length == 1 && @params.GetType() == typeof(Dictionary<string, object>))
|
||||
{
|
||||
isSupported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
public bool AddUpdateInstallerAddOn(string path)
|
||||
{
|
||||
if (Conversions.ToBoolean(!template.UpdateInstallerAddOns.Contains(path) && CheckUpdateInstallerAddOn(path)))
|
||||
{
|
||||
template.UpdateInstallerAddOns.Add(path);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetAllUpdateInstallerÁddOn()
|
||||
{
|
||||
return template.UpdateInstallerAddOns;
|
||||
}
|
||||
|
||||
public void RemoveUpdateInstallerAddOn(string path)
|
||||
{
|
||||
template.UpdateInstallerAddOns.RemoveIfContains(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Pilz.Administration/Packaging/UpdatePackagePackager.cs
Normal file
52
Pilz.Administration/Packaging/UpdatePackagePackager.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using global::System.IO;
|
||||
using global::System.IO.Compression;
|
||||
using SM64_ROM_Manager.Updating.UpdateInstaller;
|
||||
using Z.IO.Extensions;
|
||||
|
||||
namespace SM64_ROM_Manager.Updating.Administration.Packaging
|
||||
{
|
||||
public class UpdatePackagePackager
|
||||
{
|
||||
public UpdatePackageTemplate UpdatePackageTemplate { get; set; }
|
||||
|
||||
public UpdatePackagePackager(UpdatePackageTemplate updatePackageTemplate)
|
||||
{
|
||||
UpdatePackageTemplate = updatePackageTemplate;
|
||||
}
|
||||
|
||||
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
|
||||
packageDir.Delete(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Pilz.Administration/Packaging/UpdatePackageTemplate.cs
Normal file
10
Pilz.Administration/Packaging/UpdatePackageTemplate.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SM64_ROM_Manager.Updating.Administration.Packaging
|
||||
{
|
||||
public class UpdatePackageTemplate
|
||||
{
|
||||
public string FilesToCopyPath { get; set; }
|
||||
public List<string> UpdateInstallerAddOns { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user