You are here

Registry keys are not being imported by launcher-Please help...

1 post / 0 new
Espreon
Espreon's picture
Offline
Last seen: 12 years 3 months ago
Joined: 2006-09-29 18:23
Registry keys are not being imported by launcher-Please help...

Yeah, my launcher for Project64 has a flaw to it... one of the .reg files are not being imported, however the other 2 .reg files are being imported into the registry. The 3rd .reg file (the one that is not being imported), if I manually import it, after I launch P64 Portable (the data of the 3rd .reg file is not brought into use until I begin emulation), the settings are retained and after P64 Portable is closed, the Registry keys that are supposed to be brought into the 3rd .reg file (The NRage keys) are cleaned up and brought into the 3rd .reg file...

Any suggestions on why the 3rd .reg file is not being imported? The 3rd .reg file is reffered to the launcher as project642.reg

Heres the .nsi:

;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