Skip to content

Commit

Permalink
Project64: Only show support window once per hour
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Oct 27, 2020
1 parent 25dde67 commit 1751b2f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
22 changes: 21 additions & 1 deletion Source/Project64/UserInterface/ProjectSupport.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include <Common\md5.h>
#include <time.h>
#include <windows.h>
#include <Wininet.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions Source/Project64/UserInterface/ProjectSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class CProjectSupport
char Name[300];
char MachineID[300];
uint32_t RunCount;
time_t LastUpdated;
time_t LastShown;
bool Validated;
} SupportInfo;

Expand All @@ -20,6 +22,7 @@ class CProjectSupport
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; }
Expand Down
6 changes: 3 additions & 3 deletions Source/Project64/UserInterface/SupportWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 1751b2f

Please sign in to comment.