Changeset 1112 for trunk/dll/misc.c


Ignore:
Timestamp:
Aug 24, 2008, 5:13:20 AM (17 years ago)
Author:
Gregg Young
Message:

Check free space on TMP & FM2 save directory drives at start up (Ticket 268)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/misc.c

    r1106 r1112  
    5151  20 Jul 08 GKY Add save/append filename to clipboard.
    5252                Change menu wording to make these easier to find
     53  23 Aug 08 GKY Add CheckDriveSpaceAvail To pre check drive space to prevent failures
    5354
    5455***********************************************************************/
     
    22162217}
    22172218
     2219/** CheckDriveSpaceAvail
     2220 *  Take space needed and checks that drive has at least 1000 bits in excess of the required space.
     2221 *  Returns 0 if sufficient space is available; 1 if the drive is full & 2 on abort of operation
     2222 *  when the drive would have less than ullFreeSpaceWhenComplete remaining or has insufficient space.
     2223 */
     2224
     2225INT CheckDriveSpaceAvail(CHAR *pTargetPath, ULONGLONG ullSpaceNeeded,
     2226                          ULONGLONG ullFreeSpaceWhenComplete)
     2227{
     2228  FSALLOCATE fsa;
     2229  ULONGLONG  ullFreeQty;
     2230  APIRET ret;
     2231
     2232  DosQueryFSInfo(toupper(*pTargetPath) - 'A' + 1, FSIL_ALLOC, &fsa, sizeof(FSALLOCATE));
     2233  ullFreeQty = (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
     2234  if (ullFreeQty > ullSpaceNeeded + ullFreeSpaceWhenComplete)
     2235    return 0;
     2236  else if (ullFreeQty < ullSpaceNeeded + 1024) {
     2237    CHAR szKB[20];
     2238
     2239    if (ullFreeSpaceWhenComplete == 0)
     2240      ullSpaceNeeded = 0;
     2241    commafmt(szKB, sizeof(szKB),
     2242             (ULONG) ullFreeQty - ullSpaceNeeded);
     2243    if (ullFreeSpaceWhenComplete == 0) {
     2244      saymsg(MB_OK,
     2245             HWND_DESKTOP,
     2246             NullStr,
     2247             GetPString(IDS_DRIVESPACELIMITEDTMPSAVE),
     2248             pTargetPath,
     2249             szKB);
     2250      return 0;
     2251    }
     2252    else {
     2253      if (ullFreeQty - ullSpaceNeeded > 0) {
     2254        ret = saymsg(MB_YESNO,
     2255                     HWND_DESKTOP,
     2256                     NullStr,
     2257                     GetPString(IDS_DRIVESPACELIMITED),
     2258                     pTargetPath,
     2259                     szKB);
     2260        if (ret == MBID_YES)
     2261          return 0;
     2262        else
     2263          return 2;
     2264      }
     2265      else {
     2266        saymsg(MB_OK,
     2267               HWND_DESKTOP,
     2268               NullStr,
     2269               GetPString(IDS_DRIVESPACEEXCEEDED),
     2270               pTargetPath);
     2271        return 2;
     2272      }
     2273    }
     2274  }
     2275  else
     2276    return 1;
     2277}
     2278
    22182279#pragma alloc_text(MAINWND5,SetSysMenu)
    22192280#pragma alloc_text(MISC1,BoxWindow,PaintRecessedWindow,PostMsg,PaintSTextWindow,IsFm2Window)
    22202281#pragma alloc_text(MISC1,FixSwitchList,FindDirCnr,CurrentRecord,SetShiftState,AddToListboxBottom)
     2282#pragma alloc_text(MISC1,CheckDriveSpaceAvail)
    22212283
    22222284#ifdef FORTIFY
Note: See TracChangeset for help on using the changeset viewer.