Skip to content

Commit

Permalink
Updated Source Code to v4.3
Browse files Browse the repository at this point in the history
+Added sound detection (audio peak measurement)
+Added Option to cancel shutdown while sound is playing
+Added debug window to show detailed information
+Implemented Log System
+Fixed some bugs
+Code improvements and code commenting
+Improved exception handling
  • Loading branch information
flobaader committed Feb 21, 2016
1 parent f9298b4 commit 7f16674
Show file tree
Hide file tree
Showing 28 changed files with 2,042 additions and 502 deletions.
38 changes: 38 additions & 0 deletions SourceCode/AssemblyInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "stdafx.h"

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;

//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly:AssemblyTitleAttribute(L"Stand-Bye!")];
[assembly:AssemblyDescriptionAttribute(L"An enhancement of the windows standby")];
[assembly:AssemblyConfigurationAttribute(L"")];
[assembly:AssemblyCompanyAttribute(L"Florian Baader, Stephan Le, Matthias Weirich")];
[assembly:AssemblyProductAttribute(L"Stand-Bye!")];
[assembly:AssemblyCopyrightAttribute(L"Copyright (c) 2016 Florian Baader, Stephan Le, Matthias Weirich")];
[assembly:AssemblyTrademarkAttribute(L"")];
[assembly:AssemblyCultureAttribute(L"")];

//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly:AssemblyVersionAttribute("0.4.0")];

[assembly:ComVisible(false)];

[assembly:CLSCompliantAttribute(true)];
79 changes: 71 additions & 8 deletions SourceCode/BasicFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,85 @@ int BasicFunc::StringToInt(std::string str) {
return result;
}

void BasicFunc::Print(std::string str) {
//OutputDebugString(_T(str.c_str()));
//DEBUG(str);
}

System::Drawing::Font^ BasicFunc::getMetroFont(int size) {
System::Drawing::Font^ BasicFunc::getMetroFont(float size) {
return gcnew System::Drawing::Font(L"Microsoft Sans Serif", size);
}

boolean BasicFunc::VectorContains(std::vector<string> list, std::string text)
bool BasicFunc::VectorContains(std::vector<string> list, std::string text)
{
boolean result = false;
bool result = false;
for each(std::string s in list) {
if (s == text) {
result = true;
}
}
return result;
}

System::String ^ BasicFunc::getLogFilePath()
{
using namespace System::IO;
using namespace System::Diagnostics;

//Startup Time
DateTime^ starttime = Process::GetCurrentProcess()->StartTime;

//Path
String^ mainFolder = System::IO::Directory::GetCurrentDirectory();
String^ log_folder = Path::Combine(mainFolder, "logs");
String^ current_date_folder = Path::Combine(log_folder, starttime->ToString("yyyy_MM_dd"));
String^ file_path = Path::Combine(current_date_folder, starttime->ToString("HH_mm") + ".txt");

//Creates Directory if necessary
System::IO::Directory::CreateDirectory(current_date_folder);

return file_path;
}

void BasicFunc::Log(System::String^ text)
{
//Prints message on Debug-Console
System::Diagnostics::Debug::WriteLine(text);

using namespace System::IO;
using namespace System::Diagnostics;

//Line
String^ line = DateTime::Now.ToString("HH:mm:ss:FFF") + "\t" + text;

//Open Stream
StreamWriter^ sw;
try {
sw = File::AppendText(BasicFunc::getLogFilePath());
}
catch (System::Exception^) {
//Could not find / open the file
return;
}

//Appends Text
try {
sw->WriteLine(line);
}
finally
{
if (sw)
delete (IDisposable^)sw;
}
}

bool BasicFunc::isNumerique(std::string text)
{
char* p;
strtol(text.c_str(), &p, 10);
return *p == 0;
}
bool BasicFunc::isNumerique(System::String ^ text)
{
return isNumerique(BasicFunc::StringToString(text));
}

void BasicFunc::Log(std::string text)
{
Log(gcnew String(text.c_str()));
}
24 changes: 19 additions & 5 deletions SourceCode/BasicFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#include <string>
#include <msclr\marshal_cppstd.h> //Converting System::String to std::string
#include <sstream>
using namespace System;

using std::vector;
using std::string;

namespace BasicFunc {
using namespace System;
///<summary>Converts a System::String to a std::string</summary>
string StringToString(System::String^ str);

Expand All @@ -17,10 +17,24 @@ namespace BasicFunc {
///<summary>Converts a std::string to an int</summary>
int StringToInt(string str);

///<summary>Prints an std::string</summary>
void Print(string str);
///<summary>Returns an metro font with specified size in points</summary>
System::Drawing::Font^ getMetroFont(float size);

System::Drawing::Font^ getMetroFont(int size);
///<summary>Returns if an vector of std::string contains a specified std::string</summary>
bool VectorContains(std::vector<string> list, std::string text);

boolean VectorContains(std::vector<string> list, std::string text);
///<summary>Returns the log file path and ensures that the file is accessible</summary>
System::String^ getLogFilePath();

///<summary>Logs an specified statement or event.</summary>
void Log(std::string text);

///<summary>Logs an specified statement or event.</summary>
void Log(System::String^ text);

///<summary>Checks if string only contains numerique characters</summary>
bool isNumerique(std::string text);

///<summary>Checks if string only contains numerique characters</summary>
bool isNumerique(System::String^ text);
}
136 changes: 136 additions & 0 deletions SourceCode/DebugForm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "stdafx.h"
#include "DebugForm.h"
using namespace StandBye;

System::Void StandBye::DebugForm::DebugForm_Load(System::Object ^, System::EventArgs ^)
{
RefreshUISlow();
}

System::Void StandBye::DebugForm::buttonSettingsForm_Click(System::Object ^, System::EventArgs ^)
{
MetroSettingsForm^ form = gcnew MetroSettingsForm(system_watcher, settings_prov);
form->ShowDialog();
}

System::Void StandBye::DebugForm::buttonProcessForm_Click(System::Object ^, System::EventArgs ^)
{
ProcessSelectionForm^ form = gcnew ProcessSelectionForm();
form->ShowDialog();
}

System::Void StandBye::DebugForm::buttonMessageWnd_Click(System::Object ^, System::EventArgs ^)
{
MessageWindow^ wnd = gcnew MessageWindow("This is a test");
wnd->ShowDialog();
}

System::Void StandBye::DebugForm::buttonTimeWnd_Click(System::Object ^, System::EventArgs ^)
{
TimeoutWindow^ wnd = gcnew TimeoutWindow(15, settings_prov);
wnd->ShowDialog();
}

System::String ^ StandBye::DebugForm::getLogText()
{
using namespace System;
using namespace System::IO;

String^ return_string = "";
StreamReader^ sr;

try {
sr = gcnew StreamReader(BasicFunc::getLogFilePath());
while (sr->Peek() >= 0) {
return_string += sr->ReadLine() + "\n";
}
}
catch (System::IO::IOException^) {
//File is opened from an other process
return "";
}
finally{
delete sr;
}

return return_string;

}

void DebugForm::OnTick(System::Object ^, System::EventArgs ^)
{
RefreshUIRealTime();
}

void DebugForm::RefreshUISlow()
{
//ListView Settings
for each(Setting* setting in settings_prov->getAllSettings()) {
String^ name = gcnew String(setting->GetNameAsString().c_str());
string std_value;

//Adds all values to an single String^
for each(string single_value in setting->GetValue()) {
std_value += single_value;
}
String^ value = gcnew String(std_value.c_str());

listViewSettings->Items->Add(name)->SubItems->Add(value);
}

//ListView Processes
//Prepare ListView
listViewProc->View = Windows::Forms::View::Details;
ImageList^ imglistSmall = gcnew ImageList, ^imglistLarge = gcnew ImageList;
imglistSmall->ImageSize = Drawing::Size(24, 24);
imglistLarge->ImageSize = Drawing::Size(50, 50);
listViewProc->SmallImageList = imglistSmall;
listViewProc->LargeImageList = imglistLarge;

for each(std::string path in SystemAccess::GetRunningProccesses()) {
listViewProc->Items->Add(gcnew ProcessItem(path, listViewProc));
}
}

void StandBye::DebugForm::RefreshUIRealTime()
{
//Buffered Values
labelBuffCPU->Text = String::Format("{0:00.0} %", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::CPU));
labelBuffRAM->Text = String::Format("{0:00.0} %", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::RAM));
labelBuffHDD->Text = String::Format("{0:00.0} kBit/s", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::HDD));
labelBuffNET->Text = String::Format("{0:00.0} kBit/s", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::NETWORK));

//Real-Time Values
labelRTCPU->Text = String::Format("{0:00.0} %", system_access->GetMetric(SystemAccess::SystemMetric::CPU));
labelRTRAM->Text = String::Format("{0:00.0} %", system_access->GetMetric(SystemAccess::SystemMetric::RAM));
labelRTHDD->Text = String::Format("{0:00.0} kBit/s", system_access->GetMetric(SystemAccess::SystemMetric::HDD));
labelRTNET->Text = String::Format("{0:00.0} kBit/s", system_access->GetMetric(SystemAccess::SystemMetric::NETWORK));

//Input Info
int lastinput = (int)system_access->GetLastInputTime();
labelInputTime->Text = String::Format("{0} ms", lastinput);

if ((lastinput / 1000) > settings_prov->getThreshold(SettingName::WAIT_TIME)) {
labelWAITReached->Text = "YES";
}
else {
labelWAITReached->Text = "NO";
}

//Sound input
labelSoundPeak->Text = String::Format("{0:0.00}", system_access->getAudioPeak());

if (system_access->getAudioPeak() > 0) {
labelSoundOverLimit->Text = "YES";
}
else {
labelSoundOverLimit->Text = "NO";
}

//Log
if ((textBoxLog->Text != getLogText()) && getLogText() != "") {
textBoxLog->Text = getLogText();
textBoxLog->SelectionStart = textBoxLog->TextLength - 1;
textBoxLog->ScrollToCaret();
}
}
Loading

0 comments on commit 7f16674

Please sign in to comment.