Changeset 1479 for trunk/dll/assoc.c


Ignore:
Timestamp:
Nov 15, 2009, 11:40:25 PM (16 years ago)
Author:
Gregg Young
Message:

Work around MMIO's failure to recognize MPG files as media. Reorder file type checks to eliminate problem with MMIO identifying exes etc as media. Check for zero byte file and let user decide to open in an editor or abort (also prevents MMIO misidentification). Tickets 70, 405, 409, 410

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/assoc.c

    r1398 r1479  
    2020  19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
    2121  24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
     22  15 Nov 09 GKY Add check for attempt to open zero byte file (avoids MMPM trying to play them)
    2223
    2324**************************************************************************************/
     
    393394INT ExecAssociation(HWND hwnd, CHAR * datafile)
    394395{
    395   CHAR *file, sig[CCHMAXPATH], sigl[CCHMAXPATH], mask[CCHMAXPATH], *p;
     396  CHAR *file;
     397  CHAR sig[CCHMAXPATH];
     398  CHAR sigl[CCHMAXPATH];
     399  CHAR mask[CCHMAXPATH], *p;
    396400  FILE *fp;
    397   BOOL didmatch, exclude;
     401  BOOL didmatch;
     402  BOOL exclude;
     403  BOOL checked = FALSE;
    398404  ULONG offset;
    399405  LINKASSOC *info;
     
    426432                             strchr(p, ':')) ? datafile : file, p, FALSE);
    427433      if (exclude && didmatch)
    428         didmatch = FALSE;
    429       if (didmatch) {
    430         if (info->sig && *info->sig) {
    431           strcpy(sigl, info->sig);
    432           literal(sigl);
    433           fp = _fsopen(datafile, "rb", SH_DENYNO);
    434           if (fp) {
    435             if (info->offset < 0L) {
    436               fseek(fp, 0L, SEEK_END);
    437               offset = ftell(fp) + info->offset;
    438             }
    439             else
    440               offset = info->offset;
    441             fseek(fp, offset, SEEK_SET);
    442             if (fread(sig,
    443                       1,
    444                       strlen(sigl),
    445                       fp) != strlen(sigl) || strncmp(sigl, sig, strlen(sigl)))
    446               didmatch = FALSE;
    447             fclose(fp);
    448           }
    449         }
     434        didmatch = FALSE;
     435      fp = _fsopen(datafile, "rb", SH_DENYNO);
     436      if (fp) {
     437        if (!checked) {
     438          APIRET temp;
     439 
     440          temp = fread(sig, 1, 2, fp);
     441          if (temp != 2) {
     442            temp = saymsg(MB_YESNO, hwnd, NullStr, GetPString(IDS_ZEROBYTETEXT));
     443            if (temp == MBID_YES) {
     444              DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 8, datafile);
     445            }
     446            fclose(fp);
     447            return 0;
     448          }
     449          else
     450            checked = TRUE;
     451        }
     452        if (didmatch) {
     453          if (info->sig && *info->sig) {
     454            strcpy(sigl, info->sig);
     455            literal(sigl);
     456           
     457              if (info->offset < 0L) {
     458                fseek(fp, 0L, SEEK_END);
     459                offset = ftell(fp) + info->offset;
     460              }
     461              else
     462                offset = info->offset;
     463              fseek(fp, offset, SEEK_SET);
     464              if (fread(sig,
     465                        1,
     466                        strlen(sigl),
     467                        fp) != strlen(sigl) || strncmp(sigl, sig, strlen(sigl)))
     468                didmatch = FALSE;
     469             
     470          }
     471        }
     472        fclose(fp);
    450473      }
    451474      if (didmatch) {                   /* got a match; do it... */
Note: See TracChangeset for help on using the changeset viewer.