Ejemplo n.º 1
0
        private void bgwCommand_DoWork(FolderIconCommandArguments arguments)
        {
            var parent = arguments.Directory.Parent;

            switch (arguments.Command)
            {
            case FolderIconCommand.GenerateSidecarFiles:
                var parentIcon = DesktopIniParser.GetIcon(parent.FullName);
                GenerateSidecarFilesImpl(arguments.Directory, parentIcon, arguments.PreviewMode, arguments.Recursive);
                break;

            case FolderIconCommand.SetIconTree:
                SetIconTreeImpl(arguments);
                break;

            case FolderIconCommand.SetIconsAuto:
                SetIconAutoImpl(arguments);
                break;

            case FolderIconCommand.FixAttributes:
            case FolderIconCommand.ApplyFolderIcons:
                var parentInfo = FolderIconInfo.Get(parent.FullName);
                ApplyFolderIconsImpl(arguments.Directory, parentInfo, arguments.PreviewMode, arguments.Command == FolderIconCommand.FixAttributes, arguments.Recursive);
                break;
            }
        }
Ejemplo n.º 2
0
        IEnumerable <IconGenerationFolder> GetCurrentIconFoldersFromName(FolderIconInfo iconInfo)
        {
            var roots = GetRootFoldersFromDirectory(iconInfo).DistinctPaths().ToArray();
            var paths = GetCurrentIconFoldersFromRoots(roots);

            return(paths);
        }
Ejemplo n.º 3
0
        IconReference GetCurrentIconFromSidecar(DirectoryInfo current, FolderIconInfo iconInfo, IconReference parentIcon)
        {
            if (!string.IsNullOrEmpty(iconInfo.Main))
            {
                return(iconInfo);
            }

            var finalIcon = GetCurrentIconFromDirectory(current, iconInfo, parentIcon);

            return(finalIcon.IsEmpty
                ? parentIcon
                : finalIcon);
        }
Ejemplo n.º 4
0
        IEnumerable <IconGenerationResult> GetCurrentIconsFromName_DebugSteps(DirectoryInfo current)
        {
            //var debug = IsDebug(current);
            //TODO: xRemove folderIconInfo
            var folderIconInfo = FolderIconInfo.GetExisting(current);

            var sidecarIcon = ResolveCurrentSidecarIcon(folderIconInfo, current);

            if (sidecarIcon != null)
            {
                return(new[] { sidecarIcon });
            }

            //TODO: xRemove roots and strRoots
            var roots = GetRootFoldersFromDirectory(folderIconInfo)
                        .DistinctPaths()
                        .ToArray();
            var strRoots = roots
                           //.Where(p=>Paths.Exists(p.FullName))
                           .OrderBy(p => p.FullName)
                           .Select(p => p.FullName)
                           .ToArray();

            //TODO: xRemove paths and strPaths
            var allPaths = GetCurrentIconFoldersFromRoots(roots)
                           .OrderBy(x => x.Priorities, ArrayComparer <double> .Default)
                           .ThenBy(x => x.Directory.FullName)
                           .ToArray();
            var paths = allPaths
                        .Distinct()
                        .ToArray();
            var strPaths = paths
                           .Select(p => p.Directory.FullName)
                           .ToArray();

            //TODO: xReplace GetAllCurrentIconsFromPaths(current, paths) and above code with GetAllCurrentIconsFromName(current)
            //TODO: xRemove ToArray()
            var icons = GetAllCurrentIconsFromPaths(current, paths)
                        .OrderBy(x => x.Priorities, ArrayComparer <double> .Default)
                        .ThenBy(x => x.Directory.FullName)
                        .Distinct()
                        .ToArray();

            //TODO: xRemove ToArray()
            var existingIcons = icons
                                .Where(x => x.Icon.Exists)
                                .ToArray();

            return(existingIcons);
        }
Ejemplo n.º 5
0
        IconReference GetCurrentIconFromSidecar(DirectoryInfo current, FolderIconInfo iconInfo, IconReference parentIcon)
        {
            //TODO: Evaluate use of FolderIconInfo.Main vs FolderIconInfo.Icon/GetIconResource()
            if (!string.IsNullOrEmpty(iconInfo.Main))
            {
                return(iconInfo);
            }

            var finalIcon = GetCurrentIconFromDirectory(current, iconInfo, parentIcon);

            return(finalIcon.IsEmpty
                ? parentIcon
                : finalIcon);
        }
Ejemplo n.º 6
0
        void ApplyFolderIconsImpl(DirectoryInfo current, IconReference parentIcon, bool previewMode, bool fixAttributesOnly = false, bool recursive = true)
        {
            var iniFile  = new DesktopIniParser(current.FullName);
            var icon     = iniFile.Icon;
            var iconInfo = FolderIconInfo.Get(current.FullName);

            //IconReference finalIcon;
            //var isNew = GetCurrentIcon(current, icon, parentIcon, iconInfo, out finalIcon);
            if (parentIcon.IsEmpty)
            {
                var parentDirectory = current.IsRoot()
                                          ? current
                                          : current.Parent;
                parentIcon = new DesktopIniParser(parentDirectory.FullName).Icon;
            }
            var finalIcon = GetCurrentIconFromSidecar(current, iconInfo, parentIcon);

            if (!fixAttributesOnly && !finalIcon.IsEmpty && iniFile.Icon.Resource != finalIcon.Resource)
            {
                ReportProgress(0,
                               $"<<LINK:{finalIcon.Resource}||{finalIcon.Icon.FullName}::500>>\t==>\t<<LINK:{current.FullName}::800>> [<<LINK:{icon.Info}>>]");
                //ReportStatus($"Setting Main Icon To [LINK:{icon.Info}::500] for [LINK:{current.FullName}::800] [Parent: [LINK:{parentIcon.Info}]]");
                if (!previewMode)
                {
                    iniFile.IconResource = finalIcon;
                    iniFile.Save();
                }
            }
            else
            {
                var thisFile = iniFile.Ini;
                var verified = thisFile.VerifyHiddenSystem(!previewMode);
                verified &= thisFile.Directory.VerifySystem(!previewMode);
                verified &= FolderInfoFile.GetFile(thisFile.Directory.FullName, SidecarType.Main).VerifyHiddenSystem(!previewMode);
                if (!verified)
                {
                    ReportProgress(0,
                                   $"*** Fixing desktop.ini attributes for <<LINK:{current.FullName}::1200>> [<<LINK:{icon.Info}>>]");
                }
            }
            if (!recursive)
            {
                return;
            }
            foreach (var child in current.EnumerateDirectoriesSafe())
            {
                ApplyFolderIconsImpl(child, finalIcon.IsEmpty ? parentIcon : finalIcon, previewMode, fixAttributesOnly);
            }
        }
Ejemplo n.º 7
0
        IEnumerable <DirectoryInfo> GetRootFoldersFromDirectory(FolderIconInfo iconInfo)
        {
            var allRoots       = iconInfo.GetRoots();
            var folderIconInfo = FolderIconInfo.Get(iconInfo);

            //TODO: Remove ToArray() and strPaths
            var roots = new [] { iconInfo.Directory }
            .Concat(iconInfo
                    .GetRoots()
                    .Select(x => DirectoriesIO.GetInfo(Directories.Roots.Library, x)))
            .ToArray();
            var strPaths = roots
                           //.Where(p=>Paths.Exists(p.FullName))
                           .Select(p => p.FullName)
                           .ToArray();

            return(roots);
        }
Ejemplo n.º 8
0
        static IconReference GetCurrentIconFromDirectory(DirectoryInfo current, FolderIconInfo iconInfo, IconReference parentIcon)
        {
            var baseDirectory   = Path.Combine(LibSetting.Directories.Library, current.GetFullNameWithoutRoot());
            var testDirectories = new[]
            {
                current.FullName,
                //Path.Combine(baseDirectory, current.Name),
                baseDirectory
            };

            var testFileNames      = new[] { current.Name, Path.Combine(current.Name, current.Name), "", "current" };
            var testFileExtensions = new[] { ".ico", ".icl" };

            var roots = iconInfo
                        .GetRoots()
                        .Select(x => Path.Combine(LibSetting.Directories.Library, x))
                        .ToArray();

            foreach (var name in testFileNames)
            {
                foreach (var directory in roots.Concat(testDirectories))
                {
                    foreach (var extension in testFileExtensions)
                    {
                        var testPath = string.IsNullOrEmpty(name)
                            ? directory + name + extension
                            : Path.Combine(directory, name + extension);
                        var testFile = new FileInfo(testPath);
                        var message  = current.FullName.Suffix(": ").PadRight(50) + testFile?.FullName;

                        if (testFile.Exists && testFile.FullName != parentIcon.Icon?.FullName)
                        {
                            Debug.WriteLine("*** " + message);
                            return(IconReference.FromFile(testFile));
                        }

                        // Debug.WriteLine("    " + message);
                    }
                }
            }
            Debug.WriteLine("xxx " + current.FullName.Suffix(": ").PadRight(50) + parentIcon.Icon?.FullName);
            return(IconReference.Empty);
        }
Ejemplo n.º 9
0
        IEnumerable <DirectoryInfo> GetRootFoldersFromDirectory(FolderIconInfo iconInfo)
        {
            //var debug = IsDebug(iconInfo);
            //var allRoots = iconInfo.GetRoots();
            //var folderIconInfo = FolderIconInfo.GetExisting(iconInfo);


            var iconRoots = iconInfo
                            .GetRoots()
                            .Select(x => DirectoriesIO.GetInfo(Directories.Roots.Library, x));
            var roots = new [] { iconInfo.Current }
            .Concat(iconRoots);

            //.ToArray()
            //var strPaths = roots
            //    //.Where(p=>Paths.Exists(p.FullName))
            //    .Select(p => p.FullName)
            //    .ToArray();
            return(roots);
        }
Ejemplo n.º 10
0
        IEnumerable <IconGenerationResult> GetCurrentIconsFromName(DirectoryInfo current)
        {
            //var debug = IsDebug(current);
            var folderIconInfo = FolderIconInfo.GetExisting(current);

            var sidecarIcon = ResolveCurrentSidecarIcon(folderIconInfo, current);

            if (sidecarIcon != null)
            {
                return new[] { sidecarIcon }
            }
            ;

            return(GetAllCurrentIconsFromName(folderIconInfo)
                   .OrderBy(x => x.Priorities, ArrayComparer <double> .Default)
                   .ThenBy(x => x.Directory.FullName)
                   .Distinct()
                   .Where(x => x.Icon.Exists));
        }

        IconGenerationResult ResolveCurrentSidecarIcon(FolderIconInfo iconInfo, DirectoryInfo current)
        {
            var icon = iconInfo.GetIconReference(current);

            return(GetIconGenerationResultFromReference(icon, -100, checkIconExists: true));
        }

        IconGenerationResult ResolveCurrentGeneratedIcon(DirectoryInfo current)
        {
            var ini = ResolveCurrentIcon(current);

            if (ini == null)
            {
                return(null);
            }
            var icon      = ini.Icon;
            var directory = ini.Directory;

            return(GetIconGenerationResultFromReference(icon, 100, directory));
        }
Ejemplo n.º 11
0
        IEnumerable <DirectoryInfo> GetRootFoldersFromDirectory(DirectoryInfo current)
        {
            var folderIconInfo = FolderIconInfo.GetExisting(current);

            return(GetRootFoldersFromDirectory(folderIconInfo));
        }
Ejemplo n.º 12
0
 bool GetCurrentIconFromIni(DirectoryInfo current, IconReference currentIcon, IconReference parentIcon, FolderIconInfo iconInfo, out IconReference finalIcon)
 {
     if (currentIcon.Resource != parentIcon.Resource && !currentIcon.IsEmpty)
     {
         finalIcon = currentIcon;
         return(true);
     }
     if (!string.IsNullOrEmpty(iconInfo.Main))
     {
         finalIcon = currentIcon;
         return(false);
     }
     finalIcon = GetCurrentIconFromDirectory(current, iconInfo, parentIcon);
     if (finalIcon.IsEmpty)
     {
         finalIcon = currentIcon;
         return(false);
     }
     return(true);
 }
Ejemplo n.º 13
0
/*
 *      [Obsolete]
 *      IEnumerable<IconGenerationResult> GetAllCurrentIconsFromName(DirectoryInfo current)
 *      {
 *          var paths = GetCurrentIconFoldersFromName(current).Distinct().ToArray();
 *          //var strPaths = paths
 *          //    //.Where(p=>Paths.Exists(p.FullName))
 *          //    .Select(p => p.Directory.FullName).ToArray();
 *          return GetAllCurrentIconsFromPaths(current, paths);
 *      }
 */

        IEnumerable <IconGenerationResult> GetAllCurrentIconsFromName(FolderIconInfo iconInfo)
        {
            var paths = GetCurrentIconFoldersFromName(iconInfo).Distinct().ToArray();

            return(GetAllCurrentIconsFromPaths(iconInfo.Current, paths));
        }