More work on the win32 GUI. LogViewer windows are started

This commit is contained in:
Fish 2008-04-25 10:23:21 +00:00
parent c20b55447b
commit 995ed6bd27
11 changed files with 645 additions and 1 deletions

7
.gitattributes vendored
View file

@ -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

View file

@ -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();
}
};
}

View file

@ -0,0 +1,3 @@
#include "StdAfx.h"
#include "LogViewer.h"

130
src/win32/Gui/LogViewer.h Normal file
View file

@ -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>
/// 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.
/// </summary>
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<FileInfo^>^fiArr = di->GetFiles();
// Display the names of the files.
toolStripFileList->Items->AddRange(di->GetFiles("*.log"));
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~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:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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();
}
}
};
}

View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -0,0 +1,3 @@
#include "StdAfx.h"
#include "LogWindow.h"

137
src/win32/Gui/LogWindow.h Normal file
View file

@ -0,0 +1,137 @@
#pragma once
#include "stdafx.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#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>
/// 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.
/// </summary>
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:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~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:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->LogRT = (gcnew System::Windows::Forms::RichTextBox());
this->fileSystemWatcher1 = (gcnew System::IO::FileSystemWatcher());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(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<System::ComponentModel::ISupportInitialize^ >(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();
}
};
}

View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="fileSystemWatcher1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -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

View file

@ -228,6 +228,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\taillogfile.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
@ -244,6 +248,34 @@
>
</File>
</File>
<File
RelativePath=".\LogViewer.cpp"
>
</File>
<File
RelativePath=".\LogViewer.h"
FileType="3"
>
<File
RelativePath=".\LogViewer.resx"
SubType="Designer"
>
</File>
</File>
<File
RelativePath=".\LogWindow.cpp"
>
</File>
<File
RelativePath=".\LogWindow.h"
FileType="3"
>
<File
RelativePath=".\LogWindow.resx"
SubType="Designer"
>
</File>
</File>
<File
RelativePath=".\resource.h"
>

View file

@ -0,0 +1,77 @@
#include "stdafx.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#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);
}
}