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
RevLine 
[92]1
2/***********************************************************************
3
4 $Id: defview.c 1387 2009-01-05 21:12:14Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
[907]7 Copyright (c) 2003, 2008 Steven H.Levine
[92]8
[347]9 Default file viewer
[92]10
[347]11 20 Nov 03 SHL ShowMultimedia: try to convince fmplay to not play exes (Gregg Young)
12 14 Jul 06 SHL Use Runtime_Error
[570]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
[627]15 21 Apr 07 GKY Find FM2Utils by path or utils directory
[689]16 09 Jun 07 SHL ShowMultimedia: Initialize hwnd so that OpenObject might work
[793]17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[888]18 20 Dec 07 GKY Open jpg files with OS2 object default since image.exe fails
[985]19 29 Feb 08 GKY Refactor global command line variables to notebook.h
[1120]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)
[1387]22 05 Jan 09 GKY Use TestBinary so that text veiwer isn't used for hex files by default
[92]23
24***********************************************************************/
25
[907]26#include <string.h>
27#include <ctype.h>
28
[2]29#define INCL_DOS
30#define INCL_WIN
31#define INCL_GPI
32#define INCL_MMIOOS2
[907]33#define INCL_LONGLONG // dircnrs.h
[2]34#include <os2.h>
35#include <os2me.h>
[347]36
[1206]37#include "fm3dll.h"
[1222]38#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1206]39#include "mainwnd2.h" // Data declaration(s)
40#include "init.h" // Data declaration(s)
[907]41#include "fm3dlg.h"
42#include "arccnrs.h" // StartArcCnr
43#include "errutil.h" // Dos_Error...
[985]44#include "notebook.h" // external viewers
[1164]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
[1189]52#include "systemf.h" // ExecOnList
53#include "shadow.h" // OpenObject
54#include "viewer.h" // StartMLEEditor
55#include "newview.h" // StartViewer
[1206]56#include "mainwnd.h" // Data declaration(s)
[1164]57#include "misc.h" // ExecFile, ViewHelp
[2]58
[1206]59// Data definitions
[347]60static PSZ pszSrcFile = __FILE__;
61
[1206]62#pragma data_seg(GLOBAL2)
63CHAR *Default;
64
[551]65BOOL ShowMultimedia(CHAR * filename)
[92]66{
[2]67
[551]68 static BOOL no_mmos2 = FALSE;
69 BOOL played = FALSE;
70 CHAR loaderror[CCHMAXPATH];
71 HMODULE MMIOModHandle = NULLHANDLE;
[92]72 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
[570]73 PMMIOGETINFO pMMIOGetInfo = NULL;
74 PMMIOCLOSE pMMIOClose = NULL;
75 PMMIOOPEN pMMIOOpen = NULL;
76 MMIOINFO mmioinfo;
[901]77 HMMIO hmmio;
[551]78 FOURCC fccStorageSystem = 0;
79 MMFORMATINFO mmFormatInfo;
[570]80 APIRET rc, rc1;
[689]81 HWND hwnd = HWND_DESKTOP;
[570]82 char *p;
[2]83
[551]84 if (no_mmos2 || !filename || !*filename)
[92]85 return played;
[2]86
87 /* load MMPM/2, if available. */
88 *loaderror = 0;
[551]89 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
[92]90 if (rc) {
91 no_mmos2 = TRUE;
92 return played;
[2]93 }
94 else {
[92]95 if (DosQueryProcAddr(MMIOModHandle,
[551]96 0,
97 "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
[2]98 DosFreeModule(MMIOModHandle);
[92]99 no_mmos2 = TRUE;
100 return played;
[2]101 }
[570]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 }
[2]123 }
124
125 /* attempt to identify the file using MMPM/2 */
[570]126 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
127 memset( &mmioinfo, '\0', sizeof(MMIOINFO) );
128 /*Eliminate non multimedia files*/
129 hmmio = pMMIOOpen(filename,
[901]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
[570]139 if (!p)
[901]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);
[1138]150 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
[901]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 }
[570]165
[901]166 rc1 = pMMIOGetInfo(hmmio, &mmioinfo, 0L);
167 // printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
[551]168 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
[2]169 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
[92]170 rc = pMMIOIdentifyFile(filename,
[570]171 &mmioinfo,
[92]172 &mmFormatInfo,
[901]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
[2]182 /* free module handle */
[570]183 rc1 = pMMIOClose(hmmio, 0L);
[2]184 DosFreeModule(MMIOModHandle);
185
[92]186 /* if identified and not FOURCC_DOS */
[551]187 if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
[92]188 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
[901]189 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
[887]190 p = strrchr(filename, '.');
191 if (!p)
[901]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;
[2]200 }
[92]201 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
[901]202 /* is a multimedia file (WAV, MID, AVI, etc.) */
203 p = strrchr(filename, '.');
[570]204 if (!p)
[901]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;
[2]213 }
214 }
215
[92]216 return played;
[2]217}
218
[551]219VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
220 SWP * swp, CHAR * filename)
[347]221{
[551]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);
[2]228 else
[551]229 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
[2]230}
231
[551]232VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
233 ULONG flags, CHAR * filename)
[347]234{
[2]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
[551]246 HWND hwndArc = (HWND) 0;
247 char *p, *dummy[3];
[2]248
[551]249 if (!hwndParent)
[2]250 hwndParent = HWND_DESKTOP;
251
[551]252 if (flags & 32) {
[2]253 flags &= (~16);
[551]254 if (!IsFile(filename)) {
[347]255 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
[2]256 return;
257 }
258 }
259
[551]260 if (flags & 1) /* directly view the file */
[2]261 goto ViewIt;
262
[551]263 if (flags & 2) { /* open default WPS view of file */
264 OpenObject(filename, Default, hwnd);
[2]265 return;
266 }
267
[551]268 if (flags & 4) { /* open WPS settings notebook for file */
269 OpenObject(filename, Settings, hwnd);
[2]270 return;
271 }
272
[551]273 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
[2]274
275 char fullname[CCHMAXPATH];
276
[551]277 if (!IsFullName(filename)) {
278 if (!DosQueryPathInfo(filename,
279 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
[92]280 filename = fullname;
[2]281 }
[551]282 if (IsFullName(filename) &&
283 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
284 if (!IsRoot(filename)) {
[92]285 dummy[0] = filename;
286 dummy[1] = NULL;
287 WinDlgBox(HWND_DESKTOP,
288 HWND_DESKTOP,
[551]289 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
[2]290 }
291 else
[92]292 WinDlgBox(HWND_DESKTOP,
293 HWND_DESKTOP,
[551]294 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
[2]295 }
296 return;
297 }
298
[551]299 if (flags & 8) { /* edit file */
[2]300
301 ULONG type = IDM_EDITTEXT;
302
303 dummy[0] = filename;
304 dummy[1] = NULL;
[551]305 if (TestBinary(filename))
[2]306 type = IDM_EDITBINARY;
[551]307 switch (type) {
308 case IDM_EDITBINARY:
309 if (*bined) {
[901]310 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
311 pszSrcFile, __LINE__);
[551]312 break;
313 }
[2]314 /* else intentional fallthru */
[551]315 case IDM_EDITTEXT:
316 if (*editor)
[901]317 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
318 pszSrcFile, __LINE__);
[551]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;
[2]325 }
326 return;
327 }
328
[1120]329 if (ExecAssociation(hwnd, filename) == -1 &&
330 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
[2]331 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
[551]332 strcmp(realappname, FM3Str)) ?
[92]333 HWND_DESKTOP :
[551]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)
[92]340 p = ".";
[551]341 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
342 if (stricmp(p, ".HLP") || !ViewHelp(filename)) {
[1386]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 }
[92]380 }
381 }
382 }
[2]383 }
384 }
385 else {
[551]386 if ((swp &&
387 !fExternalArcboxes &&
388 !strcmp(realappname, FM3Str)) &&
389 !ParentIsDesktop(hwnd, hwndParent))
[92]390 WinSetWindowPos(hwndArc,
391 HWND_TOP,
392 swp->x,
393 swp->y,
394 swp->cx,
395 swp->cy,
[551]396 SWP_MOVE | SWP_SIZE | SWP_SHOW |
[92]397 SWP_ZORDER | SWP_ACTIVATE);
[2]398 }
399 }
400}
[793]401
402#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.