/// <inheritdoc/> public override IList <FarFile> GetFiles(GetFilesEventArgs args) { var result = new List <FarFile>(); if (args == null) { return(result); } try { //! get properties // - Using -LiteralPath is a problem, e.g. Registry: returns nothing. // - Script is used for PS conversion of property values to string. // - Script has to ignore a property with empty name (if any, can be in Registry). // - If PS* included then they can't be found by `gp <path> <name>`; // so, don't add, they are noisy anyway (even if marked system or hidden). // get property bag 090409 Collection <PSObject> bag = A.Psf.Engine.InvokeProvider.Property.Get(Kit.EscapeWildcard(ItemPath), null); // filter var filter = new List <string>(5); filter.Add("PSChildName"); filter.Add("PSDrive"); filter.Add("PSParentPath"); filter.Add("PSPath"); filter.Add("PSProvider"); // add foreach (PSObject o in bag) { foreach (PSPropertyInfo pi in o.Properties) { // skip empty ?? still needed? string name = pi.Name; if (string.IsNullOrEmpty(name)) { continue; } // filter and shrink filter int i = filter.IndexOf(name); if (i >= 0) { filter.RemoveAt(i); continue; } // create file SetFile file = new SetFile() { Name = name, IsReadOnly = !pi.IsSettable, Data = pi, // set its value Description = Converter.FormatValue(pi.Value, Settings.Default.FormatEnumerationLimit) }; // add result.Add(file); } } } catch (RuntimeException error) { if (args.UI) { A.Message(error.Message); } } return(result); }
static string GetFilePath() { return(Entry.LocalData + "\\" + Kit.ToString(DateTime.Now, "_yyMMdd_HHmmss") + Word.InteractiveSuffix); }
/// <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); } } } }
/// <summary> /// Sync provider location and current directory with Far state. /// </summary> /// <remarks> /// Returned system path (if not null) must be restored by a called. /// </remarks> internal string SyncPaths() { // don't on running if (IsRunning) { return(null); } // don't on no panels mode IPanel panel = Far.Api.Panel; if (panel == null) { return(null); } // at first get both paths: for the current system directory and provider location string directory = Far.Api.CurrentDirectory; string location = null; if (panel.IsPlugin) { Panel plugin = panel as Panel; if (plugin != null) { var itemPanel = plugin as ItemPanel; if (itemPanel != null) { location = itemPanel.Explorer.Location; } else { FolderTree folderTree = plugin as FolderTree; if (folderTree != null) { location = panel.CurrentDirectory; if (location == "*") //_130117_234326 { location = directory; } } } } } // to set yet unknown location to the directory if (location == null) { location = directory; } // set the current provider location; let's do it first, in case of failure // we can skip directory setting/restoring in cases when they are the same. bool okLocation = true; try { //! Parameter is wildcard. Test: enter into a container "[]" and invoke a command. Engine.SessionState.Path.SetLocation(Kit.EscapeWildcard(location)); // drop failure info _failedInvokingLocationNew = null; _failedInvokingLocationOld = null; } catch { okLocation = false; // get the current string currentLocation = Engine.SessionState.Path.CurrentLocation.Path; // ask a user if he has not told to ignore this pair if (location != _failedInvokingLocationNew || currentLocation != _failedInvokingLocationOld) { string message = string.Format(null, @" Cannot set the current location to {0} Continue with this current location? {1} ", location, currentLocation); switch (Far.Api.Message(message, Res.Me, MessageOptions.GuiOnMacro | MessageOptions.AbortRetryIgnore | MessageOptions.Warning | MessageOptions.LeftAligned)) { case 1: break; case 2: _failedInvokingLocationNew = location; _failedInvokingLocationOld = currentLocation; break; default: if (Far.Api.MacroState != MacroState.None) { Far.Api.UI.Break(); } throw; } } } // do not try failed if (!okLocation && location == directory) { return(null); } // get the current directory to be restored by a caller string currentDirectory = Directory.GetCurrentDirectory(); // set the current directory to the active path to avoid confusions [_090929_061740] try { // try to set Directory.SetCurrentDirectory(directory); // drop failure info _failedInvokingDirectoryNew = null; _failedInvokingDirectoryOld = null; } catch { // ask a user if he has not told to ignore this pair if (directory != _failedInvokingDirectoryNew || currentDirectory != _failedInvokingDirectoryOld) { string message = string.Format(null, @" Cannot set the current directory to {0} Continue with this current directory? {1} ", directory, currentDirectory); switch (Far.Api.Message(message, Res.Me, MessageOptions.GuiOnMacro | MessageOptions.AbortRetryIgnore | MessageOptions.Warning | MessageOptions.LeftAligned)) { case 1: currentDirectory = null; break; case 2: currentDirectory = null; _failedInvokingDirectoryNew = directory; _failedInvokingDirectoryOld = currentDirectory; break; default: if (Far.Api.MacroState != MacroState.None) { Far.Api.UI.Break(); } throw; } } } // to be restored by a caller return(currentDirectory); }