-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShareware.hpp
131 lines (106 loc) · 4.32 KB
/
Shareware.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
////////////////////////////////////////////////////////////////////////////
// Shareware.hpp -- MZC3 shareware maker for Win32
// This file is part of MZC3. See file "ReadMe.txt" and "License.txt".
////////////////////////////////////////////////////////////////////////////
#ifndef __MZC3_SHAREWARE_HPP__
#define __MZC3_SHAREWARE_HPP__
#ifndef MZC_NO_SHAREWARE
#include <string>
////////////////////////////////////////////////////////////////////////////
#define sw_shareware_max_password 256
////////////////////////////////////////////////////////////////////////////
// useful functions
LPTSTR SwLoadStringDx1(HINSTANCE hInstance, UINT uID);
LPTSTR SwLoadStringDx2(HINSTANCE hInstance, UINT uID);
void SwCenterDialog(HWND hwnd);
int SwCenterMessageBox(
HWND hwndParent, LPCTSTR pszText, LPCTSTR pszCaption, UINT uMB_);
void SwMakeStaticHyperlink(HWND hwndCtrl, LPCTSTR pszURL = NULL);
void SwMakeStaticHyperlink(
HWND hwndParent, UINT idCtrl, LPCTSTR pszURL = NULL);
////////////////////////////////////////////////////////////////////////////
#ifndef EXTENDS_MOBJECT
#define EXTENDS_MOBJECT
#endif
class SW_Shareware EXTENDS_MOBJECT
{
public:
// NOTE: pszCompanyKey is the name of the registry key of the company.
// NOTE: pszAppKey is the name of the registry key of the application.
// NOTE: dwTrialDays is the trial interval in days.
// NOTE: parameter salt is the salt string.
// NOTE: parameter new_version is the current version of this software.
SW_Shareware(LPCTSTR pszCompanyKey,
LPCTSTR pszAppKey,
const char *pszSha256HashHexString,
DWORD dwTrialDays = 15,
const char *salt = "",
const char *new_version = "");
SW_Shareware(LPCTSTR pszCompanyKey,
LPCTSTR pszAppKey,
const BYTE *pbHash32Bytes,
DWORD dwTrialDays = 15,
const char *salt = "",
const char *new_version = "");
virtual ~SW_Shareware();
// NOTE: SW_Shareware::Start must be called on start-up of the MZC3 shareware.
// NOTE: SW_Shareware::Start returns false if the application cannot be used.
virtual bool Start(HWND hwndParent = NULL);
bool IsRegistered() const;
bool IsInTrial() const;
bool IsOutOfTrial() const;
DWORD GetTrialDays() const;
bool IsPasswordValid(const char *pszPassword) const;
// NOTE: UrgeRegister show a dialog and returns true if registered.
virtual bool UrgeRegister(HWND hwndParent = NULL);
bool RegisterPassword(HWND hwndParent, const char *pszPassword);
virtual void ShowErrorMessage(HWND hwndParent, UINT uStringID);
virtual void ThisCommandRequiresRegistering(HWND hwndParent);
bool CheckDate();
virtual int CompareVersion(const char *old_ver, const char *new_ver);
public:
HINSTANCE m_hInstance;
DWORDLONG m_dwlTotalMinutesRemains;
DWORD m_dwTrialDays;
FILETIME m_ftStart;
enum SHAREWARE_STATUS
{
IN_TRIAL_FIRST_TIME, IN_TRIAL, OUT_OF_TRIAL, REGD
};
SHAREWARE_STATUS m_status;
public:
#ifdef UNICODE
typedef std::wstring tstring;
#else
typedef std::string tstring;
#endif
protected:
tstring m_strCompanyKey;
tstring m_strAppKey;
std::string m_strSha256HashHexString;
std::string m_strSalt;
std::string m_strNewVersion;
std::string m_strOldVersion;
bool CheckRegistry(HWND hwndParent);
bool CheckAppKey(HWND hwndParent, HKEY hkeyApp);
bool SetRegistryFirstTime(HWND hwndParent);
DWORD GetUserCheckSum() const;
virtual void OnTrialFirstTime(HWND hwndParent);
virtual void OnTrial(HWND hwndParent);
virtual bool OnOutOfTrial(HWND hwndParent);
virtual void EncodePassword(void *pass, DWORD size) const;
virtual void DecodePassword(void *pass, DWORD size) const;
private:
SW_Shareware();
// NOTE: SW_Shareware is not copyable.
SW_Shareware(const SW_Shareware&);
SW_Shareware& operator=(const SW_Shareware&);
};
////////////////////////////////////////////////////////////////////////////
#ifndef MZC_NO_INLINING
#undef MZC_INLINE
#define MZC_INLINE inline
#include "Shareware_inl.hpp"
#endif
#endif // ndef MZC_NO_SHAREWARE
#endif // ndef __MZC3_SHAREWARE_HPP__