source: trunk/dll/defview.c@ 1656

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

Completely rework ShowMultimedia to only test and try to open files with known multimedia extensions. This fixes some traps in GBM.DLL and PMCTLS.DLL; mmioIdentifyFile appears to pretty much be broken.

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