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