git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@133 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
94 lines
3.3 KiB
Plaintext
94 lines
3.3 KiB
Plaintext
MODULE UsbUtils;
|
|
IMPORT WinApi, Strings, Log := StdLog, XC := XdeCmds;
|
|
|
|
CONST
|
|
HK_LM_JRE_Key = "SOFTWARE\javaSoft\Java Runtime Environment";
|
|
HK_LM_JRE_CurrentVersion_value = "CurrentVersion";
|
|
HK_LM_JRE_JavaHome_value = "JavaHome";
|
|
HK_LM_PATH_Key = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
|
|
HK_CU_PATH_Key = "Environment";
|
|
PATH_value = "PATH";
|
|
|
|
PROCEDURE RegCUQuery* (IN subKey, valueName: ARRAY OF SHORTCHAR;
|
|
OUT qValue: ARRAY OF SHORTCHAR): BOOLEAN;
|
|
VAR
|
|
res, length: INTEGER; hKey: WinApi.HKEY;
|
|
BEGIN
|
|
qValue := "";
|
|
res := WinApi.RegOpenKeyEx(WinApi.HKEY_CURRENT_USER,
|
|
subKey, 0, WinApi.KEY_QUERY_VALUE, hKey);
|
|
IF res # WinApi.ERROR_SUCCESS THEN
|
|
RETURN FALSE
|
|
ELSE
|
|
length := LEN(qValue);
|
|
res := WinApi.RegQueryValueEx(hKey, valueName, NIL, NIL, qValue[0], length);
|
|
IF res # WinApi.ERROR_SUCCESS THEN
|
|
RETURN FALSE
|
|
END
|
|
END;
|
|
res := WinApi.RegCloseKey(hKey);
|
|
RETURN TRUE;
|
|
END RegCUQuery;
|
|
|
|
PROCEDURE RegCUCreateKeyAndSetValue* (IN subKey, valueName: ARRAY OF SHORTCHAR;
|
|
newValue: ARRAY OF SHORTCHAR): BOOLEAN;
|
|
VAR
|
|
res, length, lpdwDisposition: INTEGER; hKey: WinApi.HKEY;
|
|
BEGIN
|
|
res := WinApi.RegCreateKeyEx(WinApi.HKEY_CURRENT_USER, subKey, 0, NIL,
|
|
WinApi.REG_OPTION_NON_VOLATILE, WinApi.KEY_ALL_ACCESS, NIL, hKey, lpdwDisposition);
|
|
IF res # WinApi.ERROR_SUCCESS THEN
|
|
RETURN FALSE
|
|
END;
|
|
res := WinApi.RegSetValueEx(hKey, valueName, 0, WinApi.REG_SZ,
|
|
newValue[0], LEN(newValue$));
|
|
IF res # WinApi.ERROR_SUCCESS THEN
|
|
RETURN FALSE
|
|
END;
|
|
res := WinApi.RegCloseKey(hKey);
|
|
RETURN TRUE
|
|
END RegCUCreateKeyAndSetValue;
|
|
|
|
PROCEDURE CheckAndSetPath*;
|
|
CONST
|
|
PATH_Pattern = "\bin\client";
|
|
VAR
|
|
jreHome, regValue, tmpRegValue: ARRAY 512 OF SHORTCHAR;
|
|
pos: INTEGER; noUserPathValue, found: BOOLEAN;
|
|
BEGIN
|
|
(* get jre home path *)
|
|
XC.RegLocalMachineQuery(HK_LM_JRE_Key, HK_LM_JRE_CurrentVersion_value, tmpRegValue); (* e.g. "1.5" *)
|
|
XC.RegLocalMachineQuery(HK_LM_JRE_Key + "\" + tmpRegValue, HK_LM_JRE_JavaHome_value, jreHome);
|
|
(* look for %javahome%\bin\client on system and user path*)
|
|
regValue := jreHome + PATH_Pattern;
|
|
XC.RegLocalMachineQuery(HK_LM_PATH_Key, PATH_value, tmpRegValue);
|
|
Strings.Find(LONG(tmpRegValue), LONG(regValue), 0, pos);
|
|
found := pos >= 0;
|
|
IF found THEN
|
|
Log.String("the PATH system variable " + regValue + " is already set"); Log.Ln;
|
|
RETURN
|
|
END;
|
|
tmpRegValue := "";
|
|
noUserPathValue := ~RegCUQuery(HK_CU_PATH_Key, PATH_value, tmpRegValue);
|
|
Strings.Find(LONG(tmpRegValue), PATH_Pattern, 0, pos);
|
|
found := pos >= 0;
|
|
IF ~found THEN (* insert registry key into user PATH variable *)
|
|
IF tmpRegValue = "" THEN
|
|
tmpRegValue := regValue;
|
|
ELSE
|
|
tmpRegValue := tmpRegValue + ";" + regValue
|
|
END;
|
|
IF RegCUCreateKeyAndSetValue(HK_CU_PATH_Key, PATH_value, tmpRegValue) THEN
|
|
IF noUserPathValue THEN (* create user PATH value first *)
|
|
Log.String("user value PATH created"); Log.Ln;
|
|
END;
|
|
Log.String(regValue + " added to user PATH"); Log.Ln;
|
|
ELSE
|
|
Log.String("UsbUtils: Error on CreateKey with value " + tmpRegValue); Log.Ln;
|
|
END;
|
|
ELSE
|
|
Log.String("the PATH user variable " + regValue + " is already set"); Log.Ln;
|
|
END
|
|
END CheckAndSetPath;
|
|
|
|
END UsbUtils. |