Esempio n. 1
0
        void SetIconTreeImpl(DirectoryInfo current, FolderIconCommandArguments options)
        {
            if (!current.Exists)
            {
                if (options.CreateDirectories)
                {
                    current.Create();
                }
                else
                {
                    Debugger.Break();
                }
            }
            var ini = ResolveCurrentIcon(current);

            if (!ini.Ini.Exists)
            {
                return;
            }
            if (ini.Directory.FullName == current.FullName)
            {
                throw new InvalidOperationException($"Cannot set Icon Tree from self for {current.FullName}");
            }
            var icon = ini.Icon.FullName;
            //TODO: Copy Icon To Target
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        void SetIconAutoImpl(DirectoryInfo current, FolderIconCommandArguments options)
        {
            SetIconAutoSingleImpl(current, options);

            if (!options.Recursive)
            {
                return;
            }
            foreach (var child in current.EnumerateDirectories(EnumerationOptions.Directories))
            {
                SetIconAutoImpl(child, options);
            }
        }
Esempio n. 5
0
        async void RunCommand(FolderIconCommand command)
        {
            if (!MayRunCommand)
            {
                ReportError("Cannot start new job - one is already in progress");
                return;
            }
            Updates = 0;
            Roots.RefreshLabelsRegex();
            Elapsed = System.Diagnostics.Stopwatch.StartNew();
            ClearStatus();
            var arguments = new FolderIconCommandArguments(command,
                                                           SelectedDirectory?.FullPath, Settings);

            ReportStart(0, $"Loading Subdirectories of {arguments.Directory.FullName}", true);
            if (arguments.Recursive)
            {
                arguments.Directories = await Task.Run(() => arguments.Directories
                                                       .Concat(
                                                           arguments
                                                           .Directory
                                                           .EnumerateDirectories(EnumerationOptions.Recursive.Directories)
                                                           )
                                                       .OrderBy(x => x.FullName.ToLowerInvariant())
                                                       .ToArray()).ConfigureAwait(true);

                InfoReporter.ReportTiming($"Loaded {arguments.Directories.Length} Subdirectories of {arguments.Directory.FullName} in {Stopwatch.Elapsed.FormatFriendly()}");
                ReportStart(arguments.Directories.Length, "Loaded All Directories", true);
            }

            if (Toggles.Async)
            {
                bgwCommand.RunWorkerAsync(arguments);
                OnPropertyChanged(nameof(MayRunCommand));
            }
            else
            {
                MayRunCommand = false;
                bgwCommand_DoWork(arguments);
                bgwCommand_RunWorkerCompleted();
                MayRunCommand = true;
            }
        }
Esempio n. 6
0
 void SetIconAutoImpl(FolderIconCommandArguments options)
 => options
 .Directories
 .ForEach(directory => SetIconAutoSingleImpl(directory, options));
Esempio n. 7
0
 void SetIconTreeImpl(FolderIconCommandArguments options)
 => SetIconTreeImpl(options.Directory, options);
Esempio n. 8
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);
        }