Advertisement
GordCaswell

Bits&GhostscriptCustomNSH

Feb 2nd, 2012
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ${SegmentFile}
  2.  
  3. Var CustomBits
  4.  
  5. Var GSMode
  6. Var GSDirectory
  7. Var GSRegExists
  8. Var GSExecutable
  9.  
  10. Function _Ghostscript_ValidateInstall
  11.     ${If} $Bits = 64
  12.         ${If} ${FileExists} $GSDirectory\bin\gswin64c.exe
  13.             StrCpy $GSExecutable $GSDirectory\bin\gswin64c.exe
  14.             ;${DebugMsg} "Found valid 64-bit Ghostscript install at $GSDirectory."
  15.             StrCpy $R8 "Found valid 64-bit Ghostscript install at $GSDirectory."
  16.             Push true
  17.             Goto End
  18.         ${Else}
  19.             ;${DebugMsg} "64-bit Windows but gswin64c.exe not found; trying gswin32c.exe instead."
  20.             StrCpy $R8 "64-bit Windows but gswin64c.exe not found; trying gswin32c.exe instead.$\r$\n"
  21.         ${EndIf}
  22.     ${EndIf}
  23.  
  24.     ${IfNot} ${FileExists} $GSDirectory\bin\gswin32c.exe
  25.         StrCpy $GSDirectory ""
  26.         StrCpy $GSExecutable ""
  27.         ;${DebugMsg} "No valid Ghostscript install found at $GSDirectory."
  28.         StrCpy $R8 "$R8No valid Ghostscript install found at $GSDirectory."
  29.         Push false
  30.         Goto End
  31.     ${EndIf}
  32.  
  33.     StrCpy $GSExecutable $GSDirectory\bin\gswin32c.exe
  34.     ;${DebugMsg} "Found valid 32-bit Ghostscript install at $GSDirectory."
  35.     StrCpy $R8 "$R8Found valid 32-bit Ghostscript install at $GSDirectory."
  36.     Push true
  37.     Goto End
  38.  
  39.     End:
  40. FunctionEnd
  41. !macro _Ghostscript_ValidateInstall _a _b _t _f
  42.     !insertmacro _LOGICLIB_TEMP
  43.     ;${DebugMsg} "Checking for Ghostscript in $GSDirectory..."
  44.     ${DebugMsg} `$R8`
  45.     Call _Ghostscript_ValidateInstall
  46.     Pop $_LOGICLIB_TEMP
  47.     !insertmacro _== $_LOGICLIB_TEMP true `${_t}` `${_f}`
  48. !macroend
  49. !define IsValidGhostscriptInstall `"" Ghostscript_ValidateInstall ""`
  50.  
  51. ${Segment.OnInit}
  52.     ; Borrowed the following from PAL 2.2, Remove on release of PAL 2.2
  53.         ; Work out if it's 64-bit or 32-bit
  54.     System::Call kernel32::GetCurrentProcess()i.s
  55.     System::Call kernel32::IsWow64Process(is,*i.r0)
  56.     ${If} $0 == 0
  57.         StrCpy $Bits 32
  58.     ${Else}
  59.         StrCpy $Bits 64
  60.     ${EndIf}
  61.    
  62.     StrCpy $0 $Bits
  63.     ${SetEnvironmentVariable} CustomBits $0
  64. !macroend
  65.  
  66. ${SegmentPre}  
  67.     ; If [Activate]:Ghostscript=find|require, search for Ghostscript in the
  68.     ; following locations (in order):
  69.     ;
  70.     ;  - PortableApps.com CommonFiles (..\CommonFiles\Ghostscript)
  71.     ;  - GS_PROG (which will be $GSDirectory\bin\gswin(32|64)c.exe)
  72.     ;  - Anywhere in %PATH% (with SearchPath)
  73.     ;
  74.     ; If it's in none of those, give up. [Activate]:Ghostscript=require will
  75.     ; then abort, [Activate]:Ghostscript=find will not set it.
  76.     ClearErrors
  77.     ${ReadLauncherConfig} $GSMode Activate Ghostscript
  78.     ${If} $GSMode == find
  79.     ${OrIf} $GSMode == require
  80.         StrCpy $GSDirectory $PortableAppsDirectory\CommonFiles\Ghostscript
  81.         ${IfNot} ${IsValidGhostscriptInstall}
  82.             ReadEnvStr $GSDirectory GS_PROG
  83.             ${GetParent} $GSDirectory $GSDirectory
  84.             ${GetParent} $GSDirectory $GSDirectory
  85.             ${IfNot} ${IsValidGhostscriptInstall}
  86.                 ClearErrors
  87.                 SearchPath $GSDirectory gswin32c.exe
  88.                 ${GetParent} $GSDirectory $GSDirectory
  89.                 ${GetParent} $GSDirectory $GSDirectory
  90.                 ${IfNot} ${IsValidGhostscriptInstall}
  91.                     ; If not valid, ${IsValidGhostscriptInstall} will clear
  92.                     ; $GSDirectory for us.
  93.                     Nop
  94.                 ${EndIf}
  95.             ${EndIf}
  96.         ${EndIf}
  97.  
  98.         ; If Ghostscript is required and not found, quit
  99.         ${If} $GSMode == require
  100.         ${AndIf} $GSDirectory == ""
  101.             MessageBox MB_OK|MB_ICONSTOP `$(LauncherNoGhostscript)`
  102.             Quit
  103.         ${EndIf}
  104.  
  105.         ; This may be created; check if it exists before: 0 = exists
  106.         ${registry::KeyExists} "HKCU\Software\GPL Ghostscript" $GSRegExists
  107.  
  108.         ${DebugMsg} "Selected Ghostscript path: $GSDirectory"
  109.         ${DebugMsg} "Selected Ghostscript executable: $GSExecutable"
  110.         ReadEnvStr $0 PATH
  111.         StrCpy $0 "$0;$GSDirectory\bin"
  112.         ${SetEnvironmentVariablesPath} PATH $0
  113.         ${SetEnvironmentVariablesPath} GS_PROG $GSExecutable
  114.     ${ElseIfNot} ${Errors}
  115.         ${InvalidValueError} [Activate]:Ghostscript $GSMode
  116.     ${EndIf}
  117. !macroend
  118.  
  119. ${SegmentPost}
  120.     ${If} $GSRegExists != 0  ; Didn't exist before
  121.     ${AndIf} ${RegistryKeyExists} "HKCU\Software\GPL Ghostscript"
  122.         ${registry::DeleteKey} "HKCU\Software\GPL Ghostscript" $R9
  123.     ${EndIf}
  124. !macroend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement