Ejemplo n.º 1
0
        private void DoExplored(ItemExplorer explorer)
        {
            var info1 = explorer == null ? null : explorer.Info();
            var info2 = Explorer.Info();

            // fixed drive?
            if (Drive.Length > 0 && !Kit.Equals(Drive, info2.DriveName))
            {
                return;
            }

            // customise if not yet
            if (Drive.Length == 0 && (explorer == null || info1.Provider.ImplementingType != info2.Provider.ImplementingType))
            {
                if (string.IsNullOrEmpty(Drive))
                {
                    Columns = null;
                    ExcludeMemberPattern = null;

                    System.Collections.IDictionary options = A.Psf.Providers[info2.Provider.Name] as System.Collections.IDictionary;
                    if (options != null)
                    {
                        try
                        {
                            Converter.SetProperties(this, options, true);
                        }
                        catch (ArgumentException ex)
                        {
                            throw new InvalidDataException("Invalid settings for '" + info2.Provider.Name + "' provider: " + ex.Message);
                        }
                    }
                }
            }

            // Set-Location, the core remembers it for the drive, this is handy
            A.Psf.Engine.SessionState.Path.SetLocation(Kit.EscapeWildcard(Explorer.Location));

            //! path is used for Set-Location on Invoking()
            Title           = "Items: " + Explorer.Location;
            CurrentLocation = Explorer.Location;             //????

            if (info2.Provider.ImplementingType == typeof(FileSystemProvider))
            {
                UseSortGroups = true;
                Highlighting  = PanelHighlighting.Full;

                // _090929_061740 Before Far 2.0.1145 we used to sync the current directory to
                // the PS location. Now it is not needed because Far does not do that any more.
            }
            else
            {
                UseSortGroups = false;
                Highlighting  = PanelHighlighting.Default;
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override void RenameFile(RenameFileEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            var newName = args.Parameter as string;

            if (newName == null)
            {
                throw new InvalidOperationException(Res.ParameterString);
            }

            //! Registry: workaround: (default)
            if (Kit.Equals(args.File.Name, "(default)") && Provider.ImplementingType == typeof(RegistryProvider))
            {
                args.Result = JobResult.Ignore;
                if (args.UI)
                {
                    A.Message("Cannot rename this property.");
                }
                return;
            }

            using (var ps = A.Psf.NewPowerShell())
            {
                ps.AddCommand("Rename-ItemProperty")
                .AddParameter("LiteralPath", ItemPath)
                .AddParameter(Word.Name, args.File.Name)
                .AddParameter("NewName", newName)
                .AddParameter(Prm.Force)
                .AddParameter(Prm.ErrorAction, ActionPreference.Continue);

                ps.Invoke();

                if (ps.Streams.Error.Count > 0)
                {
                    args.Result = JobResult.Ignore;
                    if (args.UI)
                    {
                        A.ShowError(ps);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public override void DeleteFiles(DeleteFilesEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            // to ask
            bool confirm = args.UI && 0 != (long)Far.Api.GetSetting(FarSetting.Confirmations, "Delete");

            // names to be deleted
            List <string> names = A.FileNameList(args.Files);

            //! Registry: workaround: (default)
            if (Provider.ImplementingType == typeof(RegistryProvider))
            {
                for (int i = names.Count; --i >= 0;)
                {
                    if (Kit.Equals(names[i], "(default)"))
                    {
                        // remove or not
                        if (!confirm || 0 == Far.Api.Message("Delete the (default) property", Res.Delete, MessageOptions.YesNo))
                        {
                            A.Psf.Engine.InvokeProvider.Property.Remove(Kit.EscapeWildcard(ItemPath), string.Empty);
                        }

                        // remove from the list in any case
                        names.RemoveAt(i);
                        break;
                    }
                }

                // done?
                if (names.Count == 0)
                {
                    return;
                }
            }

            using (var ps = A.Psf.NewPowerShell())
            {
                ps.AddCommand("Remove-ItemProperty")
                .AddParameter("LiteralPath", ItemPath)
                .AddParameter(Word.Name, names)
                .AddParameter(Prm.Force)
                .AddParameter(Prm.ErrorAction, ActionPreference.Continue);

                if (confirm)
                {
                    ps.AddParameter(Prm.Confirm);
                }

                ps.Invoke();

                // ?? V2 CTP3 bug: Registry: Remove-ItemProperty -Confirm fails on 'No':
                // Remove-ItemProperty : Property X does not exist at path HKEY_CURRENT_USER\Y
                // There is no workaround added yet. Submitted: MS Connect #484664.
                if (ps.Streams.Error.Count > 0)
                {
                    args.Result = JobResult.Incomplete;
                    if (args.UI)
                    {
                        A.ShowError(ps);
                    }
                }
            }
        }