diff --git a/LANCommander.PowerShell/Cmdlets/Convert-AspectRatio.cs b/LANCommander.PowerShell/Cmdlets/Convert-AspectRatio.cs new file mode 100644 index 0000000..5bb019d --- /dev/null +++ b/LANCommander.PowerShell/Cmdlets/Convert-AspectRatio.cs @@ -0,0 +1,45 @@ +using System; +using System.Management.Automation; + +namespace LANCommander.PowerShell.Cmdlets +{ + public class DisplayResolution + { + public int Width { get; set; } + public int Height { get; set; } + } + + [Cmdlet(VerbsData.Convert, "AspectRatio")] + [OutputType(typeof(string))] + public class ConvertAspectRatioCmdlet : PSCmdlet + { + [Parameter(Mandatory = true, Position = 0)] + public int Width { get; set; } + + [Parameter(Mandatory = true, Position = 1)] + public int Height { get; set; } + + [Parameter(Mandatory = true, Position = 2)] + public double AspectRatio { get; set; } + + protected override void ProcessRecord() + { + var resolution = new DisplayResolution(); + + // Display is wider, pillar box + if ((Width / Height) < AspectRatio) + { + resolution.Width = (int)Math.Ceiling(Height * AspectRatio); + resolution.Height = Height; + } + // Letterbox + else + { + resolution.Width = Width; + resolution.Height = (int)Math.Ceiling(Width * (1 / AspectRatio)); + } + + WriteObject(resolution); + } + } +} diff --git a/LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs b/LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs new file mode 100644 index 0000000..87b3c09 --- /dev/null +++ b/LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs @@ -0,0 +1,40 @@ +using LANCommander.SDK; +using LANCommander.SDK.Helpers; +using System.Management.Automation; + +namespace LANCommander.PowerShell.Cmdlets +{ + [Cmdlet(VerbsData.ConvertTo, "StringBytes")] + [OutputType(typeof(byte[]))] + public class ConvertToStringBytesCmdlet : PSCmdlet + { + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + public string Input { get; set; } + + [Parameter] + public bool Utf16 { get; set; } = false; + + [Parameter] + public bool BigEndian { get; set; } = false; + + [Parameter] + public int MaxLength { get; set; } = 0; + + protected override void ProcessRecord() + { + byte[] output; + + if (MaxLength > 0 && Input.Length > MaxLength) + Input = Input.Substring(0, MaxLength); + + if (Utf16 && BigEndian) + output = System.Text.Encoding.BigEndianUnicode.GetBytes(Input); + else if (Utf16) + output = System.Text.Encoding.Unicode.GetBytes(Input); + else + output = System.Text.Encoding.ASCII.GetBytes(Input); + + WriteObject(output); + } + } +} diff --git a/LANCommander.PowerShell/Cmdlets/Edit-PatchBinary.cs b/LANCommander.PowerShell/Cmdlets/Edit-PatchBinary.cs new file mode 100644 index 0000000..0e73580 --- /dev/null +++ b/LANCommander.PowerShell/Cmdlets/Edit-PatchBinary.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; +using System.Management.Automation; + +namespace LANCommander.PowerShell.Cmdlets +{ + [Cmdlet(VerbsData.Edit, "PatchBinary")] + [OutputType(typeof(string))] + public class EditPatchBinaryCmdlet : PSCmdlet + { + [Parameter(Mandatory = true, Position = 0)] + public long Offset { get; set; } + + [Parameter(Mandatory = true, Position = 1)] + public byte[] Data { get; set; } + + [Parameter(Mandatory = true, Position = 2)] + public string FilePath { get; set; } + + protected override void ProcessRecord() + { + using (var writer = File.OpenWrite(FilePath)) + { + writer.Seek(Offset, SeekOrigin.Begin); + + writer.Write(Data, 0, Data.Length); + } + } + } +} diff --git a/LANCommander.PowerShell/Cmdlets/Get-GameManifest.cs b/LANCommander.PowerShell/Cmdlets/Get-GameManifest.cs new file mode 100644 index 0000000..b012bd5 --- /dev/null +++ b/LANCommander.PowerShell/Cmdlets/Get-GameManifest.cs @@ -0,0 +1,19 @@ +using LANCommander.SDK; +using LANCommander.SDK.Helpers; +using System.Management.Automation; + +namespace LANCommander.PowerShell.Cmdlets +{ + [Cmdlet(VerbsCommon.Get, "GameManifest")] + [OutputType(typeof(GameManifest))] + public class GetGameManifestCmdlet : PSCmdlet + { + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + public string Path { get; set; } + + protected override void ProcessRecord() + { + WriteObject(ManifestHelper.Read(Path)); + } + } +} diff --git a/LANCommander.PowerShell/Cmdlets/Get-PrimaryDisplay.cs b/LANCommander.PowerShell/Cmdlets/Get-PrimaryDisplay.cs new file mode 100644 index 0000000..0b53547 --- /dev/null +++ b/LANCommander.PowerShell/Cmdlets/Get-PrimaryDisplay.cs @@ -0,0 +1,18 @@ +using System.Linq; +using System.Management.Automation; +using System.Windows.Forms; + +namespace LANCommander.PowerShell.Cmdlets +{ + [Cmdlet(VerbsCommon.Get, "PrimaryDisplay")] + [OutputType(typeof(string))] + public class GetPrimaryDisplayCmdlet : PSCmdlet + { + protected override void ProcessRecord() + { + var screens = Screen.AllScreens; + + WriteObject(screens.First(s => s.Primary)); + } + } +} diff --git a/LANCommander.PowerShell/Cmdlets/Write-GameManifest.cs b/LANCommander.PowerShell/Cmdlets/Write-GameManifest.cs new file mode 100644 index 0000000..6d9ad0c --- /dev/null +++ b/LANCommander.PowerShell/Cmdlets/Write-GameManifest.cs @@ -0,0 +1,24 @@ +using LANCommander.SDK; +using LANCommander.SDK.Helpers; +using System.Management.Automation; + +namespace LANCommander.PowerShell.Cmdlets +{ + [Cmdlet(VerbsCommunications.Write, "GameManifest")] + [OutputType(typeof(string))] + public class WriteGameManifestCmdlet : PSCmdlet + { + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + public string Path { get; set; } + + [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)] + public GameManifest Manifest { get; set; } + + protected override void ProcessRecord() + { + var destination = ManifestHelper.Write(Manifest, Path); + + WriteObject(destination); + } + } +} diff --git a/LANCommander.PowerShell/Cmdlets/Write-ReplaceContentInFile.cs b/LANCommander.PowerShell/Cmdlets/Write-ReplaceContentInFile.cs new file mode 100644 index 0000000..32cda9c --- /dev/null +++ b/LANCommander.PowerShell/Cmdlets/Write-ReplaceContentInFile.cs @@ -0,0 +1,31 @@ +using System.IO; +using System.Management.Automation; +using System.Text.RegularExpressions; + +namespace LANCommander.PowerShell.Cmdlets +{ + + [Cmdlet(VerbsCommunications.Write, "ReplaceContentInFile")] + [OutputType(typeof(string))] + public class ReplaceContentInFileCmdlet : PSCmdlet + { + [Parameter(Mandatory = true, Position = 0)] + public string Pattern { get; set; } + + [Parameter(Mandatory = true, Position = 1)] + public string Substitution { get; set; } + + [Parameter(Mandatory = true, Position = 2)] + public string FilePath { get; set; } + + protected override void ProcessRecord() + { + var contents = File.ReadAllText(FilePath); + var regex = new Regex(Pattern, RegexOptions.Multiline); + + var result = regex.Replace(contents, Substitution); + + WriteObject(result); + } + } +} diff --git a/LANCommander.PowerShell/LANCommander.PowerShell.csproj b/LANCommander.PowerShell/LANCommander.PowerShell.csproj new file mode 100644 index 0000000..515ee5d --- /dev/null +++ b/LANCommander.PowerShell/LANCommander.PowerShell.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {807943BF-0C7D-4ED3-8393-CFEE64E3138C} + Library + Properties + LANCommander.PowerShell + LANCommander.PowerShell + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + ..\packages\PowerShellStandard.Library.5.1.1\lib\net452\System.Management.Automation.dll + + + + + + + + + + + + + + + + + + + + + + + + + + {4c2a71fd-a30b-4d62-888a-4ef843d8e506} + LANCommander.SDK + + + + \ No newline at end of file diff --git a/LANCommander.PowerShell/LANCommander.PowerShell.psd1 b/LANCommander.PowerShell/LANCommander.PowerShell.psd1 new file mode 100644 index 0000000..52b16e5 Binary files /dev/null and b/LANCommander.PowerShell/LANCommander.PowerShell.psd1 differ diff --git a/LANCommander.PowerShell/Properties/AssemblyInfo.cs b/LANCommander.PowerShell/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..87468b6 --- /dev/null +++ b/LANCommander.PowerShell/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("LANCommander.PowerShell")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("LANCommander.PowerShell")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("807943bf-0c7d-4ed3-8393-cfee64e3138c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/LANCommander.PowerShell/packages.config b/LANCommander.PowerShell/packages.config new file mode 100644 index 0000000..411c02f --- /dev/null +++ b/LANCommander.PowerShell/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/LANCommander.sln b/LANCommander.sln index 529f8cc..5f6fef2 100644 --- a/LANCommander.sln +++ b/LANCommander.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LANCommander.SDK", "LANComm EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LANCommander.PCGamingWiki", "LANCommander.PCGamingWiki\LANCommander.PCGamingWiki.csproj", "{2436B817-4475-4E70-9BB2-E1E7866DB79F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LANCommander.PowerShell", "LANCommander.PowerShell\LANCommander.PowerShell.csproj", "{807943BF-0C7D-4ED3-8393-CFEE64E3138C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {2436B817-4475-4E70-9BB2-E1E7866DB79F}.Debug|Any CPU.Build.0 = Debug|Any CPU {2436B817-4475-4E70-9BB2-E1E7866DB79F}.Release|Any CPU.ActiveCfg = Release|Any CPU {2436B817-4475-4E70-9BB2-E1E7866DB79F}.Release|Any CPU.Build.0 = Release|Any CPU + {807943BF-0C7D-4ED3-8393-CFEE64E3138C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {807943BF-0C7D-4ED3-8393-CFEE64E3138C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {807943BF-0C7D-4ED3-8393-CFEE64E3138C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {807943BF-0C7D-4ED3-8393-CFEE64E3138C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE