You are here

Updating reading and updating a single entry in Reg file

7 posts / 0 new
Last post
Devo
Offline
Last seen: 5 months 3 weeks ago
Joined: 2007-09-04 14:55
Updating reading and updating a single entry in Reg file

This is mostly directed at Prapper since I am modifying his launcher for Glary Utilities.

I am creating a launcher for CUE Splitter which only creates a registry file. I am trying to implement language switching in the launcher, but since the language is stored in the registry file, I'm not really sure how to update it. I have included the code below, but it obviously doesn't work. Any help would be appreciated.

Thanks.

;Copyright 2004-2010 John T. Haller
;Copyright 2008-2010 Devo

;Website: http://PortableApps.com/CUESplitterPortable

;This software is OSI Certified Open Source Software.
;OSI Certified is a certification mark of the Open Source Initiative.

;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either version 2
;of the License, or (at your option) any later version.

;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.

;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

!define PORTABLEAPPNAME "CUE Splitter Portable"
!define APPNAME "CUE Splitter"
!define NAME "CUESplitterPortable"
!define VER "1.6.8.0"
!define WEBSITE "PortableApps.com/CUESplitterPortable"
!define DEFAULTEXE "CUE_Splitter.exe"
!define DEFAULTAPPDIR "CUESplitter"
!define DEFAULTSETTINGSDIR "settings"
!define LAUNCHERLANGUAGE "English"

;=== Program Details
Name "${PORTABLEAPPNAME}"
OutFile "..\..\${NAME}.exe"
Caption "${PORTABLEAPPNAME} | PortableApps.com"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${PORTABLEAPPNAME}"
VIAddVersionKey Comments "Allows ${APPNAME} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
VIAddVersionKey CompanyName "PortableApps.com"
VIAddVersionKey LegalCopyright "PortableApps.com & Contributors"
VIAddVersionKey FileDescription "${PORTABLEAPPNAME}"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${PORTABLEAPPNAME}"
VIAddVersionKey LegalTrademarks "PortableApps.com is a Trademark of Rare Ideas, LLC."
VIAddVersionKey OriginalFilename "${NAME}.exe"
;VIAddVersionKey PrivateBuild ""
;VIAddVersionKey SpecialBuild ""

;=== Runtime Switches
CRCCheck On
WindowIcon Off
SilentInstall Silent
AutoCloseWindow True
RequestExecutionLevel user
XPStyle On

; Best Compression
SetCompress Auto
SetCompressor /SOLID lzma
SetCompressorDictSize 32
SetDatablockOptimize On

;=== Include
;(Standard NSIS)
!include FileFunc.nsh
!insertmacro GetParameters
!include LogicLib.nsh
!include Registry.nsh

;(Custom)
!include ReadINIStrWithDefault.nsh

;=== Program Icon
Icon "..\..\App\AppInfo\appicon.ico"

;=== Languages
LoadLanguageFile "${NSISDIR}\Contrib\Language files\${LAUNCHERLANGUAGE}.nlf"
!include PortableApps.comLauncherLANG_${LAUNCHERLANGUAGE}.nsh

Var PROGRAMDIRECTORY
Var SETTINGSDIRECTORY
Var ADDITIONALPARAMETERS
Var EXECSTRING
Var PROGRAMEXECUTABLE
Var INIPATH
Var DISABLESPLASHSCREEN
Var SECONDARYLAUNCH
Var LASTPLUGINSDIRECTORY
Var LASTSTARTUP
Var MISSINGFILEORPATH
Var APPLANGUAGE

Section "Main"
	;=== Check if already running
	System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}") i .r1 ?e'
	Pop $0
	StrCmp $0 0 CheckINI
		StrCpy $SECONDARYLAUNCH "true"

	CheckINI:
		;=== Find the INI file, if there is one
		IfFileExists "$EXEDIR\${NAME}.ini" "" NoINI
			StrCpy $INIPATH "$EXEDIR"

		;=== Read the parameters from the INI file
		${ReadINIStrWithDefault} $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Directory" "App\${DEFAULTAPPDIR}"
		StrCpy $PROGRAMDIRECTORY "$EXEDIR\$0"
		${ReadINIStrWithDefault} $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory" "Data\${DEFAULTSETTINGSDIR}"
		StrCpy $SETTINGSDIRECTORY "$EXEDIR\$0"
		${ReadINIStrWithDefault} $PROGRAMEXECUTABLE "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Executable" "${DEFAULTEXE}"
		${ReadINIStrWithDefault} $ADDITIONALPARAMETERS "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters" ""
		${ReadINIStrWithDefault} $DISABLESPLASHSCREEN "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen" "false"

		IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE NoProgramEXE

	NoINI:
		;=== No INI file, so we'll use the defaults
		StrCpy $PROGRAMEXECUTABLE "${DEFAULTEXE}"
		StrCpy $ADDITIONALPARAMETERS ""
		StrCpy $DISABLESPLASHSCREEN "false"

		IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
			StrCpy $PROGRAMDIRECTORY "$EXEDIR\App\${DEFAULTAPPDIR}"
			StrCpy $SETTINGSDIRECTORY "$EXEDIR\Data\${DEFAULTSETTINGSDIR}"
			Goto FoundProgramEXE

	NoProgramEXE:
		;=== Program executable not where expected
		StrCpy $MISSINGFILEORPATH $PROGRAMEXECUTABLE
		MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
		Goto TheEnd

	FoundProgramEXE:
		StrCmp $SECONDARYLAUNCH "true" GetPassedParameters
		FindProcDLL::FindProc "${DEFAULTEXE}"
		StrCmp $R0 "1" WarnAnotherInstance DisplaySplash

	WarnAnotherInstance:
		MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherAlreadyRunning)`
		Goto TheEnd

	DisplaySplash:
		StrCmp $DISABLESPLASHSCREEN "true" CheckSettings
			;=== Show the splash screen before processing the files
			InitPluginsDir
			File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"
			newadvsplash::show /NOUNLOAD 1200 0 0 -1 /L "$PLUGINSDIR\splash.jpg"

	CheckSettings:
		;=== Check for data files
		IfFileExists "$SETTINGSDIRECTORY\*.*" GetPassedParameters

			;=== Create the default settings directory
			CreateDirectory "$SETTINGSDIRECTORY"

	GetPassedParameters:
		;=== Get any passed parameters
		${GetParameters} $0
		StrCmp "'$0'" "''" "" LaunchProgramParameters

		;=== No parameters
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"`
		Goto AdditionalParameters

	LaunchProgramParameters:
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" $0`

	AdditionalParameters:
		StrCmp $ADDITIONALPARAMETERS "" StartupCheck

		;=== Additional Parameters
		StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`

	StartupCheck:
		StrCmp $SECONDARYLAUNCH "true" LaunchAndExit

	;GetPlatformLanguage:
		ReadEnvStr $0 "PortableApps.comLocaleWinName"
		StrCpy $APPLANGUAGE $0 "" 5
		StrCmp $APPLANGUAGE "" MoveSettings ;if not set, move on

	;FixPlatformLanguage:
		${IfThen} $APPLANGUAGE == PORTUGUESE ${|} StrCpy $APPLANGUAGE "Portugues (Portugal)" ${|}
		${IfThen} $APPLANGUAGE == PORTUGUESEBR ${|} StrCpy $APPLANGUAGE "Portugues (Brazilian)" ${|}
		${IfThen} $APPLANGUAGE == SIMPCHINESE ${|} StrCpy $APPLANGUAGE "Chinese (Simplified)" ${|}
		${IfThen} $APPLANGUAGE == TRADCHINESE ${|} StrCpy $APPLANGUAGE "Chinese(Traditional)" ${|}
		${IfThen} $APPLANGUAGE == SPANISH ${|} StrCpy $APPLANGUAGE "Espanol (America Latina)" ${|}

	;CheckAppLanguage:
		ReadINIStr $0 "$SETTINGSDIRECTORY\Medieval.reg" "Lang_Txt"
		StrCmp "$APPLANGUAGE" $0 RegistryBackup ;if the same, move on

	;SetAppLanguage:
		IfFileExists "$PROGRAMDIRECTORY\LANG\$APPLANGUAGE" "" RegistrySettings
		nsExec::Exec REG UPDATE $SETTINGSDIRECTORY\Medieval.reg "Lang_Txt" "$APPLANGUAGE"
		
	RegistryBackup:
		;=== Backup the registry
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\Medieval-BackupBy${NAME}" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\Medieval" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\Medieval" "HKEY_CURRENT_USER\Software\Medieval-BackupBy${NAME}" $R0
		Sleep 100
	
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\Medieval.reg" "" LaunchNow
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\Medieval.reg"`
			Pop $R0
			StrCmp $R0 '0' LaunchNow ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\Medieval.reg" $R0
		StrCmp $R0 '0' LaunchNow ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	LaunchNow:
		Sleep 100
		ExecWait $EXECSTRING

	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKEY_CURRENT_USER\Software\Medieval" "$SETTINGSDIRECTORY\Medieval.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKEY_CURRENT_USER\Software\Medieval" $R0
		Sleep 100
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\Medieval-BackupBy${NAME}" $R0
		StrCmp $R0 "-1" TheEnd
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\Medieval-BackupBy${NAME}" "HKEY_CURRENT_USER\Software\Medieval" $R0
		Sleep 100
		Goto TheEnd

	LaunchAndExit:
		Exec $EXECSTRING

	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd
OliverK
OliverK's picture
Offline
Last seen: 2 years 10 months ago
Developer
Joined: 2007-03-27 15:21
can you post the section of

can you post the section of the registry?

You might check 7-zip portable. I was looking through that the other day, and the way 7-zip stores the information is in the registry. So maybe that's the goodness you need.

Too many lonely hearts in the real world
Too many bridges you can burn
Too many tables you can't turn
Don't wanna live my life in the real world

Simeon
Simeon's picture
Offline
Last seen: 9 years 6 months ago
DeveloperTranslator
Joined: 2006-09-25 15:15
Yes

7Zip is a good example for this.

"What about Love?" - "Overrated. Biochemically no different than eating large quantities of chocolate." - Al Pacino in The Devils Advocate

John T. Haller
John T. Haller's picture
Offline
Last seen: 5 hours 48 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
INI

.reg files can be read and written to using ReadINI and WriteINI in NSIS.

Sometimes, the impossible can become possible, if you're awesome!

Devo
Offline
Last seen: 5 months 3 weeks ago
Joined: 2007-09-04 14:55
I've posted the reg file

I've posted the reg file below and I need to update the "Lang_Txt" string. It's about 3/4 of the way down.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Medieval]

[HKEY_CURRENT_USER\Software\Medieval\CUE Splitter]
"FirstTimeAssociation"=dword:000c8a00

[HKEY_CURRENT_USER\Software\Medieval\CUE Splitter\Config]
"CheckUpdates"=dword:00000001
"ShowCents"=dword:00000000
"SaveStatus"=dword:00000001
"M3U"=dword:00000001
"M3U_Mask"=dword:00000001
"M3U_Mask_Val"="[%A] %T"
"CUE"=dword:00000001
"CUE_Mask"=dword:00000001
"CUE_Mask_Val"="[%A] %T"
"DirNone"=dword:00000000
"DirLast"=dword:00000001
"DirPath"=dword:00000000
"DirPathValue"=""
"DirPathAsk"=dword:00000001
"TagUnicode"=dword:00000001
"TagID3v1"=dword:00000001
"TagID3v2"=dword:00000001
"TagFlac"=dword:00000001
"TagApe"=dword:00000001
"TagWma"=dword:00000001
"ReadMode"=dword:00000004
"WriteMode"=dword:00000004
"NoOverwrite"=dword:00000001
"UseThread"=dword:00000001
"ThreadLvl"=dword:00000003
"HiddenTime"="20"
"CodePage"=dword:00000000
"CUE_Comment"=dword:00000001
"CUE_Coding"=dword:00000002

[HKEY_CURRENT_USER\Software\Medieval\CUE Splitter\EditDisk]
"Advanced"=dword:00000000

[HKEY_CURRENT_USER\Software\Medieval\CUE Splitter\EditTrack]
"Advanced"=dword:00000000

[HKEY_CURRENT_USER\Software\Medieval\CUE Splitter\FileMask]
"Mask_Count"=dword:00000001
"Name_0"="Default"
"Text_0"="(%n) [%a] %t"

[HKEY_CURRENT_USER\Software\Medieval\CUE Splitter\Main]
"Lang_Pos"=dword:00000000
"Lang_Txt"="English / American"
"Font_Size"=dword:ffffffff
"Font_Name"=""
"FileMask"=dword:00000001
"FileMaskIndex"=dword:00000000
"ReplaceUnderscore"=dword:00000000
"CaseFile"=dword:00000000
"CaseTags"=dword:00000000
"AddGaps"=dword:00000000
"InvertGaps"=dword:00000000
"LastDir"=""

[HKEY_CURRENT_USER\Software\Medieval\CUE Splitter\Main\Status]
"iLeft"=dword:00000140
"iTop"=dword:00000105
"iWidth"=dword:00000280
"iHeight"=dword:000001f5
"iStat"=dword:00000000
"GPropDif"=dword:00000006
"GProp0"=hex:69,67,4a,af,bf,38,a9,3f
"GProp1"=hex:11,d8,be,7a,5c,a4,b9,3f
"GProp2"=hex:eb,71,91,66,8c,f2,cf,3f
"GProp3"=hex:20,34,04,b6,af,1e,d7,3f
"GProp4"=hex:43,01,1d,9b,ef,86,bf,3f
"GProp5"=hex:a2,3e,4b,6d,7c,d8,bd,3f
John T. Haller
John T. Haller's picture
Offline
Last seen: 5 hours 48 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
WriteINI

Like I said, WriteINI.

WriteINI "X:\path\filename.reg" "HKEY_CURRENT_USER\Software\Medieval\CUE Splitter\Main" "Lang_Txt" $VALUE

Sometimes, the impossible can become possible, if you're awesome!

Devo
Offline
Last seen: 5 months 3 weeks ago
Joined: 2007-09-04 14:55
Thanks

Thank you very much. I wasn't sure if that would work, but I think I had it in the wrong format when I tried. Thanks again for your help.

Log in or register to post comments