Fixed handling of command line SetCompressor option.

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3189 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
icemank 2003-11-21 21:57:39 +00:00
parent 34d4213220
commit 320cefa4b0
5 changed files with 167 additions and 42 deletions

View file

@ -34,6 +34,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd
MSG msg;
int status;
HACCEL haccel;
my_memset(&g_sdata,0,sizeof(NSCRIPTDATA));
my_memset(&g_resize,0,sizeof(NRESIZEDATA));
my_memset(&g_find,0,sizeof(NFINDREPLACE));
@ -41,31 +42,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmd
g_sdata.script_alloced=false;
g_sdata.defines = NULL;
RestoreDefines();
g_sdata.script=GetCommandLine();
if (*g_sdata.script=='"') { g_sdata.script++; while (*g_sdata.script && *g_sdata.script++!='"' ); }
else while (*g_sdata.script!=' ' && *g_sdata.script) g_sdata.script++;
while (*g_sdata.script==' ') g_sdata.script++;
if(lstrlen(g_sdata.script)) {
bool is_quoted = false;
char *p = g_sdata.script + (lstrlen(g_sdata.script) - 1);
if(*p == '"') is_quoted = true;
p--;
while(p > g_sdata.script) {
if(*p == ' ') {
if(!is_quoted) {
p++;
break;
}
}
else if(*p == '"') {
p++;
break;
}
p--;
}
PushMRUFile(p);
}
if (!InitBranding()) {
MessageBox(0,NSISERROR,"Error",MB_ICONEXCLAMATION|MB_OK);
@ -109,6 +85,11 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
{
int argc;
char **argv;
int i;
int argSpaceSize;
g_sdata.hwnd=hwndDlg;
HICON hIcon = LoadIcon(g_sdata.hInstance,MAKEINTRESOURCE(IDI_ICON));
SetClassLong(hwndDlg,GCL_HICON,(long)hIcon);
@ -129,7 +110,45 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
SendDlgItemMessage(hwndDlg,IDC_LOGWIN,EM_SETBKGNDCOLOR,0,GetSysColor(COLOR_BTNFACE));
RestoreWindowPos(g_sdata.hwnd);
g_sdata.compressor = (NCOMPRESSOR)-1;
RestoreCompressor();
argSpaceSize = SetArgv((char *)GetCommandLine(), &argc, &argv);
if(argc > 1) {
int n;
g_sdata.script_alloced = true;
g_sdata.script = (char *)GlobalAlloc(GPTR,argSpaceSize + 2*(argc-1)*sizeof(char)+1);
lstrcpy(g_sdata.script,"");
for(i=1; i<argc; i++) {
if(!lstrncmpi(argv[i],"/XSetCompressor ",lstrlen("/XSetCompressor "))) {
char *p = argv[i]+lstrlen("/XSetCompressor ");
if(!lstrncmpi(p,"/FINAL ",lstrlen("/FINAL "))) {
p += lstrlen("/FINAL ");
}
while(*p == ' ') p++;
if(!lstrcmpi(p,"zlib")) {
SetCompressor(COMPRESSOR_ZLIB);
}
else if(!lstrcmpi(p,"bzip2")) {
SetCompressor(COMPRESSOR_BZIP2);
}
}
else {
lstrcat(g_sdata.script,"\"");
lstrcat(g_sdata.script,argv[i]);
lstrcat(g_sdata.script,"\" ");
}
}
n = lstrlen(g_sdata.script);
if(n > 0) {
g_sdata.script[n-1] = '\0';
}
PushMRUFile(argv[argc-1]);
LocalFree(argv);
}
if(g_sdata.compressor == (NCOMPRESSOR)-1) {
RestoreCompressor();
}
CompileNSISScript();
return TRUE;
}

View file

@ -50,9 +50,23 @@ void *my_memset(void *dest, int c, size_t count) {
return dest;
}
int lstrcmpn(char *s1, const char *s2, int chars)
// iceman_k's clib methods
int lstrncmp(char *s1, const char *s2, int chars)
{
while ((chars > 0) && (*s1) && (*s2) && (*(s1) == *(s2))) chars--, s1++, s2++;
if ((chars == 0) || (*s1 == *s2)) return 0;
return (*s1 - *s2);
}
}
int lstrncmpi(char *s1, const char *s2, int chars)
{
while (chars-- && *s1 && *s2)
{
char ss1=*s1++;
char ss2=*s2++;
if (ss1>='a' && ss1 <= 'z') ss1+='A'-'a';
if (ss2>='a' && ss2 <= 'z') ss2+='A'-'a';
if (ss1 != ss2) return ss1-ss2;
}
return 0;
}

View file

@ -27,5 +27,7 @@ char *my_strstr(char *i, char *s);
char *my_strrchr(const char *string, int c);
void *my_memset(void *dest, int c, size_t count);
int lstrcmpn(char *s1, const char *s2, int chars);
// iceman_k's clib methods
int lstrncmp(char *s1, const char *s2, int chars);
int lstrncmpi(char *s1, const char *s2, int chars);
#endif

View file

@ -32,6 +32,85 @@ char g_mru_list[MRU_LIST_SIZE][MAX_PATH] = { NULL, NULL, NULL, NULL, NULL };
extern NSCRIPTDATA g_sdata;
int SetArgv(char *cmdLine, int *argc, char ***argv)
{
char *p, *arg, *argSpace;
int size, argSpaceSize, inquote, copy, slashes;
size = 2;
for (p = cmdLine; *p != '\0'; p++) {
if ((*p == ' ') || (*p == '\t')) {
size++;
while ((*p == ' ') || (*p == '\t')) {
p++;
}
if (*p == '\0') {
break;
}
}
}
argSpaceSize = size * sizeof(char *) + lstrlen(cmdLine) + 1;
argSpace = (char *) LocalAlloc(GMEM_FIXED, argSpaceSize);
*argv = (char **) argSpace;
argSpace += size * sizeof(char *);
size--;
p = cmdLine;
for (*argc = 0; *argc < size; (*argc)++) {
(*argv)[*argc] = arg = argSpace;
while ((*p == ' ') || (*p == '\t')) {
p++;
}
if (*p == '\0') {
break;
}
inquote = 0;
slashes = 0;
while (1) {
copy = 1;
while (*p == '\\') {
slashes++;
p++;
}
if (*p == '"') {
if ((slashes & 1) == 0) {
copy = 0;
if ((inquote) && (p[1] == '"')) {
p++;
copy = 1;
}
else {
inquote = !inquote;
}
}
slashes >>= 1;
}
while (slashes) {
*arg = '\\';
arg++;
slashes--;
}
if ((*p == '\0') || (!inquote && ((*p == ' ') || (*p == '\t')))) {
break;
}
if (copy != 0) {
*arg = *p;
arg++;
}
p++;
}
*arg = '\0';
argSpace = arg + 1;
}
(*argv)[*argc] = NULL;
return argSpaceSize;
}
void SetTitle(HWND hwnd,char *substr) {
char title[64];
if (substr==NULL) wsprintf(title,"MakeNSISW");
@ -143,13 +222,13 @@ void SetCompressorStats()
DWORD len = lstrlen(TOTAL_SIZE_COMPRESSOR_STAT);
lstrcat(g_sdata.compressor_stats,buf);
if(!lstrcmpn(buf,TOTAL_SIZE_COMPRESSOR_STAT,len)) {
if(!lstrncmp(buf,TOTAL_SIZE_COMPRESSOR_STAT,len)) {
break;
}
}
else {
DWORD len = lstrlen(EXE_HEADER_COMPRESSOR_STAT);
if(!lstrcmpn(buf,EXE_HEADER_COMPRESSOR_STAT,len)) {
if(!lstrncmp(buf,EXE_HEADER_COMPRESSOR_STAT,len)) {
found = true;
lstrcpy(g_sdata.compressor_stats,"\n\n");
lstrcat(g_sdata.compressor_stats,buf);
@ -474,6 +553,19 @@ BOOL PopMRUFile(char* fname)
}
}
BOOL IsValidFile(char *fname)
{
WIN32_FIND_DATA wfd;
HANDLE h;
h = FindFirstFile(fname,&wfd);
if(h != INVALID_HANDLE_VALUE) {
FindClose(h);
return true;
}
return false;
}
void PushMRUFile(char* fname)
{
int i;
@ -500,12 +592,14 @@ void PushMRUFile(char* fname)
return;
}
PopMRUFile(full_file_name);
for(i = MRU_LIST_SIZE - 2; i >= 0; i--) {
lstrcpy(g_mru_list[i+1], g_mru_list[i]);
if(IsValidFile(full_file_name)) {
PopMRUFile(full_file_name);
for(i = MRU_LIST_SIZE - 2; i >= 0; i--) {
lstrcpy(g_mru_list[i+1], g_mru_list[i]);
}
lstrcpy(g_mru_list[0],full_file_name);
BuildMRUMenus();
}
lstrcpy(g_mru_list[0],full_file_name);
BuildMRUMenus();
}
void BuildMRUMenus()
@ -587,16 +681,11 @@ void BuildMRUMenus()
void LoadMRUFile(int position)
{
WIN32_FIND_DATA wfd;
HANDLE h;
if (!g_sdata.thread && position >=0 && position < MRU_LIST_SIZE && g_mru_list[position][0]) {
g_sdata.script = (char *)GlobalAlloc(GPTR,lstrlen(g_mru_list[position])+3);
wsprintf(g_sdata.script,"\"%s\"",g_mru_list[position]);
h = FindFirstFile(g_mru_list[position],&wfd);
if(h != INVALID_HANDLE_VALUE) {
if(IsValidFile(g_mru_list[position])) {
PushMRUFile(g_mru_list[position]);
FindClose(h);
}
else {
PopMRUFile(g_mru_list[position]);

View file

@ -26,6 +26,7 @@
#define MRU_LIST_SIZE 5
#define MRU_DISPLAY_LENGTH 40
int SetArgv(char *cmdLine, int *argc, char ***argv);
void SetTitle(HWND hwnd,char *substr);
void SetBranding(HWND hwnd);
void CopyToClipboard(HWND hwnd);