94 bytes saved. LangString should now work with sub-sections too.

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1270 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-10-02 15:01:06 +00:00
parent f170a4d2f8
commit 3d1c70f375
7 changed files with 93 additions and 79 deletions

View file

@ -641,7 +641,8 @@ int CEXEBuild::add_function(const char *funname)
build_cursection->name_ptr=addr; build_cursection->name_ptr=addr;
build_cursection->code=cur_entries->getlen()/sizeof(entry); build_cursection->code=cur_entries->getlen()/sizeof(entry);
build_cursection->code_size=0; build_cursection->code_size=0;
build_cursection->default_state=0; build_cursection->install_types=0;
build_cursection->flags=0;
build_cursection->size_kb=0; build_cursection->size_kb=0;
return PS_OK; 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"); ERROR_MSG("Error: can't modify flags when no section is open\n");
return PS_ERROR; 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; 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)); int n=(build_sections.getlen()/sizeof(section));
build_sections.resize(build_sections.getlen()+sizeof(section)); build_sections.resize(build_sections.getlen()+sizeof(section));
build_cursection=((section*)build_sections.get()) + n; build_cursection=((section*)build_sections.get()) + n;
build_cursection->default_state=DFS_SET; build_cursection->flags=SF_SELECTED;
build_cursection->name_ptr=add_string(secname); build_cursection->name_ptr=add_string(secname[0]=='-'&&secname[1]?secname+1:secname);
build_cursection->code=cur_entries->getlen()/sizeof(entry); build_cursection->code=cur_entries->getlen()/sizeof(entry);
build_cursection->code_size=0; build_cursection->code_size=0;
build_cursection->size_kb=0; build_cursection->size_kb=0;
build_cursection->expand=expand; build_cursection->flags|=expand?SF_EXPAND:0;
if (secname[0]=='-') if (secname[0]=='-')
{ {
build_cursection->flags|=secname[1]?SF_SUBSEC:SF_SUBSECEND;
build_cursection=NULL; build_cursection=NULL;
entry ent={EW_RET,}; entry ent={EW_RET,};
cur_entries->add(&ent,sizeof(entry)); 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) 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) *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; return 0;
} }
s++; 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) if (sec->name_ptr>0 && sec->name_ptr == fptr)
{ {
ofs[0]=sec->code; ofs[0]=sec->code;
sec->default_state++; sec->flags++;
return 0; return 0;
} }
sec++; sec++;
@ -1037,7 +1055,7 @@ int CEXEBuild::resolve_coderefs(const char *str)
{ {
if (sec->name_ptr) if (sec->name_ptr)
{ {
if (!sec->default_state) if (!sec->flags)
{ {
if (sec->code_size>0) if (sec->code_size>0)
{ {
@ -1058,7 +1076,7 @@ int CEXEBuild::resolve_coderefs(const char *str)
int n=cur_labels->getlen()/sizeof(section); int n=cur_labels->getlen()/sizeof(section);
while (n-->0) while (n-->0)
{ {
if (!t->default_state) if (!t->flags)
{ {
char *n=(char*)ns_label.get()+t->name_ptr; char *n=(char*)ns_label.get()+t->name_ptr;
if (*n == '.') warning("global label \"%s\" not used",n); if (*n == '.') warning("global label \"%s\" not used",n);
@ -1437,7 +1455,7 @@ int CEXEBuild::write_output(void)
int req=0; int req=0;
for (x = 1; x < ns; x ++) 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"); INFO_MSG("Install: %d section%s",ns,ns==1?"":"s");
if (req) if (req)

View file

@ -102,6 +102,7 @@ class CEXEBuild {
int function_end(); int function_end();
void section_add_size_kb(int kb); void section_add_size_kb(int kb);
int section_add_flags(int flags); int section_add_flags(int flags);
int section_add_install_type(int inst_type);
int add_label(const char *name); int add_label(const char *name);
int add_entry(const entry *ent); int add_entry(const entry *ent);
int add_data(const char *data, int length, IGrowBuf *dblock=NULL); // returns offset int add_data(const char *data, int length, IGrowBuf *dblock=NULL); // returns offset

View file

@ -152,7 +152,7 @@ void NSISCALL build_g_logfile()
static void NSISCALL SetChildrenStates(HWND hWnd, TV_ITEM *pItem, int iState) { static void NSISCALL SetChildrenStates(HWND hWnd, TV_ITEM *pItem, int iState) {
HTREEITEM hItem; HTREEITEM hItem;
int l=0; int l=0;
int *def_state; int *flags;
pItem->mask|=TVIF_PARAM; pItem->mask|=TVIF_PARAM;
@ -160,17 +160,17 @@ static void NSISCALL SetChildrenStates(HWND hWnd, TV_ITEM *pItem, int iState) {
if (pItem->state >> 12 == 0) if (pItem->state >> 12 == 0)
return; 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->state = INDEXTOSTATEIMAGEMASK(iState+l);
pItem->stateMask = TVIS_STATEIMAGEMASK; pItem->stateMask = TVIS_STATEIMAGEMASK;
if (!(*def_state & DFS_RO)) if (!(*flags & SF_RO))
{ {
if (iState == 2) *def_state |= DFS_SET; if (iState == 2) *flags |= SF_SELECTED;
else *def_state &= ~DFS_SET; else *flags &= ~SF_SELECTED;
TreeView_SetItem(hWnd, pItem); TreeView_SetItem(hWnd, pItem);
} }
@ -197,7 +197,7 @@ static void NSISCALL SetParentState(HWND hWnd, TV_ITEM *pItem) {
pItem->mask|=TVIF_PARAM; pItem->mask|=TVIF_PARAM;
TreeView_GetItem(hWnd, pItem); TreeView_GetItem(hWnd, pItem);
iState = pItem->state >> 12; 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; if (iState==5) iState=2;
else if (iState==4) iState=1; 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) if (pItem->state >> 12 == 0)
return; 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->state = INDEXTOSTATEIMAGEMASK(checked?2:1+l);
pItem->stateMask = TVIS_STATEIMAGEMASK; 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 ++) for (x = 0; x < num_sections; x ++)
{ {
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
if (g_inst_section[x].default_state&DFS_SET) if (g_inst_section[x].flags&SF_SELECTED)
#endif #endif
total+=g_inst_section[x].size_kb; 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.pszText=process_string_fromtab(ps_tmpbuf,g_inst_section[x].name_ptr);
tv.item.stateMask=TVIS_STATEIMAGEMASK|TVIS_EXPANDED; 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) if ((g_inst_section[x].install_types>>m_whichcfg) & 1)
g_inst_section[x].default_state|=DFS_SET; g_inst_section[x].flags|=SF_SELECTED;
else else
g_inst_section[x].default_state&=~DFS_SET; g_inst_section[x].flags&=~SF_SELECTED;
} }
{ {
int l=1; int l=1;
if (g_inst_section[x].default_state & DFS_SET) l++; if (g_inst_section[x].flags & SF_SELECTED) l++;
if (g_inst_section[x].default_state & DFS_RO) l+=3; if (g_inst_section[x].flags & SF_RO) l+=3;
tv.item.state=INDEXTOSTATEIMAGEMASK(l); 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.stateMask|=TVIS_BOLD;
tv.item.state|=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.mask|=TVIF_CHILDREN;
{ tv.item.cChildren=1;
tv.item.pszText++; if (g_inst_section[x].flags&SF_EXPAND)
tv.item.mask|=TVIF_CHILDREN; tv.item.state|=TVIS_EXPANDED;
tv.item.cChildren=1; Par = hTreeItems[x] = TreeView_InsertItem(hwndTree1,&tv);
if (g_inst_section[x].name_ptr && g_inst_section[x].expand) doLines=1;
tv.item.state|=TVIS_EXPANDED; }
Par = hTreeItems[x] = TreeView_InsertItem(hwndTree1,&tv); else if (g_inst_section[x].flags&SF_SUBSECEND)
doLines=1; {
} TV_ITEM it;
else if (Par && x) it.hItem = hTreeItems[x-1];
{ it.mask = TVIF_STATE;
TV_ITEM it; it.stateMask=TVIS_STATEIMAGEMASK;
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 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); tv.pszText=process_string_fromtab(ps_tmpbuf,ns);
TreeView_SetItem(hwndTree1,&tv); 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 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; hItem.mask = TVIF_STATE|TVIF_PARAM;
TreeView_GetItem(hwndTree1, &hItem); 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 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); CheckTreeItem(hwndTree1,&hItem,0);
} }
else else
{ {
g_inst_section[hItem.lParam].default_state|=DFS_SET; g_inst_section[hItem.lParam].flags|=SF_SELECTED;
CheckTreeItem(hwndTree1,&hItem,1); CheckTreeItem(hwndTree1,&hItem,1);
} }
#if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_COMPONENTPAGE) #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; hItem.hItem=*ht;
if (g_inst_header->no_custom_instmode_flag==1) 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); CheckTreeItem(hwndTree1, &hItem,c);
} }
else if (!(t->default_state&DFS_RO)) else if (!(t->flags&SF_RO))
{ {
hItem.mask=TVIF_STATE; hItem.mask=TVIF_STATE;
TreeView_GetItem(hwndTree1,&hItem); TreeView_GetItem(hwndTree1,&hItem);
if (!(t->default_state&(1<<r)) != !((hItem.state>>12)>1 )) break; if (!(t->install_types&(1<<r)) != !((hItem.state>>12)>1 )) break;
} }
} }
t++; t++;
@ -1194,20 +1189,20 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
HTREEITEM *ht=hTreeItems; HTREEITEM *ht=hTreeItems;
while (x--) while (x--)
{ {
if (t->name_ptr && !(t->default_state & DFS_RO)) if (t->name_ptr && !(t->flags & SF_RO))
{ {
TVITEM tv; TVITEM tv;
int l=1; int l=1;
if (t->default_state & (1<<m_whichcfg)) if (t->install_types & (1<<m_whichcfg))
{ {
l++; l++;
t->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() // 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.hItem=*ht;
tv.mask=TVIF_STATE; tv.mask=TVIF_STATE;
@ -1247,7 +1242,7 @@ static BOOL CALLBACK SelProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
char s[128]; char s[128];
for (total=x=0; x < num_sections; x ++) 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; total+=g_inst_section[x].size_kb;
} }
inttosizestr(total,mystrcpy(s,LANG_STR(LANG_SPACE_REQ))); inttosizestr(total,mystrcpy(s,LANG_STR(LANG_SPACE_REQ)));
@ -1302,7 +1297,7 @@ static DWORD WINAPI install_thread(LPVOID p)
while (m_inst_sec<num_sections && !m_abort) while (m_inst_sec<num_sections && !m_abort)
{ {
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
if (g_inst_section[m_inst_sec].default_state&DFS_SET if (g_inst_section[m_inst_sec].flags&SF_SELECTED
#ifdef NSIS_CONFIG_SILENT_SUPPORT #ifdef NSIS_CONFIG_SILENT_SUPPORT
|| g_inst_cmnheader->silent_install || g_inst_cmnheader->silent_install
#endif//NSIS_CONFIG_SILENT_SUPPORT #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 ++) for (x=0; x < num_sections; x ++)
{ {
#ifdef NSIS_CONFIG_COMPONENTPAGE #ifdef NSIS_CONFIG_COMPONENTPAGE
if (g_inst_section[x].default_state&DFS_SET) if (g_inst_section[x].flags&SF_SELECTED)
#endif #endif
num+=g_inst_section[x].code_size; num+=g_inst_section[x].code_size;
} }

View file

@ -1511,15 +1511,15 @@ static int NSISCALL ExecuteEntry(entry *entry_)
} }
else if (parm1==2) // set flags 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) 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 else // get flags
{ {
myitoa(var2,g_inst_section[x].default_state); myitoa(var2,g_inst_section[x].flags);
} }
} }
else exec_errorflag++; else exec_errorflag++;

View file

@ -182,13 +182,6 @@ enum
}; };
// used for section->default_state
#define DFS_SET 0x80000000
#define DFS_RO 0x40000000
typedef struct typedef struct
{ {
int flags; // &1=CRC, &2=uninstall, &4=silent int flags; // &1=CRC, &2=uninstall, &4=silent
@ -401,18 +394,24 @@ typedef struct
int code_size; int code_size;
} uninstall_header; } 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 typedef struct
{ {
int name_ptr; // '' for non-optional components int name_ptr; // '' for non-optional components
int default_state; // bits 0-30 set for each of the different install_types, if any. int install_types; // bits set for each of the different install_types, if any.
// DFS_SET and DFS_RO can be set too int flags; // SF_SELECTED, SF_RO, SF_BOLD, SF_SUB, and/or SF_EXPAND
int code; int code;
int code_size; int code_size;
int size_kb; int size_kb;
int expand;
} section; } section;
typedef struct typedef struct
{ {
int which; int which;

View file

@ -309,7 +309,7 @@ void CEXEBuild::FillDefaultsIfNeeded(StringTable *table, NLF *nlf/*=0*/) {
char c; char c;
if (sec->name_ptr < 0) c = 'a'; if (sec->name_ptr < 0) c = 'a';
else c=build_strlist.get()[sec->name_ptr]; 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) if (iscp)
{ {

View file

@ -1658,7 +1658,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
char *p=line.gettoken_str(wt); char *p=line.gettoken_str(wt);
if (p[0]=='R' && p[1]=='O') 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] "); SCRIPT_MSG("[RO] ");
} }
else else
@ -1666,7 +1666,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
int x=atoi(p)-1; int x=atoi(p)-1;
if (x >= 0 && x < NSIS_MAX_INST_TYPES) if (x >= 0 && x < NSIS_MAX_INST_TYPES)
{ {
if (section_add_flags(1<<x) != PS_OK) return PS_ERROR; if (section_add_install_type(1<<x) != PS_OK) return PS_ERROR;
SCRIPT_MSG("[%d] ",x); SCRIPT_MSG("[%d] ",x);
} }
else if (x < 0) else if (x < 0)
@ -3556,6 +3556,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
// SetDetailsPrint lastused // SetDetailsPrint lastused
ent.which=EW_UPDATETEXT; ent.which=EW_UPDATETEXT;
ent.offsets[0]=0;
ent.offsets[1]=8; // lastused ent.offsets[1]=8; // lastused
ret=add_entry(&ent); ret=add_entry(&ent);
if (ret != PS_OK) return ret; if (ret != PS_OK) return ret;