]> git.lyx.org Git - lyx.git/blob - development/Win32/pdfview/pdfview.nsi
Add support for mixed-encoded biblatex files
[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 # FIXME
14 #Unicode true
15 #doesn't work with the Uniode system.dll of NSIS 3.0.2 
16
17 !include LogicLib.nsh
18 !include FileFunc.nsh
19
20 #--------------------------------
21 # Settings
22
23 Caption "PDF Viewer"
24 OutFile pdfview.exe
25 Icon "..\packaging\icons\lyx.ico"
26 SilentInstall silent
27
28 #--------------------------------
29 # Windows Vista (and later) settings
30
31 RequestExecutionLevel user
32
33 #--------------------------------
34 # Variables
35
36 Var Character
37 Var RunAppReturn
38
39 Var OriginalFile
40 Var OriginalFileName
41 Var OriginalDir
42
43 Var PDFFile
44 Var ViewerFileName
45 Var Viewer
46 Var ViewerHandle
47 Var ViewerVersion
48
49 #--------------------------------
50 # Macros
51
52 !macro SystemCall STACK
53
54   # Call a Windows API function
55
56   Push `${STACK}`
57   CallInstDLL "$EXEDIR\System.dll" Call
58
59 !macroend
60
61 !macro HideConsole COMMAND_LINE
62
63   # Run an application and hide console output
64
65   Push `${COMMAND_LINE}`
66   CallInstDLL "$EXEDIR\Console.dll" Exec
67   Pop $RunAppReturn
68   
69   ${If} $RunAppReturn == "error"
70     MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $PDFFile."
71   ${EndIf}
72
73 !macroend
74
75 #--------------------------------
76 # PDF viewing
77
78 Section "View PDF file"
79
80   InitPluginsDir # Temporary directory for PDF file
81
82   # Command line parameters
83   ${GetParameters} $OriginalFile
84
85   # Trim quotes
86   StrCpy $Character $OriginalFile 1
87   ${If} $Character == '"'
88     StrCpy $OriginalFile $OriginalFile "" 1
89   ${EndIf}
90   StrCpy $Character $OriginalFile 1 -1
91   ${If} $Character == '"'
92     StrCpy $OriginalFile $OriginalFile -1
93   ${EndIf}
94
95   GetFullPathName $OriginalFile $OriginalFile
96   ${GetFileName} $OriginalFile $OriginalFileName
97   ${GetParent} $OriginalFile $OriginalDir # tmpbuf
98   ${GetParent} $OriginalDir $OriginalDir # tmpdir
99
100   SetOutPath $TEMP # The LyX tmpbuf should not be locked
101
102   StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
103
104   # Check whether the file will be opened with Adobe Reader or Adobe Acrobat
105   !insertmacro SystemCall "shell32::FindExecutable(t '$OriginalFile', t '', t .s)"
106   Pop $ViewerFileName
107   ${GetFileName} $ViewerFileName $Viewer
108
109   ${If} $Viewer == ""
110     MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
111         Please install a PDF viewer such as Adobe Reader."
112     Quit        
113   ${EndIf}
114   
115   ${if} $Viewer == "AcroRd32.exe"
116   ${orif} $Viewer == "AcroRd64.exe"
117   ${orif} $Viewer == "Acrobat.exe"
118     
119     # get the version of Acrobat - currenly not necessary
120     GetDLLVersion $ViewerFileName $R0 $R1
121     IntOp $R2 $R0 >> 16
122     IntOp $R2 $R2 & 0x0000FFFF ; $R2 now contains major version
123     #IntOp $R3 $R0 & 0x0000FFFF ; $R3 now contains minor version
124     #IntOp $R4 $R1 >> 16
125     #IntOp $R4 $R4 & 0x0000FFFF ; $R4 now contains release
126     #IntOp $R5 $R1 & 0x0000FFFF ; $R5 now contains build
127     StrCpy $ViewerVersion $R2
128     
129     # check if there is a windows open containing the PDF
130     ${if} $Viewer == "AcroRd32.exe"
131     ${orif} $Viewer == "AcroRd64.exe"
132      ${if} $ViewerVersion > 14
133       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Reader DC"
134      ${else}
135       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Reader"
136      ${endif}
137     ${elseif} $Viewer == "Acrobat.exe"
138      FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat"
139      ${if} $ViewerHandle == "0"
140       FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Pro"
141      ${endif}
142     ${endif}
143     ${if} $ViewerHandle <> "0" # close the window
144       SendMessage $ViewerHandle 16 0 0
145     ${endif}
146     
147     # Copy PDF to temporary file to allow LyX to overwrite the original
148     CopyFiles /SILENT $OriginalFile $PDFFile
149     
150     # Open a new view
151     !insertmacro HideConsole '"$ViewerFileName" "$PDFFile"'
152     
153   ${Else}
154   
155     # Another PDF viewer like GSView is used
156     # No need for special actions, just forward to ShellExecute
157     ExecShell open $OriginalFile
158     
159   ${EndIf}
160     
161 SectionEnd