|
|
@ -1,6 +1,7 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.EnsureThat;
|
|
|
|
using NzbDrone.Common.EnsureThat;
|
|
|
@ -28,6 +29,12 @@ namespace NzbDrone.Common.Extensions
|
|
|
|
|
|
|
|
|
|
|
|
public static string CleanFilePath(this string path)
|
|
|
|
public static string CleanFilePath(this string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (path.IsNotNullOrWhiteSpace())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Trim trailing spaces before checking if the path is valid so validation doesn't fail for something we can fix.
|
|
|
|
|
|
|
|
path = path.TrimEnd(' ');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure.That(path, () => path).IsNotNullOrWhiteSpace();
|
|
|
|
Ensure.That(path, () => path).IsNotNullOrWhiteSpace();
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.AnyOs);
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.AnyOs);
|
|
|
|
|
|
|
|
|
|
|
@ -36,10 +43,10 @@ namespace NzbDrone.Common.Extensions
|
|
|
|
// UNC
|
|
|
|
// UNC
|
|
|
|
if (!info.FullName.Contains('/') && info.FullName.StartsWith(@"\\"))
|
|
|
|
if (!info.FullName.Contains('/') && info.FullName.StartsWith(@"\\"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return info.FullName.TrimEnd('/', '\\', ' ');
|
|
|
|
return info.FullName.TrimEnd('/', '\\');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return info.FullName.TrimEnd('/').Trim('\\', ' ');
|
|
|
|
return info.FullName.TrimEnd('/').Trim('\\');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool PathNotEquals(this string firstPath, string secondPath, StringComparison? comparison = null)
|
|
|
|
public static bool PathNotEquals(this string firstPath, string secondPath, StringComparison? comparison = null)
|
|
|
@ -143,6 +150,23 @@ namespace NzbDrone.Common.Extensions
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (path.Trim() != path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var directoryInfo = new DirectoryInfo(path);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (directoryInfo != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (directoryInfo.Name.Trim() != directoryInfo.Name)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
directoryInfo = directoryInfo.Parent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (validationType == PathValidationType.AnyOs)
|
|
|
|
if (validationType == PathValidationType.AnyOs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return IsPathValidForWindows(path) || IsPathValidForNonWindows(path);
|
|
|
|
return IsPathValidForWindows(path) || IsPathValidForNonWindows(path);
|
|
|
@ -253,6 +277,11 @@ namespace NzbDrone.Common.Extensions
|
|
|
|
return processName;
|
|
|
|
return processName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static string CleanPath(this string path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Path.Join(path.Split(Path.DirectorySeparatorChar).Select(s => s.Trim()).ToArray());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetAppDataPath(this IAppFolderInfo appFolderInfo)
|
|
|
|
public static string GetAppDataPath(this IAppFolderInfo appFolderInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return appFolderInfo.AppDataFolder;
|
|
|
|
return appFolderInfo.AppDataFolder;
|
|
|
|