improvements to module/theme installation and removal
This commit is contained in:
@ -7,6 +7,8 @@ using Oqtane.Shared;
|
||||
using Oqtane.Infrastructure;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
@ -15,11 +17,13 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
private readonly IThemeRepository Themes;
|
||||
private readonly IInstallationManager InstallationManager;
|
||||
private readonly IWebHostEnvironment environment;
|
||||
|
||||
public ThemeController(IThemeRepository Themes, IInstallationManager InstallationManager)
|
||||
public ThemeController(IThemeRepository Themes, IInstallationManager InstallationManager, IWebHostEnvironment environment)
|
||||
{
|
||||
this.Themes = Themes;
|
||||
this.InstallationManager = InstallationManager;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
@ -44,5 +48,32 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
InstallationManager.InstallPackages("Themes");
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/xxx
|
||||
[HttpDelete("{themename}")]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
public void Delete(string themename)
|
||||
{
|
||||
List<Theme> themes = Themes.GetThemes().ToList();
|
||||
Theme theme = themes.Where(item => item.ThemeName == themename).FirstOrDefault();
|
||||
if (theme != null)
|
||||
{
|
||||
themename = theme.ThemeName.Substring(0, theme.ThemeName.IndexOf(","));
|
||||
|
||||
string folder = Path.Combine(environment.WebRootPath, "Themes\\" + themename);
|
||||
if (Directory.Exists(folder))
|
||||
{
|
||||
Directory.Delete(folder, true);
|
||||
}
|
||||
|
||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
foreach (string file in Directory.EnumerateFiles(binfolder, themename + "*.dll"))
|
||||
{
|
||||
System.IO.File.Delete(file);
|
||||
}
|
||||
|
||||
InstallationManager.RestartApplication();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user