source: trunk/dll/defview.c@ 1387

Last change on this file since 1387 was 1387, checked in by Gregg Young, 17 years ago

Comments and cleanup for CS 1386

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: defview.c 1387 2009-01-05 21:12:14Z 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
24***********************************************************************/
25
26#include <string.h>
27#include <ctype.h>
28
29#define INCL_DOS
30#define INCL_WIN
31#define INCL_GPI
32#define INCL_MMIOOS2
33#define INCL_LONGLONG // dircnrs.h
34#include <os2.h>
35#include <os2me.h>
36
37#include "fm3dll.h"
38#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
39#include "mainwnd2.h" // Data declaration(s)
40#include "init.h" // Data declaration(s)
41#include "fm3dlg.h"
42#include "arccnrs.h" // StartArcCnr
43#include "errutil.h" // Dos_Error...
44#include "notebook.h" // external viewers
45#include "defview.h"
46#include "info.h" // DrvInfoProc
47#include "assoc.h" // ExecAssociation
48#include "info.h" // FileInfoProc
49#include "valid.h" // IsExecutable
50#include "srchpath.h" // RunFM2Util
51#include "inis.h" // StartIniEditor
52#include "systemf.h" // ExecOnList
53#include "shadow.h" // OpenObject
54#include "viewer.h" // StartMLEEditor
55#include "newview.h" // StartViewer
56#include "mainwnd.h" // Data declaration(s)
57#include "misc.h" // ExecFile, ViewHelp
58
59// Data definitions
60static PSZ pszSrcFile = __FILE__;
61
62#pragma data_seg(GLOBAL2)
63CHAR *Default;
64
65BOOL ShowMultimedia(CHAR * filename)
66{
67
68 static BOOL no_mmos2 = FALSE;
69 BOOL played = FALSE;
70 CHAR loaderror[CCHMAXPATH];
71 HMODULE MMIOModHandle = NULLHANDLE;
72 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
73 PMMIOGETINFO pMMIOGetInfo = NULL;
74 PMMIOCLOSE pMMIOClose = NULL;
75 PMMIOOPEN pMMIOOpen = NULL;
76 MMIOINFO mmioinfo;
77 HMMIO hmmio;
78 FOURCC fccStorageSystem = 0;
79 MMFORMATINFO mmFormatInfo;
80 APIRET rc, rc1;
81 HWND hwnd = HWND_DESKTOP;
82 char *p;
83
84 if (no_mmos2 || !filename || !*filename)
85 return played;
86
87 /* load MMPM/2, if available. */
88 *loaderror = 0;
89 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
90 if (rc) {
91 no_mmos2 = TRUE;
92 return played;
93 }
94 else {
95 if (DosQueryProcAddr(MMIOModHandle,
96 0,
97 "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
98 DosFreeModule(MMIOModHandle);
99 no_mmos2 = TRUE;
100 return played;
101 }
102 if (DosQueryProcAddr(MMIOModHandle,
103 0,
104 "mmioGetInfo", (PFN *) & pMMIOGetInfo)) {
105 DosFreeModule(MMIOModHandle);
106 no_mmos2 = TRUE;
107 return played;
108 }
109 if (DosQueryProcAddr(MMIOModHandle,
110 0,
111 "mmioClose", (PFN *) & pMMIOClose)) {
112 DosFreeModule(MMIOModHandle);
113 no_mmos2 = TRUE;
114 return played;
115 }
116 if (DosQueryProcAddr(MMIOModHandle,
117 0,
118 "mmioOpen", (PFN *) & pMMIOOpen)) {
119 DosFreeModule(MMIOModHandle);
120 no_mmos2 = TRUE;
121 return played;
122 }
123 }
124
125 /* attempt to identify the file using MMPM/2 */
126 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
127 memset( &mmioinfo, '\0', sizeof(MMIOINFO) );
128 /*Eliminate non multimedia files*/
129 hmmio = pMMIOOpen(filename,
130 &mmioinfo,
131 MMIO_READ);
132#if 0
133 printf("%s %d %d %d %d %d\n",
134 __FILE__, __LINE__,mmioinfo.ulFlags, mmioinfo.ulErrorRet,
135 mmioinfo.pIOProc, mmioinfo.aulInfo); fflush(stdout);
136#endif
137 if (!hmmio) {
138 p = strrchr(filename, '.'); //Added to save mp3, ogg & flac which fail above test
139 if (!p)
140 p = ".";
141 /* printf("%s %d %s\n",
142 __FILE__, __LINE__, p); fflush(stdout);*/
143 if (!stricmp(p, ".OGG") || !stricmp(p, ".MP3") || !stricmp(p, ".FLAC") ||
144 !stricmp(p, ".JPG") || !stricmp(p, ".JPEG")){
145 hmmio = pMMIOOpen(filename,
146 &mmioinfo,
147 MMIO_READ | MMIO_NOIDENTIFY);
148 if (!hmmio){
149 DosFreeModule(MMIOModHandle);
150 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
151 return played;
152 }
153 }
154 else {
155 DosFreeModule(MMIOModHandle);
156 // printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
157 return played;
158 }
159 }
160 if (!hmmio) {
161 DosFreeModule(MMIOModHandle);
162 // printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
163 return played;
164 }
165
166 rc1 = pMMIOGetInfo(hmmio, &mmioinfo, 0L);
167 // printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
168 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
169 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
170 rc = pMMIOIdentifyFile(filename,
171 &mmioinfo,
172 &mmFormatInfo,
173 &fccStorageSystem, 0L,
174 MMIO_FORCE_IDENTIFY_FF);
175#if 0
176 printf("%s %d %d %d %d\n %d %d %d %s\n",
177 __FILE__, __LINE__,mmioinfo.ulFlags,
178 mmioinfo.pIOProc, mmioinfo.aulInfo,
179 mmFormatInfo.fccIOProc, mmFormatInfo.fccIOProc,
180 mmFormatInfo.ulIOProcType, mmFormatInfo.szDefaultFormatExt); fflush(stdout);
181#endif
182 /* free module handle */
183 rc1 = pMMIOClose(hmmio, 0L);
184 DosFreeModule(MMIOModHandle);
185
186 /* if identified and not FOURCC_DOS */
187 if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
188 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
189 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
190 p = strrchr(filename, '.');
191 if (!p)
192 p = ".";
193 /* printf("%s %d %s\n",
194 __FILE__, __LINE__, p); fflush(stdout);*/
195 if (!stricmp(p, ".JPG") || !stricmp(p, ".JPEG"))
196 OpenObject(filename, Default, hwnd); //Image fails to display these
197 else // is an image that can be translated
198 RunFM2Util("IMAGE.EXE", filename);
199 played = TRUE;
200 }
201 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
202 /* is a multimedia file (WAV, MID, AVI, etc.) */
203 p = strrchr(filename, '.');
204 if (!p)
205 p = ".";
206 /* printf("%s %d %s\n",
207 __FILE__, __LINE__, p); fflush(stdout);*/
208 if (!stricmp(p, ".OGG") || !stricmp(p, ".MP3") || !stricmp(p, ".FLAC"))
209 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
210 else
211 RunFM2Util("FM2PLAY.EXE", filename);
212 played = TRUE;
213 }
214 }
215
216 return played;
217}
218
219VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
220 SWP * swp, CHAR * filename)
221{
222 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
223 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
224 else if (shiftstate & KC_CTRL)
225 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
226 else if (shiftstate & KC_SHIFT)
227 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
228 else
229 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
230}
231
232VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
233 ULONG flags, CHAR * filename)
234{
235 /*
236 * bitmapped flags:
237 * ---------------
238 * 1 = View directly
239 * 2 = Open WPS default view
240 * 4 = Open WPS settings view
241 * 8 = Edit
242 * 16 = Info
243 * 32 = No view info
244 */
245
246 HWND hwndArc = (HWND) 0;
247 char *p, *dummy[3];
248
249 if (!hwndParent)
250 hwndParent = HWND_DESKTOP;
251
252 if (flags & 32) {
253 flags &= (~16);
254 if (!IsFile(filename)) {
255 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
256 return;
257 }
258 }
259
260 if (flags & 1) /* directly view the file */
261 goto ViewIt;
262
263 if (flags & 2) { /* open default WPS view of file */
264 OpenObject(filename, Default, hwnd);
265 return;
266 }
267
268 if (flags & 4) { /* open WPS settings notebook for file */
269 OpenObject(filename, Settings, hwnd);
270 return;
271 }
272
273 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
274
275 char fullname[CCHMAXPATH];
276
277 if (!IsFullName(filename)) {
278 if (!DosQueryPathInfo(filename,
279 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
280 filename = fullname;
281 }
282 if (IsFullName(filename) &&
283 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
284 if (!IsRoot(filename)) {
285 dummy[0] = filename;
286 dummy[1] = NULL;
287 WinDlgBox(HWND_DESKTOP,
288 HWND_DESKTOP,
289 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
290 }
291 else
292 WinDlgBox(HWND_DESKTOP,
293 HWND_DESKTOP,
294 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
295 }
296 return;
297 }
298
299 if (flags & 8) { /* edit file */
300
301 ULONG type = IDM_EDITTEXT;
302
303 dummy[0] = filename;
304 dummy[1] = NULL;
305 if (TestBinary(filename))
306 type = IDM_EDITBINARY;
307 switch (type) {
308 case IDM_EDITBINARY:
309 if (*bined) {
310 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
311 pszSrcFile, __LINE__);
312 break;
313 }
314 /* else intentional fallthru */
315 case IDM_EDITTEXT:
316 if (*editor)
317 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
318 pszSrcFile, __LINE__);
319 else {
320 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
321 type |= 4;
322 StartMLEEditor(hwndParent, type, filename, hwndFrame);
323 }
324 break;
325 }
326 return;
327 }
328
329 if (ExecAssociation(hwnd, filename) == -1 &&
330 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
331 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
332 strcmp(realappname, FM3Str)) ?
333 HWND_DESKTOP :
334 hwndParent, hwndFrame, filename, 4, NULL);
335 if (!hwndArc) {
336 if (!fCheckMM || !ShowMultimedia(filename)) {
337 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
338 p = strrchr(filename, '.');
339 if (!p)
340 p = ".";
341 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
342 if (stricmp(p, ".HLP") || !ViewHelp(filename)) {
343 ViewIt:
344 if (TestBinary(filename)) {
345 if (*binview) {
346 dummy[0] = filename;
347 dummy[1] = NULL;
348 ExecOnList(hwnd,
349 binview,
350 WINDOWED | SEPARATE |
351 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
352 pszSrcFile, __LINE__);
353 }
354 else if (fUseNewViewer) {
355 if (fExternalViewer || strcmp(realappname, FM3Str))
356 hwndParent = HWND_DESKTOP;
357 StartViewer(hwndParent, 5, filename, hwndFrame);
358 }
359 else
360 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
361 }
362 else {
363 if (*viewer) {
364 dummy[0] = filename;
365 dummy[1] = NULL;
366 ExecOnList(hwnd,
367 viewer,
368 WINDOWED | SEPARATE |
369 ((fViewChild) ? CHILD : 0), NULL, dummy, NULL,
370 pszSrcFile, __LINE__);
371 }
372 else if (fUseNewViewer) {
373 if (fExternalViewer || strcmp(realappname, FM3Str))
374 hwndParent = HWND_DESKTOP;
375 StartViewer(hwndParent, 5, filename, hwndFrame);
376 }
377 else
378 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
379 }
380 }
381 }
382 }
383 }
384 }
385 else {
386 if ((swp &&
387 !fExternalArcboxes &&
388 !strcmp(realappname, FM3Str)) &&
389 !ParentIsDesktop(hwnd, hwndParent))
390 WinSetWindowPos(hwndArc,
391 HWND_TOP,
392 swp->x,
393 swp->y,
394 swp->cx,
395 swp->cy,
396 SWP_MOVE | SWP_SIZE | SWP_SHOW |
397 SWP_ZORDER | SWP_ACTIVATE);
398 }
399 }
400}
401
402#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.