2
0

Added methods to Update Downloadlocation and WorkingDirectory

This commit is contained in:
glax 2023-08-27 01:00:42 +02:00
parent a94d3d6b40
commit 32349c1ddf

View File

@ -1,14 +1,16 @@
using Logging; using System.Runtime.InteropServices;
using Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Tranga.LibraryConnectors; using Tranga.LibraryConnectors;
using Tranga.NotificationConnectors; using Tranga.NotificationConnectors;
using static System.IO.UnixFileMode;
namespace Tranga; namespace Tranga;
public class TrangaSettings public class TrangaSettings
{ {
public string downloadLocation { get; private set; } public string downloadLocation { get; private set; }
public string workingDirectory { get; init; } public string workingDirectory { get; private set; }
public int apiPortNumber { get; init; } public int apiPortNumber { get; init; }
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json"); [JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json"); [JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
@ -34,6 +36,8 @@ public class TrangaSettings
this.downloadLocation = settings.downloadLocation; this.downloadLocation = settings.downloadLocation;
this.workingDirectory = settings.workingDirectory; this.workingDirectory = settings.workingDirectory;
} }
UpdateDownloadLocation(this.downloadLocation, false);
} }
public HashSet<LibraryConnector> LoadLibraryConnectors() public HashSet<LibraryConnector> LoadLibraryConnectors()
@ -64,6 +68,33 @@ public class TrangaSettings
})!; })!;
} }
public void UpdateDownloadLocation(string newPath, bool moveFiles = true)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Directory.CreateDirectory(newPath,
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
else
Directory.CreateDirectory(newPath);
if (moveFiles && Directory.Exists(this.downloadLocation))
Directory.Move(this.downloadLocation, newPath);
this.downloadLocation = newPath;
ExportSettings();
}
public void UpdateWorkingDirectory(string newPath)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Directory.CreateDirectory(newPath,
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
else
Directory.CreateDirectory(newPath);
Directory.Move(this.workingDirectory, newPath);
this.workingDirectory = newPath;
ExportSettings();
}
public void ExportSettings() public void ExportSettings()
{ {
while (File.Exists(settingsFilePath)) while (File.Exists(settingsFilePath))