diff --git a/Archiver/Source/Archiver.cpp b/Archiver/Source/Archiver.cpp index e97b2dd..855dfcb 100644 --- a/Archiver/Source/Archiver.cpp +++ b/Archiver/Source/Archiver.cpp @@ -15,7 +15,6 @@ IArchiver::CREATE_RESULT IArchiver::CreateArchiver(IArchiver **ppia, IArchiveHandle *pah, COMPRESSOR_TYPE ct) { - if (ppia) { DWORD bw; @@ -63,8 +62,11 @@ void IArchiver::DestroyArchiver(IArchiver **ppia) { if (ppia && *ppia) { - delete *ppia; - *ppia = NULL; + CFastLZArchiver *pflza = dynamic_cast(*ppia); + if (pflza) + delete pflza; + + *ppia = nullptr; } } @@ -75,14 +77,14 @@ IExtractor::CREATE_RESULT IExtractor::CreateExtractor(IExtractor **ppie, IArchiv { DWORD br; uint32_t magic; - ReadFile(pah->GetHandle(), &magic, sizeof(uint32_t), &br, NULL); + ReadFile(pah->GetHandle(), &magic, sizeof(uint32_t), &br, nullptr); if (magic != IArchiver::MAGIC) return CR_BADMAGIC; *ppie = NULL; - ReadFile(pah->GetHandle(), &magic, sizeof(uint32_t), &br, NULL); + ReadFile(pah->GetHandle(), &magic, sizeof(uint32_t), &br, nullptr); UINT64 flags; ReadFile(pah->GetHandle(), &flags, sizeof(uint64_t), &br, NULL); @@ -109,7 +111,10 @@ void IExtractor::DestroyExtractor(IExtractor **ppie) { if (ppie && *ppie) { - delete *ppie; - *ppie = NULL; + CFastLZExtractor *pflze = dynamic_cast(*ppie); + if (pflze) + delete pflze; + + *ppie = nullptr; } } diff --git a/Archiver/Source/FastLZArchiver.cpp b/Archiver/Source/FastLZArchiver.cpp index 5e658c9..2a8cf3c 100644 --- a/Archiver/Source/FastLZArchiver.cpp +++ b/Archiver/Source/FastLZArchiver.cpp @@ -42,6 +42,7 @@ CFastLZArchiver::CFastLZArchiver(IArchiveHandle *pah) CFastLZArchiver::~CFastLZArchiver() { + m_FileTable.clear(); } diff --git a/sfx/sfx/LicenseAcceptanceDlg.cpp b/sfx/sfx/LicenseAcceptanceDlg.cpp new file mode 100644 index 0000000..928bdfc --- /dev/null +++ b/sfx/sfx/LicenseAcceptanceDlg.cpp @@ -0,0 +1,84 @@ +/* + Copyright © 2013-2020, Keelan Stuart (hereafter referenced as AUTHOR). All Rights Reserved. + Permission to use, copy, modify, and distribute this software is hereby granted, without fee and without a signed licensing agreement, + provided that the above copyright notice appears in all copies, modifications, and distributions. + Furthermore, AUTHOR assumes no responsibility for any damages caused either directly or indirectly by the use of this software, nor vouches for + any fitness of purpose of this software. + All other copyrighted material contained herein is noted and rights attributed to individual copyright holders. + + For inquiries, contact: keelanstuart@gmail.com +*/ + + +#include "stdafx.h" +#include "sfx.h" +#include "LicenseAcceptanceDlg.h" +#include "afxdialogex.h" + + +// CLicenseAcceptanceDlg dialog + +IMPLEMENT_DYNAMIC(CLicenseAcceptanceDlg, CDialog) + +CLicenseAcceptanceDlg::CLicenseAcceptanceDlg(const TCHAR *description, CWnd *pParent) + : CDialog(IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(_T("ICON")); + + m_Desc = description; +} + +CLicenseAcceptanceDlg::~CLicenseAcceptanceDlg() +{ +} + +void CLicenseAcceptanceDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); +} + + +BEGIN_MESSAGE_MAP(CLicenseAcceptanceDlg, CDialog) + ON_BN_CLICKED(IDC_CHECK_ACCEPTLICENSE, &CLicenseAcceptanceDlg::OnBnClickedCheckAcceptlicense) +END_MESSAGE_MAP() + + +// CLicenseAcceptanceDlg message handlers + + +void CLicenseAcceptanceDlg::OnCancel() +{ + CDialog::OnCancel(); +} + + +BOOL CLicenseAcceptanceDlg::OnInitDialog() +{ + CDialog::OnInitDialog(); + + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + m_CtlOk.SubclassDlgItem(IDOK, this); + + if (m_CtlDesc.CreateFromStatic(IDC_BROWSER, this)) + { + m_CtlDesc.LoadFromResource(_T("license")); + } + + if (m_CtlAcceptCB.SubclassDlgItem(IDC_CHECK_ACCEPTLICENSE, this)) + { + m_CtlOk.EnableWindow(false); + } + + ShowWindow(SW_SHOWNORMAL); + + return FALSE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + + +void CLicenseAcceptanceDlg::OnBnClickedCheckAcceptlicense() +{ + m_CtlOk.EnableWindow((m_CtlAcceptCB.GetCheck() > 0) ? TRUE : FALSE); +} diff --git a/sfx/sfx/LicenseAcceptanceDlg.h b/sfx/sfx/LicenseAcceptanceDlg.h new file mode 100644 index 0000000..cd7478e --- /dev/null +++ b/sfx/sfx/LicenseAcceptanceDlg.h @@ -0,0 +1,46 @@ +/* + Copyright © 2013-2020, Keelan Stuart (hereafter referenced as AUTHOR). All Rights Reserved. + Permission to use, copy, modify, and distribute this software is hereby granted, without fee and without a signed licensing agreement, + provided that the above copyright notice appears in all copies, modifications, and distributions. + Furthermore, AUTHOR assumes no responsibility for any damages caused either directly or indirectly by the use of this software, nor vouches for + any fitness of purpose of this software. + All other copyrighted material contained herein is noted and rights attributed to individual copyright holders. + + For inquiries, contact: keelanstuart@gmail.com +*/ + +#pragma once + + +#include "HtmlCtrl.h" + +// CLicenseKeyEntryDlg dialog + +class CLicenseAcceptanceDlg : public CDialog +{ + DECLARE_DYNAMIC(CLicenseAcceptanceDlg) + +public: + CLicenseAcceptanceDlg(const TCHAR *description, CWnd *pParent = nullptr); // standard constructor + virtual ~CLicenseAcceptanceDlg(); + +// Dialog Data + enum { IDD = IDD_LICENSE_DIALOG }; + +protected: + virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support + + HICON m_hIcon; + CHtmlCtrl m_CtlDesc; + CButton m_CtlAcceptCB; + CButton m_CtlOk; + + CString m_Desc; + + + DECLARE_MESSAGE_MAP() + virtual void OnCancel(); +public: + virtual BOOL OnInitDialog(); + afx_msg void OnBnClickedCheckAcceptlicense(); +}; diff --git a/sfx/sfx/ProgressDlg.cpp b/sfx/sfx/ProgressDlg.cpp index 60f0abf..d390acc 100644 --- a/sfx/sfx/ProgressDlg.cpp +++ b/sfx/sfx/ProgressDlg.cpp @@ -736,9 +736,9 @@ UINT CProgressDlg::InstallThreadProc(LPVOID param) void CProgressDlg::OnSysCommand(UINT nID, LPARAM lParam) { - if (m_Thread && (nID == SC_CLOSE)) + if (nID == SC_CLOSE) { - if (MessageBox(_T("Do you really want to cancel this installation process and exit?"), _T("Confirm Exit"), MB_YESNO) == IDYES) + if (!m_Thread || (MessageBox(_T("Do you really want to cancel this installation process and exit?"), _T("Confirm Exit"), MB_YESNO) == IDYES)) ExitProcess(0); return; diff --git a/sfx/sfx/TinyJS_SfxFunctions.cpp b/sfx/sfx/TinyJS_SfxFunctions.cpp index 1fcc8da..4747568 100644 --- a/sfx/sfx/TinyJS_SfxFunctions.cpp +++ b/sfx/sfx/TinyJS_SfxFunctions.cpp @@ -736,6 +736,22 @@ void scAbortInstall(CScriptVar* c, void* userdata) } +void scShowLicenseAcceptanceDlg(CScriptVar *c, void *userdata) +{ + if (!theApp.m_LicenseAcceptanceDlg) + { + theApp.m_LicenseAcceptanceDlg = new CLicenseAcceptanceDlg(_T("")); + } + + INT_PTR dlg_ret = theApp.m_LicenseAcceptanceDlg->DoModal(); + + if (dlg_ret == IDCANCEL) + { + exit(-1); + } +} + + void scShowLicenseDlg(CScriptVar *c, void *userdata) { if (!theApp.m_LicenseDlg) diff --git a/sfx/sfx/TinyJS_SfxFunctions.h b/sfx/sfx/TinyJS_SfxFunctions.h index 50ad340..e6ab77c 100644 --- a/sfx/sfx/TinyJS_SfxFunctions.h +++ b/sfx/sfx/TinyJS_SfxFunctions.h @@ -24,6 +24,7 @@ extern void scSpawnProcess(CScriptVar *c, void *userdata); extern void scGetExeVersion(CScriptVar* c, void* userdata); extern void scCompareStrings(CScriptVar* c, void* userdata); extern void scAbortInstall(CScriptVar* c, void* userdata); +extern void scShowLicenseAcceptanceDlg(CScriptVar *c, void *userdata); extern void scShowLicenseDlg(CScriptVar *c, void *userdata); extern void scGetLicenseKey(CScriptVar *c, void *userdata); extern void scGetLicenseUser(CScriptVar *c, void *userdata); diff --git a/sfx/sfx/resource.h b/sfx/sfx/resource.h index c045c19..8fb3e24 100644 Binary files a/sfx/sfx/resource.h and b/sfx/sfx/resource.h differ diff --git a/sfx/sfx/sfx.cpp b/sfx/sfx/sfx.cpp index 39416ea..943414b 100644 --- a/sfx/sfx/sfx.cpp +++ b/sfx/sfx/sfx.cpp @@ -49,6 +49,7 @@ CSfxApp::CSfxApp() { m_Flags = 0; m_LicenseDlg = nullptr; + m_LicenseAcceptanceDlg = nullptr; } @@ -168,6 +169,7 @@ BOOL CSfxApp::InitInstance() theApp.m_js.addNative(_T("function SetGlobalInt(name, val)"), scSetGlobalInt, (void *)this); theApp.m_js.addNative(_T("function SetProperty(name, type, aspect, value)"), scSetProperty, (void *)this); theApp.m_js.addNative(_T("function SetRegistryKeyValue(root, key, name, val)"), scSetRegistryKeyValue, (void *)this); + theApp.m_js.addNative(_T("function ShowLicenseAcceptanceDlg()"), scShowLicenseAcceptanceDlg, (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, mode)"), scTextFileOpen, (void *)this); @@ -309,9 +311,10 @@ BOOL CSfxApp::InitInstance() UINT dt = runnow ? DT_PROGRESS : DT_FIRST; + CDialog *dlg = nullptr; while (dt != DT_QUIT) { - CDialog *dlg = CreateSfxDialog((ESfxDlgType)dt); + dlg = CreateSfxDialog((ESfxDlgType)dt); if (!dlg) break; @@ -356,8 +359,15 @@ BOOL CSfxApp::InitInstance() #endif m_pMainWnd = nullptr; + + delete dlg; + dlg = nullptr; + } + + if (dlg) + { delete dlg; - dlg = NULL; + dlg = nullptr; } // Delete the shell manager created above. @@ -385,6 +395,12 @@ BOOL CSfxApp::ExitInstance() m_LicenseDlg = nullptr; } + if (m_LicenseAcceptanceDlg) + { + delete m_LicenseAcceptanceDlg; + m_LicenseAcceptanceDlg = nullptr; + } + return TRUE; } diff --git a/sfx/sfx/sfx.h b/sfx/sfx/sfx.h index 5fa5572..6e58e0f 100644 --- a/sfx/sfx/sfx.h +++ b/sfx/sfx/sfx.h @@ -22,6 +22,7 @@ #include "resource.h" // main symbols #include "TinyJS.h" #include "LicenseEntryDlg.h" +#include "LicenseAcceptanceDlg.h" // CSfxApp: @@ -49,6 +50,7 @@ class CSfxApp : public CWinApp CTinyJS m_js; CLicenseKeyEntryDlg *m_LicenseDlg; + CLicenseAcceptanceDlg *m_LicenseAcceptanceDlg; enum EScriptType { diff --git a/sfx/sfx/sfx.rc b/sfx/sfx/sfx.rc index 17d735a..e877ad1 100644 Binary files a/sfx/sfx/sfx.rc and b/sfx/sfx/sfx.rc differ diff --git a/sfx/sfx/sfx.vcxproj b/sfx/sfx/sfx.vcxproj index 099380f..d48421e 100644 --- a/sfx/sfx/sfx.vcxproj +++ b/sfx/sfx/sfx.vcxproj @@ -225,6 +225,7 @@ + @@ -250,6 +251,7 @@ + diff --git a/sfx/sfx/sfx.vcxproj.filters b/sfx/sfx/sfx.vcxproj.filters index b151765..b7fb560 100644 --- a/sfx/sfx/sfx.vcxproj.filters +++ b/sfx/sfx/sfx.vcxproj.filters @@ -131,6 +131,9 @@ Header Files + + Header Files + @@ -196,6 +199,9 @@ Source Files + + Source Files + diff --git a/sfx/sfxPackager/OutputWnd.cpp b/sfx/sfxPackager/OutputWnd.cpp index 9c1cb7d..f5cbf7b 100644 --- a/sfx/sfxPackager/OutputWnd.cpp +++ b/sfx/sfxPackager/OutputWnd.cpp @@ -185,11 +185,14 @@ void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point) { CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu; - if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE)) - return; - - ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu); - UpdateDialogControls(this, FALSE); + if (pPopupMenu) + { + if (pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE)) + { + ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu); + UpdateDialogControls(this, FALSE); + } + } } SetFocus(); diff --git a/sfx/sfxPackager/sfxPackager.rc b/sfx/sfxPackager/sfxPackager.rc index 23683bd..22ff690 100644 Binary files a/sfx/sfxPackager/sfxPackager.rc and b/sfx/sfxPackager/sfxPackager.rc differ diff --git a/sfx/sfxPackager/sfxPackagerDoc.cpp b/sfx/sfxPackager/sfxPackagerDoc.cpp index ca500fa..005adcf 100644 --- a/sfx/sfxPackager/sfxPackagerDoc.cpp +++ b/sfx/sfxPackager/sfxPackagerDoc.cpp @@ -59,32 +59,35 @@ bool GetFileVersion(const TCHAR *filename, int &major, int &minor, int &release, if (verSize != NULL) { - LPBYTE verData = new BYTE[verSize]; + LPBYTE verData = (LPBYTE)malloc(verSize); - if (GetFileVersionInfo(filename, verHandle, verSize, verData)) + if (verData) { - if (VerQueryValue(verData, _T("\\"), (LPVOID *)&lpBuffer, &size)) + if (GetFileVersionInfo(filename, verHandle, verSize, verData)) { - if (size) + if (VerQueryValue(verData, _T("\\"), (LPVOID *)&lpBuffer, &size)) { - VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer; - if (verInfo->dwSignature == 0xfeef04bd) + if (size) { - major = (verInfo->dwFileVersionMS >> 16) & 0xffff; - minor = (verInfo->dwFileVersionMS >> 0) & 0xffff; - release = (verInfo->dwFileVersionLS >> 16) & 0xffff; - build = (verInfo->dwFileVersionLS >> 0) & 0xffff; + VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer; + if (verInfo->dwSignature == 0xfeef04bd) + { + major = (verInfo->dwFileVersionMS >> 16) & 0xffff; + minor = (verInfo->dwFileVersionMS >> 0) & 0xffff; + release = (verInfo->dwFileVersionLS >> 16) & 0xffff; + build = (verInfo->dwFileVersionLS >> 0) & 0xffff; - if (retffi) - memcpy(retffi, verInfo, sizeof(VS_FIXEDFILEINFO)); + if (retffi) + memcpy(retffi, verInfo, sizeof(VS_FIXEDFILEINFO)); - ret = true; + ret = true; + } } } } - } - delete[] verData; + free(verData); + } } return ret; @@ -595,6 +598,12 @@ bool SetupSfxExecutable(const TCHAR *filename, CSfxPackagerDoc *pDoc, HANDLE &hF bresult = EndUpdateResource(hbur, FALSE); } + + if (pverinfo) + { + free(pverinfo); + pverinfo = nullptr; + } } hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); @@ -1495,7 +1504,8 @@ bool CSfxPackagerDoc::AddFileToArchive(CSfxPackagerView *pview, IArchiver *parc, msg.Format(_T(" WARNING: \"%s\" NOT FOUND!\r\n"), fullfilename); pmf->GetOutputWnd().AppendMessage(COutputWnd::OT_BUILD, msg); - return false; + ret = false; + break; } } } @@ -1619,11 +1629,11 @@ bool CSfxPackagerDoc::CreateSFXPackage(const TCHAR *filename, CSfxPackagerView * TCHAR timebuf[160]; struct tm * timeinfo; - timeinfo = localtime (&start_op); - _tcsftime(timebuf, 160, _T("%c"), timeinfo); + timeinfo = localtime(&start_op); + _tcsftime(timebuf, 160, _T("%R:%S %A, %e %B %Y"), timeinfo); auto pcaption = (*m_Props)[CSfxPackagerDoc::EDOCPROP::CAPTION]; - msg.Format(_T("[%s] Beginning build of \"%s\" (%s) ...\r\n"), timebuf, pcaption ? pcaption->AsString() : _T("???"), fullfilename); + msg.Format(_T("Beginning build of \"%s\" ---- [ %s ]\r\n\r\n Output File: %s\r\n\r\n"), pcaption ? pcaption->AsString() : fullfilename, timebuf, fullfilename); pmf->GetOutputWnd().AppendMessage(COutputWnd::OT_BUILD, msg); TStringArray created_archives; @@ -1637,10 +1647,10 @@ bool CSfxPackagerDoc::CreateSFXPackage(const TCHAR *filename, CSfxPackagerView * UINT spanct; uint64_t sz_uncomp = 0, sz_totalcomp = 0, sz_comp = 0; + CPackagerArchiveHandle *pah = nullptr; + DWORD wr = 0; { - CPackagerArchiveHandle *pah = nullptr; - auto parcmode = (*m_Props)[CSfxPackagerDoc::EDOCPROP::OUTPUT_MODE]; if (parcmode) { @@ -1751,12 +1761,6 @@ bool CSfxPackagerDoc::CreateSFXPackage(const TCHAR *filename, CSfxPackagerView * LARGE_INTEGER tsz = {0}; tsz.LowPart = GetFileSize(pah->GetHandle(), (LPDWORD)&tsz.HighPart); sz_totalcomp += tsz.QuadPart; - - if (pah) - { - pah->Release(); - pah = nullptr; - } } time(&finish_op); @@ -1769,15 +1773,15 @@ bool CSfxPackagerDoc::CreateSFXPackage(const TCHAR *filename, CSfxPackagerView * int seconds = elapsed % 60; timeinfo = localtime (&finish_op); - _tcsftime(timebuf, 160, _T("%c"), timeinfo); + _tcsftime(timebuf, 160, _T("%R:%S %A, %e %B %Y"), timeinfo); if ((wr == WAIT_OBJECT_0) || (wr == WAIT_ABANDONED)) { - msg.Format(_T("[%s] Cancelled. (after: %02d:%02d:%02d)\r\n"), timebuf, hours, minutes, seconds); + msg.Format(_T("\r\nCancelled build of \"%s\" ---- [ %s ]. (after: %02d:%02d:%02d)\r\n"), pcaption ? pcaption->AsString() : fullfilename, timebuf, hours, minutes, seconds); } else { - msg.Format(_T("[%s] Finished.\r\n\r\nAdded %d files, spanning %d archive(s).\r\n"), timebuf, parc->GetFileCount(IArchiver::IM_WHOLE), spanct); + msg.Format(_T("\r\nFinished build of \"%s\" ---- [ %s ].\r\n\r\nAdded %d files, spanning %d archive(s).\r\n"), pcaption ? pcaption->AsString() : fullfilename, timebuf, parc->GetFileCount(IArchiver::IM_WHOLE), spanct); pmf->GetOutputWnd().AppendMessage(COutputWnd::OT_BUILD, msg); double comp_pct = 0.0; @@ -1787,10 +1791,10 @@ bool CSfxPackagerDoc::CreateSFXPackage(const TCHAR *filename, CSfxPackagerView * { comp_pct = 100.0 * std::max(0.0, ((uncomp_sz / comp_sz) - 1.0)); } - msg.Format(_T("Uncompressed Size: %1.02fMB\r\nCompressed Size: %1.02fMB\r\nCompression: %1.02f%%\r\n\r\n"), uncomp_sz / 1024.0f / 1024.0f, comp_sz / 1024.0f / 1024.0f, comp_pct); + msg.Format(_T("Uncompressed size: %1.02fMB\r\nCompressed size (including installer overhead): %1.02fMB\r\nCompression: %1.02f%%\r\n\r\n"), uncomp_sz / 1024.0f / 1024.0f, comp_sz / 1024.0f / 1024.0f, comp_pct); pmf->GetOutputWnd().AppendMessage(COutputWnd::OT_BUILD, msg); - msg.Format(_T("Elapsed Time: %02d:%02d:%02d\r\n\r\n\r\n"), hours, minutes, seconds); + msg.Format(_T("Elapsed time: %02d:%02d:%02d\r\n\r\n\r\n"), hours, minutes, seconds); } pmf->GetOutputWnd().AppendMessage(COutputWnd::OT_BUILD, msg); @@ -1798,6 +1802,12 @@ bool CSfxPackagerDoc::CreateSFXPackage(const TCHAR *filename, CSfxPackagerView * pmf->GetStatusBarWnd().PostMessage(CProgressStatusBar::WM_UPDATE_STATUS, -1, 0); Sleep(0); + if (pah) + { + pah->Release(); + pah = nullptr; + } + IArchiver::DestroyArchiver(&parc); return ret;