source: trunk/dll/defview.c@ 1206

Last change on this file since 1206 was 1206, checked in by John Small, 17 years ago

Ticket 187: Move datadevlarations/definitions out of fm3dll.h

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