All are Windows *.lnk files!

This commit is contained in:
Mike Phares 2023-12-25 20:41:22 -07:00
parent 6909146d90
commit 1355cd0241
3 changed files with 114 additions and 30 deletions

View File

@ -297,8 +297,7 @@ public partial class DlibDotNet
configurationOutputResolutionsHas = true;
if (!runToDoCollectionFirst)
break;
(filesCollectionRootDirectory, filesCollection) = GetFilesCollectionThenCopyOrMove(ticks, fileSearchFilter, directorySearchFilter, options, outputResolution);
filesCollectionCountIsOne = filesCollection.Count == 1;
(filesCollectionRootDirectory, filesCollection, filesCollectionCountIsOne) = GetFilesCollectionThenCopyOrMove(ticks, fileSearchFilter, directorySearchFilter, options, outputResolution);
notNineCollection = GetNotNineCollection(filesCollection);
break;
}
@ -416,6 +415,11 @@ public partial class DlibDotNet
{
bool result = false;
string[] directories;
directories = Directory.GetDirectories(_Configuration.PropertyConfiguration.RootDirectory, "*", SearchOption.TopDirectoryOnly);
if (directories.Length == 0)
result = true;
else
{
string seasonDirectory;
DirectoryInfo directoryInfo;
DateTime dateTime = new(ticks);
@ -451,6 +455,17 @@ public partial class DlibDotNet
}
}
}
}
if (result)
{
if (result)
{ }
}
if (!result)
{
if (!result)
{ }
}
return result;
}
@ -1216,7 +1231,55 @@ public partial class DlibDotNet
}
}
private (string, ReadOnlyCollection<string[]>) GetFilesCollectionThenCopyOrMove(long ticks, string fileSearchFilter, string directorySearchFilter, ProgressBarOptions options, string outputResolution)
private static void CheckForAllWindowsLinks(ReadOnlyCollection<string[]> filesCollection)
{
string fileFullPath;
WindowsShortcut windowsShortcut;
foreach (string[] files in filesCollection)
{
if (files.Length == 0)
continue;
if (files.All(l => l.EndsWith(".lnk")))
{
foreach (string file in files)
{
windowsShortcut = WindowsShortcut.Load(file);
if (windowsShortcut.Path is null)
{
File.Delete(file);
continue;
}
fileFullPath = windowsShortcut.Path;
windowsShortcut.Dispose();
File.WriteAllText(Path.ChangeExtension(file, ".url"), fileFullPath);
File.Delete(file);
}
throw new NotSupportedException("All are Windows *.lnk files!");
}
}
}
private static bool IsFilesCollectionCountIsOne(ReadOnlyCollection<string[]> filesCollection)
{
bool result = true;
int count = 0;
foreach (string[] files in filesCollection)
{
if (files.Length == 0)
continue;
count += 1;
if (count > 1)
{
result = false;
break;
}
}
if (result)
CheckForAllWindowsLinks(filesCollection);
return result;
}
private (string, ReadOnlyCollection<string[]>, bool) GetFilesCollectionThenCopyOrMove(long ticks, string fileSearchFilter, string directorySearchFilter, ProgressBarOptions options, string outputResolution)
{
ProgressBar progressBar;
string filesCollectionRootDirectory = _Configuration.PropertyConfiguration.RootDirectory;
@ -1224,6 +1287,7 @@ public partial class DlibDotNet
IReadOnlyDictionary<string, string[]> fileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(_Configuration.PropertyConfiguration, cResultsFullGroupDirectory, [_Configuration.PropertyConfiguration.ResultContent]);
ReadOnlyCollection<string[]> filesCollection = IDirectory.GetFilesCollection(filesCollectionRootDirectory, directorySearchFilter, fileSearchFilter, useCeilingAverage: false);
int count = filesCollection.Select(l => l.Length).Sum();
bool filesCollectionCountIsOne = IsFilesCollectionCountIsOne(filesCollection);
string message = $") Selecting for ## pattern directory - {(int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds)} total second(s)";
progressBar = new(count, message, options);
(string[] distinctDirectories, List<(FilePath, string)> toDoCollection) = IDirectory.GetToDoCollection(_Configuration.PropertyConfiguration, filesCollection, fileGroups[_Configuration.PropertyConfiguration.ResultContent], () => progressBar.Tick());
@ -1237,7 +1301,7 @@ public partial class DlibDotNet
progressBar = new(count, message, options);
_ = IDirectory.CopyOrMove(toDoCollection, move: false, moveBack: false, () => progressBar.Tick());
progressBar.Dispose();
return (filesCollectionRootDirectory, new(filesCollection));
return (filesCollectionRootDirectory, new(filesCollection), filesCollectionCountIsOne);
}
}

View File

@ -87,6 +87,8 @@ internal abstract class Container
FilePath filePath = FilePath.Get(propertyConfiguration, imageFileInfo, index: null);
bool? fileSizeChanged = property is not null ? property.FileSize != filePath.Length : null;
bool isValidImageFormatExtension = propertyConfiguration.ValidImageFormatExtensions.Contains(filePath.ExtensionLowered);
if (property is not null && property.Keywords is not null && !IId.IsIgnore(filePath) && propertyConfiguration.IgnoreRulesKeyWords.Any(l => property.Keywords.Contains(l)))
throw new NotSupportedException($"Rename File! <{filePath.FileNameFirstSegment}>");
string relativePath = IPath.GetRelativePath(filePair.Path, rootDirectoryLength, forceExtensionToLower: true);
bool? lastWriteTimeChanged = property is not null ? propertyConfiguration.PropertiesChangedForProperty || property.LastWriteTime.Ticks != filePath.LastWriteTicks : null;
if (filePair.Match is not null)

View File

@ -18,6 +18,24 @@ public interface IId
static string GetPaddedId(Properties.IPropertyConfiguration propertyConfiguration, int index, int id) =>
Id.GetPaddedId(propertyConfiguration, index, id);
bool TestStatic_IsIgnore(FilePath filePath) =>
IsIgnore(filePath);
static bool IsIgnore(FilePath filePath) =>
filePath.FileNameFirstSegment[^1] is '2' or '8';
string TestStatic_GetIgnoreFullPath(FilePath filePath, Models.FileHolder fileHolder) =>
GetIgnoreFullPath(filePath, fileHolder);
static string GetIgnoreFullPath(FilePath filePath, Models.FileHolder fileHolder) =>
fileHolder.DirectoryName is null ?
throw new NotSupportedException() :
filePath.Id > -1 ?
fileHolder.NameWithoutExtension[^1] == '9' ?
Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension[..^1]}8{fileHolder.ExtensionLowered}") :
throw new NotSupportedException("High") :
fileHolder.NameWithoutExtension[^1] == '1' ?
Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension[..^1]}2{fileHolder.ExtensionLowered}") :
throw new NotSupportedException("Low");
bool TestStatic_NameWithoutExtensionIsIntelligentIdFormat(Properties.IPropertyConfiguration propertyConfiguration, string fileNameFirstSegment) =>
NameWithoutExtensionIsIntelligentIdFormat(propertyConfiguration, fileNameFirstSegment);
static bool NameWithoutExtensionIsIntelligentIdFormat(Properties.IPropertyConfiguration propertyConfiguration, string fileNameFirstSegment) =>