1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-10-30 05:42:47 +01:00
Minecraft-Phantom-Panel/Agent/Phantom.Agent.Services/AgentFolders.cs

49 lines
1.4 KiB
C#

using Phantom.Common.Logging;
using Phantom.Utils.IO;
using Serilog;
namespace Phantom.Agent.Services;
public sealed class AgentFolders {
private static readonly ILogger Logger = PhantomLogger.Create<AgentFolders>();
public string DataFolderPath { get; }
public string InstancesFolderPath { get; }
public string TemporaryFolderPath { get; }
public string ServerExecutableFolderPath { get; }
public string JavaSearchFolderPath { get; }
public AgentFolders(string dataFolderPath, string temporaryFolderPath, string javaSearchFolderPath) {
this.DataFolderPath = Path.GetFullPath(dataFolderPath);
this.InstancesFolderPath = Path.Combine(DataFolderPath, "instances");
this.TemporaryFolderPath = Path.GetFullPath(temporaryFolderPath);
this.ServerExecutableFolderPath = Path.Combine(TemporaryFolderPath, "servers");
this.JavaSearchFolderPath = javaSearchFolderPath;
}
public bool TryCreate() {
return TryCreateFolder(DataFolderPath) &&
TryCreateFolder(InstancesFolderPath) &&
TryCreateFolder(TemporaryFolderPath) &&
TryCreateFolder(ServerExecutableFolderPath);
}
private static bool TryCreateFolder(string folderPath) {
if (Directory.Exists(folderPath)) {
return true;
}
try {
Directories.Create(folderPath, Chmod.URWX_GRX);
return true;
} catch (Exception e) {
Logger.Fatal(e, "Error creating folder: {FolderPath}", folderPath);
return false;
}
}
}