source: trunk/dll/defview.c@ 1773

Last change on this file since 1773 was 1773, checked in by Gregg Young, 11 years ago

Remove bzip check added in CS [1690] Ticket [537]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
RevLine 
[92]1
2/***********************************************************************
3
4 $Id: defview.c 1773 2014-04-06 17:28:47Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
[1656]7 Copyright (c) 2003, 2012 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)
[1484]22 05 Jan 09 GKY Use TestBinary so that text viewer isn't used for hex files by default
[1402]23 08 Mar 09 GKY Additional strings move to PCSZs
[1479]24 15 Nov 09 GKY Add check for attempt to open zero byte file and reorder file type checks
25 to place exes before MMPM check (avoids MMPM trying to play them)
26 15 Nov 09 GKY Work around MMIO's falure to identify MPG files as media
[1481]27 12 Dec 09 GKY Remove code that opened files to check if they were media types
28 It was redundant.
29 12 Dec 09 GKY Pass .WPI files to PM for default handling.
[1656]30 02 Jan 12 GKY Completely rework ShowMultimedia to only test and try to open files with known multimedia extensions
31 This fixes some traps in GBM.DLL and PMCTLS.DLL; mmioIdentifyFile appears to pretty much be broken.
[92]32
33***********************************************************************/
34
[907]35#include <string.h>
36#include <ctype.h>
37
[2]38#define INCL_DOS
39#define INCL_WIN
40#define INCL_GPI
41#define INCL_MMIOOS2
[907]42#define INCL_LONGLONG // dircnrs.h
[2]43#include <os2.h>
44#include <os2me.h>
[347]45
[1206]46#include "fm3dll.h"
[1222]47#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1206]48#include "mainwnd2.h" // Data declaration(s)
49#include "init.h" // Data declaration(s)
[907]50#include "fm3dlg.h"
51#include "arccnrs.h" // StartArcCnr
52#include "errutil.h" // Dos_Error...
[985]53#include "notebook.h" // external viewers
[1164]54#include "defview.h"
55#include "info.h" // DrvInfoProc
56#include "assoc.h" // ExecAssociation
57#include "info.h" // FileInfoProc
58#include "valid.h" // IsExecutable
59#include "srchpath.h" // RunFM2Util
60#include "inis.h" // StartIniEditor
[1189]61#include "systemf.h" // ExecOnList
62#include "shadow.h" // OpenObject
63#include "viewer.h" // StartMLEEditor
64#include "newview.h" // StartViewer
[1206]65#include "mainwnd.h" // Data declaration(s)
[1164]66#include "misc.h" // ExecFile, ViewHelp
[2]67
[1206]68// Data definitions
[347]69static PSZ pszSrcFile = __FILE__;
70
[1206]71#pragma data_seg(GLOBAL2)
[1402]72PCSZ Default = "DEFAULT";
[1206]73
[1481]74/**
75 * ShowMultimedia uses MMOS2 if available to check if files are media types
76 * It will play them as media if they are. There are several work arounds
77 * to handle newer media types which are misidentified or which don't play
78 * in our default player/viewer
79 */
80
[551]81BOOL ShowMultimedia(CHAR * filename)
[92]82{
[2]83
[551]84 static BOOL no_mmos2 = FALSE;
85 BOOL played = FALSE;
86 CHAR loaderror[CCHMAXPATH];
87 HMODULE MMIOModHandle = NULLHANDLE;
[92]88 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
[551]89 FOURCC fccStorageSystem = 0;
90 MMFORMATINFO mmFormatInfo;
[1481]91 APIRET rc;
[689]92 HWND hwnd = HWND_DESKTOP;
[570]93 char *p;
[2]94
[551]95 if (no_mmos2 || !filename || !*filename)
[92]96 return played;
[2]97
[1481]98 //load MMPM/2, if available.
[2]99 *loaderror = 0;
[551]100 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
[92]101 if (rc) {
102 no_mmos2 = TRUE;
103 return played;
[2]104 }
105 else {
[1645]106 ULONG cmp;
107 CHAR cmps[5];
108
109 p = strrchr(filename, '.');
110 if (p) {
111 cmps[0] = '.';
112 cmps[1] = toupper(p[1]);
113 cmps[2] = toupper(p[2]);
114 cmps[3] = toupper(p[3]);
115 if (p[4]) {
116 cmps[4] = toupper(p[4]);
117 cmps[5] = 0;
118 }
119 else
120 cmps[4] = 0;
121
122 cmp = *(ULONG *) cmps;
123 if (cmp == *(ULONG *) PCSZ_DOTBMP || cmp == *(ULONG *) PCSZ_DOTJPEG ||
124 cmp == *(ULONG *) PCSZ_DOTMP3 || cmp == *(ULONG *) PCSZ_DOTJPG ||
125 cmp == *(ULONG *) PCSZ_DOTMPEG || cmp == *(ULONG *) PCSZ_DOTFLAC ||
126 cmp == *(ULONG *) ".TIF" || cmp == *(ULONG *) ".PCX" ||
127 cmp == *(ULONG *) ".TGA" || cmp == *(ULONG *) ".MOV" ||
128 cmp == *(ULONG *) ".PNG" || cmp == *(ULONG *) ".AVI" ||
129 cmp == *(ULONG *) ".OGG" || cmp == *(ULONG *) ".MID" ||
130 cmp == *(ULONG *) ".PCD" || cmp == *(ULONG *) ".FLC" ||
131 cmp == *(ULONG *) ".GIF" || cmp == *(ULONG *) ".FLA" ||
132 cmp == *(ULONG *) ".IFF" || cmp == *(ULONG *) ".SND" ||
133 cmp == *(ULONG *) "._AU" || cmp == *(ULONG *) ".AIF" ||
134 cmp == *(ULONG *) ".VID" || cmp == *(ULONG *) ".WAV" ||
135 cmp == *(ULONG *) "._IM" || cmp == *(ULONG *) ".RDI" ||
136 cmp == *(ULONG *) PCSZ_DOTMPG) {
137 if (DosQueryProcAddr(MMIOModHandle, 0,
138 "mmioIdentifyFile", (PFN *) &pMMIOIdentifyFile)) {
139 DosFreeModule(MMIOModHandle);
140 no_mmos2 = TRUE;
141 return played;
142 }
143 }
144 else
145 return played;
[2]146 }
[1656]147 else
148 return played;
[2]149 }
[551]150 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
[2]151 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
[1481]152 rc = pMMIOIdentifyFile(filename, 0L, &mmFormatInfo,
[901]153 &fccStorageSystem, 0L,
154 MMIO_FORCE_IDENTIFY_FF);
[2]155 DosFreeModule(MMIOModHandle);
[1656]156
157 // if identified and not FOURCC_DOS MPEGs are misidentified as DOS
[1481]158 //DbgMsg(pszSrcFile, __LINE__, "FOUCC %x %s %i", mmFormatInfo.fccIOProc,
159 // mmFormatInfo.szDefaultFormatExt, mmFormatInfo.ulMediaType);
160 if (!rc && (mmFormatInfo.fccIOProc != FOURCC_DOS ||
161 !stricmp(p, PCSZ_DOTMPG) || !stricmp(p, PCSZ_DOTMPEG))) {
[92]162 if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
[901]163 (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
[1645]164 //if (!stricmp(p, PCSZ_DOTJPG) || !stricmp(p, PCSZ_DOTJPEG))
[1481]165 OpenObject(filename, Default, hwnd); //Image fails to display these
[1645]166 // else // is an image that can be translated
167 // RunFM2Util(PCSZ_IMAGEEXE, filename); // 29 Oct 11 GKY Image.exe doesn't handle multilayer bitmaps or jpgs
[1481]168 played = TRUE;
[2]169 }
[92]170 else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
[1656]171 // is a multimedia file (WAV, MID, AVI, etc.)
[1481]172 if (!stricmp(p, PCSZ_DOTOGG) || !stricmp(p, PCSZ_DOTMP3) || !stricmp(p, PCSZ_DOTFLAC))
173 OpenObject(filename, Default, hwnd); //FM2Play fails to play these
174 else
175 RunFM2Util(PCSZ_FM2PLAYEXE, filename);
176 played = TRUE;
[2]177 }
178 }
179
[92]180 return played;
[2]181}
182
[551]183VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
184 SWP * swp, CHAR * filename)
[347]185{
[551]186 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
187 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
188 else if (shiftstate & KC_CTRL)
189 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
190 else if (shiftstate & KC_SHIFT)
191 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
[2]192 else
[551]193 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
[2]194}
195
[1481]196/**
197 * DefaultView runs multiple checks for opening files including checking
198 * for associations, archives, executables, help, ini, warpin, multimedia and
199 * viewing as binary or text.
200 */
201
[551]202VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
203 ULONG flags, CHAR * filename)
[347]204{
[1673]205 /**
[2]206 * bitmapped flags:
207 * ---------------
208 * 1 = View directly
209 * 2 = Open WPS default view
210 * 4 = Open WPS settings view
211 * 8 = Edit
212 * 16 = Info
213 * 32 = No view info
214 */
215
[551]216 HWND hwndArc = (HWND) 0;
217 char *p, *dummy[3];
[2]218
[551]219 if (!hwndParent)
[2]220 hwndParent = HWND_DESKTOP;
221
[551]222 if (flags & 32) {
[2]223 flags &= (~16);
[551]224 if (!IsFile(filename)) {
[347]225 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
[2]226 return;
227 }
228 }
229
[1673]230 if (flags & 1) // directly view the file
[2]231 goto ViewIt;
232
[1673]233 if (flags & 2) { // open default WPS view of file
[551]234 OpenObject(filename, Default, hwnd);
[2]235 return;
236 }
237
[1673]238 if (flags & 4) { // open WPS settings notebook for file
[551]239 OpenObject(filename, Settings, hwnd);
[2]240 return;
241 }
242
[1673]243 if ((flags & 16) || !IsFile(filename)) { // open info for directories
[2]244
245 char fullname[CCHMAXPATH];
246
[551]247 if (!IsFullName(filename)) {
248 if (!DosQueryPathInfo(filename,
249 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
[92]250 filename = fullname;
[2]251 }
[551]252 if (IsFullName(filename) &&
253 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
254 if (!IsRoot(filename)) {
[92]255 dummy[0] = filename;
256 dummy[1] = NULL;
257 WinDlgBox(HWND_DESKTOP,
258 HWND_DESKTOP,
[551]259 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
[2]260 }
261 else
[92]262 WinDlgBox(HWND_DESKTOP,
263 HWND_DESKTOP,
[551]264 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
[2]265 }
266 return;
267 }
268
[1673]269 if (flags & 8) { // edit file
[2]270
271 ULONG type = IDM_EDITTEXT;
272
273 dummy[0] = filename;
274 dummy[1] = NULL;
[551]275 if (TestBinary(filename))
[2]276 type = IDM_EDITBINARY;
[551]277 switch (type) {
278 case IDM_EDITBINARY:
279 if (*bined) {
[1497]280 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
[901]281 pszSrcFile, __LINE__);
[551]282 break;
283 }
[1673]284 // else intentional fallthru
[551]285 case IDM_EDITTEXT:
286 if (*editor)
[1497]287 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
[901]288 pszSrcFile, __LINE__);
[551]289 else {
290 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
291 type |= 4;
292 StartMLEEditor(hwndParent, type, filename, hwndFrame);
293 }
294 break;
[2]295 }
296 return;
297 }
298
[1120]299 if (ExecAssociation(hwnd, filename) == -1 &&
300 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
[2]301 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
[551]302 strcmp(realappname, FM3Str)) ?
[92]303 HWND_DESKTOP :
[1690]304 hwndParent, hwndFrame, filename, 4, NULL);
[551]305 if (!hwndArc) {
[1479]306 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
307 p = strrchr(filename, '.');
308 if (!p)
309 p = ".";
[1481]310 if (!stricmp(p, ".WPI")) {
311 OpenObject(filename, Default, hwnd);
312 return;
313 }
[1479]314 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
315 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
[1645]316 ViewIt:
317 if (TestBinary(filename)) {
318 if (!fCheckMM || !ShowMultimedia(filename)) {
[1386]319 if (*binview) {
320 dummy[0] = filename;
321 dummy[1] = NULL;
322 ExecOnList(hwnd,
323 binview,
324 WINDOWED | SEPARATE |
[1497]325 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
[1386]326 pszSrcFile, __LINE__);
327 }
328 else if (fUseNewViewer) {
329 if (fExternalViewer || strcmp(realappname, FM3Str))
330 hwndParent = HWND_DESKTOP;
331 StartViewer(hwndParent, 5, filename, hwndFrame);
332 }
333 else
334 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
335 }
[1645]336 }
337 else {
338 if (*viewer) {
339 dummy[0] = filename;
340 dummy[1] = NULL;
341 ExecOnList(hwnd,
342 viewer,
343 WINDOWED | SEPARATE |
344 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
345 pszSrcFile, __LINE__);
[1386]346 }
[1645]347 else if (fUseNewViewer) {
348 if (fExternalViewer || strcmp(realappname, FM3Str))
349 hwndParent = HWND_DESKTOP;
350 StartViewer(hwndParent, 5, filename, hwndFrame);
351 }
352 else
353 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
354 }
355 //}
[92]356 }
357 }
[2]358 }
359 }
360 else {
[551]361 if ((swp &&
362 !fExternalArcboxes &&
363 !strcmp(realappname, FM3Str)) &&
364 !ParentIsDesktop(hwnd, hwndParent))
[92]365 WinSetWindowPos(hwndArc,
366 HWND_TOP,
367 swp->x,
368 swp->y,
369 swp->cx,
370 swp->cy,
[551]371 SWP_MOVE | SWP_SIZE | SWP_SHOW |
[92]372 SWP_ZORDER | SWP_ACTIVATE);
[2]373 }
374 }
375}
[793]376
377#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.