Skip to content

Commit 7f16674

Browse files
committed
Updated Source Code to v4.3
+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
1 parent f9298b4 commit 7f16674

28 files changed

Lines changed: 2042 additions & 502 deletions

SourceCode/AssemblyInfo.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "stdafx.h"
2+
3+
using namespace System;
4+
using namespace System::Reflection;
5+
using namespace System::Runtime::CompilerServices;
6+
using namespace System::Runtime::InteropServices;
7+
using namespace System::Security::Permissions;
8+
9+
//
10+
// General Information about an assembly is controlled through the following
11+
// set of attributes. Change these attribute values to modify the information
12+
// associated with an assembly.
13+
//
14+
[assembly:AssemblyTitleAttribute(L"Stand-Bye!")];
15+
[assembly:AssemblyDescriptionAttribute(L"An enhancement of the windows standby")];
16+
[assembly:AssemblyConfigurationAttribute(L"")];
17+
[assembly:AssemblyCompanyAttribute(L"Florian Baader, Stephan Le, Matthias Weirich")];
18+
[assembly:AssemblyProductAttribute(L"Stand-Bye!")];
19+
[assembly:AssemblyCopyrightAttribute(L"Copyright (c) 2016 Florian Baader, Stephan Le, Matthias Weirich")];
20+
[assembly:AssemblyTrademarkAttribute(L"")];
21+
[assembly:AssemblyCultureAttribute(L"")];
22+
23+
//
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the value or you can default the Revision and Build Numbers
32+
// by using the '*' as shown below:
33+
34+
[assembly:AssemblyVersionAttribute("0.4.0")];
35+
36+
[assembly:ComVisible(false)];
37+
38+
[assembly:CLSCompliantAttribute(true)];

SourceCode/BasicFunc.cpp

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,85 @@ int BasicFunc::StringToInt(std::string str) {
2525
return result;
2626
}
2727

28-
void BasicFunc::Print(std::string str) {
29-
//OutputDebugString(_T(str.c_str()));
30-
//DEBUG(str);
31-
}
32-
33-
System::Drawing::Font^ BasicFunc::getMetroFont(int size) {
28+
System::Drawing::Font^ BasicFunc::getMetroFont(float size) {
3429
return gcnew System::Drawing::Font(L"Microsoft Sans Serif", size);
3530
}
3631

37-
boolean BasicFunc::VectorContains(std::vector<string> list, std::string text)
32+
bool BasicFunc::VectorContains(std::vector<string> list, std::string text)
3833
{
39-
boolean result = false;
34+
bool result = false;
4035
for each(std::string s in list) {
4136
if (s == text) {
4237
result = true;
4338
}
4439
}
4540
return result;
41+
}
42+
43+
System::String ^ BasicFunc::getLogFilePath()
44+
{
45+
using namespace System::IO;
46+
using namespace System::Diagnostics;
47+
48+
//Startup Time
49+
DateTime^ starttime = Process::GetCurrentProcess()->StartTime;
50+
51+
//Path
52+
String^ mainFolder = System::IO::Directory::GetCurrentDirectory();
53+
String^ log_folder = Path::Combine(mainFolder, "logs");
54+
String^ current_date_folder = Path::Combine(log_folder, starttime->ToString("yyyy_MM_dd"));
55+
String^ file_path = Path::Combine(current_date_folder, starttime->ToString("HH_mm") + ".txt");
56+
57+
//Creates Directory if necessary
58+
System::IO::Directory::CreateDirectory(current_date_folder);
59+
60+
return file_path;
61+
}
62+
63+
void BasicFunc::Log(System::String^ text)
64+
{
65+
//Prints message on Debug-Console
66+
System::Diagnostics::Debug::WriteLine(text);
67+
68+
using namespace System::IO;
69+
using namespace System::Diagnostics;
70+
71+
//Line
72+
String^ line = DateTime::Now.ToString("HH:mm:ss:FFF") + "\t" + text;
73+
74+
//Open Stream
75+
StreamWriter^ sw;
76+
try {
77+
sw = File::AppendText(BasicFunc::getLogFilePath());
78+
}
79+
catch (System::Exception^) {
80+
//Could not find / open the file
81+
return;
82+
}
83+
84+
//Appends Text
85+
try {
86+
sw->WriteLine(line);
87+
}
88+
finally
89+
{
90+
if (sw)
91+
delete (IDisposable^)sw;
92+
}
93+
}
94+
95+
bool BasicFunc::isNumerique(std::string text)
96+
{
97+
char* p;
98+
strtol(text.c_str(), &p, 10);
99+
return *p == 0;
100+
}
101+
bool BasicFunc::isNumerique(System::String ^ text)
102+
{
103+
return isNumerique(BasicFunc::StringToString(text));
104+
}
105+
106+
void BasicFunc::Log(std::string text)
107+
{
108+
Log(gcnew String(text.c_str()));
46109
}

SourceCode/BasicFunc.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#include <string>
33
#include <msclr\marshal_cppstd.h> //Converting System::String to std::string
44
#include <sstream>
5-
using namespace System;
65

76
using std::vector;
87
using std::string;
98

109
namespace BasicFunc {
10+
using namespace System;
1111
///<summary>Converts a System::String to a std::string</summary>
1212
string StringToString(System::String^ str);
1313

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

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

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

25-
boolean VectorContains(std::vector<string> list, std::string text);
26+
///<summary>Returns the log file path and ensures that the file is accessible</summary>
27+
System::String^ getLogFilePath();
28+
29+
///<summary>Logs an specified statement or event.</summary>
30+
void Log(std::string text);
31+
32+
///<summary>Logs an specified statement or event.</summary>
33+
void Log(System::String^ text);
34+
35+
///<summary>Checks if string only contains numerique characters</summary>
36+
bool isNumerique(std::string text);
37+
38+
///<summary>Checks if string only contains numerique characters</summary>
39+
bool isNumerique(System::String^ text);
2640
}

SourceCode/DebugForm.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#include "stdafx.h"
2+
#include "DebugForm.h"
3+
using namespace StandBye;
4+
5+
System::Void StandBye::DebugForm::DebugForm_Load(System::Object ^, System::EventArgs ^)
6+
{
7+
RefreshUISlow();
8+
}
9+
10+
System::Void StandBye::DebugForm::buttonSettingsForm_Click(System::Object ^, System::EventArgs ^)
11+
{
12+
MetroSettingsForm^ form = gcnew MetroSettingsForm(system_watcher, settings_prov);
13+
form->ShowDialog();
14+
}
15+
16+
System::Void StandBye::DebugForm::buttonProcessForm_Click(System::Object ^, System::EventArgs ^)
17+
{
18+
ProcessSelectionForm^ form = gcnew ProcessSelectionForm();
19+
form->ShowDialog();
20+
}
21+
22+
System::Void StandBye::DebugForm::buttonMessageWnd_Click(System::Object ^, System::EventArgs ^)
23+
{
24+
MessageWindow^ wnd = gcnew MessageWindow("This is a test");
25+
wnd->ShowDialog();
26+
}
27+
28+
System::Void StandBye::DebugForm::buttonTimeWnd_Click(System::Object ^, System::EventArgs ^)
29+
{
30+
TimeoutWindow^ wnd = gcnew TimeoutWindow(15, settings_prov);
31+
wnd->ShowDialog();
32+
}
33+
34+
System::String ^ StandBye::DebugForm::getLogText()
35+
{
36+
using namespace System;
37+
using namespace System::IO;
38+
39+
String^ return_string = "";
40+
StreamReader^ sr;
41+
42+
try {
43+
sr = gcnew StreamReader(BasicFunc::getLogFilePath());
44+
while (sr->Peek() >= 0) {
45+
return_string += sr->ReadLine() + "\n";
46+
}
47+
}
48+
catch (System::IO::IOException^) {
49+
//File is opened from an other process
50+
return "";
51+
}
52+
finally{
53+
delete sr;
54+
}
55+
56+
return return_string;
57+
58+
}
59+
60+
void DebugForm::OnTick(System::Object ^, System::EventArgs ^)
61+
{
62+
RefreshUIRealTime();
63+
}
64+
65+
void DebugForm::RefreshUISlow()
66+
{
67+
//ListView Settings
68+
for each(Setting* setting in settings_prov->getAllSettings()) {
69+
String^ name = gcnew String(setting->GetNameAsString().c_str());
70+
string std_value;
71+
72+
//Adds all values to an single String^
73+
for each(string single_value in setting->GetValue()) {
74+
std_value += single_value;
75+
}
76+
String^ value = gcnew String(std_value.c_str());
77+
78+
listViewSettings->Items->Add(name)->SubItems->Add(value);
79+
}
80+
81+
//ListView Processes
82+
//Prepare ListView
83+
listViewProc->View = Windows::Forms::View::Details;
84+
ImageList^ imglistSmall = gcnew ImageList, ^imglistLarge = gcnew ImageList;
85+
imglistSmall->ImageSize = Drawing::Size(24, 24);
86+
imglistLarge->ImageSize = Drawing::Size(50, 50);
87+
listViewProc->SmallImageList = imglistSmall;
88+
listViewProc->LargeImageList = imglistLarge;
89+
90+
for each(std::string path in SystemAccess::GetRunningProccesses()) {
91+
listViewProc->Items->Add(gcnew ProcessItem(path, listViewProc));
92+
}
93+
}
94+
95+
void StandBye::DebugForm::RefreshUIRealTime()
96+
{
97+
//Buffered Values
98+
labelBuffCPU->Text = String::Format("{0:00.0} %", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::CPU));
99+
labelBuffRAM->Text = String::Format("{0:00.0} %", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::RAM));
100+
labelBuffHDD->Text = String::Format("{0:00.0} kBit/s", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::HDD));
101+
labelBuffNET->Text = String::Format("{0:00.0} kBit/s", system_watcher->GetSystemMetric(SystemAccess::SystemMetric::NETWORK));
102+
103+
//Real-Time Values
104+
labelRTCPU->Text = String::Format("{0:00.0} %", system_access->GetMetric(SystemAccess::SystemMetric::CPU));
105+
labelRTRAM->Text = String::Format("{0:00.0} %", system_access->GetMetric(SystemAccess::SystemMetric::RAM));
106+
labelRTHDD->Text = String::Format("{0:00.0} kBit/s", system_access->GetMetric(SystemAccess::SystemMetric::HDD));
107+
labelRTNET->Text = String::Format("{0:00.0} kBit/s", system_access->GetMetric(SystemAccess::SystemMetric::NETWORK));
108+
109+
//Input Info
110+
int lastinput = (int)system_access->GetLastInputTime();
111+
labelInputTime->Text = String::Format("{0} ms", lastinput);
112+
113+
if ((lastinput / 1000) > settings_prov->getThreshold(SettingName::WAIT_TIME)) {
114+
labelWAITReached->Text = "YES";
115+
}
116+
else {
117+
labelWAITReached->Text = "NO";
118+
}
119+
120+
//Sound input
121+
labelSoundPeak->Text = String::Format("{0:0.00}", system_access->getAudioPeak());
122+
123+
if (system_access->getAudioPeak() > 0) {
124+
labelSoundOverLimit->Text = "YES";
125+
}
126+
else {
127+
labelSoundOverLimit->Text = "NO";
128+
}
129+
130+
//Log
131+
if ((textBoxLog->Text != getLogText()) && getLogText() != "") {
132+
textBoxLog->Text = getLogText();
133+
textBoxLog->SelectionStart = textBoxLog->TextLength - 1;
134+
textBoxLog->ScrollToCaret();
135+
}
136+
}

0 commit comments

Comments
 (0)