-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a UI for the driver (like network link conditioner)
- Loading branch information
Showing
20 changed files
with
1,614 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// CustomProfileDlg.cpp : implementation file | ||
// | ||
|
||
#include "stdafx.h" | ||
#include "gui.h" | ||
#include "CustomProfileDlg.h" | ||
#include "afxdialogex.h" | ||
|
||
|
||
// CustomProfileDlg dialog | ||
|
||
IMPLEMENT_DYNAMIC(CustomProfileDlg, CDialogEx) | ||
|
||
CustomProfileDlg::CustomProfileDlg(CWnd* pParent /*=NULL*/) | ||
: CDialogEx(IDD_CUSTOM_PROFILE, pParent) | ||
, m_name(_T("")) | ||
, m_inBps(0) | ||
, m_outBps(0) | ||
, m_rtt(0) | ||
, m_plr(0) | ||
, m_inBufferLength(0) | ||
, m_outBufferLen(0) | ||
{ | ||
|
||
} | ||
|
||
CustomProfileDlg::~CustomProfileDlg() | ||
{ | ||
} | ||
|
||
void CustomProfileDlg::DoDataExchange(CDataExchange* pDX) | ||
{ | ||
CDialogEx::DoDataExchange(pDX); | ||
DDX_Text(pDX, IDC_NAME, m_name); | ||
DDV_MaxChars(pDX, m_name, 100); | ||
DDX_Text(pDX, IDC_IN_BPS, m_inBps); | ||
DDX_Text(pDX, IDC_OUT_BPS, m_outBps); | ||
DDX_Text(pDX, IDC_RTT, m_rtt); | ||
DDV_MinMaxLong(pDX, m_rtt, 0, 60000); | ||
DDX_Text(pDX, IDC_PLR, m_plr); | ||
DDV_MinMaxDouble(pDX, m_plr, 0, 100); | ||
DDX_Text(pDX, IDC_IN_BUFF_LEN, m_inBufferLength); | ||
DDX_Text(pDX, IDC_OUT_BUFF_LEN, m_outBufferLen); | ||
if (pDX->m_bSaveAndValidate) { | ||
if (!m_name.Trim().GetLength()) { | ||
AfxMessageBox(L"Invalid name"); | ||
pDX->PrepareEditCtrl(IDC_NAME); | ||
pDX->Fail(); | ||
} | ||
} | ||
} | ||
|
||
|
||
BEGIN_MESSAGE_MAP(CustomProfileDlg, CDialogEx) | ||
END_MESSAGE_MAP() | ||
|
||
|
||
// CustomProfileDlg message handlers | ||
|
||
|
||
void CustomProfileDlg::OnOK() | ||
{ | ||
|
||
CDialogEx::OnOK(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
|
||
// CustomProfileDlg dialog | ||
|
||
class CustomProfileDlg : public CDialogEx | ||
{ | ||
DECLARE_DYNAMIC(CustomProfileDlg) | ||
|
||
public: | ||
CustomProfileDlg(CWnd* pParent = NULL); // standard constructor | ||
virtual ~CustomProfileDlg(); | ||
|
||
// Dialog Data | ||
#ifdef AFX_DESIGN_TIME | ||
enum { IDD = IDD_CUSTOM_PROFILE }; | ||
#endif | ||
|
||
protected: | ||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support | ||
|
||
DECLARE_MESSAGE_MAP() | ||
public: | ||
CString m_name; | ||
ULONGLONG m_inBps; | ||
ULONGLONG m_outBps; | ||
long m_rtt; | ||
double m_plr; | ||
ULONGLONG m_inBufferLength; | ||
ULONGLONG m_outBufferLen; | ||
virtual void OnOK(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "stdafx.h" | ||
#include "CustomProfiles.h" | ||
|
||
|
||
/*----------------------------------------------------------------------------- | ||
-----------------------------------------------------------------------------*/ | ||
CustomProfiles::CustomProfiles() { | ||
PWSTR path; | ||
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &path) == S_OK) { | ||
CString dir(path); | ||
CoTaskMemFree(path); | ||
dir += L"\\winShaper"; | ||
CreateDirectory(dir, NULL); | ||
data_file_ = dir + L"profiles.txt"; | ||
} | ||
Load(); | ||
} | ||
|
||
|
||
/*----------------------------------------------------------------------------- | ||
-----------------------------------------------------------------------------*/ | ||
CustomProfiles::~CustomProfiles() { | ||
} | ||
|
||
/*----------------------------------------------------------------------------- | ||
-----------------------------------------------------------------------------*/ | ||
void CustomProfiles::Save() { | ||
CString out = L""; | ||
int count = (int)profiles_.GetCount(); | ||
for (int i = 0; i < count; i++) { | ||
CString profile = profiles_[i].Serialize(); | ||
if (!profile.IsEmpty()) | ||
out += profile + L"\n"; | ||
} | ||
if (out.GetLength()) { | ||
HANDLE hFile = CreateFile(data_file_, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); | ||
if (hFile != INVALID_HANDLE_VALUE) { | ||
DWORD written = 0; | ||
DWORD len = out.GetLength() * sizeof(TCHAR); | ||
WriteFile(hFile, (LPCTSTR)out, len, &written, 0); | ||
CloseHandle(hFile); | ||
} | ||
} | ||
} | ||
|
||
/*----------------------------------------------------------------------------- | ||
-----------------------------------------------------------------------------*/ | ||
void CustomProfiles::Load() { | ||
if (!profiles_.IsEmpty()) | ||
profiles_.RemoveAll(); | ||
HANDLE hFile = CreateFile(data_file_, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); | ||
if (hFile != INVALID_HANDLE_VALUE) { | ||
DWORD len = GetFileSize(hFile, NULL); | ||
if (len > 0) { | ||
DWORD buff_len = len + sizeof(TCHAR); | ||
TCHAR * buff = (TCHAR *)malloc(buff_len); | ||
if (buff) { | ||
memset(buff, buff_len, 0); | ||
DWORD bytes_read; | ||
if (ReadFile(hFile, buff, len, &bytes_read, 0) && len == bytes_read) { | ||
CString in(buff); | ||
int pos = 0; | ||
CString line = in.Tokenize(L"\n", pos); | ||
while (line != L"") { | ||
ConnectionProfile profile(line); | ||
if (!profile.name_.IsEmpty()) | ||
profiles_.Add(profile); | ||
line = in.Tokenize(L"\n", pos); | ||
} | ||
} | ||
free(buff); | ||
} | ||
} | ||
CloseHandle(hFile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#pragma once | ||
class ConnectionProfile { | ||
public: | ||
ConnectionProfile(){} | ||
ConnectionProfile(CString name, | ||
unsigned __int64 inBps, | ||
unsigned __int64 outBps, | ||
unsigned long rtt, | ||
unsigned short plr, | ||
unsigned __int64 inBufferLen, | ||
unsigned __int64 outBufferLen){ | ||
name_ = name; | ||
inBps_ = inBps; | ||
outBps_ = outBps; | ||
rtt_ = rtt; | ||
plr_ = plr; | ||
inBufferLen_ = inBufferLen; | ||
outBufferLen_ = outBufferLen; | ||
} | ||
ConnectionProfile(const ConnectionProfile &src){*this = src;} | ||
ConnectionProfile(CString serialized) { | ||
CStringArray parts; | ||
int pos = 0; | ||
CString token = serialized.Tokenize(L"\t", pos); | ||
while (token != L"") { | ||
parts.Add(token); | ||
token = serialized.Tokenize(L"\t", pos); | ||
} | ||
if (parts.GetCount() >= 7) { | ||
name_ = parts[0]; | ||
inBps_ = _ttoi64(parts[1]); | ||
outBps_ = _ttoi64(parts[2]); | ||
rtt_ = _ttol(parts[3]); | ||
plr_ = _ttoi(parts[4]); | ||
inBufferLen_ = _ttoi64(parts[5]); | ||
outBufferLen_ = _ttoi64(parts[6]); | ||
} | ||
} | ||
~ConnectionProfile(){} | ||
const ConnectionProfile &operator =(const ConnectionProfile &src) { | ||
name_ = src.name_; | ||
inBps_ = src.inBps_; | ||
outBps_ = src.outBps_; | ||
rtt_ = src.rtt_; | ||
plr_ = src.plr_; | ||
inBufferLen_ = src.inBufferLen_; | ||
outBufferLen_ = src.outBufferLen_; | ||
return src; | ||
} | ||
CString DisplayString() { | ||
// Format the parameters into a string that includes the name and bandwidth settings | ||
CString display, buff; | ||
display = name_ + L" ("; | ||
if (inBps_ >= 1000000) { | ||
if (inBps_ % 1000000) { | ||
buff.Format(L"%0.1f Mbps", (double)inBps_ / 1000000.0); | ||
} else { | ||
buff.Format(L"%d Mbps", (DWORD)(inBps_ / 1000000)); | ||
} | ||
} else if (inBps_ >= 1000) { | ||
if (inBps_ % 1000) { | ||
buff.Format(L"%0.1f Kbps", (double)inBps_ / 1000.0); | ||
} else { | ||
buff.Format(L"%d Kbps", (DWORD)(inBps_ / 1000)); | ||
} | ||
} else { | ||
buff.Format(L"%d bps", (DWORD)inBps_); | ||
} | ||
display += buff + L"/"; | ||
if (outBps_ >= 1000000) { | ||
if (outBps_ % 1000000) { | ||
buff.Format(L"%0.1f Mbps", (double)outBps_ / 1000000.0); | ||
} else { | ||
buff.Format(L"%d Mbps", (DWORD)(outBps_ / 1000000)); | ||
} | ||
} else if (outBps_ >= 1000) { | ||
if (outBps_ % 1000) { | ||
buff.Format(L"%0.1f Kbps", (double)outBps_ / 1000.0); | ||
} else { | ||
buff.Format(L"%d Kbps", (DWORD)(outBps_ / 1000)); | ||
} | ||
} else { | ||
buff.Format(L"%d bps", (DWORD)outBps_); | ||
} | ||
display += buff + L" "; | ||
buff.Format(L"%dms RTT", rtt_); | ||
display += buff; | ||
if (plr_ > 0) { | ||
buff.Format(L", %0.2f%% plr", (double)plr_ / 100.0); | ||
display += buff; | ||
} | ||
display += ")"; | ||
return display; | ||
} | ||
CString Serialize() { | ||
CString buff; | ||
if (name_.GetLength() && name_.Find(L"\t") == -1) | ||
buff.Format(L"%s\t%I64u\t%I64u\t%lu\t%u\t%I64u\t%I64u", (LPCTSTR)name_, inBps_, outBps_, rtt_, plr_, inBufferLen_, outBufferLen_); | ||
return buff; | ||
} | ||
|
||
CString name_; | ||
unsigned __int64 inBps_; | ||
unsigned __int64 outBps_; | ||
unsigned long rtt_; | ||
unsigned short plr_; // 0 - 10000 (hundreths) | ||
unsigned __int64 inBufferLen_; | ||
unsigned __int64 outBufferLen_; | ||
}; | ||
|
||
|
||
class CustomProfiles { | ||
public: | ||
CustomProfiles(); | ||
~CustomProfiles(); | ||
void Load(); | ||
void Save(); | ||
CArray<ConnectionProfile> profiles_; | ||
|
||
protected: | ||
CString data_file_; | ||
}; | ||
|
Oops, something went wrong.