Project64: Only show support window once per hour

This commit is contained in:
zilmar 2020-10-27 16:41:50 +10:30
parent 25dde67f9d
commit 1751b2fd8b
3 changed files with 27 additions and 4 deletions

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include <Common\md5.h>
#include <time.h>
#include <windows.h>
#include <Wininet.h>
@ -106,10 +107,29 @@ std::string CProjectSupport::GenerateMachineID(void)
void CProjectSupport::IncrementRunCount()
{
time_t now = time(nullptr);
if (m_SupportInfo.LastUpdated <= now && ((now - m_SupportInfo.LastUpdated) / 60) < 60)
{
return;
}
m_SupportInfo.RunCount += 1;
m_SupportInfo.LastUpdated = now;
SaveSupportInfo();
}
bool CProjectSupport::ShowSuppotWindow()
{
return true;
time_t now = time(nullptr);
if (m_SupportInfo.LastShown <= now && ((now - m_SupportInfo.LastShown) / 60) < 60)
{
return false;
}
m_SupportInfo.LastShown = now;
SaveSupportInfo();
return true;
}
bool CProjectSupport::PerformRequest(const wchar_t * Url, const std::string & PostData, DWORD & StatusCode, std::vector<std::string> & Headers)
{
StatusCode = 0;
@ -259,7 +279,7 @@ void CProjectSupport::LoadSupportInfo(void)
}
}
if (OutData.size() > 0)
if (OutData.size() == sizeof(SupportInfo) + 32)
{
SupportInfo * Info = (SupportInfo *)OutData.data();
const char * CurrentHash = (const char *)(OutData.data() + sizeof(SupportInfo));

View File

@ -11,6 +11,8 @@ class CProjectSupport
char Name[300];
char MachineID[300];
uint32_t RunCount;
time_t LastUpdated;
time_t LastShown;
bool Validated;
} SupportInfo;
@ -20,6 +22,7 @@ public:
bool RequestCode(const char * Email);
bool ValidateCode(const char * Code);
void IncrementRunCount();
bool ShowSuppotWindow();
inline uint32_t RunCount() const { return m_SupportInfo.RunCount; }
inline const char * MachineID(void) const { return m_SupportInfo.MachineID; }

View File

@ -33,7 +33,7 @@ void CSupportWindow::Show(HWND hParent, bool Delay)
}
m_Support.IncrementRunCount();
if (m_Support.RunCount() < 7)
if (m_Support.RunCount() < 7 || !m_Support.ShowSuppotWindow())
{
return;
}
@ -116,7 +116,7 @@ LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
MoveWindow(Left, Top, rcWin.Width(), rcWin.Height(), TRUE);
/*if (m_Delay && m_RunCount >= 10)
if (m_Delay && m_Support.RunCount() >= 15)
{
CMenuHandle menu = GetSystemMenu(false);
menu.RemoveMenu(SC_CLOSE, MF_BYCOMMAND);
@ -127,7 +127,7 @@ LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
GetDlgItem(IDCANCEL).EnableWindow(false);
srand ((uint32_t)time(NULL));
SetTimer(0, 1000, NULL);
}*/
}
return TRUE;
}