Skip to content

Commit e47ad9b

Browse files
committed
env_getvariable command
1 parent 32c05bb commit e47ad9b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

defplugins/envvars/envvars/interface.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ std::vector<std::wstring> split(const std::wstring& wszString, const wchar_t wcS
2525
return vResult;
2626
}
2727

28+
class IGetEnvVarCommandInterface : public IResultCommandInterface<dnyString> {
29+
public:
30+
IGetEnvVarCommandInterface() {}
31+
32+
virtual bool CommandCallback(void* pCodeContext, void* pInterfaceObject)
33+
{
34+
ICodeContext* pContext = (ICodeContext*)pCodeContext;
35+
36+
pContext->ReplaceAllVariables(pInterfaceObject);
37+
38+
std::wstring wszName = pContext->GetPartString(1);
39+
40+
wchar_t wszValue[32767] = { 0 };
41+
DWORD dwSize = GetEnvironmentVariable(wszName.c_str(), wszValue, sizeof(wszValue));
42+
43+
if ((dwSize > 0) && (dwSize < sizeof(wszValue))) {
44+
this->SetResult(std::wstring(wszValue));
45+
}
46+
47+
return ((dwSize) && (GetLastError() == ERROR_SUCCESS));
48+
}
49+
50+
} g_oGetEnvVarCommandInterface;
51+
2852
bool RegisterEnvironmentVariables(void)
2953
{
3054
//Register environment variables
@@ -68,13 +92,17 @@ bool dnyAS_PluginLoad(dnyVersionInfo version, IShellPluginAPI* pInterfaceData, p
6892
//Store plugin infos
6993
memcpy(pPluginInfos, &g_sPluginInfos, sizeof(plugininfo_s));
7094

95+
g_pShellPluginAPI->Cmd_RegisterCommand(L"env_getvariable", &g_oGetEnvVarCommandInterface, CT_STRING);
96+
7197
//Register environment variables
7298
return RegisterEnvironmentVariables();
7399
}
74100

75101
void dnyAS_PluginUnload(void)
76102
{
77103
//Called when plugin gets unloaded
104+
105+
g_pShellPluginAPI->Cmd_UnregisterCommand(L"env_getvariable");
78106
}
79107

80108
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)

0 commit comments

Comments
 (0)