mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 07:40:13 +01:00
Fix #248
Move contents of old DownloadLocation and WorkingDirectory to new paths. Overwrite existing files, and add from oldPath.
This commit is contained in:
parent
77bb309dfa
commit
99df9a9dfd
@ -98,14 +98,13 @@ public static class TrangaSettings
|
|||||||
public static void UpdateDownloadLocation(string newPath, bool moveFiles = true)
|
public static void UpdateDownloadLocation(string newPath, bool moveFiles = true)
|
||||||
{
|
{
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
Directory.CreateDirectory(newPath,
|
Directory.CreateDirectory(newPath, GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
|
||||||
else
|
else
|
||||||
Directory.CreateDirectory(newPath);
|
Directory.CreateDirectory(newPath);
|
||||||
|
|
||||||
if (moveFiles && Directory.Exists(TrangaSettings.downloadLocation))
|
if (moveFiles)
|
||||||
Directory.Move(TrangaSettings.downloadLocation, newPath);
|
MoveContentsOfDirectoryTo(TrangaSettings.downloadLocation, newPath);
|
||||||
|
|
||||||
TrangaSettings.downloadLocation = newPath;
|
TrangaSettings.downloadLocation = newPath;
|
||||||
ExportSettings();
|
ExportSettings();
|
||||||
}
|
}
|
||||||
@ -113,15 +112,38 @@ public static class TrangaSettings
|
|||||||
public static void UpdateWorkingDirectory(string newPath)
|
public static void UpdateWorkingDirectory(string newPath)
|
||||||
{
|
{
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
Directory.CreateDirectory(newPath,
|
Directory.CreateDirectory(newPath, GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
|
||||||
else
|
else
|
||||||
Directory.CreateDirectory(newPath);
|
Directory.CreateDirectory(newPath);
|
||||||
Directory.Move(TrangaSettings.workingDirectory, newPath);
|
|
||||||
|
MoveContentsOfDirectoryTo(TrangaSettings.workingDirectory, newPath);
|
||||||
|
|
||||||
TrangaSettings.workingDirectory = newPath;
|
TrangaSettings.workingDirectory = newPath;
|
||||||
ExportSettings();
|
ExportSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void MoveContentsOfDirectoryTo(string oldDir, string newDir)
|
||||||
|
{
|
||||||
|
string[] directoryPaths = Directory.GetDirectories(oldDir);
|
||||||
|
string[] filePaths = Directory.GetFiles(oldDir);
|
||||||
|
foreach (string file in filePaths)
|
||||||
|
{
|
||||||
|
string newPath = Path.Join(newDir, Path.GetFileName(file));
|
||||||
|
File.Move(file, newPath, true);
|
||||||
|
}
|
||||||
|
foreach(string directory in directoryPaths)
|
||||||
|
{
|
||||||
|
string? dirName = Path.GetDirectoryName(directory);
|
||||||
|
if(dirName is null)
|
||||||
|
continue;
|
||||||
|
string newPath = Path.Join(newDir, dirName);
|
||||||
|
if(Directory.Exists(newPath))
|
||||||
|
MoveContentsOfDirectoryTo(directory, newPath);
|
||||||
|
else
|
||||||
|
Directory.Move(directory, newPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void UpdateUserAgent(string? customUserAgent)
|
public static void UpdateUserAgent(string? customUserAgent)
|
||||||
{
|
{
|
||||||
TrangaSettings.userAgent = customUserAgent ?? DefaultUserAgent;
|
TrangaSettings.userAgent = customUserAgent ?? DefaultUserAgent;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user