Changeset 783 for trunk/dll/dirsize.c
- Timestamp:
- Aug 14, 2007, 6:09:54 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/dirsize.c
r781 r783 28 28 03 Aug 07 SHL DirSizeProc; correct sizing and positioning to be deterministic 29 29 06 Aug 07 GKY Reduce DosSleep times (ticket 148) 30 11 Aug 07 SHL ProcessDir: remove unneeded reallocs 30 13 Aug 07 SHL ProcessDir: remove unneeded reallocs. Sanitize code 31 13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat 31 32 32 33 ***********************************************************************/ … … 68 69 static PSZ pszSrcFile = __FILE__; 69 70 70 #pragma alloc_text(DIRSIZE,ProcessDir,FillCnrThread,DirSizeProc) 71 #pragma alloc_text(DIRSIZE2,PrintToFile,FillInRecSizes,SortSizeCnr) 72 73 static SHORT APIENTRY SortSizeCnr(PMINIRECORDCORE p1, PMINIRECORDCORE p2, 71 static SHORT APIENTRY SortSizeCnr(PMINIRECORDCORE p1, 72 PMINIRECORDCORE p2, 74 73 PVOID SortFlags) 75 74 { … … 95 94 register char *sp; 96 95 register char *pp; 97 ULONG nm;96 ULONG ulFindCnt; 98 97 ULONGLONG ullCurDirBytes = 0; 99 98 ULONGLONG ullSubDirBytes = 0; 100 99 ULONGLONG ull; 101 100 HDIR hdir; 102 FILEFINDBUF4 *pffb;101 PFILEFINDBUF4 pffbArray; 103 102 APIRET rc; 104 103 RECORDINSERT ri; 105 104 PCNRITEM pci; 106 107 // fixme to report errors 105 ULONG ulBufBytes; 106 108 107 *pullTotalBytes = 0; // In case we fail 109 108 110 pffb = xmalloc(sizeof(FILEFINDBUF4) * FilesToGet, pszSrcFile, __LINE__); 111 if (!pffb) 109 ulBufBytes = sizeof(FILEFINDBUF4) * FilesToGet; 110 pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__); 111 if (!pffbArray) 112 112 return FALSE; // Error already reported 113 113 … … 119 119 120 120 hdir = HDIR_CREATE; 121 nm = 1; 122 // 11 Aug 07 SHL fixme to know if we can bypass memset 123 memset(pffb, 0, sizeof(FILEFINDBUF4)); 121 ulFindCnt = 1; 122 // memset(pffbArray, 0, sizeof(FILEFINDBUF4)); // 11 Aug 07 SHL bypass memset 124 123 DosError(FERR_DISABLEHARDERR); 125 124 // Check directory exists … … 127 126 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED | 128 127 FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY, 129 pffb , sizeof(FILEFINDBUF4), &nm, FIL_QUERYEASIZE);128 pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZE); 130 129 131 130 if (!rc) … … 137 136 * requesting EASIZE. sheesh. 138 137 */ 139 if ((!rc && (pffb ->attrFile & FILE_DIRECTORY)) || strlen(pszFileName) < 4) {138 if ((!rc && (pffbArray->attrFile & FILE_DIRECTORY)) || strlen(pszFileName) < 4) { 140 139 if (*pchStopFlag) { 141 free(pffb );140 free(pffbArray); 142 141 return FALSE; 143 142 } … … 145 144 MPFROMLONG(1)); 146 145 if (!pci) { 147 free(pffb); 146 Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_ALLOCRECORD"); 147 free(pffbArray); 148 148 return FALSE; 149 149 } 150 150 if (!rc) { 151 ullCurDirBytes = pffb ->cbFile;152 ullCurDirBytes += CBLIST_TO_EASIZE(pffb ->cbList);151 ullCurDirBytes = pffbArray->cbFile; 152 ullCurDirBytes += CBLIST_TO_EASIZE(pffbArray->cbList); 153 153 } 154 154 else … … 161 161 else { 162 162 // No match 163 free(pffb );163 free(pffbArray); 164 164 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, 165 165 GetPString(IDS_CANTFINDDIRTEXT), pszFileName); … … 186 186 pci->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__); 187 187 } 188 // fixme to know why - itappears to be indirectly saving length, but why?188 // fixme to understand this - appears to be indirectly saving length, but why? 189 189 pci->pszDisplayName = pci->pszFileName + strlen(pci->pszFileName); 190 190 pci->pszLongName = pci->pszFileName; // fixme to be sure? … … 204 204 ri.fInvalidateRecord = TRUE; 205 205 if (!WinSendMsg(hwndCnr, CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) { 206 free(pffb );206 free(pffbArray); 207 207 return FALSE; 208 208 } … … 210 210 // Find files and directories in this directory 211 211 hdir = HDIR_CREATE; 212 nm = FilesToGet; 212 // 13 Aug 07 SHL fixme to know if need to support fRemoteBug here like objcnr.c? 213 ulFindCnt = FilesToGet; 213 214 rc = DosFindFirst(maskstr, &hdir, 214 215 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED | 215 216 FILE_SYSTEM | FILE_HIDDEN | FILE_DIRECTORY, 216 pffb , nm * sizeof(FILEFINDBUF4), &nm, FIL_QUERYEASIZE);217 pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZE); 217 218 if (!rc) { 218 PBYTE fb = (PBYTE)pffb; 219 FILEFINDBUF4 *pffbFile; 219 PFILEFINDBUF4 pffbFile; 220 220 ULONG x; 221 221 222 222 while (!rc) { 223 224 #if 0 // 13 Aug 07 SHL fixme to be gone 225 { 226 static ULONG ulMaxCnt = 1; 227 if (ulFindCnt > ulMaxCnt) { 228 ulMaxCnt = ulFindCnt; 229 DbgMsg(pszSrcFile, __LINE__, "ulMaxCnt %u/%u", ulMaxCnt, FilesToGet); 230 } 231 } 232 #endif 233 223 234 priority_normal(); 224 for (x = 0; x < nm; x++) {225 pffbFile = (FILEFINDBUF4 *)fb; 235 pffbFile = pffbArray; 236 for (x = 0; x < ulFindCnt; x++) { 226 237 // Total size skipping . and .. 227 238 if ((~pffbFile->attrFile & FILE_DIRECTORY) || … … 232 243 ullCurDirBytes += CBLIST_TO_EASIZE(pffbFile->cbList) & 0x3ff; 233 244 234 if (!(pffbFile->attrFile & FILE_DIRECTORY))235 pci->attrFile++; // Bump file count236 245 if (*pchStopFlag) 237 246 break; 238 if (pffbFile->attrFile & FILE_DIRECTORY) { 247 if (~pffbFile->attrFile & FILE_DIRECTORY) 248 pci->attrFile++; // Bump file count 249 else { 239 250 // Recurse into subdir 240 251 strcpy(pEndMask, pffbFile->achName); // Append dirname to base dirname 241 if (!*pchStopFlag) { 242 ProcessDir(hwndCnr, maskstr, pci, pchStopFlag, FALSE, &ull); 243 ullSubDirBytes += ull; 244 } 252 ProcessDir(hwndCnr, maskstr, pci, pchStopFlag, FALSE, &ull); 253 ullSubDirBytes += ull; 245 254 } 246 255 } 247 256 if (!pffbFile->oNextEntryOffset) 248 257 break; 249 fb += pffbFile->oNextEntryOffset; 258 pffbFile = (PFILEFINDBUF4)((PBYTE)pffbFile + pffbFile->oNextEntryOffset); 259 260 #if 0 // 13 Aug 07 SHL fixme to be gone 261 { 262 static ULONG ulMaxBytes = 65535; 263 ULONG ul = (PBYTE)pffbFile - (PBYTE)pffbArray; 264 if (ul > ulMaxBytes) { 265 ulMaxBytes = ul; 266 DbgMsg(pszSrcFile, __LINE__, "ulFindCnt %u/%u ulMaxBytes %u/%u", 267 ulFindCnt, FilesToGet, ulMaxBytes, ulBufBytes); 268 } 269 } 270 #endif 271 250 272 } // for matches 251 273 if (*pchStopFlag) 252 274 break; 253 DosSleep( 1);254 nm= FilesToGet;275 DosSleep(0); 276 ulFindCnt = FilesToGet; 255 277 DosError(FERR_DISABLEHARDERR); 256 rc = DosFindNext(hdir, pffb , sizeof(FILEFINDBUF4) * FilesToGet, &nm);278 rc = DosFindNext(hdir, pffbArray, ulBufBytes, &ulFindCnt); 257 279 } // while more found 258 259 if (rc != ERROR_NO_MORE_FILES) {260 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,261 GetPString(IDS_CANTFINDDIRTEXT), pszFileName);262 }263 280 264 281 DosFindClose(hdir); … … 266 283 } // if got files or directories 267 284 268 free(pffb); 285 if (rc && rc != ERROR_NO_MORE_FILES) { 286 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__, 287 GetPString(IDS_CANTFINDDIRTEXT), pszFileName); 288 } 289 290 free(pffbArray); 269 291 270 292 pci->cbFile = ullCurDirBytes; … … 407 429 } 408 430 409 static VOID FillCnrThread(VOID * 431 static VOID FillCnrThread(VOID *args) 410 432 { 411 433 HAB hab; 412 434 HMQ hmq; 413 DIRSIZE *dirsize = (DIRSIZE *) 435 DIRSIZE *dirsize = (DIRSIZE *)args; 414 436 HWND hwndCnr; 415 437 ULONGLONG ull; 416 438 417 if (!dirsize) 439 if (!dirsize) { 440 Runtime_Error(pszSrcFile, __LINE__, "no data"); 418 441 return; 442 } 443 419 444 hwndCnr = dirsize->hwndCnr; 420 445 … … 965 990 return WinDefDlgProc(hwnd, msg, mp1, mp2); 966 991 } 992 993 #pragma alloc_text(DIRSIZE,ProcessDir,FillCnrThread,DirSizeProc) 994 #pragma alloc_text(DIRSIZE2,PrintToFile,FillInRecSizes,SortSizeCnr) 995
Note:
See TracChangeset
for help on using the changeset viewer.