1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Split IDE into 2 projects.

BEWARE: HIGHLY EXPERIMENTAL BRANCH
This commit is contained in:
Cristian Maglie
2014-09-23 17:31:46 +02:00
parent 2de206cccd
commit ba8eadeeb5
274 changed files with 5903 additions and 4826 deletions

View File

@ -0,0 +1,335 @@
package processing.app.windows;
/*
* Advapi32.java
*
* Created on 6. August 2007, 11:24
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.*;
/**
*
* @author TB
*/
public interface Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", Advapi32.class, Options.UNICODE_OPTIONS);
/*
BOOL WINAPI LookupAccountName(
LPCTSTR lpSystemName,
LPCTSTR lpAccountName,
PSID Sid,
LPDWORD cbSid,
LPTSTR ReferencedDomainName,
LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse
);*/
public boolean LookupAccountName(String lpSystemName, String lpAccountName,
byte[] Sid, IntByReference cbSid, char[] ReferencedDomainName,
IntByReference cchReferencedDomainName, PointerByReference peUse);
/*
BOOL WINAPI LookupAccountSid(
LPCTSTR lpSystemName,
PSID lpSid,
LPTSTR lpName,
LPDWORD cchName,
LPTSTR lpReferencedDomainName,
LPDWORD cchReferencedDomainName,
PSID_NAME_USE peUse
);*/
public boolean LookupAccountSid(String lpSystemName, byte[] Sid,
char[] lpName, IntByReference cchName, char[] ReferencedDomainName,
IntByReference cchReferencedDomainName, PointerByReference peUse);
/*
BOOL ConvertSidToStringSid(
PSID Sid,
LPTSTR* StringSid
);*/
public boolean ConvertSidToStringSid(byte[] Sid, PointerByReference StringSid);
/*
BOOL WINAPI ConvertStringSidToSid(
LPCTSTR StringSid,
PSID* Sid
);*/
public boolean ConvertStringSidToSid(String StringSid, PointerByReference Sid);
/*
SC_HANDLE WINAPI OpenSCManager(
LPCTSTR lpMachineName,
LPCTSTR lpDatabaseName,
DWORD dwDesiredAccess
);*/
public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName, int dwDesiredAccess);
/*
BOOL WINAPI CloseServiceHandle(
SC_HANDLE hSCObject
);*/
public boolean CloseServiceHandle(Pointer hSCObject);
/*
SC_HANDLE WINAPI OpenService(
SC_HANDLE hSCManager,
LPCTSTR lpServiceName,
DWORD dwDesiredAccess
);*/
public Pointer OpenService(Pointer hSCManager, String lpServiceName, int dwDesiredAccess);
/*
BOOL WINAPI StartService(
SC_HANDLE hService,
DWORD dwNumServiceArgs,
LPCTSTR* lpServiceArgVectors
);*/
public boolean StartService(Pointer hService, int dwNumServiceArgs, char[] lpServiceArgVectors);
/*
BOOL WINAPI ControlService(
SC_HANDLE hService,
DWORD dwControl,
LPSERVICE_STATUS lpServiceStatus
);*/
public boolean ControlService(Pointer hService, int dwControl, SERVICE_STATUS lpServiceStatus);
/*
BOOL WINAPI StartServiceCtrlDispatcher(
const SERVICE_TABLE_ENTRY* lpServiceTable
);*/
public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
/*
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler(
LPCTSTR lpServiceName,
LPHANDLER_FUNCTION lpHandlerProc
);*/
public Pointer RegisterServiceCtrlHandler(String lpServiceName, Handler lpHandlerProc);
/*
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx(
LPCTSTR lpServiceName,
LPHANDLER_FUNCTION_EX lpHandlerProc,
LPVOID lpContext
);*/
public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName, HandlerEx lpHandlerProc, Pointer lpContext);
/*
BOOL WINAPI SetServiceStatus(
SERVICE_STATUS_HANDLE hServiceStatus,
LPSERVICE_STATUS lpServiceStatus
);*/
public boolean SetServiceStatus(Pointer hServiceStatus, SERVICE_STATUS lpServiceStatus);
/*
SC_HANDLE WINAPI CreateService(
SC_HANDLE hSCManager,
LPCTSTR lpServiceName,
LPCTSTR lpDisplayName,
DWORD dwDesiredAccess,
DWORD dwServiceType,
DWORD dwStartType,
DWORD dwErrorControl,
LPCTSTR lpBinaryPathName,
LPCTSTR lpLoadOrderGroup,
LPDWORD lpdwTagId,
LPCTSTR lpDependencies,
LPCTSTR lpServiceStartName,
LPCTSTR lpPassword
);*/
public Pointer CreateService(Pointer hSCManager, String lpServiceName, String lpDisplayName,
int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl,
String lpBinaryPathName, String lpLoadOrderGroup, IntByReference lpdwTagId,
String lpDependencies, String lpServiceStartName, String lpPassword);
/*
BOOL WINAPI DeleteService(
SC_HANDLE hService
);*/
public boolean DeleteService(Pointer hService);
/*
BOOL WINAPI ChangeServiceConfig2(
SC_HANDLE hService,
DWORD dwInfoLevel,
LPVOID lpInfo
);*/
public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel, ChangeServiceConfig2Info lpInfo);
/*
LONG WINAPI RegOpenKeyEx(
HKEY hKey,
LPCTSTR lpSubKey,
DWORD ulOptions,
REGSAM samDesired,
PHKEY phkResult
);*/
public int RegOpenKeyEx(int hKey, String lpSubKey, int ulOptions, int samDesired, IntByReference phkResult);
/*
LONG WINAPI RegQueryValueEx(
HKEY hKey,
LPCTSTR lpValueName,
LPDWORD lpReserved,
LPDWORD lpType,
LPBYTE lpData,
LPDWORD lpcbData
);*/
public int RegQueryValueEx(int hKey, String lpValueName, IntByReference lpReserved, IntByReference lpType, byte[] lpData, IntByReference lpcbData);
/*
LONG WINAPI RegCloseKey(
HKEY hKey
);*/
public int RegCloseKey(int hKey);
/*
LONG WINAPI RegDeleteValue(
HKEY hKey,
LPCTSTR lpValueName
);*/
public int RegDeleteValue(int hKey, String lpValueName);
/*
LONG WINAPI RegSetValueEx(
HKEY hKey,
LPCTSTR lpValueName,
DWORD Reserved,
DWORD dwType,
const BYTE* lpData,
DWORD cbData
);*/
public int RegSetValueEx(int hKey, String lpValueName, int Reserved, int dwType, byte[] lpData, int cbData);
/*
LONG WINAPI RegCreateKeyEx(
HKEY hKey,
LPCTSTR lpSubKey,
DWORD Reserved,
LPTSTR lpClass,
DWORD dwOptions,
REGSAM samDesired,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
PHKEY phkResult,
LPDWORD lpdwDisposition
);*/
public int RegCreateKeyEx(int hKey, String lpSubKey, int Reserved, String lpClass, int dwOptions,
int samDesired, WINBASE.SECURITY_ATTRIBUTES lpSecurityAttributes, IntByReference phkResult,
IntByReference lpdwDisposition);
/*
LONG WINAPI RegDeleteKey(
HKEY hKey,
LPCTSTR lpSubKey
);*/
public int RegDeleteKey(int hKey, String name);
/*
LONG WINAPI RegEnumKeyEx(
HKEY hKey,
DWORD dwIndex,
LPTSTR lpName,
LPDWORD lpcName,
LPDWORD lpReserved,
LPTSTR lpClass,
LPDWORD lpcClass,
PFILETIME lpftLastWriteTime
);*/
public int RegEnumKeyEx(int hKey, int dwIndex, char[] lpName, IntByReference lpcName, IntByReference reserved,
char[] lpClass, IntByReference lpcClass, WINBASE.FILETIME lpftLastWriteTime);
/*
LONG WINAPI RegEnumValue(
HKEY hKey,
DWORD dwIndex,
LPTSTR lpValueName,
LPDWORD lpcchValueName,
LPDWORD lpReserved,
LPDWORD lpType,
LPBYTE lpData,
LPDWORD lpcbData
);*/
public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName, IntByReference lpcchValueName, IntByReference reserved,
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
/*
VOID WINAPI ServiceMain(
DWORD dwArgc,
LPTSTR* lpszArgv
);*/
public void callback(int dwArgc, Pointer lpszArgv);
}
interface Handler extends StdCallCallback {
/*
VOID WINAPI Handler(
DWORD fdwControl
);*/
public void callback(int fdwControl);
}
interface HandlerEx extends StdCallCallback {
/*
DWORD WINAPI HandlerEx(
DWORD dwControl,
DWORD dwEventType,
LPVOID lpEventData,
LPVOID lpContext
);*/
public void callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext);
}
/*
typedef struct _SERVICE_STATUS {
DWORD dwServiceType;
DWORD dwCurrentState;
DWORD dwControlsAccepted;
DWORD dwWin32ExitCode;
DWORD dwServiceSpecificExitCode;
DWORD dwCheckPoint;
DWORD dwWaitHint;
} SERVICE_STATUS,
*LPSERVICE_STATUS;*/
public static class SERVICE_STATUS extends Structure {
public int dwServiceType;
public int dwCurrentState;
public int dwControlsAccepted;
public int dwWin32ExitCode;
public int dwServiceSpecificExitCode;
public int dwCheckPoint;
public int dwWaitHint;
}
/*
typedef struct _SERVICE_TABLE_ENTRY {
LPTSTR lpServiceName;
LPSERVICE_MAIN_FUNCTION lpServiceProc;
} SERVICE_TABLE_ENTRY,
*LPSERVICE_TABLE_ENTRY;*/
public static class SERVICE_TABLE_ENTRY extends Structure {
public String lpServiceName;
public SERVICE_MAIN_FUNCTION lpServiceProc;
}
public static class ChangeServiceConfig2Info extends Structure {
}
/*
typedef struct _SERVICE_DESCRIPTION {
LPTSTR lpDescription;
} SERVICE_DESCRIPTION,
*LPSERVICE_DESCRIPTION;*/
public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
public String lpDescription;
}
}

View File

@ -0,0 +1,40 @@
package processing.app.windows;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Interprets the output of listComPorts.exe
* <p/>
* https://github.com/todbot/usbSearch/
*/
public class ListComPortsParser {
private final Pattern vidRegExp;
private final Pattern pidRegExp;
public ListComPortsParser() {
vidRegExp = Pattern.compile("VID_(\\w\\w\\w\\w)");
pidRegExp = Pattern.compile("PID_(\\w\\w\\w\\w)");
}
public String extractVIDAndPID(String output, String serial) throws IOException {
BufferedReader reader = new BufferedReader(new StringReader(output));
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith(serial.toUpperCase())) {
Matcher vidMatcher = vidRegExp.matcher(line);
Matcher pidMatcher = pidRegExp.matcher(line);
if (vidMatcher.find() && pidMatcher.find()) {
return ("0x" + vidMatcher.group(1) + "_0x" + pidMatcher.group(1)).toUpperCase();
}
}
}
return null;
}
}

View File

@ -0,0 +1,27 @@
/*
* Options.java
*
* Created on 8. August 2007, 17:07
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package processing.app.windows;
import static com.sun.jna.Library.*;
import com.sun.jna.win32.*;
import java.util.*;
/**
*
* @author TB
*/
public interface Options {
Map<String, Object> UNICODE_OPTIONS = new HashMap<String, Object>() {
{
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
}
};
}

View File

@ -0,0 +1,456 @@
package processing.app.windows;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.TreeSet;
import com.sun.jna.ptr.IntByReference;
/**
* Methods for accessing the Windows Registry. Only String and DWORD values supported at the moment.
*/
public class Registry {
public static enum REGISTRY_ROOT_KEY{CLASSES_ROOT, CURRENT_USER, LOCAL_MACHINE, USERS};
private final static HashMap<REGISTRY_ROOT_KEY, Integer> rootKeyMap = new HashMap<REGISTRY_ROOT_KEY, Integer>();
static {
rootKeyMap.put(REGISTRY_ROOT_KEY.CLASSES_ROOT, WINREG.HKEY_CLASSES_ROOT);
rootKeyMap.put(REGISTRY_ROOT_KEY.CURRENT_USER, WINREG.HKEY_CURRENT_USER);
rootKeyMap.put(REGISTRY_ROOT_KEY.LOCAL_MACHINE, WINREG.HKEY_LOCAL_MACHINE);
rootKeyMap.put(REGISTRY_ROOT_KEY.USERS, WINREG.HKEY_USERS);
}
/**
* Testing.
*
* @param args arguments
* @throws java.lang.Exception on error
*/
public static void main(String[] args) throws Exception {
}
/**
* Gets one of the root keys.
*
* @param key key type
* @return root key
*/
private static int getRegistryRootKey(REGISTRY_ROOT_KEY key) {
Advapi32 advapi32;
IntByReference pHandle;
int handle = 0;
advapi32 = Advapi32.INSTANCE;
pHandle = new IntByReference();
if(advapi32.RegOpenKeyEx(rootKeyMap.get(key), null, 0, 0, pHandle) == WINERROR.ERROR_SUCCESS) {
handle = pHandle.getValue();
}
return(handle);
}
/**
* Opens a key.
*
* @param rootKey root key
* @param subKeyName name of the key
* @param access access mode
* @return handle to the key or 0
*/
private static int openKey(REGISTRY_ROOT_KEY rootKey, String subKeyName, int access) {
Advapi32 advapi32;
IntByReference pHandle;
int rootKeyHandle;
advapi32 = Advapi32.INSTANCE;
rootKeyHandle = getRegistryRootKey(rootKey);
pHandle = new IntByReference();
if(advapi32.RegOpenKeyEx(rootKeyHandle, subKeyName, 0, access, pHandle) == WINERROR.ERROR_SUCCESS) {
return(pHandle.getValue());
} else {
return(0);
}
}
/**
* Converts a Windows buffer to a Java String.
*
* @param buf buffer
* @throws java.io.UnsupportedEncodingException on error
* @return String
*/
private static String convertBufferToString(byte[] buf) throws UnsupportedEncodingException {
return(new String(buf, 0, buf.length - 2, "UTF-16LE"));
}
/**
* Converts a Windows buffer to an int.
*
* @param buf buffer
* @return int
*/
private static int convertBufferToInt(byte[] buf) {
return(((int)(buf[0] & 0xff)) + (((int)(buf[1] & 0xff)) << 8) + (((int)(buf[2] & 0xff)) << 16) + (((int)(buf[3] & 0xff)) << 24));
}
/**
* Read a String value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @throws java.io.UnsupportedEncodingException on error
* @return String or null
*/
public static String getStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) throws UnsupportedEncodingException {
Advapi32 advapi32;
IntByReference pType, lpcbData;
byte[] lpData = new byte[1];
int handle = 0;
String ret = null;
advapi32 = Advapi32.INSTANCE;
pType = new IntByReference();
lpcbData = new IntByReference();
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
if(handle != 0) {
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
ret = convertBufferToString(lpData);
}
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Read an int value.
*
*
* @return int or 0
* @param rootKey root key
* @param subKeyName key name
* @param name value name
*/
public static int getIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
Advapi32 advapi32;
IntByReference pType, lpcbData;
byte[] lpData = new byte[1];
int handle = 0;
int ret = 0;
advapi32 = Advapi32.INSTANCE;
pType = new IntByReference();
lpcbData = new IntByReference();
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
if(handle != 0) {
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
ret = convertBufferToInt(lpData);
}
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Delete a value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @return true on success
*/
public static boolean deleteValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
Advapi32 advapi32;
int handle;
boolean ret = true;
advapi32 = Advapi32.INSTANCE;
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
if(handle != 0) {
if(advapi32.RegDeleteValue(handle, name) == WINERROR.ERROR_SUCCESS) {
ret = true;
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Writes a String value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @param value value
* @throws java.io.UnsupportedEncodingException on error
* @return true on success
*/
public static boolean setStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, String value) throws UnsupportedEncodingException {
Advapi32 advapi32;
int handle;
byte[] data;
boolean ret = false;
// appears to be Java 1.6 syntax, removing [fry]
//data = Arrays.copyOf(value.getBytes("UTF-16LE"), value.length() * 2 + 2);
data = new byte[value.length() * 2 + 2];
byte[] src = value.getBytes("UTF-16LE");
System.arraycopy(src, 0, data, 0, src.length);
advapi32 = Advapi32.INSTANCE;
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
if(handle != 0) {
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_SZ, data, data.length) == WINERROR.ERROR_SUCCESS) {
ret = true;
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Writes an int value.
*
*
* @return true on success
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @param value value
*/
public static boolean setIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, int value) {
Advapi32 advapi32;
int handle;
byte[] data;
boolean ret = false;
data = new byte[4];
data[0] = (byte)(value & 0xff);
data[1] = (byte)((value >> 8) & 0xff);
data[2] = (byte)((value >> 16) & 0xff);
data[3] = (byte)((value >> 24) & 0xff);
advapi32 = Advapi32.INSTANCE;
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
if(handle != 0) {
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_DWORD, data, data.length) == WINERROR.ERROR_SUCCESS) {
ret = true;
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Check for existence of a value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @return true if exists
*/
public static boolean valueExists(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
Advapi32 advapi32;
IntByReference pType, lpcbData;
byte[] lpData = new byte[1];
int handle = 0;
boolean ret = false;
advapi32 = Advapi32.INSTANCE;
pType = new IntByReference();
lpcbData = new IntByReference();
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
if(handle != 0) {
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) != WINERROR.ERROR_FILE_NOT_FOUND) {
ret = true;
} else {
ret = false;
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Create a new key.
*
* @param rootKey root key
* @param parent name of parent key
* @param name key name
* @return true on success
*/
public static boolean createKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
Advapi32 advapi32;
IntByReference hkResult, dwDisposition;
int handle = 0;
boolean ret = false;
advapi32 = Advapi32.INSTANCE;
hkResult = new IntByReference();
dwDisposition = new IntByReference();
handle = openKey(rootKey, parent, WINNT.KEY_READ);
if(handle != 0) {
if(advapi32.RegCreateKeyEx(handle, name, 0, null, WINNT.REG_OPTION_NON_VOLATILE, WINNT.KEY_READ, null,
hkResult, dwDisposition) == WINERROR.ERROR_SUCCESS) {
ret = true;
advapi32.RegCloseKey(hkResult.getValue());
} else {
ret = false;
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Delete a key.
*
* @param rootKey root key
* @param parent name of parent key
* @param name key name
* @return true on success
*/
public static boolean deleteKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
Advapi32 advapi32;
int handle = 0;
boolean ret = false;
advapi32 = Advapi32.INSTANCE;
handle = openKey(rootKey, parent, WINNT.KEY_READ);
if(handle != 0) {
if(advapi32.RegDeleteKey(handle, name) == WINERROR.ERROR_SUCCESS) {
ret = true;
} else {
ret = false;
}
advapi32.RegCloseKey(handle);
}
return(ret);
}
/**
* Get all sub keys of a key.
*
* @param rootKey root key
* @param parent key name
* @return array with all sub key names
*/
public static String[] getSubKeys(REGISTRY_ROOT_KEY rootKey, String parent) {
Advapi32 advapi32;
int handle = 0, dwIndex;
char[] lpName;
IntByReference lpcName;
WINBASE.FILETIME lpftLastWriteTime;
TreeSet<String> subKeys = new TreeSet<String>();
advapi32 = Advapi32.INSTANCE;
handle = openKey(rootKey, parent, WINNT.KEY_READ);
lpName = new char[256];
lpcName = new IntByReference(256);
lpftLastWriteTime = new WINBASE.FILETIME();
if(handle != 0) {
dwIndex = 0;
while(advapi32.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null,
null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) {
subKeys.add(new String(lpName, 0, lpcName.getValue()));
lpcName.setValue(256);
dwIndex++;
}
advapi32.RegCloseKey(handle);
}
return(subKeys.toArray(new String[]{}));
}
/**
* Get all values under a key.
*
* @param rootKey root key
* @param key jey name
* @throws java.io.UnsupportedEncodingException on error
* @return TreeMap with name and value pairs
*/
public static TreeMap<String, Object> getValues(REGISTRY_ROOT_KEY rootKey, String key) throws UnsupportedEncodingException {
Advapi32 advapi32;
int handle = 0, dwIndex, result = 0;
char[] lpValueName;
byte[] lpData;
IntByReference lpcchValueName, lpType, lpcbData;
String name;
TreeMap<String, Object> values = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
advapi32 = Advapi32.INSTANCE;
handle = openKey(rootKey, key, WINNT.KEY_READ);
lpValueName = new char[16384];
lpcchValueName = new IntByReference(16384);
lpType = new IntByReference();
lpData = new byte[1];
lpcbData = new IntByReference();
if(handle != 0) {
dwIndex = 0;
do {
lpcbData.setValue(0);
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
lpType, lpData, lpcbData);
if(result == WINERROR.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
lpcchValueName = new IntByReference(16384);
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
lpType, lpData, lpcbData);
if(result == WINERROR.ERROR_SUCCESS) {
name = new String(lpValueName, 0, lpcchValueName.getValue());
switch(lpType.getValue()) {
case WINNT.REG_SZ:
values.put(name, convertBufferToString(lpData));
break;
case WINNT.REG_DWORD:
values.put(name, convertBufferToInt(lpData));
break;
default:
break;
}
}
}
dwIndex++;
} while(result == WINERROR.ERROR_SUCCESS);
advapi32.RegCloseKey(handle);
}
return(values);
}
}

View File

@ -0,0 +1,43 @@
/*
* WINBASE.java
*
* Created on 5. September 2007, 11:24
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package processing.app.windows;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
/**
*
* @author TB
*/
public interface WINBASE {
/*
typedef struct _SECURITY_ATTRIBUTES {
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES,
*PSECURITY_ATTRIBUTES,
*LPSECURITY_ATTRIBUTES;*/
public static class SECURITY_ATTRIBUTES extends Structure {
public int nLength;
public Pointer lpSecurityDescriptor;
public boolean bInheritHandle;
}
/*
typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;*/
public static class FILETIME extends Structure {
public int dwLowDateTime;
public int dwHighDateTime;
}
}

View File

@ -0,0 +1,22 @@
/*
* WINERROR.java
*
* Created on 7. August 2007, 08:09
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package processing.app.windows;
/**
*
* @author TB
*/
public interface WINERROR {
public final static int ERROR_SUCCESS = 0;
public final static int NO_ERROR = 0;
public final static int ERROR_FILE_NOT_FOUND = 2;
public final static int ERROR_MORE_DATA = 234;
}

View File

@ -0,0 +1,73 @@
/*
* WINNT.java
*
* Created on 8. August 2007, 13:41
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package processing.app.windows;
/**
*
* @author TB
*/
public interface WINNT {
public final static int DELETE = 0x00010000;
public final static int READ_CONTROL = 0x00020000;
public final static int WRITE_DAC = 0x00040000;
public final static int WRITE_OWNER = 0x00080000;
public final static int SYNCHRONIZE = 0x00100000;
public final static int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
public final static int STANDARD_RIGHTS_READ = READ_CONTROL;
public final static int STANDARD_RIGHTS_WRITE = READ_CONTROL;
public final static int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
public final static int STANDARD_RIGHTS_ALL = 0x001F0000;
public final static int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
public final static int GENERIC_EXECUTE = 0x20000000;
public final static int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
public final static int KEY_QUERY_VALUE = 0x0001;
public final static int KEY_SET_VALUE = 0x0002;
public final static int KEY_CREATE_SUB_KEY = 0x0004;
public final static int KEY_ENUMERATE_SUB_KEYS = 0x0008;
public final static int KEY_NOTIFY = 0x0010;
public final static int KEY_CREATE_LINK = 0x0020;
public final static int KEY_READ = ((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & (~SYNCHRONIZE));
public final static int KEY_WRITE = ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE));
public final static int REG_NONE = 0; // No value type
public final static int REG_SZ = 1; // Unicode nul terminated string
public final static int REG_EXPAND_SZ = 2; // Unicode nul terminated string
// (with environment variable references)
public final static int REG_BINARY = 3; // Free form binary
public final static int REG_DWORD = 4; // 32-bit number
public final static int REG_DWORD_LITTLE_ENDIAN = 4; // 32-bit number (same as REG_DWORD)
public final static int REG_DWORD_BIG_ENDIAN = 5; // 32-bit number
public final static int REG_LINK = 6; // Symbolic Link (unicode)
public final static int REG_MULTI_SZ = 7; // Multiple Unicode strings
public final static int REG_RESOURCE_LIST = 8; // Resource list in the resource map
public final static int REG_FULL_RESOURCE_DESCRIPTOR = 9; // Resource list in the hardware description
public final static int REG_RESOURCE_REQUIREMENTS_LIST = 10;
public final static int REG_OPTION_RESERVED = 0x00000000; // Parameter is reserved
public final static int REG_OPTION_NON_VOLATILE = 0x00000000; // Key is preserved
// when system is rebooted
public final static int REG_OPTION_VOLATILE = 0x00000001; // Key is not preserved
// when system is rebooted
public final static int REG_OPTION_CREATE_LINK = 0x00000002; // Created key is a
// symbolic link
public final static int REG_OPTION_BACKUP_RESTORE = 0x00000004; // open for backup or restore
// special access rules
// privilege required
public final static int REG_OPTION_OPEN_LINK = 0x00000008; // Open symbolic link
}

View File

@ -0,0 +1,21 @@
/*
* WINREG.java
*
* Created on 17. August 2007, 14:32
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package processing.app.windows;
/**
*
* @author TB
*/
public interface WINREG {
public final static int HKEY_CLASSES_ROOT = 0x80000000;
public final static int HKEY_CURRENT_USER = 0x80000001;
public final static int HKEY_LOCAL_MACHINE = 0x80000002;
public final static int HKEY_USERS = 0x80000003;
}