Skip to content

Commit

Permalink
Large set of updates:
Browse files Browse the repository at this point in the history
- ToUpper, ToLower js functions added
- Copy, Clear log window fixed
- Added ability to change pre-compression block size, affects overall size
- Added build start and end times
  • Loading branch information
keelanstuart committed Sep 17, 2020
1 parent f0e661c commit e7faa2c
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 112 deletions.
16 changes: 16 additions & 0 deletions Archiver/Include/Archiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ class IArchiver
IM_SPAN // information about only the current span
};

typedef enum BUFFER_SIZE
{
DEFAULT = 0,

LARGEST, // 256k, 1
LARGER, // 128k, 2
LARGE, // 64k, 3
NORMAL, // 32k, 4
SMALL, // 16k, 5
SMALLER, // 8k, 6
SMALLEST, // 4k, 7
} EBufferSize;

enum { MAGIC = 'MAGI' };

// Creates and destroys the archiver
Expand All @@ -108,6 +121,9 @@ class IArchiver
// dst_filename should always be relative
virtual ADD_RESULT AddFile(const TCHAR *src_filename, const TCHAR *dst_filename, uint64_t *sz_uncomp = nullptr, uint64_t *sz_comp = nullptr, const TCHAR *prefile_scriptsnippet = nullptr, const TCHAR *postfile_scriptsnippet = nullptr) = NULL;

// Sets the size of the pre-compressed blocks after the time of this call
virtual void SetCompressionBlockSize(EBufferSize sz) = NULL;

// Finalizes the output, performing any operations that may be necessary to later extract and decompress the data (writing file tables, etc)
virtual FINALIZE_RESULT Finalize() = NULL;
};
Expand Down
22 changes: 20 additions & 2 deletions Archiver/Source/FastLZArchiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ CFastLZArchiver::CFastLZArchiver(IArchiveHandle *pah)
m_pah = pah;
m_InitialOffset = m_pah->GetOffset();

m_BlockSize = IArchiver::BUFFER_SIZE::DEFAULT;

DWORD bw;

// temporary file table offset
Expand Down Expand Up @@ -119,6 +121,8 @@ CFastLZArchiver::ADD_RESULT CFastLZArchiver::AddFile(const TCHAR *src_filename,
GetFileTime(hin, &(fte.m_FTCreated), NULL, &(fte.m_FTModified));

SFileBlock b;
DWORD size_flags = (m_BlockSize << FTEFLAG_BLOCKSIZESHIFT) & (uint64_t)sFileTableEntry::FTEFLAG_BLOCKSIZEMASK;
b.m_Header.m_Flags |= size_flags;

fte.m_Offset = m_pah->GetOffset();

Expand Down Expand Up @@ -419,7 +423,14 @@ bool sFileBlock::ReadUncompressedData(HANDLE hIn)
{
m_Header.m_SizeC = -1; // invalidate our compressed data once we read new uncompressed data

if (ReadFile(hIn, m_BufU, FB_UNCOMPRESSED_BUFSIZE, (LPDWORD)&(m_Header.m_SizeU), NULL) && (m_Header.m_SizeU > 0))
DWORD shift_amt = (m_Header.m_Flags & (uint64_t)sFileTableEntry::FTEFLAG_BLOCKSIZEMASK) >> FTEFLAG_BLOCKSIZESHIFT;
if (!shift_amt)
shift_amt = IArchiver::BUFFER_SIZE::NORMAL;
shift_amt--;

DWORD read_amt = FB_UNCOMPRESSED_BUFSIZE >> shift_amt;

if (ReadFile(hIn, m_BufU, read_amt, (LPDWORD)&(m_Header.m_SizeU), NULL) && (m_Header.m_SizeU > 0))
{
return true;
}
Expand Down Expand Up @@ -474,9 +485,16 @@ bool sFileBlock::ReadCompressedData(HANDLE hIn)

bool sFileBlock::DecompressData()
{
DWORD shift_amt = (m_Header.m_Flags & (uint64_t)sFileTableEntry::FTEFLAG_BLOCKSIZEMASK) >> FTEFLAG_BLOCKSIZESHIFT;
if (!shift_amt)
shift_amt = IArchiver::BUFFER_SIZE::NORMAL;
shift_amt--;

DWORD read_amt = FB_UNCOMPRESSED_BUFSIZE >> shift_amt;

if (m_Header.m_SizeC != (uint32_t)-1)
{
m_Header.m_SizeU = fastlz_decompress(m_BufC, m_Header.m_SizeC, m_BufU, FB_UNCOMPRESSED_BUFSIZE);
m_Header.m_SizeU = fastlz_decompress(m_BufC, m_Header.m_SizeC, m_BufU, read_amt);

return true;
}
Expand Down
18 changes: 14 additions & 4 deletions Archiver/Source/FastLZArchiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ struct sFileTableEntry
{
enum
{
FTEFLAG_SPANNED = 0x0000000000000001, // a spanned file will be partially in multiple files
FTEFLAG_DOWNLOAD = 0x0000000000000002, // an empty file that is just a download reference
FTEFLAG_SPANNED = 0x0000000000000001, // a spanned file will be partially in multiple files
FTEFLAG_DOWNLOAD = 0x0000000000000002, // an empty file that is just a download reference
FTEFLAG_BLOCKSIZEMASK = 0x000000000000001C, // a mask of 3 bits (0-7) that indicates the size of the block
};

uint64_t m_Flags;
#define FTEFLAG_BLOCKSIZESHIFT 2 // mask off the bytes with BLOCKSIZEMASK, then shift right by this amount

uint32_t m_Flags;
uint64_t m_UncompressedSize;
uint64_t m_CompressedSize;
uint32_t m_Crc;
Expand Down Expand Up @@ -67,9 +70,12 @@ typedef std::deque<SFileTableEntry> TFileTable;

struct sFileBlock
{

#define MAX_UNCOMPRESSED_BUFSIZE 256

enum
{
FB_UNCOMPRESSED_BUFSIZE = 64 * (1 << 10),
FB_UNCOMPRESSED_BUFSIZE = MAX_UNCOMPRESSED_BUFSIZE * (1 << 10),
FB_COMPRESSED_BUFSIZE = (FB_UNCOMPRESSED_BUFSIZE * 2)
};

Expand Down Expand Up @@ -111,6 +117,9 @@ class CFastLZArchiver : public IArchiver
// Adds a file to the archive
virtual ADD_RESULT AddFile(const TCHAR *src_filename, const TCHAR *dst_filename, uint64_t *sz_uncomp = nullptr, uint64_t *sz_comp = nullptr, const TCHAR *prefile_scriptsnippet = nullptr, const TCHAR *postfile_scriptsnippet = nullptr);

// Sets the size of the pre-compressed blocks after the time of this call
virtual void SetCompressionBlockSize(IArchiver::EBufferSize sz) { m_BlockSize = sz; }

virtual FINALIZE_RESULT Finalize();

enum { MAGIC_FASTLZ = 'FSTL' };
Expand All @@ -131,6 +140,7 @@ class CFastLZArchiver : public IArchiver

uint64_t m_MaxSize;

IArchiver::EBufferSize m_BlockSize;
};

class CFastLZExtractor : public IExtractor
Expand Down
3 changes: 2 additions & 1 deletion sfx/sfx/ProgressDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ DWORD CProgressDlg::RunInstall()
return ret;
}


UINT CProgressDlg::InstallThreadProc(LPVOID param)
{
CProgressDlg *_this = (CProgressDlg *)param;
Expand All @@ -735,7 +736,7 @@ UINT CProgressDlg::InstallThreadProc(LPVOID param)

void CProgressDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if (nID == SC_CLOSE)
if (m_Thread && (nID == SC_CLOSE))
{
if (MessageBox(_T("Do you really want to cancel this installation process and exit?"), _T("Confirm Exit"), MB_YESNO) == IDYES)
ExitProcess(0);
Expand Down
24 changes: 24 additions & 0 deletions sfx/sfx/TinyJS_SfxFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,30 @@ void scCompareStrings(CScriptVar* c, void* userdata)
}


void scToUpper(CScriptVar* c, void* userdata)
{
tstring str = c->getParameter(_T("str"))->getString();

std::transform(str.begin(), str.end(), str.begin(), std::toupper);

CScriptVar* ret = c->getReturnVar();
if (ret)
ret->setString(str);
}


void scToLower(CScriptVar* c, void* userdata)
{
tstring str = c->getParameter(_T("str"))->getString();

std::transform(str.begin(), str.end(), str.begin(), std::tolower);

CScriptVar* ret = c->getReturnVar();
if (ret)
ret->setString(str);
}


void scAbortInstall(CScriptVar* c, void* userdata)
{
exit(-1);
Expand Down
2 changes: 2 additions & 0 deletions sfx/sfx/TinyJS_SfxFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ extern void scGetFileNameFromPath(CScriptVar *c, void *userdata);
extern void scEcho(CScriptVar *c, void *userdata);
extern void scSetProperty(CScriptVar *c, void *userdata);
extern void scGetProperty(CScriptVar *c, void *userdata);
extern void scToLower(CScriptVar *c, void *userdata);
extern void scToUpper(CScriptVar *c, void *userdata);
8 changes: 5 additions & 3 deletions sfx/sfx/sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ BOOL CSfxApp::InitInstance()
theApp.m_js.addNative(_T("function DeleteFile(path)"), scDeleteFile, (void *)this);
theApp.m_js.addNative(_T("function DeleteRegistryKey(root, key, subkey)"), scDeleteRegistryKey, (void *)this);
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 FilenameHasExtension(filename, ext)"), scFilenameHasExtension, (void *)this);
theApp.m_js.addNative(_T("function GetCurrentDateString()"), scGetCurrentDateStr, (void *)this);
theApp.m_js.addNative(_T("function GetGlobalEnvironmentVariable(varname)"), scGetGlobalEnvironmentVariable, (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 GetProperty(name)"), scGetProperty, (void *)this);
theApp.m_js.addNative(_T("function GetRegistryKeyValue(root, key, name)"), scGetRegistryKeyValue, (void *)this);
theApp.m_js.addNative(_T("function GetFileNameFromPath(filepath)"), scGetFileNameFromPath, (void*)this);
theApp.m_js.addNative(_T("function GetLicenseKey()"), scGetLicenseKey, (void *)this);
Expand All @@ -164,6 +166,7 @@ BOOL CSfxApp::InitInstance()
theApp.m_js.addNative(_T("function RenameFile(filename, newname)"), scRenameFile, (void *)this);
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 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 ShowLicenseDlg()"), scShowLicenseDlg, (void *)this);
theApp.m_js.addNative(_T("function SpawnProcess(cmd, params, rundir, block)"), scSpawnProcess, (void *)this);
Expand All @@ -172,9 +175,8 @@ BOOL CSfxApp::InitInstance()
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_js.addNative(_T("function Echo(msg)"), scEcho, (void *)this);
theApp.m_js.addNative(_T("function SetProperty(name, type, aspect, value)"), scSetProperty, (void *)this);
theApp.m_js.addNative(_T("function GetProperty(name)"), scGetProperty, (void *)this);
theApp.m_js.addNative(_T("function ToLower(str)"), scToLower, (void *)this);
theApp.m_js.addNative(_T("function ToUpper(str)"), scToUpper, (void *)this);

// Create the shell manager, in case the dialog contains
// any shell tree view or shell list view controls.
Expand Down
37 changes: 20 additions & 17 deletions sfx/sfxPackager/OutputWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int COutputWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
m_wndTabs.AddTab(&m_wndOutputDebug, strTabName, (UINT)1);

// Fill output tabs with some dummy text (nothing magic here)
AppendMessage(OT_DEBUG, _T("sfxPackager v2.6 - contact Keelan Stuart ([email protected]) with comments, bug reports, or suggestions.\r\n"));
AppendMessage(OT_DEBUG, _T("sfxPackager v3.3 - contact Keelan Stuart ([email protected]) with comments, bug reports, or suggestions.\r\n"));

return 0;
}
Expand Down Expand Up @@ -169,7 +169,6 @@ BEGIN_MESSAGE_MAP(COutputList, CListBox)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
ON_COMMAND(ID_VIEW_OUTPUTWND, OnViewOutput)
ON_WM_WINDOWPOSCHANGING()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -198,24 +197,28 @@ void COutputList::OnContextMenu(CWnd* /*pWnd*/, CPoint point)

void COutputList::OnEditCopy()
{
MessageBox(_T("Copy output"));
int sa, sb;
bool clearsel = false;

GetSel(sa, sb);
size_t size = sb - sa;

if (!size)
{
SetSel(0, -1);
clearsel = true;
}

Copy();

if (clearsel)
SetSel(0);
}

void COutputList::OnEditClear()
{
SetSel(0, -1, TRUE);
SetReadOnly(FALSE);
Clear();
}

void COutputList::OnViewOutput()
{
CDockablePane* pParentBar = DYNAMIC_DOWNCAST(CDockablePane, GetOwner());
CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());

if (pMainFrame != NULL && pParentBar != NULL)
{
pMainFrame->SetFocus();
pMainFrame->ShowPane(pParentBar, FALSE, FALSE, FALSE);
pMainFrame->RecalcLayout();

}
SetReadOnly(TRUE);
}
1 change: 0 additions & 1 deletion sfx/sfxPackager/OutputWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class COutputList : public CEdit
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
afx_msg void OnEditCopy();
afx_msg void OnEditClear();
afx_msg void OnViewOutput();

DECLARE_MESSAGE_MAP()
};
Expand Down
Binary file modified sfx/sfxPackager/resource.h
Binary file not shown.
Binary file modified sfx/sfxPackager/sfxPackager.rc
Binary file not shown.
Loading

0 comments on commit e7faa2c

Please sign in to comment.