示例#1
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);
        }