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