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
RevLine 
[92]1
2/***********************************************************************
3
4 $Id: defview.c 1189 2008-09-10 21:58:57Z 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
[907]36#include "fm3dlg.h"
37#include "arccnrs.h" // StartArcCnr
38#include "errutil.h" // Dos_Error...
[985]39#include "notebook.h" // external viewers
[1164]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
[1189]47#include "systemf.h" // ExecOnList
48#include "shadow.h" // OpenObject
49#include "viewer.h" // StartMLEEditor
50#include "newview.h" // StartViewer
[2]51#include "fm3dll.h"
[1164]52#include "misc.h" // ExecFile, ViewHelp
[2]53
[347]54static PSZ pszSrcFile = __FILE__;
55
[551]56BOOL ShowMultimedia(CHAR * filename)
[92]57{
[2]58
[551]59 static BOOL no_mmos2 = FALSE;
60 BOOL played = FALSE;
61 CHAR loaderror[CCHMAXPATH];
62 HMODULE MMIOModHandle = NULLHANDLE;
[92]63 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
[570]64 PMMIOGETINFO pMMIOGetInfo = NULL;
65 PMMIOCLOSE pMMIOClose = NULL;
66 PMMIOOPEN pMMIOOpen = NULL;
67 MMIOINFO mmioinfo;
[901]68 HMMIO hmmio;
[551]69 FOURCC fccStorageSystem = 0;
70 MMFORMATINFO mmFormatInfo;
[570]71 APIRET rc, rc1;
[689]72 HWND hwnd = HWND_DESKTOP;
[570]73 char *p;
[2]74
[551]75 if (no_mmos2 || !filename || !*filename)
[92]76 return played;
[2]77
78 /* load MMPM/2, if available. */
79 *loaderror = 0;
[551]80 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
[92]81 if (rc) {
82 no_mmos2 = TRUE;
83 return played;
[2]84 }
85 else {
[92]86 if (DosQueryProcAddr(MMIOModHandle,
[551]87 0,
88 "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
[2]89 DosFreeModule(MMIOModHandle);
[92]90 no_mmos2 = TRUE;
91 return played;
[2]92 }
[570]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 }
[2]114 }
115
116 /* attempt to identify the file using MMPM/2 */
[570]117 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
118 memset( &mmioinfo, '\0', sizeof(MMIOINFO) );
119 /*Eliminate non multimedia files*/
120 hmmio = pMMIOOpen(filename,
[901]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
[570]130 if (!p)
[901]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);
[1138]141 //printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
[901]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 }
[570]156
[901]157 rc1 = pMMIOGetInfo(hmmio, &mmioinfo, 0L);
158 // printf("%s %d\n ", __FILE__, __LINE__); fflush(stdout);
[551]159 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
[2]160 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
[92]161 rc = pMMIOIdentifyFile(filename,
[570]162 &mmioinfo,
[92]163 &mmFormatInfo,
[901]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
[2]173 /* free module handle */
[570]174 rc1 = pMMIOClose(hmmio, 0L);
[2]175 DosFreeModule(MMIOModHandle);
176
[92]177 /* if identified and not FOURCC_DOS */
[551]178 if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
[92]179 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
[901]180 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
[887]181 p = strrchr(filename, '.');
182 if (!p)
[901]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;
[2]191 }
[92]192 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
[901]193 /* is a multimedia file (WAV, MID, AVI, etc.) */
194 p = strrchr(filename, '.');
[570]195 if (!p)
[901]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;
[2]204 }
205 }
206
[92]207 return played;
[2]208}
209
[551]210VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
211 SWP * swp, CHAR * filename)
[347]212{
[551]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);
[2]219 else
[551]220 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
[2]221}
222
[551]223VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
224 ULONG flags, CHAR * filename)
[347]225{
[2]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
[551]237 HWND hwndArc = (HWND) 0;
238 char *p, *dummy[3];
[2]239
[551]240 if (!hwndParent)
[2]241 hwndParent = HWND_DESKTOP;
242
[551]243 if (flags & 32) {
[2]244 flags &= (~16);
[551]245 if (!IsFile(filename)) {
[347]246 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
[2]247 return;
248 }
249 }
250
[551]251 if (flags & 1) /* directly view the file */
[2]252 goto ViewIt;
253
[551]254 if (flags & 2) { /* open default WPS view of file */
255 OpenObject(filename, Default, hwnd);
[2]256 return;
257 }
258
[551]259 if (flags & 4) { /* open WPS settings notebook for file */
260 OpenObject(filename, Settings, hwnd);
[2]261 return;
262 }
263
[551]264 if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
[2]265
266 char fullname[CCHMAXPATH];
267
[551]268 if (!IsFullName(filename)) {
269 if (!DosQueryPathInfo(filename,
270 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
[92]271 filename = fullname;
[2]272 }
[551]273 if (IsFullName(filename) &&
274 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
275 if (!IsRoot(filename)) {
[92]276 dummy[0] = filename;
277 dummy[1] = NULL;
278 WinDlgBox(HWND_DESKTOP,
279 HWND_DESKTOP,
[551]280 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
[2]281 }
282 else
[92]283 WinDlgBox(HWND_DESKTOP,
284 HWND_DESKTOP,
[551]285 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
[2]286 }
287 return;
288 }
289
[551]290 if (flags & 8) { /* edit file */
[2]291
292 ULONG type = IDM_EDITTEXT;
293
294 dummy[0] = filename;
295 dummy[1] = NULL;
[551]296 if (TestBinary(filename))
[2]297 type = IDM_EDITBINARY;
[551]298 switch (type) {
299 case IDM_EDITBINARY:
300 if (*bined) {
[901]301 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL,
302 pszSrcFile, __LINE__);
[551]303 break;
304 }
[2]305 /* else intentional fallthru */
[551]306 case IDM_EDITTEXT:
307 if (*editor)
[901]308 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL,
309 pszSrcFile, __LINE__);
[551]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;
[2]316 }
317 return;
318 }
319
[1120]320 if (ExecAssociation(hwnd, filename) == -1 &&
321 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
[2]322 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
[551]323 strcmp(realappname, FM3Str)) ?
[92]324 HWND_DESKTOP :
[551]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)
[92]331 p = ".";
[551]332 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
333 if (stricmp(p, ".HLP") || !ViewHelp(filename)) {
334 ViewIt:
335 if (*viewer) {
[92]336 dummy[0] = filename;
337 dummy[1] = NULL;
338 ExecOnList(hwnd,
339 viewer,
340 WINDOWED | SEPARATE |
[901]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 }
[92]349 else
[551]350 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
[92]351 }
352 }
353 }
[2]354 }
355 }
356 else {
[551]357 if ((swp &&
358 !fExternalArcboxes &&
359 !strcmp(realappname, FM3Str)) &&
360 !ParentIsDesktop(hwnd, hwndParent))
[92]361 WinSetWindowPos(hwndArc,
362 HWND_TOP,
363 swp->x,
364 swp->y,
365 swp->cx,
366 swp->cy,
[551]367 SWP_MOVE | SWP_SIZE | SWP_SHOW |
[92]368 SWP_ZORDER | SWP_ACTIVATE);
[2]369 }
370 }
371}
[793]372
373#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.