Compare commits

...

5 Commits

6 changed files with 86 additions and 1 deletions

View File

@ -2,10 +2,17 @@
internal static partial class Kernel32
{
[LibraryImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool GetConsoleScreenBufferInfo(nint hConsoleOutput, out ConsoleScreenBufferInfo lpConsoleScreenBufferInfo);
[LibraryImport("kernel32.dll", SetLastError = true)]
public static partial nint GetConsoleWindow();
[LibraryImport("kernel32.dll", SetLastError = true)]
public static partial uint GetFinalPathNameByHandleA(nint hFile, [MarshalAs(UnmanagedType.LPTStr)] string lpszFilePath,
uint cchFilePath, uint dwFlags);
[LibraryImport("kernel32.dll")]
[LibraryImport("kernel32.dll", SetLastError = true)]
public static partial nuint GlobalSize(nint hPtr);
}

View File

@ -0,0 +1,15 @@
namespace SrcMod.Shell.Interop.ObjectModels;
[StructLayout(LayoutKind.Sequential)]
internal struct ConsoleScreenBufferInfo
{
[MarshalAs(UnmanagedType.LPStruct)]
public Coord dwSize;
[MarshalAs(UnmanagedType.LPStruct)]
public Coord dwCursorPosition;
public int wAttributes;
[MarshalAs(UnmanagedType.LPStruct)]
public SmallRect srWindow;
[MarshalAs(UnmanagedType.LPStruct)]
public Coord dwMaximumWindowSize;
}

View File

@ -0,0 +1,8 @@
namespace SrcMod.Shell.Interop.ObjectModels;
[StructLayout(LayoutKind.Sequential)]
internal struct Coord
{
public short X;
public short Y;
}

View File

@ -0,0 +1,10 @@
namespace SrcMod.Shell.Interop.ObjectModels;
[StructLayout(LayoutKind.Sequential)]
internal struct SmallRect
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}

View File

@ -6,6 +6,7 @@ global using SharpCompress.Archives.SevenZip;
global using SharpCompress.Readers;
global using SrcMod.Shell.Extensions;
global using SrcMod.Shell.Interop;
global using SrcMod.Shell.Interop.ObjectModels;
global using SrcMod.Shell.Modules;
global using SrcMod.Shell.Modules.ObjectModels;
global using SrcMod.Shell.ObjectModels;

View File

@ -0,0 +1,44 @@
namespace SrcMod.Shell.Modules.Valve;
[Module("vkv")]
public static class VkvModule
{
[Command("create")]
public static void CreateVkv(string path)
{
if (File.Exists(path)) throw new($"File already exists at \"{path}\". Did you mean to run \"vkv edit\"?");
VkvNode parentNode = new VkvTreeNode()
{
{ "key", new VkvSingleNode("value") }
};
string parentNodeName = "tree";
VkvModifyWhole(ref parentNode, ref parentNodeName);
}
private static void VkvModifyWhole(ref VkvNode node, ref string nodeName)
{
VkvDisplayNode(node, nodeName);
}
private static void VkvDisplayNode(in VkvNode? node, in string nodeName, in int indent = 0)
{
int spaceCount = indent * 4;
if (node is null) return;
else if (node is VkvSingleNode single)
{
Write(new string(' ', spaceCount) + $"\"{nodeName}\" \"{single.value}\"");
}
else if (node is VkvTreeNode tree)
{
Write(new string(' ', spaceCount) + $"\"{nodeName}\"\n" + new string(' ', spaceCount) + "{");
foreach (KeyValuePair<string, VkvNode?> subNode in tree)
{
VkvDisplayNode(subNode.Value, subNode.Key, indent + 1);
}
Write(new string(' ', spaceCount) + "}");
}
else return;
}
}