| Autor |
Beitrag |
Tana´Ri
      
Beiträge: 230
|
Verfasst: Mo 15.09.03 14:40
Hi Leute,
hab mal ein prog gesehen, mit dem man Ordner vor Veränderungen schützen kann, dabei tauchte der dialog auf den man bei zugriff auf aktive exe-dateien kennt. Dies ging wenn ich mich recht entsinne mit FindFirstCangeNotification, FindNextCangeNotification und FindCloseCangeNotification. Ich weiss jetzt nicht genau weiter, ich erzeuge das Handle usw. doch wenn ich manipulativ auf den Zielordner einwirke passiert nichts. Ich hatte zum testen dialoge in das CASE eingebaut doch nur der else-teil war betroffen.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
| procedure Thr_DirectoryChangeNotification.Execute;
procedure MsgQueue; var Msg : TMsg; begin if PeekMessage(Msg,hParent,0,0,PM_REMOVE) then case Msg.message of WM_CLOSE, WM_QUIT : Terminate; end; end; begin hNotify:= NotifyFileChange(Path,Typ,Filter); if hNotify <> 0 then try repeat case WaitForSingleObject(hNotify,1000 ) of WAIT_ABANDONED : begin end; WAIT_OBJECT_0 : begin end; WAIT_TIMEOUT : begin end; else begin end; end; MsgQueue; until terminated OR not FindNextChangeNotification(hNotify); finally FindCloseChangeNotification(hNotify); end; end; |
_________________ mfg
Tana´Ri
|
|
Tana´Ri 
      
Beiträge: 230
|
Verfasst: Do 18.09.03 10:22
Hi Leut, sieht wohl so aus als weiß es niemand, naja. Das Prob ist, das er mir nicht in die case WAIT_OBJECT+n hinein springt wenn ein solches ereignis eigentlich stattfinden sollte. Was ich in dem zusammenhang noch öffters gesehen hab sind Events, wenn ichs recht verstanden hab bräuchte ich diese jedoch nicht zwingend. Ich poste meine letzte version mal, vielleicht kann ja doch noch einer helfen, jedenfalls dank ich mal schon im voraus recht herzlich  .
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159:
| unit class_ThrDirectoryChangeNotification;
interface
uses Classes, Windows, Messages, Dialogs;
const
NOTIFY_DIRECTORY_TREE = TRUE; NOTIFY_SPECIFIED_DIRECTORY = FALSE;
type
TNotifyFilterType = ( FILE_NAME, FILE_DIR, FILE_ATTR, FILE_SIZE, FILE_LAST_WRITE, FILE_SECURITY );
TNotifyFilters = set of TNotifyFilterType;
TNotifyType = (OnlyDirectory,DirectoryTree);
Thr_DirectoryChangeNotification = class(TThread)
private
Filter : TNotifyFilters; hParent : THandle; hNotify : array of THandle; bool : Boolean;
public
constructor Create(CreateSuspended: Boolean; FileName: string; NotifyTyp: TNotifyType; NotifyFilter: TNotifyFilters; hOwner: THandle);
protected
procedure Execute; override;
end;
implementation
procedure Thr_DirectoryChangeNotification.Execute; var i: integer;
procedure MsgQueue; var Msg : TMsg; begin if PeekMessage(Msg,hParent,0,0,PM_REMOVE) then case Msg.message of WM_CLOSE, WM_QUIT : Terminate; end; end;
begin if High(hNotify) > -1 then try repeat case WaitForMultipleObjects( High(hNotify), @hNotify, FALSE, 1000 ) of WAIT_ABANDONED : begin ShowMessage('WAIT_ABANDONED'); end; WAIT_OBJECT_0 : begin FindNextChangeNotification(hNotify[0]); end; WAIT_OBJECT_0+1 : begin FindNextChangeNotification(hNotify[1]); end; WAIT_OBJECT_0+2 : begin FindNextChangeNotification(hNotify[2]); end; WAIT_OBJECT_0+3 : begin FindNextChangeNotification(hNotify[3]); end; WAIT_OBJECT_0+4 : begin FindNextChangeNotification(hNotify[4]); end; WAIT_OBJECT_0+5 : begin FindNextChangeNotification(hNotify[5]); end; WAIT_TIMEOUT : begin end; else begin end; end; MsgQueue; until terminated; finally for i:=low(hNotify) to high(hNotify) do FindCloseChangeNotification(hNotify[i]); end; end;
constructor Thr_DirectoryChangeNotification.Create(CreateSuspended: Boolean; FileName: string; NotifyTyp: TNotifyType; NotifyFilter: TNotifyFilters; hOwner: THandle); var a : array [0..5] of THandle; i : integer; const n : integer = 0; begin inherited Create(CreateSuspended); hParent := hOwner; case NotfyType of OnlyDirectory : bool := NOTIFY_SPECIFIED_DIRECTORY; DirectoryTree : bool := NOTIFY_DIRECTORY_TREE; end; if NotifyFilter <> [] then Filter := NotifyFilter else Filter := [FILE_NAME, FILE_DIR, FILE_ATTR, FILE_SIZE, FILE_LAST_WRITE]; for i:=0 to 5 do a[i] := INVALID_HANDLE_VALUE; if (FILE_NAME in Filter) then begin a[0]:= FindFirstChangeNotification(PChar(FileName),bool,FILE_NOTIFY_CHANGE_FILE_NAME); end; if (FILE_DIR in Filter) then begin a[1]:= FindFirstChangeNotification(PChar(FileName),bool,FILE_NOTIFY_CHANGE_DIR_NAME); end; if (FILE_ATTR in Filter) then begin a[2]:= FindFirstChangeNotification(PChar(FileName),bool,FILE_NOTIFY_CHANGE_ATTRIBUTES); end; if (FILE_SIZE in Filter) then begin a[3]:= FindFirstChangeNotification(PChar(FileName),bool,FILE_NOTIFY_CHANGE_SIZE); end; if (FILE_LAST_WRITE in Filter) then begin a[4]:= FindFirstChangeNotification(PChar(FileName),bool,FILE_NOTIFY_CHANGE_LAST_WRITE); end; if (FILE_SECURITY in Filter) then begin a[5]:= FindFirstChangeNotification(PChar(FileName),bool,FILE_NOTIFY_CHANGE_SECURITY); end; for i:=0 to 5 do if a[i] <> INVALID_HANDLE_VALUE then inc(n); SetLength(hNotify,n); n := 0; for i:=0 to 5 do if a[i] <> INVALID_HANDLE_VALUE then begin hNotify[n] := a[i]; inc(n); end; end;
end. |
_________________ mfg
Tana´Ri
|
|
Tana´Ri 
      
Beiträge: 230
|
Verfasst: Do 25.09.03 14:00
Titel: ReadDirectoryChangesW
Hi Leute,
ich habs jetzt auf ner anderen Schiene gemacht, nämlich mit
ReadDirectoryChangesW ();
jedenfalls registriert diese Fkt ob ein Change eintritt, dabei gibt sie einen Bool zurück. Jedenfalls scheint die bei mir immer true zurückzugeben
ich überwache ein verzeichnis und jedesmal wird mein postmessage dadruch ausgelöst, woran könnte das liegen, der ActionCode ist dabei 0.
mein code zu der InnerLoop:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
| PROCEDURE ThrWatchDirectory.ChangeNotification;
var BytesWritten : DWORD;
begin
if DirectoryExists ( fDir ) then begin hFile := CreateFile ( PChar ( fDir ), FILE_LIST_DIRECTORY, FILE_SHARE_WRITE OR FILE_SHARE_READ OR FILE_SHARE_DELETE, NIL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS OR FILE_FLAG_OVERLAPPED, 0 );
if hFile <> INVALID_HANDLE_VALUE then try while not Terminated or ( WaitForSingleObject( hEvent, 0 ) <> WAIT_OBJECT_0 ) do if ReadDirectoryChangesW ( hFile, @fNotifyBuf, SizeOf ( fNotifyBuf ), fWatchSubtree, fNotifyFilter, @BytesWritten, @fOverlapped, NIL ) then PostMessage(hSelf, WM_CHANGE_NOTIFICATION, 0, 0 ); finally CloseHandle ( hFile ); end else raise Exception.Create('INVALID_HANDLE_VALUE'); end else raise Exception.Create('directory doesn´t exist');
end; |
_________________ mfg
Tana´Ri
|
|
lambruco
      
Beiträge: 100
Win 2000/2000 Server/XP
D6 Prof.
|
Verfasst: Fr 26.09.03 13:34
Kann sein das ich jetzt Schwachsinn rede, aber du prüfst die ganze Zeit,
ob nichts passiert.
Setze doch mal ein not vor ReadDirectoryChangesW.
_________________ Wer Rechtschreibfehler findet, kann Sie behalten
|
|
|