Rev 4 | Rev 8 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4 | Rev 6 | ||
---|---|---|---|
Line 158... | Line 158... | ||
158 | FileTimeToSystemTime(fad.ftCreationTime, systime); |
158 | FileTimeToSystemTime(fad.ftCreationTime, systime); |
159 | 159 | ||
160 | Result := SystemTimeToDateTime(systime); |
160 | Result := SystemTimeToDateTime(systime); |
161 | end; |
161 | end; |
162 | 162 | ||
163 | function UTCTimeToLocalTime(const aValue: TDateTime): TDateTime; |
- | |
164 | var |
- | |
165 | lBias: Integer; |
- | |
166 | lTZI: TTimeZoneInformation; |
- | |
167 | begin |
- | |
168 | lBias := 0; |
- | |
169 | case GetTimeZoneInformation(lTZI) of |
- | |
170 | TIME_ZONE_ID_UNKNOWN: |
- | |
171 | lBias := lTZI.Bias; |
- | |
172 | TIME_ZONE_ID_DAYLIGHT: |
- | |
173 | lBias := lTZI.Bias + lTZI.DaylightBias; |
- | |
174 | TIME_ZONE_ID_STANDARD: |
- | |
175 | lBias := lTZI.Bias + lTZI.StandardBias; |
- | |
176 | end; |
- | |
177 | // UTC = local time + bias |
- | |
178 | // bias is in number of minutes, TDateTime is in days |
- | |
179 | Result := aValue - (lBias / (24 * 60)); |
- | |
180 | end; |
- | |
181 | - | ||
182 | function GetFileSize(const AFileName: String): int64; |
163 | function GetFileSize(const AFileName: String): int64; |
183 | var |
164 | var |
184 | lFindData: TWin32FindData; |
165 | lFindData: TWin32FindData; |
185 | lHandle: Cardinal; |
166 | lHandle: Cardinal; |
186 | begin |
167 | begin |
Line 264... | Line 245... | ||
264 | Result := StringReplace(Result, GUID_EHDD_A, 'EHDD:\', []); |
245 | Result := StringReplace(Result, GUID_EHDD_A, 'EHDD:\', []); |
265 | Result := StringReplace(Result, GUID_EHDD_B, 'EHDD:\', []); |
246 | Result := StringReplace(Result, GUID_EHDD_B, 'EHDD:\', []); |
266 | {$ENDIF} |
247 | {$ENDIF} |
267 | end; |
248 | end; |
268 | 249 | ||
- | 250 | function SpecialCompare(a, b: TDateTime): boolean; // true = same timestamp |
|
- | 251 | begin |
|
- | 252 | if SecondsBetween(a,b) < 2 then exit(true); // equal |
|
- | 253 | ||
- | 254 | if SecondsBetween(a,b) > 7200 then exit(false); |
|
- | 255 | ||
- | 256 | // Minute and Second equal, and difference is < 2h: fair enough, seems to be a DST issue |
|
- | 257 | if copy(TimeToStr(a),4,5) = copy(TimeToStr(b),4,5) then exit(true); |
|
- | 258 | ||
- | 259 | result := false; |
|
- | 260 | end; |
|
- | 261 | ||
269 | procedure TfrmIndexCreator.CheckFile(const originalFileName, |
262 | procedure TfrmIndexCreator.CheckFile(const originalFileName, |
270 | uniqueFilename: string); |
263 | uniqueFilename: string); |
271 | 264 | ||
272 | function DateTimeToSQL(dt: TDateTime): string; |
265 | function DateTimeToSQL(dt: TDateTime): string; |
273 | begin |
266 | begin |
Line 294... | Line 287... | ||
294 | try |
287 | try |
295 | if q.RecordCount = 0 then |
288 | if q.RecordCount = 0 then |
296 | Result := erDoesNotExist |
289 | Result := erDoesNotExist |
297 | else if not q.Fields[0].IsNull then |
290 | else if not q.Fields[0].IsNull then |
298 | Result := erHadError |
291 | Result := erHadError |
299 | else if (q.Fields[1].AsString <> IntToStr(size)) or |
292 | else if (q.Fields[1].AsString <> IntToStr(size)) or // we are combining strings because of int64 |
300 | // we are combining strings because of int64 |
- | |
301 | (SecondsBetween(q.Fields[2].AsDateTime, UTCTimeToLocalTime(modified) |
293 | not SpecialCompare(q.Fields[2].AsDateTime, modified) then |
302 | ) > 2) then |
- | |
303 | begin |
294 | begin |
304 | Result := erChanged |
295 | Result := erChanged |
305 | end |
296 | end |
306 | else |
297 | else |
307 | Result := erUnchanged; |
298 | Result := erUnchanged; |
Line 340... | Line 331... | ||
340 | if not cbSimulate.Checked then |
331 | if not cbSimulate.Checked then |
341 | begin |
332 | begin |
342 | conn.ExecSQL('INSERT INTO ' + TableName + |
333 | conn.ExecSQL('INSERT INTO ' + TableName + |
343 | ' (filename, size, created, modified, md5hash, error) values (' + |
334 | ' (filename, size, created, modified, md5hash, error) values (' + |
344 | conn.SQLStringEscape(VtsSpecial(uniqueFilename)) + ', ' + |
335 | conn.SQLStringEscape(VtsSpecial(uniqueFilename)) + ', ' + |
345 | IntToStr(size) + ', ' + DateTimeToSQL(UTCTimeToLocalTime(created)) + |
336 | IntToStr(size) + ', ' + DateTimeToSQL(created) + |
346 | ', ' + DateTimeToSQL(UTCTimeToLocalTime(modified)) + ', ' + |
337 | ', ' + DateTimeToSQL(modified) + ', ' + |
347 | conn.SQLStringEscape(LowerCase(md5)) + ', NULL);'); |
338 | conn.SQLStringEscape(LowerCase(md5)) + ', NULL);'); |
348 | end; |
339 | end; |
349 | if cbVerboseLogs.Checked then |
340 | if cbVerboseLogs.Checked then |
350 | Memo2.Lines.Add('New: ' + uniqueFilename); |
341 | Memo2.Lines.Add('New: ' + uniqueFilename); |
351 | Inc(sumfiles_new); |
342 | Inc(sumfiles_new); |
Line 362... | Line 353... | ||
362 | begin |
353 | begin |
363 | conn.ExecSQL('INSERT INTO ' + TableName + |
354 | conn.ExecSQL('INSERT INTO ' + TableName + |
364 | ' (filename, size, created, modified, md5hash, error) values (' |
355 | ' (filename, size, created, modified, md5hash, error) values (' |
365 | + conn.SQLStringEscape(VtsSpecial(uniqueFilename)) + ', ' + |
356 | + conn.SQLStringEscape(VtsSpecial(uniqueFilename)) + ', ' + |
366 | IntToStr(size) + ', ' + |
357 | IntToStr(size) + ', ' + |
367 | DateTimeToSQL(UTCTimeToLocalTime(created)) + ', ' + |
358 | DateTimeToSQL(created) + ', ' + |
368 | DateTimeToSQL(UTCTimeToLocalTime(modified)) + ', ' + |
359 | DateTimeToSQL(modified) + ', ' + |
369 | conn.SQLStringEscape(LowerCase(md5)) + ', NULL);'); |
360 | conn.SQLStringEscape(LowerCase(md5)) + ', NULL);'); |
370 | end; |
361 | end; |
371 | if cbVerboseLogs.Checked then |
362 | if cbVerboseLogs.Checked then |
372 | Memo2.Lines.Add('New: ' + uniqueFilename); |
363 | Memo2.Lines.Add('New: ' + uniqueFilename); |
373 | Inc(sumfiles_new); |
364 | Inc(sumfiles_new); |
Line 379... | Line 370... | ||
379 | if not cbSimulate.Checked and (rgModus.ItemIndex <> modusValidation) |
370 | if not cbSimulate.Checked and (rgModus.ItemIndex <> modusValidation) |
380 | then |
371 | then |
381 | begin |
372 | begin |
382 | conn.ExecSQL('UPDATE ' + TableName + ' SET size = ' + |
373 | conn.ExecSQL('UPDATE ' + TableName + ' SET size = ' + |
383 | IntToStr(size) + ', created = ' + |
374 | IntToStr(size) + ', created = ' + |
384 | DateTimeToSQL(UTCTimeToLocalTime(created)) + ', modified = ' + |
375 | DateTimeToSQL(created) + ', modified = ' + |
385 | DateTimeToSQL(UTCTimeToLocalTime(modified)) + ', md5hash = ' + |
376 | DateTimeToSQL(modified) + ', md5hash = ' + |
386 | conn.SQLStringEscape(LowerCase(md5)) + |
377 | conn.SQLStringEscape(LowerCase(md5)) + |
387 | ', error = NULL WHERE filename = ' + conn.SQLStringEscape |
378 | ', error = NULL WHERE filename = ' + conn.SQLStringEscape |
388 | (VtsSpecial(uniqueFilename)) + ';'); |
379 | (VtsSpecial(uniqueFilename)) + ';'); |
389 | end; |
380 | end; |
390 | if cbVerboseLogs.Checked then |
381 | if cbVerboseLogs.Checked then |
391 | Memo2.Lines.Add('Updated: ' + uniqueFilename); |
382 | Memo2.Lines.Add('Updated: ' + uniqueFilename); |
392 | Inc(sumfiles_updated); |
383 | Inc(sumfiles_updated); |
393 | end; |
384 | end; |
394 | erUnchanged: // Date/Time+Size has not changed |
385 | erUnchanged: // Date/Time+Size has not changed |
395 | begin |
386 | begin |
- | 387 | {$REGION 'Update it to correct wrong UTC/DST datasets...'} |
|
- | 388 | conn.ExecSQL('UPDATE ' + TableName + ' SET size = ' + |
|
- | 389 | IntToStr(size) + ', created = ' + |
|
- | 390 | DateTimeToSQL(created) + ', modified = ' + |
|
- | 391 | DateTimeToSQL(modified) + |
|
- | 392 | ', error = NULL WHERE filename = ' + conn.SQLStringEscape |
|
- | 393 | (VtsSpecial(uniqueFilename)) + ';'); |
|
- | 394 | {$ENDREGION} |
|
- | 395 | ||
396 | if rgModus.ItemIndex = modusValidation then |
396 | if rgModus.ItemIndex = modusValidation then |
397 | begin |
397 | begin |
398 | md5 := MD5File(uniqueFilename); |
398 | md5 := MD5File(uniqueFilename); |
399 | if not SameText(md5, lastCheckedMd5) then |
399 | if not SameText(md5, lastCheckedMd5) then |
400 | begin |
400 | begin |
Line 752... | Line 752... | ||
752 | begin |
752 | begin |
753 | ShowMessage('Finished'); |
753 | ShowMessage('Finished'); |
754 | end; |
754 | end; |
755 | *) |
755 | *) |
756 | finally |
756 | finally |
757 | EnableDisableControls(true); |
757 | if not StopRequest then EnableDisableControls(true); |
758 | end; |
758 | end; |
759 | 759 | ||
- | 760 | if not StopRequest then |
|
- | 761 | begin |
|
760 | Beep; |
762 | Beep; |
761 | Label1.Caption := 'Done.'; |
763 | Label1.Caption := 'Done.'; |
762 | Application.ProcessMessages; |
764 | Application.ProcessMessages; |
763 | end; |
765 | end; |
- | 766 | end; |
|
764 | 767 | ||
765 | procedure TfrmIndexCreator.FormClose(Sender: TObject; var Action: TCloseAction); |
768 | procedure TfrmIndexCreator.FormClose(Sender: TObject; var Action: TCloseAction); |
766 | begin |
769 | begin |
767 | StopRequest := true; |
770 | StopRequest := true; |
768 | Action := caFree; // TODO: müssen wir warten bis der prozess angehalten ist? |
771 | Action := caFree; // TODO: müssen wir warten bis der prozess angehalten ist? |