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
RevLine 
[92]1
2/***********************************************************************
3
4 $Id: defview.c 1206 2008-09-13 06:48:55Z jbs $
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)
[92]22
23***********************************************************************/
24
[907]25#include <string.h>
26#include <ctype.h>
27
[2]28#define INCL_DOS
29#define INCL_WIN
30#define INCL_GPI
31#define INCL_MMIOOS2
[907]32#define INCL_LONGLONG // dircnrs.h
[2]33#include <os2.h>
34#include <os2me.h>
[347]35
[1206]36#include "fm3dll.h"
37#include "mainwnd2.h" // Data declaration(s)
38#include "init.h" // Data declaration(s)
[907]39#include "fm3dlg.h"
40#include "arccnrs.h" // StartArcCnr
41#include "errutil.h" // Dos_Error...
[985]42#include "notebook.h" // external viewers
[1164]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
[1189]50#include "systemf.h" // ExecOnList
51#include "shadow.h" // OpenObject
52#include "viewer.h" // StartMLEEditor
53#include "newview.h" // StartViewer
[1206]54#include "mainwnd.h" // Data declaration(s)
[1164]55#include "misc.h" // ExecFile, ViewHelp
[2]56
[1206]57// Data definitions
[347]58static PSZ pszSrcFile = __FILE__;
59
[1206]60#pragma data_seg(GLOBAL2)
61CHAR *Default;
62
[551]63BOOL ShowMultimedia(CHAR * filename)
[92]64{
[2]65
[551]66 static BOOL no_mmos2 = FALSE;
67 BOOL played = FALSE;
68 CHAR loaderror[CCHMAXPATH];
69 HMODULE MMIOModHandle = NULLHANDLE;
[92]70 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
[570]71 PMMIOGETINFO pMMIOGetInfo = NULL;
72 PMMIOCLOSE pMMIOClose = NULL;
73 PMMIOOPEN pMMIOOpen = NULL;
74 MMIOINFO mmioinfo;
[901]75 HMMIO hmmio;
[551]76 FOURCC fccStorageSystem = 0;
77 MMFORMATINFO mmFormatInfo;
[570]78 APIRET rc, rc1;
[689]79 HWND hwnd = HWND_DESKTOP;
[570]80 char *p;
[2]81
[551]82 if (no_mmos2 || !filename || !*filename)
[92]83 return played;
[2]84
85 /* load MMPM/2, if available. */
86 *loaderror = 0;
[551]87 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
[92]88 if (rc) {
89 no_mmos2 = TRUE;
90 return played;
[2]91 }
92 else {
[92]93 if (DosQueryProcAddr(MMIOModHandle,
[551]94 0,
95 "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
[2]96 DosFreeModule(MMIOModHandle);
[92]97 no_mmos2 = TRUE;
98 return played;
[2]99 }
[570]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 }
[2]121 }
122
123 /* attempt to identify the file using MMPM/2 */
[570]124 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
125 memset( &mmioinfo, '\0', sizeof(MMIOINFO) );
126 /*Eliminate non multimedia files*/
127 hmmio = pMMIOOpen(filename,
[901]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
[570]137 if (!p)
[901]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);
[1138]148 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
[901]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 }
[570]163
[901]164 rc1 = pMMIOGetInfo(hmmio, &mmioinfo, 0L);
165 // printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
[551]166 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
[2]167 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
[92]168 rc = pMMIOIdentifyFile(filename,
[570]169 &mmioinfo,
[92]170 &mmFormatInfo,
[901]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
[2]180 /* free module handle */
[570]181 rc1 = pMMIOClose(hmmio, 0L);
[2]182 DosFreeModule(MMIOModHandle);
183
[92]184 /* if identified and not FOURCC_DOS */
[551]185 if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
[92]186 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
[901]187 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
[887]188 p = strrchr(filename, '.');
189 if (!p)
[901]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;
[2]198 }
[92]199 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
[901]200 /* is a multimedia file (WAV, MID, AVI, etc.) */
201 p = strrchr(filename, '.');
[570]202 if (!p)
[901]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;
[2]211 }
212 }
213
[92]214 return played;
[2]215}
216
[551]217VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
218 SWP * swp, CHAR * filename)
[347]219{
[551]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);
[2]226 else
[551]227 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
[2]228}
229
[551]230VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
231 ULONG flags, CHAR * filename)
[347]232{
[2]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
[551]244 HWND hwndArc = (HWND) 0;
245 char *p, *dummy[3];
[2]246
[551]247 if (!hwndParent)
[2]248 hwndParent = HWND_DESKTOP;
249
[551]250 if (flags & 32) {
[2]251 flags &= (~16);
[551]252 if (!IsFile(filename)) {
[347]253 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
[2]254 return;
255 }
256 }
257
[551]258 if (flags & 1) /* directly view the file */
[2]259 goto ViewIt;
260
[551]261 if (flags & 2) { /* open default WPS view of file */
262 OpenObject(filename, Default, hwnd);
[2]263 return;
264 }
265
[551]266 if (flags & 4) { /* open WPS settings notebook for file */
267 OpenObject(filename, Settings, hwnd);
[2]268 return;
269 }
270
[551]271 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
[2]272
273 char fullname[CCHMAXPATH];
274
[551]275 if (!IsFullName(filename)) {
276 if (!DosQueryPathInfo(filename,
277 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
[92]278 filename = fullname;
[2]279 }
[551]280 if (IsFullName(filename) &&
281 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
282 if (!IsRoot(filename)) {
[92]283 dummy[0] = filename;
284 dummy[1] = NULL;
285 WinDlgBox(HWND_DESKTOP,
286 HWND_DESKTOP,
[551]287 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
[2]288 }
289 else
[92]290 WinDlgBox(HWND_DESKTOP,
291 HWND_DESKTOP,
[551]292 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
[2]293 }
294 return;
295 }
296
[551]297 if (flags & 8) { /* edit file */
[2]298
299 ULONG type = IDM_EDITTEXT;
300
301 dummy[0] = filename;
302 dummy[1] = NULL;
[551]303 if (TestBinary(filename))
[2]304 type = IDM_EDITBINARY;
[551]305 switch (type) {
306 case IDM_EDITBINARY:
307 if (*bined) {
[901]308 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
309 pszSrcFile, __LINE__);
[551]310 break;
311 }
[2]312 /* else intentional fallthru */
[551]313 case IDM_EDITTEXT:
314 if (*editor)
[901]315 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
316 pszSrcFile, __LINE__);
[551]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;
[2]323 }
324 return;
325 }
326
[1120]327 if (ExecAssociation(hwnd, filename) == -1 &&
328 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
[2]329 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
[551]330 strcmp(realappname, FM3Str)) ?
[92]331 HWND_DESKTOP :
[551]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)
[92]338 p = ".";
[551]339 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
340 if (stricmp(p, ".HLP") || !ViewHelp(filename)) {
341 ViewIt:
342 if (*viewer) {
[92]343 dummy[0] = filename;
344 dummy[1] = NULL;
345 ExecOnList(hwnd,
346 viewer,
347 WINDOWED | SEPARATE |
[901]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 }
[92]356 else
[551]357 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
[92]358 }
359 }
360 }
[2]361 }
362 }
363 else {
[551]364 if ((swp &&
365 !fExternalArcboxes &&
366 !strcmp(realappname, FM3Str)) &&
367 !ParentIsDesktop(hwnd, hwndParent))
[92]368 WinSetWindowPos(hwndArc,
369 HWND_TOP,
370 swp->x,
371 swp->y,
372 swp->cx,
373 swp->cy,
[551]374 SWP_MOVE | SWP_SIZE | SWP_SHOW |
[92]375 SWP_ZORDER | SWP_ACTIVATE);
[2]376 }
377 }
378}
[793]379
380#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.