diff --git a/.gitattributes b/.gitattributes index 25166ff4..edfb6716 100644 --- a/.gitattributes +++ b/.gitattributes @@ -560,6 +560,12 @@ src/typemap -text src/win32/Gui/AssemblyInfo.cpp -text src/win32/Gui/Form1.h -text src/win32/Gui/Form1.resx -text +src/win32/Gui/LogViewer.cpp -text +src/win32/Gui/LogViewer.h -text +src/win32/Gui/LogViewer.resx -text +src/win32/Gui/LogWindow.cpp -text +src/win32/Gui/LogWindow.h -text +src/win32/Gui/LogWindow.resx -text src/win32/Gui/NeoStats[!!-~]Control[!!-~]Panel.cpp -text src/win32/Gui/NeoStats[!!-~]Control[!!-~]Panel.sln -text src/win32/Gui/NeoStats[!!-~]Control[!!-~]Panel.vcproj -text @@ -568,6 +574,7 @@ src/win32/Gui/app.rc -text src/win32/Gui/resource.h -text src/win32/Gui/stdafx.cpp -text src/win32/Gui/stdafx.h -text +src/win32/Gui/taillogfile.cpp -text src/win32/Rules.rules -text src/win32/ServiceTest/ServiceTest.cpp -text src/win32/ServiceTest/ServiceTest.vcproj -text diff --git a/src/win32/Gui/Form1.h b/src/win32/Gui/Form1.h index 2e94f766..6dbc5273 100644 --- a/src/win32/Gui/Form1.h +++ b/src/win32/Gui/Form1.h @@ -1,5 +1,5 @@ #pragma once - +#include "LogViewer.h" namespace NeoStatsControlPanel { @@ -287,6 +287,7 @@ namespace NeoStatsControlPanel { this->logViewerToolStripMenuItem->Name = L"logViewerToolStripMenuItem"; this->logViewerToolStripMenuItem->Size = System::Drawing::Size(77, 20); this->logViewerToolStripMenuItem->Text = L"Log Viewer"; + this->logViewerToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::logViewerToolStripMenuItem_Click); // // process1 // @@ -407,6 +408,11 @@ private: System::Void process1_Exited(System::Object^ sender, System::EventArgs System::Diagnostics::Debug::WriteLine(this->process1->ExitCode); } +private: System::Void logViewerToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { + LogViewer^ lv; + lv = (gcnew LogViewer()); + lv->Show(); + } }; } diff --git a/src/win32/Gui/LogViewer.cpp b/src/win32/Gui/LogViewer.cpp new file mode 100644 index 00000000..e5095b1a --- /dev/null +++ b/src/win32/Gui/LogViewer.cpp @@ -0,0 +1,3 @@ +#include "StdAfx.h" +#include "LogViewer.h" + diff --git a/src/win32/Gui/LogViewer.h b/src/win32/Gui/LogViewer.h new file mode 100644 index 00000000..59a0e317 --- /dev/null +++ b/src/win32/Gui/LogViewer.h @@ -0,0 +1,130 @@ +#pragma once +#include "LogWindow.h" + +using namespace System; +using namespace System::ComponentModel; +using namespace System::Collections; +using namespace System::Windows::Forms; +using namespace System::Data; +using namespace System::Drawing; +using namespace System::IO; + + +namespace NeoStatsControlPanel { + + /// + /// Summary for LogViewer + /// + /// WARNING: If you change the name of this class, you will need to change the + /// 'Resource File Name' property for the managed resource compiler tool + /// associated with all .resx files this class depends on. Otherwise, + /// the designers will not be able to interact properly with localized + /// resources associated with this form. + /// + public ref class LogViewer : public System::Windows::Forms::Form + { + public: + LogViewer(void) + { + InitializeComponent(); + DirectoryInfo^ di = gcnew DirectoryInfo( "c:\\windows\\temp\\" ); + // Get a reference to each file in that directory. + array^fiArr = di->GetFiles(); + + // Display the names of the files. + toolStripFileList->Items->AddRange(di->GetFiles("*.log")); + + // + //TODO: Add the constructor code here + // + } + + protected: + /// + /// Clean up any resources being used. + /// + ~LogViewer() + { + if (components) + { + delete components; + } +// this->LWS->Values(); + for each(LogWindow^ mywin in this->LWS->Values) { + mywin->Close(); + } + + } + private: System::Windows::Forms::ToolStrip^ toolStrip1; + private: System::Windows::Forms::ToolStripComboBox^ toolStripFileList; + private: Hashtable^ LWS; + protected: + + + private: + /// + /// Required designer variable. + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip()); + this->toolStripFileList = (gcnew System::Windows::Forms::ToolStripComboBox()); + this->toolStrip1->SuspendLayout(); + this->SuspendLayout(); + // + // toolStrip1 + // + this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->toolStripFileList}); + this->toolStrip1->Location = System::Drawing::Point(0, 0); + this->toolStrip1->Name = L"toolStrip1"; + this->toolStrip1->Size = System::Drawing::Size(610, 25); + this->toolStrip1->TabIndex = 2; + this->toolStrip1->Text = L"toolStrip1"; + // + // toolStripFileList + // + this->toolStripFileList->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList; + this->toolStripFileList->Name = L"toolStripFileList"; + this->toolStripFileList->Size = System::Drawing::Size(75, 25); + this->toolStripFileList->SelectedIndexChanged += gcnew System::EventHandler(this, &LogViewer::toolStripFileList_SelectedIndexChanged); + // + // LogViewer + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(610, 470); + this->Controls->Add(this->toolStrip1); + this->IsMdiContainer = true; + this->Name = L"LogViewer"; + this->Text = L"LogViewer"; + this->toolStrip1->ResumeLayout(false); + this->toolStrip1->PerformLayout(); + this->LWS = gcnew Hashtable; + this->ResumeLayout(false); + this->PerformLayout(); + + } +#pragma endregion + private: System::Void toolStripFileList_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) { + if (!this->LWS[toolStripFileList->SelectedItem]) { + LogWindow^ newwin = gcnew LogWindow(); + this->LWS->Add(toolStripFileList->SelectedItem, newwin); + newwin->Tag = toolStripFileList->SelectedItem; + newwin->Text = toolStripFileList->SelectedItem->ToString(); + newwin->MdiParent = this; + newwin->SetLogFile("c:\\windows\\temp\\" + toolStripFileList->SelectedItem->ToString()); + newwin->Show(); + } else { + LogWindow^ newwin = (LogWindow^ )this->LWS[toolStripFileList->SelectedItem]; + newwin->BringToFront(); + } + } + }; +} diff --git a/src/win32/Gui/LogViewer.resx b/src/win32/Gui/LogViewer.resx new file mode 100644 index 00000000..36f2967b --- /dev/null +++ b/src/win32/Gui/LogViewer.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/src/win32/Gui/LogWindow.cpp b/src/win32/Gui/LogWindow.cpp new file mode 100644 index 00000000..770d97a2 --- /dev/null +++ b/src/win32/Gui/LogWindow.cpp @@ -0,0 +1,3 @@ +#include "StdAfx.h" +#include "LogWindow.h" + diff --git a/src/win32/Gui/LogWindow.h b/src/win32/Gui/LogWindow.h new file mode 100644 index 00000000..a80ef475 --- /dev/null +++ b/src/win32/Gui/LogWindow.h @@ -0,0 +1,137 @@ +#pragma once +#include "stdafx.h" +#include +#include +#include +#include "windows.h" + +using namespace System; +using namespace System::ComponentModel; +using namespace System::Collections; +using namespace System::Windows::Forms; +using namespace System::Data; +using namespace System::Drawing; +using namespace System::IO; + + +namespace NeoStatsControlPanel { + + /// + /// Summary for LogWindow + /// + /// WARNING: If you change the name of this class, you will need to change the + /// 'Resource File Name' property for the managed resource compiler tool + /// associated with all .resx files this class depends on. Otherwise, + /// the designers will not be able to interact properly with localized + /// resources associated with this form. + /// + public ref class LogWindow : public System::Windows::Forms::Form + { + public: + LogWindow(void) + { + InitializeComponent(); + // + //TODO: Add the constructor code here + // + } + void SetLogFile(String^ file) + { + + this->fileSystemWatcher1->Path = Path::GetDirectoryName(file); + this->fileSystemWatcher1->Filter = Path::GetFileName(file); + this->din = gcnew FileStream(file, FileMode::Open, FileAccess::Read, FileShare::ReadWrite); + this->din2 = gcnew StreamReader(this->din); + String^ str; + while ((str = this->din2->ReadLine()) != nullptr) + { + if (this->LogRT->TextLength > 0) + this->LogRT->Text = this->LogRT->Text + "\n" + str; + else + this->LogRT->Text = str; + } + + } + + + + + protected: + /// + /// Clean up any resources being used. + /// + ~LogWindow() + { + if (components) + { + delete components; + } + } + private: System::Windows::Forms::RichTextBox^ LogRT; + private: System::IO::FileSystemWatcher^ fileSystemWatcher1; + private: FileStream^ din; + private: StreamReader ^din2; + protected: + + protected: + + private: + /// + /// Required designer variable. + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent(void) + { + this->LogRT = (gcnew System::Windows::Forms::RichTextBox()); + this->fileSystemWatcher1 = (gcnew System::IO::FileSystemWatcher()); + (cli::safe_cast(this->fileSystemWatcher1))->BeginInit(); + this->SuspendLayout(); + // + // LogRT + // + this->LogRT->Location = System::Drawing::Point(12, 12); + this->LogRT->Name = L"LogRT"; + this->LogRT->ReadOnly = true; + this->LogRT->Size = System::Drawing::Size(260, 240); + this->LogRT->TabIndex = 0; + this->LogRT->Text = L""; + // + // fileSystemWatcher1 + // + this->fileSystemWatcher1->EnableRaisingEvents = true; + this->fileSystemWatcher1->NotifyFilter = System::IO::NotifyFilters::LastWrite; + this->fileSystemWatcher1->SynchronizingObject = this; + this->fileSystemWatcher1->Changed += gcnew System::IO::FileSystemEventHandler(this, &LogWindow::fileSystemWatcher1_Changed); + // + // LogWindow + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(284, 264); + this->Controls->Add(this->LogRT); + this->Name = L"LogWindow"; + this->Text = L"LogWindow"; + (cli::safe_cast(this->fileSystemWatcher1))->EndInit(); + this->ResumeLayout(false); + + } +#pragma endregion + private: System::Void fileSystemWatcher1_Changed(System::Object^ sender, System::IO::FileSystemEventArgs^ e) { + int i; + Char b; + while ((i = this->din2->Read()) != -1) + { + b = (char)i; + this->LogRT->AppendText(b.ToString(i)); + } + this->LogRT->ScrollToCaret(); + } + + }; +} diff --git a/src/win32/Gui/LogWindow.resx b/src/win32/Gui/LogWindow.resx new file mode 100644 index 00000000..5882351c --- /dev/null +++ b/src/win32/Gui/LogWindow.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/src/win32/Gui/NeoStats Control Panel.sln b/src/win32/Gui/NeoStats Control Panel.sln index 17775619..915e92e7 100644 --- a/src/win32/Gui/NeoStats Control Panel.sln +++ b/src/win32/Gui/NeoStats Control Panel.sln @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 10.00 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NeoStats Control Panel", "NeoStats Control Panel.vcproj", "{FACB5498-CC3E-415A-96E5-91737F986A52}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServiceTest", "..\ServiceTest\ServiceTest.vcproj", "{9504558B-6EF4-4ECE-AA2B-00C1AD9C5F4C}" + ProjectSection(ProjectDependencies) = postProject + {FACB5498-CC3E-415A-96E5-91737F986A52} = {FACB5498-CC3E-415A-96E5-91737F986A52} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/win32/Gui/NeoStats Control Panel.vcproj b/src/win32/Gui/NeoStats Control Panel.vcproj index 39354537..c3769cea 100644 --- a/src/win32/Gui/NeoStats Control Panel.vcproj +++ b/src/win32/Gui/NeoStats Control Panel.vcproj @@ -228,6 +228,10 @@ /> + + + + + + + + + + + + + + diff --git a/src/win32/Gui/taillogfile.cpp b/src/win32/Gui/taillogfile.cpp new file mode 100644 index 00000000..3182c60a --- /dev/null +++ b/src/win32/Gui/taillogfile.cpp @@ -0,0 +1,77 @@ +#include "stdafx.h" +#include +#include +#include +#include "windows.h" + +char* getftime(char *fname) +{ + char *rtn = new char[99]; + char modt[99]; + struct _stat buf; + _stat( fname, &buf ); + strcpy(modt, ctime( &buf.st_atime )); + strcpy(rtn,modt); + return rtn; +} + + +long getfnoc(FILE * pFile) +{ + long fnoc=0; + while(!feof(pFile)) + { + fgetc(pFile); + fnoc++; + } + fseek( pFile, 0, SEEK_SET); + return fnoc; +} + + + +void tailmain(int argc, char *argv[]) +{ + + FILE *pFile; + + if(argc<2){printf("Usage: Tail [filepath]\n");return;} + + pFile =fopen (argv[1],"r"); + if(pFile==NULL){printf("File Status: NULL\n");return;} + + long fnoc = getfnoc(pFile); + fclose(pFile); + + char *modt = getftime(argv[1]); + + while(TRUE) + { + char *tmp = getftime(argv[1]); + + if(strcmp(modt,tmp)!=0) + { + strcpy(modt,tmp); + + pFile =fopen (argv[1],"r"); + long fnoccur = getfnoc(pFile); + + long charno = 0; + + while(TRUE) + { + char c=fgetc(pFile); + if(++charno>=fnoc)printf("%c",c); + if(feof(pFile) || charno==fnoccur-1)break; + } + + fclose (pFile); + + fnoc=fnoccur; + + } + + Sleep(100); + } + +} \ No newline at end of file