source: trunk/dll/defview.c@ 1386

Last change on this file since 1386 was 1386, checked in by Gregg Young, 17 years ago

Fix IsBinary so it doesn't think codes like \xda are negative. Which fixes problem with texted opened as hex. Also use test binary in default view code so hex veiwer is used when appropriate. Tickets 326, 338

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