| [92] | 1 | 
 | 
|---|
 | 2 | /***********************************************************************
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 |   $Id: defview.c 347 2006-07-26 05:43:28Z root $
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| [347] | 7 |   Copyright (c) 2003, 2006 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
 | 
|---|
| [92] | 13 | 
 | 
|---|
 | 14 | ***********************************************************************/
 | 
|---|
 | 15 | 
 | 
|---|
| [2] | 16 | #define INCL_DOS
 | 
|---|
 | 17 | #define INCL_WIN
 | 
|---|
 | 18 | #define INCL_GPI
 | 
|---|
 | 19 | #define INCL_MMIOOS2
 | 
|---|
 | 20 | #include <os2.h>
 | 
|---|
 | 21 | #include <os2me.h>
 | 
|---|
| [347] | 22 | 
 | 
|---|
| [2] | 23 | #include <stdio.h>
 | 
|---|
 | 24 | #include <stdlib.h>
 | 
|---|
 | 25 | #include <string.h>
 | 
|---|
 | 26 | #include <ctype.h>
 | 
|---|
| [347] | 27 | 
 | 
|---|
| [2] | 28 | #include "fm3dll.h"
 | 
|---|
 | 29 | #include "fm3dlg.h"
 | 
|---|
 | 30 | 
 | 
|---|
| [347] | 31 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
 | 32 | 
 | 
|---|
| [2] | 33 | #pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | 
 | 
|---|
| [92] | 36 | BOOL ShowMultimedia (CHAR *filename)
 | 
|---|
 | 37 | {
 | 
|---|
| [2] | 38 | 
 | 
|---|
| [92] | 39 |   static BOOL       no_mmos2 = FALSE;
 | 
|---|
 | 40 |   BOOL              played = FALSE;
 | 
|---|
| [2] | 41 |   CHAR              loaderror[CCHMAXPATH];
 | 
|---|
| [92] | 42 |   HMODULE           MMIOModHandle = NULLHANDLE;
 | 
|---|
 | 43 |   PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
 | 
|---|
 | 44 |   FOURCC            fccStorageSystem = 0;
 | 
|---|
| [2] | 45 |   MMFORMATINFO      mmFormatInfo;
 | 
|---|
 | 46 |   APIRET            rc;
 | 
|---|
 | 47 | 
 | 
|---|
| [92] | 48 |   if (no_mmos2 ||
 | 
|---|
 | 49 |       !filename ||
 | 
|---|
 | 50 |       !*filename)
 | 
|---|
 | 51 |     return played;
 | 
|---|
| [2] | 52 | 
 | 
|---|
 | 53 |   /* load MMPM/2, if available. */
 | 
|---|
 | 54 |   *loaderror = 0;
 | 
|---|
 | 55 |   rc = DosLoadModule(loaderror,
 | 
|---|
| [92] | 56 |                      sizeof(loaderror),
 | 
|---|
 | 57 |                      "MMIO",
 | 
|---|
 | 58 |                      &MMIOModHandle);
 | 
|---|
 | 59 |   if (rc) {
 | 
|---|
 | 60 |     no_mmos2 = TRUE;
 | 
|---|
 | 61 |     return played;
 | 
|---|
| [2] | 62 |   }
 | 
|---|
 | 63 |   else {
 | 
|---|
| [92] | 64 |     if (DosQueryProcAddr(MMIOModHandle,
 | 
|---|
 | 65 |                         0,
 | 
|---|
 | 66 |                         "mmioIdentifyFile",
 | 
|---|
 | 67 |                         (PFN *)&pMMIOIdentifyFile)) {
 | 
|---|
| [2] | 68 |       DosFreeModule(MMIOModHandle);
 | 
|---|
| [92] | 69 |       no_mmos2 = TRUE;
 | 
|---|
 | 70 |       return played;
 | 
|---|
| [2] | 71 |     }
 | 
|---|
 | 72 |   }
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 |   /* attempt to identify the file using MMPM/2 */
 | 
|---|
 | 75 |   memset(&mmFormatInfo,0,sizeof(MMFORMATINFO));
 | 
|---|
 | 76 |   mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
 | 
|---|
| [92] | 77 |   rc = pMMIOIdentifyFile(filename,
 | 
|---|
 | 78 |                          0L,
 | 
|---|
 | 79 |                          &mmFormatInfo,
 | 
|---|
 | 80 |                          &fccStorageSystem,
 | 
|---|
 | 81 |                          0L,
 | 
|---|
 | 82 |                          MMIO_FORCE_IDENTIFY_FF);
 | 
|---|
| [2] | 83 |   /* free module handle */
 | 
|---|
 | 84 |   DosFreeModule(MMIOModHandle);
 | 
|---|
 | 85 | 
 | 
|---|
| [92] | 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 */
 | 
|---|
| [2] | 92 |       runemf2(SEPARATE | WINDOWED,
 | 
|---|
| [92] | 93 |               HWND_DESKTOP,
 | 
|---|
 | 94 |               NULL,
 | 
|---|
 | 95 |               NULL,
 | 
|---|
 | 96 |               "%sIMAGE.EXE \"%s\"",
 | 
|---|
 | 97 |               (fAddUtils) ? "UTILS\\" : NullStr,
 | 
|---|
 | 98 |               filename);
 | 
|---|
 | 99 |       played = TRUE;
 | 
|---|
| [2] | 100 |     }
 | 
|---|
| [92] | 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;
 | 
|---|
| [2] | 111 |     }
 | 
|---|
 | 112 |   }
 | 
|---|
 | 113 | 
 | 
|---|
| [92] | 114 |   return played;
 | 
|---|
| [2] | 115 | }
 | 
|---|
 | 116 | 
 | 
|---|
 | 117 | 
 | 
|---|
 | 118 | VOID DefaultViewKeys (HWND hwnd,HWND hwndFrame,HWND hwndParent,
 | 
|---|
| [347] | 119 |                       SWP *swp,CHAR *filename)
 | 
|---|
 | 120 | {
 | 
|---|
| [2] | 121 |   if((shiftstate & (KC_CTRL | KC_SHIFT)) ==
 | 
|---|
 | 122 |      (KC_CTRL | KC_SHIFT))
 | 
|---|
 | 123 |     DefaultView(hwnd,
 | 
|---|
| [92] | 124 |                 hwndFrame,
 | 
|---|
 | 125 |                 hwndParent,
 | 
|---|
 | 126 |                 swp,
 | 
|---|
 | 127 |                 4,
 | 
|---|
 | 128 |                 filename);
 | 
|---|
| [2] | 129 |   else if(shiftstate & KC_CTRL)
 | 
|---|
 | 130 |     DefaultView(hwnd,
 | 
|---|
| [92] | 131 |                 hwndFrame,
 | 
|---|
 | 132 |                 hwndParent,
 | 
|---|
 | 133 |                 swp,
 | 
|---|
 | 134 |                 2,
 | 
|---|
 | 135 |                 filename);
 | 
|---|
| [2] | 136 |   else if(shiftstate & KC_SHIFT)
 | 
|---|
 | 137 |     DefaultView(hwnd,
 | 
|---|
| [92] | 138 |                 hwndFrame,
 | 
|---|
 | 139 |                 hwndParent,
 | 
|---|
 | 140 |                 swp,
 | 
|---|
 | 141 |                 1,
 | 
|---|
 | 142 |                 filename);
 | 
|---|
| [2] | 143 |   else
 | 
|---|
 | 144 |     DefaultView(hwnd,
 | 
|---|
| [92] | 145 |                 hwndFrame,
 | 
|---|
 | 146 |                 hwndParent,
 | 
|---|
 | 147 |                 swp,
 | 
|---|
 | 148 |                 0,
 | 
|---|
 | 149 |                 filename);
 | 
|---|
| [2] | 150 | }
 | 
|---|
 | 151 | 
 | 
|---|
 | 152 | 
 | 
|---|
 | 153 | VOID DefaultView (HWND hwnd,HWND hwndFrame,HWND hwndParent,SWP *swp,
 | 
|---|
| [347] | 154 |                   ULONG flags,CHAR *filename)
 | 
|---|
 | 155 | {
 | 
|---|
| [2] | 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)) {
 | 
|---|
| [347] | 176 |       Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
 | 
|---|
| [2] | 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,
 | 
|---|
| [92] | 186 |                Default,
 | 
|---|
 | 187 |                hwnd);
 | 
|---|
| [2] | 188 |     return;
 | 
|---|
 | 189 |   }
 | 
|---|
 | 190 | 
 | 
|---|
 | 191 |   if(flags & 4) {   /* open WPS settings notebook for file */
 | 
|---|
 | 192 |     OpenObject(filename,
 | 
|---|
| [92] | 193 |                Settings,
 | 
|---|
 | 194 |                hwnd);
 | 
|---|
| [2] | 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,
 | 
|---|
| [92] | 205 |                            FIL_QUERYFULLNAME,
 | 
|---|
 | 206 |                            fullname,
 | 
|---|
 | 207 |                            sizeof(fullname)))
 | 
|---|
 | 208 |         filename = fullname;
 | 
|---|
| [2] | 209 |     }
 | 
|---|
 | 210 |     if(IsFullName(filename) &&
 | 
|---|
 | 211 |        !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
 | 
|---|
 | 212 |       if(!IsRoot(filename)) {
 | 
|---|
| [92] | 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);
 | 
|---|
| [2] | 221 |       }
 | 
|---|
 | 222 |       else
 | 
|---|
| [92] | 223 |         WinDlgBox(HWND_DESKTOP,
 | 
|---|
 | 224 |                   HWND_DESKTOP,
 | 
|---|
 | 225 |                   DrvInfoProc,
 | 
|---|
 | 226 |                   FM3ModHandle,
 | 
|---|
 | 227 |                   INFO_FRAME,
 | 
|---|
 | 228 |                   (PVOID)filename);
 | 
|---|
| [2] | 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:
 | 
|---|
| [92] | 243 |         if(*bined) {
 | 
|---|
 | 244 |           ExecOnList((HWND)0,
 | 
|---|
 | 245 |                      bined,
 | 
|---|
 | 246 |                      WINDOWED | SEPARATE,
 | 
|---|
 | 247 |                      NULL,
 | 
|---|
 | 248 |                      dummy,
 | 
|---|
 | 249 |                      NULL);
 | 
|---|
 | 250 |           break;
 | 
|---|
 | 251 |         }
 | 
|---|
| [2] | 252 |       /* else intentional fallthru */
 | 
|---|
 | 253 |       case IDM_EDITTEXT:
 | 
|---|
| [92] | 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;
 | 
|---|
| [2] | 272 |     }
 | 
|---|
 | 273 |     return;
 | 
|---|
 | 274 |   }
 | 
|---|
 | 275 | 
 | 
|---|
 | 276 |   if(ExecAssociation(hwnd,
 | 
|---|
| [92] | 277 |                      filename) == -1) {
 | 
|---|
| [2] | 278 |     hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
 | 
|---|
| [92] | 279 |                            strcmp(realappname,FM3Str)) ?
 | 
|---|
 | 280 |                           HWND_DESKTOP :
 | 
|---|
 | 281 |                           hwndParent,
 | 
|---|
 | 282 |                           hwndFrame,
 | 
|---|
 | 283 |                           filename,
 | 
|---|
 | 284 |                           4,
 | 
|---|
 | 285 |                           NULL);
 | 
|---|
| [2] | 286 |     if(!hwndArc) {
 | 
|---|
 | 287 |       if(!fCheckMM ||
 | 
|---|
| [92] | 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)) {
 | 
|---|
| [2] | 300 | ViewIt:
 | 
|---|
| [92] | 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 |         }
 | 
|---|
| [2] | 320 |       }
 | 
|---|
 | 321 |     }
 | 
|---|
 | 322 |     else {
 | 
|---|
 | 323 |       if((swp &&
 | 
|---|
| [92] | 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);
 | 
|---|
| [2] | 335 |     }
 | 
|---|
 | 336 |   }
 | 
|---|
 | 337 | }
 | 
|---|
 | 338 | 
 | 
|---|