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