[92] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: defview.c 1783 2014-07-19 20:39:26Z 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] | 73 | static PSZ pszSrcFile = __FILE__;
|
---|
| 74 |
|
---|
[1206] | 75 | #pragma data_seg(GLOBAL2)
|
---|
[1402] | 76 | PCSZ 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] | 85 | BOOL 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 | //DbgMsg(pszSrcFile, __LINE__, "FOUCC %x %s %i", mmFormatInfo.fccIOProc,
|
---|
| 163 | // mmFormatInfo.szDefaultFormatExt, mmFormatInfo.ulMediaType);
|
---|
| 164 | if (!rc && (mmFormatInfo.fccIOProc != FOURCC_DOS ||
|
---|
| 165 | !stricmp(p, PCSZ_DOTMPG) || !stricmp(p, PCSZ_DOTMPEG))) {
|
---|
[1783] | 166 | if ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
|
---|
| 167 | OpenObject(filename, Default, hwnd);
|
---|
| 168 | played = TRUE;
|
---|
[2] | 169 | }
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[92] | 172 | return played;
|
---|
[2] | 173 | }
|
---|
| 174 |
|
---|
[551] | 175 | VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
|
---|
| 176 | SWP * swp, CHAR * filename)
|
---|
[347] | 177 | {
|
---|
[551] | 178 | if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
|
---|
| 179 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
|
---|
| 180 | else if (shiftstate & KC_CTRL)
|
---|
| 181 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
|
---|
| 182 | else if (shiftstate & KC_SHIFT)
|
---|
| 183 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
|
---|
[2] | 184 | else
|
---|
[551] | 185 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
|
---|
[2] | 186 | }
|
---|
| 187 |
|
---|
[1481] | 188 | /**
|
---|
| 189 | * DefaultView runs multiple checks for opening files including checking
|
---|
| 190 | * for associations, archives, executables, help, ini, warpin, multimedia and
|
---|
| 191 | * viewing as binary or text.
|
---|
| 192 | */
|
---|
| 193 |
|
---|
[551] | 194 | VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
|
---|
| 195 | ULONG flags, CHAR * filename)
|
---|
[347] | 196 | {
|
---|
[1673] | 197 | /**
|
---|
[2] | 198 | * bitmapped flags:
|
---|
| 199 | * ---------------
|
---|
| 200 | * 1 = View directly
|
---|
| 201 | * 2 = Open WPS default view
|
---|
| 202 | * 4 = Open WPS settings view
|
---|
| 203 | * 8 = Edit
|
---|
| 204 | * 16 = Info
|
---|
| 205 | * 32 = No view info
|
---|
| 206 | */
|
---|
| 207 |
|
---|
[551] | 208 | HWND hwndArc = (HWND) 0;
|
---|
| 209 | char *p, *dummy[3];
|
---|
[2] | 210 |
|
---|
[551] | 211 | if (!hwndParent)
|
---|
[2] | 212 | hwndParent = HWND_DESKTOP;
|
---|
| 213 |
|
---|
[551] | 214 | if (flags & 32) {
|
---|
[2] | 215 | flags &= (~16);
|
---|
[551] | 216 | if (!IsFile(filename)) {
|
---|
[347] | 217 | Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
|
---|
[2] | 218 | return;
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[1673] | 222 | if (flags & 1) // directly view the file
|
---|
[2] | 223 | goto ViewIt;
|
---|
| 224 |
|
---|
[1673] | 225 | if (flags & 2) { // open default WPS view of file
|
---|
[551] | 226 | OpenObject(filename, Default, hwnd);
|
---|
[2] | 227 | return;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[1673] | 230 | if (flags & 4) { // open WPS settings notebook for file
|
---|
[551] | 231 | OpenObject(filename, Settings, hwnd);
|
---|
[2] | 232 | return;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[1673] | 235 | if ((flags & 16) || !IsFile(filename)) { // open info for directories
|
---|
[2] | 236 |
|
---|
| 237 | char fullname[CCHMAXPATH];
|
---|
| 238 |
|
---|
[551] | 239 | if (!IsFullName(filename)) {
|
---|
| 240 | if (!DosQueryPathInfo(filename,
|
---|
| 241 | FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
|
---|
[92] | 242 | filename = fullname;
|
---|
[2] | 243 | }
|
---|
[551] | 244 | if (IsFullName(filename) &&
|
---|
| 245 | !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
|
---|
| 246 | if (!IsRoot(filename)) {
|
---|
[92] | 247 | dummy[0] = filename;
|
---|
| 248 | dummy[1] = NULL;
|
---|
| 249 | WinDlgBox(HWND_DESKTOP,
|
---|
| 250 | HWND_DESKTOP,
|
---|
[551] | 251 | FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
|
---|
[2] | 252 | }
|
---|
| 253 | else
|
---|
[92] | 254 | WinDlgBox(HWND_DESKTOP,
|
---|
| 255 | HWND_DESKTOP,
|
---|
[551] | 256 | DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
|
---|
[2] | 257 | }
|
---|
| 258 | return;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
[1673] | 261 | if (flags & 8) { // edit file
|
---|
[2] | 262 |
|
---|
| 263 | ULONG type = IDM_EDITTEXT;
|
---|
| 264 |
|
---|
| 265 | dummy[0] = filename;
|
---|
| 266 | dummy[1] = NULL;
|
---|
[551] | 267 | if (TestBinary(filename))
|
---|
[2] | 268 | type = IDM_EDITBINARY;
|
---|
[551] | 269 | switch (type) {
|
---|
| 270 | case IDM_EDITBINARY:
|
---|
| 271 | if (*bined) {
|
---|
[1497] | 272 | ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
|
---|
[901] | 273 | pszSrcFile, __LINE__);
|
---|
[551] | 274 | break;
|
---|
| 275 | }
|
---|
[1673] | 276 | // else intentional fallthru
|
---|
[551] | 277 | case IDM_EDITTEXT:
|
---|
| 278 | if (*editor)
|
---|
[1497] | 279 | ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
|
---|
[901] | 280 | pszSrcFile, __LINE__);
|
---|
[551] | 281 | else {
|
---|
| 282 | type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
|
---|
| 283 | type |= 4;
|
---|
| 284 | StartMLEEditor(hwndParent, type, filename, hwndFrame);
|
---|
| 285 | }
|
---|
| 286 | break;
|
---|
[2] | 287 | }
|
---|
| 288 | return;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[1120] | 291 | if (ExecAssociation(hwnd, filename) == -1 &&
|
---|
| 292 | CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
|
---|
[2] | 293 | hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
|
---|
[551] | 294 | strcmp(realappname, FM3Str)) ?
|
---|
[92] | 295 | HWND_DESKTOP :
|
---|
[1690] | 296 | hwndParent, hwndFrame, filename, 4, NULL);
|
---|
[551] | 297 | if (!hwndArc) {
|
---|
[1479] | 298 | if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
|
---|
| 299 | p = strrchr(filename, '.');
|
---|
| 300 | if (!p)
|
---|
| 301 | p = ".";
|
---|
[1481] | 302 | if (!stricmp(p, ".WPI")) {
|
---|
| 303 | OpenObject(filename, Default, hwnd);
|
---|
| 304 | return;
|
---|
| 305 | }
|
---|
[1479] | 306 | if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
|
---|
| 307 | if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
|
---|
[1645] | 308 | ViewIt:
|
---|
| 309 | if (TestBinary(filename)) {
|
---|
| 310 | if (!fCheckMM || !ShowMultimedia(filename)) {
|
---|
[1386] | 311 | if (*binview) {
|
---|
| 312 | dummy[0] = filename;
|
---|
| 313 | dummy[1] = NULL;
|
---|
| 314 | ExecOnList(hwnd,
|
---|
| 315 | binview,
|
---|
| 316 | WINDOWED | SEPARATE |
|
---|
[1497] | 317 | ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
|
---|
[1386] | 318 | pszSrcFile, __LINE__);
|
---|
| 319 | }
|
---|
| 320 | else if (fUseNewViewer) {
|
---|
| 321 | if (fExternalViewer || strcmp(realappname, FM3Str))
|
---|
| 322 | hwndParent = HWND_DESKTOP;
|
---|
| 323 | StartViewer(hwndParent, 5, filename, hwndFrame);
|
---|
| 324 | }
|
---|
| 325 | else
|
---|
| 326 | StartMLEEditor(hwndParent, 5, filename, hwndFrame);
|
---|
| 327 | }
|
---|
[1645] | 328 | }
|
---|
| 329 | else {
|
---|
| 330 | if (*viewer) {
|
---|
| 331 | dummy[0] = filename;
|
---|
| 332 | dummy[1] = NULL;
|
---|
| 333 | ExecOnList(hwnd,
|
---|
| 334 | viewer,
|
---|
| 335 | WINDOWED | SEPARATE |
|
---|
| 336 | ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
|
---|
| 337 | pszSrcFile, __LINE__);
|
---|
[1386] | 338 | }
|
---|
[1645] | 339 | else if (fUseNewViewer) {
|
---|
| 340 | if (fExternalViewer || strcmp(realappname, FM3Str))
|
---|
| 341 | hwndParent = HWND_DESKTOP;
|
---|
| 342 | StartViewer(hwndParent, 5, filename, hwndFrame);
|
---|
| 343 | }
|
---|
| 344 | else
|
---|
| 345 | StartMLEEditor(hwndParent, 5, filename, hwndFrame);
|
---|
| 346 | }
|
---|
[92] | 347 | }
|
---|
| 348 | }
|
---|
[2] | 349 | }
|
---|
| 350 | }
|
---|
| 351 | else {
|
---|
[551] | 352 | if ((swp &&
|
---|
| 353 | !fExternalArcboxes &&
|
---|
| 354 | !strcmp(realappname, FM3Str)) &&
|
---|
| 355 | !ParentIsDesktop(hwnd, hwndParent))
|
---|
[92] | 356 | WinSetWindowPos(hwndArc,
|
---|
| 357 | HWND_TOP,
|
---|
| 358 | swp->x,
|
---|
| 359 | swp->y,
|
---|
| 360 | swp->cx,
|
---|
| 361 | swp->cy,
|
---|
[551] | 362 | SWP_MOVE | SWP_SIZE | SWP_SHOW |
|
---|
[92] | 363 | SWP_ZORDER | SWP_ACTIVATE);
|
---|
[2] | 364 | }
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
[793] | 367 |
|
---|
| 368 | #pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
|
---|