;Copyright (C) 2004-2006 John T. Haller ;Website: http://PortableApps.com/7-ZipPortable ;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 FULLNAME "7-Zip Portable" !define NAME "7-ZipPortable" !define APP "7-Zip" !define VER "1.2.1.4" !define WEBSITE "PortableApps.com/7-ZipPortable" !define DEFAULTEXE "7zFM.exe" !define DEFAULTAPPDIR "7-Zip" !define DEFAULTSETTINGSPATH "settings" ;=== Program Details Name "${NAME}" OutFile "${NAME}.exe" Caption "${FULLNAME} | PortableApps.com" VIProductVersion "${VER}" VIAddVersionKey FileDescription "${FULLNAME}" VIAddVersionKey LegalCopyright "2004-2006 John T. Haller" VIAddVersionKey Comments "Allows ${APP} to be run from a removable drive. For additional details, visit ${WEBSITE}" VIAddVersionKey CompanyName "PortableApps.com (John T. Haller)" VIAddVersionKey OriginalFilename "${NAME}.exe" VIAddVersionKey FileVersion "${VER}" ;=== Runtime Switches CRCCheck On WindowIcon Off SilentInstall Silent AutoCloseWindow True ;=== Include !include "Registry.nsh" !include "GetParameters.nsh" ;=== Program Icon Icon "${NAME}.ico" Var PROGRAMDIRECTORY Var SETTINGSDIRECTORY Var ADDITIONALPARAMETERS Var REGISTRYDIRECTORY Var EXECSTRING Var PROGRAMEXECUTABLE Var INIPATH Var DISABLESPLASHSCREEN Var ISDEFAULTDIRECTORY Var SECONDARYLAUNCH Section "Main" ;=== Find the INI file, if there is one IfFileExists "$EXEDIR\${NAME}.ini" "" CheckSubINI StrCpy "$INIPATH" "$EXEDIR" Goto ReadINI CheckSubINI: IfFileExists "$EXEDIR\${NAME}\${NAME}.ini" "" CheckSubSubINI StrCpy "$INIPATH" "$EXEDIR\${NAME}" Goto ReadINI CheckSubSubINI: IfFileExists "$EXEDIR\PortableApps\${NAME}\${NAME}.ini" "" CheckPortableAppsINI StrCpy "$INIPATH" "$EXEDIR\PortableApps\${NAME}" Goto ReadINI CheckPortableAppsINI: IfFileExists "$EXEDIR\Data\${NAME}\${NAME}.ini" "" NoINI StrCpy "$INIPATH" "$EXEDIR\Data\${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 $0 "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters" StrCpy "$ADDITIONALPARAMETERS" $0 ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APP}Executable" StrCpy "$PROGRAMEXECUTABLE" $0 ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen" StrCpy "$DISABLESPLASHSCREEN" $0 ;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}" StrCpy "$DISABLESPLASHSCREEN" "false" IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" CheckPortableProgramDIR StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\App\${DEFAULTAPPDIR}" StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${DEFAULTSETTINGSPATH}" StrCpy "$ISDEFAULTDIRECTORY" "true" GoTo EndINI CheckPortableProgramDIR: IfFileExists "$EXEDIR\${NAME}\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" CheckPortableAppsDIR StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\${NAME}\App\${DEFAULTAPPDIR}" StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\${NAME}\Data\${DEFAULTSETTINGSPATH}" GoTo EndINI CheckPortableAppsDIR: IfFileExists "$EXEDIR\PortableApps\${NAME}\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" CheckPortableAppsSplitDIR StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\PortableApps\${NAME}\App\${DEFAULTAPPDIR}" StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\PortableApps\${NAME}\Data\${DEFAULTSETTINGSPATH}" GoTo EndINI CheckPortableAppsSplitDIR: IfFileExists "$EXEDIR\Apps\${NAME}\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\Apps\${NAME}\${DEFAULTAPPDIR}" StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${NAME}\${DEFAULTSETTINGSPATH}" 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 already running FindProcDLL::FindProc "$PROGRAMEXECUTABLE" StrCmp $R0 "1" "" CheckForSettings StrCpy $SECONDARYLAUNCH "true" CheckForSettings: IfFileExists "$SETTINGSDIRECTORY\*.*" SettingsFound ;=== No settings found StrCmp $ISDEFAULTDIRECTORY "true" CopyDefaultSettings CreateDirectory $SETTINGSDIRECTORY Goto SettingsFound CopyDefaultSettings: CreateDirectory "$EXEDIR\Data" CreateDirectory "$EXEDIR\Data\settings" CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings GoTo SettingsFound SettingsFound: ;=== Figure out the temp registry store StrCpy "$REGISTRYDIRECTORY" "$TEMP\${NAME}\registry" ;DisplaySplash: StrCmp $DISABLESPLASHSCREEN "true" GetPassedParameters ;=== Show the splash screen before processing the files InitPluginsDir File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg" newadvsplash::show /NOUNLOAD 1500 200 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 "" LaunchNow ;=== Additional Parameters StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS` LaunchNow: StrCmp $SECONDARYLAUNCH "true" StartProgramAndExit CreateDirectory "$REGISTRYDIRECTORY" ${registry::SaveKey} "HKEY_CURRENT_USER\Software\7-zip" "$REGISTRYDIRECTORY\7zip_local.reg" "" $0 Sleep 100 ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\7-zip" $0 Sleep 100 IfFileExists "$SETTINGSDIRECTORY\7zip_portable.reg" "" StartProgramNow ${registry::RestoreKey} "$SETTINGSDIRECTORY\7zip_portable.reg" $0 Sleep 100 StartProgramNow: ExecWait $EXECSTRING CheckRunning: Sleep 2000 FindProcDLL::FindProc "$PROGRAMEXECUTABLE" StrCmp $R0 "1" CheckRunning TheEnd StartProgramAndExit: Exec $EXECSTRING Goto CloseRegistry TheEnd: ;=== Restore registry keys ${registry::SaveKey} "HKEY_CURRENT_USER\Software\7-zip" "$SETTINGSDIRECTORY\7zip_portable.reg" "" $0 Sleep 100 ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\7-zip" $0 Sleep 100 ${registry::RestoreKey} "$REGISTRYDIRECTORY\7zip_local.reg" $0 ;EndWithoutRegRestore: StrCmp $DISABLESPLASHSCREEN "true" CleanupRunLocally Sleep 2000 newadvsplash::stop CleanupRunLocally: ${registry::Unload} RMDir /r "$TEMP\${NAME}\" Goto EndOfLauncher CloseRegistry: ${registry::Unload} EndOfLauncher: SectionEnd