Skip to content

Commit

Permalink
v2.4.1
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
keelanstuart committed Mar 26, 2020
1 parent 974bfd1 commit e5c5ae0
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 32 deletions.
28 changes: 28 additions & 0 deletions sfx/sfx/LicenseEntryDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
Expand All @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions sfx/sfx/LicenseEntryDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
117 changes: 98 additions & 19 deletions sfx/sfx/ProgressDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "LicenseEntryDlg.h"
#include <vector>
#include <istream>
#include <chrono>
#include <ctime>
#include "../sfxPackager/GenParser.h"
#include "HttpDownload.h"

Expand All @@ -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)
Expand Down Expand Up @@ -801,30 +805,47 @@ 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)
ret->setString(key);
}


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"));
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -865,7 +887,8 @@ void scTextFileClose(CScriptVar *c, void *userdata)
if (phandle)
{
FILE *f = (FILE *)phandle->getInt();
fclose(f);
if (f)
fclose(f);
}
}

Expand All @@ -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();
Expand All @@ -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));
}


// ******************************************************************************
// ******************************************************************************

Expand Down Expand Up @@ -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);
Expand All @@ -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("/"));

Expand Down
24 changes: 12 additions & 12 deletions sfx/sfx/TinyJS_Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -250,7 +250,7 @@ void scArrayContains(CScriptVar *c, void *data)
void scArrayRemove(CScriptVar *c, void *data)
{
CScriptVar *obj = c->getParameter(_T("obj"));
vector<int> removedIndices;
vector<int64_t> removedIndices;

CScriptVarLink *v;

Expand All @@ -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++)
{
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions sfx/sfx/res/license.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<html>
<body>
<p>A valid license key must be entered to proceed...</p>
</body>
Loading

0 comments on commit e5c5ae0

Please sign in to comment.