Ejemplo n.º 1
0
        bool SetIconAutoSingleImpl(DirectoryInfo current, FolderIconCommandArguments options)
        {
            if (!current.Exists && options.CreateDirectories)
            {
                current.Create();
            }
            var paths    = GetRelativePaths(current).ToArray();
            var label    = paths.FirstOrDefault()?.SubPath;
            var altLabel = Roots.GetAlternateRootLabels(label).FirstOrDefault();
            var labels   = string.IsNullOrWhiteSpace(label) ? new string[0] : Paths.Split(label);
            var name     = labels.FirstOrDefault(x => x.ToUpperInvariant() != x && x.Length > 4);
            var icon     = GetCurrentIcon(current);

            if (icon.IsEmpty || !icon.Exists)
            {
                ReportError($"Could not find Folder Icon for <<LINK:{current.FullName}::800>>");
                return(false);
            }
            var newIcon = icon.ChangeDirectory(current);
            var ini     = new DesktopIniParser(current)
            {
                IconResource = newIcon
            };
            var depth     = current.GetDepth(options.Root);
            var verbosity = Math.Min(MAX_VERBOSITY - 1, depth + 1);

            if (options.LastIcon.FullName != icon.FullName)
            {
                verbosity = Math.Min(verbosity, 1);
            }
            if (label?.IndexOf(Paths.DirectorySeparatorChar) == -1)
            {
                verbosity = Math.Min(verbosity, MANUAL_VERBOSITY - 2);
            }
            if (altLabel != null)
            {
                verbosity = Math.Min(verbosity, MANUAL_VERBOSITY - 1);
            }
            if (name == null || newIcon.FullName.Contains(name))
            {
                verbosity = Math.Min(verbosity, MANUAL_VERBOSITY - 1);
            }
            if (newIcon.FullName.Contains("..\\"))
            {
                verbosity = Math.Min(verbosity, 2);
            }
            ReportProgress(0, new ReportedStatus($"Setting Folder Icon To <<LINK:{newIcon.Resource}||{newIcon.FullName}::500>> for <<LINK:{current.FullName}::800>> [<<LINK:{icon.Info}>>]", options.Command, current.FullName, newIcon.Resource, verbosity: verbosity));
            var success = ini.Save();

            if (!success)
            {
                ReportError($"Unable to save INI for {current.FullName}");
            }
            options.LastIcon = icon;
            return(true);
        }
Ejemplo n.º 2
0
        IEnumerable <IconGenerationPath> GetRelativePaths(DirectoryInfo current, DirectoryInfo rootDirectory, int priority)
        {
            //var debug = IsDebug(current);
            var generationRoot = new IconGenerationRoot(priority, rootDirectory);

            //TODO: xRemove ToArray()
            var roots = GetRootPaths(current, generationRoot)
                        .Distinct()
                        .ToArray()
            ;
            RelativePath relative = null;

            foreach (var root in roots)
            {
                if (!Roots.IsActionRoot(current))
                {
                    var actionRoot = Roots.GetActionRoot(current);
                    relative = current.ParseRelativePath(actionRoot, root.Directory);
                    yield return(new IconGenerationPath(root, 1, relative));
                }
                if (Roots.Action != null)
                {
                    relative = current.ParseRelativePath(Roots.Action, root.Directory);
                    yield return(new IconGenerationPath(root, 2, relative));
                }
            }
            if (relative == null)
            {
                yield break;
            }
            var label = relative.SubPath;

            var newLabels = Roots.GetAlternateRootLabels(label);

            //.ToArray()

            foreach (var newLabel in newLabels)
            {
                foreach (var root in roots)
                {
                    relative = root.Directory.CreateRelativePath(newLabel);
                    yield return(new IconGenerationPath(root, 3, relative));
                }
            }
        }
Ejemplo n.º 3
0
        IEnumerable <RelativePath> GetRelativePaths(DirectoryInfo current)
        {
            //TODO: Remove ToArray()
            var roots = GetRootPaths(current)
                        .NotNull()
                        .DistinctPaths()
                        .ToArray();
            RelativePath relative = null;
            var          debug    = IsDebug(current);

            foreach (var root in roots)
            {
                if (!Roots.IsActionRoot(current))
                {
                    relative = current.ParseRelativePath(Roots.GetActionRoot(current), root);
                    yield return(relative);
                }
                relative = current.ParseRelativePath(Roots.Action, root);
                yield return(relative);
            }
            if (relative == null)
            {
                yield break;
            }
            var label = relative.SubPath;
            //TODO: Remove ToArray()
            var newLabels = Roots.GetAlternateRootLabels(label).ToArray();

            foreach (var newLabel in newLabels)
            {
                foreach (var root in roots)
                {
                    relative = root.CreateRelativePath(newLabel);
                    yield return(relative);
                }
            }
        }
Ejemplo n.º 4
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        bool SetIconAutoSingleImpl(DirectoryInfo current, FolderIconCommandArguments options)
        {
            if (!current.Exists && options.CreateDirectories)
            {
                current.Create();
            }
            var paths    = GetRelativePaths(current, Roots.Action, 100).ToArray();
            var label    = paths.FirstOrDefault()?.Directory.SubPath;
            var altLabel = Roots.GetAlternateRootLabels(label).FirstOrDefault();
            var labels   = string.IsNullOrWhiteSpace(label) ? new string[0] : Paths.Split(label);
            var name     = labels.FirstOrDefault(x => x.ToUpperInvariant() != x && x.Length > 4);
            var result   = GetCurrentIcon(current);
            var icon     = result.Icon;

            if (icon.IsEmpty || !icon.Exists)
            {
                ReportError($"Could not find Folder Icon for <<LINK:{current.FullName}::800>>");
                return(false);
            }
            var newIcon = icon.ChangeDirectory(current);
            var ini     = new DesktopIniParser(current);
            var oldIcon = ini.Icon;

            ini.IconResource = newIcon;
            var depth     = current.GetDepth(options.Root);
            var verbosity = Math.Min(MAX_VERBOSITY - 1, depth + NEW_ICON_VERBOSITY);

            if (options.LastIcon.FullName != icon.FullName)
            {
                verbosity = Math.Min(verbosity, NEW_ICON_VERBOSITY);
            }
            if (label?.IndexOf(Paths.DirectorySeparatorChar) == -1)
            {
                verbosity = Math.Min(verbosity, MANUAL_VERBOSITY - 2);
            }
            if (altLabel != null)
            {
                verbosity = Math.Min(verbosity, MANUAL_VERBOSITY - 1);
            }
            if (name == null || newIcon.FullName.Contains(name))
            {
                verbosity = Math.Min(verbosity, MANUAL_VERBOSITY - 1);
            }
            if (newIcon.FullName.Contains("..\\"))
            {
                verbosity = Math.Min(verbosity, NEW_ICON_VERBOSITY + 1);
            }
            if (Settings.Toggles.ReportChanges)
            {
                var oldIconPath = ResolvedPath.Resolve(oldIcon.FullName);
                var newIconPath = ResolvedPath.Resolve(newIcon.FullName);
                if (!oldIconPath.Resolved.Equals(newIconPath.Resolved, StringComparison.OrdinalIgnoreCase))
                {
                    verbosity = Math.Min(verbosity, verbosity > NEW_ICON_VERBOSITY ? 2 : 1);
                }
            }
            var message = $"{ReportedStatusElement.GetLink(newIcon.FullName, newIcon.Resource, 700, 115)}\t==>\t{ReportedStatusElement.GetLink(current.FullName, width: 700)} [{ReportedStatusElement.GetLink(icon.Info)}]";

            ReportProgress(0, new ReportedStatus(message, options.Command, current.FullName, newIcon.Resource, verbosity: verbosity));
            var success = options.PreviewMode || ini.Save();

            if (!success)
            {
                ReportError($"Unable to save INI for {current.FullName}");
            }
            options.LastIcon = icon;
            return(true);
        }