@@ -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+
2852bool 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
75101void dnyAS_PluginUnload (void )
76102{
77103 // Called when plugin gets unloaded
104+
105+ g_pShellPluginAPI->Cmd_UnregisterCommand (L" env_getvariable" );
78106}
79107
80108BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
0 commit comments