* MakeNSISW symbol sets don't need movable memory
* Use helper functions to read&write MRU and symbol set strings * Don't create empty MRU key when there is nothing to save * Made some helper functions static git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6618 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
6de4fbc743
commit
8577c8e9ae
4 changed files with 174 additions and 216 deletions
|
@ -113,7 +113,7 @@ void SetScript(const TCHAR *script, bool clearArgs /*= true*/)
|
|||
lstrcpy(g_sdata.script, script);
|
||||
}
|
||||
|
||||
void AddScriptCmdArgs(const TCHAR *arg)
|
||||
static void AddScriptCmdArgs(const TCHAR *arg)
|
||||
{
|
||||
g_sdata.script_cmd_args = GlobalReAlloc(g_sdata.script_cmd_args,
|
||||
GlobalSize(g_sdata.script_cmd_args) + (lstrlen(arg) + 2/* quotes */ + 1 /* space */)*sizeof(TCHAR),
|
||||
|
@ -128,7 +128,7 @@ void AddScriptCmdArgs(const TCHAR *arg)
|
|||
GlobalUnlock(g_sdata.script_cmd_args);
|
||||
}
|
||||
|
||||
void ProcessCommandLine()
|
||||
static void ProcessCommandLine()
|
||||
{
|
||||
TCHAR **argv;
|
||||
int i, j;
|
||||
|
@ -243,9 +243,8 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
|
|||
}
|
||||
case WM_DESTROY:
|
||||
{
|
||||
DragAcceptFiles(g_sdata.hwnd,FALSE);
|
||||
DragAcceptFiles(g_sdata.hwnd, FALSE);
|
||||
SaveSymbols();
|
||||
SaveCompressor();
|
||||
SaveMRUList();
|
||||
SaveWindowPos(g_sdata.hwnd);
|
||||
ImageList_Destroy(g_toolbar.imagelist);
|
||||
|
@ -862,29 +861,26 @@ INT_PTR CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
void EnableSymbolSetButtons(HWND hwndDlg)
|
||||
static void EnableSymbolSetButtons(HWND hwndDlg)
|
||||
{
|
||||
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETCOUNT, 0, 0);
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_CLEAR), n > 0);
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), n > 0);
|
||||
}
|
||||
|
||||
void EnableSymbolEditButtons(HWND hwndDlg)
|
||||
static void EnableSymbolEditButtons(HWND hwndDlg)
|
||||
{
|
||||
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETSELCOUNT, 0, 0);
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT), n == 1);
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), n != 0);
|
||||
}
|
||||
|
||||
void SetSymbols(HWND hwndDlg, TCHAR **symbols)
|
||||
static void SetSymbols(HWND hwndDlg, TCHAR **symbols)
|
||||
{
|
||||
int i = 0;
|
||||
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_RESETCONTENT , 0, 0);
|
||||
if (symbols) {
|
||||
while (symbols[i]) {
|
||||
for (SIZE_T i = 0; symbols[i]; ++i)
|
||||
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_ADDSTRING, 0, (LPARAM)symbols[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
EnableSymbolSetButtons(hwndDlg);
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_RIGHT), FALSE);
|
||||
|
@ -892,16 +888,19 @@ void SetSymbols(HWND hwndDlg, TCHAR **symbols)
|
|||
EnableWindow(GetDlgItem(hwndDlg, IDC_DEL), FALSE);
|
||||
}
|
||||
|
||||
TCHAR **GetSymbols(HWND hwndDlg)
|
||||
static TCHAR **GetSymbols(HWND hwndDlg)
|
||||
{
|
||||
LRESULT n = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETCOUNT, 0, 0);
|
||||
TCHAR **symbols = NULL;
|
||||
if(n > 0) {
|
||||
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (n+1)*sizeof(TCHAR *));
|
||||
symbols = (TCHAR **)GlobalLock(hMem);
|
||||
symbols = (TCHAR **) GlobalAlloc(GPTR, (n+1)*sizeof(TCHAR *));
|
||||
for (LRESULT i = 0; i < n; i++) {
|
||||
LRESULT len = SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXTLEN, (WPARAM)i, 0);
|
||||
symbols[i] = (TCHAR*) MemAllocZI((len+1)*sizeof(TCHAR));
|
||||
if (!symbols[i]) {
|
||||
FreeSymbolSet(symbols);
|
||||
return NULL;
|
||||
}
|
||||
SendDlgItemMessage(hwndDlg, IDC_SYMBOLS, LB_GETTEXT, (WPARAM)i, (LPARAM)symbols[i]);
|
||||
}
|
||||
symbols[n] = NULL;
|
||||
|
@ -926,13 +925,9 @@ INT_PTR CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar
|
|||
{
|
||||
TCHAR *name = (TCHAR *)wParam;
|
||||
TCHAR **symbols = LoadSymbolSet(name);
|
||||
HGLOBAL hMem;
|
||||
|
||||
SetSymbols(hwndDlg, symbols);
|
||||
if(symbols) {
|
||||
hMem = GlobalHandle(symbols);
|
||||
GlobalUnlock(hMem);
|
||||
GlobalFree(hMem);
|
||||
SetSymbols(hwndDlg, symbols);
|
||||
GlobalFree((HGLOBAL) symbols);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -940,13 +935,9 @@ INT_PTR CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar
|
|||
{
|
||||
TCHAR *name = (TCHAR *)wParam;
|
||||
TCHAR **symbols = GetSymbols(hwndDlg);
|
||||
HGLOBAL hMem;
|
||||
|
||||
if(symbols) {
|
||||
SaveSymbolSet(name, symbols);
|
||||
hMem = GlobalHandle(symbols);
|
||||
GlobalUnlock(hMem);
|
||||
GlobalFree(hMem);
|
||||
GlobalFree((HGLOBAL) symbols);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -960,14 +951,13 @@ INT_PTR CALLBACK SettingsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar
|
|||
g_sdata.symbols = GetSymbols(hwndDlg);
|
||||
|
||||
INT_PTR n = SendDlgItemMessage(hwndDlg, IDC_COMPRESSOR, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
|
||||
if (n >= (INT_PTR)COMPRESSOR_SCRIPT && n <= (INT_PTR)COMPRESSOR_BEST) {
|
||||
if (n >= (INT_PTR)COMPRESSOR_SCRIPT && n <= (INT_PTR)COMPRESSOR_BEST)
|
||||
g_sdata.default_compressor = (NCOMPRESSOR)n;
|
||||
}
|
||||
else {
|
||||
else
|
||||
g_sdata.default_compressor = COMPRESSOR_SCRIPT;
|
||||
}
|
||||
EndDialog(hwndDlg, TRUE);
|
||||
SaveCompressor();
|
||||
SetCompressor(g_sdata.default_compressor);
|
||||
EndDialog(hwndDlg, TRUE);
|
||||
}
|
||||
break;
|
||||
case IDCANCEL:
|
||||
|
@ -1153,7 +1143,7 @@ INT_PTR CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
|
|||
|
||||
hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), 0, 0, 0); // Handle of list
|
||||
hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), hwndEdit, 0, 0); //Handle of edit box
|
||||
SendMessage(hwndEdit, EM_LIMITTEXT, (WPARAM)SYMBOL_SET_NAME_MAXLEN, 0);
|
||||
SendMessage(hwndEdit, EM_LIMITTEXT, (WPARAM)SYMSETNAME_MAXLEN, 0);
|
||||
if(g_symbol_set_mode == 1) { //Load
|
||||
SetWindowText(hwndDlg, LOAD_SYMBOL_SET_DLG_NAME);
|
||||
SetWindowText(GetDlgItem(hwndDlg, IDOK), LOAD_BUTTON_TEXT);
|
||||
|
@ -1171,11 +1161,11 @@ INT_PTR CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
|
|||
case IDOK:
|
||||
{
|
||||
HWND hwndEdit;
|
||||
TCHAR name[SYMBOL_SET_NAME_MAXLEN+1];
|
||||
TCHAR name[SYMSETNAME_MAXLEN+1];
|
||||
|
||||
hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), 0, 0, 0); // Handle of list
|
||||
hwndEdit = FindWindowEx(GetDlgItem(hwndDlg, IDC_NAMES), hwndEdit, 0, 0); //Handle of edit box
|
||||
SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)SYMBOL_SET_NAME_MAXLEN+1, (LPARAM)name);
|
||||
SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)COUNTOF(name), (LPARAM)name);
|
||||
if(!*name) {
|
||||
if(g_symbol_set_mode == 1) { //Load
|
||||
MessageBox(hwndDlg,LOAD_SYMBOL_SET_MESSAGE,LOAD_SYMBOL_SET_DLG_NAME,MB_OK|MB_ICONEXCLAMATION);
|
||||
|
|
|
@ -65,7 +65,6 @@
|
|||
#define RESTORED_COMPRESSOR_MESSAGE _T("\n\nThe %s compressor created the smallest installer (%d bytes).")
|
||||
#define EXE_HEADER_COMPRESSOR_STAT _T("EXE header size:")
|
||||
#define TOTAL_SIZE_COMPRESSOR_STAT _T("Total size:")
|
||||
#define SYMBOL_SET_NAME_MAXLEN 40
|
||||
#define LOAD_SYMBOL_SET_DLG_NAME _T("Load Symbol Definitions Set")
|
||||
#define SAVE_SYMBOL_SET_DLG_NAME _T("Save Symbol Definitions Set")
|
||||
#define LOAD_BUTTON_TEXT _T("Load")
|
||||
|
@ -170,9 +169,10 @@ TCHAR* BuildSymbols();
|
|||
void SetCompressor(NCOMPRESSOR);
|
||||
void RestoreSymbols();
|
||||
void SaveSymbols();
|
||||
void DeleteSymbolSet(TCHAR *);
|
||||
TCHAR** LoadSymbolSet(TCHAR *);
|
||||
void SaveSymbolSet(TCHAR *, TCHAR **);
|
||||
void FreeSymbolSet(TCHAR **);
|
||||
void DeleteSymbolSet(const TCHAR *);
|
||||
TCHAR** LoadSymbolSet(const TCHAR *);
|
||||
void SaveSymbolSet(const TCHAR *, TCHAR **);
|
||||
void RestoreMRUList();
|
||||
void SaveMRUList();
|
||||
|
||||
|
|
|
@ -144,20 +144,20 @@ void SetTitle(HWND hwnd,const TCHAR *substr) {
|
|||
}
|
||||
|
||||
void CopyToClipboard(HWND hwnd) {
|
||||
if (!hwnd||!OpenClipboard(hwnd)) return;
|
||||
LRESULT len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE,(len+1)*sizeof(TCHAR));
|
||||
if (!hwnd || !OpenClipboard(hwnd)) return;
|
||||
LRESULT len = SendDlgItemMessage(hwnd, IDC_LOGWIN, WM_GETTEXTLENGTH, 0, 0);
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (++len)*sizeof(TCHAR));
|
||||
if (!mem) { CloseClipboard(); return; }
|
||||
TCHAR *existing_text = (TCHAR *)GlobalLock(mem);
|
||||
if (!existing_text) { CloseClipboard(); return; }
|
||||
TCHAR *txt = (TCHAR *)GlobalLock(mem);
|
||||
if (!txt) { CloseClipboard(); return; }
|
||||
EmptyClipboard();
|
||||
existing_text[0]=0;
|
||||
SendMessage(GetDlgItem(hwnd, IDC_LOGWIN), WM_GETTEXT, (WPARAM)(len+1), (LPARAM)existing_text);
|
||||
txt[0] = 0;
|
||||
SendDlgItemMessage(hwnd, IDC_LOGWIN, WM_GETTEXT, (WPARAM)(len), (LPARAM)txt);
|
||||
GlobalUnlock(mem);
|
||||
#ifdef _UNICODE
|
||||
SetClipboardData(CF_UNICODETEXT,mem);
|
||||
SetClipboardData(CF_UNICODETEXT, mem);
|
||||
#else
|
||||
SetClipboardData(CF_TEXT,mem);
|
||||
SetClipboardData(CF_TEXT, mem);
|
||||
#endif
|
||||
CloseClipboard();
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ void LogMessage(HWND hwnd,const TCHAR *str) {
|
|||
void ErrorMessage(HWND hwnd,const TCHAR *str) {
|
||||
if (!str) return;
|
||||
TCHAR buf[1028];
|
||||
wsprintf(buf,_T("[Error] %s\r\n"),str);
|
||||
wsprintf(buf, _T("[Error] %s\r\n"), str);
|
||||
LogMessage(hwnd,buf);
|
||||
}
|
||||
|
||||
|
@ -324,23 +324,43 @@ void CompileNSISScript() {
|
|||
g_sdata.thread=CreateThread(NULL,0,MakeNSISProc,0,0,&tid);
|
||||
}
|
||||
|
||||
static DWORD RegWriteString(HKEY hKey, LPCTSTR Name, LPCTSTR Data)
|
||||
{
|
||||
const DWORD cb = (lstrlen(Data) + 1) * sizeof(*Data);
|
||||
return RegSetValueEx(hKey, Name, 0, REG_SZ, (LPBYTE)Data, cb);
|
||||
}
|
||||
|
||||
static DWORD RegReadString(HKEY hKey, LPCTSTR Name, LPTSTR Buf, DWORD cbBufSize) {
|
||||
DWORD ec, rt, cb = cbBufSize, cbCh = sizeof(*Buf);
|
||||
ec = RegQueryValueEx(hKey, Name, NULL, &rt, (BYTE*) Buf, &cb);
|
||||
if (cbBufSize) {
|
||||
#if 0
|
||||
if (rt == REG_DWORD) cb = cbCh * wsprintf(Buf, _T("%d"), *((INT32*)Buf));
|
||||
#endif
|
||||
if (cb+cbCh < cbBufSize) Buf[cb / cbCh] = _T('\0'); // Add a \0 after the data if there is room
|
||||
Buf[(cbBufSize / cbCh) - 1] = _T('\0'); // Always \0 terminate, truncating data if necessary
|
||||
}
|
||||
return ec;
|
||||
}
|
||||
|
||||
static DWORD RegOpenKeyForReading(HKEY hRoot, LPCTSTR SubKey, HKEY*pKey) {
|
||||
return RegOpenKeyEx(hRoot, SubKey, 0, KEY_READ, pKey);
|
||||
}
|
||||
|
||||
static bool InternalOpenRegSettingsKey(HKEY root, HKEY &key, bool create) {
|
||||
if (create) {
|
||||
if (RegCreateKey(root, REGKEY, &key) == ERROR_SUCCESS)
|
||||
return true;
|
||||
} else {
|
||||
if (RegOpenKeyEx(root, REGKEY, 0, KEY_READ, &key) == ERROR_SUCCESS)
|
||||
if (RegOpenKeyForReading(root, REGKEY, &key) == ERROR_SUCCESS)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OpenRegSettingsKey(HKEY &hKey, bool create) {
|
||||
if (InternalOpenRegSettingsKey(REGSEC, hKey, create))
|
||||
return true;
|
||||
if (InternalOpenRegSettingsKey(REGSECDEF, hKey, create))
|
||||
return true;
|
||||
return false;
|
||||
return InternalOpenRegSettingsKey(REGSEC, hKey, create)
|
||||
|| InternalOpenRegSettingsKey(REGSECDEF, hKey, create);
|
||||
}
|
||||
|
||||
DWORD ReadRegSettingDW(LPCTSTR name, const DWORD defval) {
|
||||
|
@ -407,139 +427,104 @@ void SaveWindowPos(HWND hwnd) {
|
|||
WINDOWPLACEMENT p;
|
||||
p.length = sizeof(p);
|
||||
GetWindowPlacement(hwnd, &p);
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(LPBYTE)&p,sizeof(p));
|
||||
if (CreateRegSettingsKey(hKey)) {
|
||||
RegSetValueEx(hKey, REGLOC, 0, REG_BINARY, (LPBYTE)&p, sizeof(p));
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
void RestoreSymbols()
|
||||
{
|
||||
void RestoreSymbols() {
|
||||
g_sdata.symbols = LoadSymbolSet(NULL);
|
||||
}
|
||||
|
||||
void SaveSymbols()
|
||||
{
|
||||
void SaveSymbols() {
|
||||
SaveSymbolSet(NULL, g_sdata.symbols);
|
||||
}
|
||||
|
||||
void DeleteSymbolSet(TCHAR *name)
|
||||
{
|
||||
if(name) {
|
||||
HKEY hKey;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
TCHAR subkey[1024];
|
||||
wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name);
|
||||
RegDeleteKey(hKey,subkey);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
#define SYMSET_SUBKEY_MAXLEN (100 + SYMSETNAME_MAXLEN) // REGSYMSUBKEY + [\name]
|
||||
static int CreateSymbolSetSubkeyPath(const TCHAR *name, TCHAR *buffer) {
|
||||
return wsprintf(buffer, name ? _T("%s\\%s") : _T("%s"), REGSYMSUBKEY, name);
|
||||
}
|
||||
|
||||
void FreeSymbolSet(TCHAR **symbols) {
|
||||
if (symbols) {
|
||||
for (SIZE_T i = 0; symbols[i]; ++i)
|
||||
MemSafeFree(symbols[i]);
|
||||
GlobalFree((HGLOBAL) symbols);
|
||||
}
|
||||
}
|
||||
|
||||
TCHAR** LoadSymbolSet(TCHAR *name)
|
||||
{
|
||||
void DeleteSymbolSet(const TCHAR *name) {
|
||||
HKEY hKey;
|
||||
HKEY hSubKey;
|
||||
TCHAR **symbols = NULL;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
TCHAR subkey[1024];
|
||||
if(name) {
|
||||
wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name);
|
||||
}
|
||||
else {
|
||||
lstrcpy(subkey,REGSYMSUBKEY);
|
||||
}
|
||||
if (RegCreateKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) {
|
||||
TCHAR buf[8];
|
||||
DWORD l;
|
||||
DWORD t;
|
||||
DWORD bufSize;
|
||||
DWORD i = 0;
|
||||
HGLOBAL hMem = NULL;
|
||||
|
||||
while(TRUE) {
|
||||
l = 0;
|
||||
bufSize = sizeof(buf);
|
||||
if ((RegEnumValue(hSubKey,i, buf, &bufSize,NULL,&t,NULL,&l)==ERROR_SUCCESS)&&(t == REG_SZ)) {
|
||||
if(symbols) {
|
||||
GlobalUnlock(hMem);
|
||||
hMem = GlobalReAlloc(hMem, (i+2)*sizeof(TCHAR *), GMEM_MOVEABLE|GMEM_ZEROINIT);
|
||||
symbols = (TCHAR **)GlobalLock(hMem);
|
||||
}
|
||||
else {
|
||||
hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, (i+2)*sizeof(TCHAR *));
|
||||
symbols = (TCHAR **)GlobalLock(hMem);
|
||||
}
|
||||
if(symbols) {
|
||||
l++;
|
||||
DWORD bytes = sizeof(TCHAR) * l;
|
||||
symbols[i] = (TCHAR*) MemAllocZI(bytes);
|
||||
if (symbols[i]) {
|
||||
RegQueryValueEx(hSubKey,buf,NULL,&t,(unsigned char*)symbols[i],&bytes);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
symbols[i] = NULL;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
RegCloseKey(hSubKey);
|
||||
}
|
||||
if (name && OpenRegSettingsKey(hKey)) {
|
||||
TCHAR subkey[SYMSET_SUBKEY_MAXLEN+1];
|
||||
CreateSymbolSetSubkeyPath(name, subkey);
|
||||
RegDeleteKey(hKey, subkey);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
TCHAR** LoadSymbolSet(const TCHAR *name) {
|
||||
HKEY hCfgKey, hSymKey;
|
||||
TCHAR **symbols = NULL;
|
||||
if (OpenRegSettingsKey(hCfgKey)) {
|
||||
TCHAR subkey[SYMSET_SUBKEY_MAXLEN+1];
|
||||
CreateSymbolSetSubkeyPath(name, subkey);
|
||||
if (RegOpenKeyForReading(hCfgKey, subkey, &hSymKey) == ERROR_SUCCESS) {
|
||||
TCHAR bufName[8];
|
||||
for (DWORD i = 0, rt, cbBuf, cbData;;) {
|
||||
cbBuf = sizeof(bufName);
|
||||
if (RegEnumValue(hSymKey, i, bufName, &cbBuf, NULL, &rt, NULL, &cbData) == ERROR_SUCCESS && rt == REG_SZ) {
|
||||
if(symbols) {
|
||||
HGLOBAL newmem = GlobalReAlloc(symbols, (i+2)*sizeof(TCHAR*), GMEM_MOVEABLE|GMEM_ZEROINIT);
|
||||
if (!newmem) FreeSymbolSet(symbols);
|
||||
symbols = (TCHAR**) newmem;
|
||||
}
|
||||
else {
|
||||
symbols = (TCHAR**) GlobalAlloc(GPTR, (i+2)*sizeof(TCHAR*));
|
||||
}
|
||||
if (!symbols) break; // Out of memory, abort!
|
||||
symbols[i] = (TCHAR*) MemAllocZI(cbData += sizeof(TCHAR));
|
||||
if (!symbols[i] || RegReadString(hSymKey, bufName, symbols[i], cbData)) {
|
||||
FreeSymbolSet(symbols);
|
||||
break;
|
||||
}
|
||||
symbols[++i] = NULL; // The symbols array is terminated by a NULL pointer
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
RegCloseKey(hSymKey);
|
||||
}
|
||||
RegCloseKey(hCfgKey);
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
void SaveSymbolSet(TCHAR *name, TCHAR **symbols)
|
||||
{
|
||||
HKEY hKey;
|
||||
HKEY hSubKey;
|
||||
int n = 0;
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
TCHAR subkey[1024];
|
||||
if(name) {
|
||||
wsprintf(subkey,_T("%s\\%s"),REGSYMSUBKEY,name);
|
||||
}
|
||||
else {
|
||||
lstrcpy(subkey,REGSYMSUBKEY);
|
||||
}
|
||||
|
||||
if (RegOpenKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) {
|
||||
TCHAR buf[8];
|
||||
DWORD l;
|
||||
while(TRUE) {
|
||||
l = sizeof(buf);
|
||||
if (RegEnumValue(hSubKey,0, buf, &l,NULL,NULL,NULL,NULL)==ERROR_SUCCESS) {
|
||||
RegDeleteValue(hSubKey,buf);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
void SaveSymbolSet(const TCHAR *name, TCHAR **symbols) {
|
||||
HKEY hCfgKey, hSymKey;
|
||||
if (CreateRegSettingsKey(hCfgKey)) {
|
||||
TCHAR subkey[SYMSET_SUBKEY_MAXLEN+1], bufName[8];
|
||||
CreateSymbolSetSubkeyPath(name, subkey);
|
||||
if (RegOpenKey(hCfgKey, subkey, &hSymKey) == ERROR_SUCCESS) {
|
||||
// Cannot use DeleteSymbolSet because name might be NULL and named sets are stored inside the base symbols key
|
||||
for (DWORD cb;;) {
|
||||
cb = sizeof(bufName);
|
||||
if (RegEnumValue(hSymKey,0, bufName, &cb,NULL,NULL,NULL,NULL)!=ERROR_SUCCESS) break;
|
||||
RegDeleteValue(hSymKey, bufName);
|
||||
}
|
||||
RegCloseKey(hSubKey);
|
||||
RegCloseKey(hSymKey);
|
||||
}
|
||||
if(symbols) {
|
||||
if (RegCreateKey(hKey,subkey,&hSubKey) == ERROR_SUCCESS) {
|
||||
TCHAR buf[8];
|
||||
n = 0;
|
||||
while(symbols[n]) {
|
||||
wsprintf(buf,_T("%d"),n);
|
||||
RegSetValueEx(hSubKey,buf,0,REG_SZ,(CONST BYTE *)symbols[n],(lstrlen(symbols[n])+1)*sizeof(TCHAR));
|
||||
n++;
|
||||
if (RegCreateKey(hCfgKey, subkey, &hSymKey) == ERROR_SUCCESS) {
|
||||
for (SIZE_T i = 0; symbols[i]; ++i) {
|
||||
wsprintf(bufName, _T("%d"), (INT) i);
|
||||
RegWriteString(hSymKey, bufName, symbols[i]);
|
||||
}
|
||||
RegCloseKey(hSubKey);
|
||||
RegCloseKey(hSymKey);
|
||||
}
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
RegCloseKey(hCfgKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -552,18 +537,8 @@ void ResetObjects() {
|
|||
}
|
||||
|
||||
void ResetSymbols() {
|
||||
if(g_sdata.symbols) {
|
||||
HGLOBAL hMem;
|
||||
int i = 0;
|
||||
while(g_sdata.symbols[i]) {
|
||||
MemFree(g_sdata.symbols[i]);
|
||||
i++;
|
||||
}
|
||||
hMem = GlobalHandle(g_sdata.symbols);
|
||||
GlobalUnlock(hMem);
|
||||
GlobalFree(hMem);
|
||||
g_sdata.symbols = NULL;
|
||||
}
|
||||
FreeSymbolSet(g_sdata.symbols);
|
||||
g_sdata.symbols = NULL;
|
||||
}
|
||||
|
||||
void FreeSpawn(PROCESS_INFORMATION *pPI, HANDLE hRd, HANDLE hWr) {
|
||||
|
@ -876,25 +851,21 @@ void LoadMRUFile(int position)
|
|||
|
||||
void RestoreMRUList()
|
||||
{
|
||||
HKEY hKey;
|
||||
HKEY hSubKey;
|
||||
int n = 0;
|
||||
int i;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
||||
TCHAR buf[8];
|
||||
DWORD l, ec;
|
||||
HKEY hCfgKey, hMRUKey;
|
||||
UINT n = 0, i;
|
||||
if (OpenRegSettingsKey(hCfgKey)) {
|
||||
if (RegOpenKeyForReading(hCfgKey, REGMRUSUBKEY, &hMRUKey) == ERROR_SUCCESS) {
|
||||
for(int i=0; i<MRU_LIST_SIZE; i++) {
|
||||
wsprintf(buf,_T("%d"),i);
|
||||
l = sizeof(g_mru_list[n]);
|
||||
ec = RegQueryValueEx(hSubKey,buf,NULL,NULL,(LPBYTE)g_mru_list[n],&l);
|
||||
TCHAR bufName[8];
|
||||
wsprintf(bufName, _T("%d"), i);
|
||||
DWORD ec = RegReadString(hMRUKey, bufName, g_mru_list[n], sizeof(g_mru_list[n]));
|
||||
if(!ec && g_mru_list[n][0] != _T('\0')) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
RegCloseKey(hSubKey);
|
||||
RegCloseKey(hMRUKey);
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
RegCloseKey(hCfgKey);
|
||||
}
|
||||
for(i = n; i < MRU_LIST_SIZE; i++) {
|
||||
g_mru_list[i][0] = _T('\0');
|
||||
|
@ -905,32 +876,30 @@ void RestoreMRUList()
|
|||
|
||||
void SaveMRUList()
|
||||
{
|
||||
HKEY hKey;
|
||||
HKEY hSubKey;
|
||||
int i = 0;
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) {
|
||||
TCHAR buf[8];
|
||||
for(i = 0; i < MRU_LIST_SIZE; i++) {
|
||||
wsprintf(buf,_T("%d"),i);
|
||||
if (*g_mru_list[i]) {
|
||||
// cbData must include the size of the terminating null character.
|
||||
RegSetValueEx(hSubKey,buf,0,REG_SZ,(const BYTE*)g_mru_list[i],(lstrlen(g_mru_list[i])+1)*sizeof(TCHAR));
|
||||
}
|
||||
else {
|
||||
RegDeleteValue(hSubKey,buf);
|
||||
}
|
||||
UINT c = 0, i;
|
||||
for (i = 0; i < MRU_LIST_SIZE; ++i)
|
||||
if (*g_mru_list[i])
|
||||
++c;
|
||||
HKEY hCfgKey, hMRUKey;
|
||||
if (CreateRegSettingsKey(hCfgKey)) {
|
||||
if ((c ? RegCreateKey : RegOpenKey)(hCfgKey, REGMRUSUBKEY, &hMRUKey) == ERROR_SUCCESS) {
|
||||
for (i = 0; i < MRU_LIST_SIZE; ++i) {
|
||||
TCHAR bufName[8];
|
||||
wsprintf(bufName, _T("%d"), i);
|
||||
if (*g_mru_list[i])
|
||||
RegWriteString(hMRUKey, bufName, g_mru_list[i]);
|
||||
else
|
||||
RegDeleteValue(hMRUKey, bufName);
|
||||
}
|
||||
RegCloseKey(hSubKey);
|
||||
RegCloseKey(hMRUKey);
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
RegCloseKey(hCfgKey);
|
||||
}
|
||||
}
|
||||
|
||||
void ClearMRUList()
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<MRU_LIST_SIZE; i++) {
|
||||
for(UINT i=0; i < MRU_LIST_SIZE; ++i) {
|
||||
g_mru_list[i][0] = _T('\0');
|
||||
}
|
||||
|
||||
|
@ -943,13 +912,9 @@ void RestoreCompressor()
|
|||
NCOMPRESSOR v = COMPRESSOR_SCRIPT;
|
||||
if (OpenRegSettingsKey(hKey)) {
|
||||
TCHAR compressor_name[32];
|
||||
DWORD l = sizeof(compressor_name);
|
||||
DWORD t;
|
||||
|
||||
if (RegQueryValueEx(hKey,REGCOMPRESSOR,NULL,&t,(LPBYTE)compressor_name,&l)==ERROR_SUCCESS) {
|
||||
int i;
|
||||
for(i=(int)COMPRESSOR_SCRIPT; i<= (int)COMPRESSOR_BEST; i++) {
|
||||
if(!lstrcmpi(compressor_names[i],compressor_name)) {
|
||||
if (RegReadString(hKey, REGCOMPRESSOR, compressor_name, sizeof(compressor_name))==ERROR_SUCCESS) {
|
||||
for(UINT i= (UINT)COMPRESSOR_SCRIPT; i <= (UINT)COMPRESSOR_BEST; i++) {
|
||||
if(!lstrcmpi(compressor_names[i], compressor_name)) {
|
||||
v = (NCOMPRESSOR)i;
|
||||
break;
|
||||
}
|
||||
|
@ -957,7 +922,7 @@ void RestoreCompressor()
|
|||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
g_sdata.default_compressor=v;
|
||||
g_sdata.default_compressor = v;
|
||||
}
|
||||
|
||||
void SaveCompressor()
|
||||
|
@ -970,10 +935,11 @@ void SaveCompressor()
|
|||
n = (int)v;
|
||||
}
|
||||
|
||||
if (OpenRegSettingsKey(hKey, true)) {
|
||||
// compressor_names, even if Unicode is saved as BYTE* data.
|
||||
RegSetValueEx(hKey,REGCOMPRESSOR,0,REG_SZ,(const BYTE*)compressor_names[n],
|
||||
lstrlen(compressor_names[n])*sizeof(TCHAR));
|
||||
if (CreateRegSettingsKey(hKey)) {
|
||||
if (compressor_names[n][0])
|
||||
RegWriteString(hKey, REGCOMPRESSOR, compressor_names[n]);
|
||||
else
|
||||
RegDeleteValue(hKey, REGCOMPRESSOR);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#define MRU_LIST_SIZE 5
|
||||
#define MRU_DISPLAY_LENGTH 40
|
||||
#define SYMSETNAME_MAXLEN 40
|
||||
|
||||
void* MemAllocZI(SIZE_T cb);
|
||||
void MemSafeFree(void*mem);
|
||||
|
@ -55,6 +56,7 @@ void SetDialogFocus(HWND hDlg, HWND hCtl); // Use this and not SetFocus()!
|
|||
#define EnableItems(hwnd) EnableDisableItems(hwnd, 1)
|
||||
void EnableDisableItems(HWND hwnd, int on);
|
||||
bool OpenRegSettingsKey(HKEY &hKey, bool create = false);
|
||||
#define CreateRegSettingsKey(refhkey) OpenRegSettingsKey((refhkey), true)
|
||||
DWORD ReadRegSettingDW(LPCTSTR name, const DWORD defval);
|
||||
void RestoreWindowPos(HWND hwnd);
|
||||
void SaveWindowPos(HWND hwnd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue