Merge lp:~phill-ridout/openlp/1012110_2.0 into lp:openlp/2.0

Proposed by Phill
Status: Merged
Approved by: Jonathan Corwin
Approved revision: 2175
Merged at revision: 2173
Proposed branch: lp:~phill-ridout/openlp/1012110_2.0
Merge into: lp:openlp/2.0
Diff against target: 724 lines (+146/-139)
5 files modified
openlp/plugins/presentations/lib/pptviewcontroller.py (+9/-3)
openlp/plugins/presentations/lib/pptviewlib/ppttest.py (+4/-3)
openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp (+122/-122)
openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h (+9/-9)
openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj (+2/-2)
To merge this branch: bzr merge lp:~phill-ridout/openlp/1012110_2.0
Reviewer Review Type Date Requested Status
Jonathan Corwin (community) Approve
Raoul Snyman Approve
Phill Pending
Review via email: mp+192230@code.launchpad.net

This proposal supersedes a proposal from 2013-10-06.

Description of the change

Fixes bug #1012110 by encoding the file name with the file system encoding

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

I can't test this (as I don't have Windows), but there are a few things you need to change:

On line 17 you should use os.path.normpath(), don't do a manual find and replace. See http://docs.python.org/2/library/os.path.html#os.path.normpath

On line 22 you should use os.path.join().

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

This looks better but I'm going to have to wait for someone with Windows to confirm the fix.

review: Approve
Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

Sure, I'll let the mailing list know!

On 6 October 2013 09:37, Raoul Snyman <email address hidden> wrote:

> Review: Approve
>
> This looks better but I'm going to have to wait for someone with Windows
> to confirm the fix.
> --
> https://code.launchpad.net/~phill-ridout/openlp/1012110_2.0/+merge/189494
> You are the owner of lp:~phill-ridout/openlp/1012110_2.0.
>

Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

Worked with an English file name. Didn't work with the file name Հայաստան.pptx
(Didn't crash, just said it couldn't open filename ?????????.pptx)

However this might be an issue with the C++ in pptviewlib.dll rather than the python.

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

On 7 Oct 2013 08:56, "Jonathan Corwin" <email address hidden> wrote:
>
> Worked with an English file name. Didn't work with the file name
Հայաստան.pptx
> (Didn't crash, just said it couldn't open filename ?????????.pptx)

Presumably it worked fine opening the file in Power Point with out using
OpenLP?

> However this might be an issue with the C++ in pptviewlib.dll rather than
the python.
> --
> https://code.launchpad.net/~phill-ridout/openlp/1012110_2.0/+merge/189494
> You are the owner of lp:~phill-ridout/openlp/1012110_2.0.

Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

> Presumably it worked fine opening the file in Power Point with out using
> OpenLP?

Yes it did

Revision history for this message
Phill (phill-ridout) wrote : Posted in a previous version of this proposal

Python actually creates the question marks when it tries to encode the unicode file name. From what I've read on windows all file names are unicode. How much work would it be to rewrite the c library to use unicode? Would this even solve the issue? Either way this is a bit out of my depth...

review: Needs Fixing
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

I hope this actually works, as I have no way of testing it :-)

review: Approve
Revision history for this message
Jonathan Corwin (j-corwin) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/presentations/lib/pptviewcontroller.py'
--- openlp/plugins/presentations/lib/pptviewcontroller.py 2013-08-20 18:30:15 +0000
+++ openlp/plugins/presentations/lib/pptviewcontroller.py 2013-10-22 19:57:11 +0000
@@ -29,6 +29,7 @@
2929
30import os30import os
31import logging31import logging
32import sys
3233
33if os.name == u'nt':34if os.name == u'nt':
34 from ctypes import cdll35 from ctypes import cdll
@@ -125,11 +126,16 @@
125 renderer = self.controller.plugin.renderer126 renderer = self.controller.plugin.renderer
126 rect = renderer.screens.current[u'size']127 rect = renderer.screens.current[u'size']
127 rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom())128 rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom())
128 filepath = str(self.filepath.replace(u'/', u'\\'))129 file_system_encoding = 'utf-16-le'
130 file_path = os.path.normpath(self.filepath)
131 preview_path = os.path.join(self.get_temp_folder(), u'slide')
132 # Ensure that the paths are null terminated
133 file_path = file_path.encode(file_system_encoding) + '\0'
134 preview_path = preview_path.encode(file_system_encoding) + '\0'
129 if not os.path.isdir(self.get_temp_folder()):135 if not os.path.isdir(self.get_temp_folder()):
130 os.makedirs(self.get_temp_folder())136 os.makedirs(self.get_temp_folder())
131 self.pptid = self.controller.process.OpenPPT(filepath, None, rect,137 self.pptid = self.controller.process.OpenPPT(file_path, None, rect,
132 str(self.get_temp_folder()) + '\\slide')138 preview_path)
133 if self.pptid >= 0:139 if self.pptid >= 0:
134 self.create_thumbnails()140 self.create_thumbnails()
135 self.stop_presentation()141 self.stop_presentation()
136142
=== modified file 'openlp/plugins/presentations/lib/pptviewlib/ppttest.py'
--- openlp/plugins/presentations/lib/pptviewlib/ppttest.py 2012-12-30 19:41:24 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/ppttest.py 2013-10-22 19:57:11 +0000
@@ -27,7 +27,9 @@
27# Temple Place, Suite 330, Boston, MA 02111-1307 USA #27# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
28###############################################################################28###############################################################################
2929
30import os
30import sys31import sys
32
31from PyQt4 import QtGui, QtCore33from PyQt4 import QtGui, QtCore
32from ctypes import *34from ctypes import *
33from ctypes.wintypes import RECT35from ctypes.wintypes import RECT
@@ -172,9 +174,8 @@
172 oldid = self.pptid;174 oldid = self.pptid;
173 rect = RECT(int(self.xEdit.text()), int(self.yEdit.text()),175 rect = RECT(int(self.xEdit.text()), int(self.yEdit.text()),
174 int(self.widthEdit.text()), int(self.heightEdit.text()))176 int(self.widthEdit.text()), int(self.heightEdit.text()))
175 filename = str(self.pptEdit.text().replace(u'/', u'\\'))177 filename = os.path.normpath(unicode(self.pptEdit.text())).encode('utf-16-le') + '\0'
176 folder = str(self.folderEdit.text().replace(u'/', u'\\'))178 folder = os.path.normpath(unicode(self.folderEdit.text())).encode('utf-16-le') + '\0'
177 print filename, folder
178 self.pptid = self.pptdll.OpenPPT(filename, None, rect, folder)179 self.pptid = self.pptdll.OpenPPT(filename, None, rect, folder)
179 print u'id: ' + unicode(self.pptid)180 print u'id: ' + unicode(self.pptid)
180 if oldid >= 0:181 if oldid >= 0:
181182
=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp'
--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp 2012-12-30 19:41:24 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.cpp 2013-10-22 19:57:11 +0000
@@ -61,18 +61,18 @@
61 switch(ulReasonForCall)61 switch(ulReasonForCall)
62 {62 {
63 case DLL_PROCESS_ATTACH:63 case DLL_PROCESS_ATTACH:
64 DEBUG("PROCESS_ATTACH\n");64 DEBUG(L"PROCESS_ATTACH\n");
65 break;65 break;
66 case DLL_THREAD_ATTACH:66 case DLL_THREAD_ATTACH:
67 //DEBUG("THREAD_ATTACH\n");67 //DEBUG(L"THREAD_ATTACH\n");
68 break;68 break;
69 case DLL_THREAD_DETACH:69 case DLL_THREAD_DETACH:
70 //DEBUG("THREAD_DETACH\n");70 //DEBUG(L"THREAD_DETACH\n");
71 break;71 break;
72 case DLL_PROCESS_DETACH:72 case DLL_PROCESS_DETACH:
73 // Clean up... hopefully there is only the one process attached?73 // Clean up... hopefully there is only the one process attached?
74 // We'll find out soon enough during tests!74 // We'll find out soon enough during tests!
75 DEBUG("PROCESS_DETACH\n");75 DEBUG(L"PROCESS_DETACH\n");
76 for (int i = 0; i < MAX_PPTS; i++)76 for (int i = 0; i < MAX_PPTS; i++)
77 ClosePPT(i);77 ClosePPT(i);
78 break;78 break;
@@ -84,18 +84,18 @@
84{84{
85 printf("SetDebug\n");85 printf("SetDebug\n");
86 debug = onOff;86 debug = onOff;
87 DEBUG("enabled\n");87 DEBUG(L"enabled\n");
88}88}
8989
90DllExport BOOL CheckInstalled()90DllExport BOOL CheckInstalled()
91{91{
92 char cmdLine[MAX_PATH * 2];92 wchar_t cmdLine[MAX_PATH * 2];
9393
94 DEBUG("CheckInstalled\n");94 DEBUG(L"CheckInstalled\n");
95 BOOL found = GetPPTViewerPath(cmdLine, sizeof(cmdLine));95 BOOL found = GetPPTViewerPath(cmdLine, sizeof(cmdLine));
96 if(found)96 if(found)
97 {97 {
98 DEBUG("Exe: %s\n", cmdLine);98 DEBUG(L"Exe: %s\n", cmdLine);
99 }99 }
100 return found;100 return found;
101}101}
@@ -106,20 +106,20 @@
106// "<n>.bmp" will be appended to complete the path. E.g. "c:\temp\slide" would106// "<n>.bmp" will be appended to complete the path. E.g. "c:\temp\slide" would
107// create "c:\temp\slide1.bmp" slide2.bmp, slide3.bmp etc.107// create "c:\temp\slide1.bmp" slide2.bmp, slide3.bmp etc.
108// It will also create a *info.txt containing information about the ppt108// It will also create a *info.txt containing information about the ppt
109DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect,109DllExport int OpenPPT(wchar_t *filename, HWND hParentWnd, RECT rect,
110 char *previewPath)110 wchar_t *previewPath)
111{111{
112 STARTUPINFO si;112 STARTUPINFO si;
113 PROCESS_INFORMATION pi;113 PROCESS_INFORMATION pi;
114 char cmdLine[MAX_PATH * 2];114 wchar_t cmdLine[MAX_PATH * 2];
115 int id;115 int id;
116116
117 DEBUG("OpenPPT start: %s; %s\n", filename, previewPath);117 DEBUG(L"OpenPPT start: %s; %s\n", filename, previewPath);
118 DEBUG("OpenPPT start: %u; %i, %i, %i, %i\n", hParentWnd, rect.top,118 DEBUG(L"OpenPPT start: %u; %i, %i, %i, %i\n", hParentWnd, rect.top,
119 rect.left, rect.bottom, rect.right);119 rect.left, rect.bottom, rect.right);
120 if (GetPPTViewerPath(cmdLine, sizeof(cmdLine)) == FALSE)120 if (GetPPTViewerPath(cmdLine, sizeof(cmdLine)) == FALSE)
121 {121 {
122 DEBUG("OpenPPT: GetPPTViewerPath failed\n");122 DEBUG(L"OpenPPT: GetPPTViewerPath failed\n");
123 return -1;123 return -1;
124 }124 }
125 id = -1;125 id = -1;
@@ -133,12 +133,12 @@
133 }133 }
134 if (id < 0)134 if (id < 0)
135 {135 {
136 DEBUG("OpenPPT: Too many PPTs\n");136 DEBUG(L"OpenPPT: Too many PPTs\n");
137 return -1;137 return -1;
138 }138 }
139 memset(&pptView[id], 0, sizeof(PPTVIEW));139 memset(&pptView[id], 0, sizeof(PPTVIEW));
140 strcpy_s(pptView[id].filename, MAX_PATH, filename);140 wcscpy_s(pptView[id].filename, MAX_PATH, filename);
141 strcpy_s(pptView[id].previewPath, MAX_PATH, previewPath);141 wcscpy_s(pptView[id].previewPath, MAX_PATH, previewPath);
142 pptView[id].state = PPT_CLOSED;142 pptView[id].state = PPT_CLOSED;
143 pptView[id].slideCount = 0;143 pptView[id].slideCount = 0;
144 pptView[id].currentSlide = 0;144 pptView[id].currentSlide = 0;
@@ -169,9 +169,9 @@
169 pptView[id].rect.bottom = rect.bottom;169 pptView[id].rect.bottom = rect.bottom;
170 pptView[id].rect.right = rect.right;170 pptView[id].rect.right = rect.right;
171 }171 }
172 strcat_s(cmdLine, MAX_PATH * 2, " /F /S \"");172 wcscat_s(cmdLine, MAX_PATH * 2, L" /F /S \"");
173 strcat_s(cmdLine, MAX_PATH * 2, filename);173 wcscat_s(cmdLine, MAX_PATH * 2, filename);
174 strcat_s(cmdLine, MAX_PATH * 2, "\"");174 wcscat_s(cmdLine, MAX_PATH * 2, L"\"");
175 memset(&si, 0, sizeof(si));175 memset(&si, 0, sizeof(si));
176 memset(&pi, 0, sizeof(pi));176 memset(&pi, 0, sizeof(pi));
177 BOOL gotInfo = GetPPTInfo(id);177 BOOL gotInfo = GetPPTInfo(id);
@@ -190,7 +190,7 @@
190 globalHook = SetWindowsHookEx(WH_CBT, CbtProc, hInstance, NULL);190 globalHook = SetWindowsHookEx(WH_CBT, CbtProc, hInstance, NULL);
191 if (globalHook == 0)191 if (globalHook == 0)
192 {192 {
193 DEBUG("OpenPPT: SetWindowsHookEx failed\n");193 DEBUG(L"OpenPPT: SetWindowsHookEx failed\n");
194 ClosePPT(id);194 ClosePPT(id);
195 return -1;195 return -1;
196 }196 }
@@ -198,7 +198,7 @@
198 Sleep(10);198 Sleep(10);
199 if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, 0, 0, NULL, &si, &pi))199 if (!CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, 0, 0, NULL, &si, &pi))
200 {200 {
201 DEBUG("OpenPPT: CreateProcess failed: %s\n", cmdLine);201 DEBUG(L"OpenPPT: CreateProcess failed: %s\n", cmdLine);
202 ClosePPT(id);202 ClosePPT(id);
203 return -1;203 return -1;
204 }204 }
@@ -210,13 +210,13 @@
210 Sleep(10);210 Sleep(10);
211 if (gotInfo)211 if (gotInfo)
212 {212 {
213 DEBUG("OpenPPT: Info loaded, no refresh\n");213 DEBUG(L"OpenPPT: Info loaded, no refresh\n");
214 pptView[id].state = PPT_LOADED;214 pptView[id].state = PPT_LOADED;
215 Resume(id);215 Resume(id);
216 }216 }
217 else217 else
218 {218 {
219 DEBUG("OpenPPT: Get info\n");219 DEBUG(L"OpenPPT: Get info\n");
220 pptView[id].steps = 0;220 pptView[id].steps = 0;
221 int steps = 0;221 int steps = 0;
222 while (pptView[id].state == PPT_OPENED)222 while (pptView[id].state == PPT_OPENED)
@@ -224,18 +224,18 @@
224 if (steps <= pptView[id].steps)224 if (steps <= pptView[id].steps)
225 {225 {
226 Sleep(20);226 Sleep(20);
227 DEBUG("OpenPPT: Step %d/%d\n", steps, pptView[id].steps);227 DEBUG(L"OpenPPT: Step %d/%d\n", steps, pptView[id].steps);
228 steps++;228 steps++;
229 NextStep(id);229 NextStep(id);
230 }230 }
231 Sleep(10);231 Sleep(10);
232 }232 }
233 DEBUG("OpenPPT: Slides %d, Steps %d, first slide steps %d\n",233 DEBUG(L"OpenPPT: Slides %d, Steps %d, first slide steps %d\n",
234 pptView[id].slideCount, pptView[id].steps,234 pptView[id].slideCount, pptView[id].steps,
235 pptView[id].firstSlideSteps);235 pptView[id].firstSlideSteps);
236 for(int i = 1; i <= pptView[id].slideCount; i++)236 for(int i = 1; i <= pptView[id].slideCount; i++)
237 {237 {
238 DEBUG("OpenPPT: Slide %d = %d\n", i, pptView[id].slideNos[i]);238 DEBUG(L"OpenPPT: Slide %d = %d\n", i, pptView[id].slideNos[i]);
239 }239 }
240 SavePPTInfo(id);240 SavePPTInfo(id);
241 if (pptView[id].state == PPT_CLOSING241 if (pptView[id].state == PPT_CLOSING
@@ -257,7 +257,7 @@
257 }257 }
258 pptView[id].msgHook = NULL;258 pptView[id].msgHook = NULL;
259 }259 }
260 DEBUG("OpenPPT: Exit: id=%i\n", id);260 DEBUG(L"OpenPPT: Exit: id=%i\n", id);
261 return id;261 return id;
262}262}
263// Load information about the ppt from an info.txt file.263// Load information about the ppt from an info.txt file.
@@ -270,75 +270,75 @@
270BOOL GetPPTInfo(int id)270BOOL GetPPTInfo(int id)
271{271{
272 struct _stat fileStats;272 struct _stat fileStats;
273 char info[MAX_PATH];273 wchar_t info[MAX_PATH];
274 FILE* pFile;274 FILE* pFile;
275 char buf[100];275 wchar_t buf[100];
276276
277 DEBUG("GetPPTInfo: start\n");277 DEBUG(L"GetPPTInfo: start\n");
278 if (_stat(pptView[id].filename, &fileStats) != 0)278 if (_wstat(pptView[id].filename, &fileStats) != 0)
279 {279 {
280 return FALSE;280 return FALSE;
281 }281 }
282 sprintf_s(info, MAX_PATH, "%sinfo.txt", pptView[id].previewPath);282 swprintf_s(info, MAX_PATH, L"%sinfo.txt", pptView[id].previewPath);
283 int err = fopen_s(&pFile, info, "r");283 int err = _wfopen_s(&pFile, info, L"r");
284 if (err != 0)284 if (err != 0)
285 {285 {
286 DEBUG("GetPPTInfo: file open failed - %d\n", err);286 DEBUG(L"GetPPTInfo: file open failed - %d\n", err);
287 return FALSE;287 return FALSE;
288 }288 }
289 fgets(buf, 100, pFile); // version == 1289 fgetws(buf, 100, pFile); // version == 1
290 fgets(buf, 100, pFile);290 fgetws(buf, 100, pFile);
291 if (fileStats.st_mtime != atoi(buf))291 if (fileStats.st_mtime != _wtoi(buf))
292 {292 {
293 DEBUG("GetPPTInfo: date changed\n");293 DEBUG(L"GetPPTInfo: date changed\n");
294 fclose (pFile);294 fclose (pFile);
295 return FALSE;295 return FALSE;
296 }296 }
297 fgets(buf, 100, pFile);297 fgetws(buf, 100, pFile);
298 if (fileStats.st_size != atoi(buf))298 if (fileStats.st_size != _wtoi(buf))
299 {299 {
300 DEBUG("GetPPTInfo: size changed\n");300 DEBUG(L"GetPPTInfo: size changed\n");
301 fclose (pFile);301 fclose (pFile);
302 return FALSE;302 return FALSE;
303 }303 }
304 fgets(buf, 100, pFile); // slidecount304 fgetws(buf, 100, pFile); // slidecount
305 int slideCount = atoi(buf);305 int slideCount = _wtoi(buf);
306 fgets(buf, 100, pFile); // first slide steps306 fgetws(buf, 100, pFile); // first slide steps
307 int firstSlideSteps = atoi(buf);307 int firstSlideSteps = _wtoi(buf);
308 // check all the preview images still exist308 // check all the preview images still exist
309 for (int i = 1; i <= slideCount; i++)309 for (int i = 1; i <= slideCount; i++)
310 {310 {
311 sprintf_s(info, MAX_PATH, "%s%i.bmp", pptView[id].previewPath, i);311 swprintf_s(info, MAX_PATH, L"%s%i.bmp", pptView[id].previewPath, i);
312 if (GetFileAttributes(info) == INVALID_FILE_ATTRIBUTES)312 if (GetFileAttributes(info) == INVALID_FILE_ATTRIBUTES)
313 {313 {
314 DEBUG("GetPPTInfo: bmp not found\n");314 DEBUG(L"GetPPTInfo: bmp not found\n");
315 return FALSE;315 return FALSE;
316 }316 }
317 }317 }
318 fclose(pFile);318 fclose(pFile);
319 pptView[id].slideCount = slideCount;319 pptView[id].slideCount = slideCount;
320 pptView[id].firstSlideSteps = firstSlideSteps;320 pptView[id].firstSlideSteps = firstSlideSteps;
321 DEBUG("GetPPTInfo: exit ok\n");321 DEBUG(L"GetPPTInfo: exit ok\n");
322 return TRUE;322 return TRUE;
323}323}
324324
325BOOL SavePPTInfo(int id)325BOOL SavePPTInfo(int id)
326{326{
327 struct _stat fileStats;327 struct _stat fileStats;
328 char info[MAX_PATH];328 wchar_t info[MAX_PATH];
329 FILE* pFile;329 FILE* pFile;
330330
331 DEBUG("SavePPTInfo: start\n");331 DEBUG(L"SavePPTInfo: start\n");
332 if (_stat(pptView[id].filename, &fileStats) != 0)332 if (_wstat(pptView[id].filename, &fileStats) != 0)
333 {333 {
334 DEBUG("SavePPTInfo: stat of %s failed\n", pptView[id].filename);334 DEBUG(L"SavePPTInfo: stat of %s failed\n", pptView[id].filename);
335 return FALSE;335 return FALSE;
336 }336 }
337 sprintf_s(info, MAX_PATH, "%sinfo.txt", pptView[id].previewPath);337 swprintf_s(info, MAX_PATH, L"%sinfo.txt", pptView[id].previewPath);
338 int err = fopen_s(&pFile, info, "w");338 int err = _wfopen_s(&pFile, info, L"w");
339 if (err != 0)339 if (err != 0)
340 {340 {
341 DEBUG("SavePPTInfo: fopen of %s failed%i\n", info, err);341 DEBUG(L"SavePPTInfo: fopen of %s failed%i\n", info, err);
342 return FALSE;342 return FALSE;
343 }343 }
344 fprintf(pFile, "1\n");344 fprintf(pFile, "1\n");
@@ -347,21 +347,21 @@
347 fprintf(pFile, "%u\n", pptView[id].slideCount);347 fprintf(pFile, "%u\n", pptView[id].slideCount);
348 fprintf(pFile, "%u\n", pptView[id].firstSlideSteps);348 fprintf(pFile, "%u\n", pptView[id].firstSlideSteps);
349 fclose(pFile);349 fclose(pFile);
350 DEBUG("SavePPTInfo: exit ok\n");350 DEBUG(L"SavePPTInfo: exit ok\n");
351 return TRUE;351 return TRUE;
352}352}
353353
354// Get the path of the PowerPoint viewer from the registry354// Get the path of the PowerPoint viewer from the registry
355BOOL GetPPTViewerPath(char *pptViewerPath, int stringSize)355BOOL GetPPTViewerPath(wchar_t *pptViewerPath, int stringSize)
356{356{
357 char cwd[MAX_PATH];357 wchar_t cwd[MAX_PATH];
358358
359 DEBUG("GetPPTViewerPath: start\n");359 DEBUG(L"GetPPTViewerPath: start\n");
360 if(GetPPTViewerPathFromReg(pptViewerPath, stringSize))360 if(GetPPTViewerPathFromReg(pptViewerPath, stringSize))
361 {361 {
362 if(_access(pptViewerPath, 0) != -1)362 if(_waccess(pptViewerPath, 0) != -1)
363 {363 {
364 DEBUG("GetPPTViewerPath: exit registry\n");364 DEBUG(L"GetPPTViewerPath: exit registry\n");
365 return TRUE;365 return TRUE;
366 }366 }
367 }367 }
@@ -370,37 +370,37 @@
370 // upset those who like to put things somewhere else370 // upset those who like to put things somewhere else
371371
372 // Viewer 2007 in 64bit Windows:372 // Viewer 2007 in 64bit Windows:
373 if(_access("C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE",373 if(_waccess(L"C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE",
374 0) != -1)374 0) != -1)
375 {375 {
376 strcpy_s(376 wcscpy_s(
377 "C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE",377 L"C:\\Program Files (x86)\\Microsoft Office\\Office12\\PPTVIEW.EXE",
378 stringSize, pptViewerPath);378 stringSize, pptViewerPath);
379 DEBUG("GetPPTViewerPath: exit 64bit 2007\n");379 DEBUG(L"GetPPTViewerPath: exit 64bit 2007\n");
380 return TRUE;380 return TRUE;
381 }381 }
382 // Viewer 2007 in 32bit Windows:382 // Viewer 2007 in 32bit Windows:
383 if(_access("C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE", 0)383 if(_waccess(L"C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE", 0)
384 != -1)384 != -1)
385 {385 {
386 strcpy_s("C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE",386 wcscpy_s(L"C:\\Program Files\\Microsoft Office\\Office12\\PPTVIEW.EXE",
387 stringSize, pptViewerPath);387 stringSize, pptViewerPath);
388 DEBUG("GetPPTViewerPath: exit 32bit 2007\n");388 DEBUG(L"GetPPTViewerPath: exit 32bit 2007\n");
389 return TRUE;389 return TRUE;
390 }390 }
391 // Give them the opportunity to place it in the same folder as the app391 // Give them the opportunity to place it in the same folder as the app
392 _getcwd(cwd, MAX_PATH);392 _wgetcwd(cwd, MAX_PATH);
393 strcat_s(cwd, MAX_PATH, "\\PPTVIEW.EXE");393 wcscat_s(cwd, MAX_PATH, L"\\PPTVIEW.EXE");
394 if(_access(cwd, 0) != -1)394 if(_waccess(cwd, 0) != -1)
395 {395 {
396 strcpy_s(pptViewerPath, stringSize, cwd);396 wcscpy_s(pptViewerPath, stringSize, cwd);
397 DEBUG("GetPPTViewerPath: exit local\n");397 DEBUG(L"GetPPTViewerPath: exit local\n");
398 return TRUE;398 return TRUE;
399 }399 }
400 DEBUG("GetPPTViewerPath: exit fail\n");400 DEBUG(L"GetPPTViewerPath: exit fail\n");
401 return FALSE;401 return FALSE;
402}402}
403BOOL GetPPTViewerPathFromReg(char *pptViewerPath, int stringSize)403BOOL GetPPTViewerPathFromReg(wchar_t *pptViewerPath, int stringSize)
404{404{
405 HKEY hKey;405 HKEY hKey;
406 DWORD dwType, dwSize;406 DWORD dwType, dwSize;
@@ -411,17 +411,17 @@
411 // PPT Viewer 2003 (recent versions)411 // PPT Viewer 2003 (recent versions)
412 // PPT Viewer 2003 (older versions) 412 // PPT Viewer 2003 (older versions)
413 // PPT Viewer 97413 // PPT Viewer 97
414 if ((RegOpenKeyEx(HKEY_CLASSES_ROOT,414 if ((RegOpenKeyExW(HKEY_CLASSES_ROOT,
415 "PowerPointViewer.Show.12\\shell\\Show\\command", 0, KEY_READ, &hKey)415 L"PowerPointViewer.Show.12\\shell\\Show\\command", 0, KEY_READ, &hKey)
416 != ERROR_SUCCESS)416 != ERROR_SUCCESS)
417 && (RegOpenKeyEx(HKEY_CLASSES_ROOT,417 && (RegOpenKeyExW(HKEY_CLASSES_ROOT,
418 "PowerPointViewer.Show.11\\shell\\Show\\command", 0, KEY_READ, &hKey)418 L"PowerPointViewer.Show.11\\shell\\Show\\command", 0, KEY_READ, &hKey)
419 != ERROR_SUCCESS)419 != ERROR_SUCCESS)
420 && (RegOpenKeyEx(HKEY_CLASSES_ROOT,420 && (RegOpenKeyExW(HKEY_CLASSES_ROOT,
421 "Applications\\PPTVIEW.EXE\\shell\\open\\command", 0, KEY_READ, &hKey)421 L"Applications\\PPTVIEW.EXE\\shell\\open\\command", 0, KEY_READ, &hKey)
422 != ERROR_SUCCESS)422 != ERROR_SUCCESS)
423 && (RegOpenKeyEx(HKEY_CLASSES_ROOT,423 && (RegOpenKeyExW(HKEY_CLASSES_ROOT,
424 "Applications\\PPTVIEW.EXE\\shell\\Show\\command", 0, KEY_READ, &hKey)424 L"Applications\\PPTVIEW.EXE\\shell\\Show\\command", 0, KEY_READ, &hKey)
425 != ERROR_SUCCESS))425 != ERROR_SUCCESS))
426 {426 {
427 return FALSE;427 return FALSE;
@@ -436,14 +436,14 @@
436 return FALSE;436 return FALSE;
437 }437 }
438 // remove "%1" from end of key value438 // remove "%1" from end of key value
439 pptViewerPath[strlen(pptViewerPath) - 4] = '\0';439 pptViewerPath[wcslen(pptViewerPath) - 4] = '\0';
440 return TRUE;440 return TRUE;
441}441}
442442
443// Unhook the Windows hook443// Unhook the Windows hook
444void Unhook(int id)444void Unhook(int id)
445{445{
446 DEBUG("Unhook: start %d\n", id);446 DEBUG(L"Unhook: start %d\n", id);
447 if (pptView[id].hook != NULL)447 if (pptView[id].hook != NULL)
448 {448 {
449 UnhookWindowsHookEx(pptView[id].hook);449 UnhookWindowsHookEx(pptView[id].hook);
@@ -454,13 +454,13 @@
454 }454 }
455 pptView[id].hook = NULL;455 pptView[id].hook = NULL;
456 pptView[id].msgHook = NULL;456 pptView[id].msgHook = NULL;
457 DEBUG("Unhook: exit ok\n");457 DEBUG(L"Unhook: exit ok\n");
458}458}
459459
460// Close the PowerPoint viewer, release resources460// Close the PowerPoint viewer, release resources
461DllExport void ClosePPT(int id)461DllExport void ClosePPT(int id)
462{462{
463 DEBUG("ClosePPT: start%d\n", id);463 DEBUG(L"ClosePPT: start%d\n", id);
464 pptView[id].state = PPT_CLOSED;464 pptView[id].state = PPT_CLOSED;
465 Unhook(id);465 Unhook(id);
466 if (pptView[id].hWnd == 0)466 if (pptView[id].hWnd == 0)
@@ -474,13 +474,13 @@
474 CloseHandle(pptView[id].hThread);474 CloseHandle(pptView[id].hThread);
475 CloseHandle(pptView[id].hProcess);475 CloseHandle(pptView[id].hProcess);
476 memset(&pptView[id], 0, sizeof(PPTVIEW));476 memset(&pptView[id], 0, sizeof(PPTVIEW));
477 DEBUG("ClosePPT: exit ok\n");477 DEBUG(L"ClosePPT: exit ok\n");
478 return;478 return;
479}479}
480// Moves the show back onto the display480// Moves the show back onto the display
481DllExport void Resume(int id)481DllExport void Resume(int id)
482{482{
483 DEBUG("Resume: %d\n", id);483 DEBUG(L"Resume: %d\n", id);
484 MoveWindow(pptView[id].hWnd, pptView[id].rect.left,484 MoveWindow(pptView[id].hWnd, pptView[id].rect.left,
485 pptView[id].rect.top,485 pptView[id].rect.top,
486 pptView[id].rect.right - pptView[id].rect.left,486 pptView[id].rect.right - pptView[id].rect.left,
@@ -490,7 +490,7 @@
490// Moves the show off the screen so it can't be seen490// Moves the show off the screen so it can't be seen
491DllExport void Stop(int id)491DllExport void Stop(int id)
492{492{
493 DEBUG("Stop:%d\n", id);493 DEBUG(L"Stop:%d\n", id);
494 MoveWindow(pptView[id].hWnd, -32000, -32000,494 MoveWindow(pptView[id].hWnd, -32000, -32000,
495 pptView[id].rect.right - pptView[id].rect.left,495 pptView[id].rect.right - pptView[id].rect.left,
496 pptView[id].rect.bottom - pptView[id].rect.top, TRUE);496 pptView[id].rect.bottom - pptView[id].rect.top, TRUE);
@@ -499,7 +499,7 @@
499// Return the total number of slides499// Return the total number of slides
500DllExport int GetSlideCount(int id)500DllExport int GetSlideCount(int id)
501{501{
502 DEBUG("GetSlideCount:%d\n", id);502 DEBUG(L"GetSlideCount:%d\n", id);
503 if (pptView[id].state == 0)503 if (pptView[id].state == 0)
504 {504 {
505 return -1;505 return -1;
@@ -513,7 +513,7 @@
513// Return the number of the slide currently viewing513// Return the number of the slide currently viewing
514DllExport int GetCurrentSlide(int id)514DllExport int GetCurrentSlide(int id)
515{515{
516 DEBUG("GetCurrentSlide:%d\n", id);516 DEBUG(L"GetCurrentSlide:%d\n", id);
517 if (pptView[id].state == 0)517 if (pptView[id].state == 0)
518 {518 {
519 return -1;519 return -1;
@@ -527,7 +527,7 @@
527// Take a step forwards through the show527// Take a step forwards through the show
528DllExport void NextStep(int id)528DllExport void NextStep(int id)
529{529{
530 DEBUG("NextStep:%d (%d)\n", id, pptView[id].currentSlide);530 DEBUG(L"NextStep:%d (%d)\n", id, pptView[id].currentSlide);
531 if (pptView[id].currentSlide > pptView[id].slideCount) return;531 if (pptView[id].currentSlide > pptView[id].slideCount) return;
532 if (pptView[id].currentSlide < pptView[id].slideCount)532 if (pptView[id].currentSlide < pptView[id].slideCount)
533 {533 {
@@ -540,7 +540,7 @@
540// Take a step backwards through the show540// Take a step backwards through the show
541DllExport void PrevStep(int id)541DllExport void PrevStep(int id)
542{542{
543 DEBUG("PrevStep:%d (%d)\n", id, pptView[id].currentSlide);543 DEBUG(L"PrevStep:%d (%d)\n", id, pptView[id].currentSlide);
544 if (pptView[id].currentSlide > 1)544 if (pptView[id].currentSlide > 1)
545 {545 {
546 pptView[id].guess = pptView[id].currentSlide - 1;546 pptView[id].guess = pptView[id].currentSlide - 1;
@@ -556,7 +556,7 @@
556 // So send random unmapped letter first (say 'A'), then we can556 // So send random unmapped letter first (say 'A'), then we can
557 // better guarantee B will blank instead of trying to guess557 // better guarantee B will blank instead of trying to guess
558 // whether it was already blank or not.558 // whether it was already blank or not.
559 DEBUG("Blank:%d\n", id);559 DEBUG(L"Blank:%d\n", id);
560 HWND h1 = GetForegroundWindow();560 HWND h1 = GetForegroundWindow();
561 HWND h2 = GetFocus();561 HWND h2 = GetFocus();
562 SetForegroundWindow(pptView[id].hWnd);562 SetForegroundWindow(pptView[id].hWnd);
@@ -573,7 +573,7 @@
573// Unblank the show573// Unblank the show
574DllExport void Unblank(int id)574DllExport void Unblank(int id)
575{575{
576 DEBUG("Unblank:%d\n", id);576 DEBUG(L"Unblank:%d\n", id);
577 // Pressing any key resumes.577 // Pressing any key resumes.
578 // For some reason SendMessage works for unblanking, but not blanking.578 // For some reason SendMessage works for unblanking, but not blanking.
579 SendMessage(pptView[id].hWnd2, WM_CHAR, 'A', 0);579 SendMessage(pptView[id].hWnd2, WM_CHAR, 'A', 0);
@@ -582,7 +582,7 @@
582// Go directly to a slide582// Go directly to a slide
583DllExport void GotoSlide(int id, int slideNo)583DllExport void GotoSlide(int id, int slideNo)
584{584{
585 DEBUG("GotoSlide %i %i:\n", id, slideNo);585 DEBUG(L"GotoSlide %i %i:\n", id, slideNo);
586 // Did try WM_KEYDOWN/WM_CHAR/WM_KEYUP with SendMessage but didn't work586 // Did try WM_KEYDOWN/WM_CHAR/WM_KEYUP with SendMessage but didn't work
587 // perhaps I was sending to the wrong window? No idea.587 // perhaps I was sending to the wrong window? No idea.
588 // Anyway fall back to keybd_event, which is OK as long we makesure588 // Anyway fall back to keybd_event, which is OK as long we makesure
@@ -619,7 +619,7 @@
619 // Only way I've found to get around this is to step backwards all the way619 // Only way I've found to get around this is to step backwards all the way
620 // through. Lets move the window out of the way first so the audience620 // through. Lets move the window out of the way first so the audience
621 // doesn't see this.621 // doesn't see this.
622 DEBUG("RestartShow:%d\n", id);622 DEBUG(L"RestartShow:%d\n", id);
623 Stop(id);623 Stop(id);
624 GotoSlide(id, pptView[id].slideCount);624 GotoSlide(id, pptView[id].slideCount);
625 for (int i=0; i <= pptView[id].steps - pptView[id].lastSlideSteps; i++)625 for (int i=0; i <= pptView[id].steps - pptView[id].lastSlideSteps; i++)
@@ -644,12 +644,12 @@
644 HHOOK hook = globalHook;644 HHOOK hook = globalHook;
645 if (nCode == HCBT_CREATEWND)645 if (nCode == HCBT_CREATEWND)
646 {646 {
647 char csClassName[16];647 wchar_t csClassName[32];
648 HWND hCurrWnd = (HWND)wParam;648 HWND hCurrWnd = (HWND)wParam;
649 DWORD retProcId = NULL;649 DWORD retProcId = NULL;
650 GetClassName(hCurrWnd, csClassName, sizeof(csClassName));650 GetClassName(hCurrWnd, csClassName, sizeof(csClassName));
651 if ((strcmp(csClassName, "paneClassDC") == 0)651 if ((wcscmp(csClassName, L"paneClassDC") == 0)
652 ||(strcmp(csClassName, "screenClass") == 0))652 ||(wcscmp(csClassName, L"screenClass") == 0))
653 {653 {
654 int id = -1;654 int id = -1;
655 DWORD windowThread = GetWindowThreadProcessId(hCurrWnd, NULL);655 DWORD windowThread = GetWindowThreadProcessId(hCurrWnd, NULL);
@@ -663,7 +663,7 @@
663 }663 }
664 if (id >= 0)664 if (id >= 0)
665 {665 {
666 if (strcmp(csClassName, "paneClassDC") == 0)666 if (wcscmp(csClassName, L"paneClassDC") == 0)
667 {667 {
668 pptView[id].hWnd2 = hCurrWnd;668 pptView[id].hWnd2 = hCurrWnd;
669 }669 }
@@ -737,7 +737,7 @@
737 CWPSTRUCT *cwp;737 CWPSTRUCT *cwp;
738 cwp = (CWPSTRUCT *)lParam;738 cwp = (CWPSTRUCT *)lParam;
739 HHOOK hook = NULL;739 HHOOK hook = NULL;
740 char filename[MAX_PATH];740 wchar_t filename[MAX_PATH];
741741
742 DWORD windowThread = GetWindowThreadProcessId(cwp->hwnd, NULL);742 DWORD windowThread = GetWindowThreadProcessId(cwp->hwnd, NULL);
743 int id = -1;743 int id = -1;
@@ -758,9 +758,9 @@
758 {758 {
759 if ((pptView[id].currentSlide > 0)759 if ((pptView[id].currentSlide > 0)
760 && (pptView[id].previewPath != NULL760 && (pptView[id].previewPath != NULL
761 && strlen(pptView[id].previewPath) > 0))761 && wcslen(pptView[id].previewPath) > 0))
762 {762 {
763 sprintf_s(filename, MAX_PATH, "%s%i.bmp",763 swprintf_s(filename, MAX_PATH, L"%s%i.bmp",
764 pptView[id].previewPath,764 pptView[id].previewPath,
765 pptView[id].currentSlide);765 pptView[id].currentSlide);
766 CaptureAndSaveWindow(cwp->hwnd, filename);766 CaptureAndSaveWindow(cwp->hwnd, filename);
@@ -820,7 +820,7 @@
820 return CallNextHookEx(hook, nCode, wParam, lParam);820 return CallNextHookEx(hook, nCode, wParam, lParam);
821}821}
822822
823VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename)823VOID CaptureAndSaveWindow(HWND hWnd, wchar_t* filename)
824{824{
825 HBITMAP hBmp;825 HBITMAP hBmp;
826 if ((hBmp = CaptureWindow(hWnd)) == NULL)826 if ((hBmp = CaptureWindow(hWnd)) == NULL)
@@ -863,7 +863,7 @@
863863
864 // Writing:864 // Writing:
865 FILE* pFile;865 FILE* pFile;
866 int err = fopen_s(&pFile, filename, "wb");866 int err = _wfopen_s(&pFile, filename, L"wb");
867 if (err == 0)867 if (err == 0)
868 {868 {
869 fwrite(&bmf, sizeof(bmf), 1, pFile);869 fwrite(&bmf, sizeof(bmf), 1, pFile);
@@ -893,7 +893,7 @@
893 if ((hMemDC = CreateCompatibleDC(hDC)) != NULL)893 if ((hMemDC = CreateCompatibleDC(hDC)) != NULL)
894 {894 {
895 hDCBmp = (HBITMAP)SelectObject(hMemDC, hImage);895 hDCBmp = (HBITMAP)SelectObject(hMemDC, hImage);
896 HMODULE hLib = LoadLibrary("User32");896 HMODULE hLib = LoadLibrary(L"User32");
897 // PrintWindow works for windows outside displayable area897 // PrintWindow works for windows outside displayable area
898 // but was only introduced in WinXP. BitBlt requires the window to898 // but was only introduced in WinXP. BitBlt requires the window to
899 // be topmost and within the viewable area of the display899 // be topmost and within the viewable area of the display
900900
=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h'
--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h 2012-12-30 19:41:24 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.h 2013-10-22 19:57:11 +0000
@@ -26,13 +26,13 @@
2626
27#define DllExport extern "C" __declspec( dllexport )27#define DllExport extern "C" __declspec( dllexport )
2828
29#define DEBUG(...) if (debug) printf(__VA_ARGS__)29#define DEBUG(...) if (debug) wprintf(__VA_ARGS__)
3030
31enum PPTVIEWSTATE {PPT_CLOSED, PPT_STARTED, PPT_OPENED, PPT_LOADED,31enum PPTVIEWSTATE {PPT_CLOSED, PPT_STARTED, PPT_OPENED, PPT_LOADED,
32 PPT_CLOSING};32 PPT_CLOSING};
3333
34DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect,34DllExport int OpenPPT(wchar_t *filename, HWND hParentWnd, RECT rect,
35 char *previewPath);35 wchar_t *previewPath);
36DllExport BOOL CheckInstalled();36DllExport BOOL CheckInstalled();
37DllExport void ClosePPT(int id);37DllExport void ClosePPT(int id);
38DllExport int GetCurrentSlide(int id);38DllExport int GetCurrentSlide(int id);
@@ -50,11 +50,11 @@
50LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam);50LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam);
51LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam);51LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam);
52LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);52LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);
53BOOL GetPPTViewerPath(char *pptViewerPath, int stringSize);53BOOL GetPPTViewerPath(wchar_t *pptViewerPath, int stringSize);
54BOOL GetPPTViewerPathFromReg(char *pptViewerPath, int stringSize);54BOOL GetPPTViewerPathFromReg(wchar_t *pptViewerPath, int stringSize);
55HBITMAP CaptureWindow(HWND hWnd);55HBITMAP CaptureWindow(HWND hWnd);
56VOID SaveBitmap(CHAR* filename, HBITMAP hBmp) ;56VOID SaveBitmap(wchar_t* filename, HBITMAP hBmp) ;
57VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename);57VOID CaptureAndSaveWindow(HWND hWnd, wchar_t* filename);
58BOOL GetPPTInfo(int id);58BOOL GetPPTInfo(int id);
59BOOL SavePPTInfo(int id);59BOOL SavePPTInfo(int id);
60void Unhook(int id);60void Unhook(int id);
@@ -80,8 +80,8 @@
80 int lastSlideSteps;80 int lastSlideSteps;
81 int steps;81 int steps;
82 int guess;82 int guess;
83 char filename[MAX_PATH];83 wchar_t filename[MAX_PATH];
84 char previewPath[MAX_PATH];84 wchar_t previewPath[MAX_PATH];
85 int slideNos[MAX_SLIDES];85 int slideNos[MAX_SLIDES];
86 PPTVIEWSTATE state;86 PPTVIEWSTATE state;
87};87};
8888
=== modified file 'openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj'
--- openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj 2010-09-14 18:18:47 +0000
+++ openlp/plugins/presentations/lib/pptviewlib/pptviewlib.vcproj 2013-10-22 19:57:11 +0000
@@ -21,7 +21,7 @@
21 OutputDirectory="$(SolutionDir)$(ConfigurationName)"21 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
22 IntermediateDirectory="$(ConfigurationName)"22 IntermediateDirectory="$(ConfigurationName)"
23 ConfigurationType="2"23 ConfigurationType="2"
24 CharacterSet="2"24 CharacterSet="1"
25 >25 >
26 <Tool26 <Tool
27 Name="VCPreBuildEventTool"27 Name="VCPreBuildEventTool"
@@ -93,7 +93,7 @@
93 OutputDirectory="$(SolutionDir)$(ConfigurationName)"93 OutputDirectory="$(SolutionDir)$(ConfigurationName)"
94 IntermediateDirectory="$(ConfigurationName)"94 IntermediateDirectory="$(ConfigurationName)"
95 ConfigurationType="2"95 ConfigurationType="2"
96 CharacterSet="2"96 CharacterSet="1"
97 WholeProgramOptimization="1"97 WholeProgramOptimization="1"
98 >98 >
99 <Tool99 <Tool

Subscribers

People subscribed via source and target branches