mirror of
https://github.com/fiso64/slsk-batchdl.git
synced 2024-12-22 14:32:40 +00:00
fix move deleting file if same path
This commit is contained in:
parent
ed12ea9cc5
commit
4a34ec0cbd
3 changed files with 25 additions and 14 deletions
|
@ -101,7 +101,7 @@ public class FileManager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MoveAndDeleteParent(track.DownloadPath, newFilePath);
|
Utils.MoveAndDeleteParent(track.DownloadPath, newFilePath, config.parentDir);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ public class FileManager
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MoveAndDeleteParent(track.DownloadPath, newFilePath);
|
Utils.MoveAndDeleteParent(track.DownloadPath, newFilePath, config.parentDir);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -143,16 +143,6 @@ public class FileManager
|
||||||
organized.Add(track);
|
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)
|
string SubstituteValues(string format, Track track, Soulseek.File? slfile)
|
||||||
{
|
{
|
||||||
string newName = format;
|
string newName = format;
|
||||||
|
|
|
@ -256,7 +256,7 @@ static partial class Program
|
||||||
|
|
||||||
for (int i = 0; i < trackLists.lists.Count; i++)
|
for (int i = 0; i < trackLists.lists.Count; i++)
|
||||||
{
|
{
|
||||||
if (!enableParallelSearch) Console.WriteLine();
|
if (!enableParallelSearch && i > 0) Console.WriteLine();
|
||||||
|
|
||||||
var tle = trackLists[i];
|
var tle = trackLists[i];
|
||||||
var config = tle.config;
|
var config = tle.config;
|
||||||
|
|
|
@ -181,7 +181,13 @@ public static class Utils
|
||||||
if (File.Exists(sourceFilePath))
|
if (File.Exists(sourceFilePath))
|
||||||
{
|
{
|
||||||
if (File.Exists(destinationFilePath))
|
if (File.Exists(destinationFilePath))
|
||||||
|
{
|
||||||
|
if (Path.GetFullPath(sourceFilePath) == Path.GetFullPath(destinationFilePath))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
File.Delete(destinationFilePath);
|
File.Delete(destinationFilePath);
|
||||||
|
}
|
||||||
File.Move(sourceFilePath, 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)
|
public static bool EqualsAny(this string input, string[] values, StringComparison comparison = StringComparison.Ordinal)
|
||||||
{
|
{
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
|
@ -634,7 +650,12 @@ public static class Utils
|
||||||
if (string.IsNullOrEmpty(path))
|
if (string.IsNullOrEmpty(path))
|
||||||
return 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)
|
public static bool IsInDirectory(string path, string dir, bool strict)
|
||||||
|
|
Loading…
Reference in a new issue