1
0
Fork 0
mirror of https://github.com/fiso64/slsk-batchdl.git synced 2024-12-22 06:22:41 +00:00

fix move deleting file if same path

This commit is contained in:
fiso64 2024-12-21 21:47:06 +01:00
parent ed12ea9cc5
commit 4a34ec0cbd
3 changed files with 25 additions and 14 deletions

View file

@ -101,7 +101,7 @@ public class FileManager
try
{
MoveAndDeleteParent(track.DownloadPath, newFilePath);
Utils.MoveAndDeleteParent(track.DownloadPath, newFilePath, config.parentDir);
}
catch (Exception ex)
{
@ -130,7 +130,7 @@ public class FileManager
try
{
MoveAndDeleteParent(track.DownloadPath, newFilePath);
Utils.MoveAndDeleteParent(track.DownloadPath, newFilePath, config.parentDir);
}
catch (Exception ex)
{
@ -142,16 +142,6 @@ public class FileManager
organized.Add(track);
}
void MoveAndDeleteParent(string oldPath, string newPath)
{
if (Utils.NormalizedPath(oldPath) != Utils.NormalizedPath(newPath))
{
Directory.CreateDirectory(Path.GetDirectoryName(newPath));
Utils.Move(oldPath, newPath);
Utils.DeleteAncestorsIfEmpty(Path.GetDirectoryName(oldPath), config.parentDir);
}
}
string SubstituteValues(string format, Track track, Soulseek.File? slfile)
{

View file

@ -256,7 +256,7 @@ static partial class Program
for (int i = 0; i < trackLists.lists.Count; i++)
{
if (!enableParallelSearch) Console.WriteLine();
if (!enableParallelSearch && i > 0) Console.WriteLine();
var tle = trackLists[i];
var config = tle.config;

View file

@ -181,7 +181,13 @@ public static class Utils
if (File.Exists(sourceFilePath))
{
if (File.Exists(destinationFilePath))
{
if (Path.GetFullPath(sourceFilePath) == Path.GetFullPath(destinationFilePath))
{
return;
}
File.Delete(destinationFilePath);
}
File.Move(sourceFilePath, destinationFilePath);
}
}
@ -206,6 +212,16 @@ public static class Utils
}
}
public static void MoveAndDeleteParent(string oldPath, string newPath, string recurseUntil)
{
if (Path.GetFullPath(oldPath) != Path.GetFullPath(newPath))
{
Directory.CreateDirectory(Path.GetDirectoryName(newPath));
Move(oldPath, newPath);
DeleteAncestorsIfEmpty(Path.GetDirectoryName(oldPath), recurseUntil);
}
}
public static bool EqualsAny(this string input, string[] values, StringComparison comparison = StringComparison.Ordinal)
{
foreach (var value in values)
@ -634,7 +650,12 @@ public static class Utils
if (string.IsNullOrEmpty(path))
return path;
return path.Replace('\\', '/').TrimEnd('/').Trim();
path = path.Replace('\\', '/').TrimEnd('/').Trim();
while (path.Contains("//"))
path = path.Replace("//", "/");
return path;
}
public static bool IsInDirectory(string path, string dir, bool strict)