From 8fee283c3d73e81213cf10cda431b19a5c55e196 Mon Sep 17 00:00:00 2001 From: d0vgan Date: Thu, 10 Dec 2020 19:23:13 +0200 Subject: [PATCH] Reading the Hash Keys from a file --- SharpKeys/Dialog_Main.cs | 59 +++++++++++++++++++++++++++ SharpKeys/bin/Debug/SharpKeys.keys | Bin 0 -> 18092 bytes SharpKeys/bin/Release/SharpKeys.keys | Bin 0 -> 18092 bytes 3 files changed, 59 insertions(+) create mode 100644 SharpKeys/bin/Debug/SharpKeys.keys create mode 100644 SharpKeys/bin/Release/SharpKeys.keys diff --git a/SharpKeys/Dialog_Main.cs b/SharpKeys/Dialog_Main.cs index 6c6c988..028c138 100644 --- a/SharpKeys/Dialog_Main.cs +++ b/SharpKeys/Dialog_Main.cs @@ -5,6 +5,7 @@ using System.Windows.Forms; using System.ComponentModel; using System.IO; +using System.Text.RegularExpressions; using Microsoft.Win32; namespace SharpKeys @@ -826,11 +827,69 @@ private void btnSaveKeys_Click(object sender, EventArgs e) } } + private string UnquoteString(string s) + { + // remove the leading & trailing '"' + if (s.StartsWith("\"") && s.EndsWith("\"")) + { + s = s.Substring(1, s.Length - 2); + } + return s; + } + + private bool ReadHashKeysFromFile(string pathToKeysFile) + { + if (!File.Exists(pathToKeysFile)) + return false; // the file does not exist + + string[] lines = File.ReadAllLines(pathToKeysFile, System.Text.Encoding.Unicode); + if (lines.Length == 0) + return false; // the file is empty + + m_hashKeys = new Hashtable(); + + foreach (string line in lines) + { + string[] items = line.Split(new char[]{','}, 2); + if (items.GetLength(0) == 2) + { + string param1 = items[0].Trim(); // w/o leading & trailing spaces + string param2 = items[1].Trim(); // w/o leading & trailing spaces + + int n = param2.LastIndexOf('"'); + if (n != -1) + { + // removing the trailing '//' after the last '"', if any + n = param2.IndexOf("//", n); + if (n != -1) + { + param2 = param2.Remove(n); + param2 = param2.TrimEnd(); + } + } + + param2 = UnquoteString(param2); + param2 = Regex.Unescape(param2); + + param1 = UnquoteString(param1); + param1 = Regex.Unescape(param1); + + m_hashKeys.Add(param1, param2); + } + } + return true; + } + private void BuildParseTables() { if (m_hashKeys != null) return; + string pathToExeDir = Path.GetDirectoryName(Application.ExecutablePath); + string pathToKeysFile = Path.Combine(pathToExeDir, "SharpKeys.keys"); + if (ReadHashKeysFromFile(pathToKeysFile)) + return; + // the hash table uses a string in the form of Hi_Lo scan code (in Hex values) // that most sources say are scan codes. The 00_00 will disable a key - everything else // is pretty obvious. There is a bit of a reverse lookup however, so labels changed here diff --git a/SharpKeys/bin/Debug/SharpKeys.keys b/SharpKeys/bin/Debug/SharpKeys.keys new file mode 100644 index 0000000000000000000000000000000000000000..639af435da2ed4ee01195039623ef1e22f4cb943 GIT binary patch literal 18092 zcmcg!Yja#j5uMLe@gElPNCNR=-$_UUdu46x#Il9u2aiA^OR^&@TPn$pa1r=7eB(C) zeP%rF?&-d>vvL)s@qoavtFyZrY*8{s_QG-agcw`loc_KS|Gngm-tyA* zfgjSJpO^?^2RS0-Zw+$dAjgFKsXY zAU}4H9})7G2DxyM9~1I@gX|pSbwYk%kedz?+W5vGZ#c-$2>C06+ z<~06xXxPgN`#y0VzhOv?4oRz7qpY>x71th;`Yh^^L3z5xJ?V&^X73r4r`P)iJTt(&rhiU*(LlZdpUPH$CsHPe$#&K}qDu)g(r!QJy9dL!&%Reqm6aCT|*) zr^zo3%G2am2IXn;wn2HC{58$QCkE;1@;yR+O~~?@cUkjR%lHZyWu;^Y|uy< z$>x?QZ=?OW}MuZkIr*dAW zLeqS`(vwqB|1zrd;WV&z8HM^Z(DpMjz1X@{InRgo`)p%=Pd$8u#@u4dt_* z(!b?9ukp&KKdox?7OnGlNu7rj7ZuXRaqN7shHH0O zs(LC`{~E8XU8jL{UgMP&!Bi-}#w#n6sqjLLSJuQ+I#pv%L9nK|vSBBSHuB@-i&h5J{BCmg4&R2ccMdbCb z%g*<&n|7=6y0>Vx*rrI^^lT4kl|)`&(w`wIcSPrhY2`dGo;T;nzBq8gyT{=y+ZPAU zdG|QH67|J_Yu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zvs>LQg>q!KG%0Cyw>0s%Tbg<7%lWl)Y1Cp-Ol{QE;kNo-55n-eZQp zC!LAB$Jk{Y&qchCyk>9EE(T}YGqGD^Mte=hS{ye0c{naAGhzem}h%e)pp$^KmCv7c)3%A7ZEIv+_WJrA7qYVm;5 zJl?a_ctB}hOa4n;Jk4v#f2oV7d7S@h;{;0cIOo-PWu+;5b2T2^s^hhIPv;NBkAHtHK3c>bTzf>FgZ#KHK3v3X*dAABRzGfw zj~6ksw#Uu+*^k(=0xV)?UMC_~Dt^?K^)}TeK653$Jwh35kp)SHh0! zn)(|?SlJUQ$J6K5-1|%K_oDxc>K?tJ^o_9>^gDk0K;@WDoVfMRWJ39obLSb~qCf{} zKvD39ar+2bs<1Ae^7$j+6{6*STWYs1o@)5fyq;OxlWwX0x|n}+WLdSR3coE}w;*JptZ<a)-{Gh4N_){-@@c2?X-hPG-`b1Tl0`d}MUf-Z zIT=od4hpBWWXDcr$NKeJa$l!%--9?htnN?9t*Bp~Q`Ls=v11>I{xP}**~i$aBP+nm zX$?6K`0gV1;{*CPpa--^2L@H&(`l@GUOv0$PcStM%3)8QwXi> z);q{&OgF^oj~*4e$@o@LsuQ5@Jo@!xtgp)TW2~>a^<(^h6t#7U3ToYZ*%Cd@+PtHZ zy6n7fiB3)}2I{BF$5_7xYJFDe8v>X4lrB!+08TEp=jJzK&igBU=KtpyePXi|^VG+F KN>%c4!T%p{%MynG literal 0 HcmV?d00001 diff --git a/SharpKeys/bin/Release/SharpKeys.keys b/SharpKeys/bin/Release/SharpKeys.keys new file mode 100644 index 0000000000000000000000000000000000000000..639af435da2ed4ee01195039623ef1e22f4cb943 GIT binary patch literal 18092 zcmcg!Yja#j5uMLe@gElPNCNR=-$_UUdu46x#Il9u2aiA^OR^&@TPn$pa1r=7eB(C) zeP%rF?&-d>vvL)s@qoavtFyZrY*8{s_QG-agcw`loc_KS|Gngm-tyA* zfgjSJpO^?^2RS0-Zw+$dAjgFKsXY zAU}4H9})7G2DxyM9~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