source: trunk/dll/defview.c@ 1479

Last change on this file since 1479 was 1479, checked in by Gregg Young, 16 years ago

Work around MMIO's failure to recognize MPG files as media. Reorder file type checks to eliminate problem with MMIO identifying exes etc as media. Check for zero byte file and let user decide to open in an editor or abort (also prevents MMIO misidentification). Tickets 70, 405, 409, 410

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: defview.c 1479 2009-11-15 22:40:25Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2003, 2008 Steven H.Levine
8
9 Default file viewer
10
11 20 Nov 03 SHL ShowMultimedia: try to convince fmplay to not play exes (Gregg Young)
12 14 Jul 06 SHL Use Runtime_Error
13 18 Mar 07 GKY Fixed misindentifycation of nonmultimedia files by ShowMultiMedia
14 18 Mar 07 GKY Open mp3, ogg & flac files with OS2 object default since fm2play fails
15 21 Apr 07 GKY Find FM2Utils by path or utils directory
16 09 Jun 07 SHL ShowMultimedia: Initialize hwnd so that OpenObject might work
17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
18 20 Dec 07 GKY Open jpg files with OS2 object default since image.exe fails
19 29 Feb 08 GKY Refactor global command line variables to notebook.h
20 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
21 less than 10 KiB (It hangs and can't be closed)
22 05 Jan 09 GKY Use TestBinary so that text veiwer isn't used for hex files by default
23 08 Mar 09 GKY Additional strings move to PCSZs
24 15 Nov 09 GKY Add check for attempt to open zero byte file and reorder file type checks
25 to place exes before MMPM check (avoids MMPM trying to play them)
26 15 Nov 09 GKY Work around MMIO's falure to identify MPG files as media
27
28***********************************************************************/
29
30#include <string.h>
31#include <ctype.h>
32
33#define INCL_DOS
34#define INCL_WIN
35#define INCL_GPI
36#define INCL_MMIOOS2
37#define INCL_LONGLONG // dircnrs.h
38#include <os2.h>
39#include <os2me.h>
40
41#include "fm3dll.h"
42#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
43#include "mainwnd2.h" // Data declaration(s)
44#include "init.h" // Data declaration(s)
45#include "fm3dlg.h"
46#include "arccnrs.h" // StartArcCnr
47#include "errutil.h" // Dos_Error...
48#include "notebook.h" // external viewers
49#include "defview.h"
50#include "info.h" // DrvInfoProc
51#include "assoc.h" // ExecAssociation
52#include "info.h" // FileInfoProc
53#include "valid.h" // IsExecutable
54#include "srchpath.h" // RunFM2Util
55#include "inis.h" // StartIniEditor
56#include "systemf.h" // ExecOnList
57#include "shadow.h" // OpenObject
58#include "viewer.h" // StartMLEEditor
59#include "newview.h" // StartViewer
60#include "mainwnd.h" // Data declaration(s)
61#include "misc.h" // ExecFile, ViewHelp
62
63// Data definitions
64static PSZ pszSrcFile = __FILE__;
65
66#pragma data_seg(GLOBAL2)
67PCSZ Default = "DEFAULT";
68
69BOOL ShowMultimedia(CHAR * filename)
70{
71
72 static BOOL no_mmos2 = FALSE;
73 BOOL played = FALSE;
74 CHAR loaderror[CCHMAXPATH];
75 HMODULE MMIOModHandle = NULLHANDLE;
76 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
77 //PMMIOGETINFO pMMIOGetInfo = NULL;
78 //PMMIOCLOSE pMMIOClose = NULL;
79 //PMMIOOPEN pMMIOOpen = NULL;
80 //MMIOINFO mmioinfo;
81 //HMMIO hmmio;
82 FOURCC fccStorageSystem = 0;
83 MMFORMATINFO mmFormatInfo;
84 APIRET rc; // rc1;
85 HWND hwnd = HWND_DESKTOP;
86 char *p;
87
88 if (no_mmos2 || !filename || !*filename)
89 return played;
90
91 /* load MMPM/2, if available. */
92 *loaderror = 0;
93 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
94 if (rc) {
95 no_mmos2 = TRUE;
96 return played;
97 }
98 else {
99 if (DosQueryProcAddr(MMIOModHandle,
100 0,
101 "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
102 DosFreeModule(MMIOModHandle);
103 no_mmos2 = TRUE;
104 return played;
105 }
106 /* This code seems to serve no purpose GKY 11-15-09
107 if (DosQueryProcAddr(MMIOModHandle,
108 0,
109 "mmioGetInfo", (PFN *) & pMMIOGetInfo)) {
110 DosFreeModule(MMIOModHandle);
111 no_mmos2 = TRUE;
112 return played;
113 }
114 if (DosQueryProcAddr(MMIOModHandle,
115 0,
116 "mmioClose", (PFN *) & pMMIOClose)) {
117 DosFreeModule(MMIOModHandle);
118 no_mmos2 = TRUE;
119 return played;
120 }
121 if (DosQueryProcAddr(MMIOModHandle,
122 0,
123 "mmioOpen", (PFN *) & pMMIOOpen)) {
124 DosFreeModule(MMIOModHandle);
125 no_mmos2 = TRUE;
126 return played;
127 }*/
128 }
129
130 /* attempt to identify the file using MMPM/2 */
131 //memset( &mmioinfo, '\0', sizeof(MMIOINFO) );
132 /*Eliminate non multimedia files*/
133 /*hmmio = pMMIOOpen(filename,
134 &mmioinfo,
135 MMIO_READ);
136 if (!hmmio) {
137 p = strrchr(filename, '.'); //Added to save mp3, ogg & flac which fail above test
138 if (!p)
139 p = ".";
140 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC) ||
141 !stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG)) {
142 hmmio = pMMIOOpen(filename,
143 &mmioinfo,
144 MMIO_READ | MMIO_NOIDENTIFY);
145 if (!hmmio){
146 DosFreeModule(MMIOModHandle);
147 return played;
148 }
149 }
150 else {
151 DosFreeModule(MMIOModHandle);
152 return played;
153 }
154 }
155 if (!hmmio) {
156 DosFreeModule(MMIOModHandle);
157 return played;
158 }
159 rc1 = pMMIOGetInfo(hmmio, &mmioinfo, 0L);*/
160 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
161 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
162 rc = pMMIOIdentifyFile(filename,
163 0L, //&mmioinfo,
164 &mmFormatInfo,
165 &fccStorageSystem, 0L,
166 MMIO_FORCE_IDENTIFY_FF);
167 /* free module handle */
168 //rc1 = pMMIOClose(hmmio, 0L);
169 DosFreeModule(MMIOModHandle);
170
171 /* if identified and not FOURCC_DOS */
172 p = strrchr(filename, '.'); //Added to save mp3, ogg & flac which fail above test
173 if (!p)
174 p = ".";
175 if (!rc && (mmFormatInfo.fccIOProc != FOURCC_DOS || !stricmp(p, PCSZ_DOTMPG) ||
176 !stricmp(p, PCSZ_DOTMPEG))) { // MPG are identified as FOURCC_DOS
177 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
178 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
179 p = strrchr(filename, '.');
180 if (!p)
181 p = ".";
182 if (!stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG))
183 OpenObject(filename, Default, hwnd); //Image fails to display these
184 else // is an image that can be translated
185 RunFM2Util(PCSZ_IMAGEEXE, filename);
186 played = TRUE;
187 }
188 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
189 /* is a multimedia file (WAV, MID, AVI, etc.) */
190 p = strrchr(filename, '.');
191 if (!p)
192 p = ".";
193 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC))
194 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
195 else
196 RunFM2Util(PCSZ_FM2PLAYEXE, filename);
197 played = TRUE;
198 }
199 }
200
201 return played;
202}
203
204VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
205 SWP * swp, CHAR * filename)
206{
207 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
208 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
209 else if (shiftstate & KC_CTRL)
210 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
211 else if (shiftstate & KC_SHIFT)
212 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
213 else
214 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
215}
216
217VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
218 ULONG flags, CHAR * filename)
219{
220 /*
221 * bitmapped flags:
222 * ---------------
223 * 1 = View directly
224 * 2 = Open WPS default view
225 * 4 = Open WPS settings view
226 * 8 = Edit
227 * 16 = Info
228 * 32 = No view info
229 */
230
231 HWND hwndArc = (HWND) 0;
232 char *p, *dummy[3];
233
234 if (!hwndParent)
235 hwndParent = HWND_DESKTOP;
236
237 if (flags & 32) {
238 flags &= (~16);
239 if (!IsFile(filename)) {
240 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
241 return;
242 }
243 }
244
245 if (flags & 1) /* directly view the file */
246 goto ViewIt;
247
248 if (flags & 2) { /* open default WPS view of file */
249 OpenObject(filename, Default, hwnd);
250 return;
251 }
252
253 if (flags & 4) { /* open WPS settings notebook for file */
254 OpenObject(filename, Settings, hwnd);
255 return;
256 }
257
258 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
259
260 char fullname[CCHMAXPATH];
261
262 if (!IsFullName(filename)) {
263 if (!DosQueryPathInfo(filename,
264 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
265 filename = fullname;
266 }
267 if (IsFullName(filename) &&
268 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
269 if (!IsRoot(filename)) {
270 dummy[0] = filename;
271 dummy[1] = NULL;
272 WinDlgBox(HWND_DESKTOP,
273 HWND_DESKTOP,
274 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
275 }
276 else
277 WinDlgBox(HWND_DESKTOP,
278 HWND_DESKTOP,
279 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
280 }
281 return;
282 }
283
284 if (flags & 8) { /* edit file */
285
286 ULONG type = IDM_EDITTEXT;
287
288 dummy[0] = filename;
289 dummy[1] = NULL;
290 if (TestBinary(filename))
291 type = IDM_EDITBINARY;
292 switch (type) {
293 case IDM_EDITBINARY:
294 if (*bined) {
295 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
296 pszSrcFile, __LINE__);
297 break;
298 }
299 /* else intentional fallthru */
300 case IDM_EDITTEXT:
301 if (*editor)
302 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
303 pszSrcFile, __LINE__);
304 else {
305 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
306 type |= 4;
307 StartMLEEditor(hwndParent, type, filename, hwndFrame);
308 }
309 break;
310 }
311 return;
312 }
313
314 if (ExecAssociation(hwnd, filename) == -1 &&
315 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
316 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
317 strcmp(realappname, FM3Str)) ?
318 HWND_DESKTOP :
319 hwndParent, hwndFrame, filename, 4, NULL);
320 if (!hwndArc) {
321 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
322 p = strrchr(filename, '.');
323 if (!p)
324 p = ".";
325 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
326 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
327 if (!fCheckMM || !stricmp(p, ".DLL") || !ShowMultimedia(filename)) {
328 ViewIt:
329 if (TestBinary(filename)) {
330 if (*binview) {
331 dummy[0] = filename;
332 dummy[1] = NULL;
333 ExecOnList(hwnd,
334 binview,
335 WINDOWED | SEPARATE |
336 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
337 pszSrcFile, __LINE__);
338 }
339 else if (fUseNewViewer) {
340 if (fExternalViewer || strcmp(realappname, FM3Str))
341 hwndParent = HWND_DESKTOP;
342 StartViewer(hwndParent, 5, filename, hwndFrame);
343 }
344 else
345 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
346 }
347 else {
348 if (*viewer) {
349 dummy[0] = filename;
350 dummy[1] = NULL;
351 ExecOnList(hwnd,
352 viewer,
353 WINDOWED | SEPARATE |
354 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
355 pszSrcFile, __LINE__);
356 }
357 else if (fUseNewViewer) {
358 if (fExternalViewer || strcmp(realappname, FM3Str))
359 hwndParent = HWND_DESKTOP;
360 StartViewer(hwndParent, 5, filename, hwndFrame);
361 }
362 else
363 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
364 }
365 }
366 }
367 }
368 }
369 }
370 else {
371 if ((swp &&
372 !fExternalArcboxes &&
373 !strcmp(realappname, FM3Str)) &&
374 !ParentIsDesktop(hwnd, hwndParent))
375 WinSetWindowPos(hwndArc,
376 HWND_TOP,
377 swp->x,
378 swp->y,
379 swp->cx,
380 swp->cy,
381 SWP_MOVE | SWP_SIZE | SWP_SHOW |
382 SWP_ZORDER | SWP_ACTIVATE);
383 }
384 }
385}
386
387#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.