Core - Moved first run code to the static utility class

Core - Improved first run code, this closes #504
Storage - Fixed some migrations on fresh databases
This commit is contained in:
SpoinkyNL committed 2020-11-23 22:11:26 +01:00
1 parent 0c7583d3e4
commit 9e75131948
10 files changed
+124 -50

No files matched your search

+1
View File
@@ -53,6 +53,7 @@
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="System.Reflection.Metadata" Version="1.8.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
@@ -35,10 +35,6 @@ namespace Artemis.Core.Services
_logger = logger;
_pluginRepository = pluginRepository;
_plugins = new List<Plugin>();
// Ensure the plugins directory exists
if (!Directory.Exists(Constants.DataFolder + "plugins"))
Directory.CreateDirectory(Constants.DataFolder + "plugins");
}
private void CopyBuiltInPlugin(FileInfo zipFileInfo, ZipArchive zipArchive)
@@ -1,5 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
namespace Artemis.Core
{
@@ -8,6 +11,15 @@ namespace Artemis.Core
/// </summary>
public static class Utilities
{
/// <summary>
/// Call this before even initializing the Core to make sure the folders required for operation are in place
/// </summary>
public static void PrepareFirstLaunch()
{
CreateArtemisFolderIfMissing(Constants.DataFolder);
CreateArtemisFolderIfMissing(Constants.DataFolder + "plugins");
}
/// <summary>
/// Attempts to gracefully shut down the application with a delayed kill to ensure the application shut down
/// <para>
@@ -64,6 +76,28 @@ namespace Artemis.Core
return Process.GetCurrentProcess().MainModule!.FileName!;
}
private static void CreateArtemisFolderIfMissing(string path)
{
if (!Directory.Exists(path))
{
DirectoryInfo dataDirectory = Directory.CreateDirectory(path);
if (!OperatingSystem.IsWindows())
return;
// On Windows, ensure everyone has permission (important when running as admin)
DirectorySecurity security = dataDirectory.GetAccessControl();
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
security.AddAccessRule(new FileSystemAccessRule(
everyone,
FileSystemRights.Modify | FileSystemRights.Synchronize,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow)
);
dataDirectory.SetAccessControl(security);
}
}
#region Events
/// <summary>
+26 -2
View File
@@ -127,6 +127,16 @@
"resolved": "4.5.0",
"contentHash": "pL2ChpaRRWI/p4LXyy4RgeWlYF2sgfj/pnVMvBqwNFr5cXg7CXNnWZWxrOONLg8VGdFB8oB+EG2Qw4MLgTOe+A=="
},
"System.IO.FileSystem.AccessControl": {
"type": "Direct",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "SxHB3nuNrpptVk+vZ/F+7OHEpoHUIKKMl02bUmYHQr1r+glbZQxs7pRtsf4ENO29TVm2TH3AEeep2fJcy92oYw==",
"dependencies": {
"System.Security.AccessControl": "5.0.0",
"System.Security.Principal.Windows": "5.0.0"
}
},
"System.Numerics.Vectors": {
"type": "Direct",
"requested": "[4.5.0, )",
@@ -183,8 +193,8 @@
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
"resolved": "1.1.0",
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
"resolved": "5.0.0",
"contentHash": "VyPlqzH2wavqquTcYpkIIAQ6WdenuKoFN0BdYBbCWsclXacSOHNQn66Gt4z5NBqEYW0FAPm5rlvki9ZiCij5xQ=="
},
"Microsoft.NETCore.Targets": {
"type": "Transitive",
@@ -932,6 +942,15 @@
"System.Runtime.Extensions": "4.3.0"
}
},
"System.Security.AccessControl": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "dagJ1mHZO3Ani8GH0PHpPEe/oYO+rVdbQjvjJkBRNQkX4t0r1iaeGn8+/ybkSLEan3/slM0t59SVdHzuHf2jmw==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0",
"System.Security.Principal.Windows": "5.0.0"
}
},
"System.Security.Cryptography.Algorithms": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -1076,6 +1095,11 @@
"runtime.native.System.Security.Cryptography.OpenSsl": "4.3.0"
}
},
"System.Security.Principal.Windows": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "t0MGLukB5WAVU9bO3MGzvlGnyJPgUlcwerXn1kzBRjwLKixT96XV0Uza41W49gVd8zEMFu9vQEFlv0IOrytICA=="
},
"System.Text.Encoding": {
"type": "Transitive",
"resolved": "4.3.0",