diff --git a/Source/build.cpp b/Source/build.cpp index 6fb82c16..072694dd 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -641,7 +641,8 @@ int CEXEBuild::add_function(const char *funname) build_cursection->name_ptr=addr; build_cursection->code=cur_entries->getlen()/sizeof(entry); build_cursection->code_size=0; - build_cursection->default_state=0; + build_cursection->install_types=0; + build_cursection->flags=0; build_cursection->size_kb=0; return PS_OK; } @@ -679,7 +680,23 @@ int CEXEBuild::section_add_flags(int flags) ERROR_MSG("Error: can't modify flags when no section is open\n"); return PS_ERROR; } - build_cursection->default_state|=flags; + build_cursection->flags|=flags; + return PS_OK; +} + +int CEXEBuild::section_add_install_type(int inst_type) +{ + if (uninstall_mode) + { + ERROR_MSG("Error: can't modify flags of uninstall section\n"); + return PS_ERROR; + } + if (!build_cursection || build_cursection_isfunc) + { + ERROR_MSG("Error: can't modify flags when no section is open\n"); + return PS_ERROR; + } + build_cursection->install_types|=inst_type; return PS_OK; } @@ -759,15 +776,16 @@ int CEXEBuild::add_section(const char *secname, const char *file, int line, cons int n=(build_sections.getlen()/sizeof(section)); build_sections.resize(build_sections.getlen()+sizeof(section)); build_cursection=((section*)build_sections.get()) + n; - build_cursection->default_state=DFS_SET; - build_cursection->name_ptr=add_string(secname); + build_cursection->flags=SF_SELECTED; + build_cursection->name_ptr=add_string(secname[0]=='-'&&secname[1]?secname+1:secname); build_cursection->code=cur_entries->getlen()/sizeof(entry); build_cursection->code_size=0; build_cursection->size_kb=0; - build_cursection->expand=expand; + build_cursection->flags|=expand?SF_EXPAND:0; if (secname[0]=='-') { + build_cursection->flags|=secname[1]?SF_SUBSEC:SF_SUBSECEND; build_cursection=NULL; entry ent={EW_RET,}; cur_entries->add(&ent,sizeof(entry)); @@ -848,7 +866,7 @@ int CEXEBuild::resolve_jump_int(const char *fn, int *a, int offs, int start, int if ((*lname == '.' || (s->code >= start && s->code <= end)) && s->name_ptr == *a) { *a = s->code+1; // jumps are to the absolute position, +1 (to differentiate between no jump, and jumping to offset 0) - s->default_state++; + s->flags++; return 0; } s++; @@ -875,7 +893,7 @@ int CEXEBuild::resolve_call_int(const char *fn, const char *str, int fptr, int * if (sec->name_ptr>0 && sec->name_ptr == fptr) { ofs[0]=sec->code; - sec->default_state++; + sec->flags++; return 0; } sec++; @@ -1037,7 +1055,7 @@ int CEXEBuild::resolve_coderefs(const char *str) { if (sec->name_ptr) { - if (!sec->default_state) + if (!sec->flags) { if (sec->code_size>0) { @@ -1058,7 +1076,7 @@ int CEXEBuild::resolve_coderefs(const char *str) int n=cur_labels->getlen()/sizeof(section); while (n-->0) { - if (!t->default_state) + if (!t->flags) { char *n=(char*)ns_label.get()+t->name_ptr; if (*n == '.') warning("global label \"%s\" not used",n); @@ -1437,7 +1455,7 @@ int CEXEBuild::write_output(void) int req=0; for (x = 1; x < ns; x ++) { - if (!s[x].name_ptr || s[x].default_state & DFS_RO) req++; + if (!s[x].name_ptr || s[x].flags & SF_RO) req++; } INFO_MSG("Install: %d section%s",ns,ns==1?"":"s"); if (req) diff --git a/Source/build.h b/Source/build.h index 44388956..0cf660c7 100644 --- a/Source/build.h +++ b/Source/build.h @@ -102,6 +102,7 @@ class CEXEBuild { int function_end(); void section_add_size_kb(int kb); int section_add_flags(int flags); + int section_add_install_type(int inst_type); int add_label(const char *name); int add_entry(const entry *ent); int add_data(const char *data, int length, IGrowBuf *dblock=NULL); // returns offset diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index 93177158..8062e8fe 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -152,7 +152,7 @@ void NSISCALL build_g_logfile() static void NSISCALL SetChildrenStates(HWND hWnd, TV_ITEM *pItem, int iState) { HTREEITEM hItem; int l=0; - int *def_state; + int *flags; pItem->mask|=TVIF_PARAM; @@ -160,17 +160,17 @@ static void NSISCALL SetChildrenStates(HWND hWnd, TV_ITEM *pItem, int iState) { if (pItem->state >> 12 == 0) return; - def_state=&g_inst_section[pItem->lParam].default_state; + flags=&g_inst_section[pItem->lParam].flags; - if (iState < 3 && (*def_state & DFS_RO)) l=3; + if (iState < 3 && (*flags & SF_RO)) l=3; pItem->state = INDEXTOSTATEIMAGEMASK(iState+l); pItem->stateMask = TVIS_STATEIMAGEMASK; - if (!(*def_state & DFS_RO)) + if (!(*flags & SF_RO)) { - if (iState == 2) *def_state |= DFS_SET; - else *def_state &= ~DFS_SET; + if (iState == 2) *flags |= SF_SELECTED; + else *flags &= ~SF_SELECTED; TreeView_SetItem(hWnd, pItem); } @@ -197,7 +197,7 @@ static void NSISCALL SetParentState(HWND hWnd, TV_ITEM *pItem) { pItem->mask|=TVIF_PARAM; TreeView_GetItem(hWnd, pItem); iState = pItem->state >> 12; - if (iState && !(g_inst_section[pItem->lParam].default_state & DFS_RO)) + if (iState && !(g_inst_section[pItem->lParam].flags & SF_RO)) { if (iState==5) iState=2; else if (iState==4) iState=1; @@ -229,7 +229,7 @@ static void NSISCALL CheckTreeItem(HWND hWnd, TV_ITEM *pItem, int checked) { if (pItem->state >> 12 == 0) return; - if (g_inst_section[pItem->lParam].default_state & DFS_RO) l=3; + if (g_inst_section[pItem->lParam].flags & SF_RO) l=3; pItem->state = INDEXTOSTATEIMAGEMASK(checked?2:1+l); pItem->stateMask = TVIS_STATEIMAGEMASK; @@ -846,7 +846,7 @@ static BOOL CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar for (x = 0; x < num_sections; x ++) { #ifdef NSIS_CONFIG_COMPONENTPAGE - if (g_inst_section[x].default_state&DFS_SET) + if (g_inst_section[x].flags&SF_SELECTED) #endif total+=g_inst_section[x].size_kb; } @@ -1002,52 +1002,47 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar tv.item.pszText=process_string_fromtab(ps_tmpbuf,g_inst_section[x].name_ptr); tv.item.stateMask=TVIS_STATEIMAGEMASK|TVIS_EXPANDED; - if (m_num_insttypes && m_whichcfg != m_num_insttypes && !(g_inst_section[x].default_state&DFS_RO)) + if (m_num_insttypes && m_whichcfg != m_num_insttypes && !(g_inst_section[x].flags&SF_RO)) { - if ((g_inst_section[x].default_state>>m_whichcfg) & 1) - g_inst_section[x].default_state|=DFS_SET; + if ((g_inst_section[x].install_types>>m_whichcfg) & 1) + g_inst_section[x].flags|=SF_SELECTED; else - g_inst_section[x].default_state&=~DFS_SET; + g_inst_section[x].flags&=~SF_SELECTED; } { int l=1; - if (g_inst_section[x].default_state & DFS_SET) l++; - if (g_inst_section[x].default_state & DFS_RO) l+=3; + if (g_inst_section[x].flags & SF_SELECTED) l++; + if (g_inst_section[x].flags & SF_RO) l+=3; tv.item.state=INDEXTOSTATEIMAGEMASK(l); } - if (ps_tmpbuf[0] == '!' || *(WORD*)ps_tmpbuf == CHAR2_TO_WORD('-','!')) + if (g_inst_section[x].flags&SF_BOLD) { - tv.item.pszText++; tv.item.stateMask|=TVIS_BOLD; tv.item.state|=TVIS_BOLD; } - if (ps_tmpbuf[0] == '-') + if (g_inst_section[x].flags&SF_SUBSEC) { - if (ps_tmpbuf[1]) - { - tv.item.pszText++; - tv.item.mask|=TVIF_CHILDREN; - tv.item.cChildren=1; - if (g_inst_section[x].name_ptr && g_inst_section[x].expand) - tv.item.state|=TVIS_EXPANDED; - Par = hTreeItems[x] = TreeView_InsertItem(hwndTree1,&tv); - doLines=1; - } - else if (Par && x) - { - TV_ITEM it; - it.hItem = hTreeItems[x-1]; - it.mask = TVIF_STATE; - it.stateMask=TVIS_STATEIMAGEMASK; + tv.item.mask|=TVIF_CHILDREN; + tv.item.cChildren=1; + if (g_inst_section[x].flags&SF_EXPAND) + tv.item.state|=TVIS_EXPANDED; + Par = hTreeItems[x] = TreeView_InsertItem(hwndTree1,&tv); + doLines=1; + } + else if (g_inst_section[x].flags&SF_SUBSECEND) + { + TV_ITEM it; + it.hItem = hTreeItems[x-1]; + it.mask = TVIF_STATE; + it.stateMask=TVIS_STATEIMAGEMASK; - SetParentState(hwndTree1,&it); + SetParentState(hwndTree1,&it); - Par=TreeView_GetParent(hwndTree1,Par); - } + Par=TreeView_GetParent(hwndTree1,Par); } else { @@ -1076,7 +1071,7 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar tv.pszText=process_string_fromtab(ps_tmpbuf,ns); TreeView_SetItem(hwndTree1,&tv); } - SendMessage(hwndDlg,WM_USER+0x18,x,(LPARAM)!!(g_inst_section[x].default_state&DFS_SET)); + SendMessage(hwndDlg,WM_USER+0x18,x,(LPARAM)!!(g_inst_section[x].flags&SF_SELECTED)); } if (uMsg == WM_USER+0x18) // select { @@ -1111,16 +1106,16 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar hItem.mask = TVIF_STATE|TVIF_PARAM; TreeView_GetItem(hwndTree1, &hItem); - if (!(g_inst_section[hItem.lParam].default_state&DFS_RO)) + if (!(g_inst_section[hItem.lParam].flags&SF_RO)) { if ((hItem.state >> 12) == 2) // already checked { - g_inst_section[hItem.lParam].default_state&=~DFS_SET; + g_inst_section[hItem.lParam].flags&=~SF_SELECTED; CheckTreeItem(hwndTree1,&hItem,0); } else { - g_inst_section[hItem.lParam].default_state|=DFS_SET; + g_inst_section[hItem.lParam].flags|=SF_SELECTED; CheckTreeItem(hwndTree1,&hItem,1); } #if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_COMPONENTPAGE) @@ -1145,14 +1140,14 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar hItem.hItem=*ht; if (g_inst_header->no_custom_instmode_flag==1) { - int c=(t->default_state>>m_whichcfg)&1; + int c=(t->install_types>>m_whichcfg)&1; CheckTreeItem(hwndTree1, &hItem,c); } - else if (!(t->default_state&DFS_RO)) + else if (!(t->flags&SF_RO)) { hItem.mask=TVIF_STATE; TreeView_GetItem(hwndTree1,&hItem); - if (!(t->default_state&(1<>12)>1 )) break; + if (!(t->install_types&(1<>12)>1 )) break; } } t++; @@ -1194,20 +1189,20 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar HTREEITEM *ht=hTreeItems; while (x--) { - if (t->name_ptr && !(t->default_state & DFS_RO)) + if (t->name_ptr && !(t->flags & SF_RO)) { TVITEM tv; int l=1; - if (t->default_state & (1<install_types & (1<default_state|=DFS_SET; + t->flags|=SF_SELECTED; } - else t->default_state&=~DFS_SET; + else t->flags&=~SF_SELECTED; // this can't happen because of the above if() - //if (t->default_state & DFS_RO) l+=3; + //if (t->flags & SF_RO) l+=3; tv.hItem=*ht; tv.mask=TVIF_STATE; @@ -1247,7 +1242,7 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar char s[128]; for (total=x=0; x < num_sections; x ++) { - if (g_inst_section[x].default_state&DFS_SET) + if (g_inst_section[x].flags&SF_SELECTED) total+=g_inst_section[x].size_kb; } inttosizestr(total,mystrcpy(s,LANG_STR(LANG_SPACE_REQ))); @@ -1302,7 +1297,7 @@ static DWORD WINAPI install_thread(LPVOID p) while (m_inst_secsilent_install #endif//NSIS_CONFIG_SILENT_SUPPORT @@ -1353,7 +1348,7 @@ static BOOL CALLBACK InstProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa for (x=0; x < num_sections; x ++) { #ifdef NSIS_CONFIG_COMPONENTPAGE - if (g_inst_section[x].default_state&DFS_SET) + if (g_inst_section[x].flags&SF_SELECTED) #endif num+=g_inst_section[x].code_size; } diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 3c92a324..7583d654 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -1511,15 +1511,15 @@ static int NSISCALL ExecuteEntry(entry *entry_) } else if (parm1==2) // set flags { - g_inst_section[x].default_state=process_string_fromparm_toint(2); + g_inst_section[x].flags=process_string_fromparm_toint(2); if (g_SectionHack) { - SendMessage(g_SectionHack,WM_USER+0x18,x,(LPARAM)!!(g_inst_section[x].default_state&DFS_SET)); + SendMessage(g_SectionHack,WM_USER+0x18,x,(LPARAM)!!(g_inst_section[x].flags&SF_SELECTED)); } } else // get flags { - myitoa(var2,g_inst_section[x].default_state); + myitoa(var2,g_inst_section[x].flags); } } else exec_errorflag++; diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index cd3852db..db729859 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -182,13 +182,6 @@ enum }; - -// used for section->default_state -#define DFS_SET 0x80000000 -#define DFS_RO 0x40000000 - - - typedef struct { int flags; // &1=CRC, &2=uninstall, &4=silent @@ -401,18 +394,24 @@ typedef struct int code_size; } uninstall_header; +// used for section->flags +#define SF_SELECTED 1 +#define SF_SUBSEC 2 +#define SF_SUBSECEND 4 +#define SF_BOLD 8 +#define SF_RO 16 +#define SF_EXPAND 32 + typedef struct { int name_ptr; // '' for non-optional components - int default_state; // bits 0-30 set for each of the different install_types, if any. - // DFS_SET and DFS_RO can be set too + int install_types; // bits set for each of the different install_types, if any. + int flags; // SF_SELECTED, SF_RO, SF_BOLD, SF_SUB, and/or SF_EXPAND int code; int code_size; int size_kb; - int expand; } section; - typedef struct { int which; diff --git a/Source/lang.cpp b/Source/lang.cpp index e68caa29..f271fd01 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -309,7 +309,7 @@ void CEXEBuild::FillDefaultsIfNeeded(StringTable *table, NLF *nlf/*=0*/) { char c; if (sec->name_ptr < 0) c = 'a'; else c=build_strlist.get()[sec->name_ptr]; - if (c && c != '-' && !(sec->default_state&DFS_RO)) iscp++; + if (c && c != '-' && !(sec->flags&SF_RO)) iscp++; } if (iscp) { diff --git a/Source/script.cpp b/Source/script.cpp index 9de036c3..26d9a943 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1658,7 +1658,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char char *p=line.gettoken_str(wt); if (p[0]=='R' && p[1]=='O') { - if (section_add_flags(DFS_SET|DFS_RO) != PS_OK) return PS_ERROR; + if (section_add_flags(SF_SELECTED|SF_RO) != PS_OK) return PS_ERROR; SCRIPT_MSG("[RO] "); } else @@ -1666,7 +1666,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char int x=atoi(p)-1; if (x >= 0 && x < NSIS_MAX_INST_TYPES) { - if (section_add_flags(1<