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