source: trunk/dll/defview.c@ 1189

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

Ticket 187: Draft 2: Move remaining function declarations

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