LANCommander/LANCommander.SDK/PowerShell/Cmdlets/Update-IniValue.cs
Pat Hartl 9e770f4965 Bundle PowerShell runtime
This does a very basic job of bundling a PowerShell runtime into the SDK. Previously, scripts had been run by spawning a separate PowerShell process and feeding the script into it. This was nothing better than a hack and meant that PowerShell had to be separately installed on the machine it's executing on. This should open up the opportunity for scripts to run on other platforms.

There's still some things that need to be figured out. Some sort of console output as well as a debugging mode would be highly beneficial for those that wish to actively develop scripts for their games.
2024-08-05 18:02:01 -05:00

39 lines
1.1 KiB
C#

using PeanutButter.INI;
using System;
using System.IO;
using System.Management.Automation;
namespace LANCommander.SDK.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; }
[Parameter(Mandatory = false)]
public bool WrapValueInQuotes { get; set; } = false;
protected override void ProcessRecord()
{
if (File.Exists(FilePath))
{
var ini = new INIFile(FilePath);
ini.SetValue(Section, Key, Value);
ini.WrapValueInQuotes = WrapValueInQuotes;
ini.Persist();
}
}
}
}