source: trunk/dll/defview.c@ 1877

Last change on this file since 1877 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

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