Added 'wpfhwacceleration' console command for windows

Bryan Roe committed Dec 10, 2019 at 14:15 UTC 2a5738b7e9b5d61debe3ab1ef146cb52a9a34f27
1 file changed +70 -1
agents/meshcore.js
+70 -1
@@ -1871,7 +1871,11 @@ function createMeshCore(agent) {
1871 var response = null;
1872 switch (cmd) {
1873 case 'help': { // Displays available commands
1874 - var fin = '', f = '', availcommands = 'help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,nwslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,amt,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,sendcaps,openurl,amtreset,amtccm,amtacm,amtdeactivate,amtpolicy,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,scanamt,safemode,wallpaper';
1874 + var fin = '', f = '', availcommands = 'help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,nwslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,amt,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,sendcaps,openurl,amtreset,amtccm,amtacm,amtdeactivate,amtpolicy,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,scanamt,wallpaper';
1875 + if (process.platform == 'win32')
1876 + {
1877 + availcommands += ',safemode,wpfhwacceleration';
1878 + }
1879 availcommands = availcommands.split(',').sort();
1880 while (availcommands.length > 0) {
1881 if (f.length > 100) { fin += (f + ',\r\n'); f = ''; }
@@ -1881,6 +1885,71 @@ function createMeshCore(agent) {
1885 response = 'Available commands: \r\n' + fin + '.';
1886 break;
1887 }
1888 + case 'wpfhwacceleration':
1889 + if (process.platform != 'win32') { throw ('wpfhwacceleration setting is only supported on Windows'); }
1890 + if (args['_'].length != 1)
1891 + {
1892 + response = 'Proper usage: wpfhwacceleration (ON|OFF|STATUS)'; // Display usage
1893 + }
1894 + else
1895 + {
1896 + var reg = require('win-registry');
1897 + var uname = require('user-sessions').getUsername(require('user-sessions').consoleUid());
1898 + var key = reg.usernameToUserKey(uname);
1899 +
1900 + switch(args['_'][0].toUpperCase())
1901 + {
1902 + default:
1903 + response = 'Proper usage: wpfhwacceleration (ON|OFF|STATUS|DEFAULT)'; // Display usage
1904 + break;
1905 + case 'ON':
1906 + try
1907 + {
1908 + reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 1);
1909 + response = 'OK';
1910 + }
1911 + catch (ee)
1912 + {
1913 + response = 'FAILED';
1914 + }
1915 + break;
1916 + case 'OFF':
1917 + try
1918 + {
1919 + reg.WriteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration', 0);
1920 + response = 'OK';
1921 + }
1922 + catch (ee)
1923 + {
1924 + response = 'FAILED';
1925 + }
1926 + break;
1927 + break;
1928 + case 'STATUS':
1929 + var s;
1930 + try
1931 + {
1932 + s = reg.QueryKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration')==1?'ENABLED':'DISABLED';
1933 + }
1934 + catch (ee)
1935 + {
1936 + s = 'DEFAULT';
1937 + }
1938 + response = 'WPF Hardware Acceleration: ' + s;
1939 + break;
1940 + case 'DEFAULT':
1941 + try
1942 + {
1943 + reg.DeleteKey(reg.HKEY.Users, key + '\\SOFTWARE\\Microsoft\\Avalon.Graphics', 'DisableHWAcceleration');
1944 + }
1945 + catch (ee)
1946 + {
1947 + }
1948 + response = 'OK';
1949 + break;
1950 + }
1951 + }
1952 + break;
1953 case 'tsid':
1954 if (process.platform == 'win32')
1955 {