]> git.lyx.org Git - lyx.git/blob - development/Win32/pdfview/pdfview.nsi
01dd6e876172dad98f4ad8b2e5f37d492056aba1
[lyx.git] / development / Win32 / pdfview / pdfview.nsi
1 /*
2
3 Windows PDF view helper
4 Author: Uwe Stöhr and Joost Verburg
5
6 This will be installed as pdfview.exe.
7
8 The application will launch the default PDF viewer to display the PDF file,
9 but works around the file locking problems of Adobe Reader and Acrobat.
10
11 */
12
13 Unicode true
14
15 !include LogicLib.nsh
16 !include FileFunc.nsh
17
18 #--------------------------------
19 # Settings
20
21 Caption "PDF Viewer"
22 OutFile pdfview.exe
23 Icon "..\packaging\icons\lyx.ico"
24 SilentInstall silent
25
26 #--------------------------------
27 # Windows Vista (and later) settings
28
29 RequestExecutionLevel user
30
31 #--------------------------------
32 # Variables
33
34 Var Character
35
36 Var OriginalFile
37 Var OriginalFileName
38
39 Var PDFFile
40 Var ViewerFileName
41 Var Viewer
42 Var ViewerHandle
43 Var ViewerVersion
44
45 #--------------------------------
46 # PDF viewing
47
48 Section "View PDF file"
49
50   InitPluginsDir # Temporary directory for PDF file
51
52   # Command line parameters
53   ${GetParameters} $OriginalFileName
54
55   # Trim quotes
56   StrCpy $Character $OriginalFileName 1
57   ${If} $Character == '"'
58     StrCpy $OriginalFileName $OriginalFileName "" 1
59   ${EndIf}
60   StrCpy $Character $OriginalFileName 1 -1
61   ${If} $Character == '"'
62     StrCpy $OriginalFileName $OriginalFileName -1
63   ${EndIf}
64
65   GetFullPathName $OriginalFile $OriginalFileName
66
67   SetOutPath $TEMP # The LyX tmpbuf should not be locked
68
69   StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
70
71   # Check whether the file will be opened with Adobe Reader or Adobe Acrobat
72  
73   FileOpen $R0 "$PLUGINSDIR\a.pdf" "w" #create a temp pdf file with a simple name
74   FileClose $R0
75   
76   #find stadard executable for "a.pdf", writes result in $0 (".r0" below)
77   System::Call "shell32::FindExecutable(t '$PLUGINSDIR\a.pdf', t '', t .r0)"
78   StrCpy $ViewerFileName $0
79   ${GetFileName} $ViewerFileName $Viewer
80   
81   ${if} $Viewer == "AcroRd32.exe"
82   ${orif} $Viewer == "AcroRd64.exe"
83   ${orif} $Viewer == "Acrobat.exe"
84     
85     # get the version of Acrobat - currenly not necessary
86     GetDLLVersion $ViewerFileName $R0 $R1
87     IntOp $R2 $R0 >> 16
88     IntOp $R2 $R2 & 0x0000FFFF ; $R2 now contains major version
89     #IntOp $R3 $R0 & 0x0000FFFF ; $R3 now contains minor version
90     #IntOp $R4 $R1 >> 16
91     #IntOp $R4 $R4 & 0x0000FFFF ; $R4 now contains release
92     #IntOp $R5 $R1 & 0x0000FFFF ; $R5 now contains build
93     StrCpy $ViewerVersion $R2
94     
95     # check if there is a windows open containing the PDF
96     ${if} $Viewer == "AcroRd32.exe"
97     ${orif} $Viewer == "AcroRd64.exe"
98      ${if} $ViewerVersion > 14
99       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Reader DC"
100      ${else}
101       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Reader"
102      ${endif}
103     ${elseif} $Viewer == "Acrobat.exe"
104      FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat"
105      ${if} $ViewerHandle == "0"
106       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Pro"
107      ${endif}
108     ${endif}
109     ${if} $ViewerHandle <> "0" # close the window
110       SendMessage $ViewerHandle 16 0 0
111     ${endif}
112     
113     # Copy PDF to temporary file to allow LyX to overwrite the original
114     CopyFiles /SILENT $OriginalFile $PDFFile
115     
116     # Open a new view
117     ExecWait '"$ViewerFileName" "$PDFFile"'
118     
119   ${Else}
120   
121     # Another PDF viewer like GSView is used
122     # No need for special actions, just forward to ShellExecute
123     ExecShell open $OriginalFile
124     
125   ${EndIf}
126     
127 SectionEnd