Merge pull request #715 from sbwalker/master
improved module/theme installation by saving the list of files which are in the Nuget package and using that list to remove them during uninstall
This commit is contained in:
commit
4effa8ec66
@ -15,6 +15,7 @@ using System;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -110,6 +111,7 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
|
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
|
||||||
|
|
||||||
|
// execute uninstall logic
|
||||||
foreach (Tenant tenant in _tenants.GetTenants())
|
foreach (Tenant tenant in _tenants.GetTenants())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -131,24 +133,27 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use assets.json to clean up file resources
|
||||||
|
string assetfilepath = Path.Combine(_environment.WebRootPath, "Modules", Utilities.GetTypeName(moduledefinition.ModuleDefinitionName), "assets.json");
|
||||||
|
if (System.IO.File.Exists(assetfilepath))
|
||||||
|
{
|
||||||
|
List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(assetfilepath));
|
||||||
|
foreach(string asset in assets)
|
||||||
|
{
|
||||||
|
if (System.IO.File.Exists(asset))
|
||||||
|
{
|
||||||
|
System.IO.File.Delete(asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assets Removed For {ModuleDefinitionName}", moduledefinition.ModuleDefinitionName);
|
||||||
|
}
|
||||||
|
|
||||||
// clean up module static resource folder
|
// clean up module static resource folder
|
||||||
string folder = Path.Combine(_environment.WebRootPath, Path.Combine("Modules", Utilities.GetTypeName(moduledefinition.ModuleDefinitionName)));
|
string folder = Path.Combine(_environment.WebRootPath, Path.Combine("Modules", Utilities.GetTypeName(moduledefinition.ModuleDefinitionName)));
|
||||||
if (Directory.Exists(folder))
|
if (Directory.Exists(folder))
|
||||||
{
|
{
|
||||||
Directory.Delete(folder, true);
|
Directory.Delete(folder, true);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Static Resources Removed For {ModuleDefinitionName}", moduledefinition.ModuleDefinitionName);
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Resources Folder Removed For {ModuleDefinitionName}", moduledefinition.ModuleDefinitionName);
|
||||||
}
|
|
||||||
|
|
||||||
// get root assembly name ( note that this only works if modules follow a specific naming convention for their assemblies )
|
|
||||||
string assemblyname = Utilities.GetAssemblyName(moduledefinition.ModuleDefinitionName).ToLower();
|
|
||||||
assemblyname = assemblyname.Replace(".client", "").Replace(".oqtane", "");
|
|
||||||
|
|
||||||
// remove module assemblies from /bin
|
|
||||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
|
||||||
foreach (string file in Directory.EnumerateFiles(binfolder, assemblyname + "*.*"))
|
|
||||||
{
|
|
||||||
System.IO.File.Delete(file);
|
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assembly {Filename} Removed For {ModuleDefinitionName}", file, moduledefinition.ModuleDefinitionName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove module definition
|
// remove module definition
|
||||||
|
@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Oqtane.Enums;
|
using Oqtane.Enums;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
using Oqtane.Repository;
|
using Oqtane.Repository;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||||
|
|
||||||
@ -56,19 +57,29 @@ namespace Oqtane.Controllers
|
|||||||
Theme theme = themes.Where(item => item.ThemeName == themename).FirstOrDefault();
|
Theme theme = themes.Where(item => item.ThemeName == themename).FirstOrDefault();
|
||||||
if (theme != null && Utilities.GetAssemblyName(theme.ThemeName) != "Oqtane.Client")
|
if (theme != null && Utilities.GetAssemblyName(theme.ThemeName) != "Oqtane.Client")
|
||||||
{
|
{
|
||||||
|
// use assets.json to clean up file resources
|
||||||
|
string assetfilepath = Path.Combine(_environment.WebRootPath, "Modules", Utilities.GetTypeName(theme.ThemeName), "assets.json");
|
||||||
|
if (System.IO.File.Exists(assetfilepath))
|
||||||
|
{
|
||||||
|
List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(assetfilepath));
|
||||||
|
foreach (string asset in assets)
|
||||||
|
{
|
||||||
|
if (System.IO.File.Exists(asset))
|
||||||
|
{
|
||||||
|
System.IO.File.Delete(asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Assets Removed For {ThemeName}", theme.ThemeName);
|
||||||
|
}
|
||||||
|
|
||||||
// clean up theme static resource folder
|
// clean up theme static resource folder
|
||||||
string folder = Path.Combine(_environment.WebRootPath, "Themes" , Utilities.GetTypeName(theme.ThemeName));
|
string folder = Path.Combine(_environment.WebRootPath, "Themes" , Utilities.GetTypeName(theme.ThemeName));
|
||||||
if (Directory.Exists(folder))
|
if (Directory.Exists(folder))
|
||||||
{
|
{
|
||||||
Directory.Delete(folder, true);
|
Directory.Delete(folder, true);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Static Resources Removed For {ThemeName}", theme.ThemeName);
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Resource Folder Removed For {ThemeName}", theme.ThemeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove theme assembly from /bin
|
|
||||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
|
||||||
System.IO.File.Delete(Path.Combine(binfolder, Utilities.GetAssemblyName(theme.ThemeName) + ".dll"));
|
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Theme Assembly {Filename} Removed For {ThemeName}", Utilities.GetAssemblyName(theme.ThemeName) + ".dll", themename);
|
|
||||||
|
|
||||||
_installationManager.RestartApplication();
|
_installationManager.RestartApplication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
@ -80,6 +82,8 @@ namespace Oqtane.Infrastructure
|
|||||||
// if compatible with framework version
|
// if compatible with framework version
|
||||||
if (frameworkversion == "" || Version.Parse(Constants.Version).CompareTo(Version.Parse(frameworkversion)) >= 0)
|
if (frameworkversion == "" || Version.Parse(Constants.Version).CompareTo(Version.Parse(frameworkversion)) >= 0)
|
||||||
{
|
{
|
||||||
|
List<string> assets = new List<string>();
|
||||||
|
|
||||||
// module and theme packages must be in form of name.1.0.0.nupkg
|
// module and theme packages must be in form of name.1.0.0.nupkg
|
||||||
string name = Path.GetFileNameWithoutExtension(packagename);
|
string name = Path.GetFileNameWithoutExtension(packagename);
|
||||||
string[] segments = name?.Split('.');
|
string[] segments = name?.Split('.');
|
||||||
@ -96,18 +100,32 @@ namespace Oqtane.Infrastructure
|
|||||||
case "lib":
|
case "lib":
|
||||||
filename = Path.Combine(binFolder, filename);
|
filename = Path.Combine(binFolder, filename);
|
||||||
ExtractFile(entry, filename);
|
ExtractFile(entry, filename);
|
||||||
|
assets.Add(filename);
|
||||||
break;
|
break;
|
||||||
case "wwwroot":
|
case "wwwroot":
|
||||||
filename = Path.Combine(webRootPath.Replace(Path.DirectorySeparatorChar + "wwwroot", ""), Utilities.PathCombine(entry.FullName.Split('/')));
|
filename = Path.Combine(webRootPath.Replace(Path.DirectorySeparatorChar + "wwwroot", ""), Utilities.PathCombine(entry.FullName.Split('/')));
|
||||||
ExtractFile(entry, filename);
|
ExtractFile(entry, filename);
|
||||||
|
assets.Add(filename);
|
||||||
break;
|
break;
|
||||||
case "runtimes":
|
case "runtimes":
|
||||||
var destSubFolder = Path.GetDirectoryName(entry.FullName);
|
var destSubFolder = Path.GetDirectoryName(entry.FullName);
|
||||||
filename = Path.Combine(binFolder, destSubFolder, filename);
|
filename = Path.Combine(binFolder, destSubFolder, filename);
|
||||||
ExtractFile(entry, filename);
|
ExtractFile(entry, filename);
|
||||||
|
assets.Add(filename);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save list of assets
|
||||||
|
if (assets.Count != 0)
|
||||||
|
{
|
||||||
|
string assetfilepath = Path.Combine(webRootPath, "Modules", name, "assets.json");
|
||||||
|
if (File.Exists(assetfilepath))
|
||||||
|
{
|
||||||
|
File.Delete(assetfilepath);
|
||||||
|
}
|
||||||
|
File.WriteAllText(assetfilepath, JsonSerializer.Serialize(assets));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user