You are here

Help replacing path within INI

12 posts / 0 new
Last post
Devo
Offline
Last seen: 5 months 2 weeks ago
Joined: 2007-09-04 14:55
Help replacing path within INI

I am trying to implement code in a launcher to modify the path to the App directory within an ini. Is there a good example in a launcher or something I could look at/lift out? Below is the ini file.

AppDir = "C:\VTPSUHM\"
MessagesEnabled = 1
Mark Sikkema
Offline
Last seen: 12 years 7 months ago
Developer
Joined: 2009-07-20 14:55
I'm not sure if I understand you right? But, ....

Hi Devo,

Wouldn't it be enough to modify the ini file once, and locate it in the DefaultData folder. And then, replace the drive letter at every startup !

Formerly Gringoloco
Windows XP Pro sp3 x32

Devo
Offline
Last seen: 5 months 2 weeks ago
Joined: 2007-09-04 14:55
I'm sure that would be easy,

I'm sure that would be easy, but I'd rather update the entire path. The reason being is that this is a program I will be using for school and I'm going to have a copy on my laptop and one on my flash drive. The folder paths are different, so I was hoping to not have to manually put in the path for each.

Also, not everybody has the same folder structure, so the default of

X:\PortableApps\VTPSUHMPortable\App\VTPSUHM\

might not work for everybody. The path would have to be updated any time a user has a different folder structure. Why not automate the process?

Mark Sikkema
Offline
Last seen: 12 years 7 months ago
Developer
Joined: 2009-07-20 14:55
So use some thing

So use some thing like:

writeINIstr 'inifile.ini' 'section' 'AppDir' '$EXEDIR\App\VTPSUHM\'

at every startup!

Formerly Gringoloco
Windows XP Pro sp3 x32

Devo
Offline
Last seen: 5 months 2 weeks ago
Joined: 2007-09-04 14:55
Still not working

So I tried adding in that code, but it doesn't seem to do anything. The string never gets replaced. Below is my launcher, what am I doing wrong?

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

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

;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 "VTPSUHM Portable"
!define APPNAME "VTPSUHM"
!define NAME "VTPSUHMPortable"
!define VER "1.6.8.0"
!define WEBSITE "PortableApps.com/Development/test"
!define DEFAULTEXE "VTPSUHM7.exe"
!define DEFAULTAPPDIR "VTPSUHM"
!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 GetParameters.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 MISSINGFILEORPATH
Var ISDEFAULTDIRECTORY
;Var FAILEDTORESTOREKEY

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}"
			StrCpy $ISDEFAULTDIRECTORY "true"
			Goto FoundProgramEXE

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

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

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

	DisplaySplash:
		StrCmp $DISABLESPLASHSCREEN "true" CheckForSettings
			;=== 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"
	
	CheckForSettings:
		IfFileExists "$SETTINGSDIRECTORY\*.*" GetPassedParameters
		;=== No settings found
		StrCmp $ISDEFAULTDIRECTORY "true" CopyDefaultSettings
		CreateDirectory $SETTINGSDIRECTORY
		Goto GetPassedParameters
	
	CopyDefaultSettings:
		CreateDirectory "$EXEDIR\Data"
		CreateDirectory "$EXEDIR\Data\settings"
		CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings
		Goto GetPassedParameters

	GetPassedParameters:
		;=== Get any passed parameters
		Call GetParameters
		Pop $0
		StrCmp "'$0'" "''" "" LaunchProgramParameters

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

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

	AdditionalParameters:
		StrCmp $ADDITIONALPARAMETERS "" UpdateDirectory

		;=== Additional Parameters
		StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`
		
	UpdateDirectory:
		writeINIstr 'VTPSUHM.ini' '' 'AppDir' '"$EXEDIR\App\VTPSUHM\"'

	LaunchNow:
		CopyFiles /SILENT "$SETTINGSDIRECTORY\VTPSUHM.INI" "$PROGRAMDIRECTORY\VTPSUHM.INI"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\VTPSUHM.GID" "$PROGRAMDIRECTORY\VTPSUHM.GID"
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
	;MoveSettingsBack:
		Sleep 100
		Delete "$SETTINGSDIRECTORY\VTPSUHM.INI"
		Rename "$PROGRAMDIRECTORY\VTPSUHM.INI" "$SETTINGSDIRECTORY\VTPSUHM.INI"
		Delete "$SETTINGSDIRECTORY\VTPSUHM.GID"
		Rename "$PROGRAMDIRECTORY\VTPSUHM.GID" "$SETTINGSDIRECTORY\VTPSUHM.GID"
		Goto TheEnd
		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		newadvsplash::stop /WAIT
SectionEnd
Mark Sikkema
Offline
Last seen: 12 years 7 months ago
Developer
Joined: 2009-07-20 14:55
You forgot to add the

You forgot to add the directory of the ini file.

writeINIstr '$SETTINGSDIRECTORY\VTPSUHM.ini' '[section name]' 'AppDir' '"$EXEDIR\App\VTPSUHM\"'

As well, you will need to add a 'section name', if you have a look at the ini file you will see the name of the section between [], just above the 'AppDir' entry !

Formerly Gringoloco
Windows XP Pro sp3 x32

Devo
Offline
Last seen: 5 months 2 weeks ago
Joined: 2007-09-04 14:55
Unfortunately there is no

Unfortunately there is no section name, so I tried to just leave it blank. I posted the entire ini in the initial post.

There are only 2 lines in the entire ini

AppDir = "C:\VTPSUHM\"
MessagesEnabled = 1
Mark Sikkema
Offline
Last seen: 12 years 7 months ago
Developer
Joined: 2009-07-20 14:55
There are a few options you

There are a few options you could try:

  1. See what happens if you add a section name to the ini file.
  2. Make use of the TextReplace plugin, some how.
  3. Rewrite the file at every startup (fileopen, fileread, filewrite, fileclose).While doing that, just replace the AppDir entry

Formerly Gringoloco
Windows XP Pro sp3 x32

Devo
Offline
Last seen: 5 months 2 weeks ago
Joined: 2007-09-04 14:55
Adding a section header fixed

Adding a section header fixed it. Now I just need to find where else the settings are hiding. They're not in the registry or in AppData. Anyways, thanks for your help.

OliverK
OliverK's picture
Offline
Last seen: 2 years 9 months ago
Developer
Joined: 2007-03-27 15:21
cheesy fix. It works, but

cheesy fix. It works, but you're (more) likely to run into trouble. Use ConfigWrite.

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

OliverK
OliverK's picture
Offline
Last seen: 2 years 9 months ago
Developer
Joined: 2007-03-27 15:21
check out configwrite E.2.11

check out configwrite

E.2.11 ConfigWrite
Write value from entry name in config file.
Syntax:

${ConfigWrite} "[File]" "[Entry]" "[Value]" $var
"[File]"      ; config file
              ;
"[Entry]"     ; entry name
              ;
"[Value]"     ; value name
              ;  if "" then delete Entry
              ;
$var          ; Result:
              ;    $var=CHANGED  Value is written
              ;    $var=DELETED  Entry is deleted
              ;    $var=ADDED    Entry and Value are added
              ;    $var=SAME     Entry and Value already exist

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

OliverK
OliverK's picture
Offline
Last seen: 2 years 9 months ago
Developer
Joined: 2007-03-27 15:21
GIMP Portable has what you're

GIMP Portable has what you're looking for.

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

Log in or register to post comments