2024-07-03 17:55:54 -05:00
|
|
|
|
using PeanutButter.INI;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Management.Automation;
|
|
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.PowerShell.Cmdlets
|
|
|
|
|
|
{
|
|
|
|
|
|
[Cmdlet(VerbsData.Update, "IniValue")]
|
|
|
|
|
|
[OutputType(typeof(string))]
|
|
|
|
|
|
public class UpdateIniValueCmdlet : Cmdlet
|
|
|
|
|
|
{
|
|
|
|
|
|
[Parameter(Mandatory = true, Position = 0)]
|
|
|
|
|
|
public string Section { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = true, Position = 1)]
|
|
|
|
|
|
public string Key { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = true, Position = 2)]
|
|
|
|
|
|
public string Value { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter(Mandatory = true, Position = 3)]
|
|
|
|
|
|
public string FilePath { get; set; }
|
|
|
|
|
|
|
2024-07-04 01:18:32 -05:00
|
|
|
|
[Parameter(Mandatory = false)]
|
|
|
|
|
|
public bool WrapValueInQuotes { get; set; } = false;
|
|
|
|
|
|
|
2024-07-03 17:55:54 -05:00
|
|
|
|
protected override void ProcessRecord()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(FilePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
var ini = new INIFile(FilePath);
|
|
|
|
|
|
|
|
|
|
|
|
ini.SetValue(Section, Key, Value);
|
2024-07-04 01:18:32 -05:00
|
|
|
|
ini.WrapValueInQuotes = WrapValueInQuotes;
|
2024-07-03 17:55:54 -05:00
|
|
|
|
ini.Persist();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|