;(c)GNU GPL latest version, adapted from (c)PortableAppz

${SegmentFile}

!define CUSTOM_APPDIR '$AppDirectory\Chrome-bin'
!define CUSTOM_COMMONFILES "$PortableAppsDirectory\CommonFiles" ;standard PortableApps.com common folder
!define CUSTOM_APPPLUGINDIR "${CUSTOM_APPDIR}\plugins" ;browser's plugins folder

Var Custom_AdditionalParameters ;variable to hold additional parameters in portable app. ini file

${SegmentPre}
	;setting up PPAPI/pepper switches and write them to $EXEDIR\$BaseName.ini
	;set in Pre before ExecString
	${If} ${FileExists} "${CUSTOM_COMMONFILES}\Flash\pepflashplayer.dll"
		StrCpy $Custom_AdditionalParameters '--ppapi-flash-path="${CUSTOM_COMMONFILES}\Flash\pepflashplayer.dll"'
		${GetFileVersion} "${CUSTOM_COMMONFILES}\Flash\pepflashplayer.dll" $0
		StrCpy $Custom_AdditionalParameters '$Custom_AdditionalParameters --ppapi-flash-version=$0'
	${Else}
		;if not in CommonFiles, then in some custom, hard-coded folder
		${If} ${FileExists} "${CUSTOM_APPPLUGINDIR}\pepflashplayer.dll"
			StrCpy $Custom_AdditionalParameters '--ppapi-flash-path="${CUSTOM_APPPLUGINDIR}\pepflashplayer.dll"'
			${GetFileVersion} "${CUSTOM_APPPLUGINDIR}\pepflashplayer.dll" $0
			StrCpy $Custom_AdditionalParameters '$Custom_AdditionalParameters --ppapi-flash-version=$0'
		${Endif}
	${Endif}

	${IfNot} ${FileExists} '$EXEDIR\$BaseName.ini'
		;copy AppNamePortable.ini to $BaseName.ini
		CopyFiles /silent '$EXEDIR\Other\Source\AppNamePortable.ini' '$EXEDIR\$BaseName.ini'
		FileOpen $R9 '$EXEDIR\$BaseName.ini' w ;delete contents
		FileClose $R9
	${Endif}

	;write AdditionalParameters
	${ConfigWrite} '$EXEDIR\$BaseName.ini' 'AdditionalParameters=' '$Custom_AdditionalParameters' $R9
!macroend

${SegmentPostPrimary}
	;clean up some folders/files...
	;RMDir [/r] [/REBOOTOK] directory_name
	;Without /r, the directory will only be removed if it is completely empty.
	RMDir /r '$DataDirectory\User Data\PepperFlash'
	RMDir /r '$DataDirectory\User Data\Default\Pepper Data'
	RMDir /r '$DataDirectory\User Data\Default\Cache'
	RMDir /r '$DataDirectory\User Data\Default\Media Cache'
!macroend
