Caute, nasiel som celkom dobry zdrojovy kod na vytvorenie filewatcheru, ale neviem pochopit niektore prikazy. Je to pisane v jazyku C++/CLI, nasiel by sa tu nejaky ochotny clovek, ktory by mi poradil alebo aspon odporucil nejaku dobru literaturu, v ktorej je daco o tom popisane? Zaklady programovania v C++/CLI uz mam, ale neviem zohnat nic k tomu filewatcheru. Zvyyraznene veci nevim. Dakujem
Kód:
#include "stdafx.h"
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Security::Permissions;
public ref class Watcher
{
private:
// Definovanie funkcie na zistenie stavu sledovaného súboru.
static void OnChanged( Object^ /*source*/, FileSystemEventArgs^ e ) // FileSystemEventArgs slúži na získanie údajov o sledovanom súbore: FullPath, ChangeType
{
// Vypíše, že bol vytvorený, zmazaný alebo premiestnený súbor.
Console::WriteLine( "File: {0} {1}", e->FullPath, e->ChangeType );
}
// Vytvorenie funkcie na zistenie stavu sledovaného súboru.
static void OnRenamed( Object^ /*source*/, RenamedEventArgs^ e ) // RenamedEventArgs slúži na získanie údajov o premenovaní súboru: OldFullPath, FullPath
{
// Vypíše, že bol sledovaný súbor premenovaný.
Console::WriteLine( "File: {0} renamed to {1}", e->OldFullPath, e->FullPath );
}
public:
[b][PermissionSet(SecurityAction::Demand, Name="FullTrust")] [/b]
int static run()
{
[b] array<String^>^args = System::Environment::GetCommandLineArgs(); [/b]
// If a directory is not specified, exit program.
if ( args->Length != 2 )
{
Console::WriteLine( "Usage: Watcher.exe (directory)" );
return 0;
}
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher^ watcher = gcnew FileSystemWatcher; // Instancia novej triedy.
[b]watcher->Path = args[ 1 ];[/b]
watcher->NotifyFilter = static_cast<NotifyFilters>(NotifyFilters::LastAccess |
NotifyFilters::LastWrite | NotifyFilters::FileName | NotifyFilters::DirectoryName);
watcher->Filter = "*.txt"; // Nastavenie sledovania textových súborov. [b]Na co je ->???[/b]
[b]watcher->Changed += gcnew FileSystemEventHandler( Watcher::OnChanged );
watcher->Created += gcnew FileSystemEventHandler( Watcher::OnChanged );
watcher->Deleted += gcnew FileSystemEventHandler( Watcher::OnChanged );
watcher->Renamed += gcnew RenamedEventHandler( Watcher::OnRenamed );[/b]
watcher->EnableRaisingEvents = true;
// Wait for the user to quit the program.
Console::WriteLine( "Press \'q\' to quit the sample." );
while ( Console::Read() != 'q' );
return 0;
}
};
int main() {
Watcher::run();
}
| Kody vkladaj do znacky [code]. Ďuri