1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Core - Replaced plugin folder mentions with a constant

Added linux support for opening a folder

Should also fix some case sensitive inconsistencies
This commit is contained in:
Diogo Trindade 2021-11-08 21:52:10 +00:00
parent 41171a5ade
commit 56f5b91f11
9 changed files with 32 additions and 13 deletions

View File

@ -29,6 +29,21 @@ namespace Artemis.Core
/// </summary> /// </summary>
public static readonly string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Artemis"); public static readonly string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Artemis");
/// <summary>
/// The full path to the Artemis logs folder
/// </summary>
public static readonly string LogsFolder = Path.Combine(DataFolder, "Logs");
/// <summary>
/// The full path to the Artemis plugins folder
/// </summary>
public static readonly string PluginsFolder = Path.Combine(DataFolder, "Plugins");
/// <summary>
/// The full path to the Artemis user layouts folder
/// </summary>
public static readonly string LayoutsFolder = Path.Combine(DataFolder, "User Layouts");
/// <summary> /// <summary>
/// The plugin info used by core components of Artemis /// The plugin info used by core components of Artemis
/// </summary> /// </summary>

View File

@ -79,7 +79,7 @@ namespace Artemis.Core.Ninject
private bool HasAccessToProtectedService(IRequest r) private bool HasAccessToProtectedService(IRequest r)
{ {
return r.ParentRequest != null && !r.ParentRequest.Service.Assembly.Location.StartsWith(Path.Combine(Constants.DataFolder, "plugins")); return r.ParentRequest != null && !r.ParentRequest.Service.Assembly.Location.StartsWith(Constants.PluginsFolder);
} }
} }
} }

View File

@ -13,7 +13,7 @@ namespace Artemis.Core.Ninject
private static readonly ILogger Logger = new LoggerConfiguration() private static readonly ILogger Logger = new LoggerConfiguration()
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.File(Path.Combine(Constants.DataFolder, "logs", "Artemis log-.log"), .WriteTo.File(Path.Combine(Constants.LogsFolder, "Artemis log-.log"),
rollingInterval: RollingInterval.Day, rollingInterval: RollingInterval.Day,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}") outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Console() .WriteTo.Console()

View File

@ -87,7 +87,7 @@ namespace Artemis.Core.DeviceProviders
/// <returns>The resulting Artemis layout</returns> /// <returns>The resulting Artemis layout</returns>
public virtual ArtemisLayout LoadUserLayout(ArtemisDevice device) public virtual ArtemisLayout LoadUserLayout(ArtemisDevice device)
{ {
string layoutDir = Path.Combine(Constants.DataFolder, "user layouts"); string layoutDir = Constants.LayoutsFolder;
string filePath = Path.Combine( string filePath = Path.Combine(
layoutDir, layoutDir,
device.RgbDevice.DeviceInfo.Manufacturer, device.RgbDevice.DeviceInfo.Manufacturer,

View File

@ -48,7 +48,7 @@ namespace Artemis.Core.Services
private void CopyBuiltInPlugin(ZipArchive zipArchive, string targetDirectory) private void CopyBuiltInPlugin(ZipArchive zipArchive, string targetDirectory)
{ {
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins", targetDirectory)); DirectoryInfo pluginDirectory = new(Path.Combine(Constants.PluginsFolder, targetDirectory));
bool createLockFile = File.Exists(Path.Combine(pluginDirectory.FullName, "artemis.lock")); bool createLockFile = File.Exists(Path.Combine(pluginDirectory.FullName, "artemis.lock"));
// Remove the old directory if it exists // Remove the old directory if it exists
@ -68,7 +68,7 @@ namespace Artemis.Core.Services
public void CopyBuiltInPlugins() public void CopyBuiltInPlugins()
{ {
OnCopyingBuildInPlugins(); OnCopyingBuildInPlugins();
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins")); DirectoryInfo pluginDirectory = new(Constants.PluginsFolder);
if (Directory.Exists(Path.Combine(pluginDirectory.FullName, "Artemis.Plugins.Modules.Overlay-29e3ff97"))) if (Directory.Exists(Path.Combine(pluginDirectory.FullName, "Artemis.Plugins.Modules.Overlay-29e3ff97")))
Directory.Delete(Path.Combine(pluginDirectory.FullName, "Artemis.Plugins.Modules.Overlay-29e3ff97"), true); Directory.Delete(Path.Combine(pluginDirectory.FullName, "Artemis.Plugins.Modules.Overlay-29e3ff97"), true);
@ -221,7 +221,7 @@ namespace Artemis.Core.Services
UnloadPlugins(); UnloadPlugins();
// Load the plugin assemblies into the plugin context // Load the plugin assemblies into the plugin context
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins")); DirectoryInfo pluginDirectory = new(Constants.PluginsFolder);
foreach (DirectoryInfo subDirectory in pluginDirectory.EnumerateDirectories()) foreach (DirectoryInfo subDirectory in pluginDirectory.EnumerateDirectories())
{ {
try try
@ -506,7 +506,7 @@ namespace Artemis.Core.Services
public Plugin ImportPlugin(string fileName) public Plugin ImportPlugin(string fileName)
{ {
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins")); DirectoryInfo pluginDirectory = new(Constants.PluginsFolder);
// Find the metadata file in the zip // Find the metadata file in the zip
using ZipArchive archive = ZipFile.OpenRead(fileName); using ZipArchive archive = ZipFile.OpenRead(fileName);

View File

@ -19,8 +19,8 @@ namespace Artemis.Core
public static void PrepareFirstLaunch() public static void PrepareFirstLaunch()
{ {
CreateAccessibleDirectory(Constants.DataFolder); CreateAccessibleDirectory(Constants.DataFolder);
CreateAccessibleDirectory(Path.Combine(Constants.DataFolder, "plugins")); CreateAccessibleDirectory(Constants.PluginsFolder);
CreateAccessibleDirectory(Path.Combine(Constants.DataFolder, "user layouts")); CreateAccessibleDirectory(Constants.LayoutsFolder);
} }
/// <summary> /// <summary>
@ -107,8 +107,12 @@ namespace Artemis.Core
{ {
if (OperatingSystem.IsWindows()) if (OperatingSystem.IsWindows())
Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", path); Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", path);
else if (OperatingSystem.IsMacOS())
Process.Start("open", path);
else if (OperatingSystem.IsLinux())
Process.Start("xdg-open", path);
else else
throw new PlatformNotSupportedException("Can't open folders yet on non-Windows systems Q.Q"); throw new PlatformNotSupportedException("Can't open folders on this platform");
} }
/// <summary> /// <summary>

View File

@ -69,7 +69,7 @@ namespace Artemis.UI.Avalonia.Screens.Plugins.ViewModels
{ {
try try
{ {
Utilities.OpenFolder(Path.Combine(Constants.DataFolder, "logs")); Utilities.OpenFolder(Constants.LogsFolder);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -215,7 +215,7 @@ namespace Artemis.UI.Avalonia.Screens.Plugins.ViewModels
{ {
try try
{ {
Utilities.OpenFolder(Path.Combine(Constants.DataFolder, "logs")); Utilities.OpenFolder(Constants.LogsFolder);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -118,7 +118,7 @@ namespace Artemis.UI.Avalonia.Screens.Settings.Tabs.ViewModels
private void ExecuteShowLogs() private void ExecuteShowLogs()
{ {
OpenFolder(Path.Combine(Constants.DataFolder, "Logs")); OpenFolder(Constants.LogsFolder);
} }
#endregion #endregion