Optimisations phase 1
1.5K saved in total git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@935 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
fefb61ea45
commit
57d6476a67
1 changed files with 114 additions and 133 deletions
|
@ -159,9 +159,11 @@ char *STRDUP(const char *c)
|
||||||
|
|
||||||
struct TableEntry {
|
struct TableEntry {
|
||||||
char *pszName;
|
char *pszName;
|
||||||
int nBitsToSet;
|
int nValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int LookupToken(TableEntry*, char*);
|
||||||
|
|
||||||
struct FieldType {
|
struct FieldType {
|
||||||
char *pszText;
|
char *pszText;
|
||||||
char *pszState;
|
char *pszState;
|
||||||
|
@ -202,7 +204,6 @@ char *pszCancelQuestionCaption = NULL;
|
||||||
char *pszCancelButtonText = NULL;
|
char *pszCancelButtonText = NULL;
|
||||||
char *pszNextButtonText = NULL;
|
char *pszNextButtonText = NULL;
|
||||||
char *pszBackButtonText = NULL;
|
char *pszBackButtonText = NULL;
|
||||||
char *pszOldTitle = NULL;
|
|
||||||
unsigned int nCancelQuestionIcon = 0;
|
unsigned int nCancelQuestionIcon = 0;
|
||||||
BOOL bBackEnabled=FALSE;
|
BOOL bBackEnabled=FALSE;
|
||||||
|
|
||||||
|
@ -213,14 +214,6 @@ FieldType *pFields = NULL;
|
||||||
int nNumFields = 0;
|
int nNumFields = 0;
|
||||||
int g_done;
|
int g_done;
|
||||||
|
|
||||||
// will contain a count of the number of controls on the main NSIS window.
|
|
||||||
unsigned int nNSISControlCount = 0;
|
|
||||||
|
|
||||||
struct WindowEntry {
|
|
||||||
HWND hwnd;
|
|
||||||
long nOldStyle;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// array of HWNDs and window styles used to make the main NSIS controls invisible while this program runs.
|
// array of HWNDs and window styles used to make the main NSIS controls invisible while this program runs.
|
||||||
|
|
||||||
|
@ -488,6 +481,18 @@ bool ReadSettings(LPSTR pszFilename) {
|
||||||
char pszField[25];
|
char pszField[25];
|
||||||
int nSize;
|
int nSize;
|
||||||
int nIdx;
|
int nIdx;
|
||||||
|
// Messagebox icon types
|
||||||
|
static TableEntry IconTable[] = {
|
||||||
|
{ "MB_ICONEXCLAMATION", MB_ICONEXCLAMATION },
|
||||||
|
{ "MB_ICONWARNING", MB_ICONWARNING },
|
||||||
|
{ "MB_ICONINFORMATION", MB_ICONINFORMATION },
|
||||||
|
{ "MB_ICONASTERISK", MB_ICONASTERISK },
|
||||||
|
{ "MB_ICONQUESTION", MB_ICONQUESTION },
|
||||||
|
{ "MB_ICONSTOP", MB_ICONSTOP },
|
||||||
|
{ "MB_ICONERROR", MB_ICONERROR },
|
||||||
|
{ "MB_ICONHAND", MB_ICONHAND },
|
||||||
|
{ NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
nSize = 1000;
|
nSize = 1000;
|
||||||
pszResult = (char*)MALLOC(nSize); // buffer to read from the file
|
pszResult = (char*)MALLOC(nSize); // buffer to read from the file
|
||||||
|
@ -501,22 +506,7 @@ bool ReadSettings(LPSTR pszFilename) {
|
||||||
nResult = GetPrivateProfileString("Settings", "CancelConfirmCaption", "", pszResult, nSize, pszFilename);
|
nResult = GetPrivateProfileString("Settings", "CancelConfirmCaption", "", pszResult, nSize, pszFilename);
|
||||||
pszCancelQuestionCaption = (nResult > 0) ? strdup(pszResult) : NULL;
|
pszCancelQuestionCaption = (nResult > 0) ? strdup(pszResult) : NULL;
|
||||||
nResult = GetPrivateProfileString("Settings", "CancelConfirmIcon", "", pszResult, nSize, pszFilename);
|
nResult = GetPrivateProfileString("Settings", "CancelConfirmIcon", "", pszResult, nSize, pszFilename);
|
||||||
if (!lstrcmpi(pszResult, "MB_ICONEXCLAMATION"))
|
nCancelQuestionIcon = LookupToken(IconTable, pszResult);
|
||||||
nCancelQuestionIcon = MB_ICONEXCLAMATION;
|
|
||||||
else if (!lstrcmpi(pszResult, "MB_ICONWARNING"))
|
|
||||||
nCancelQuestionIcon = MB_ICONWARNING;
|
|
||||||
else if (!lstrcmpi(pszResult, "MB_ICONINFORMATION"))
|
|
||||||
nCancelQuestionIcon = MB_ICONINFORMATION;
|
|
||||||
else if (!lstrcmpi(pszResult, "MB_ICONASTERISK"))
|
|
||||||
nCancelQuestionIcon = MB_ICONASTERISK;
|
|
||||||
else if (!lstrcmpi(pszResult, "MB_ICONQUESTION"))
|
|
||||||
nCancelQuestionIcon = MB_ICONQUESTION;
|
|
||||||
else if (!lstrcmpi(pszResult, "MB_ICONSTOP"))
|
|
||||||
nCancelQuestionIcon = MB_ICONSTOP;
|
|
||||||
else if (!lstrcmpi(pszResult, "MB_ICONERROR"))
|
|
||||||
nCancelQuestionIcon = MB_ICONERROR;
|
|
||||||
else if (!lstrcmpi(pszResult, "MB_ICONHAND"))
|
|
||||||
nCancelQuestionIcon = MB_ICONHAND;
|
|
||||||
|
|
||||||
nResult = GetPrivateProfileString("Settings", "CancelButtonText", "", pszResult, nSize, pszFilename);
|
nResult = GetPrivateProfileString("Settings", "CancelButtonText", "", pszResult, nSize, pszFilename);
|
||||||
pszCancelButtonText = (nResult > 0) ? strdup(pszResult) : NULL;
|
pszCancelButtonText = (nResult > 0) ? strdup(pszResult) : NULL;
|
||||||
|
@ -539,39 +529,54 @@ bool ReadSettings(LPSTR pszFilename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(nIdx = 0; nIdx < nNumFields; nIdx++) {
|
for(nIdx = 0; nIdx < nNumFields; nIdx++) {
|
||||||
wsprintf(pszField, "field %d", nIdx + 1);
|
// Control types
|
||||||
|
static TableEntry TypeTable[] = {
|
||||||
|
{ "LABEL", FIELD_LABEL },
|
||||||
|
{ "TEXT", FIELD_TEXT },
|
||||||
|
{ "PASSWORD", FIELD_TEXT },
|
||||||
|
{ "LISTBOX", FIELD_LISTBOX },
|
||||||
|
{ "COMBOBOX", FIELD_COMBOBOX },
|
||||||
|
{ "DROPLIST", FIELD_COMBOBOX },
|
||||||
|
{ "FILEREQUEST", FIELD_FILEREQUEST },
|
||||||
|
{ "DIRREQUEST", FIELD_DIRREQUEST },
|
||||||
|
{ "CHECKBOX", FIELD_CHECKBOX },
|
||||||
|
{ "RADIOBUTTON", FIELD_RADIOBUTTON },
|
||||||
|
{ "ICON", FIELD_ICON },
|
||||||
|
{ "BITMAP", FIELD_BITMAP },
|
||||||
|
{ NULL, 0 }
|
||||||
|
};
|
||||||
|
// Control flags
|
||||||
|
static TableEntry FlagTable[] = {
|
||||||
|
{ "FILE_MUST_EXIST", OFN_FILEMUSTEXIST },
|
||||||
|
{ "PATH_MUST_EXIST", OFN_PATHMUSTEXIST },
|
||||||
|
{ "WARN_IF_EXIST", OFN_OVERWRITEPROMPT },
|
||||||
|
{ "PROMPT_CREATE", OFN_CREATEPROMPT },
|
||||||
|
{ "RIGHT", FLAG_RIGHT },
|
||||||
|
{ "PASSWORD", FLAG_PASSWORD },
|
||||||
|
{ "DROPLIST", FLAG_DROPLIST },
|
||||||
|
{ "MULTISELECT", FLAG_MULTISELECT },
|
||||||
|
{ "FILE_EXPLORER", OFN_EXPLORER },
|
||||||
|
{ "FILE_HIDEREADONLY", OFN_HIDEREADONLY },
|
||||||
|
/*
|
||||||
|
{ "NO_ALPHA", 0 },
|
||||||
|
{ "NO_NUMBERS", 0 },
|
||||||
|
{ "NO_SYMBOLS", 0 },
|
||||||
|
{ "BOLD", FLAG_BOLD },
|
||||||
|
*/
|
||||||
|
{ NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
wsprintf(pszField, "field %d", nIdx + 1);
|
||||||
*pszResult = '\0';
|
*pszResult = '\0';
|
||||||
nResult = GetPrivateProfileString(pszField, "TYPE", "", pszResult, nSize, pszFilename);
|
nResult = GetPrivateProfileString(pszField, "TYPE", "", pszResult, nSize, pszFilename);
|
||||||
if (!stricmp(pszResult, "LABEL")) {
|
|
||||||
pFields[nIdx].nType = FIELD_LABEL;
|
// Get the control type
|
||||||
} else if (!stricmp(pszResult, "TEXT")) {
|
pFields[nIdx].nType = LookupToken(TypeTable, pszResult);
|
||||||
pFields[nIdx].nType = FIELD_TEXT;
|
if (!pFields[nIdx].nType)
|
||||||
} else if (!stricmp(pszResult, "PASSWORD")) {
|
|
||||||
pFields[nIdx].nType = FIELD_TEXT;
|
|
||||||
pFields[nIdx].nFlags |= FLAG_PASSWORD;
|
|
||||||
} else if (!stricmp(pszResult, "LISTBOX")) {
|
|
||||||
pFields[nIdx].nType = FIELD_LISTBOX;
|
|
||||||
} else if (!stricmp(pszResult, "COMBOBOX")) {
|
|
||||||
pFields[nIdx].nType = FIELD_COMBOBOX;
|
|
||||||
} else if (!stricmp(pszResult, "DROPLIST")) {
|
|
||||||
pFields[nIdx].nType = FIELD_COMBOBOX;
|
|
||||||
pFields[nIdx].nFlags |= FLAG_DROPLIST;
|
|
||||||
} else if (!stricmp(pszResult, "FILEREQUEST")) {
|
|
||||||
pFields[nIdx].nType = FIELD_FILEREQUEST;
|
|
||||||
} else if (!stricmp(pszResult, "DIRREQUEST")) {
|
|
||||||
pFields[nIdx].nType = FIELD_DIRREQUEST;
|
|
||||||
} else if (!stricmp(pszResult, "CHECKBOX")) {
|
|
||||||
pFields[nIdx].nType = FIELD_CHECKBOX;
|
|
||||||
} else if (!stricmp(pszResult, "RADIOBUTTON")) {
|
|
||||||
pFields[nIdx].nType = FIELD_RADIOBUTTON;
|
|
||||||
} else if (!stricmp(pszResult, "ICON")) {
|
|
||||||
pFields[nIdx].nType = FIELD_ICON;
|
|
||||||
} else if (!stricmp(pszResult, "BITMAP")) {
|
|
||||||
pFields[nIdx].nType = FIELD_BITMAP;
|
|
||||||
} else {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
// Lookup flags associated with the control type
|
||||||
|
pFields[nIdx].nFlags |= LookupToken(FlagTable, pszResult);
|
||||||
|
|
||||||
nResult = GetPrivateProfileString(pszField, "TEXT", "", pszResult, nSize, pszFilename);
|
nResult = GetPrivateProfileString(pszField, "TEXT", "", pszResult, nSize, pszFilename);
|
||||||
if (nResult) {
|
if (nResult) {
|
||||||
|
@ -630,30 +635,6 @@ bool ReadSettings(LPSTR pszFilename) {
|
||||||
pFields[nIdx].rect.top = GetPrivateProfileInt(pszField, "TOP", 0, pszFilename);
|
pFields[nIdx].rect.top = GetPrivateProfileInt(pszField, "TOP", 0, pszFilename);
|
||||||
pFields[nIdx].rect.bottom = GetPrivateProfileInt(pszField, "BOTTOM", 0, pszFilename);
|
pFields[nIdx].rect.bottom = GetPrivateProfileInt(pszField, "BOTTOM", 0, pszFilename);
|
||||||
|
|
||||||
TableEntry FlagTable[] = {
|
|
||||||
{ "FILE_MUST_EXIST", OFN_FILEMUSTEXIST },
|
|
||||||
{ "PATH_MUST_EXIST", OFN_PATHMUSTEXIST },
|
|
||||||
{ "WARN_IF_EXIST", OFN_OVERWRITEPROMPT },
|
|
||||||
{ "PROMPT_CREATE", OFN_CREATEPROMPT },
|
|
||||||
|
|
||||||
{ "RIGHT" , FLAG_RIGHT },
|
|
||||||
|
|
||||||
{ "PASSWORD" , FLAG_PASSWORD },
|
|
||||||
{ "DROPLIST" , FLAG_DROPLIST },
|
|
||||||
|
|
||||||
{ "MULTISELECT" , FLAG_MULTISELECT },
|
|
||||||
{ "FILE_EXPLORER", OFN_EXPLORER },
|
|
||||||
{ "FILE_HIDEREADONLY", OFN_HIDEREADONLY },
|
|
||||||
|
|
||||||
/*
|
|
||||||
{ "NO_ALPHA", 0 },
|
|
||||||
{ "NO_NUMBERS", 0 },
|
|
||||||
{ "NO_SYMBOLS", 0 },
|
|
||||||
{ "BOLD", FLAG_BOLD },
|
|
||||||
*/
|
|
||||||
{ NULL, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
nResult = GetPrivateProfileString(pszField, "flags", "", pszResult, nSize, pszFilename);
|
nResult = GetPrivateProfileString(pszField, "flags", "", pszResult, nSize, pszFilename);
|
||||||
if (nResult > 0) {
|
if (nResult > 0) {
|
||||||
// append the | to make parsing a bit easier
|
// append the | to make parsing a bit easier
|
||||||
|
@ -671,14 +652,7 @@ bool ReadSettings(LPSTR pszFilename) {
|
||||||
// v1.3 converted this to a table lookup.
|
// v1.3 converted this to a table lookup.
|
||||||
// I think it's a bit larger now, but we can
|
// I think it's a bit larger now, but we can
|
||||||
// add new flags with very little overhead.
|
// add new flags with very little overhead.
|
||||||
int nFlagIdx = 0;
|
pFields[nIdx].nFlags |= LookupToken(FlagTable, pszStart);
|
||||||
while (FlagTable[nFlagIdx].pszName != NULL) {
|
|
||||||
if (!stricmp(FlagTable[nFlagIdx].pszName, pszStart)) {
|
|
||||||
pFields[nIdx].nFlags |= FlagTable[nFlagIdx].nBitsToSet;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nFlagIdx++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// jump to the next item, skip any redundant | characters
|
// jump to the next item, skip any redundant | characters
|
||||||
|
@ -1117,4 +1091,11 @@ char *getuservariable(int varnum)
|
||||||
return g_variables+varnum*g_stringsize;
|
return g_variables+varnum*g_stringsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LookupToken(TableEntry* psTable_, char* pszToken_)
|
||||||
|
{
|
||||||
|
for (int i = 0; psTable_[i].pszName; i++)
|
||||||
|
if (!stricmp(pszToken_, psTable_[i].pszName))
|
||||||
|
return psTable_[i].nValue;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue