thedarkness
// dirwatcher.cpp : main project file.
#include "stdafx.h" System::Void serialize( System::Xml::Serialization::XmlSerializer^ xs, System:ateTime^ timeLastWritten ) { System::Xml::XmlTextWriter^ writer = ( gcnew System::Xml::XmlTextWriter( "tlw.xml", System::Text::Encoding::UTF8 ) ); writer->Formatting = System::Xml::Formatting::Indented; try { xs->Serialize( writer, timeLastWritten ); } catch( System::Exception^ e ) { System::Console::WriteLine( e->InnerException->Message ); } writer->Close(); } int main(array<System::String ^> ^args) { System::String^ sTargetDir = "C:\some\directory\I\want\to\watch"; System::IO:irectoryInfo^ dir = ( gcnew System::IO:irectoryInfo( sTargetDir) ); System:ateTime^ timeLastWritten = dir->LastWriteTime; System::Xml::Serialization::XmlSerializer^ xs = ( gcnew System::Xml::Serialization::XmlSerializer( timeLastWritten->GetType() ) ); if( System::IO::File::Exists( "tlw.xml" ) ) { System::Xml::XmlTextReader^ reader = ( gcnew System::Xml::XmlTextReader( "tlw.xml" ) ); System:ateTime^ savedTimeLastWritten = dynamic_cast<System:ateTime^>( xs->eserialize( reader ) ); reader->Close(); if( savedTimeLastWritten->Equals( timeLastWritten ) ) return 0; else { System::Windows::Forms:ialogResult confirmed = System::Windows::Forms::MessageBox::Show( "The Target Directory has Changed!", "irWatcher", System::Windows::Forms::MessageBoxButtons::OKCancel, System::Windows::Forms::MessageBoxIcon::Stop ); if( confirmed == System::Windows::Forms:ialogResult::OK ) { serialize( xs, timeLastWritten ); } } return 0; } serialize( xs, timeLastWritten ); return 0; } perkiset
TD -
I used a function years ago that popped an event when a DIR changed in any way (W2K)... is this the .NETreplacement for such, or is this an augmentation? I'm a little lost in the code to know what it's doing at all...nutballs
hijack===
this is why i cant get going in .netSystem::Windows::Forms::MessageBoxButtons::OKCancel System::Xml::Serialization::XmlSerializer and those arent even that bad... god i really gotta just jump into it. maybe i can really screw myself up and PHP.nethijack=== thedarkness
quote author=perkiset link=topic=127.msg668#msg668 date=1177632630 TD - I used a function years ago that popped an event when a DIR changed in any way (W2K)... is this the .NETreplacement for such, or is this an augmentation? I'm a little lost in the code to know what it's doing at all...It just checks the last write time of the directory and serializes it to disk, then on subsequent runs it reads (and unserializes) the last write time on the directory to see if it's changed, if it has it shows an alert. Cheers, td thedarkness
quote author=nutballs link=topic=127.msg676#msg676 date=1177638118 hijack=== this is why i cant get going in .netSystem::Windows::Forms::MessageBoxButtons::OKCancel System::Xml::Serialization::XmlSerializer and those arent even that bad... god i really gotta just jump into it. maybe i can really screw myself up and PHP.nethijack=== These can be reduced by using, for example; using namespace System::Windows::Forms; You can then refer to MessageBoxButtons::OKCancel using namespace System::Xml::Serialization; would allow you to change System::Xml::Serialization::XmlSerializer to just XmlSerializer Not as bad as brainfish Cheers, td |
Thread Categories
Best of The Cache Home | ||
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads