using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Reflection; using System.Text.Json; using Artemis.Core.JsonConverters; using Artemis.Storage.Entities.Plugins; namespace Artemis.Core; /// /// A few useful constant values /// public static class Constants { /// /// The Artemis.Core assembly /// public static readonly Assembly CoreAssembly = typeof(Constants).Assembly; /// /// The full path to the Artemis application folder /// public static readonly string ApplicationFolder = Path.GetDirectoryName(typeof(Constants).Assembly.Location)!; /// /// The full path to the Artemis executable /// public static readonly string ExecutablePath = Utilities.GetCurrentLocation(); /// /// The base path for Artemis application data folder /// public static readonly string BaseFolder = Environment.GetFolderPath(OperatingSystem.IsWindows() ? Environment.SpecialFolder.CommonApplicationData : Environment.SpecialFolder.LocalApplicationData); /// /// The full path to the Artemis data folder /// #if DEBUG public static readonly string DataFolder = Path.Combine(BaseFolder, "Artemis-dev"); #else public static readonly string DataFolder = Path.Combine(BaseFolder, "Artemis"); #endif /// /// The full path to the Artemis logs folder /// public static readonly string LogsFolder = Path.Combine(DataFolder, "Logs"); /// /// The full path to the Artemis logs folder /// public static readonly string UpdatingFolder = Path.Combine(DataFolder, "updating"); /// /// The full path to the Artemis plugins folder /// public static readonly string PluginsFolder = Path.Combine(DataFolder, "Plugins"); /// /// The full path to the Artemis user layouts folder /// public static readonly string LayoutsFolder = Path.Combine(DataFolder, "User Layouts"); /// /// The full path to the Artemis user layouts folder /// public static readonly string WorkshopFolder = Path.Combine(DataFolder, "workshop"); /// /// The current API version for plugins /// public static readonly int PluginApiVersion = int.Parse(CoreAssembly.GetCustomAttributes().FirstOrDefault(a => a.Key == "PluginApiVersion")?.Value ?? throw new InvalidOperationException("Cannot find PluginApiVersion metadata in assembly")); /// /// The current version of the application /// public static readonly string CurrentVersion = CoreAssembly.GetCustomAttribute()!.InformationalVersion.StartsWith("1.0.0") ? "local" : CoreAssembly.GetCustomAttribute()!.InformationalVersion; /// /// The plugin info used by core components of Artemis /// public static readonly PluginInfo CorePluginInfo = new() { Guid = Guid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff"), Name = "Artemis Core", Version = CurrentVersion }; /// /// The plugin used by core components of Artemis /// public static readonly Plugin CorePlugin = new(CorePluginInfo, new DirectoryInfo(ApplicationFolder), new PluginEntity(){PluginGuid = CorePluginInfo.Guid}, false); /// /// A read-only collection containing all primitive numeric types /// public static IReadOnlyCollection NumberTypes = new List { typeof(sbyte), typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) }; /// /// A read-only collection containing all primitive integral numeric types /// public static IReadOnlyCollection IntegralNumberTypes = new List { typeof(sbyte), typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong) }; /// /// A read-only collection containing all primitive floating-point numeric types /// public static IReadOnlyCollection FloatNumberTypes = new List { typeof(float), typeof(double), typeof(decimal) }; /// /// Gets the startup arguments provided to the application /// public static ReadOnlyCollection StartupArguments { get; set; } = null!; public static string? GetStartupRoute() { return StartupArguments.FirstOrDefault(a => a.StartsWith("--route=artemis://"))?.Split("--route=artemis://")[1]; } internal static readonly CorePluginFeature CorePluginFeature = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Core")}; internal static readonly EffectPlaceholderPlugin EffectPlaceholderPlugin = new() {Plugin = CorePlugin, Profiler = CorePlugin.GetProfiler("Feature - Effect Placeholder")}; internal static readonly JsonSerializerOptions JsonConvertSettings = new() {Converters = {new SKColorConverter(), new NumericJsonConverter()}}; }