source: trunk/dll/defview.c@ 1645

Last change on this file since 1645 was 1645, checked in by Gregg Young, 14 years ago

Yet another attempt to get MMPM2 to behave with modern (and not so modern) codecs and IOprocs. Should prevent traps in GBM.DLL even for individuals not using the latest version. The version of JPEGIO.DLL which "fixes" it has not been publicly released.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: defview.c 1645 2011-10-31 02:23:03Z 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 viewer 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 12 Dec 09 GKY Remove code that opened files to check if they were media types
28 It was redundant.
29 12 Dec 09 GKY Pass .WPI files to PM for default handling.
30
31***********************************************************************/
32
33#include <string.h>
34#include <ctype.h>
35
36#define INCL_DOS
37#define INCL_WIN
38#define INCL_GPI
39#define INCL_MMIOOS2
40#define INCL_LONGLONG // dircnrs.h
41#include <os2.h>
42#include <os2me.h>
43
44#include "fm3dll.h"
45#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
46#include "mainwnd2.h" // Data declaration(s)
47#include "init.h" // Data declaration(s)
48#include "fm3dlg.h"
49#include "arccnrs.h" // StartArcCnr
50#include "errutil.h" // Dos_Error...
51#include "notebook.h" // external viewers
52#include "defview.h"
53#include "info.h" // DrvInfoProc
54#include "assoc.h" // ExecAssociation
55#include "info.h" // FileInfoProc
56#include "valid.h" // IsExecutable
57#include "srchpath.h" // RunFM2Util
58#include "inis.h" // StartIniEditor
59#include "systemf.h" // ExecOnList
60#include "shadow.h" // OpenObject
61#include "viewer.h" // StartMLEEditor
62#include "newview.h" // StartViewer
63#include "mainwnd.h" // Data declaration(s)
64#include "misc.h" // ExecFile, ViewHelp
65
66// Data definitions
67static PSZ pszSrcFile = __FILE__;
68
69#pragma data_seg(GLOBAL2)
70PCSZ Default = "DEFAULT";
71
72/**
73 * ShowMultimedia uses MMOS2 if available to check if files are media types
74 * It will play them as media if they are. There are several work arounds
75 * to handle newer media types which are misidentified or which don't play
76 * in our default player/viewer
77 */
78
79BOOL ShowMultimedia(CHAR * filename)
80{
81
82 static BOOL no_mmos2 = FALSE;
83 BOOL played = FALSE;
84 CHAR loaderror[CCHMAXPATH];
85 HMODULE MMIOModHandle = NULLHANDLE;
86 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
87 FOURCC fccStorageSystem = 0;
88 MMFORMATINFO mmFormatInfo;
89 APIRET rc;
90 HWND hwnd = HWND_DESKTOP;
91 char *p;
92
93 if (no_mmos2 || !filename || !*filename)
94 return played;
95
96 //load MMPM/2, if available.
97 *loaderror = 0;
98 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
99 if (rc) {
100 no_mmos2 = TRUE;
101 return played;
102 }
103 else {
104 ULONG cmp;
105 CHAR cmps[5];
106
107 p = strrchr(filename, '.');
108 if (p) {
109 cmps[0] = '.';
110 cmps[1] = toupper(p[1]);
111 cmps[2] = toupper(p[2]);
112 cmps[3] = toupper(p[3]);
113 if (p[4]) {
114 cmps[4] = toupper(p[4]);
115 cmps[5] = 0;
116 }
117 else
118 cmps[4] = 0;
119
120 cmp = *(ULONG *) cmps;
121 if (cmp == *(ULONG *) PCSZ_DOTBMP || cmp == *(ULONG *) PCSZ_DOTJPEG ||
122 cmp == *(ULONG *) PCSZ_DOTMP3 || cmp == *(ULONG *) PCSZ_DOTJPG ||
123 cmp == *(ULONG *) PCSZ_DOTMPEG || cmp == *(ULONG *) PCSZ_DOTFLAC ||
124 cmp == *(ULONG *) ".TIF" || cmp == *(ULONG *) ".PCX" ||
125 cmp == *(ULONG *) ".TGA" || cmp == *(ULONG *) ".MOV" ||
126 cmp == *(ULONG *) ".PNG" || cmp == *(ULONG *) ".AVI" ||
127 cmp == *(ULONG *) ".OGG" || cmp == *(ULONG *) ".MID" ||
128 cmp == *(ULONG *) ".PCD" || cmp == *(ULONG *) ".FLC" ||
129 cmp == *(ULONG *) ".GIF" || cmp == *(ULONG *) ".FLA" ||
130 cmp == *(ULONG *) ".IFF" || cmp == *(ULONG *) ".SND" ||
131 cmp == *(ULONG *) "._AU" || cmp == *(ULONG *) ".AIF" ||
132 cmp == *(ULONG *) ".VID" || cmp == *(ULONG *) ".WAV" ||
133 cmp == *(ULONG *) "._IM" || cmp == *(ULONG *) ".RDI" ||
134 cmp == *(ULONG *) PCSZ_DOTMPG) {
135 if (DosQueryProcAddr(MMIOModHandle, 0,
136 "mmioIdentifyFile", (PFN *) &pMMIOIdentifyFile)) {
137 DosFreeModule(MMIOModHandle);
138 no_mmos2 = TRUE;
139 return played;
140 }
141 }
142 else
143 return played;
144 }
145 }
146 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
147 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
148 rc = pMMIOIdentifyFile(filename, 0L, &mmFormatInfo,
149 &fccStorageSystem, 0L,
150 MMIO_FORCE_IDENTIFY_FF);
151 DosFreeModule(MMIOModHandle);
152 p = strrchr(filename, '.');
153 if (!p)
154 p = ".";
155 /* if identified and not FOURCC_DOS MPEGs are misidentified as DOS*/
156 //DbgMsg(pszSrcFile, __LINE__, "FOUCC %x %s %i", mmFormatInfo.fccIOProc,
157 // mmFormatInfo.szDefaultFormatExt, mmFormatInfo.ulMediaType);
158 if (!rc && (mmFormatInfo.fccIOProc != FOURCC_DOS ||
159 !stricmp(p, PCSZ_DOTMPG) || !stricmp(p, PCSZ_DOTMPEG))) {
160 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
161 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
162 //if (!stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG))
163 OpenObject(filename, Default, hwnd); //Image fails to display these
164 // else // is an image that can be translated
165 // RunFM2Util(PCSZ_IMAGEEXE, filename); // 29 Oct 11 GKY Image.exe doesn't handle multilayer bitmaps or jpgs
166 played = TRUE;
167 }
168 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
169 /* is a multimedia file (WAV, MID, AVI, etc.) */
170 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC))
171 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
172 else
173 RunFM2Util(PCSZ_FM2PLAYEXE, filename);
174 played = TRUE;
175 }
176 }
177
178 return played;
179}
180
181VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
182 SWP * swp, CHAR * filename)
183{
184 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
185 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
186 else if (shiftstate & KC_CTRL)
187 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
188 else if (shiftstate & KC_SHIFT)
189 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
190 else
191 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
192}
193
194/**
195 * DefaultView runs multiple checks for opening files including checking
196 * for associations, archives, executables, help, ini, warpin, multimedia and
197 * viewing as binary or text.
198 */
199
200VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
201 ULONG flags, CHAR * filename)
202{
203 /*
204 * bitmapped flags:
205 * ---------------
206 * 1 = View directly
207 * 2 = Open WPS default view
208 * 4 = Open WPS settings view
209 * 8 = Edit
210 * 16 = Info
211 * 32 = No view info
212 */
213
214 HWND hwndArc = (HWND) 0;
215 char *p, *dummy[3];
216
217 if (!hwndParent)
218 hwndParent = HWND_DESKTOP;
219
220 if (flags & 32) {
221 flags &= (~16);
222 if (!IsFile(filename)) {
223 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
224 return;
225 }
226 }
227
228 if (flags & 1) /* directly view the file */
229 goto ViewIt;
230
231 if (flags & 2) { /* open default WPS view of file */
232 OpenObject(filename, Default, hwnd);
233 return;
234 }
235
236 if (flags & 4) { /* open WPS settings notebook for file */
237 OpenObject(filename, Settings, hwnd);
238 return;
239 }
240
241 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
242
243 char fullname[CCHMAXPATH];
244
245 if (!IsFullName(filename)) {
246 if (!DosQueryPathInfo(filename,
247 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
248 filename = fullname;
249 }
250 if (IsFullName(filename) &&
251 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
252 if (!IsRoot(filename)) {
253 dummy[0] = filename;
254 dummy[1] = NULL;
255 WinDlgBox(HWND_DESKTOP,
256 HWND_DESKTOP,
257 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
258 }
259 else
260 WinDlgBox(HWND_DESKTOP,
261 HWND_DESKTOP,
262 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
263 }
264 return;
265 }
266
267 if (flags & 8) { /* edit file */
268
269 ULONG type = IDM_EDITTEXT;
270
271 dummy[0] = filename;
272 dummy[1] = NULL;
273 if (TestBinary(filename))
274 type = IDM_EDITBINARY;
275 switch (type) {
276 case IDM_EDITBINARY:
277 if (*bined) {
278 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
279 pszSrcFile, __LINE__);
280 break;
281 }
282 /* else intentional fallthru */
283 case IDM_EDITTEXT:
284 if (*editor)
285 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
286 pszSrcFile, __LINE__);
287 else {
288 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
289 type |= 4;
290 StartMLEEditor(hwndParent, type, filename, hwndFrame);
291 }
292 break;
293 }
294 return;
295 }
296
297 if (ExecAssociation(hwnd, filename) == -1 &&
298 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
299 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
300 strcmp(realappname, FM3Str)) ?
301 HWND_DESKTOP :
302 hwndParent, hwndFrame, filename, 4, NULL);
303 if (!hwndArc) {
304 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
305 p = strrchr(filename, '.');
306 if (!p)
307 p = ".";
308 if (!stricmp(p, ".WPI")) {
309 OpenObject(filename, Default, hwnd);
310 return;
311 }
312 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
313 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
314 ViewIt:
315 if (TestBinary(filename)) {
316 if (!fCheckMM || !ShowMultimedia(filename)) {
317 if (*binview) {
318 dummy[0] = filename;
319 dummy[1] = NULL;
320 ExecOnList(hwnd,
321 binview,
322 WINDOWED | SEPARATE |
323 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
324 pszSrcFile, __LINE__);
325 }
326 else if (fUseNewViewer) {
327 if (fExternalViewer || strcmp(realappname, FM3Str))
328 hwndParent = HWND_DESKTOP;
329 StartViewer(hwndParent, 5, filename, hwndFrame);
330 }
331 else
332 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
333 }
334 }
335 else {
336 if (*viewer) {
337 dummy[0] = filename;
338 dummy[1] = NULL;
339 ExecOnList(hwnd,
340 viewer,
341 WINDOWED | SEPARATE |
342 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
343 pszSrcFile, __LINE__);
344 }
345 else if (fUseNewViewer) {
346 if (fExternalViewer || strcmp(realappname, FM3Str))
347 hwndParent = HWND_DESKTOP;
348 StartViewer(hwndParent, 5, filename, hwndFrame);
349 }
350 else
351 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
352 }
353 //}
354 }
355 }
356 }
357 }
358 else {
359 if ((swp &&
360 !fExternalArcboxes &&
361 !strcmp(realappname, FM3Str)) &&
362 !ParentIsDesktop(hwnd, hwndParent))
363 WinSetWindowPos(hwndArc,
364 HWND_TOP,
365 swp->x,
366 swp->y,
367 swp->cx,
368 swp->cy,
369 SWP_MOVE | SWP_SIZE | SWP_SHOW |
370 SWP_ZORDER | SWP_ACTIVATE);
371 }
372 }
373}
374
375#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.