]> git.lyx.org Git - lyx.git/blob - development/Win32/pdfview/pdfview.nsi
Address #9368
[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 == ""
82     MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
83         Please install a PDF viewer such as Adobe Reader."
84     Quit        
85   ${EndIf}
86   
87   ${if} $Viewer == "AcroRd32.exe"
88   ${orif} $Viewer == "AcroRd64.exe"
89   ${orif} $Viewer == "Acrobat.exe"
90     
91     # get the version of Acrobat - currenly not necessary
92     GetDLLVersion $ViewerFileName $R0 $R1
93     IntOp $R2 $R0 >> 16
94     IntOp $R2 $R2 & 0x0000FFFF ; $R2 now contains major version
95     #IntOp $R3 $R0 & 0x0000FFFF ; $R3 now contains minor version
96     #IntOp $R4 $R1 >> 16
97     #IntOp $R4 $R4 & 0x0000FFFF ; $R4 now contains release
98     #IntOp $R5 $R1 & 0x0000FFFF ; $R5 now contains build
99     StrCpy $ViewerVersion $R2
100     
101     # check if there is a windows open containing the PDF
102     ${if} $Viewer == "AcroRd32.exe"
103     ${orif} $Viewer == "AcroRd64.exe"
104      ${if} $ViewerVersion > 14
105       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Reader DC"
106      ${else}
107       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Reader"
108      ${endif}
109     ${elseif} $Viewer == "Acrobat.exe"
110      FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat"
111      ${if} $ViewerHandle == "0"
112       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Pro"
113      ${endif}
114     ${endif}
115     ${if} $ViewerHandle <> "0" # close the window
116       SendMessage $ViewerHandle 16 0 0
117     ${endif}
118     
119     # Copy PDF to temporary file to allow LyX to overwrite the original
120     CopyFiles /SILENT $OriginalFile $PDFFile
121     
122     # Open a new view
123     ExecWait '"$ViewerFileName" "$PDFFile"'
124     
125   ${Else}
126   
127     # Another PDF viewer like GSView is used
128     # No need for special actions, just forward to ShellExecute
129     ExecShell open $OriginalFile
130     
131   ${EndIf}
132     
133 SectionEnd