X-Git-Url: https://git.josue.xyz/?p=VSoRC%2F.git;a=blobdiff_plain;f=node_modules%2Fnode-pty%2Fsrc%2Fwin%2Fconpty_console_list.cc;fp=node_modules%2Fnode-pty%2Fsrc%2Fwin%2Fconpty_console_list.cc;h=be135ba024a73547ac9702bf7cb22ae649c60dd3;hp=0000000000000000000000000000000000000000;hb=e79e4a5a87f3e84f7c1777f10a954453a69bf540;hpb=4339da12467b75fb8b6ca831f4bf0081c485ed2c diff --git a/node_modules/node-pty/src/win/conpty_console_list.cc b/node_modules/node-pty/src/win/conpty_console_list.cc new file mode 100644 index 0000000..be135ba --- /dev/null +++ b/node_modules/node-pty/src/win/conpty_console_list.cc @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2019, Microsoft Corporation (MIT License). + */ + +#include +#include + +static NAN_METHOD(ApiConsoleProcessList) { + if (info.Length() != 1 || + !info[0]->IsNumber()) { + Nan::ThrowError("Usage: getConsoleProcessList(shellPid)"); + return; + } + + const SHORT pid = info[0]->Uint32Value(Nan::GetCurrentContext()).FromJust(); + + if (!FreeConsole()) { + Nan::ThrowError("FreeConsole failed"); + } + if (!AttachConsole(pid)) { + Nan::ThrowError("AttachConsole failed"); + } + auto processList = std::vector(64); + auto processCount = GetConsoleProcessList(&processList[0], processList.size()); + if (processList.size() < processCount) { + processList.resize(processCount); + processCount = GetConsoleProcessList(&processList[0], processList.size()); + } + FreeConsole(); + + v8::Local result = Nan::New(); + for (DWORD i = 0; i < processCount; i++) { + Nan::Set(result, i, Nan::New(processList[i])); + } + info.GetReturnValue().Set(result); +} + +extern "C" void init(v8::Local target) { + Nan::HandleScope scope; + Nan::SetMethod(target, "getConsoleProcessList", ApiConsoleProcessList); +}; + +NODE_MODULE(pty, init);