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