From e5c5ae04fe2935d9a98bccfc92a839330366a9cf Mon Sep 17 00:00:00 2001 From: Keelan Stuart Date: Thu, 26 Mar 2020 13:27:03 -0400 Subject: [PATCH] v2.4.1 - Slight refactor of license key dlg JS funcs; call ShowLicenseDlg to display it, then call GetLicenseKey, GetLicenseUser, and GetLicenseOrg to get the contents - Added JS func GetCurrentDateString; returns date as YYYY/MM/DD (so you can sort it properly, ya know) - Beefed up JS text file support; TextFileOpen, TextFileClose, TextFileReadLn, TextFileWrite, TextFileReachedEOF - Added JS func DownloadFile to make http requests --- sfx/sfx/LicenseEntryDlg.cpp | 28 ++++++++ sfx/sfx/LicenseEntryDlg.h | 7 ++ sfx/sfx/ProgressDlg.cpp | 117 +++++++++++++++++++++++++++------ sfx/sfx/TinyJS_Functions.cpp | 24 +++---- sfx/sfx/res/license.htm | 4 ++ sfx/sfx/sfx.vcxproj | 52 +++++++++++++++ sfx/sfxPackager/sfxPackager.rc | Bin 46460 -> 46460 bytes sfxPackagerSetup.sfxpp | 3 +- 8 files changed, 203 insertions(+), 32 deletions(-) create mode 100644 sfx/sfx/res/license.htm diff --git a/sfx/sfx/LicenseEntryDlg.cpp b/sfx/sfx/LicenseEntryDlg.cpp index 5624dd1..3987ede 100644 --- a/sfx/sfx/LicenseEntryDlg.cpp +++ b/sfx/sfx/LicenseEntryDlg.cpp @@ -26,6 +26,9 @@ CLicenseKeyEntryDlg::CLicenseKeyEntryDlg(const TCHAR *description, CWnd *pParent m_hIcon = AfxGetApp()->LoadIcon(_T("ICON")); m_Key = _T(""); + m_User = _T(""); + m_Org = _T(""); + m_Desc = description; } @@ -48,11 +51,25 @@ const TCHAR *CLicenseKeyEntryDlg::GetKey() return m_Key; } + +const TCHAR *CLicenseKeyEntryDlg::GetUser() +{ + return m_User; +} + + +const TCHAR *CLicenseKeyEntryDlg::GetOrg() +{ + return m_Org; +} + // CLicenseKeyEntryDlg message handlers void CLicenseKeyEntryDlg::OnOK() { + m_CtlUser.GetWindowText(m_User); + m_CtlOrg.GetWindowText(m_Org); m_CtlKey.GetWindowText(m_Key); if (!m_Key.IsEmpty()) CDialog::OnOK(); @@ -77,8 +94,19 @@ BOOL CLicenseKeyEntryDlg::OnInitDialog() m_CtlDesc.LoadFromResource(_T("license")); } + if (m_CtlUser.SubclassDlgItem(IDC_EDIT_USERNAME, this)) + { + m_CtlUser.SetWindowText(m_User); + } + + if (m_CtlOrg.SubclassDlgItem(IDC_EDIT_ORGANIZATION, this)) + { + m_CtlOrg.SetWindowText(m_Org); + } + if (m_CtlKey.SubclassDlgItem(IDC_EDIT_KEY, this)) { + m_CtlKey.SetWindowText(_T("")); m_CtlKey.SetFocus(); } diff --git a/sfx/sfx/LicenseEntryDlg.h b/sfx/sfx/LicenseEntryDlg.h index 1db26f2..95b2221 100644 --- a/sfx/sfx/LicenseEntryDlg.h +++ b/sfx/sfx/LicenseEntryDlg.h @@ -28,16 +28,23 @@ class CLicenseKeyEntryDlg : public CDialog enum { IDD = IDD_LICENSEKEY_DIALOG }; const TCHAR *GetKey(); + const TCHAR *GetUser(); + const TCHAR *GetOrg(); protected: virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support HICON m_hIcon; CHtmlCtrl m_CtlDesc; + CEdit m_CtlKey; + CEdit m_CtlUser; + CEdit m_CtlOrg; CString m_Desc; CString m_Key; + CString m_User; + CString m_Org; DECLARE_MESSAGE_MAP() diff --git a/sfx/sfx/ProgressDlg.cpp b/sfx/sfx/ProgressDlg.cpp index 35212f8..5f109df 100644 --- a/sfx/sfx/ProgressDlg.cpp +++ b/sfx/sfx/ProgressDlg.cpp @@ -19,6 +19,8 @@ #include "LicenseEntryDlg.h" #include #include +#include +#include #include "../sfxPackager/GenParser.h" #include "HttpDownload.h" @@ -28,6 +30,8 @@ extern bool ReplaceEnvironmentVariables(const tstring &src, tstring &dst); extern bool ReplaceRegistryKeys(const tstring &src, tstring &dst); extern bool FLZACreateDirectories(const TCHAR *dir); +static CLicenseKeyEntryDlg licensedlg(_T("")); + // CProgressDlg dialog IMPLEMENT_DYNAMIC(CProgressDlg, CDialogEx) @@ -801,23 +805,20 @@ void scAbortInstall(CScriptVar* c, void* userdata) } -void scGetLicenseKey(CScriptVar *c, void *userdata) +void scShowLicenseDlg(CScriptVar *c, void *userdata) { - CScriptVar *pdv = c->getParameter(_T("desc")); - tstring desc = pdv ? pdv->getString() : _T(""); + INT_PTR dlg_ret = licensedlg.DoModal(); - tstring key; - CLicenseKeyEntryDlg dlg(desc.c_str()); - - INT_PTR dlg_ret = dlg.DoModal(); - if (dlg_ret == IDOK) - { - key = dlg.GetKey(); - } - else if (dlg_ret == IDCANCEL) + if (dlg_ret == IDCANCEL) { exit(-1); } +} + + +void scGetLicenseKey(CScriptVar *c, void *userdata) +{ + tstring key = licensedlg.GetKey(); CScriptVar *ret = c->getReturnVar(); if (ret) @@ -825,6 +826,26 @@ void scGetLicenseKey(CScriptVar *c, void *userdata) } +void scGetLicenseUser(CScriptVar *c, void *userdata) +{ + tstring user = licensedlg.GetUser(); + + CScriptVar *ret = c->getReturnVar(); + if (ret) + ret->setString(user); +} + + +void scGetLicenseOrg(CScriptVar *c, void *userdata) +{ + tstring org = licensedlg.GetOrg(); + + CScriptVar *ret = c->getReturnVar(); + if (ret) + ret->setString(org); +} + + void scDownloadFile(CScriptVar *c, void *userdata) { CScriptVar *purl = c->getParameter(_T("url")); @@ -835,7 +856,7 @@ void scDownloadFile(CScriptVar *c, void *userdata) if (purl && pfile) { CHttpDownloader dl; - result = dl.DownloadHttpFile(purl->getString().c_str(), pfile->getString().c_str(), _T(".")); + result = dl.DownloadHttpFile(purl->getString().c_str(), pfile->getString().c_str(), _T("")); } CScriptVar *ret = c->getReturnVar(); @@ -847,10 +868,11 @@ void scDownloadFile(CScriptVar *c, void *userdata) void scTextFileOpen(CScriptVar *c, void *userdata) { CScriptVar *pfile = c->getParameter(_T("filename")); + CScriptVar *pmode = c->getParameter(_T("mode")); FILE *f = nullptr; if (pfile) - f = _tfopen(pfile->getString().c_str(), _T("r")); + f = _tfopen(pfile->getString().c_str(), pmode ? pmode->getString().c_str() : _T("r")); CScriptVar *ret = c->getReturnVar(); if (ret) @@ -865,7 +887,8 @@ void scTextFileClose(CScriptVar *c, void *userdata) if (phandle) { FILE *f = (FILE *)phandle->getInt(); - fclose(f); + if (f) + fclose(f); } } @@ -879,9 +902,12 @@ void scTextFileReadLn(CScriptVar *c, void *userdata) if (phandle) { FILE *f = (FILE *)phandle->getInt(); - TCHAR _s[4096]; - _fgetts(_s, 2096, f); - s = _s; + if (f) + { + TCHAR _s[4096]; + _fgetts(_s, 4096, f); + s = _s; + } } CScriptVar *ret = c->getReturnVar(); @@ -890,6 +916,53 @@ void scTextFileReadLn(CScriptVar *c, void *userdata) } +void scTextFileWrite(CScriptVar *c, void *userdata) +{ + CScriptVar *phandle = c->getParameter(_T("handle")); + CScriptVar *ptext = c->getParameter(_T("text")); + + if (phandle && ptext) + { + FILE *f = (FILE *)phandle->getInt(); + if (f) + _fputts(ptext->getString().c_str(), f); + } +} + + +void scTextFileReachedEOF(CScriptVar *c, void *userdata) +{ + CScriptVar *phandle = c->getParameter(_T("handle")); + + int64_t b = 1; + if (phandle) + { + FILE *f = (FILE *)phandle->getInt(); + if (f) + b = feof(f); + } + + CScriptVar *ret = c->getReturnVar(); + if (ret) + ret->setInt(b); +} + + +void scGetCurrentDateStr(CScriptVar *c, void *userdata) +{ + auto now = std::chrono::system_clock::now(); + std::time_t now_c = std::chrono::system_clock::to_time_t(now); + struct tm *parts = std::localtime(&now_c); + + TCHAR dates[MAX_PATH]; + _stprintf(dates, _T("%04d/%02d/%02d"), 1900 + parts->tm_year, 1 + parts->tm_mon, parts->tm_mday); + + CScriptVar *ret = c->getReturnVar(); + if (ret) + ret->setString(tstring(dates)); +} + + // ****************************************************************************** // ****************************************************************************** @@ -933,9 +1006,12 @@ DWORD CProgressDlg::RunInstall() theApp.m_js.addNative(_T("function DownloadFile(url, file)"), scDownloadFile, (void *)this); theApp.m_js.addNative(_T("function Echo(msg)"), scEcho, (void *)this); theApp.m_js.addNative(_T("function FileExists(path)"), scFileExists, (void *)this); + theApp.m_js.addNative(_T("function GetCurrentDateString()"), scGetCurrentDateStr, (void *)this); theApp.m_js.addNative(_T("function GetGlobalInt(name)"), scGetGlobalInt, (void *)this); theApp.m_js.addNative(_T("function GetExeVersion(file)"), scGetExeVersion, (void*)this); - theApp.m_js.addNative(_T("function GetLicenseKey(desc)"), scGetLicenseKey, (void *)this); + theApp.m_js.addNative(_T("function GetLicenseKey()"), scGetLicenseKey, (void *)this); + theApp.m_js.addNative(_T("function GetLicenseOrg()"), scGetLicenseKey, (void *)this); + theApp.m_js.addNative(_T("function GetLicenseUser()"), scGetLicenseKey, (void *)this); theApp.m_js.addNative(_T("function IsDirectory(path)"), scIsDirectory, (void *)this); theApp.m_js.addNative(_T("function IsDirectoryEmpty(path)"), scIsDirectoryEmpty, (void *)this); theApp.m_js.addNative(_T("function MessageBox(title, msg)"), scMessageBox, (void *)this); @@ -945,10 +1021,13 @@ DWORD CProgressDlg::RunInstall() theApp.m_js.addNative(_T("function SetGlobalEnvironmentVariable(varname, val)"), scSetGlobalEnvironmentVariable, (void *)this); theApp.m_js.addNative(_T("function SetGlobalInt(name, val)"), scSetGlobalInt, (void *)this); theApp.m_js.addNative(_T("function SetRegistryKeyValue(root, key, name, val)"), scSetRegistryKeyValue, (void *)this); + theApp.m_js.addNative(_T("function ShowLicenseDlg()"), scShowLicenseDlg, (void *)this); theApp.m_js.addNative(_T("function SpawnProcess(cmd, params, rundir, block)"), scSpawnProcess, (void *)this); theApp.m_js.addNative(_T("function TextFileOpen(filename)"), scTextFileOpen, (void *)this); theApp.m_js.addNative(_T("function TextFileClose(handle)"), scTextFileClose, (void *)this); theApp.m_js.addNative(_T("function TextFileReadLn(handle)"), scTextFileReadLn, (void *)this); + theApp.m_js.addNative(_T("function TextFileWrite(handle, text)"), scTextFileWrite, (void *)this); + theApp.m_js.addNative(_T("function TextFileReachedEOF(handle)"), scTextFileReachedEOF, (void *)this); theApp.m_InstallPath.Replace(_T("\\"), _T("/")); diff --git a/sfx/sfx/TinyJS_Functions.cpp b/sfx/sfx/TinyJS_Functions.cpp index f2e9afb..f76d682 100644 --- a/sfx/sfx/TinyJS_Functions.cpp +++ b/sfx/sfx/TinyJS_Functions.cpp @@ -93,10 +93,10 @@ void scStringIndexOf(CScriptVar *c, void *) void scStringSubstring(CScriptVar *c, void *) { tstring str = c->getParameter(_T("this"))->getString(); - int lo = c->getParameter(_T("lo"))->getInt(); - int hi = c->getParameter(_T("hi"))->getInt(); + int64_t lo = c->getParameter(_T("lo"))->getInt(); + int64_t hi = c->getParameter(_T("hi"))->getInt(); - int l = hi - lo; + int64_t l = hi - lo; if ((l > 0) && (lo >= 0) && (lo + l <= (int)str.length())) c->getReturnVar()->setString(str.substr(lo, l)); else @@ -107,7 +107,7 @@ void scStringCharAt(CScriptVar *c, void *) { tstring str = c->getParameter(_T("this"))->getString(); - int p = c->getParameter(_T("pos"))->getInt(); + int64_t p = c->getParameter(_T("pos"))->getInt(); if (p >= 0 && p < (int)str.length()) c->getReturnVar()->setString(str.substr(p, 1)); @@ -118,7 +118,7 @@ void scStringCharAt(CScriptVar *c, void *) void scStringCharCodeAt(CScriptVar *c, void *) { tstring str = c->getParameter(_T("this"))->getString(); - int p = c->getParameter(_T("pos"))->getInt(); + int64_t p = c->getParameter(_T("pos"))->getInt(); if (p >= 0 && p < (int)str.length()) c->getReturnVar()->setInt(str.at(p)); @@ -133,7 +133,7 @@ void scStringSplit(CScriptVar *c, void *) CScriptVar *result = c->getReturnVar(); result->setArray(); - int length = 0; + int64_t length = 0; size_t pos = str.find(sep); while (pos != tstring::npos) @@ -152,7 +152,7 @@ void scStringFromCharCode(CScriptVar *c, void *) { TCHAR str[2]; - str[0] = c->getParameter(_T("char"))->getInt(); + str[0] = (TCHAR)(c->getParameter(_T("char"))->getInt()); str[1] = 0; c->getReturnVar()->setString(str); @@ -250,7 +250,7 @@ void scArrayContains(CScriptVar *c, void *data) void scArrayRemove(CScriptVar *c, void *data) { CScriptVar *obj = c->getParameter(_T("obj")); - vector removedIndices; + vector removedIndices; CScriptVarLink *v; @@ -270,8 +270,8 @@ void scArrayRemove(CScriptVar *c, void *data) v = c->getParameter(_T("this"))->firstChild; while (v) { - int n = v->getIntName(); - int newn = n; + int64_t n = v->getIntName(); + int64_t newn = n; for (size_t i = 0; i < removedIndices.size(); i++) { @@ -295,8 +295,8 @@ void scArrayJoin(CScriptVar *c, void *data) tostringstream sstr; - int l = arr->getArrayLength(); - for (int i = 0; i < l; i++) + int64_t l = arr->getArrayLength(); + for (int64_t i = 0; i < l; i++) { if (i > 0) sstr << sep; diff --git a/sfx/sfx/res/license.htm b/sfx/sfx/res/license.htm new file mode 100644 index 0000000..00593fd --- /dev/null +++ b/sfx/sfx/res/license.htm @@ -0,0 +1,4 @@ + + +

A valid license key must be entered to proceed...

+ diff --git a/sfx/sfx/sfx.vcxproj b/sfx/sfx/sfx.vcxproj index 7e5b291..bca2c19 100644 --- a/sfx/sfx/sfx.vcxproj +++ b/sfx/sfx/sfx.vcxproj @@ -9,6 +9,10 @@ Release x64 + + Test Release + x64 + {729159FA-E208-40A0-9BC5-F4C5B53EE6FB} @@ -32,6 +36,14 @@ Static v142 + + Application + false + true + Unicode + Static + v142 + @@ -43,6 +55,10 @@ + + + + true @@ -56,6 +72,12 @@ $(ProjectDir)obj\$(Configuration)$(PlatformArchitecture)\ $(ProjectName)$(PlatformArchitecture)$(ShortConfiguration) + + false + $(SolutionDir)bin\ + $(ProjectDir)obj\$(Configuration)$(PlatformArchitecture)\ + $(ProjectName)$(PlatformArchitecture)$(ShortConfiguration) + Use @@ -108,6 +130,35 @@ $(IntDir);%(AdditionalIncludeDirectories) + + + Level3 + Use + Disabled + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + ProgramDatabase + + + Windows + true + true + true + AsInvoker + $(SolutionDir)Lib + Archiver$(PlatformArchitecture)$(ShortConfiguration).lib;Version.lib + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + @@ -160,6 +211,7 @@ Create Create + Create diff --git a/sfx/sfxPackager/sfxPackager.rc b/sfx/sfxPackager/sfxPackager.rc index 6e113fe9a4629ce1a39059010b57fcc5d6d5b70a..d22aec13f92fa6da913a8570b9f351300116851d 100644 GIT binary patch delta 52 zcmezKis{cQrVTp9jE0kSiwzkKH^&!0WnwjC&|@%|{IOJbb6J@kf-AoHLd6;z02a{` AbN~PV delta 52 zcmezKis{cQrVTp9j0Tf+iwzkKHpdq~Wnwj8&|@%|{IOJbb6J@kf-AoHLd6;z02Wvi AZ~y=R diff --git a/sfxPackagerSetup.sfxpp b/sfxPackagerSetup.sfxpp index 67a4d74..aad0cd2 100644 --- a/sfxPackagerSetup.sfxpp +++ b/sfxPackagerSetup.sfxpp @@ -2,7 +2,8 @@ - + +