From dc2edce1efa7ff1dafd53ca90c6f2d0d1957e3c6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 26 Apr 2011 14:29:38 +0000 Subject: [PATCH] 2011-04-26 16:28 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/hbwin.ch * contrib/hbwin/win_regc.c * contrib/hbwin/win_reg.prg * contrib/hbwin/tests/testreg.prg + added type parameter to win_regWrite()/win_regSet()/win_regSetValueEx() functions + added QWORD support in win registry ! fixed very old xhb typo: sizeof( REG_DWORD ) -> sizeof( DWORD ) (didn't cause actual error in compiled code) + added REG_DWORD, REG_QWORD tests * package/mpkg_win.nsi * package/winuni/mpkg_win_uni.nsi * uninstall icon changed to better looking one --- harbour/ChangeLog | 15 ++++++++ harbour/contrib/hbwin/hbwin.ch | 16 ++++++++ harbour/contrib/hbwin/tests/testreg.prg | 8 ++++ harbour/contrib/hbwin/win_reg.prg | 49 +++++++++++++------------ harbour/contrib/hbwin/win_regc.c | 14 ++++++- harbour/package/mpkg_win.nsi | 1 + harbour/package/winuni/mpkg_win_uni.nsi | 1 + 7 files changed, 80 insertions(+), 24 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index de16f47afb..2d3366afe9 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ +2011-04-26 16:28 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbwin/hbwin.ch + * contrib/hbwin/win_regc.c + * contrib/hbwin/win_reg.prg + * contrib/hbwin/tests/testreg.prg + + added type parameter to win_regWrite()/win_regSet()/win_regSetValueEx() functions + + added QWORD support in win registry + ! fixed very old xhb typo: sizeof( REG_DWORD ) -> sizeof( DWORD ) + (didn't cause actual error in compiled code) + + added REG_DWORD, REG_QWORD tests + + * package/mpkg_win.nsi + * package/winuni/mpkg_win_uni.nsi + * uninstall icon changed to better looking one + 2011-04-26 14:34 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * package/harb_osx.icns * package/harb_win.ico diff --git a/harbour/contrib/hbwin/hbwin.ch b/harbour/contrib/hbwin/hbwin.ch index 0ab3b368dc..efeb66a1e5 100644 --- a/harbour/contrib/hbwin/hbwin.ch +++ b/harbour/contrib/hbwin/hbwin.ch @@ -70,6 +70,22 @@ #define WIN_HKEY_CURRENT_CONFIG 0x80000005 #define WIN_HKEY_DYN_DATA 0x80000006 +/* Windows registry key types in win_regWrite()/win_regSet()/win_regSetValueEx() functions */ +#define WIN_REG_NONE 0 /* No value type */ +#define WIN_REG_SZ 1 /* Unicode nul terminated string */ +#define WIN_REG_EXPAND_SZ 2 /* Unicode nul terminated string (with environment variable references) */ +#define WIN_REG_BINARY 3 /* Free form binary */ +#define WIN_REG_DWORD 4 /* 32-bit number */ +#define WIN_REG_DWORD_LITTLE_ENDIAN 4 /* 32-bit number (same as REG_DWORD) */ +#define WIN_REG_DWORD_BIG_ENDIAN 5 /* 32-bit number */ +#define WIN_REG_LINK 6 /* Symbolic Link (unicode) */ +#define WIN_REG_MULTI_SZ 7 /* Multiple Unicode strings */ +#define WIN_REG_RESOURCE_LIST 8 /* Resource list in the resource map */ +#define WIN_REG_FULL_RESOURCE_DESCRIPTOR 9 /* Resource list in the hardware description */ +#define WIN_REG_RESOURCE_REQUIREMENTS_LIST 10 +#define WIN_REG_QWORD 11 /* 64-bit number */ +#define WIN_REG_QWORD_LITTLE_ENDIAN 11 /* 64-bit number (same as REG_QWORD) */ + /* WIN_PORT() related values */ /* WIN_COMOPEN() bit rates */ diff --git a/harbour/contrib/hbwin/tests/testreg.prg b/harbour/contrib/hbwin/tests/testreg.prg index aa7e2f9548..890950a44f 100644 --- a/harbour/contrib/hbwin/tests/testreg.prg +++ b/harbour/contrib/hbwin/tests/testreg.prg @@ -7,6 +7,14 @@ PROCEDURE Main() LOCAL tmp + ? win_regWrite( "HKCU\_TEST\mydword", 0x11223344, WIN_REG_DWORD ) + ? hb_numtohex( win_regRead( "HKCU\_TEST\mydword" ) ) + + ? win_regWrite( "HKCU\_TEST\myqword", 0x1122334455667788, WIN_REG_QWORD ) + ? hb_numtohex( win_regRead( "HKCU\_TEST\myqword" ) ) + + Inkey( 0 ) + ? win_regDelete( "HKCU\_TEST\teszt" ) ? win_regDelete( "HKCU\_TEST\" ) diff --git a/harbour/contrib/hbwin/win_reg.prg b/harbour/contrib/hbwin/win_reg.prg index ae22e7afb6..8891d8c59a 100644 --- a/harbour/contrib/hbwin/win_reg.prg +++ b/harbour/contrib/hbwin/win_reg.prg @@ -64,19 +64,6 @@ #define KEY_NOTIFY 16 #define KEY_CREATE_LINK 32 -#define REG_NONE 0 // No value type -#define REG_SZ 1 // Unicode nul terminated string -#define REG_EXPAND_SZ 2 // Unicode nul terminated string (with environment variable references) -#define REG_BINARY 3 // Free form binary -#define REG_DWORD 4 // 32-bit number -#define REG_DWORD_LITTLE_ENDIAN 4 // 32-bit number (same as REG_DWORD) -#define REG_DWORD_BIG_ENDIAN 5 // 32-bit number -#define REG_LINK 6 // Symbolic Link (unicode) -#define REG_MULTI_SZ 7 // Multiple Unicode strings -#define REG_RESOURCE_LIST 8 // Resource list in the resource map -#define REG_FULL_RESOURCE_DESCRIPTOR 9 // Resource list in the hardware description -#define REG_RESOURCE_REQUIREMENTS_LIST 10 - /* ------------------------------------------------------------------- */ PROCEDURE win_regPathSplit( cRegPath, /* @ */ nHKEY, /* @ */ cKey, /* @ */ cEntry ) @@ -128,12 +115,12 @@ FUNCTION win_regRead( cRegPath, xDefault ) RETURN win_regGet( nHKEY, cKey, cEntry, xDefault ) -FUNCTION win_regWrite( cRegPath, xValue ) +FUNCTION win_regWrite( cRegPath, xValue, nType ) LOCAL nHKEY, cKey, cEntry win_regPathSplit( cRegPath, @nHKEY, @cKey, @cEntry ) - RETURN win_regSet( nHKEY, cKey, cEntry, xValue ) + RETURN win_regSet( nHKEY, cKey, cEntry, xValue, nType ) FUNCTION win_regDelete( cRegPath ) LOCAL nHKEY, cKey, cEntry @@ -197,10 +184,15 @@ FUNCTION win_regGet( nHKEY, cKeyName, cEntryName, xDefault ) IF ISCHARACTER( xRetVal ) DO CASE - CASE nValueType == REG_DWORD .OR. nValueType == REG_DWORD_LITTLE_ENDIAN + CASE nValueType == WIN_REG_DWORD .OR. ; + nValueType == WIN_REG_DWORD_LITTLE_ENDIAN xRetVal := Bin2U( xRetVal ) - CASE nValueType == REG_DWORD_BIG_ENDIAN + CASE nValueType == WIN_REG_DWORD_BIG_ENDIAN xRetVal := Bin2U( Right( xRetVal, 2 ) + Left( xRetVal, 2 ) ) + CASE nValueType == WIN_REG_QWORD .OR. ; + nValueType == WIN_REG_QWORD_LITTLE_ENDIAN + xRetVal := hb_bitShift( Bin2U( SubStr( xRetVal, 5, 2 ) + SubStr( xRetVal, 7, 2 ) ), 32 ) +; + Bin2U( SubStr( xRetVal, 1, 2 ) + SubStr( xRetVal, 3, 2 ) ) OTHERWISE /* Strip ending zero byte */ IF Right( xRetVal, 1 ) == Chr( 0 ) @@ -218,9 +210,8 @@ FUNCTION win_regGet( nHKEY, cKeyName, cEntryName, xDefault ) RETURN xRetVal -FUNCTION win_regSet( nHKEY, cKeyName, cEntryName, xValue ) +FUNCTION win_regSet( nHKEY, cKeyName, cEntryName, xValue, nValueType ) LOCAL cName - LOCAL nValueType LOCAL lRetVal := .F. LOCAL pKeyHandle @@ -229,20 +220,32 @@ FUNCTION win_regSet( nHKEY, cKeyName, cEntryName, xValue ) /* no support for Arrays, Codeblock ... */ SWITCH ValType( xValue ) CASE "L" - nValueType := REG_DWORD + nValueType := WIN_REG_DWORD cName := iif( xValue, 1, 0 ) EXIT CASE "D" - nValueType := REG_SZ + nValueType := WIN_REG_SZ cName := DToS( xValue ) EXIT CASE "N" - nValueType := REG_DWORD + IF ! hb_isNumeric( nValueType ) .OR. ; + !( nValueType == WIN_REG_DWORD .OR. ; + nValueType == WIN_REG_DWORD_LITTLE_ENDIAN .OR. ; + nValueType == WIN_REG_DWORD_BIG_ENDIAN .OR. ; + nValueType == WIN_REG_QWORD .OR. ; + nValueType == WIN_REG_QWORD_LITTLE_ENDIAN ) + nValueType := WIN_REG_DWORD + ENDIF cName := xValue EXIT CASE "C" CASE "M" - nValueType := REG_SZ + IF ! hb_isNumeric( nValueType ) .OR. ; + !( nValueType == WIN_REG_SZ .OR. ; + nValueType == WIN_REG_EXPAND_SZ .OR. ; + nValueType == WIN_REG_MULTI_SZ ) + nValueType := WIN_REG_SZ + ENDIF cName := xValue EXIT ENDSWITCH diff --git a/harbour/contrib/hbwin/win_regc.c b/harbour/contrib/hbwin/win_regc.c index f25a95e457..5347f3a7db 100644 --- a/harbour/contrib/hbwin/win_regc.c +++ b/harbour/contrib/hbwin/win_regc.c @@ -201,8 +201,20 @@ HB_FUNC( WIN_REGSETVALUEEX ) 0, dwType, ( const BYTE * ) &nSpace, - sizeof( REG_DWORD ) ) == ERROR_SUCCESS ); + sizeof( DWORD ) ) == ERROR_SUCCESS ); } +#if defined( REG_QWORD ) + else if( dwType == REG_QWORD ) + { + HB_U64 nSpace = ( HB_U64 ) hb_parnint( 5 ); + hb_retl( RegSetValueEx( ( HKEY ) hb_parptr( 1 ), + lpKey, + 0, + dwType, + ( const BYTE * ) &nSpace, + sizeof( HB_U64 ) ) == ERROR_SUCCESS ); + } +#endif else if( dwType == REG_SZ || dwType == REG_EXPAND_SZ || dwType == REG_MULTI_SZ ) diff --git a/harbour/package/mpkg_win.nsi b/harbour/package/mpkg_win.nsi index f7ada9bcac..31ed901872 100644 --- a/harbour/package/mpkg_win.nsi +++ b/harbour/package/mpkg_win.nsi @@ -21,6 +21,7 @@ !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\doc\readme.txt" !define MUI_ICON "harb_win.ico" + !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico" SetDateSave on SetDatablockOptimize on diff --git a/harbour/package/winuni/mpkg_win_uni.nsi b/harbour/package/winuni/mpkg_win_uni.nsi index d5a4f2866d..62a7caed81 100644 --- a/harbour/package/winuni/mpkg_win_uni.nsi +++ b/harbour/package/winuni/mpkg_win_uni.nsi @@ -20,6 +20,7 @@ SetCompressor /solid lzma !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\doc\readme.txt" !define MUI_ICON "..\harb_win.ico" + !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico" SetDateSave on SetDatablockOptimize on