ReserveFile "${NSISDIR}\Plugins\Processes.dll"

#プロセスチェック
!macro PROCCESS_CHECK
	push $R0	; habit to save vars before using
	Processes::FindProcess "Mabinogi"
	StrCmp $R0 1 PRC_NG PRC_OK
	Processes::FindProcess "Client"
	StrCmp $R0 1 PRC_NG PRC_OK
	
	PRC_NG:
		MessageBox MB_OK|MB_ICONEXCLAMATION $(Client_Launched_Error)
		Abort
	PRC_OK:
	Pop $R0
!macroend

# Microsoft Visual C++ 2008 SP1 再頒布可能パッケージのチェック
!macro CHECK_VCREDIST
	Banner::show $(Check_vcredist)
	push $R0	; habit to save vars before using
	ReadRegDWORD $R0 HKLM "SOFTWARE\Classes\Installer\Products\1A4DE204B5F8A783688899A7FB858B2F" "ProductName"
	${If} $R0 == ''
		${If} ${FileExists} "$EXEDIR\Cache\$vcredist_x86.exe"
			DetailPrint $(Skip_Download)vcredist_x86.exe
		${Else}
			inetc::get /caption "Microsoft Visual C++ 2008 SP1" $(vcredist_url) /resume "$(Error_Download)" "$EXEDIR\Cache\vcredist_x86.exe" /end
		${EndIf}
		ExecWait '"$EXEDIR\Cache\vcredist_x86.exe" /q:a /c:"VCREDI~1.EXE /q:a /c:""msiexec /i vcredist.msi /qb!"" "'
	${EndIf}
	Pop $R0
	Banner::destroy
!macroend

#.net Frameworkのインストールチェック
!macro CHECK_DOTNET
	Banner::show "Checking Microsoft .net Framework 3.5..."
	push $R0	; habit to save vars before using
	ReadRegDWORD $R0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Install"
	${If} $R0 == ''
		${If} ${FileExists} "$EXEDIR\Cache\$dotnetfx35setup.exe"
			DetailPrint $(Skip_Download)dotnetfx35setup.exe
		${Else}
			Pop $0 # return value = exit code, "OK" means OK
			inetc::get /caption "Microsoft .NET Framework 3.5" "http://download.microsoft.com/download/6/0/f/60fc5854-3cb8-4892-b6db-bd4f42510f28/dotnetfx35.exe" /resume "$(Error_Download)" "$EXEDIR\Cache\dotnetfx35.exe" /end
		${EndIf}
		ExecWait '"$EXEDIR\Cache\dotnetfx35.exe /q:a /c:"setup.exe /q /norestart" /norestart'
	${EndIf}
	Pop $R0
	Banner::destroy
!macroend

; IsDotNETInstalled
;
; Usage:
;   Call IsDotNETInstalled
;   Pop $0
;   StrCmp $0 1 found.NETFramework no.NETFramework
Function IsDotNETInstalled
  Push $0
  Push $1
  Push $2
  Push $3
  Push $4
 
  ReadRegStr $4 HKEY_LOCAL_MACHINE \
    "Software\Microsoft\.NETFramework" "InstallRoot"
  # remove trailing back slash
  Push $4
  Exch $EXEDIR
  Exch $EXEDIR
  Pop $4
  # if the root directory doesn't exist .NET is not installed
  IfFileExists $4 0 noDotNET
 
  StrCpy $0 0
 
  EnumStart:
 
    EnumRegKey $2 HKEY_LOCAL_MACHINE \
      "Software\Microsoft\.NETFramework\Policy"  $0
    IntOp $0 $0 + 1
    StrCmp $2 "" noDotNET
 
    StrCpy $1 0
 
    EnumPolicy:
 
      EnumRegValue $3 HKEY_LOCAL_MACHINE \
        "Software\Microsoft\.NETFramework\Policy\$2" $1
      IntOp $1 $1 + 1
       StrCmp $3 "" EnumStart
        IfFileExists "$4\$2.$3" foundDotNET EnumPolicy
 
  noDotNET:
    StrCpy $0 0
    Goto done
 
  foundDotNET:
    StrCpy $0 1
 
  done:
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Exch $0
FunctionEnd