You are here

Coding IntelliLaunch . . .

OliverK's picture
Submitted by OliverK on October 13, 2008 - 10:33am

Realize that this thing is only half coded. And the logic flow will likely change.
The idea is that a general launcher could be made, and then a config ini used to setup the application.

Configuration INI (Store in AppNamePortable\Data\):

#IF YOU DON"T USE A VARIABLE LEAVE IT AS FALSE!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[Application]
ExeName=
ExecutableDirectory=
CheckRunning=True 
#Normally, you should leave "CheckRunning" set to true

[Settings]
HKCU=
HKLM=
Config_File=
Manipulate_Set_Out_Path=
#Utilize "True" or "False" for each settings storage place.
[RegistryBranch]
HKCU_Branch=
HKLM_Branch=

[Config_File_1]
#For Location_# Specify the location of the file from the App\AppName
#For instance, for a file in App\Appname\AppConfig, set Location_#=App\Appname\AppConfig
Location_1=
#For Config_File_#, specify the name of the file.
Config_File_1=

[Config_File_2]
Location_2=
Config_File_2=

[Config_File_3]
Location_3=
Config_File_3=

[Config_File_4]
Location_4=
Config_File_4=

[Config_File_5]
Location_5=
Config_File_5=

[Config_File_6]
Location_6=
Config_File_6=

[Update]
Update_Location=
Update_Location_File_1=
Update_Location_File_2=
Update_Location_File_3=

[Variables]
Path=False
#Set Path from the AppNamePortable Directory
App_Data_Redirect=False
#AppData redirect has been known not to work

And the half coded luancher that uses all this stuff

;Copyright(C) OliverKrystal 2008
;Website:  http://www.simplexitynetwork.com/mr.soup12/fakenes

;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.

;=== Program Details
Name "IntelliLaunch"
OutFile "..\..\IntelliLaunch.exe"
Caption "IntelliLaunch | PortableApps.com"
VIProductVersion "0.0.1.0"
VIAddVersionKey Comments "A luancher that use a configuration INI to allow a user to create a custom wrapper"
VIAddVersionKey CompanyName "PortableApps.com"
VIAddVersionKey LegalCopyright "PortableApps.com and Contributers"
VIAddVersionKey FileDescription ""
VIAddVersionKey FileVersion "0.0.1.0"
VIAddVersionKey ProductVersion "0.0.1.0"
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 ;no icon for the script
SilentInstall Silent ;NSIS is actually an installer language.  This keeps the script from popping open a window
AutoCloseWindow True ;in case it shows up anyway
RequestExecutionLevel user

;=== Include
;!include "GetParameters.nsh" ;these three !includes make the macro able to work
!include "ReplaceInFile.nsh"
!include "StrRep.nsh"
!include "TextFunc.nsh"
!include "MUI.nsh" ;for multi language support
;!insertmacro cfgigWrite ;this is the part that fixes the cfg file so it allows points to the write place.  Commenting out prevents the script from compiling, and thus, running.
!insertmacro GetRoot
!insertmacro UserInfo

;=== Program Icon
Icon "..\..\App\AppInfo\appicon.ico" ;defines the icon for the script

;=== Icon & Stye ===
!define MUI_ICON "..\..\App\AppInfo\appicon.ico"

;=== Languages
!insertmacro MUI_LANGUAGE "English"

LangString LauncherFileNotFound ${LANG_ENGLISH} "${PORTABLEAPPNAME} cannot be started. You may wish to re-install to fix this issue. (ERROR: $MISSINGFILEORPATH could not be found)"
LangString LauncherAlreadyRunning ${LANG_ENGLISH} "Another instance of ${APPNAME} is already running. Please close other instances of ${APPNAME} before launching ${PORTABLEAPPNAME}."
LangString LauncherAskCopyLocal ${LANG_ENGLISH} "${PORTABLEAPPNAME} appears to be running from a location that is read-only. Would you like to temporarily copy it to the local hard drive and run it from there?$\n$\nPrivacy Note: If you say Yes, your personal data within ${PORTABLEAPPNAME} will be temporarily copied to a local drive. Although this copy of your data will be deleted when you close ${PORTABLEAPPNAME}, it may be possible for someone else to access your data later."
LangString LauncherNoReadOnly ${LANG_ENGLISH} "${PORTABLEAPPNAME} can not run directly from a read-only location and will now close."

; These are all the INI Values needed to load up and start this thing :(
Var CONFIGINI
Var PROGRAMEXECUTABLE
Var PROGRAMDIRECTORY
Var HKCUUSE
Var HKLMUSE
Var CONFIGFILELOCATIONUSE
Var HKCUBRANCH
Var HKLMBRANCH
Var CONFIGFILELOCATION1
Var CONFIGFILELOCATION2
Var CONFIGFILELOCATION3
Var CONFIGFILELOCATION4
Var CONFIGFILELOCATION5
Var CONFIGFILELOCATION6
Var CONFIGFILE1
Var CONFIGFILE2
Var CONFIGFILE3
Var CONFIGFILE4
Var CONFIGFILE5
Var CONFIGFILE6
Var UPDATELOCATION
Var UPDATEFILE1
Var UPDATEFILE2
Var UPDATEFILE3
Var PATHADDITION
Var APPDATAREDIRECT
Var SETOUTPATH


Section "Main"

                IfFileExists "$EXEDIR\Data\configuration.ini" DisplaySplash
                ;=== Configuration INI not where expected
                MessageBox MB_OK|MB_ICONEXCLAMATION `IntelliLuanch's Configuration INI was not found.  Please insure that you have a placed a configured Configuration.ini in the Data folder`
                Abort
				
				DisplaySplash:
					;=== Show the splash screen before processing the files
					InitPluginsDir
					File /oname=$PLUGINSDIR\splash.jpg "IntelliLuanch.jpg"
					newadvsplash::show /NOUNLOAD 1000 0 0 -1 /L $PLUGINSDIR\splash.jpg

                LoadValues:
					StrCpy $CONFIGINI "$EXEDIR\Data\configuration.ini"
					
					;Check right off the bat if we need Admin Rights or not.  We'll check the INI.
						ReadINIStr $HKCUUSE "$CONFIGINI" "Settings" "HKCU"
						ReadINIStr $HKLMUSE "$CONFIGINI" "Settings" "HKLM"
						ReadINIStr $CONFIGFILELOCATIONUSE "$CONFIGINI" "Settings" "Config_File"
						;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
                        ClearErrors
							
					;Let's check write now for Registry Keys in the HKLM location.  If we find them there, then exit, else, we can keep loading
						StrCmp $HKLMUSE "False" "ContinueLoading 
								UserInfo::GetAccountType
								Pop $0
								StrCmp $0 "Admin" ContinueLoading
										MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherNotAdmin)`
										Abort
							
				ContinueLoading:
					;So we've checked to see if we need Admin Rights.  We either didn't, and we can keep loading, or we did and we have the rights
					;Load Application Information, setup up the Program Directory and Program Executable
						ReadINIStr $PROGRAMEXECUTABLE "$CONFIGINI" "Application" "ExeName"
						ReadINIStr $PROGRAMDIRECTORY "$CONFIGINI" "Application" "ExecutableDirectory"
						;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
                        ClearErrors
							 
					;Check to make sure that the exe is present before we take the time to do anything more
						IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" CheckRunning
							;=== Program executable not where expected
								MessageBox MB_OK|MB_ICONEXCLAMATION `$PROGRAMEXECUTABLE was not found.  Please check your configuration`
								Abort

				CheckRunning:
					;Check to make sure that the user hasn't changed the defualt Check running behavior in the INI- And for now we're gonna leave the user type floating in $0
						ReadINIStr $1 "$CONFIGINI" "Application" "ExecutableDirectory"
						StrCmp $1 "False" ConfigFileCheck
								FindProcDLL::FindProc "${DEFAULTEXE}"
									StrCmp $R0 "1" "" ConfigFileCheck
										MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherAlreadyRunning)`
										Abort
							
				ConfigFileCheck:
					;Check to see if there's any variable loading we can skip- Start with the config files
						StrCmp $CONFIGFILELOCATIONUSE "False" CheckRegistryUse ;If false, skip loading these variables and go to loading the registry		
							
					;Read the Names of the Configuration Files that the program uses
						ReadINIStr $CONFIGFILELOCATION1 "$CONFIGINI" "Configuration_Data" "Location_1"
						ReadINIStr $CONFIGFILE1 "$CONFIGINI" "Configuration_Data" "Config_File_1"
						ReadINIStr $CONFIGFILELOCATION2 "$CONFIGINI" "Configuration_Data" "Location_2"
						ReadINIStr $CONFIGFILE2 "$CONFIGINI" "Configuration_Data" "Config_File_2"
						ReadINIStr $CONFIGFILELOCATION3 "$CONFIGINI" "Configuration_Data" "Location_3"
						ReadINIStr $CONFIGFILE3 "$CONFIGINI" "Configuration_Data" "Config_File_3"
						ReadINIStr $CONFIGFILELOCATION4 "$CONFIGINI" "Configuration_Data" "Location_4"
						ReadINIStr $CONFIGFILE4 "$CONFIGINI" "Configuration_Data" "Config_File_4"
						ReadINIStr $CONFIGFILELOCATION5 "$CONFIGINI" "Configuration_Data" "Location_5"
						ReadINIStr $CONFIGFILE5 "$CONFIGINI" "Configuration_Data" "Config_File_5"
						ReadINIStr $CONFIGFILELOCATION6 "$CONFIGINI" "Configuration_Data" "Location_6"
						ReadINIStr $CONFIGFILE6 "$CONFIGINI" "Configuration_Data" "Config_File_6"
						;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
                        ClearErrors
							
					;Now, check to see if any of those files need to have their locations updated.		
						ReadINIStr $UPDATELOCATION "$CONFIGINI" "Update" "Update_Location"
						StrCmp $UPDATELOCATION "False" CheckRegistryUse ;If false, go to registry use check
							;Read the Update Locations
								ReadINIStr $UPDATEFILE1 "$CONFIGINI" "Update" "Update_Location_File_1"
								ReadINIStr $UPDATEFILE2 "$CONFIGINI" "Update" "Update_Location_File_2"
								ReadINIStr $UPDATEFILE3 "$CONFIGINI" "Update" "Update_Location_File_3"
						;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
                        ClearErrors
	;UPDATE FILES THINGS ARE HERE, REMAINS UNCODED
	ProcessFiles:
		Rename "$SETTINGSDIRECTORY\$CONFIGFILELOCATION1" "$PROGRAMDIRECTORY\$CONFIGFILELOCATION1"
		StrCmp $CONFIGFILE1 "False" AdjustSettings
		Rename "$SETTINGSDIRECTORY\$CONFIGFILELOCATION2"  "$PROGRAMSETTINGSDIRECTORY\$CONFIGFILELOCATION2"
		StrCmp $CONFIGFILELOCATION3 "False" AdjustSettings
		Rename "$SETTINGSDIRECTORY\$CONFIGFILELOCATION3" "$PROGRAMTTINGSDIRECTORY\$CONFIGFILELOCATION3"
		StrCmp $CONFIGFILELOCATION4 "False" AdjustSettings
		Rename "$SETTINGSDIRECTORY\$CONFIGFILELOCATION4" "$PROGRAMTTINGSDIRECTORY\$CONFIGFILELOCATION4"
		StrCmp $CONFIGFILELOCATION5 "False" AdjustSettings
		Rename "$SETTINGSDIRECTORY\$CONFIGFILELOCATION5" "$PROGRAMTTINGSDIRECTORY\$CONFIGFILELOCATION5"
		StrCmp $CONFIGFILELOCATION6 "False" AdjustSettings
		Rename "$SETTINGSDIRECTORY\$CONFIGFILELOCATION6" "$PROGRAMTTINGSDIRECTORY\$CONFIGFILELOCATION6"

	AdjustSettings: ;this is the part that does some of the harder work.
		StrCmp $UPDATELOCATIONS "False" RegistryBackup
		;=== Update files for new location
		${GetRoot} $EXEDIR $0
		ReadINIStr $1 "$SETTINGSDIRECTORY\${PORTABLEAPPNAME}Settings.ini" "${PORTABLEAPPNAME}Settings" "LastDriveLetter"
		StrCmp $1 "" StoreCurrentDriveLetter
		StrCmp $1 $0 Launch
		${ReplaceInFile} "$SETTINGSDIRECTORY\faknesw.cfg" "$1\" "$0\"
		Delete "$SETTINGSDIRECTORY\faknesw.cfg.old"

	StoreCurrentDriveLetter:
		WriteINIStr "$EXEDIR\Data\${PORTABLEAPPNAME}Settings.ini" "${PORTABLEAPPNAME}Settings" "LastDriveLetter" "$0"
				
				CheckRegistryUse:
					StrCmp $HKCUUSE "False" SetUpEnviroment
					StrCmp $HKLMUSE "False" SetUpEnviroment
					
					;Here's where our registry manipulations come into play
						ReadINIStr $HKCUBRANCH "$CONFIGINI" "RegistryBranch" "HKCU_Branch"
						ReadINIStr $HKLMBRANCH "$CONFIGINI" "RegistryBranch" "HKLM_Branch"
							;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
							ClearErrors
					;Begin Playing with the registry
					
					
				SetUpEnviroment:
					;Read for variable Redirects
						ReadINIStr $PATHADDTION "$CONFIGINI" "Variables" "Path"
						ReadINIStr $APPDATAREDIRECT "$CONFIGINI" "Variables" "App_Data_Redirect"
						;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
                        ClearErrors
					;Check to see if there are values with $PATHADDITON or $APPDATREDIRECT
					StrCmp $PATHADDTION "False" "" AppDataRedirectUse
						System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", "$PATHADDTION").r0'
					AppDataRedirectUse:
						StrCmp $PATHADDTION "False" "" Launch? ;Action from here is undetermined
							System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$APPDATAREDIRECT").r0'

	Launch: ;at launch do this:
		SetOutPath "$SAVEDSTATEDIRECTORY"
		Exec "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"

	CheckRunning:
		FindProcDLL::FindProc "$PROGRAMEXECUTABLE"
		StrCmp $R0 "1" CheckRunning
		Sleep 100
		
			;Cleanup after plugin leftovers :(
                newadvsplash::stop /WAIT
				${Registry:Unload}
SectionEnd