[92] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: defview.c 551 2007-02-28 01:33:51Z gyoung $
|
---|
| 5 |
|
---|
| 6 | Copyright (c) 1993-98 M. Kimes
|
---|
[347] | 7 | Copyright (c) 2003, 2006 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
|
---|
[92] | 13 |
|
---|
| 14 | ***********************************************************************/
|
---|
| 15 |
|
---|
[2] | 16 | #define INCL_DOS
|
---|
| 17 | #define INCL_WIN
|
---|
| 18 | #define INCL_GPI
|
---|
| 19 | #define INCL_MMIOOS2
|
---|
| 20 | #include <os2.h>
|
---|
| 21 | #include <os2me.h>
|
---|
[347] | 22 |
|
---|
[2] | 23 | #include <stdio.h>
|
---|
| 24 | #include <stdlib.h>
|
---|
| 25 | #include <string.h>
|
---|
| 26 | #include <ctype.h>
|
---|
[347] | 27 |
|
---|
[2] | 28 | #include "fm3dll.h"
|
---|
| 29 | #include "fm3dlg.h"
|
---|
| 30 |
|
---|
[347] | 31 | static PSZ pszSrcFile = __FILE__;
|
---|
| 32 |
|
---|
[2] | 33 | #pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
|
---|
| 34 |
|
---|
[551] | 35 | BOOL ShowMultimedia(CHAR * filename)
|
---|
[92] | 36 | {
|
---|
[2] | 37 |
|
---|
[551] | 38 | static BOOL no_mmos2 = FALSE;
|
---|
| 39 | BOOL played = FALSE;
|
---|
| 40 | CHAR loaderror[CCHMAXPATH];
|
---|
| 41 | HMODULE MMIOModHandle = NULLHANDLE;
|
---|
[92] | 42 | PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
|
---|
[551] | 43 | FOURCC fccStorageSystem = 0;
|
---|
| 44 | MMFORMATINFO mmFormatInfo;
|
---|
| 45 | APIRET rc;
|
---|
[2] | 46 |
|
---|
[551] | 47 | if (no_mmos2 || !filename || !*filename)
|
---|
[92] | 48 | return played;
|
---|
[2] | 49 |
|
---|
| 50 | /* load MMPM/2, if available. */
|
---|
| 51 | *loaderror = 0;
|
---|
[551] | 52 | rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
|
---|
[92] | 53 | if (rc) {
|
---|
| 54 | no_mmos2 = TRUE;
|
---|
| 55 | return played;
|
---|
[2] | 56 | }
|
---|
| 57 | else {
|
---|
[92] | 58 | if (DosQueryProcAddr(MMIOModHandle,
|
---|
[551] | 59 | 0,
|
---|
| 60 | "mmioIdentifyFile", (PFN *) & pMMIOIdentifyFile)) {
|
---|
[2] | 61 | DosFreeModule(MMIOModHandle);
|
---|
[92] | 62 | no_mmos2 = TRUE;
|
---|
| 63 | return played;
|
---|
[2] | 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /* attempt to identify the file using MMPM/2 */
|
---|
[551] | 68 | memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
|
---|
[2] | 69 | mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
|
---|
[92] | 70 | rc = pMMIOIdentifyFile(filename,
|
---|
| 71 | 0L,
|
---|
| 72 | &mmFormatInfo,
|
---|
[551] | 73 | &fccStorageSystem, 0L, MMIO_FORCE_IDENTIFY_FF);
|
---|
[2] | 74 | /* free module handle */
|
---|
| 75 | DosFreeModule(MMIOModHandle);
|
---|
| 76 |
|
---|
[92] | 77 | /* if identified and not FOURCC_DOS */
|
---|
[551] | 78 | if (!rc && mmFormatInfo.fccIOProc != FOURCC_DOS) {
|
---|
[92] | 79 | if (mmFormatInfo.ulMediaType == MMIO_MEDIATYPE_IMAGE &&
|
---|
[551] | 80 | (mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
|
---|
[92] | 81 | /* is an image that can be translated */
|
---|
[2] | 82 | runemf2(SEPARATE | WINDOWED,
|
---|
[92] | 83 | HWND_DESKTOP,
|
---|
| 84 | NULL,
|
---|
| 85 | NULL,
|
---|
| 86 | "%sIMAGE.EXE \"%s\"",
|
---|
[551] | 87 | (fAddUtils) ? "UTILS\\" : NullStr, filename);
|
---|
[92] | 88 | played = TRUE;
|
---|
[2] | 89 | }
|
---|
[92] | 90 | else if (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) {
|
---|
| 91 | /* is a multimedia file (WAV, MID, AVI, etc.) */
|
---|
| 92 | runemf2(SEPARATE | WINDOWED,
|
---|
| 93 | HWND_DESKTOP,
|
---|
| 94 | NULL,
|
---|
| 95 | NULL,
|
---|
| 96 | "%sFM2PLAY.EXE \"%s\"",
|
---|
[551] | 97 | (fAddUtils) ? "UTILS\\" : NullStr, filename);
|
---|
[92] | 98 | played = TRUE;
|
---|
[2] | 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[92] | 102 | return played;
|
---|
[2] | 103 | }
|
---|
| 104 |
|
---|
[551] | 105 | VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
|
---|
| 106 | SWP * swp, CHAR * filename)
|
---|
[347] | 107 | {
|
---|
[551] | 108 | if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
|
---|
| 109 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
|
---|
| 110 | else if (shiftstate & KC_CTRL)
|
---|
| 111 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
|
---|
| 112 | else if (shiftstate & KC_SHIFT)
|
---|
| 113 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
|
---|
[2] | 114 | else
|
---|
[551] | 115 | DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
|
---|
[2] | 116 | }
|
---|
| 117 |
|
---|
[551] | 118 | VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
|
---|
| 119 | ULONG flags, CHAR * filename)
|
---|
[347] | 120 | {
|
---|
[2] | 121 | /*
|
---|
| 122 | * bitmapped flags:
|
---|
| 123 | * ---------------
|
---|
| 124 | * 1 = View directly
|
---|
| 125 | * 2 = Open WPS default view
|
---|
| 126 | * 4 = Open WPS settings view
|
---|
| 127 | * 8 = Edit
|
---|
| 128 | * 16 = Info
|
---|
| 129 | * 32 = No view info
|
---|
| 130 | */
|
---|
| 131 |
|
---|
[551] | 132 | HWND hwndArc = (HWND) 0;
|
---|
| 133 | char *p, *dummy[3];
|
---|
[2] | 134 |
|
---|
[551] | 135 | if (!hwndParent)
|
---|
[2] | 136 | hwndParent = HWND_DESKTOP;
|
---|
| 137 |
|
---|
[551] | 138 | if (flags & 32) {
|
---|
[2] | 139 | flags &= (~16);
|
---|
[551] | 140 | if (!IsFile(filename)) {
|
---|
[347] | 141 | Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
|
---|
[2] | 142 | return;
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[551] | 146 | if (flags & 1) /* directly view the file */
|
---|
[2] | 147 | goto ViewIt;
|
---|
| 148 |
|
---|
[551] | 149 | if (flags & 2) { /* open default WPS view of file */
|
---|
| 150 | OpenObject(filename, Default, hwnd);
|
---|
[2] | 151 | return;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[551] | 154 | if (flags & 4) { /* open WPS settings notebook for file */
|
---|
| 155 | OpenObject(filename, Settings, hwnd);
|
---|
[2] | 156 | return;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[551] | 159 | if ((flags & 16) || !IsFile(filename)) { /* open info for directories */
|
---|
[2] | 160 |
|
---|
| 161 | char fullname[CCHMAXPATH];
|
---|
| 162 |
|
---|
[551] | 163 | if (!IsFullName(filename)) {
|
---|
| 164 | if (!DosQueryPathInfo(filename,
|
---|
| 165 | FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
|
---|
[92] | 166 | filename = fullname;
|
---|
[2] | 167 | }
|
---|
[551] | 168 | if (IsFullName(filename) &&
|
---|
| 169 | !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
|
---|
| 170 | if (!IsRoot(filename)) {
|
---|
[92] | 171 | dummy[0] = filename;
|
---|
| 172 | dummy[1] = NULL;
|
---|
| 173 | WinDlgBox(HWND_DESKTOP,
|
---|
| 174 | HWND_DESKTOP,
|
---|
[551] | 175 | FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
|
---|
[2] | 176 | }
|
---|
| 177 | else
|
---|
[92] | 178 | WinDlgBox(HWND_DESKTOP,
|
---|
| 179 | HWND_DESKTOP,
|
---|
[551] | 180 | DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
|
---|
[2] | 181 | }
|
---|
| 182 | return;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[551] | 185 | if (flags & 8) { /* edit file */
|
---|
[2] | 186 |
|
---|
| 187 | ULONG type = IDM_EDITTEXT;
|
---|
| 188 |
|
---|
| 189 | dummy[0] = filename;
|
---|
| 190 | dummy[1] = NULL;
|
---|
[551] | 191 | if (TestBinary(filename))
|
---|
[2] | 192 | type = IDM_EDITBINARY;
|
---|
[551] | 193 | switch (type) {
|
---|
| 194 | case IDM_EDITBINARY:
|
---|
| 195 | if (*bined) {
|
---|
| 196 | ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, dummy, NULL);
|
---|
| 197 | break;
|
---|
| 198 | }
|
---|
[2] | 199 | /* else intentional fallthru */
|
---|
[551] | 200 | case IDM_EDITTEXT:
|
---|
| 201 | if (*editor)
|
---|
| 202 | ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, dummy, NULL);
|
---|
| 203 | else {
|
---|
| 204 | type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
|
---|
| 205 | type |= 4;
|
---|
| 206 | StartMLEEditor(hwndParent, type, filename, hwndFrame);
|
---|
| 207 | }
|
---|
| 208 | break;
|
---|
[2] | 209 | }
|
---|
| 210 | return;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[551] | 213 | if (ExecAssociation(hwnd, filename) == -1) {
|
---|
[2] | 214 | hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
|
---|
[551] | 215 | strcmp(realappname, FM3Str)) ?
|
---|
[92] | 216 | HWND_DESKTOP :
|
---|
[551] | 217 | hwndParent, hwndFrame, filename, 4, NULL);
|
---|
| 218 | if (!hwndArc) {
|
---|
| 219 | if (!fCheckMM || !ShowMultimedia(filename)) {
|
---|
| 220 | if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
|
---|
| 221 | p = strrchr(filename, '.');
|
---|
| 222 | if (!p)
|
---|
[92] | 223 | p = ".";
|
---|
[551] | 224 | if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
|
---|
| 225 | if (stricmp(p, ".HLP") || !ViewHelp(filename)) {
|
---|
| 226 | ViewIt:
|
---|
| 227 | if (*viewer) {
|
---|
[92] | 228 | dummy[0] = filename;
|
---|
| 229 | dummy[1] = NULL;
|
---|
| 230 | ExecOnList(hwnd,
|
---|
| 231 | viewer,
|
---|
| 232 | WINDOWED | SEPARATE |
|
---|
[551] | 233 | ((fViewChild) ? CHILD : 0), NULL, dummy, NULL);
|
---|
[92] | 234 | }
|
---|
| 235 | else
|
---|
[551] | 236 | StartMLEEditor(hwndParent, 5, filename, hwndFrame);
|
---|
[92] | 237 | }
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
[2] | 240 | }
|
---|
| 241 | }
|
---|
| 242 | else {
|
---|
[551] | 243 | if ((swp &&
|
---|
| 244 | !fExternalArcboxes &&
|
---|
| 245 | !strcmp(realappname, FM3Str)) &&
|
---|
| 246 | !ParentIsDesktop(hwnd, hwndParent))
|
---|
[92] | 247 | WinSetWindowPos(hwndArc,
|
---|
| 248 | HWND_TOP,
|
---|
| 249 | swp->x,
|
---|
| 250 | swp->y,
|
---|
| 251 | swp->cx,
|
---|
| 252 | swp->cy,
|
---|
[551] | 253 | SWP_MOVE | SWP_SIZE | SWP_SHOW |
|
---|
[92] | 254 | SWP_ZORDER | SWP_ACTIVATE);
|
---|
[2] | 255 | }
|
---|
| 256 | }
|
---|
| 257 | }
|
---|