You are here

Launcher Problem - Please Help

10 posts / 0 new
Last post
Espreon
Espreon's picture
Offline
Last seen: 12 years 4 months ago
Joined: 2006-09-29 18:23
Launcher Problem - Please Help

Yeagh, with my Project64 Portable launcher, for some reason one set of Registry keys is not being imported into the Registry upon execution. When I manually import them they get exported after closing P64 Portable/

The .reg thats not being imported is reffered to as "project642.reg" w/o quotes

Could someone please explain why the .reg is not being imported and what I can do to correct this cause it is annoying to hafta manually import a .reg and I am sure P64 Portable Launcher users find it annoying too.

Heres the .nsi and lets stay on-topic regarding the problem:

;Copyright (C) 2004-2007 John T. Haller of PortableApps.com

;Website: http://armogohmasuites.sf.net/Project64Portable

;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 NAME "Project64Portable"
!define FULLNAME "Project64 Portable"
!define APP "Project64"
!define VER "1.5.0.0"
!define WEBSITE "PortableApps.com/EraserPortable"
!define DEFAULTEXE "Project64.exe"
!define DEFAULTAPPDIR "project64"
!define DEFAULTSETTINGSDIR "settings"

;=== Program Details
Name "${FULLNAME}"
OutFile "${NAME}.exe"
Caption "${FULLNAME} | ArmogohmaSuites"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${FULLNAME}"
VIAddVersionKey Comments "Allows ${APP} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
VIAddVersionKey CompanyName "ArmogohmaSuites"
VIAddVersionKey LegalCopyright "John T. Haller"
VIAddVersionKey FileDescription "${FULLNAME}"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${FULLNAME}"
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

;=== Include
!include "GetParameters.nsh"
!include "Registry.nsh"

;=== Program Icon
Icon "${NAME}.ico"

Var PROGRAMDIRECTORY
Var SETTINGSDIRECTORY
Var ADDITIONALPARAMETERS
Var EXECSTRING
Var PROGRAMEXECUTABLE
Var INIPATH
Var SECONDARYLAUNCH
Var DISABLESPLASHSCREEN
Var FAILEDTORESTOREKEY
Var USERTYPE


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" "" CheckSubINI
            StrCpy "$INIPATH" "$EXEDIR"
            Goto ReadINI

    CheckSubINI:
        IfFileExists "$EXEDIR\${NAME}\${NAME}.ini" "" NoINI
            StrCpy "$INIPATH" "$EXEDIR\${NAME}"
            Goto ReadINI

    ReadINI:
        ;=== Read the parameters from the INI file
        ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APP}Directory"
        StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\$0"
        ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
        StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"
    

        ;=== Check that the above required parameters are present
        IfErrors NoINI
        ReadINIStr $ADDITIONALPARAMETERS "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters"
        ReadINIStr $DISABLESPLASHSCREEN "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen"

    ;CleanUpAnyErrors:
        ;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
        ClearErrors

        ;=== Correct PROGRAMEXECUTABLE if blank
        StrCmp $PROGRAMEXECUTABLE "" "" EndINI
            StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
            Goto EndINI

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

        IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" CheckPortableProgramDIR
            StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\App\${DEFAULTAPPDIR}"
            StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${DEFAULTSETTINGSDIR}"
            GoTo EndINI

        CheckPortableProgramDIR:
            IfFileExists "$EXEDIR\${NAME}\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
            StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\${NAME}\App\${DEFAULTAPPDIR}"
            StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\${NAME}\Data\${DEFAULTSETTINGSDIR}"
            GoTo EndINI

    EndINI:
        IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE

    NoProgramEXE:
        ;=== Program executable not where expected
        MessageBox MB_OK|MB_ICONEXCLAMATION `$PROGRAMEXECUTABLE was not found.  Please check your configuration`
        Abort
        
    FoundProgramEXE:
        ;=== Check if running
        StrCmp $SECONDARYLAUNCH "true" GetPassedParameters
        FindProcDLL::FindProc "Project64.exe"
        StrCmp $R0 "1" WarnAnotherInstance DisplaySplash

    WarnAnotherInstance:
        MessageBox MB_OK|MB_ICONINFORMATION `Another instance of ${APP} is already running.  Please close other instances of ${APP} before launching ${FULLNAME}.`
        Abort
    
    DisplaySplash:
        StrCmp $DISABLESPLASHSCREEN "true" GetPassedParameters
            ;=== Show the splash screen while processing registry entries
            InitPluginsDir
            File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"
            newadvsplash::show /NOUNLOAD 1200 100 0 -1 /L $PLUGINSDIR\splash.jpg
    
    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 "" SettingsDirectory

        ;=== Additional Parameters
        StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`
    
    SettingsDirectory:
        ;=== Set the settings directory if we have a path
        IfFileExists "$SETTINGSDIRECTORY\project64.reg" RegistryBackup
            CreateDirectory $SETTINGSDIRECTORY
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project64.reg` $SETTINGSDIRECTORY
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project641.reg` $SETTINGSDIRECTORY
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project642.reg` $SETTINGSDIRECTORY
    
    RegistryBackup:
        StrCmp $SECONDARYLAUNCH "true" LaunchAndExit
        ;=== Backup the registry
        UserInfo::GetAccountType
        Pop $USERTYPE
        ${registry::KeyExists} "HKEY_CURRENT_USER\Software\N64 Emulation-BackupByProject64Portable" $R0
        StrCmp $R0 "0" RestoreSettings
        ${registry::KeyExists} "HKEY_CURRENT_USER\Software\JaboSoft-BackupByProject64Portable" $R0
        StrCmp $R0 "0" RestoreSettings
        ${registry::KeyExists} "HKEY_CURRENT_USER\Software\NRage-BackupByProject64Portable" $R0
        StrCmp $R0 "0" RestoreSettings
        ${registry::KeyExists} "HKEY_CURRENT_USER\Software\N64 Emulation" $R0
        StrCmp $R0 "-1" RestoreSettings
        ${registry::KeyExists} "HKEY_CURRENT_USER\Software\JaboSoft" $R0
        StrCmp $R0 "-1" RestoreSettings
        ${registry::KeyExists} "HKEY_CURRENT_USER\Software\NRage" $R0
        StrCmp $R0 "-1" RestoreSettings
        ${registry::MoveKey} "HKEY_CURRENT_USER\Software\N64 Eumlation" "HKEY_CURRENT_USER\Software\N64 Emulation-BackupByProject64Portable" $R0
        ${registry::MoveKey} "HKEY_CURRENT_USER\Software\JaboSoft" "HKEY_CURRENT_USER\Software\JaboSoft-BackupByProject64Portable" $R0
        ${registry::MoveKey} "HKEY_CURRENT_USER\Software\NRage" "HKEY_CURRENT_USER\Software\NRage-BackupByProject64Portable" $R0
        Sleep 100
    
    RestoreSettings:
        IfFileExists "$SETTINGSDIRECTORY\project64.reg" "" BackupRun
        IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
            nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\project64.reg"`
            Pop $R0
            StrCmp $R0 '0' BackupRun ;successfully restored key
        IfFileExists "$SETTINGSDIRECTORY\project641.reg" "" BackupRun
        IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
            nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\project641.reg"`
            Pop $R0
            StrCmp $R0 '0' BackupRun ;successfully restored key
        IfFileExists "$SETTINGSDIRECTORY\project642.reg" "" BackupRun
        IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
            nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\project642.reg"`
            Pop $R0
            StrCmp $R0 '0' BackupRun ;successfully restored key
    RestoreTheKey9x:
        ${registry::RestoreKey} "$SETTINGSDIRECTORY\project64.reg" $R0
        StrCmp $R0 '0' BackupRun ;successfully restored key
        StrCpy $FAILEDTORESTOREKEY "true"
        ${registry::RestoreKey} "$SETTINGSDIRECTORY\project641.reg" $R0
        StrCmp $R0 '0' BackupRun ;successfully restored key
        StrCpy $FAILEDTORESTOREKEY "true"
        ${registry::RestoreKey} "$SETTINGSDIRECTORY\project642.reg" $R0
        StrCmp $R0 '0' BackupRun ;successfully restored key
        StrCpy $FAILEDTORESTOREKEY "true"
          
    BackupRun:
        ${registry::Read} "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" "Project64" $0 $1
        ${registry::MoveValue} "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" "Project64" "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" "Project64-BackupByProject64Portable" $R0
    
    StartProgramNow:
        Sleep 100
        ExecWait $EXECSTRING
        
        StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
        ${registry::SaveKey} "HKEY_CURRENT_USER\Software\N64 Emulation" "$SETTINGSDIRECTORY\project64.reg" "" $R0
        Sleep 100
        StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
        ${registry::SaveKey} "HKEY_CURRENT_USER\Software\JaboSoft" "$SETTINGSDIRECTORY\project641.reg" "" $R0
        Sleep 100
        StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
        ${registry::SaveKey} "HKEY_CURRENT_USER\Software\NRage" "$SETTINGSDIRECTORY\project642.reg" "" $R0
        Sleep 100
    
    SetOriginalKeyBack:
        ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\N64 Emulation" $R0
        ${registry::MoveKey} "HKEY_CURRENT_USER\Software\N64 Emulation-BackupByProject64Portable" "HKEY_CURRENT_USER\Software\N64 Emulation" $R0
        ${registry::DeleteValue} "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" "Project64" $R0
        ${registry::MoveValue} "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" "Project64-BackupByProject64Portable" "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" "Project64" $R0
        ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\JaboSoft" $R0
        ${registry::MoveKey} "HKEY_CURRENT_USER\Software\JaboSoft-BackupByProject64Portable" "HKEY_CURRENT_USER\Software\JaboSoft" $R0
        ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\NRage" $R0
        ${registry::MoveKey} "HKEY_CURRENT_USER\Software\NRage-BackupByProject64Portable" "HKEY_CURRENT_USER\Software\NRage" $R0
        StrCmp $USERTYPE "Guest" TheEnd
        StrCmp $USERTYPE "User" TheEnd
        Goto TheEnd

    LaunchAndExit:
        Exec $EXECSTRING

    TheEnd:
        ${registry::Unload}
        newadvsplash::wait
SectionEnd
Kevin Porter
Kevin Porter's picture
Offline
Last seen: 10 years 10 months ago
Developer
Joined: 2007-01-10 19:25
Okay.

I'm not too familiar with registry in NSIS, but I think I've got it. I'm assuming that the problem is right here:

 
SettingsDirectory:
        ;=== Set the settings directory if we have a path
        IfFileExists "$SETTINGSDIRECTORY\project64.reg" RegistryBackup
            CreateDirectory $SETTINGSDIRECTORY
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project64.reg` $SETTINGSDIRECTORY
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project641.reg` $SETTINGSDIRECTORY
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project642.reg` $SETTINGSDIRECTORY

It's very simple. You forgot your "`" around "$SETTINGSDIRECTORY." If that is the problem, then just recopy this into the launcher code.

 
SettingsDirectory:
        ;=== Set the settings directory if we have a path
        IfFileExists "$SETTINGSDIRECTORY\project64.reg" RegistryBackup
            CreateDirectory $SETTINGSDIRECTORY
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project64.reg` `$SETTINGSDIRECTORY`
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project641.reg` `$SETTINGSDIRECTORY`
            CopyFiles /SILENT `$EXEDIR\App\DefaultData\settings\project642.reg` `$SETTINGSDIRECTORY`

Let me know if that fixes it, or if it doesn't.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

sag47
Offline
Last seen: 10 years 10 months ago
Joined: 2007-11-17 16:19
Is it a must to import the

Is it a must to import the reg? Meaning are there so many entries that you simply can't do it with WriteRegStr?

Look it up in the NSIS help documentation. Other categories of interest.
ReadRegStr
DeleteRegKey

Also it would be worth it to post a topic like this in the NSIS forums. A solution is normally given in a timely fashion.

Or you may want to execute this function with a batch operation:
http://www.robvanderwoude.com/regedit.html

All the information you need can be found in the NSIS manual here for registry functions.
http://nsis.sourceforge.net/Docs/Chapter4.html
(use Ctrl+F to search for specific terms)

Just giving possible alternatives,
SAM

What's a signature?

Espreon
Espreon's picture
Offline
Last seen: 12 years 4 months ago
Joined: 2006-09-29 18:23
Uh

Yes it, well if your using the N-Rage Input Plugin (has nothing to do with NSIS, it hasta do with Project64) like I do. And what is this WriteRegStr you speak of?

And I put 1 set of Registry keys in 1 .reg cause I don't know better commands.

sag47
Offline
Last seen: 10 years 10 months ago
Joined: 2007-11-17 16:19
WriteRegStr is NSIS' way of

WriteRegStr is NSIS' way of writing registry entries. If you post the contents of the reg file then I can convert them to WriteRegStr lines of code for you.

WriteRegStr rootkey subkey entry_name new_value_string
root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)

Leave entry_name as "" if you want it to be (Default)

If you search the NSIS help for for the terms I listed above then you will see all the info you need. Assuming you have at least a basic understanding of how the Windows registry works. If not, I can collaborate with you on achieving what you wish because I have a thorough understanding of the Windows registry.

Also get HM NIS Edit (HMNE) which is the best IDE I've ever seen for NSIS. You can download my custom installer which downloads and associates the files for you (comes with source code so you can see how the WriteRegStr, ReadRegStr, and DeleteRegKey is formatted). All code I provide is of course open source. Or just download my installer to see my source which is well commented.
http://www.pages.drexel.edu/~sag47/source/NSIS-Installer.zip

My installer also downloads fabio functions plugin for HMNE. If you press Ctrl+G then a list of functions comes up and you can jump across your code.

And don't worry if you already have NSIS installed it will automatically detect it and then only get what is necessary.

Or you can get HMNE from its homepage.
http://hmne.sf.net

I have 4 years experience programming in NSIS and I regularly participate in their documentation so if you have any questions feel free to ask. Also if you have any registry questions I have just as much if not more in that as well.

SAM

What's a signature?

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 15 years 2 months ago
Joined: 2006-01-06 21:27
Whoa.

Ever tried your hand at making portable apps with NSIS?

"If you're not part of the solution, you're part of the precipitate."

sag47
Offline
Last seen: 10 years 10 months ago
Joined: 2007-11-17 16:19
http://sourceforge.net/projec

http://sourceforge.net/projects/portableappsext/

Thats my SF project for PortableApps. I haven't created installers for them yet. I just made launchers for them.

SAM

What's a signature?

Espreon
Espreon's picture
Offline
Last seen: 12 years 4 months ago
Joined: 2006-09-29 18:23
It

Didn't work... I think the problem lies in this area I believe:

 RestoreSettings:
        IfFileExists "$SETTINGSDIRECTORY\project64.reg" "" BackupRun
        IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
            nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\project64.reg"`
            Pop $R0
            StrCmp $R0 '0' BackupRun ;successfully restored key
        IfFileExists "$SETTINGSDIRECTORY\project641.reg" "" BackupRun
        IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
            nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\project641.reg"`
            Pop $R0
            StrCmp $R0 '0' BackupRun ;successfully restored key
        IfFileExists "$SETTINGSDIRECTORY\project642.reg" "" BackupRun
        IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
            nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\project642.reg"`
            Pop $R0
            StrCmp $R0 '0' BackupRun ;successfully restored key
    RestoreTheKey9x:
        ${registry::RestoreKey} "$SETTINGSDIRECTORY\project64.reg" $R0
        StrCmp $R0 '0' BackupRun ;successfully restored key
        StrCpy $FAILEDTORESTOREKEY "true"
        ${registry::RestoreKey} "$SETTINGSDIRECTORY\project641.reg" $R0
        StrCmp $R0 '0' BackupRun ;successfully restored key
        StrCpy $FAILEDTORESTOREKEY "true"
        ${registry::RestoreKey} "$SETTINGSDIRECTORY\project642.reg" $R0
        StrCmp $R0 '0' BackupRun ;successfully restored key
        StrCpy $FAILEDTORESTOREKEY "true"
Kevin Porter
Kevin Porter's picture
Offline
Last seen: 10 years 10 months ago
Developer
Joined: 2007-01-10 19:25
Sorry.

I really don't know very much about NSIS, much less registry.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

wraithdu
Offline
Last seen: 11 years 6 months ago
Developer
Joined: 2007-06-27 20:22
Ok, bunch of stuff I see

Ok, bunch of stuff I see here. Whew, here we go. (seems like you adapted this from another launcher?)

1. You don't actually use the account info from UserInfo::GetAccountType, so you can get rid of all references to it.

2. Since you're only checking the return value of reg.exe, you want to use nsExec::Exec. If you use ExecToStack then any other output of the reg.exe command is pushed onto the stack after the return code. You don't want that.

3. The success return code of reg.exe is 0. According to your code, if the first reg file import is successful, everything else is skipped and you go right to the BackupRun section! It sounds like you want to import all the reg files, so you need to fix this.

4. The line before your RestoreTheKey9x section should be a Goto jump to skip it. Assuming the previous commands are successful (after you've fixed point #3) you don't want to import all 3 files again.

5. The same return value check as point #3 applies to the RestoreTheKey9x section. If the first key is restored successfully, the rest of the keys are skipped.

6. ${registry::RestoreKey} does NOT wait for the command to complete before moving on in the script (I've confirmed this with the developer). This can lead to incomplete registry importing if the program is launched too soon after the last RestoreKey command. A better way is to use

ExecWait 'regedit /s "path\to\filename.reg"'

7. I don't see why you have a ${registry::Read} command in your BackupRun section. You can remove this.

After fixing all that, see if it works better.

Log in or register to post comments