;Copyright (C) 2007 Ryan McCue of PortableApps.com ;Copyright (C) 2004-2007 John T. Haller of PortableApps.com ;Website: http://example.com/ ;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 "CDisplayExPortable" !define FULLNAME "CDisplayEx Portable" !define APP "CDisplayEx" !define VER "1.4.0.0" !define WEBSITE "Example.com" !define DEFAULTEXE "cdisplayex.exe" !define DEFAULTAPPDIR "cdisplayex" !define DEFAULTSETTINGSDIR "settings" ;=== Program Details Name "${FULLNAME}" OutFile "${NAME}.exe" Caption "${FULLNAME} | PortableApps.com" VIProductVersion "${VER}" VIAddVersionKey ProductName "${FULLNAME}" VIAddVersionKey Comments "Allows ${APP} to be run from a removable drive. For additional details, visit ${WEBSITE}" VIAddVersionKey CompanyName "PortableApps.com" VIAddVersionKey LegalCopyright "PortableApps.com and contributors" 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 "FileFunc.nsh" !insertmacro GetRoot !include "ReplaceInFile.nsh" !include "StrRep.nsh" ;=== Program Icon Icon "${NAME}.ico" Var SECONDARYLAUNCH Var PROGRAMDIRECTORY Var SETTINGSDIRECTORY Var ADDITIONALPARAMETERS Var EXECSTRING Var DISABLESPLASHSCREEN 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: ReadINIStr $ADDITIONALPARAMETERS "$EXEDIR\${NAME}.ini" "${NAME}" "AdditionalParameters" ReadINIStr $DISABLESPLASHSCREEN "$EXEDIR\${NAME}.ini" "${NAME}" "DisableSplashScreen" StrCpy $PROGRAMDIRECTORY "$EXEDIR\App\${DEFAULTAPPDIR}" StrCpy $SETTINGSDIRECTORY "$EXEDIR\Data\${DEFAULTSETTINGSDIR}" IfFileExists "$PROGRAMDIRECTORY\${DEFAULTEXE}" FoundProgramEXE ;NoProgramEXE: ;=== Program executable not where expected MessageBox MB_OK|MB_ICONEXCLAMATION `${DEFAULTEXE} was not found. Please check your configuration` Abort FoundProgramEXE: ;=== Check if running StrCmp $SECONDARYLAUNCH "true" GetPassedParameters FindProcDLL::FindProc "${DEFAULTEXE}" 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 1000 100 0 -1 /L $PLUGINSDIR\splash.jpg GetPassedParameters: ;=== Get any passed parameters Call GetParameters Pop $0 StrCmp "'$0'" "''" "" LaunchProgramParameters ;=== No parameters StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\${DEFAULTEXE}"` Goto AdditionalParameters LaunchProgramParameters: StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\${DEFAULTEXE}" $0` AdditionalParameters: StrCmp $ADDITIONALPARAMETERS "" SettingsDirectory ;=== Additional Parameters StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS` SettingsDirectory: ;=== Set the settings directory if we have a path IfFileExists "$SETTINGSDIRECTORY\*.*" AdjustSettings CreateDirectory $SETTINGSDIRECTORY AdjustSettings: ;=== Update files for new location ${GetRoot} $EXEDIR $0 ReadINIStr $1 "$SETTINGSDIRECTORY\${NAME}Settings.ini" "${NAME}Settings" "LastDriveLetter" StrCmp $1 "" StoreCurrentDriveLetter StrCmp $1 $0 StoreCurrentDriveLetter IfFileExists "$PROGRAMDIRECTORY\cdisplayex.xml" "" StoreCurrentDriveLetter ${ReplaceInFile} "$PROGRAMDIRECTORY\cdisplayex.xml" "$1" "$0" StoreCurrentDriveLetter: WriteINIStr "$SETTINGSDIRECTORY\${NAME}Settings.ini" "${NAME}Settings" "LastDriveLetter" "$0" ; CheckForSettings: IfFileExists "$PROGRAMDIRECTORY\cdisplayex.xml" LaunchNow IfFileExists "$SETTINGSDIRECTORY\cdisplayex.xml" CopySettings IfFileExists "$EXEDIR\App\DefaultData\*.*" CopyDefaultSettings IfFileExists "$EXEDIR\${NAME}\App\DefaultData\*.*" CopySubSettings MessageBox MB_OK|MB_ICONEXCLAMATION "Your settings could not be found and default settings could not be copied. Please run ${NAME} once with a standard directory setup to create default settings" Abort CopyDefaultSettings: CopyFiles /SILENT "$EXEDIR\App\DefaultData\*.*" "$PROGRAMDIRECTORY" Goto LaunchNow CopySubSettings: CopyFiles /SILENT "$EXEDIR\${NAME}\App\DefaultData\*.*" "$PROGRAMDIRECTORY" Goto LaunchNow CopySettings: Rename "$SETTINGSDIRECTORY\cdisplayex.xml" "$PROGRAMDIRECTORY\cdisplayex.xml" LaunchNow: SetOutPath "$SETTINGSDIRECTORY" ExecWait $EXECSTRING CheckRunning: Sleep 1000 FindProcDLL::FindProc "${DEFAULTEXE}" StrCmp $R0 "1" CheckRunning ;=== Put the settings files back Sleep 500 Rename "$PROGRAMDIRECTORY\cdisplayex.xml" "$SETTINGSDIRECTORY\cdisplayex.xml" Goto TheEnd TheEnd: newadvsplash::wait SectionEnd