This commit was generated by cvs2svn to compensate for changes in r2,

which included commits to RCS files with non-trunk default branches.


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@625 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2002-08-02 10:01:35 +00:00
parent 9b3b220a13
commit 3e9e73ec59
177 changed files with 37677 additions and 0 deletions

102
Contrib/ExDLL/exdll.c Normal file
View file

@ -0,0 +1,102 @@
#include <windows.h>
typedef struct _stack_t {
struct _stack_t *next;
char text[1]; // this should be the length of string_size
} stack_t;
int popstring(char *str); // 0 on success, 1 on empty stack
void pushstring(char *str);
enum
{
INST_0, // $0
INST_1, // $1
INST_2, // $2
INST_3, // $3
INST_4, // $4
INST_5, // $5
INST_6, // $6
INST_7, // $7
INST_8, // $8
INST_9, // $9
INST_R0, // $R0
INST_R1, // $R1
INST_R2, // $R2
INST_R3, // $R3
INST_R4, // $R4
INST_R5, // $R5
INST_R6, // $R6
INST_R7, // $R7
INST_R8, // $R8
INST_R9, // $R9
INST_CMDLINE, // $CMDLINE
INST_INSTDIR, // $INSTDIR
INST_OUTDIR, // $OUTDIR
INST_EXEDIR, // $EXEDIR
__INST_LAST
};
char *getuservariable(int varnum);
HINSTANCE g_hInstance;
HWND g_hwndParent;
int g_stringsize;
stack_t **g_stacktop;
char *g_variables;
void __declspec(dllexport) myFunction(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop)
{
g_hwndParent=hwndParent;
g_stringsize=string_size;
g_stacktop=stacktop;
g_variables=variables;
// do your stuff here
{
char buf[1024];
wsprintf(buf,"$0=%s\n",getuservariable(INST_0));
MessageBox(g_hwndParent,buf,0,MB_OK);
}
}
BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
g_hInstance=hInst;
return TRUE;
}
// utility functions (not required but often useful)
int popstring(char *str)
{
stack_t *th;
if (!g_stacktop || !*g_stacktop) return 1;
th=(*g_stacktop);
lstrcpy(str,th->text);
*g_stacktop = th->next;
GlobalFree((HGLOBAL)th);
return 0;
}
void pushstring(char *str)
{
stack_t *th;
if (!g_stacktop) return;
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
lstrcpyn(th->text,str,g_stringsize);
th->next=*g_stacktop;
*g_stacktop=th;
}
char *getuservariable(int varnum)
{
if (varnum < 0 || varnum >= __INST_LAST) return NULL;
return g_variables+varnum*g_stringsize;
}

122
Contrib/ExDLL/exdll.dpr Normal file
View file

@ -0,0 +1,122 @@
{
NSIS ExDLL example
(C) 2001 - Peter Windridge
Fixed and formatted by Alexander Tereschenko
http://futuris.plastiqueweb.com/
Tested in Delphi 6.01
}
library exdll;
uses Windows;
type
VarConstants = (
INST_0,
INST_1, // $1
INST_2, // $2
INST_3, // $3
INST_4, // $4
INST_5, // $5
INST_6, // $6
INST_7, // $7
INST_8, // $8
INST_9, // $9
INST_R0, // $R0
INST_R1, // $R1
INST_R2, // $R2
INST_R3, // $R3
INST_R4, // $R4
INST_R5, // $R5
INST_R6, // $R6
INST_R7, // $R7
INST_R8, // $R8
INST_R9, // $R9
INST_CMDLINE, // $CMDLINE
INST_INSTDIR, // $INSTDIR
INST_OUTDIR, // $OUTDIR
INST_EXEDIR, // $EXEDIR
__INST_LAST
);
TVariableList = INST_0..__INST_LAST;
pstack_t = ^stack_t;
stack_t = record
next: pstack_t;
text: PChar;
end;
var
g_stringsize: integer;
g_stacktop: ^pstack_t;
g_variables: PChar;
g_hwndParent: HWND;
function PopString(str: PChar):integer;
var
th: pstack_t;
begin
if integer(g_stacktop^) = 0 then
begin
Result:=1;
Exit;
end;
th:=g_stacktop^;
lstrcpy(str,@th.text);
g_stacktop^ := th.next;
GlobalFree(HGLOBAL(th));
Result:=0;
end;
function PushString(str: PChar):integer;
var
th: pstack_t;
begin
if integer(g_stacktop) = 0 then
begin
Result:=1;
Exit;
end;
th:=pstack_t(GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize));
lstrcpyn(@th.text,str,g_stringsize);
th.next:=g_stacktop^;
g_stacktop^:=th;
Result:=0;
end;
function GetUserVariable(varnum: TVariableList):PChar;
begin
if (integer(varnum) < 0) or (integer(varnum) >= integer(__INST_LAST)) then
begin
Result:='';
Exit;
end;
Result:=g_variables+integer(varnum)*g_stringsize;
end;
function ex_dll(hwndParent: HWND; string_size: integer; variables: PChar; stacktop: pointer):integer; cdecl;
var
c: PChar;
buf: array[0..1024] of char;
begin
// set up global variables
g_stringsize:=string_size;
g_hwndParent:=hwndParent;
g_stringsize:=string_size;
g_stacktop:=stacktop;
g_variables:=variables;
c:=GetUserVariable(INST_0);
MessageBox(g_hwndParent,c,'The value of $0',MB_OK);
PopString(@buf);
MessageBox(g_hwndParent,@buf,'pop',MB_OK);
PushString(PChar('Hello, this is a push'));
Result:=1;
end;
exports ex_dll;
begin
end.

107
Contrib/ExDLL/exdll.dsp Normal file
View file

@ -0,0 +1,107 @@
# Microsoft Developer Studio Project File - Name="exdll" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=exdll - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "exdll.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "exdll.mak" CFG="exdll - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "exdll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "exdll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "exdll - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"_DllMainCRTStartup" /dll /machine:I386 /nodefaultlib /out:"../../exdll.dll" /opt:nowin98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "exdll - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "exdll - Win32 Release"
# Name "exdll - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\exdll.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

29
Contrib/ExDLL/exdll.dsw Normal file
View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "exdll"=.\exdll.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

BIN
Contrib/Icons/checks1.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

BIN
Contrib/Icons/checks2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

BIN
Contrib/Icons/checks4.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

BIN
Contrib/Icons/checksX.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

BIN
Contrib/Icons/checksX2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

BIN
Contrib/Icons/setup.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

View file

@ -0,0 +1,363 @@
<HTML><HEAD><TITLE>Install Options/DLL Documentation</TITLE></HEAD>
<BODY bgColor=#ffffff>
<CENTER><FONT size=+2><A
href="http://installoptions.sourceforge.net/"><B>Install
Options</B></A> (/DLL)</FONT><BR><FONT size=-1>Copyright © 2001 <A
href="mailto:mbishop@bytealliance.com?subject=Installer Options">Michael
Bishop</A> (original version) and Nullsoft, Inc. (DLL conversion and integration)
</FONT></CENTER>
<UL><B>Table of Contents</B>
<LI><A
href="#introduction">Introduction</A>
<LI><A
href="#history">Version
History</A>
<LI><A
href="#license">License</A>
</LI></UL>
<HR>
<A name=introduction><B>Introduction:</B><BR><I>Installer Options</I> was a quick
application Michael Bishop threw together so he could prompt the user for some information
during the install process. This version is a highly modified version of it that is designed
as a NSIS extension DLL for the <A
href="http://www.nullsoft.com/free/nsis/">NSIS</A> installer. Installer Options will create a
dialog box which will be displayed inside of the NSIS window. The dialog box is
defined by an INI file, which allows you to define the layout of controls by
changing the INI file.
<P>To use the DLL, you should include it as part of your installation.
Extract it to known location (probably $TEMP), and then load it using CallInstDLL, passing one parameter on the stack.
The one parameter is a name of an .ini file that defines the window.
Example: <PRE>
SetOutPath $TEMP
File inst.ini
File InstallOptions.dll
Push $TEMP\inst.ini
CallInstDLL $TEMP\InstallOptions.dll dialog
Pop $0
; ($0 would be "success" "cancel" "back" or some other value on error.
ReadINIStr $1 $TEMP\inst.ini "Field 1" State ; $1 = field #1's state
Delete $TEMP\inst.nsi
Delete $TEMP\InstallOptions.dll
</PRE>
It is often very useful to call InstallOptions from the NSIS callback functions .onNextPage and .onPrevPage.
<P>The INI file has one required section. This section includes the number of controls to be created as well as general window attributes. The INI file also
includes a variable number of Field sections which are used to create the
controls to be displayed.
<P>The required section is named "<I>Settings</I>". It will contain the
following values:
<UL>
<TABLE border=0>
<TBODY>
<TR>
<TD vAlign=top bgColor=#cccccc><B>NumFields</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(required)</I></TD>
<TD vAlign=top bgColor=#eeeeee>The number of control elements to be
displayed on the dialog window.</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>Title</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>If specified, gives the text to set the
titlebar to. Otherwise, the titlebar text is not changed.</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>CancelConfirm</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>If specified, prompts the user (With text) whether or not to cancel if they select the cancel button.</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>BackEnabled</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Controls whether or not the back button in the NSIS window is enabled. If set to 0 or omitted, the back button will be disabled. If set to 1, the back button will be enabled.</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>CancelButtonText</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Overrides the text for the cancel button. If not specified, the cancel button text will not be changed. Recommended value: "Cancel"</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>NextButtonText</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Overrides the text for the next button. If not specified, the next button text will not be changed. Recommended value: "Next >"</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>BackButtonText</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Overrides the text for the back button. If not specified, the back button text will not be changed. Recommended value: "< Back"</TD></TR>
</TBODY></TABLE></UL>
<P>Each field section has the heading "Field #" where # must be sequential
numbers from 1 to NumFields. Each Field section contains the following values:
<UL>
<TABLE border=0>
<TBODY>
<TR>
<TD vAlign=top bgColor=#cccccc><B>Type</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(required)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Type of control to be created. Valid
values are "<I>Label</I>", "<I>Text</I>", "<I>Password</I>",
"<I>Combobox</I>", "<I>DropList</I>", "<I>Listbox</I>", "<I>CheckBox</I>",
"<I>RadioButton</I>",
"<I>FileRequest</I>", or "<I>DirRequest</I>".<BR><FONT size=-1>A
"<I>label</I>" is used to display static text. (i.e. a caption for a
textbox)<BR>A "<I>textbox</I>" and "<I>password</I>" accept text input
from the user. "<I>password</I>" masks the input with * characters.<BR>A
"<I>combobox</I>" allows the user to type text not in the popup list, a
"<I>droplist</I>" only allows selection of items in the list.<BR>A
"<I>listbox</I>" shows multiple items and can optionally allow the user
to select more than one item.<BR>
A "<I>CheckBox</I>" control displays a check box with label.<BR>
A "<I>RadioButton</I>" control displays a radio button with label.<BR>
A "<I>FileRequest</I>" control displays
a textbox and a browse button. Clicking the browse button will display a
file requester where the user can browse for a file.<BR>A
"<I>DirRequest</I>" control displays a textbox and a browse button.
Clicking the browse button will display a directory requester where the
user can browse for a directory.<BR></FONT></TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>Text</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Specifies the caption of a label, checkbox, or radio button control.
</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>State</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Specifies the state of the control. This is updated when the user closes the window,
so you can read from it from NSIS. For edit texts and dir and file request boxes, this is the string that is
specified. For radio button and check boxes, this can be '0' or '1' (for unchecked or checked).
</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>ListItems</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>A list of items to display in a combobox,
droplist, or listbox.<BR>This is a single line of text with each item
separated by a pipe character '<B>|</B>'</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>MaxLen</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Causes validation on the selected control
to limit the maximum length of text.<BR>If the user specifies more text
than this, a message box will appear when they click "OK" and the dialog
will not be dismissed.<BR><FONT size=-1>You should not use this on a
"<I>combobox</I>" since the user can not control what is
selected.</FONT><BR><FONT size=-1>This should be set to a maximum of 260
for "<I>FileRequest</I>" and "<I>DirRequest</I>"
controls.</FONT><BR><FONT size=-1>Ignored on "<I>label</I>"
controls.</FONT></TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>MinLen</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Causes validation on the selected control
to force the user to enter a minimum amount of text.<BR>If the user
specifies less text than this, a message box will appear when they click
"OK" and the dialog will not be dismissed.<BR>Unlike MaxLen, this is
useful for "<I>Combobox</I>" controls. By setting this to a value of "1"
the program will force the user to select an item.<BR><FONT
size=-1>Ignored on "<I>label</I>" controls.</FONT></TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>ValidateText</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>If a particular field fails the test for
"<I>MinLen</I>" or "<I>MaxLen</I>", a messagebox will be displayed with
this text.<BR><FONT size=-1>NOTE: The only formatting performed on this
text is "\n" will be replaced with a newline in the
messagebox.</FONT></TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>Left<BR>Right<BR>Top<BR>Bottom</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(required)</I></TD>
<TD vAlign=top bgColor=#eeeeee>The position on the dialog where this
control appears.<BR>Sorry, no GUI here to help you.<BR><FONT color=red
size=-1>NOTE: For combobox or droplist, the "<I>bottom</I>" value is not
used in the same way.<BR>In this case, the bottom value is the maximum
size of the window when the pop-up list is being displayed. All other
times, the combobox is automatically szed to be one element tall. If you
have trouble where you can not see the combobox drop-down, then check
the bottom value and ensure it is large enough. <BR>NOTE (2):
FileRequest and DirRequest controls will allocate 20 pixels to the
browse button. Make this control wide enough the contents of the textbox
can be seen. Note that you can specify negative coordinates to specify the distance from the right or bottom edge.</FONT></TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>Filter</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Specifies the filter to be used in the
"<I>FileRequest</I>" control.<BR>This is constructed by putting pairs of
entries together, each item seperated by a | character.<BR>The first
value in each pair is the text to display for the filter.<BR>The second
value is the pattern to use to match files.<BR>For example, you might
specify:<BR>
<UL>Filter=Text Files|*.txt|Programs|*.exe;*.com|All Files|*.*
</UL><FONT size=-1>If not specified, then the filter defaults to All
Files|*.*</FONT><BR><FONT size=-1>NOTE: you should not put any extra
spaces around the | characters.</FONT> </TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>Root</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>Used by <I>DirRequest</I> controls to
specify the root directory of the search. By default, this allows the
user to browse any directory on the computer. This will limit the search
to a particular directory on the system.</TD></TR>
<TR>
<TD vAlign=top bgColor=#cccccc><B>Flags</B></TD>
<TD vAlign=top bgColor=#cccccc><I>(optional)</I></TD>
<TD vAlign=top bgColor=#eeeeee>This specifies additional flags for the
display of different controls. Each value should be seperated by a |
character, and you should be careful not to put any spaces around the |
character.<BR>
<TABLE border=0>
<TBODY>
<TR>
<TD vAlign=top><B>Value</B></TD>
<TD vAlign=top><B>Meaning</B></TD></TR>
<TR>
<TD vAlign=top>REQ_SAVE</TD>
<TD vAlign=top>This causes the "<I>FileRequest</I>" to dislpay a
Save As dialog. If not specified, an Open dialog is used.</TD></TR>
<TR>
<TD vAlign=top>FILE_MUST_EXIST</TD>
<TD vAlign=top>Used by "<I>FileRequest</I>" to determine if the
selected file must exist.<BR>This only applies if an "Open" dialog
is being displayed.<BR><FONT size=-1>This currently does not force
the file to exist other than through the browse
button.</FONT></TD></TR>
<TR>
<TD vAlign=top>FILE_EXPLORER</TD>
<TD vAlign=top>Used by "<I>FileRequest</I>", enables new file request look (recommended)</FONT></TD></TR>
<TR>
<TD vAlign=top>FILE_HIDEREADONLY</TD>
<TD vAlign=top>Used by "<I>FileRequest</I>", hides "open read only" checkbox in open dialog.</FONT></TD></TR>
<TR>
<TD vAlign=top>WARN_IF_EXIST</TD>
<TD vAlign=top>Used by "<I>FileRequest</I>" to display a warning
message if the selected file already exists.<BR><FONT size=-1>The
warning message is only displayed for files selected with the
browse button.</FONT></TD></TR>
<TR>
<TD vAlign=top>PATH_MUST_EXIST</TD>
<TD vAlign=top>Used by "<I>FileRequest</I>" to force the path to
exist. Prevents the user from typing a non-existant path into the
browse dialog window.<BR><FONT size=-1>This only validates path's
selected with the browse button.</FONT></TD></TR>
<TR>
<TD vAlign=top>PROMPT_CREATE</TD>
<TD vAlign=top>Used by "<I>FileRequest</I>" to display a warning
if the selected file does not exist. However, it still allows the
user to select the file.<BR><FONT size=-1>This only displays the
warning for files selected with the browse button.</FONT></TD></TR>
<TR>
<TD vAlign=top>RIGHT</TD>
<TD vAlign=top>Used by "<I>Checkbox</I>" and "<I>Radiobutton</I>"
controls to specify you want the checkbox to the right of the text
instead of the left as is the default. </TD></TR>
<TR>
<TD vAlign=top>MULTISELECT</TD>
<TD vAlign=top>Used by "<I>Listbox</I>" controls to specify if
more than item may be selected. If this flag is not specified,
then only one item may be selected from the
list.</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></UL>
<HR>
<A name=history><A name=top><B>History:</B>
<P>
<UL>
<LI><a name=DLL1.1>DLL version 1.2 beta (7/31/2002)
<UL>
<li>Added CancelEnabled (by ORTIM)
<li>Added CancelConfirmCaption and CancelConfirmIcon (by Amir Szekely)
</UL>
<LI><a name=DLL1.1>DLL version 1.1 beta (7/22/2002)
<UL>
<li>Font is now taken from the main NSIS window (by Amir Szekely)
</UL>
<LI><a name=DLL1.0>DLL version 1.0 beta (12/16/2001)
<UL>
<LI>Moved to DLL, no longer need parentwnd ini writing
<li>Tons of changes - no longer fully compatible (see source for a big list)
<LI>removed support for silent installers (it seems the old version would bring up it's own dialog)
</UL>
<LI><A name=1.4>version 1.4 (11/18/2001)
<UL>
<LI>Added <I>Listbox</I> controls.
<UL>
<LI>Added <I>MULTISELECT</I> flag. </LI></UL>
<LI>Made the HWND list for the parent window controls dynamically allocated.
This prevents a crash if NSIS ever gets more than 150 controls on it's main
window.
<LI>The <I>TEXT</I> property of DirRequest control can be used to specify an
initial directory. The current directory is automatically selected when
clicking the browse button of the DirRequest control.
<LI>Added <I>ROOT</I> property to DirRequest which can be used to set the
root directory. (mostly due to felfert)
<LI>Edit controls will now auto scroll. (thanks felfert)
<LI>Fixed a problem where the window wouldn't draw properly on some systems.
(thanks felfert) </LI></UL>
<LI><A name=1.3>version 1.3 (11/03/2001)
<UL>
<LI>Got rid of the call to RedrawWindow() because it's no longer needed with
the WS_CLIPCHILDREN flag for NSIS.
<LI>Removed a few hardcoded limits of buffer sizes.
<LI>Added <I>Checkbox</I> and <I>RadioButton</I> controls.
<UL>
<LI>Added <I>RIGHT</I> and <I>CHECKED</I> flags. </LI></UL></LI></UL>
<LI><A name=1.2.2>version 1.2.2 (10/30/2001)
<UL>
<LI>Additional size reductions. Further reduced the size down to 8k.
<LI>The text parameter to a combobox can now be used to specify the initial
value.
<LI>Changed from InvalidateRect() to RedrawWindow() to force a redraw after
a browse dialog.
<LI>On startup, set the flags of the NSIS window to include WS_CLIPCHILDREN.
Otherwise, our controls don't get drawn right. </LI></UL>
<LI><A name=1.2.1>version 1.2.1 (10/28/2001)
<UL>
<LI>Bug fix. ControlID for the caption and the OK button were reused by the
first two controls. (Thanks Schultz) </LI></UL>
<LI><A name=1.2j>version 1.2j (10/28/2001) (justin frankel's modifications)
<UL>
<LI>8.5kb from 44kb. heh. </LI></UL>
<LI><A name=1.2>version 1.2 (10/28/2001)
<UL><FONT size=-1>(Thanks to Schultz for requesting the first
item.)</FONT><BR><FONT size=-1>Still 44k, but would like to make it smaller.
All of NSIS only amounts to 35.5k</FONT>
<LI>Added the "<I>FileRequest</I>" and "<I>DirRequest</I>" control
types.<BR><FONT size=-1>NOTE: Please let me know if this is going to require
any DLL's which might not be on the target machine.<BR>Keep in mind that
although we are using system DLL's, the program will exit before NSIS tries
to copy any files.</FONT>
<LI>Added "<I>MinLen</I>", "<I>MaxLen</I>", and "<I>ValidateText</I>"
properties to fields.
<LI>Added "<I>Flags</I>" as a way to specifiy additional parameters for
controls.
<LI>Few more changes to the documentation.
<LI>Cleaned the code in a few places...still trying to make it smaller.
</LI></UL>
<LI><A name=1.1>version 1.1 (10/27/2001)
<UL><FONT size=-1>(Thanks to Alex ??? for requesting the first
three.)</FONT>
<LI>Added the "<I>Title</I>" option.
<LI>Moved the OK button so it is in the same location as the buttons on the
main NSIS window.
<LI>Pressing "ENTER" will now automatically select the OK butt/FONT&gt;
<LI>Slightly improved the documentation. </LI></UL>
<LI><A name=1.01>version 1.01: (10/25/2001)
<UL>
<LI>Fixed the SetFocus loop so it exits after the first control like it was
supposed to.
<LI>Added the license to the documentation. </LI></UL>
<LI><A name=1.0>version 1.0: (10/25/2001)
<UL>
<LI>Barely qualifies as a distribution. </LI></UL></LI></UL>
<HR>
<A name=license><PRE> Copyright © 2001 Michael Bishop
Portions Copyright © 2001 Nullsoft, Inc.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
</PRE></A></BODY></HTML>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,115 @@
# Microsoft Developer Studio Project File - Name="io" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=io - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "io.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "io.mak" CFG="io - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "io - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "io - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "io - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTOPTDLL_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTOPTDLL_EXPORTS" /D "WIN32_LEAN_AND_MEAN" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /nodefaultlib /out:"../../Bin/InstallOptions.dll" /opt:nowin98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "io - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTOPTDLL_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "INSTOPTDLL_EXPORTS" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "io - Win32 Release"
# Name "io - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\InstallerOptions.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\ioptdll.rc
# End Source File
# End Group
# End Target
# End Project

View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "io"=.\io.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View file

@ -0,0 +1,94 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 57, 41
STYLE DS_CONTROL | WS_CHILD
FONT 8, "MS Sans Serif"
BEGIN
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 50
TOPMARGIN, 7
BOTTOMMARGIN, 34
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View file

@ -0,0 +1,16 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by ioptdll.rc
//
#define IDD_DIALOG1 101
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View file

@ -0,0 +1,67 @@
[Settings]
NumFields=6
Title=Test Install Setup: Testing Installer Options
; uncomment this to confirm on exit.
; CancelConfirm=Are you sure you want to cancel the install?
; comment this out to hide the back button
BackEnabled=1
; you can override the defaults here
CancelButtonText=Cancel
NextButtonText=Next >
BackButtonText=< Back
[Field 1]
Type=checkbox
text=Install support for X
left=0
right=300
top=0
bottom=15
state=0
[Field 2]
Type=checkbox
text=Install support for Y
left=0
right=300
top=15
bottom=30
state=1
[Field 3]
Type=checkbox
text=Install support for Z
left=0
right=300
top=30
bottom=45
state=0
[Field 4]
Type=FileRequest
State=C:\poop.poop
Left=0
Right=-1
Top=45
Bottom=64
Filter=Poop Files|*.poop|All files|*.*
Flags=FILE_MUST_EXIST|OFN_EXPLORER|OFN_HIDEREADONLY
[Field 5]
Type=DirRequest
Left=0
Right=-1
Top=65
Bottom=84
[Field 6]
Type=Label
Left=0
Right=-1
Top=85
Bottom=104
Text=This is a label...

View file

@ -0,0 +1,128 @@
; Copyright (C) 2001 Michael Bishop
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
;
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it
; freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source distribution.
;
; Test installation script
; The name of the installer
Name "Test Install"
; The file to write
OutFile "test-setup.exe"
ShowInstDetails show
; The default installation directory
InstallDir $PROGRAMFILES\Test
DirText "Choose dir"
LicenseText "You are about to install test install and it owns, you will love it, we think."
LicenseData "..\..\license.txt"
ComponentText "Choose components"
; Do not automatically close the installation window
AutoCloseWindow false
; Define some installation templates
InstType "Typical" ; 1
Section "Required Components"
ReadINIStr $R0 $7 "Field 1" State
DetailPrint "Install X=$R0"
ReadINIStr $R0 $7 "Field 2" State
DetailPrint "Install Y=$R0"
ReadINIStr $R0 $7 "Field 3" State
DetailPrint "Install Z=$R0"
ReadINIStr $R0 $7 "Field 4" State
DetailPrint "File=$R0"
ReadINIStr $R0 $7 "Field 5" State
DetailPrint "Dir=$R0"
SectionEnd
Section "more components"
Nop
SectionEnd
; $9 = counter
; $8 = DLL
; $7 = ini
Function .onInit
StrCpy $9 0
GetTempFileName $8
GetTempFileName $7
File /oname=$8 ..\..\Bin\InstallOptions.dll
File /oname=$7 "test.ini"
FunctionEnd
; cleanup on exit.
Function .onInstSuccess
Call Cleanup
FunctionEnd
Function .onInstFailed
Call Cleanup
FunctionEnd
Function .onUserAbort
Call Cleanup
FunctionEnd
Function Cleanup
Delete $8
Delete $7
FunctionEnd
Function .onNextPage
StrCmp $9 1 good
IntOp $9 $9 + 1
Return
good:
Call RunConfigure
Pop $0
StrCmp $0 "cancel" "" nocancel
Call Cleanup
Quit
nocancel:
StrCmp $0 "back" "" noback
Abort
noback:
IntOp $9 $9 + 1
FunctionEnd
Function .onPrevPage
StrCmp $9 2 good
IntOp $9 $9 - 1
Return
good:
Call RunConfigure
Pop $0
StrCmp $0 "cancel" "" nocancel
Call Cleanup
Quit
nocancel:
StrCmp $0 "back" back
Abort
back:
IntOp $9 $9 - 1
FunctionEnd
Function RunConfigure
Push $7
CallInstDLL $8 dialog
FunctionEnd

View file

@ -0,0 +1,18 @@
Copyright (c) 2002 Robert Rainwter <rrainwater@yahoo.com>
-- this version was slightly modified by Justin Frankel --
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

View file

@ -0,0 +1,152 @@
----------------------------------------------------
MakeNSISW - MakeNSIS Windows Wrapper
----------------------------------------------------
About MakeNSISW
---------------
MakeNSISW is a wrapper for the MakeNSIS that is distributed with
NSIS (http://www.nullsoft.com/free/nsis/). MakeNSISW allows you
to compile NSIS scripts using a Windows GUI interface. To install
MakeNSISW, compile the source using Visual C++ or Mingw.
Requirements
------------
MakeNSISW requires NSIS be installed on your system. The default
directory for this installation is $PROGRAMFILES\NSIS\Contrib\MakeNSISW.
Usage:
------
If you installed the Shell Extensions option during the installation, then
all that is required is that you choose 'Compile NSI' from the right-
click menu on a NSIS script. This will invoke MakeNSISW.
The format of the parameters when calling MakeNSISW from the commandline is:
makensisw full_path_of_makensis.exe [options] [script.nsi | - [...]]
Where full_path_of_makensis.exe is the full name including the path of the
compiler. For the options, please see the MakeNSIS documentation.
Shortcut Keys
-------------
Ctrl+R: Recompiles the script
Ctrl+X: Exits the application
Ctrl+T: Tests the installer
Ctrl+E: Edits the script
Version History
---------------
0.1
- Initial Release
0.2
- Added ability to save output and copy output
0.3
- Added option to recompile script (F2 or File|Recompile)
- Added Help Menu
- Return code is now always set
- Added Accelerator key support for Exit and Recompile
- No longer uses NSIS's version string
- Made clearer status message in title bar
- Disabled menu/accelerator functions during compile
0.4
- Fixed Copy Selected bug
0.5
- Minor Makefile changes (mingw)
- Moved strings into global strings to make editing easier
- Added Clear Log Command under Edit menu
- Recompile no longer clears the log window (use F5)
- Close is now the default button when you hit enter
- added VC++ project, updated resources to work with VC++
- rearranged directory structure
- makefiles now target ../../makensisw.exe
- removed makensisw home link in help menu (hope this is ok,
doesn't really seem needed to me)
- made display use a fixed width font (Some people may not like
this, but I do)
- added 'test' button (peeks output for 'Output' line)
- made it so that the log shows the most recent 32k.
- made it so that the log always clears on a recompile.
- compiled with VC++ so no longer needs msvcrt.dll
- made the compiler name be a full path (for more flexibility)
0.6
- print correct usage if unable to execute compiler
- removed mingw warnings
- set title/branding before errors
- some docs changes
- Added Edit|Edit Script function
0.7
- Edit Script should now work for output>32k
- Added resize support (thanks to felfert)
- Added window position saving (thanks to felfert)
- Disable some items when exec of makensis failed
0.8
- Added window size constraints (thanks to bcheck)
- Cleaned up the resource file
0.9
- Removed global strings (moved into #defines)
- Some GUI changes
- No longer focused Close button (its default anyways)
- Fixed resize bug on minimize/restore (thanks to felfert)
- Made window placement stored in HKLM instead of HKCU, cause
I hate things that get littered in HKCU.
1.0
- Fixed bug with large output causing crash
1.1
- Crash may actually be fixed
1.2
- XP visual style support
1.3
- Added Documentation menu item
- Fix GUI problem with About dialog
1.4
- Edit Script command will now work with or without file associations
- Added default filename for save dialog
- Use standard fonts
- Documentation menuitem caused recompile
1.5
- Fixed Copy All function
1.6
- Reduced size from 44k to 12k (kickik)
- Editbox not limited to 32k (now using richedit control)
- Made the log window font-size smaller.
Copyright Information
---------------------
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

View file

@ -0,0 +1,5 @@
#include <windows.h>
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif

View file

@ -0,0 +1,363 @@
/*
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <windows.h>
#include <stdio.h>
#include "makensisw.h"
#include "resource.h"
#include "noclib.h"
char *g_script;
int g_retcode;
static RECT resizeRect;
static int dx;
static int dy;
HINSTANCE g_hInstance;
HWND g_hwnd;
HANDLE g_hThread;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow) {
HACCEL haccel;
g_hInstance=GetModuleHandle(0);
g_script=GetCommandLine(); // set commandline global string
if (*g_script++=='"') while (*g_script++!='"');
else while (*g_script++!=' ');
while (*g_script==' ') g_script++;
g_retcode = -1; // return code is always false unless set to true by GetExitCodeProcess
HWND hDialog = CreateDialog(g_hInstance,MAKEINTRESOURCE(DLG_MAIN),0,DialogProc);
if (!hDialog) {
char buf [MAX_STRING];
wsprintf(buf, "Error creating dialog box.\n\nError: %x", GetLastError ());
MessageBox(0, buf, "Error", MB_ICONEXCLAMATION | MB_OK);
return 1;
}
haccel = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDK_ACCEL));
MSG msg;
int status;
while ((status=GetMessage(&msg,0,0,0))!=0) {
if (status==-1) return -1;
if (!TranslateAccelerator(hDialog,haccel,&msg)) {
if (!IsDialogMessage(hDialog,&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
ExitProcess(msg.wParam);
return msg.wParam;
}
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
static HINSTANCE hRichEditDLL = 0;
if (!hRichEditDLL) hRichEditDLL= LoadLibrary("RichEd32.dll");
switch (msg) {
case WM_INITDIALOG:
{
g_hwnd=hwndDlg;
HICON hIcon = LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON));
SetClassLong(hwndDlg,GCL_HICON,(long)hIcon);
HFONT hFont = CreateFont(14,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,"Courier New");
SendDlgItemMessage(hwndDlg,IDC_LOGWIN,WM_SETFONT,(WPARAM)hFont,0);
SendDlgItemMessage(hwndDlg,IDC_LOGWIN,EM_SETBKGNDCOLOR,0,GetSysColor(COLOR_BTNFACE));
RestoreWindowPos(g_hwnd);
CompileNSISScript();
return TRUE;
}
case WM_DESTROY:
{
SaveWindowPos(g_hwnd);
PostQuitMessage(0);
return TRUE;
}
case WM_CLOSE:
{
if (!g_hThread) {
DestroyWindow(hwndDlg);
FreeLibrary(hRichEditDLL);
}
return TRUE;
}
case WM_GETMINMAXINFO:
{
((MINMAXINFO*)lParam)->ptMinTrackSize.x=MINWIDTH;
((MINMAXINFO*)lParam)->ptMinTrackSize.y=MINHEIGHT;
}
case WM_ENTERSIZEMOVE:
{
GetClientRect(g_hwnd, &resizeRect);
return TRUE;
}
case WM_SIZE:
{
if ((wParam == SIZE_MAXHIDE)||(wParam == SIZE_MAXSHOW)) return TRUE;
}
case WM_SIZING:
{
RECT rSize;
if (hwndDlg == g_hwnd) {
GetClientRect(g_hwnd, &rSize);
if (((rSize.right==0)&&(rSize.bottom==0))||((resizeRect.right==0)&&(resizeRect.bottom==0)))
return TRUE;
dx = rSize.right - resizeRect.right;
dy = rSize.bottom - resizeRect.bottom;
EnumChildWindows(g_hwnd, DialogResize, (LPARAM)0);
resizeRect = rSize;
}
return TRUE;
}
case WM_MAKENSIS_PROCESSCOMPLETE:
{
if (g_hThread) {
CloseHandle(g_hThread);
g_hThread=0;
}
if (g_retcode==0) SetTitle(g_hwnd,"Finished Sucessfully");
else SetTitle(g_hwnd,"Compile Error: See Log for Details");
EnableItems(g_hwnd);
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam)) {
case IDM_ABOUT:
{
DialogBox(g_hInstance,MAKEINTRESOURCE(DLG_ABOUT),g_hwnd,(DLGPROC)AboutProc);
return TRUE;
}
case IDM_NSISHOME:
{
ShellExecute(g_hwnd,"open",NSIS_URL,NULL,NULL,SW_SHOWNORMAL);
return TRUE;
}
case IDM_DOCS:
{
char pathf[MAX_PATH],*path;
GetModuleFileName(NULL,pathf,sizeof(pathf));
path=my_strrchr(pathf,'\\');
if(path!=NULL) *path=0;
lstrcat(pathf,"\\makensis.htm");
if ((int)ShellExecute(g_hwnd,"open",pathf,NULL,NULL,SW_SHOWNORMAL)<=32)
ShellExecute(g_hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL);
return TRUE;
}
case IDM_RECOMPILE:
{
CompileNSISScript();
return TRUE;
}
case IDM_TEST:
case IDC_TEST:
{
if (g_output_exe[0]) {
ShellExecute(g_hwnd,"open",g_output_exe,NULL,NULL,SW_SHOWNORMAL);
}
return TRUE;
}
case IDM_EDITSCRIPT:
{
if (g_input_script[0]) {
if ((int)ShellExecute(g_hwnd,"open",g_input_script,NULL,NULL,SW_SHOWNORMAL)<=32) {
char path[MAX_PATH];
if (GetWindowsDirectory(path,sizeof(path))) {
lstrcat(path,"\\notepad.exe");
ShellExecute(g_hwnd,"open",path,g_input_script,NULL,SW_SHOWNORMAL);
}
}
}
return TRUE;
}
case IDC_CLOSE:
case IDM_EXIT:
{
if (!g_hThread) {
DestroyWindow(hwndDlg);
}
return TRUE;
}
case IDM_COPY:
{
CopyToClipboard(g_hwnd);
return TRUE;
}
case IDM_COPYSELECTED:
{
SendMessage(GetDlgItem(g_hwnd,IDC_LOGWIN), WM_COPY, 0, 0);
return TRUE;
}
case IDM_SAVE:
{
OPENFILENAME l={sizeof(l),};
char buf[MAX_STRING];
l.hwndOwner = hwndDlg;
l.lpstrFilter = "Log Files (*.log)\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
l.lpstrFile = buf;
l.nMaxFile = 1023;
l.lpstrTitle = "Save Output";
l.lpstrDefExt = "log";
l.lpstrInitialDir = NULL;
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST;
lstrcpy(buf,"output.log");
if (GetSaveFileName(&l)) {
HANDLE hFile = CreateFile(buf,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0);
if (hFile) {
int len=SendDlgItemMessage(g_hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
char *existing_text=(char*)GlobalAlloc(GPTR,len);
existing_text[0]=0;
GetDlgItemText(g_hwnd, IDC_LOGWIN, existing_text, len);
DWORD dwWritten = 0;
WriteFile(hFile,existing_text,len,&dwWritten,0);
CloseHandle(hFile);
GlobalFree(existing_text);
}
}
return TRUE;
}
}
}
}
return 0;
}
DWORD WINAPI MakeNSISProc(LPVOID p) {
char buf[1024];
STARTUPINFO si={sizeof(si),};
SECURITY_ATTRIBUTES sa={sizeof(sa),};
SECURITY_DESCRIPTOR sd={0,};
PROCESS_INFORMATION pi={0,};
HANDLE newstdout=0,read_stdout=0;
OSVERSIONINFO osv={sizeof(osv)};
GetVersionEx(&osv);
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd,true,NULL,false);
sa.lpSecurityDescriptor = &sd;
}
else sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
ErrorMessage(g_hwnd,"There was an error creating the pipe.");
PostMessage(g_hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
return 1;
}
GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.hStdOutput = newstdout;
si.hStdError = newstdout;
if (!CreateProcess(NULL,g_script,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
char buf[MAX_STRING];
wsprintf(buf,"Could not execute:\r\n %s.",g_script);
ErrorMessage(g_hwnd,buf);
CloseHandle(newstdout);
CloseHandle(read_stdout);
PostMessage(g_hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
return 1;
}
unsigned long exit=0,read,avail;
my_memset(buf,0,sizeof(buf));
while(1) {
PeekNamedPipe(read_stdout,buf,sizeof(buf)-1,&read,&avail,NULL);
if (read != 0) {
my_memset(buf,0,sizeof(buf));
if (avail > sizeof(buf)-1) {
while (read >= sizeof(buf)-1) {
ReadFile(read_stdout,buf,sizeof(buf)-1,&read,NULL);
LogMessage(g_hwnd,buf);
my_memset(buf,0,sizeof(buf));
}
}
else {
ReadFile(read_stdout,buf,sizeof(buf),&read,NULL);
LogMessage(g_hwnd,buf);
}
}
GetExitCodeProcess(pi.hProcess,&exit);
if (exit != STILL_ACTIVE) break;
Sleep(TIMEOUT);
}
g_retcode = exit;
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(newstdout);
CloseHandle(read_stdout);
PostMessage(g_hwnd,WM_MAKENSIS_PROCESSCOMPLETE,0,0);
return 0;
}
BOOL CALLBACK DialogResize(HWND hWnd, LPARAM /* unused */)
{
RECT r;
GetWindowRect(hWnd, &r);
ScreenToClient(g_hwnd, (LPPOINT)&r);
ScreenToClient(g_hwnd, ((LPPOINT)&r)+1);
switch (GetDlgCtrlID(hWnd)) {
case IDC_LOGWIN:
SetWindowPos(hWnd, 0, r.left, r.top,r.right - r.left + dx, r.bottom - r.top + dy, SWP_NOZORDER|SWP_NOMOVE);
break;
case IDC_TEST:
case IDC_CLOSE:
SetWindowPos(hWnd, 0, r.left + dx, r.top + dy, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
break;
default:
SetWindowPos(hWnd, 0, r.left, r.top + dy, r.right - r.left + dx, r.bottom - r.top, SWP_NOZORDER);
break;
}
RedrawWindow(hWnd,NULL,NULL,RDW_INVALIDATE);
return TRUE;
}
BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_INITDIALOG:
{
HFONT bfont = CreateFont(14,0,0,0,FW_BOLD,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FIXED_PITCH|FF_DONTCARE, "MS Shell Dlg");
HFONT rfont = CreateFont(12,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FIXED_PITCH|FF_DONTCARE, "MS Shell Dlg");
if (bfont) SendDlgItemMessage(hwndDlg, IDC_ABOUTVERSION, WM_SETFONT, (WPARAM)bfont, FALSE);
if (rfont) {
SendDlgItemMessage(hwndDlg, IDC_ABOUTCOPY, WM_SETFONT, (WPARAM)rfont, FALSE);
SendDlgItemMessage(hwndDlg, IDC_ABOUTPORTIONS, WM_SETFONT, (WPARAM)rfont, FALSE);
}
char buf[MAX_STRING];
wsprintf(buf,"MakeNSISW %s",NSISW_VERSION);
SetDlgItemText(hwndDlg,IDC_ABOUTVERSION,buf);
SetDlgItemText(hwndDlg,IDC_ABOUTCOPY,COPYRIGHT);
SetDlgItemText(hwndDlg,IDC_ABOUTPORTIONS,CONTRIBUTOR);
}
case WM_COMMAND:
{
switch (LOWORD(wParam)) {
case IDOK: {
EndDialog(hwndDlg, TRUE);
}
}
}
}
return FALSE;
}

View file

@ -0,0 +1,160 @@
# Microsoft Developer Studio Project File - Name="makensisw" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=makensisw - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "makensisw.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "makensisw.mak" CFG="makensisw - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "makensisw - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "makensisw - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "makensisw - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D RELEASE=1.6 /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"WinMain" /subsystem:windows /machine:I386 /nodefaultlib /out:"../../makensisw.exe" /opt:nowin98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "makensisw - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "makensisw - Win32 Release"
# Name "makensisw - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\makensisw.cpp
# End Source File
# Begin Source File
SOURCE=.\noclib.cpp
# End Source File
# Begin Source File
SOURCE=.\utils.cpp
# End Source File
# Begin Source File
SOURCE=.\version.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\afxres.h
# End Source File
# Begin Source File
SOURCE=.\makensisw.h
# End Source File
# Begin Source File
SOURCE=.\noclib.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=..\..\Source\default1.bin
# End Source File
# Begin Source File
SOURCE=..\..\source\icon.ico
# End Source File
# Begin Source File
SOURCE=.\resource.rc
# End Source File
# Begin Source File
SOURCE=..\..\Source\rt_manif.bin
# End Source File
# End Group
# Begin Group "Documentation"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Readme.txt
# End Source File
# End Group
# Begin Source File
SOURCE=.\makensisw.xml
# End Source File
# End Target
# End Project

View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "makensisw"=.\makensisw.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View file

@ -0,0 +1,74 @@
/*
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef MAKENSIS_H
#define MAKENSIS_H
#include <commctrl.h>
#define _RICHEDIT_VER 0x0200
#include <RichEdit.h>
#undef _RICHEDIT_VER
// Defines
#define NSIS_URL "http://www.nullsoft.com/free/nsis/"
#define USAGE "Usage:\r\n makensisw full_path_of_makensis.exe [options] [script.nsi | - [...]]\r\n"
#define COPYRIGHT "Copyright (c) 2002 Robert Rainwater"
#define CONTRIBUTOR "Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert"
#define DOCPATH "http://firehose.net/free/nsis/makensis.htm"
#define REGSEC HKEY_LOCAL_MACHINE
#define REGKEY "Software\\NSIS"
#define REGLOC "MakeNSISWPlacement"
#define MAX_STRING 256
#define TIMEOUT 200
#define MINWIDTH 350
#define MINHEIGHT 180
#define WM_MAKENSIS_PROCESSCOMPLETE (WM_USER+1001)
// Extern Variables
extern const char *NSISW_VERSION;
extern char *g_script;
extern HWND g_hwnd;
extern HANDLE g_hThread;
extern char g_output_exe[1024];
extern char g_input_script[1024];
// makensisw
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow);
static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
DWORD WINAPI MakeNSISProc(LPVOID p);
BOOL CALLBACK DialogResize(HWND hWnd, LPARAM /* unused*/);
BOOL CALLBACK AboutProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
void CompileNSISScript();
// utils
void SetTitle(HWND hwnd,char *substr);
void SetBranding(HWND hwnd);
void CopyToClipboard(HWND hwnd);
void ClearLog(HWND hwnd);
void LogMessage(HWND hwnd,const char *str);
void ErrorMessage(HWND hwnd,const char *str);
void DisableItems(HWND hwnd);
void EnableItems(HWND hwnd);
void RestoreWindowPos(HWND hwnd);
void SaveWindowPos(HWND hwnd);
#endif

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="Nullsoft.NSIS.makensisw" type="win32"/>
<description>MakeNSIS Wrapper</description>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" />
</dependentAssembly>
</dependency>
</assembly>

View file

@ -0,0 +1,52 @@
/*
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
Contribution by kickik
*/
#include <windows.h>
#include "noclib.h"
char *my_strrchr(const char *string, int c) {
for (int i = lstrlen(string); i >= 0; i--)
if (string[i] == c)
return (char*)&string[i];
return 0;
}
void *my_memset(void *dest, int c, size_t count) {
for (size_t i = 0; i < count; i++) ((char*)dest)[i]=c;
return dest;
}
char *my_strstr(const char *string, const char *strCharSet) {
if (!*strCharSet) return (char*)string;
size_t chklen=lstrlen(string)-lstrlen(strCharSet);
char *s1, *s2;
for (size_t i = 0; i < chklen; i++) {
s1=&((char*)string)[i];
s2=(char*)strCharSet;
while (*s1++ == *s2++)
if (!*s2)
return &((char*)string)[i];
}
return 0;
}

View file

@ -0,0 +1,32 @@
/*
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
Contribution by kickik
*/
#ifndef NOCLIB_H
#define NOCLIB_H
char *my_strrchr(const char *string, int c);
void *my_memset(void *dest, int c, size_t count);
char *my_strstr(const char *string, const char *strCharSet);
#endif

View file

@ -0,0 +1,38 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
#define DLG_MAIN 101
#define IDI_ICON 102
#define DLG_ABOUT 103
#define IDM_MENU 104
#define IDK_ACCEL 105
#define IDR_DEFAULT1 108
#define IDC_LOGWIN 402
#define IDC_VERSION 405
#define IDC_CLOSE 406
#define IDM_ABOUT 501
#define IDM_EXIT 502
#define IDM_SAVE 503
#define IDM_COPY 504
#define IDM_COPYSELECTED 505
#define IDM_RECOMPILE 506
#define IDM_NSISHOME 507
#define IDC_TEST 1000
#define IDC_ABOUTVERSION 1001
#define IDC_ABOUTCOPY 1003
#define IDC_ABOUTPORTIONS 1005
#define IDM_TEST 40002
#define IDM_EDITSCRIPT 40003
#define IDM_DOCS 40004
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40005
#define _APS_NEXT_CONTROL_VALUE 1009
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View file

@ -0,0 +1,179 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON ICON DISCARDABLE "..\\..\\source\\icon.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDM_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Recompile\tCtrl+R", IDM_RECOMPILE
MENUITEM "&Test\tCtrl+T", IDM_TEST
MENUITEM "&Save Output...", IDM_SAVE
MENUITEM SEPARATOR
MENUITEM "E&xit\tCtrl+X", IDM_EXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "Edit Script\tCtrl+E", IDM_EDITSCRIPT
MENUITEM SEPARATOR
MENUITEM "Copy &All", IDM_COPY
MENUITEM "Copy &Selected", IDM_COPYSELECTED
END
POPUP "&Help"
BEGIN
MENUITEM "NSIS Home", IDM_NSISHOME
MENUITEM "Documentation", IDM_DOCS
MENUITEM SEPARATOR
MENUITEM "&About", IDM_ABOUT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDK_ACCEL ACCELERATORS PRELOAD MOVEABLE PURE
BEGIN
"E", IDM_EDITSCRIPT, VIRTKEY, CONTROL, NOINVERT
"R", IDM_RECOMPILE, VIRTKEY, CONTROL, NOINVERT
"T", IDM_TEST, VIRTKEY, CONTROL, NOINVERT
"X", IDM_EXIT, VIRTKEY, CONTROL, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
DLG_MAIN DIALOG DISCARDABLE 0, 0, 361, 228
STYLE DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP |
WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "MakeNSIS"
MENU IDM_MENU
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL "",IDC_LOGWIN,"RICHEDIT",ES_MULTILINE | ES_AUTOVSCROLL |
ES_READONLY | WS_BORDER | WS_VSCROLL,7,4,345,186
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,202,346,1
LTEXT "",IDC_VERSION,7,212,200,12,WS_DISABLED
DEFPUSHBUTTON "Clo&se",IDC_CLOSE,303,209,49,14
PUSHBUTTON "&Test",IDC_TEST,247,209,50,14,WS_DISABLED
END
DLG_ABOUT DIALOG DISCARDABLE 0, 0, 235, 86
STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_CAPTION |
WS_SYSMENU
CAPTION "About MakeNSISW"
FONT 8, "MS Shell Dlg"
BEGIN
ICON IDI_ICON,IDC_STATIC,7,4,20,20
DEFPUSHBUTTON "Clo&se",IDOK,185,64,43,15
LTEXT "MakeNSISW",IDC_ABOUTVERSION,44,4,184,8
LTEXT "Copyright",IDC_ABOUTCOPY,44,18,184,8
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,45,55,183,1
LTEXT "Portions Copyright",IDC_ABOUTPORTIONS,44,30,184,20
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
DLG_ABOUT, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 228
TOPMARGIN, 4
BOTTOMMARGIN, 79
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// 24
//
1 24 MOVEABLE PURE "makensisw.xml"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

185
Contrib/Makensisw/utils.cpp Normal file
View file

@ -0,0 +1,185 @@
/*
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <windows.h>
#include "resource.h"
#include "makensisw.h"
#include "noclib.h"
void SetTitle(HWND hwnd,char *substr) {
char title[64];
if (substr==NULL) wsprintf(title,"MakeNSISW");
else wsprintf(title,"MakeNSISW - %s",substr);
SetWindowText(hwnd,title);
}
void SetBranding(HWND hwnd) {
char title[64];
wsprintf(title,"MakeNSISW %s",NSISW_VERSION);
SetDlgItemText(hwnd, IDC_VERSION, title);
}
void CopyToClipboard(HWND hwnd) {
int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
char *existing_text=(char*)GlobalAlloc(GPTR,len);
if (!hwnd||!OpenClipboard(hwnd)||!existing_text) return;
EmptyClipboard();
existing_text[0]=0;
GetDlgItemText(hwnd, IDC_LOGWIN, existing_text, len);
SetClipboardData(CF_TEXT,existing_text);
CloseClipboard();
}
void ClearLog(HWND hwnd) {
SetDlgItemText(hwnd, IDC_LOGWIN, "");
}
char g_output_exe[1024];
char g_input_script[1024];
BOOL g_input_found;
void LogMessage(HWND hwnd,const char *str) {
if (!str || !*str) return;
int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
char *existing_text=(char*)GlobalAlloc(GPTR,len+lstrlen(str)+3);//3=\r\n\0
if (!existing_text) return;
existing_text[0]=0;
GETTEXTEX gt={0};
gt.cb = len;
gt.codepage = CP_ACP;
gt.flags = GT_DEFAULT;
SendDlgItemMessage(hwnd,IDC_LOGWIN,EM_GETTEXTEX,(WPARAM)&gt,(LPARAM)existing_text);
lstrcat(existing_text,str);
if (!g_input_found) {
char *p1=my_strstr(existing_text,"\r\nProcessing script file: \"");
if (p1) {
while (*p1++ != '"');
char *p2=my_strstr(p1,"\r\n");
lstrcpyn(g_input_script,p1,p2-p1);
g_input_found=TRUE;
}
}
SetDlgItemText(hwnd, IDC_LOGWIN, existing_text);
SendDlgItemMessage(hwnd, IDC_LOGWIN,EM_SETSEL,lstrlen(existing_text),lstrlen(existing_text));
SendDlgItemMessage(hwnd, IDC_LOGWIN,EM_SCROLLCARET,0,0);
GlobalFree(existing_text);
}
void ErrorMessage(HWND hwnd,const char *str) {
if (!str) return;
char buf[1028];
wsprintf(buf,"Error - %s\r\n",str);
LogMessage(hwnd,buf);
}
void DisableItems(HWND hwnd) {
g_output_exe[0]=0;
g_input_script[0]=0;
g_input_found=FALSE;
EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),0);
EnableWindow(GetDlgItem(hwnd,IDC_TEST),0);
HMENU m = GetMenu(hwnd);
EnableMenuItem(m,IDM_SAVE,MF_GRAYED);
EnableMenuItem(m,IDM_TEST,MF_GRAYED);
EnableMenuItem(m,IDM_EXIT,MF_GRAYED);
EnableMenuItem(m,IDM_RECOMPILE,MF_GRAYED);
EnableMenuItem(m,IDM_COPY,MF_GRAYED);
EnableMenuItem(m,IDM_COPYSELECTED,MF_GRAYED);
EnableMenuItem(m,IDM_EDITSCRIPT,MF_GRAYED);
}
void EnableItems(HWND hwnd) {
int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0);
char *existing_text=(char*)GlobalAlloc(GPTR,len);
if (!existing_text) return;
existing_text[0]=0;
GetDlgItemText(hwnd, IDC_LOGWIN, existing_text, len);
char *p=existing_text;
char *p2;
char *p3;
if ((p2=my_strstr(p,"\r\nOutput: \""))) {
while (*p2 != '\"') p2++;
p2++;
if ((p3=my_strstr(p2,"\"\r\n")) && p3 < my_strstr(p2,"\r\n")) {
*p3=0;
lstrcpy(g_output_exe,p2);
}
}
HMENU m = GetMenu(hwnd);
if (g_output_exe[0]) {
EnableWindow(GetDlgItem(hwnd,IDC_TEST),1);
EnableMenuItem(m,IDM_TEST,MF_ENABLED);
}
EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),1);
EnableMenuItem(m,IDM_SAVE,MF_ENABLED);
EnableMenuItem(m,IDM_EXIT,MF_ENABLED);
EnableMenuItem(m,IDM_RECOMPILE,MF_ENABLED);
EnableMenuItem(m,IDM_COPY,MF_ENABLED);
EnableMenuItem(m,IDM_COPYSELECTED,MF_ENABLED);
EnableMenuItem(m,IDM_EDITSCRIPT,MF_ENABLED);
}
void CompileNSISScript() {
ClearLog(g_hwnd);
SetTitle(g_hwnd,NULL);
SetBranding(g_hwnd);
if (lstrlen(g_script)==0) {
HMENU m = GetMenu(g_hwnd);
LogMessage(g_hwnd,USAGE);
EnableMenuItem(m,IDM_RECOMPILE,MF_GRAYED);
EnableMenuItem(m,IDM_EDITSCRIPT,MF_GRAYED);
EnableMenuItem(m,IDM_TEST,MF_GRAYED);
EnableWindow(GetDlgItem(g_hwnd,IDC_TEST),0);
return;
}
// Disable buttons during compile
DisableItems(g_hwnd);
DWORD id;
g_hThread=CreateThread(NULL,0,MakeNSISProc,0,0,&id);
}
void RestoreWindowPos(HWND hwnd) {
HKEY hKey;
WINDOWPLACEMENT p;
if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) {
DWORD l = sizeof(p);
DWORD t;
if ((RegQueryValueEx(hKey,REGLOC,NULL,&t,(unsigned char*)&p,&l)==ERROR_SUCCESS)&&(t == REG_BINARY)&&(l==sizeof(p))) {
p.length = sizeof(p);
SetWindowPlacement(hwnd, &p);
}
RegCloseKey(hKey);
}
}
void SaveWindowPos(HWND hwnd) {
HKEY hKey;
WINDOWPLACEMENT p;
p.length = sizeof(p);
GetWindowPlacement(hwnd, &p);
if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) {
RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(unsigned char*)&p,sizeof(p));
RegCloseKey(hKey);
}
}

46
Contrib/Makensisw/utils.h Normal file
View file

@ -0,0 +1,46 @@
/*
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef UTILS_H
#define UTILS_H
#define REGSEC HKEY_LOCAL_MACHINE // JF> modified this to HKLM so that
// nsis uninstaller would remove. this means
// window placement is shared across users, but
// bfd.
#define REGKEY "Software\\NSIS"
#define REGLOC "MakeNSISWPlacement"
extern const char *NSISW_VERSION;
// Methods
void SetTitle(HWND hwnd,char *substr);
void SetBranding(HWND hwnd);
void CopyToClipboard(HWND hwnd);
void ClearLog(HWND hwnd);
void LogMessage(HWND hwnd,const char *str);
void ErrorMessage(HWND hwnd,const char *str);
void DisableItems(HWND hwnd);
void EnableItems(HWND hwnd);
void RestoreWindowPos(HWND hwnd);
void SaveWindowPos(HWND hwnd);
#endif

View file

@ -0,0 +1,30 @@
/*
Copyright (c) 2002 Robert Rainwater
Portions Copyright (c) 2002 Justin Frankel and Fritz Elfert
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
// Turns a define into a string
#define REALSTR(x) #x
#define STR(x) REALSTR(x)
#ifdef RELEASE
const char *NSISW_VERSION = STR(RELEASE);
#else
const char *NSISW_VERSION = "Local Build: " __DATE__;
#endif

59
Contrib/NSISdl/ReadMe.txt Normal file
View file

@ -0,0 +1,59 @@
NSIS-DL 1.1 - http downloading DLL for NSIS
Copyright (C) 2001 Yaroslav Faybishenko & Justin Frankel
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
This dll can be used from NSIS to download files via http.
How to use (for another example, see waplugin.nsi in the nsis directory):
Pass the url and filename on the stack
Result is returned in $0
"cancel" if cancelled
"success" if success
otherwise, an error string describing the error
Example:
; pack the dll in the install file
File /oname=$TEMP\nsdtmp09.dll nsisdl.dll
; make the call to download
Push "http://www.xcf.berkeley.edu/~yaroslav/photos/mike/mike1-full.jpg"
Push "$INSTDIR\test.jpg"
CallInstDLL $TEMP\nsdtmp09.dll download ; for a quiet install, use download_quiet
; delete DLL from temporary directory
Delete $TEMP\nsdtmp09.dll
; check if download succeeded
StrCmp $0 "success" successful
StrCmp $0 "cancel" cancelled
; we failed
DetailPrint "Download failed: $0"
goto done
cancelled:
DetailPrint "Download cancelled"
goto done
successful:
DetailPrint "Download successful"
ExecShell $INSTDIR\test.jpg
goto done

78
Contrib/NSISdl/Script1.rc Normal file
View file

@ -0,0 +1,78 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 265, 104
STYLE DS_CONTROL | WS_CHILD
FONT 8, "MS Sans Serif"
BEGIN
CONTROL "Progress1",IDC_PROGRESS1,"msctls_progress32",WS_BORDER,
0,36,265,11
CTEXT "",IDC_STATIC2,0,25,263,8
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View file

@ -0,0 +1,78 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: asyncdns.cpp - JNL portable asynchronous DNS implementation
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
#include "asyncdns.h"
JNL_AsyncDNS::JNL_AsyncDNS(int max_cache_entries)
{
m_thread_kill=1;
m_thread=0;
m_addr=0;
m_hostname[0]=0;
}
JNL_AsyncDNS::~JNL_AsyncDNS()
{
m_thread_kill=1;
if (m_thread)
{
WaitForSingleObject(m_thread,INFINITE);
CloseHandle(m_thread);
}
}
unsigned long WINAPI JNL_AsyncDNS::_threadfunc(LPVOID _d)
{
JNL_AsyncDNS *_this=(JNL_AsyncDNS*)_d;
int nowinsock=JNL::open_socketlib();
struct hostent *hostentry;
hostentry=::gethostbyname(_this->m_hostname);
if (hostentry)
{
_this->m_addr=*((int*)hostentry->h_addr);
}
else
_this->m_addr=INADDR_NONE;
if (!nowinsock) JNL::close_socketlib();
_this->m_thread_kill=1;
return 0;
}
int JNL_AsyncDNS::resolve(char *hostname, unsigned long *addr)
{
// return 0 on success, 1 on wait, -1 on unresolvable
unsigned long ip=inet_addr(hostname);
if (ip != INADDR_NONE)
{
*addr=ip;
return 0;
}
if (lstrcmpi(m_hostname,hostname)) m_addr=0;
else if (m_addr == INADDR_NONE) return -1;
else if (m_addr)
{
*addr=m_addr;
return 0;
}
lstrcpy(m_hostname,hostname);
if (m_thread_kill)
{
DWORD id;
if (m_thread) return -1;
m_thread_kill=0;
m_thread=CreateThread(NULL,0,_threadfunc,(LPVOID)this,0,&id);
if (!m_thread) return -1;
}
return 1;
}

38
Contrib/NSISdl/asyncdns.h Normal file
View file

@ -0,0 +1,38 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: asyncdns.h - JNL portable asynchronous DNS interface
** License: see jnetlib.h
**
** Usage:
** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries.
** 2. call resolve() to resolve a hostname into an address. The return value of
** resolve is 0 on success (host successfully resolved), 1 on wait (meaning
** try calling resolve() with the same hostname in a few hundred milliseconds
** or so), or -1 on error (i.e. the host can't resolve).
** 4. enjoy.
*/
#ifndef _ASYNCDNS_H_
#define _ASYNCDNS_H_
class JNL_AsyncDNS
{
public:
JNL_AsyncDNS(int max_cache_entries=64);
~JNL_AsyncDNS();
int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable
private:
char m_hostname[256];
unsigned long m_addr;
volatile int m_thread_kill;
HANDLE m_thread;
static unsigned long WINAPI _threadfunc(LPVOID _d);
};
#endif //_ASYNCDNS_H_

View file

@ -0,0 +1,447 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: connection.cpp - JNL TCP connection implementation
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
#include "connection.h"
JNL_Connection::JNL_Connection(JNL_AsyncDNS *dns, int sendbufsize, int recvbufsize)
{
m_errorstr="";
if (dns == JNL_CONNECTION_AUTODNS)
{
m_dns=new JNL_AsyncDNS();
m_dns_owned=1;
}
else
{
m_dns=dns;
m_dns_owned=0;
}
m_recv_buffer_len=recvbufsize;
m_send_buffer_len=sendbufsize;
m_recv_buffer=(char*)malloc(m_recv_buffer_len);
m_send_buffer=(char*)malloc(m_send_buffer_len);
m_socket=-1;
memset(m_recv_buffer,0,recvbufsize);
memset(m_send_buffer,0,sendbufsize);
m_remote_port=0;
m_state=STATE_NOCONNECTION;
m_recv_len=m_recv_pos=0;
m_send_len=m_send_pos=0;
m_host[0]=0;
memset(&m_saddr,0,sizeof(m_saddr));
}
void JNL_Connection::connect(int s, struct sockaddr_in *loc)
{
close(1);
m_socket=s;
m_remote_port=0;
m_dns=NULL;
if (loc) m_saddr=*loc;
else memset(&m_saddr,0,sizeof(m_saddr));
if (m_socket != -1)
{
SET_SOCK_BLOCK(m_socket,0);
m_state=STATE_CONNECTED;
}
else
{
m_errorstr="invalid socket passed to connect";
m_state=STATE_ERROR;
}
}
void JNL_Connection::connect(char *hostname, int port)
{
close(1);
m_remote_port=(short)port;
m_socket=::socket(AF_INET,SOCK_STREAM,0);
if (m_socket==-1)
{
m_errorstr="creating socket";
m_state=STATE_ERROR;
}
else
{
SET_SOCK_BLOCK(m_socket,0);
strncpy(m_host,hostname,sizeof(m_host)-1);
m_host[sizeof(m_host)-1]=0;
memset(&m_saddr,0,sizeof(m_saddr));
if (!m_host[0])
{
m_errorstr="empty hostname";
m_state=STATE_ERROR;
}
else
{
m_state=STATE_RESOLVING;
m_saddr.sin_family=AF_INET;
m_saddr.sin_port=htons((unsigned short)port);
m_saddr.sin_addr.s_addr=inet_addr(hostname);
}
}
}
JNL_Connection::~JNL_Connection()
{
if (m_socket >= 0)
{
::shutdown(m_socket, SHUT_RDWR);
::closesocket(m_socket);
m_socket=-1;
}
free(m_recv_buffer);
free(m_send_buffer);
if (m_dns_owned)
{
delete m_dns;
}
}
void JNL_Connection::run(int max_send_bytes, int max_recv_bytes, int *bytes_sent, int *bytes_rcvd)
{
int bytes_allowed_to_send=(max_send_bytes<0)?m_send_buffer_len:max_send_bytes;
int bytes_allowed_to_recv=(max_recv_bytes<0)?m_recv_buffer_len:max_recv_bytes;
if (bytes_sent) *bytes_sent=0;
if (bytes_rcvd) *bytes_rcvd=0;
switch (m_state)
{
case STATE_RESOLVING:
if (m_saddr.sin_addr.s_addr == INADDR_NONE)
{
int a=m_dns?m_dns->resolve(m_host,(unsigned long int *)&m_saddr.sin_addr.s_addr):-1;
if (!a) { m_state=STATE_CONNECTING; }
else if (a == 1)
{
m_state=STATE_RESOLVING;
break;
}
else
{
m_errorstr="resolving hostname";
m_state=STATE_ERROR;
return;
}
}
if (!::connect(m_socket,(struct sockaddr *)&m_saddr,16))
{
m_state=STATE_CONNECTED;
}
else if (ERRNO!=EINPROGRESS)
{
m_errorstr="connecting to host";
m_state=STATE_ERROR;
}
else { m_state=STATE_CONNECTING; }
break;
case STATE_CONNECTING:
{
fd_set f[3];
FD_ZERO(&f[0]);
FD_ZERO(&f[1]);
FD_ZERO(&f[2]);
FD_SET(m_socket,&f[0]);
FD_SET(m_socket,&f[1]);
FD_SET(m_socket,&f[2]);
struct timeval tv;
memset(&tv,0,sizeof(tv));
if (select(m_socket+1,&f[0],&f[1],&f[2],&tv)==-1)
{
m_errorstr="connecting to host (calling select())";
m_state=STATE_ERROR;
}
else if (FD_ISSET(m_socket,&f[1]))
{
m_state=STATE_CONNECTED;
}
else if (FD_ISSET(m_socket,&f[2]))
{
m_errorstr="connecting to host";
m_state=STATE_ERROR;
}
}
break;
case STATE_CONNECTED:
case STATE_CLOSING:
if (m_send_len>0 && bytes_allowed_to_send>0)
{
int len=m_send_buffer_len-m_send_pos;
if (len > m_send_len) len=m_send_len;
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
if (len > 0)
{
int res=::send(m_socket,m_send_buffer+m_send_pos,len,0);
if (res==-1 && ERRNO != EWOULDBLOCK)
{
// m_state=STATE_CLOSED;
// return;
}
if (res>0)
{
bytes_allowed_to_send-=res;
if (bytes_sent) *bytes_sent+=res;
m_send_pos+=res;
m_send_len-=res;
}
}
if (m_send_pos>=m_send_buffer_len)
{
m_send_pos=0;
if (m_send_len>0)
{
len=m_send_buffer_len-m_send_pos;
if (len > m_send_len) len=m_send_len;
if (len > bytes_allowed_to_send) len=bytes_allowed_to_send;
int res=::send(m_socket,m_send_buffer+m_send_pos,len,0);
if (res==-1 && ERRNO != EWOULDBLOCK)
{
// m_state=STATE_CLOSED;
}
if (res>0)
{
bytes_allowed_to_send-=res;
if (bytes_sent) *bytes_sent+=res;
m_send_pos+=res;
m_send_len-=res;
}
}
}
}
if (m_recv_len<m_recv_buffer_len)
{
int len=m_recv_buffer_len-m_recv_pos;
if (len > m_recv_buffer_len-m_recv_len) len=m_recv_buffer_len-m_recv_len;
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
if (len>0)
{
int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0);
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
{
m_state=STATE_CLOSED;
break;
}
if (res > 0)
{
bytes_allowed_to_recv-=res;
if (bytes_rcvd) *bytes_rcvd+=res;
m_recv_pos+=res;
m_recv_len+=res;
}
}
if (m_recv_pos >= m_recv_buffer_len)
{
m_recv_pos=0;
if (m_recv_len < m_recv_buffer_len)
{
len=m_recv_buffer_len-m_recv_len;
if (len > bytes_allowed_to_recv) len=bytes_allowed_to_recv;
if (len > 0)
{
int res=::recv(m_socket,m_recv_buffer+m_recv_pos,len,0);
if (res == 0 || (res < 0 && ERRNO != EWOULDBLOCK))
{
m_state=STATE_CLOSED;
break;
}
if (res > 0)
{
bytes_allowed_to_recv-=res;
if (bytes_rcvd) *bytes_rcvd+=res;
m_recv_pos+=res;
m_recv_len+=res;
}
}
}
}
}
if (m_state == STATE_CLOSING)
{
if (m_send_len < 1) m_state = STATE_CLOSED;
}
break;
default: break;
}
}
void JNL_Connection::close(int quick)
{
if (quick || m_state == STATE_RESOLVING || m_state == STATE_CONNECTING)
{
m_state=STATE_CLOSED;
if (m_socket >= 0)
{
::shutdown(m_socket, SHUT_RDWR);
::closesocket(m_socket);
}
m_socket=-1;
memset(m_recv_buffer,0,m_recv_buffer_len);
memset(m_send_buffer,0,m_send_buffer_len);
m_remote_port=0;
m_recv_len=m_recv_pos=0;
m_send_len=m_send_pos=0;
m_host[0]=0;
memset(&m_saddr,0,sizeof(m_saddr));
}
else
{
if (m_state == STATE_CONNECTED) m_state=STATE_CLOSING;
}
}
int JNL_Connection::send_bytes_in_queue(void)
{
return m_send_len;
}
int JNL_Connection::send_bytes_available(void)
{
return m_send_buffer_len-m_send_len;
}
int JNL_Connection::send(char *data, int length)
{
if (length > send_bytes_available())
{
return -1;
}
int write_pos=m_send_pos+m_send_len;
if (write_pos >= m_send_buffer_len)
{
write_pos-=m_send_buffer_len;
}
int len=m_send_buffer_len-write_pos;
if (len > length)
{
len=length;
}
memcpy(m_send_buffer+write_pos,data,len);
if (length > len)
{
memcpy(m_send_buffer,data+len,length-len);
}
m_send_len+=length;
return 0;
}
int JNL_Connection::send_string(char *line)
{
return send(line,strlen(line));
}
int JNL_Connection::recv_bytes_available(void)
{
return m_recv_len;
}
int JNL_Connection::peek_bytes(char *data, int maxlength)
{
if (maxlength > m_recv_len)
{
maxlength=m_recv_len;
}
int read_pos=m_recv_pos-m_recv_len;
if (read_pos < 0)
{
read_pos += m_recv_buffer_len;
}
int len=m_recv_buffer_len-read_pos;
if (len > maxlength)
{
len=maxlength;
}
memcpy(data,m_recv_buffer+read_pos,len);
if (len < maxlength)
{
memcpy(data+len,m_recv_buffer,maxlength-len);
}
return maxlength;
}
int JNL_Connection::recv_bytes(char *data, int maxlength)
{
int ml=peek_bytes(data,maxlength);
m_recv_len-=ml;
return ml;
}
int JNL_Connection::getbfromrecv(int pos, int remove)
{
int read_pos=m_recv_pos-m_recv_len + pos;
if (pos < 0 || pos > m_recv_len) return -1;
if (read_pos < 0)
{
read_pos += m_recv_buffer_len;
}
if (read_pos >= m_recv_buffer_len)
{
read_pos-=m_recv_buffer_len;
}
if (remove) m_recv_len--;
return m_recv_buffer[read_pos];
}
int JNL_Connection::recv_lines_available(void)
{
int l=recv_bytes_available();
int lcount=0;
int lastch=0;
int pos;
for (pos=0; pos < l; pos ++)
{
int t=getbfromrecv(pos,0);
if (t == -1) return lcount;
if ((t=='\r' || t=='\n') &&(
(lastch != '\r' && lastch != '\n') || lastch==t
)) lcount++;
lastch=t;
}
return lcount;
}
int JNL_Connection::recv_line(char *line, int maxlength)
{
if (maxlength > m_recv_len) maxlength=m_recv_len;
while (maxlength--)
{
int t=getbfromrecv(0,1);
if (t == -1)
{
*line=0;
return 0;
}
if (t == '\r' || t == '\n')
{
int r=getbfromrecv(0,0);
if ((r == '\r' || r == '\n') && r != t) getbfromrecv(0,1);
*line=0;
return 0;
}
*line++=(char)t;
}
return 1;
}
unsigned long JNL_Connection::get_interface(void)
{
if (m_socket==-1) return 0;
struct sockaddr_in sin;
memset(&sin,0,sizeof(sin));
socklen_t len=16;
if (::getsockname(m_socket,(struct sockaddr *)&sin,&len)) return 0;
return (unsigned long) sin.sin_addr.s_addr;
}

135
Contrib/NSISdl/connection.h Normal file
View file

@ -0,0 +1,135 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: connection.h - JNL TCP connection interface
** License: see jnetlib.h
**
** Usage:
** 1. Create a JNL_Connection object, optionally specifying a JNL_AsyncDNS
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
** and the send and receive buffer sizes.
** 2. Call connect() to have it connect to a host/port (the hostname will be
** resolved if possible).
** 3. call run() with the maximum send/recv amounts, and optionally parameters
** so you can tell how much has been send/received. You want to do this a lot, while:
** 4. check get_state() to check the state of the connection. The states are:
** JNL_Connection::STATE_ERROR
** - an error has occured on the connection. the connection has closed,
** and you can no longer write to the socket (there still might be
** data in the receive buffer - use recv_bytes_available()).
** JNL_Connection::STATE_NOCONNECTION
** - no connection has been made yet. call connect() already! :)
** JNL_Connection::STATE_RESOLVING
** - the connection is still waiting for a JNL_AsycnDNS to resolve the
** host.
** JNL_Connection::STATE_CONNECTING
** - the asynchronous call to connect() is still running.
** JNL_Connection::STATE_CONNECTED
** - the connection has connected, all is well.
** JNL_Connection::STATE_CLOSING
** - the connection is closing. This happens after a call to close,
** without the quick parameter set. This means that the connection
** will close once the data in the send buffer is sent (data could
** still be being received when it would be closed). After it is
** closed, the state will transition to:
** JNL_Connection::STATE_CLOSED
** - the connection has closed, generally without error. There still
** might be data in the receieve buffer, use recv_bytes_available().
** 5. Use send() and send_string() to send data. You can use
** send_bytes_in_queue() to see how much has yet to go out, or
** send_bytes_available() to see how much you can write. If you use send()
** or send_string() and not enough room is available, both functions will
** return error ( < 0)
** 6. Use recv() and recv_line() to get data. If you want to see how much data
** there is, use recv_bytes_available() and recv_lines_available(). If you
** call recv() and not enough data is available, recv() will return how much
** data was actually read. See comments at the function defs.
**
** 7. To close, call close(1) for a quick close, or close() for a close that will
** make the socket close after sending all the data sent.
**
** 8. delete ye' ol' object.
*/
#ifndef _CONNECTION_H_
#define _CONNECTION_H_
#include "asyncdns.h"
#define JNL_CONNECTION_AUTODNS ((JNL_AsyncDNS*)-1)
class JNL_Connection
{
public:
typedef enum
{
STATE_ERROR,
STATE_NOCONNECTION,
STATE_RESOLVING,
STATE_CONNECTING,
STATE_CONNECTED,
STATE_CLOSING,
STATE_CLOSED
} state;
JNL_Connection(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int sendbufsize=8192, int recvbufsize=8192);
~JNL_Connection();
void connect(char *hostname, int port);
void connect(int sock, struct sockaddr_in *loc=NULL); // used by the listen object, usually not needed by users.
void run(int max_send_bytes=-1, int max_recv_bytes=-1, int *bytes_sent=NULL, int *bytes_rcvd=NULL);
int get_state() { return m_state; }
char *get_errstr() { return m_errorstr; }
void close(int quick=0);
void flush_send(void) { m_send_len=m_send_pos=0; }
int send_bytes_in_queue(void);
int send_bytes_available(void);
int send(char *data, int length); // returns -1 if not enough room
int send_string(char *line); // returns -1 if not enough room
int recv_bytes_available(void);
int recv_bytes(char *data, int maxlength); // returns actual bytes read
unsigned int recv_int(void);
int recv_lines_available(void);
int recv_line(char *line, int maxlength); // returns 0 if the line was terminated with a \r or \n, 1 if not.
// (i.e. if you specify maxlength=10, and the line is 12 bytes long
// it will return 1. or if there is no \r or \n and that's all the data
// the connection has.)
int peek_bytes(char *data, int maxlength); // returns bytes peeked
unsigned long get_interface(void); // this returns the interface the connection is on
unsigned long get_remote(void) { return m_saddr.sin_addr.s_addr; } // remote host ip.
short get_remote_port(void) { return m_remote_port; } // this returns the remote port of connection
protected:
int m_socket;
short m_remote_port;
char *m_recv_buffer;
char *m_send_buffer;
int m_recv_buffer_len;
int m_send_buffer_len;
int m_recv_pos;
int m_recv_len;
int m_send_pos;
int m_send_len;
struct sockaddr_in m_saddr;
char m_host[256];
JNL_AsyncDNS *m_dns;
int m_dns_owned;
state m_state;
char *m_errorstr;
int getbfromrecv(int pos, int remove); // used by recv_line*
};
#endif // _Connection_H_

471
Contrib/NSISdl/httpget.cpp Normal file
View file

@ -0,0 +1,471 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: httpget.cpp - JNL HTTP GET implementation
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
#include "httpget.h"
JNL_HTTPGet::JNL_HTTPGet(JNL_AsyncDNS *dns, int recvbufsize, char *proxy)
{
m_recvbufsize=recvbufsize;
m_dns=dns;
m_con=NULL;
m_http_proxylpinfo=0;
m_http_proxyhost=0;
m_http_proxyport=0;
if (proxy && *proxy)
{
char *p=(char*)malloc(strlen(proxy)+1);
if (p)
{
char *r=NULL;
strcpy(p,proxy);
do_parse_url(p,&m_http_proxyhost,&m_http_proxyport,&r,&m_http_proxylpinfo);
free(r);
free(p);
}
}
m_sendheaders=NULL;
reinit();
}
void JNL_HTTPGet::reinit()
{
m_errstr=0;
m_recvheaders=NULL;
m_recvheaders_size=0;
m_http_state=0;
m_http_port=0;
m_http_url=0;
m_reply=0;
m_http_host=m_http_lpinfo=m_http_request=NULL;
}
void JNL_HTTPGet::deinit()
{
delete m_con;
free(m_recvheaders);
free(m_http_url);
free(m_http_host);
free(m_http_lpinfo);
free(m_http_request);
free(m_errstr);
free(m_reply);
reinit();
}
JNL_HTTPGet::~JNL_HTTPGet()
{
deinit();
free(m_sendheaders);
free(m_http_proxylpinfo);
free(m_http_proxyhost);
}
void JNL_HTTPGet::addheader(char *header)
{
//if (strstr(header,"\r") || strstr(header,"\n")) return;
if (!m_sendheaders)
{
m_sendheaders=(char*)malloc(strlen(header)+3);
if (m_sendheaders)
{
strcpy(m_sendheaders,header);
strcat(m_sendheaders,"\r\n");
}
}
else
{
char *t=(char*)malloc(strlen(header)+strlen(m_sendheaders)+1+2);
if (t)
{
strcpy(t,m_sendheaders);
strcat(t,header);
strcat(t,"\r\n");
free(m_sendheaders);
m_sendheaders=t;
}
}
}
void JNL_HTTPGet::do_encode_mimestr(char *in, char *out)
{
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int shift = 0;
int accum = 0;
while (*in)
{
if (*in)
{
accum <<= 8;
shift += 8;
accum |= *in++;
}
while ( shift >= 6 )
{
shift -= 6;
*out++ = alphabet[(accum >> shift) & 0x3F];
}
}
if (shift == 4)
{
*out++ = alphabet[(accum & 0xF)<<2];
*out++='=';
}
else if (shift == 2)
{
*out++ = alphabet[(accum & 0x3)<<4];
*out++='=';
*out++='=';
}
*out++=0;
}
void JNL_HTTPGet::connect(char *url)
{
deinit();
m_http_url=(char*)malloc(strlen(url)+1);
strcpy(m_http_url,url);
do_parse_url(m_http_url,&m_http_host,&m_http_port,&m_http_request, &m_http_lpinfo);
strcpy(m_http_url,url);
if (!m_http_host || !m_http_host[0] || !m_http_port)
{
m_http_state=-1;
seterrstr("invalid URL");
return;
}
int sendbufferlen=0;
if (!m_http_proxyhost || !m_http_proxyhost[0])
{
sendbufferlen += 4 /* GET */ + strlen(m_http_request) + 9 /* HTTP/1.0 */ + 2;
}
else
{
sendbufferlen += 4 /* GET */ + strlen(m_http_url) + 9 /* HTTP/1.0 */ + 2;
if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
{
sendbufferlen+=58+strlen(m_http_proxylpinfo)*2; // being safe here
}
}
sendbufferlen += 5 /* Host: */ + strlen(m_http_host) + 2;
if (m_http_lpinfo&&m_http_lpinfo[0])
{
sendbufferlen+=46+strlen(m_http_lpinfo)*2; // being safe here
}
if (m_sendheaders) sendbufferlen+=strlen(m_sendheaders);
char *str=(char*)malloc(sendbufferlen+1024);
if (!str)
{
seterrstr("error allocating memory");
m_http_state=-1;
}
if (!m_http_proxyhost || !m_http_proxyhost[0])
{
wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_request);
}
else
{
wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_url);
}
wsprintf(str+strlen(str),"Host:%s\r\n",m_http_host);
if (m_http_lpinfo&&m_http_lpinfo[0])
{
strcat(str,"Authorization: Basic ");
do_encode_mimestr(m_http_lpinfo,str+strlen(str));
strcat(str,"\r\n");
}
if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
{
strcat(str,"Proxy-Authorization: Basic ");
do_encode_mimestr(m_http_proxylpinfo,str+strlen(str));
strcat(str,"\r\n");
}
if (m_sendheaders) strcat(str,m_sendheaders);
strcat(str,"\r\n");
int a=m_recvbufsize;
if (a < 4096) a=4096;
m_con=new JNL_Connection(m_dns,strlen(str)+4,a);
if (m_con)
{
if (!m_http_proxyhost || !m_http_proxyhost[0])
{
m_con->connect(m_http_host,m_http_port);
}
else
{
m_con->connect(m_http_proxyhost,m_http_proxyport);
}
m_con->send_string(str);
}
else
{
m_http_state=-1;
seterrstr("could not create connection object");
}
free(str);
}
static int _strnicmp(char *b1, char *b2, int l)
{
while (l-- && *b1 && *b2)
{
char bb1=*b1++;
char bb2=*b2++;
if (bb1>='a' && bb1 <= 'z') bb1+='A'-'a';
if (bb2>='a' && bb2 <= 'z') bb2+='A'-'a';
if (bb1 != bb2) return bb1-bb2;
}
return 0;
}
char *_strstr(char *i, char *s)
{
if (strlen(i)>=strlen(s)) while (i[strlen(s)-1])
{
int l=strlen(s)+1;
char *ii=i;
char *is=s;
while (--l>0)
{
if (*ii != *is) break;
ii++;
is++;
}
if (l==0) return i;
i++;
}
return NULL;
}
#define strstr _strstr
void JNL_HTTPGet::do_parse_url(char *url, char **host, int *port, char **req, char **lp)
{
char *p,*np;
free(*host); *host=0;
free(*req); *req=0;
free(*lp); *lp=0;
if (strstr(url,"://")) np=p=strstr(url,"://")+3;
else np=p=url;
while (*np != '/' && *np) np++;
if (*np)
{
*req=(char*)malloc(strlen(np)+1);
if (*req) strcpy(*req,np);
*np++=0;
}
else
{
*req=(char*)malloc(2);
if (*req) strcpy(*req,"/");
}
np=p;
while (*np != '@' && *np) np++;
if (*np)
{
*np++=0;
*lp=(char*)malloc(strlen(p)+1);
if (*lp) strcpy(*lp,p);
p=np;
}
else
{
*lp=(char*)malloc(1);
if (*lp) strcpy(*lp,"");
}
np=p;
while (*np != ':' && *np) np++;
if (*np)
{
*np++=0;
*port=my_atoi(np);
} else *port=80;
*host=(char*)malloc(strlen(p)+1);
if (*host) strcpy(*host,p);
}
char *JNL_HTTPGet::getallheaders()
{ // double null terminated, null delimited list
if (m_recvheaders) return m_recvheaders;
else return "\0\0";
}
char *JNL_HTTPGet::getheader(char *headername)
{
char *ret=NULL;
if (strlen(headername)<1||!m_recvheaders) return NULL;
char *p=m_recvheaders;
while (*p)
{
if (!_strnicmp(headername,p,strlen(headername)))
{
ret=p+strlen(headername);
while (*ret == ' ') ret++;
break;
}
p+=strlen(p)+1;
}
return ret;
}
int JNL_HTTPGet::run()
{
int cnt=0;
if (m_http_state==-1||!m_con) return -1; // error
run_again:
static char buf[4096];
m_con->run();
if (m_con->get_state()==JNL_Connection::STATE_ERROR)
{
seterrstr(m_con->get_errstr());
return -1;
}
if (m_con->get_state()==JNL_Connection::STATE_CLOSED) return 1;
if (m_http_state==0) // connected, waiting for reply
{
if (m_con->recv_lines_available()>0)
{
m_con->recv_line(buf,4095);
buf[4095]=0;
m_reply=(char*)malloc(strlen(buf)+1);
strcpy(m_reply,buf);
if (strstr(buf,"200")) m_http_state=2; // proceed to read headers normally
else if (strstr(buf,"301") || strstr(buf,"302"))
{
m_http_state=1; // redirect city
}
else
{
seterrstr(buf);
m_http_state=-1;
return -1;
}
cnt=0;
}
else if (!cnt++) goto run_again;
}
if (m_http_state == 1) // redirect
{
while (m_con->recv_lines_available() > 0)
{
m_con->recv_line(buf,4096);
if (!buf[0])
{
m_http_state=-1;
return -1;
}
if (!_strnicmp(buf,"Location:",9))
{
char *p=buf+9; while (*p== ' ') p++;
if (*p)
{
connect(p);
return 0;
}
}
}
}
if (m_http_state==2)
{
if (!cnt++ && m_con->recv_lines_available() < 1) goto run_again;
while (m_con->recv_lines_available() > 0)
{
m_con->recv_line(buf,4096);
if (!buf[0]) { m_http_state=3; break; }
if (!m_recvheaders)
{
m_recvheaders_size=strlen(buf)+1;
m_recvheaders=(char*)malloc(m_recvheaders_size+1);
if (m_recvheaders)
{
strcpy(m_recvheaders,buf);
m_recvheaders[m_recvheaders_size]=0;
}
}
else
{
int oldsize=m_recvheaders_size;
m_recvheaders_size+=strlen(buf)+1;
char *n=(char*)malloc(m_recvheaders_size+1);
if (n)
{
memcpy(n,m_recvheaders,oldsize);
strcpy(n+oldsize,buf);
n[m_recvheaders_size]=0;
free(m_recvheaders);
m_recvheaders=n;
}
}
}
}
if (m_http_state==3)
{
}
return 0;
}
int JNL_HTTPGet::get_status() // returns 0 if connecting, 1 if reading headers,
// 2 if reading content, -1 if error.
{
if (m_http_state < 0) return -1;
if (m_http_state < 2) return 0;
if (m_http_state == 2) return 1;
if (m_http_state == 3) return 2;
return -1;
}
int JNL_HTTPGet::getreplycode()// returns 0 if none yet, otherwise returns http reply code.
{
if (!m_reply) return 0;
char *p=m_reply;
while (*p && *p != ' ') p++; // skip over HTTP/x.x
if (!*p) return 0;
return my_atoi(++p);
}
int JNL_HTTPGet::bytes_available()
{
if (m_con && m_http_state==3) return m_con->recv_bytes_available();
return 0;
}
int JNL_HTTPGet::get_bytes(char *buf, int len)
{
if (m_con && m_http_state==3) return m_con->recv_bytes(buf,len);
return 0;
}
int JNL_HTTPGet::peek_bytes(char *buf, int len)
{
if (m_con && m_http_state==3) return m_con->peek_bytes(buf,len);
return 0;
}

109
Contrib/NSISdl/httpget.h Normal file
View file

@ -0,0 +1,109 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: httpget.h - JNL interface for doing HTTP GETs.
** License: see jnetlib.h
**
** Usage:
** 1. Create a JNL_HTTPGet object, optionally specifying a JNL_AsyncDNS
** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
** and the receive buffer size, and a string specifying proxy (or NULL
** for none). See note on proxy string below.
** 2. call addheader() to add whatever headers you want. It is recommended to
** add at least the following two:
** addheader("User-Agent:MyApp (Mozilla)");
*/// addheader("Accept:*/*");
/* ( the comment weirdness is there so I Can do the star-slash :)
** 3. Call connect() with the URL you wish to GET (see URL string note below)
** 4. Call run() once in a while, checking to see if it returns -1
** (if it does return -1, call geterrorstr() to see what the error is).
** (if it returns 1, no big deal, the connection has closed).
** 5. While you're at it, you can call bytes_available() to see if any data
** from the http stream is available, or getheader() to see if any headers
** are available, or getreply() to see the HTTP reply, or getallheaders()
** to get a double null terminated, null delimited list of headers returned.
** 6. If you want to read from the stream, call get_bytes (which returns how much
** was actually read).
** 7. content_length() is a helper function that uses getheader() to check the
** content-length header.
** 8. Delete ye' ol' object when done.
**
** Proxy String:
** should be in the format of host:port, or user@host:port, or
** user:password@host:port. if port is not specified, 80 is assumed.
** URL String:
** should be in the format of http://user:pass@host:port/requestwhatever
** note that user, pass, port, and /requestwhatever are all optional :)
** note that also, http:// is really not important. if you do poo://
** or even leave out the http:// altogether, it will still work.
*/
#ifndef _HTTPGET_H_
#define _HTTPGET_H_
#include "connection.h"
class JNL_HTTPGet
{
public:
JNL_HTTPGet(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int recvbufsize=16384, char *proxy=NULL);
~JNL_HTTPGet();
void addheader(char *header);
void connect(char *url);
int run(); // returns: 0 if all is OK. -1 if error (call geterrorstr()). 1 if connection closed.
int get_status(); // returns 0 if connecting, 1 if reading headers,
// 2 if reading content, -1 if error.
char *getallheaders(); // double null terminated, null delimited list
char *getheader(char *headername);
char *getreply() { return m_reply; }
int getreplycode(); // returns 0 if none yet, otherwise returns http reply code.
char *geterrorstr() { return m_errstr;}
int bytes_available();
int get_bytes(char *buf, int len);
int peek_bytes(char *buf, int len);
int content_length() { char *p=getheader("content-length:"); if (p) return my_atoi(p); return 0; }
JNL_Connection *get_con() { return m_con; }
public:
void reinit();
void deinit();
void seterrstr(char *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); }
void do_parse_url(char *url, char **host, int *port, char **req, char **lp);
void do_encode_mimestr(char *in, char *out);
JNL_AsyncDNS *m_dns;
JNL_Connection *m_con;
int m_recvbufsize;
int m_http_state;
int m_http_port;
char *m_http_url;
char *m_http_host;
char *m_http_lpinfo;
char *m_http_request;
char *m_http_proxylpinfo;
char *m_http_proxyhost;
int m_http_proxyport;
char *m_sendheaders;
char *m_recvheaders;
int m_recvheaders_size;
char *m_reply;
char *m_errstr;
};
#endif // _HTTPGET_H_

82
Contrib/NSISdl/netinc.h Normal file
View file

@ -0,0 +1,82 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: netinc.h - network includes and portability defines (used internally)
** License: see jnetlib.h
*/
#ifndef _NETINC_H_
#define _NETINC_H_
#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
#include <time.h>
#define strcasecmp(x,y) stricmp(x,y)
#define ERRNO (WSAGetLastError())
#define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); }
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEWOULDBLOCK
typedef int socklen_t;
#else
#ifndef THREAD_SAFE
#define THREAD_SAFE
#endif
#ifndef _REENTRANT
#define _REENTRANT
#endif
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define ERRNO errno
#define closesocket(s) close(s)
#define SET_SOCK_BLOCK(s,block) { int __flags; if ((__flags = fcntl(s, F_GETFL, 0)) != -1) { if (!block) __flags |= O_NONBLOCK; else __flags &= ~O_NONBLOCK; fcntl(s, F_SETFL, __flags); } }
#define stricmp(x,y) strcasecmp(x,y)
#define strnicmp(x,y,z) strncasecmp(x,y,z)
#define wsprintf sprintf
#endif // !_WIN32
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
#ifndef INADDR_ANY
#define INADDR_ANY 0
#endif
#ifndef SHUT_RDWR
#define SHUT_RDWR 2
#endif
extern void mini_memset(void *,char,int);
extern void mini_memcpy(void *,void*,int);
#define memset mini_memset
#define memcpy mini_memcpy
#define strcpy lstrcpy
#define strncpy lstrcpyn
#define strcat lstrcat
#define strlen lstrlen
#define malloc(x) GlobalAlloc(GPTR,(x))
#define free(x) { if (x) GlobalFree(x); }
#endif //_NETINC_H_

448
Contrib/NSISdl/nsisdl.cpp Normal file
View file

@ -0,0 +1,448 @@
/*
NSIS-DL 1.1 - http downloading DLL for NSIS
Copyright (C) 2001 Yaroslav Faybishenko & Justin Frankel
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Note: this source code is pretty hacked together right now, improvements
and cleanups will come later.
*/
#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
#include "netinc.h"
#include "util.h"
#include "resource.h"
#include "httpget.h"
void *operator new( unsigned int num_bytes )
{
return GlobalAlloc(GPTR,num_bytes);
}
void operator delete( void *p ) { if (p) GlobalFree(p); }
typedef struct _stack_t {
struct _stack_t *next;
char text[1]; // this should be the length of string_size
} stack_t;
static int popstring(char *str); // 0 on success, 1 on empty stack
static void setuservariable(int varnum, char *var);
enum
{
INST_0, // $0
INST_1, // $1
INST_2, // $2
INST_3, // $3
INST_4, // $4
INST_5, // $5
INST_6, // $6
INST_7, // $7
INST_8, // $8
INST_9, // $9
INST_R0, // $R0
INST_R1, // $R1
INST_R2, // $R2
INST_R3, // $R3
INST_R4, // $R4
INST_R5, // $R5
INST_R6, // $R6
INST_R7, // $R7
INST_R8, // $R8
INST_R9, // $R9
INST_CMDLINE, // $CMDLINE
INST_INSTDIR, // $INSTDIR
INST_OUTDIR, // $OUTDIR
INST_EXEDIR, // $EXEDIR
__INST_LAST
};
HANDLE hModule;
HWND g_parent;
HWND g_dialog;
HWND g_childwnd;
int g_stringsize;
stack_t **g_stacktop;
char *g_variables;
static int g_cancelled;
BOOL CALLBACK DownloadDialogProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
return 0;
}
static void *lpWndProcOld;
static LRESULT CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_COMMAND && LOWORD(wParam) == IDCANCEL)
{
g_cancelled = 1;
return 0;
}
return CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam);
}
BOOL APIENTRY DllMain( HANDLE _hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
hModule = _hModule;
JNL::open_socketlib ();
break;
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
JNL::close_socketlib ();
break;
}
return TRUE;
}
static int g_file_size;
static void progress_callback(char *msg, int read_bytes)
{
if (g_dialog)
{
HWND hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
SetDlgItemText (g_dialog, IDC_STATIC2, msg);
if (g_file_size) SendMessage(hwndProgressBar, PBM_SETPOS, (WPARAM)MulDiv(read_bytes,30000,g_file_size), 0);
}
}
static int getProxyInfo(char *out)
{
DWORD v=0;
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",0,KEY_READ,&hKey) == ERROR_SUCCESS)
{
DWORD l = 4;
DWORD t;
if (RegQueryValueEx(hKey,"ProxyEnable",NULL,&t,(unsigned char *)&v,&l) == ERROR_SUCCESS && t == REG_DWORD)
{
l=8192;
if (RegQueryValueEx(hKey,"ProxyServer",NULL,&t,(unsigned char *)out,&l ) != ERROR_SUCCESS || t != REG_SZ)
{
v=0;
*out=0;
}
}
else v=0;
out[8192-1]=0;
RegCloseKey(hKey);
}
return v;
}
extern char *_strstr(char *i, char *s);
static
void downloadFile(char *url,
HANDLE hFile,
char **error)
{
static char buf[8192];
char *p=NULL;
if (getProxyInfo(buf))
{
p=_strstr(buf,"http=");
if (!p) p=buf;
else
{
p+=5;
char *tp=_strstr(p,";");
if (tp) *tp=0;
}
}
DWORD start_time=GetTickCount();
JNL_HTTPGet *get=new JNL_HTTPGet(JNL_CONNECTION_AUTODNS,16384,(p&&p[0])?p:NULL);
int st;
int has_printed_headers = 0;
int cl;
int len;
int sofar = 0;
get->addheader ("User-Agent: NSISDL/1.1 (Mozilla)");
get->addheader ("Accept: */*");
get->connect (url);
while (1) {
if (g_dialog)
{
MSG msg;
while (PeekMessage(&msg,g_dialog,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Sleep(25);
if (g_cancelled) break;
st = get->run ();
if (st == -1) {
*error=get->geterrorstr();
break;
} else if (st == 1) {
if (sofar < cl)
*error="download incomplete";
break;
} else {
if (get->get_status () == 0) {
// progressFunc ("Connecting ...", 0);
} else if (get->get_status () == 1) {
progress_callback("Reading headers", 0);
} else if (get->get_status () == 2) {
if (! has_printed_headers) {
has_printed_headers = 1;
cl = get->content_length ();
if (cl == 0) {
*error = "Server did not specify content length.";
break;
} else if (g_dialog) {
HWND hwndProgressBar = GetDlgItem (g_dialog, IDC_PROGRESS1);
SendMessage(hwndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,30000));
g_file_size=cl;
}
}
while ((len = get->bytes_available ()) > 0) {
if (len > 8192)
len = 8192;
len = get->get_bytes (buf, len);
if (len > 0) {
DWORD dw;
WriteFile(hFile,buf,len,&dw,NULL);
sofar += len;
int time_sofar=(GetTickCount()-start_time)/1000;
int bps=sofar/(time_sofar?time_sofar:1);
int remain=MulDiv(time_sofar,cl,sofar) - time_sofar;
char *rtext="second";
if (remain >= 60)
{
remain/=60;
rtext="minute";
if (remain >= 60)
{
remain/=60;
rtext="hour";
}
}
wsprintf (buf,
"%dkB (%d%%) of %dkB @ %d.%01dkB/s",
sofar/1024,
MulDiv(100,sofar,cl),
cl/1024,
bps/1024,((bps*10)/1024)%10
);
if (remain) wsprintf(buf+lstrlen(buf)," (%d %s%s remaining)",
remain,
rtext,
remain==1?"":"s"
);
progress_callback(buf, sofar);
} else {
if (sofar < cl)
*error = "Server aborted.";
break;
}
}
} else {
*error = "Bad response status.";
break;
}
}
}
if (*error)
{
char *t=*error;
*error = (char *)GlobalAlloc(GPTR,strlen(t)+1);
lstrcpy(*error,t);
}
delete get;
}
extern "C"
{
__declspec(dllexport) void download (HWND parent,
int stringsize,
char *variables,
stack_t **stacktop)
{
static char buf[1024];
static char url[1024];
static char filename[1024];
int wasen=0;
HWND hwndL=0;
HWND hwndB=0;
g_parent = parent;
g_stringsize = stringsize;
g_variables = variables;
g_stacktop = stacktop;
popstring (filename);
popstring (url);
HANDLE hFile = CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
if (hFile == INVALID_HANDLE_VALUE) {
wsprintf (buf, "Unable to open %s", filename);
setuservariable(INST_0, buf);
} else {
if (g_parent)
{
g_childwnd=FindWindowEx(g_parent,NULL,"#32770",NULL);
hwndL=GetDlgItem(g_childwnd,1016);
hwndB=GetDlgItem(g_childwnd,1027);
if (hwndL && IsWindowVisible(hwndL)) ShowWindow(hwndL,SW_HIDE);
else hwndL=NULL;
if (hwndB && IsWindowVisible(hwndB)) ShowWindow(hwndB,SW_HIDE);
else hwndB=NULL;
wasen=EnableWindow(GetDlgItem(g_parent,IDCANCEL),1);
lpWndProcOld = (void *) GetWindowLong(g_parent,GWL_WNDPROC);
SetWindowLong(g_parent,GWL_WNDPROC,(long)ParentWndProc);
g_dialog = CreateDialog((HINSTANCE)hModule,
MAKEINTRESOURCE(IDD_DIALOG1),
g_childwnd,
DownloadDialogProc);
if (g_dialog)
{
RECT r;
GetWindowRect(GetDlgItem(g_childwnd,1016),&r);
ScreenToClient(g_childwnd,(LPPOINT)&r);
SetWindowPos(g_dialog,0,r.left,r.top,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
ShowWindow(g_dialog,SW_SHOWNA);
char *p=filename;
while (*p) p++;
while (*p != '\\' && p != filename) p=CharPrev(filename,p);
wsprintf(buf,"Downloading %s", p+1);
SetDlgItemText(g_childwnd,1006,buf);
wsprintf(buf,"Connecting ...");
SetDlgItemText (g_dialog, IDC_STATIC2, buf);
}
}
char *error=NULL;
downloadFile(url, hFile, &error);
CloseHandle(hFile);
if (g_parent)
{
if (g_dialog) DestroyWindow(g_dialog);
if (lpWndProcOld)
SetWindowLong(g_parent,GWL_WNDPROC,(long)lpWndProcOld);
if (g_childwnd)
{
if (hwndB) ShowWindow(hwndB,SW_SHOWNA);
if (hwndL) ShowWindow(hwndL,SW_SHOWNA);
}
if (wasen) EnableWindow(GetDlgItem(g_parent,IDCANCEL),0);
}
if (g_cancelled) {
setuservariable(INST_0, "cancel");
DeleteFile(filename);
} else if (error == NULL) {
setuservariable(INST_0, "success");
} else {
DeleteFile(filename);
setuservariable(INST_0, error);
}
if (error) GlobalFree(error);
}
}
__declspec(dllexport) void download_quiet(HWND parent,
int stringsize,
char *variables,
stack_t **stacktop)
{
download(NULL,stringsize,variables,stacktop);
}
}
// utility functions (not required but often useful)
static
int popstring(char *str)
{
stack_t *th;
if (!g_stacktop || !*g_stacktop) return 1;
th=(*g_stacktop);
lstrcpy(str,th->text);
*g_stacktop = th->next;
GlobalFree((HGLOBAL)th);
return 0;
}
static
void setuservariable(int varnum, char *var)
{
if (var != NULL && varnum >= 0 && varnum < __INST_LAST) {
lstrcpy (g_variables + varnum*g_stringsize, var);
}
}

152
Contrib/NSISdl/nsisdl.dsp Normal file
View file

@ -0,0 +1,152 @@
# Microsoft Developer Studio Project File - Name="nsisdl" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=nsisdl - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "nsisdl.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "nsisdl.mak" CFG="nsisdl - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "nsisdl - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "nsisdl - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "nsisdl - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NSISDL_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NSISDL_EXPORTS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /entry:"DllMain" /dll /machine:I386 /nodefaultlib /out:"../../nsisdl.dll" /opt:nowin98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "nsisdl - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NSISDL_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NSISDL_EXPORTS" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "nsisdl - Win32 Release"
# Name "nsisdl - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asyncdns.cpp
# End Source File
# Begin Source File
SOURCE=.\connection.cpp
# End Source File
# Begin Source File
SOURCE=.\httpget.cpp
# End Source File
# Begin Source File
SOURCE=.\nsisdl.cpp
# End Source File
# Begin Source File
SOURCE=.\Script1.rc
# End Source File
# Begin Source File
SOURCE=.\util.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asyncdns.h
# End Source File
# Begin Source File
SOURCE=.\connection.h
# End Source File
# Begin Source File
SOURCE=.\httpget.h
# End Source File
# Begin Source File
SOURCE=.\netinc.h
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# Begin Source File
SOURCE=.\util.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

29
Contrib/NSISdl/nsisdl.dsw Normal file
View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "nsisdl"=.\nsisdl.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

19
Contrib/NSISdl/resource.h Normal file
View file

@ -0,0 +1,19 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define IDD_DIALOG1 101
#define IDC_PROGRESS1 1001
#define IDC_STATIC1 1002
#define IDC_STATIC2 1003
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1004
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

64
Contrib/NSISdl/util.cpp Normal file
View file

@ -0,0 +1,64 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: util.cpp - JNL implementation of basic network utilities
** License: see jnetlib.h
*/
#include "netinc.h"
#include "util.h"
int JNL::open_socketlib()
{
#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData)) return 1;
#endif
return 0;
}
void JNL::close_socketlib()
{
#ifdef _WIN32
WSACleanup();
#endif
}
unsigned long JNL::ipstr_to_addr(const char *cp)
{
return ::inet_addr(cp);
}
void JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen)
{
struct in_addr a; a.s_addr=addr;
char *p=::inet_ntoa(a); strncpy(host,p?p:"",maxhostlen);
}
int my_atoi(char *s)
{
int sign=0;
int v=0;
if (*s == '-') { s++; sign++; }
for (;;)
{
int c=*s++ - '0';
if (c < 0 || c > 9) break;
v*=10;
v+=c;
}
if (sign) return -(int) v;
return (int)v;
}
void mini_memset(void *o,char i,int l)
{
char *oo=(char*)o;
while (l-- > 0) *oo++=i;
}
void mini_memcpy(void *o,void*i,int l)
{
char *oo=(char*)o;
char *ii=(char*)i;
while (l-- > 0) *oo++=*ii++;
}

41
Contrib/NSISdl/util.h Normal file
View file

@ -0,0 +1,41 @@
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: util.h - JNL interface for basic network utilities
** License: see jnetlib.h
**
** routines you may be interested in:
** JNL::open_socketlib();
** opens the socket library. Call this once before using any network
** code. If you create a new thread, call this again. Only really an
** issue for Win32 support, but use it anyway for portability/
**
** JNL::close_Socketlib();
** closes the socketlib. Call this when you're done with the network,
** after all your JNetLib objects have been destroyed.
**
** unsigned long JNL::ipstr_to_addr(const char *cp);
** gives you the integer representation of a ip address in dotted
** decimal form.
**
** JNL::addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
** gives you the dotted decimal notation of an integer ip address.
**
*/
#ifndef _UTIL_H_
#define _UTIL_H_
class JNL
{
public:
static int open_socketlib();
static void close_socketlib();
static unsigned long ipstr_to_addr(const char *cp);
static void addr_to_ipstr(unsigned long addr, char *host, int maxhostlen);
};
int my_atoi(char *p);
#endif //_UTIL_H_

137
Contrib/Splash/splash.c Normal file
View file

@ -0,0 +1,137 @@
#include <windows.h>
HBITMAP g_hbm;
int sleep_val;
int g_rv;
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CREATE)
{
BITMAP bm;
RECT vp;
GetObject(g_hbm, sizeof(bm), (LPSTR)&bm);
SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0);
SetWindowLong(hwnd,GWL_STYLE,0);
SetWindowPos(hwnd,NULL,
vp.left+(vp.right-vp.left-bm.bmWidth)/2,
vp.top+(vp.bottom-vp.top-bm.bmHeight)/2,
bm.bmWidth,bm.bmHeight,
SWP_NOZORDER);
ShowWindow(hwnd,SW_SHOW);
SetTimer(hwnd,1,sleep_val,NULL);
return 0;
}
if (uMsg == WM_PAINT)
{
PAINTSTRUCT ps;
RECT r;
HDC curdc=BeginPaint(hwnd,&ps);
HDC hdc=CreateCompatibleDC(curdc);
HBITMAP oldbm;
GetClientRect(hwnd,&r);
oldbm=(HBITMAP)SelectObject(hdc,g_hbm);
BitBlt(curdc,r.left,r.top,r.right-r.left,r.bottom-r.top,hdc,0,0,SRCCOPY);
SelectObject(hdc,oldbm);
DeleteDC(hdc);
EndPaint(hwnd,&ps);
return 0;
}
if (uMsg == WM_CLOSE) return 0;
if (uMsg == WM_DESTROY)
{
PostQuitMessage(0);
return 0;
}
if (uMsg == WM_TIMER || uMsg == WM_LBUTTONDOWN)
{
g_rv=(uMsg == WM_LBUTTONDOWN);
DestroyWindow(hwnd);
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpszCmdParam, int nCmdShow)
{
char fn[MAX_PATH];
int hwndParent;
char *o=fn;
hInstance=GetModuleHandle(NULL);
lpszCmdParam=GetCommandLine();
if (*lpszCmdParam == '\"')
{
do
{
lpszCmdParam++;
} while (*lpszCmdParam != '\"' && *lpszCmdParam);
if (*lpszCmdParam) lpszCmdParam++;
}
else
{
do
{
lpszCmdParam++;
} while (*lpszCmdParam != ' ' && *lpszCmdParam);
}
while (*lpszCmdParam == ' ') lpszCmdParam++;
sleep_val=0;
while (*lpszCmdParam >= '0' && *lpszCmdParam <= '9')
{
sleep_val*=10;
sleep_val += *lpszCmdParam++-'0';
}
while (*lpszCmdParam == ' ') lpszCmdParam++;
hwndParent=0;
while (*lpszCmdParam >= '0' && *lpszCmdParam <= '9')
{
hwndParent*=10;
hwndParent += *lpszCmdParam++-'0';
}
while (*lpszCmdParam == ' ') lpszCmdParam++;
while (*lpszCmdParam)
{
*o++=*lpszCmdParam++;
}
*o=0;
if (fn[0] && sleep_val>0)
{
MSG msg;
char classname[4]="_sp";
static WNDCLASS wc;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.lpszClassName = classname;
if (RegisterClass(&wc))
{
char fn2[MAX_PATH];
lstrcpy(fn2,fn);
lstrcat(fn,".bmp");
lstrcat(fn2,".wav");
g_hbm=LoadImage(NULL,fn,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
if (g_hbm)
{
BOOL s=0;
HANDLE f=CreateFile(fn2,0,0,NULL,OPEN_EXISTING,0,NULL);
if (f != INVALID_HANDLE_VALUE) { CloseHandle(f); s=PlaySound(fn2,NULL,SND_ASYNC|SND_FILENAME); }
CreateWindowEx(WS_EX_TOOLWINDOW,classname,classname,
0,0,0,0,0,(HWND)hwndParent,NULL,hInstance,NULL);
while (GetMessage(&msg,NULL,0,0))
{
DispatchMessage(&msg);
}
if (s) PlaySound(NULL,0,0);
DeleteObject(g_hbm);
}
}
}
ExitProcess(g_rv);
}

108
Contrib/Splash/splash.dsp Normal file
View file

@ -0,0 +1,108 @@
# Microsoft Developer Studio Project File - Name="splash" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=splash - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "splash.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "splash.mak" CFG="splash - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "splash - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "splash - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "splash - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /Og /Os /Oy /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FD /c
# SUBTRACT CPP /Ox /Ow /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib winmm.lib /nologo /entry:"WinMain" /subsystem:windows /machine:I386 /nodefaultlib /out:"../../splash.exe" /opt:nowin98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "splash - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "splash - Win32 Release"
# Name "splash - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\splash.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

29
Contrib/Splash/splash.dsw Normal file
View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "splash"=.\splash.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

38
Contrib/Splash/splash.txt Normal file
View file

@ -0,0 +1,38 @@
Splash.exe - small (3.5k), simple (one file) program that lets you throw
up a splash screen in NSIS installers.
--- UPDATED in 1.50 - will break old scripts ---
To use:
Create a .BMP file of your splash screen.
(optional) Create a .WAV file to play while your splash screen shows.
Add the following lines to your .NSI file:
Function .onInit
SetOutPath $TEMP
File /oname=spltmp.bmp "my_splash.bmp"
; optional
; File /oname=spltmp.wav "my_splashshit.wav"
File /oname=spltmp.exe "C:\program files\nsis\splash.exe"
ExecWait '"$TEMP\spltmp.exe" 1000 $HWNDPARENT $TEMP\spltmp'
Delete $TEMP\spltmp.exe
Delete $TEMP\spltmp.bmp
; Delete $TEMP\spltmp.wav
FunctionEnd
Note that the first parameter to splash.exe is the length to show the
screen for (in milliseconds), the second is the parent window (in decimal),
and the last is the splash bitmap filename (without the .bmp). The BMP file
used will be this parameter.bmp, and the wave file used (if present) will be
this parameter.wav.
(If you already have an .onInit function, put that in it)
Note: the return value of splash.exe is 1 if the user closed the splash
screen early (you can check it using ClearErrors/IfErrors)
-Justin

BIN
Contrib/UIs/default.exe Executable file

Binary file not shown.

BIN
Contrib/UIs/mlbl.exe Executable file

Binary file not shown.

BIN
Contrib/UIs/mlbl2.exe Executable file

Binary file not shown.

BIN
Contrib/zip2exe/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

715
Contrib/zip2exe/main.cpp Normal file
View file

@ -0,0 +1,715 @@
#include <windows.h>
#include <stdio.h>
// portions Copyright © 1999-2001 Miguel Garrido (mgarrido01@hotmail.com)
extern "C"
{
#include "zlib/unzip.h"
};
#include "resource.h"
const char *g_errcaption="ZIP2EXE Error";
HINSTANCE g_hInstance;
HWND g_hwnd;
HANDLE g_hThread;
char g_cmdline[1024];
char g_makensis_path[MAX_PATH];
int g_extracting;
int g_zipfile_size;
char *g_options="";//"/V3";
static BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
LPSTR lpszCmdParam, int nCmdShow)
{
g_hInstance=hInstance;
return DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),GetDesktopWindow(),DlgProc);
}
char tempzip_path[1024];
int made;
static void doRMDir(char *buf)
{
HANDLE h;
WIN32_FIND_DATA fd;
char *p=buf;
while (*p) p++;
lstrcpy(p,"\\*.*");
h = FindFirstFile(buf,&fd);
if (h != INVALID_HANDLE_VALUE)
{
do
{
if (fd.cFileName[0] != '.' ||
(fd.cFileName[1] != '.' && fd.cFileName[1]))
{
lstrcpy(p+1,fd.cFileName);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
SetFileAttributes(buf,fd.dwFileAttributes^FILE_ATTRIBUTE_READONLY);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) doRMDir(buf);
else
{
DeleteFile(buf);
}
}
} while (FindNextFile(h,&fd));
FindClose(h);
}
p[0]=0; // fix buffer
RemoveDirectory(buf);
}
static void doMKDir(char *directory)
{
char *p, *p2;
char buf[MAX_PATH];
if (!*directory) return;
lstrcpy(buf,directory);
p=buf; while (*p) p++;
while (p >= buf && *p != '\\') p--;
p2 = buf;
if (p2[1] == ':') p2+=4;
else if (p2[0] == '\\' && p2[1] == '\\')
{
p2+=2;
while (*p2 && *p2 != '\\') p2++;
if (*p2) p2++;
while (*p2 && *p2 != '\\') p2++;
if (*p2) p2++;
}
if (p >= p2)
{
*p=0;
doMKDir(buf);
}
CreateDirectory(directory,NULL);
}
void tempzip_cleanup(HWND hwndDlg, int err)
{
if (tempzip_path[0]) doRMDir(tempzip_path);
tempzip_path[0]=0;
if (err)
{
SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_RESETCONTENT,0,0);
EnableWindow(GetDlgItem(hwndDlg,IDOK),0);
SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,"");
SetDlgItemText(hwndDlg,IDC_ZIPFILE,"");
SetDlgItemText(hwndDlg,IDC_OUTFILE,"");
}
}
int tempzip_make(HWND hwndDlg, char *fn)
{
char buf[MAX_PATH];
GetTempPath(MAX_PATH,buf);
GetTempFileName(buf,"z2e",GetTickCount(),tempzip_path);
if (!CreateDirectory(tempzip_path,NULL))
{
GetTempPath(MAX_PATH,tempzip_path);
strcat(tempzip_path,"\\nsi");
if (!CreateDirectory(tempzip_path,NULL))
{
tempzip_path[0]=0;
MessageBox(hwndDlg,"Error creating temporary directory",g_errcaption,MB_OK|MB_ICONSTOP);
return 1;
}
}
FILE *fp=fopen(fn,"rb");
if (fp)
{
fseek(fp,0,SEEK_END);
g_zipfile_size=ftell(fp);
fclose(fp);
}
else g_zipfile_size=0;
unzFile f;
f = unzOpen(fn);
if (!f || unzGoToFirstFile(f) != UNZ_OK)
{
if (f) unzClose(f);
MessageBox(hwndDlg,"Error opening ZIP file",g_errcaption,MB_OK|MB_ICONSTOP);
return 1;
}
int nf=0, nkb=0;
g_extracting=1;
do {
char filename[MAX_PATH];
unzGetCurrentFileInfo(f,NULL,filename,sizeof(filename),NULL,0,NULL,0);
if (filename[0] &&
filename[strlen(filename)-1] != '\\' &&
filename[strlen(filename)-1] != '/')
{
char *pfn=filename;
while (*pfn)
{
if (*pfn == '/') *pfn='\\';
pfn++;
}
pfn=filename;
if (pfn[1] == ':' && pfn[2] == '\\') pfn+=3;
while (*pfn == '\\') pfn++;
char out_filename[1024];
lstrcpy(out_filename,tempzip_path);
lstrcat(out_filename,"\\");
lstrcat(out_filename,pfn);
if (strstr(pfn,"\\"))
{
char buf[1024];
lstrcpy(buf,out_filename);
char *p=buf+strlen(buf);
while (p > buf && *p != '\\') p--;
*p=0;
if (buf[0]) doMKDir(buf);
}
if (unzOpenCurrentFile(f) == UNZ_OK)
{
SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_ADDSTRING,0,(LPARAM)pfn);
FILE *fp;
int l;
fp = fopen(out_filename,"wb");
if (fp)
{
do
{
char buf[1024];
l=unzReadCurrentFile(f,buf,sizeof(buf));
if (l > 0)
{
if (fwrite(buf,1,l,fp) != (unsigned int)l)
{
unzClose(f);
fclose(fp);
MessageBox(hwndDlg,"Error writing output file(s)",g_errcaption,MB_OK|MB_ICONSTOP);
g_extracting=0;
return 1;
}
nkb++;
}
} while (l > 0);
fclose(fp);
}
else
{
unzClose(f);
MessageBox(hwndDlg,"Error opening output file(s)",g_errcaption,MB_OK|MB_ICONSTOP);
g_extracting=0;
return 1;
}
nf++;
wsprintf(buf,"Extracting: %d files, %dKB",nf,nkb);
SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf);
MSG msg;
int quit=0;
while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_DESTROY && msg.hwnd == g_hwnd)
{
quit++;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
unzCloseCurrentFile(f);
if (quit) break;
}
else
{
unzClose(f);
MessageBox(hwndDlg,"Error extracting from ZIP file",g_errcaption,MB_OK|MB_ICONSTOP);
g_extracting=0;
return 1;
}
}
} while (unzGoToNextFile(f) == UNZ_OK);
g_extracting=0;
wsprintf(buf,"Extracted: %d files, %dKB",nf,nkb);
SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf);
unzClose(f);
return 0;
}
char *gp_winamp = "(WINAMP DIRECTORY)";
char *gp_winamp_plugins = "(WINAMP PLUG-INS DIRECTORY)";
char *gp_winamp_vis = "(WINAMP VIS PLUG-INS DIRECTORY)";
char *gp_winamp_dsp = "(WINAMP DSP PLUG-INS DIRECTORY)";
char *gp_winamp_skins = "(WINAMP SKINS DIRECTORY)";
char *gp_poi = "(PATH OF INSTALLER)";
void wnd_printf(const char *str)
{
if (!*str) return;
char existing_text[32000];
existing_text[0]=0;
UINT l=GetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, existing_text, 32000);
l+=strlen(str);
char *p=existing_text;
existing_text[31000]=0;
while (l > 31000 && *p)
{
while (*p != '\r' && *p != '\n' && *p)
{
p++;
l--;
}
while (*p == '\r' || *p == '\n')
{
p++;
l--;
}
}
char buf[31000];
lstrcpy(buf,p);
lstrcpy(existing_text,buf);
lstrcat(existing_text,str);
SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, existing_text);
SendDlgItemMessage(g_hwnd, IDC_OUTPUTTEXT, EM_LINESCROLL, 0, SendDlgItemMessage(g_hwnd, IDC_OUTPUTTEXT, EM_GETLINECOUNT, 0, 0)); // scroll to the last line of the textbox
}
void ErrorMessage(char *str) //display detailed error info
{
LPVOID msg;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &msg,
0,
NULL
);
wnd_printf(str);
wnd_printf(": ");
wnd_printf((char*)msg);
LocalFree(msg);
}
DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp
{
char buf[1024]; //i/o buffer
STARTUPINFO si={sizeof(si),};
SECURITY_ATTRIBUTES sa={sizeof(sa),};
SECURITY_DESCRIPTOR sd={0,}; //security information for pipes
PROCESS_INFORMATION pi={0,};
HANDLE newstdout=0,read_stdout=0; //pipe handles
OSVERSIONINFO osv={sizeof(osv)};
GetVersionEx(&osv);
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) //initialize security descriptor (Windows NT)
{
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);
sa.lpSecurityDescriptor = &sd;
}
else sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true; //allow inheritable handles
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) //create stdout pipe
{
ErrorMessage("CreatePipe");
PostMessage(g_hwnd,WM_USER+1203,0,1);
return 1;
}
GetStartupInfo(&si); //set startupinfo for the spawned process
/*
The dwFlags member tells CreateProcess how to make the process.
STARTF_USESTDHANDLES validates the hStd* members. STARTF_USESHOWWINDOW
validates the wShowWindow member.
*/
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.hStdOutput = newstdout;
si.hStdError = newstdout; //set the new handles for the child process
// *******************************************************************
// If there is a command line in the config file, use it for create process
//spawn the child process
if (!CreateProcess(NULL,g_cmdline,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,
NULL,tempzip_path,&si,&pi))
{
ErrorMessage("CreateProcess");
wnd_printf("\r\nPlease make sure the path to makensis.exe is correct.");
CloseHandle(newstdout);
CloseHandle(read_stdout);
PostMessage(g_hwnd,WM_USER+1203,0,1);
return 1;
}
unsigned long exit=0; //process exit code
unsigned long bread; //bytes read
unsigned long avail; //bytes available
memset(buf,0,sizeof(buf));
while (1) //main program loop
{
PeekNamedPipe(read_stdout,buf,1023,&bread,&avail,NULL);
//check to see if there is any data to read from stdout
if (bread != 0)
{
memset(buf,0,sizeof(buf));
if (avail > 1023)
{
while (bread >= 1023)
{
ReadFile(read_stdout,buf,1023,&bread,NULL); //read the stdout pipe
wnd_printf(buf);
memset(buf,0,sizeof(buf));
}
}
else
{
ReadFile(read_stdout,buf,1023,&bread,NULL);
wnd_printf(buf);
}
}
GetExitCodeProcess(pi.hProcess,&exit); //while the process is running
if (exit != STILL_ACTIVE)
break;
Sleep(100);
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(newstdout);
CloseHandle(read_stdout);
wsprintf(buf,"(source ZIP size was %d bytes)\r\n",g_zipfile_size);
wnd_printf(buf);
PostMessage(g_hwnd,WM_USER+1203,0,0);
return 0;
}
char nsifilename[MAX_PATH];
void makeEXE(HWND hwndDlg)
{
char buf[2048];
GetTempPath(MAX_PATH,buf);
GetTempFileName(buf,"zne",0,nsifilename);
FILE *fp=fopen(nsifilename,"w");
if (!fp)
{
MessageBox(hwndDlg,"Error writing .NSI file",g_errcaption,MB_OK|MB_ICONSTOP);
return;
}
GetDlgItemText(hwndDlg,IDC_INSTNAME,buf,sizeof(buf));
fprintf(fp,"Name `%s`\n",buf);
fprintf(fp,"Caption `%s Self Extractor`\n",buf);
GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf));
fprintf(fp,"OutFile `%s`\n",buf);
GetDlgItemText(hwndDlg,IDC_INSTPATH,buf,sizeof(buf));
char *outpath = "$INSTDIR";
int iswinamp=0;
char *iswinampmode=NULL;
if (!strcmp(buf,gp_poi)) lstrcpy(buf,"$EXEDIR");
if (!strcmp(buf,gp_winamp))
{
iswinamp=1;
fprintf(fp,"Function SetMyOutPath\n"
" SetOutPath $INSTDIR\n"
"FunctionEnd\n");
}
if (!strcmp(buf,gp_winamp_plugins))
{
iswinamp=1;
fprintf(fp,"Function SetMyOutPath\n"
" SetOutPath $INSTDIR\\Plugins\n"
"FunctionEnd\n");
}
if (!strcmp(buf,gp_winamp_vis))
{
iswinamp=1;
iswinampmode="VisDir";
}
if (!strcmp(buf,gp_winamp_dsp))
{
iswinamp=1;
iswinampmode="DSPDir";
}
if (!strcmp(buf,gp_winamp_skins))
{
iswinamp=1;
iswinampmode="SkinDir";
}
if (iswinamp)
{
fprintf(fp,"InstallDir `$PROGRAMFILES\\Winamp`\n");
fprintf(fp,"InstallDirRegKey HKEY_LOCAL_MACHINE `Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Winamp` `UninstallString`\n");
fprintf(fp,"Function .onVerifyInstDir\n"
" IfFileExists $INSTDIR\\winamp.exe WinampInstalled\n"
" Abort\n"
" WinampInstalled:\n"
"FunctionEnd\n");
if (iswinampmode)
{
fprintf(fp,"Function SetMyOutPath\n"
" StrCpy $1 $INSTDIR\\Plugins\n"
" ReadINIStr $9 $INSTDIR\\winamp.ini Winamp %s\n"
" StrCmp $9 '' End\n"
" IfFileExists $9 0 End\n"
" StrCpy $1 $9\n"
" End:\n"
" SetOutPath $1\n"
"FunctionEnd\n",iswinampmode);
}
}
else // set out path to $INSTDIR
{
fprintf(fp,"InstallDir `%s`\n",buf);
fprintf(fp,"Function SetMyOutPath\n"
" SetOutPath $INSTDIR\n"
"FunctionEnd\n");
}
GetDlgItemText(hwndDlg,IDC_DESCTEXT,buf,sizeof(buf));
fprintf(fp,"DirText `%s`\n",buf);
fprintf(fp,"Section\n");
fprintf(fp,"Call SetMyOutPath\n");
fprintf(fp,"File /r `%s\\*.*`\n",tempzip_path);
fprintf(fp,"SectionEnd\n");
fclose(fp);
wsprintf(g_cmdline,"\"%s\" %s \"%s\"",g_makensis_path,g_options,nsifilename);
DWORD id;
g_hThread=CreateThread(NULL,0,ThreadProc,0,0,&id);
}
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static int ids[]={IDC_SZIPFRAME,IDC_BROWSE,IDC_ZIPFILE,IDC_ZIPINFO_SUMMARY,IDC_ZIPINFO_FILES,IDC_OFRAME,IDC_INAMEST,
IDC_INSTNAME,IDC_DTEXTST,IDC_DESCTEXT,IDC_DEPST,IDC_INSTPATH,IDC_OEFST,IDC_OUTFILE,IDC_BROWSE2,IDC_BROWSE3,IDC_COMPILER};
static HICON hIcon;
static HFONT hFont;
if (uMsg == WM_DESTROY) { if (hIcon) DeleteObject(hIcon); hIcon=0; if (hFont) DeleteObject(hFont); hFont=0; }
switch (uMsg)
{
case WM_INITDIALOG:
g_hwnd=hwndDlg;
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_poi);
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$TEMP");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$SYSDIR");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$WINDIR");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$DESKTOP");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$DESKTOP\\Poop");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$PROGRAMFILES\\Poop");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$STARTMENU");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$SMPROGRAMS");
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp);
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_plugins);
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_vis);
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_dsp);
SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_skins);
SetDlgItemText(hwndDlg,IDC_INSTPATH,gp_poi);
SetDlgItemText(hwndDlg,IDC_DESCTEXT,"Select the folder where you would like to extract the files to:");
hIcon=LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON1));
SetClassLong(hwndDlg,GCL_HICON,(long)hIcon);
hFont=CreateFont(15,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,"Courier New");
SendDlgItemMessage(hwndDlg,IDC_OUTPUTTEXT,WM_SETFONT,(WPARAM)hFont,0);
{
char *p=g_makensis_path;
GetModuleFileName(g_hInstance,g_makensis_path,sizeof(g_makensis_path));
while (*p) p++;
while (p >= g_makensis_path && *p != '\\') p--;
strcpy(++p,"makensis.exe");
}
SetDlgItemText(hwndDlg,IDC_COMPILER,g_makensis_path);
return 1;
case WM_CLOSE:
if (!g_hThread)
{
tempzip_cleanup(hwndDlg,0);
EndDialog(hwndDlg,1);
}
break;
case WM_USER+1203:
if (g_hThread)
{
if (!lParam)
{
ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_SHOWNA);
}
made=1;
ShowWindow(GetDlgItem(hwndDlg,IDC_BACK),SW_SHOWNA);
EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
CloseHandle(g_hThread);
g_hThread=0;
if (nsifilename[0]) DeleteFile(nsifilename);
nsifilename[0]=0;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_BROWSE:
if (!g_extracting) {
OPENFILENAME l={sizeof(l),};
char buf[1024];
l.hwndOwner = hwndDlg;
l.lpstrFilter = "ZIP files\0*.zip\0All files\0*.*\0";
l.lpstrFile = buf;
l.nMaxFile = 1023;
l.lpstrTitle = "Open ZIP file";
l.lpstrDefExt = "zip";
l.lpstrInitialDir = NULL;
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST;
buf[0]=0;
if (GetOpenFileName(&l))
{
char buf2[1024];
lstrcpy(buf2,buf);
tempzip_cleanup(hwndDlg,1);
SetDlgItemText(hwndDlg,IDC_ZIPFILE,buf);
char *t=buf+strlen(buf);
while (t > buf && *t != '\\' && *t != '.') t--;
{
char *p=t;
while (p >= buf && *p != '\\') p--;
p++;
*t=0;
SetDlgItemText(hwndDlg,IDC_INSTNAME,p[0]?p:"Stuff");
}
strcpy(t,".exe");
SetDlgItemText(hwndDlg,IDC_OUTFILE,buf);
if (tempzip_make(hwndDlg,buf2)) tempzip_cleanup(hwndDlg,1);
else
{
EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
}
}
}
break;
case IDC_BROWSE2:
{
OPENFILENAME l={sizeof(l),};
char buf[1024];
l.hwndOwner = hwndDlg;
l.lpstrFilter = "EXE files\0*.exe\0All files\0*.*\0";
l.lpstrFile = buf;
l.nMaxFile = 1023;
l.lpstrTitle = "Select output EXE file";
l.lpstrDefExt = "exe";
l.lpstrInitialDir = NULL;
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER;
GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf));
if (GetSaveFileName(&l))
{
SetDlgItemText(hwndDlg,IDC_OUTFILE,buf);
}
}
break;
case IDC_BROWSE3:
{
OPENFILENAME l={sizeof(l),};
char buf[1024];
l.hwndOwner = hwndDlg;
l.lpstrFilter = "Makensis EXE files (Makensis*.exe)\0Makensis*.exe\0All files\0*.*\0";
l.lpstrFile = buf;
l.nMaxFile = 1023;
l.lpstrTitle = "Select compiler EXE file";
l.lpstrDefExt = "exe";
l.lpstrInitialDir = NULL;
l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST;
GetDlgItemText(hwndDlg,IDC_COMPILER,buf,sizeof(buf));
if (GetOpenFileName(&l))
{
SetDlgItemText(hwndDlg,IDC_COMPILER,buf);
}
}
break;
case IDC_BACK:
if (!g_hThread)
{
made=0;
ShowWindow(GetDlgItem(hwndDlg,IDC_BACK),SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_HIDE);
{
int x;
for (x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++)
ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_SHOWNA);
SetDlgItemText(hwndDlg,IDOK,"Convert");
EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
}
}
break;
case IDC_TEST:
if (!g_hThread) {
char buf[1024];
GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf));
ShellExecute(hwndDlg,"open",buf,"","",SW_SHOW);
}
break;
case IDOK:
if (!g_hThread)
{
if (!made)
{
GetDlgItemText(hwndDlg,IDC_COMPILER,g_makensis_path,sizeof(g_makensis_path));
SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, "");
int x;
for (x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++)
ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_HIDE);
ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_SHOWNA);
SetDlgItemText(hwndDlg,IDOK,"Close");
EnableWindow(GetDlgItem(hwndDlg,IDOK),0);
makeEXE(hwndDlg);
}
else
{
tempzip_cleanup(hwndDlg,0);
EndDialog(hwndDlg,0);
}
}
break;
}
break;
}
return 0;
}

132
Contrib/zip2exe/res.rc Normal file
View file

@ -0,0 +1,132 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 361, 234
STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Nullsoft ZIP2EXE v0.16"
FONT 8, "MS Sans Serif"
BEGIN
PUSHBUTTON "Open &ZIP",IDC_BROWSE,13,17,49,14
EDITTEXT IDC_ZIPFILE,66,18,284,12,ES_AUTOHSCROLL | ES_READONLY |
NOT WS_TABSTOP
LISTBOX IDC_ZIPINFO_FILES,13,45,335,56,LBS_NOINTEGRALHEIGHT |
LBS_NOSEL | WS_VSCROLL
EDITTEXT IDC_INSTNAME,81,113,267,12,ES_AUTOHSCROLL
EDITTEXT IDC_DESCTEXT,81,129,267,12,ES_AUTOHSCROLL
COMBOBOX IDC_INSTPATH,81,144,268,126,CBS_DROPDOWN | WS_VSCROLL |
WS_TABSTOP
EDITTEXT IDC_OUTFILE,13,169,292,12,ES_AUTOHSCROLL
PUSHBUTTON "Browse",IDC_BROWSE2,307,168,41,14
DEFPUSHBUTTON "Convert",IDOK,304,213,50,14,WS_DISABLED
GROUPBOX "Source ZIP file",IDC_SZIPFRAME,7,7,347,180
LTEXT "",IDC_ZIPINFO_SUMMARY,13,33,245,8
GROUPBOX "Output",IDC_OFRAME,7,102,347,85
LTEXT "Default extract path:",IDC_DEPST,13,145,66,8
LTEXT "Description text:",IDC_DTEXTST,13,131,66,8
LTEXT "Output EXE file:",IDC_OEFST,14,157,51,8
LTEXT "Installer name",IDC_INAMEST,13,116,66,8
PUSHBUTTON "Test",IDC_TEST,251,213,50,14,NOT WS_VISIBLE
PUSHBUTTON "< Back",IDC_BACK,7,213,50,14,NOT WS_VISIBLE
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,210,347,1
PUSHBUTTON "Change Compiler",IDC_BROWSE3,7,190,62,14
EDITTEXT IDC_COMPILER,74,191,280,12,ES_AUTOHSCROLL | ES_READONLY |
NOT WS_TABSTOP
EDITTEXT IDC_OUTPUTTEXT,7,7,347,202,ES_MULTILINE | ES_AUTOVSCROLL |
ES_AUTOHSCROLL | ES_READONLY | NOT WS_VISIBLE |
WS_VSCROLL | WS_HSCROLL
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 354
TOPMARGIN, 7
BOTTOMMARGIN, 227
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON DISCARDABLE "icon.ico"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View file

@ -0,0 +1,37 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by res.rc
//
#define IDD_DIALOG1 101
#define IDI_ICON1 102
#define IDC_ZIPFILE 1000
#define IDC_BROWSE 1001
#define IDC_ZIPINFO_SUMMARY 1002
#define IDC_BROWSE3 1003
#define IDC_ZIPINFO_FILES 1004
#define IDC_INSTPATH 1005
#define IDC_DESCTEXT 1006
#define IDC_OUTFILE 1007
#define IDC_BROWSE2 1008
#define IDC_INSTNAME 1009
#define IDC_SZIPFRAME 1010
#define IDC_OFRAME 1011
#define IDC_INAMEST 1012
#define IDC_DTEXTST 1013
#define IDC_DEPST 1014
#define IDC_OEFST 1015
#define IDC_OUTPUTTEXT 1016
#define IDC_TEST 1017
#define IDC_BACK 1018
#define IDC_COMPILER 1019
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1020
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

160
Contrib/zip2exe/zip2exe.dsp Normal file
View file

@ -0,0 +1,160 @@
# Microsoft Developer Studio Project File - Name="zip2exe" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=zip2exe - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "zip2exe.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "zip2exe.mak" CFG="zip2exe - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "zip2exe - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "zip2exe - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "zip2exe - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX- /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"../../zip2exe.exe" /opt:nowin98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "zip2exe - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "zip2exe - Win32 Release"
# Name "zip2exe - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Group "zlib"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\zlib\Adler32.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Crc32.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Infblock.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Infcodes.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Inffast.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Inflate.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Inftrees.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Infutil.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Unzip.c
# End Source File
# Begin Source File
SOURCE=.\zlib\Zutil.c
# End Source File
# End Group
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\icon.ico
# End Source File
# Begin Source File
SOURCE=.\res.rc
# End Source File
# End Group
# End Target
# End Project

View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "zip2exe"=.\zip2exe.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View file

@ -0,0 +1,48 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
#define BASE 65521L /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
/* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
int k;
if (buf == Z_NULL) return 1L;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) do {
s1 += *buf++;
s2 += s1;
} while (--k);
s1 %= BASE;
s2 %= BASE;
}
return (s2 << 16) | s1;
}

View file

@ -0,0 +1,162 @@
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
#define local static
#ifdef DYNAMIC_CRC_TABLE
local int crc_table_empty = 1;
local uLongf crc_table[256];
local void make_crc_table OF((void));
/*
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
The table is simply the CRC of all possible eight bit values. This is all
the information needed to generate CRC's on data a byte at a time for all
combinations of CRC register values and incoming bytes.
*/
local void make_crc_table()
{
uLong c;
int n, k;
uLong poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
poly = 0L;
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
poly |= 1L << (31 - p[n]);
for (n = 0; n < 256; n++)
{
c = (uLong)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[n] = c;
}
crc_table_empty = 0;
}
#else
/* ========================================================================
* Table of CRC-32's of all single-byte values (made by make_crc_table)
*/
local const uLongf crc_table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
#endif
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
const uLongf * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) make_crc_table();
#endif
return (const uLongf *)crc_table;
}
/* ========================================================================= */
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
#define DO2(buf) DO1(buf); DO1(buf);
#define DO4(buf) DO2(buf); DO2(buf);
#define DO8(buf) DO4(buf); DO4(buf);
/* ========================================================================= */
uLong ZEXPORT crc32(crc, buf, len)
uLong crc;
const Bytef *buf;
uInt len;
{
if (buf == Z_NULL) return 0L;
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif
crc = crc ^ 0xffffffffL;
while (len >= 8)
{
DO8(buf);
len -= 8;
}
if (len) do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL;
}

View file

@ -0,0 +1,398 @@
/* infblock.c -- interpret and process block types to last block
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "infblock.h"
#include "inftrees.h"
#include "infcodes.h"
#include "infutil.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
/* Table for deflate from PKZIP's appnote.txt. */
local const uInt border[] = { /* Order of the bit length code lengths */
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
/*
Notes beyond the 1.93a appnote.txt:
1. Distance pointers never point before the beginning of the output
stream.
2. Distance pointers can point back across blocks, up to 32k away.
3. There is an implied maximum of 7 bits for the bit length table and
15 bits for the actual data.
4. If only one code exists, then it is encoded using one bit. (Zero
would be more efficient, but perhaps a little confusing.) If two
codes exist, they are coded using one bit each (0 and 1).
5. There is no way of sending zero distance codes--a dummy must be
sent if there are none. (History: a pre 2.0 version of PKZIP would
store blocks with no distance codes, but this was discovered to be
too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
zero distance codes, which is sent as one code of zero bits in
length.
6. There are up to 286 literal/length codes. Code 256 represents the
end-of-block. Note however that the static length tree defines
288 codes just to fill out the Huffman codes. Codes 286 and 287
cannot be used though, since there is no length base or extra bits
defined for them. Similarily, there are up to 30 distance codes.
However, static trees define 32 codes (all 5 bits) to fill out the
Huffman codes, but the last two had better not show up in the data.
7. Unzip can check dynamic Huffman blocks for complete code sets.
The exception is that a single code would not be complete (see #4).
8. The five bits following the block type is really the number of
literal codes sent minus 257.
9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
(1+6+6). Therefore, to output three times the length, you output
three codes (1+1+1), whereas to output four times the same length,
you only need two codes (1+3). Hmm.
10. In the tree reconstruction algorithm, Code = Code + Increment
only if BitLength(i) is not zero. (Pretty obvious.)
11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
12. Note: length code 284 can represent 227-258, but length code 285
really is 258. The last length deserves its own, short code
since it gets used a lot in very redundant files. The length
258 is special since 258 - 3 (the min match length) is 255.
13. The literal/length and distance code bit lengths are read as a
single stream of lengths. It is possible (and advantageous) for
a repeat code (16, 17, or 18) to go across the boundary between
the two sets of lengths.
*/
void inflate_blocks_reset(s, z, c)
inflate_blocks_statef *s;
z_streamp z;
uLongf *c;
{
if (c != Z_NULL)
*c = s->check;
if (s->mode == BTREE || s->mode == DTREE)
ZFREE(z, s->sub.trees.blens);
if (s->mode == CODES)
inflate_codes_free(s->sub.decode.codes, z);
s->mode = TYPE;
s->bitk = 0;
s->bitb = 0;
s->read = s->write = s->window;
if (s->checkfn != Z_NULL)
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
Tracev((stderr, "inflate: blocks reset\n"));
}
inflate_blocks_statef *inflate_blocks_new(z, c, w)
z_streamp z;
check_func c;
uInt w;
{
inflate_blocks_statef *s;
if ((s = (inflate_blocks_statef *)ZALLOC
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
return s;
if ((s->hufts =
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
{
ZFREE(z, s);
return Z_NULL;
}
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
{
ZFREE(z, s->hufts);
ZFREE(z, s);
return Z_NULL;
}
s->end = s->window + w;
s->checkfn = c;
s->mode = TYPE;
Tracev((stderr, "inflate: blocks allocated\n"));
inflate_blocks_reset(s, z, Z_NULL);
return s;
}
int inflate_blocks(s, z, r)
inflate_blocks_statef *s;
z_streamp z;
int r;
{
uInt t; /* temporary storage */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
/* copy input/output information to locals (UPDATE macro restores) */
LOAD
/* process input based on current state */
while (1) switch (s->mode)
{
case TYPE:
NEEDBITS(3)
t = (uInt)b & 7;
s->last = t & 1;
switch (t >> 1)
{
case 0: /* stored */
Tracev((stderr, "inflate: stored block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
t = k & 7; /* go to byte boundary */
DUMPBITS(t)
s->mode = LENS; /* get length of stored block */
break;
case 1: /* fixed */
Tracev((stderr, "inflate: fixed codes block%s\n",
s->last ? " (last)" : ""));
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
if (s->sub.decode.codes == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
}
DUMPBITS(3)
s->mode = CODES;
break;
case 2: /* dynamic */
Tracev((stderr, "inflate: dynamic codes block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
s->mode = TABLE;
break;
case 3: /* illegal */
DUMPBITS(3)
s->mode = BAD;
z->msg = (char*)"invalid block type";
r = Z_DATA_ERROR;
LEAVE
}
break;
case LENS:
NEEDBITS(32)
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
{
s->mode = BAD;
z->msg = (char*)"invalid stored block lengths";
r = Z_DATA_ERROR;
LEAVE
}
s->sub.left = (uInt)b & 0xffff;
b = k = 0; /* dump bits */
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
break;
case STORED:
if (n == 0)
LEAVE
NEEDOUT
t = s->sub.left;
if (t > n) t = n;
if (t > m) t = m;
zmemcpy(q, p, t);
p += t; n -= t;
q += t; m -= t;
if ((s->sub.left -= t) != 0)
break;
Tracev((stderr, "inflate: stored end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :
(s->end - s->read) + (q - s->window))));
s->mode = s->last ? DRY : TYPE;
break;
case TABLE:
NEEDBITS(14)
s->sub.trees.table = t = (uInt)b & 0x3fff;
#ifndef PKZIP_BUG_WORKAROUND
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
{
s->mode = BAD;
z->msg = (char*)"too many length or distance symbols";
r = Z_DATA_ERROR;
LEAVE
}
#endif
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
DUMPBITS(14)
s->sub.trees.index = 0;
Tracev((stderr, "inflate: table sizes ok\n"));
s->mode = BTREE;
case BTREE:
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
{
NEEDBITS(3)
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
DUMPBITS(3)
}
while (s->sub.trees.index < 19)
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
s->sub.trees.bb = 7;
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
&s->sub.trees.tb, s->hufts, z);
if (t != Z_OK)
{
ZFREE(z, s->sub.trees.blens);
r = t;
if (r == Z_DATA_ERROR)
s->mode = BAD;
LEAVE
}
s->sub.trees.index = 0;
Tracev((stderr, "inflate: bits tree ok\n"));
s->mode = DTREE;
case DTREE:
while (t = s->sub.trees.table,
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
{
inflate_huft *h;
uInt i, j, c;
t = s->sub.trees.bb;
NEEDBITS(t)
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
t = h->bits;
c = h->base;
if (c < 16)
{
DUMPBITS(t)
s->sub.trees.blens[s->sub.trees.index++] = c;
}
else /* c == 16..18 */
{
i = c == 18 ? 7 : c - 14;
j = c == 18 ? 11 : 3;
NEEDBITS(t + i)
DUMPBITS(t)
j += (uInt)b & inflate_mask[i];
DUMPBITS(i)
i = s->sub.trees.index;
t = s->sub.trees.table;
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
(c == 16 && i < 1))
{
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
z->msg = (char*)"invalid bit length repeat";
r = Z_DATA_ERROR;
LEAVE
}
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
do {
s->sub.trees.blens[i++] = c;
} while (--j);
s->sub.trees.index = i;
}
}
s->sub.trees.tb = Z_NULL;
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_codes_statef *c;
bl = 9; /* must be <= 9 for lookahead assumptions */
bd = 6; /* must be <= 9 for lookahead assumptions */
t = s->sub.trees.table;
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
s->sub.trees.blens, &bl, &bd, &tl, &td,
s->hufts, z);
ZFREE(z, s->sub.trees.blens);
if (t != Z_OK)
{
if (t == (uInt)Z_DATA_ERROR)
s->mode = BAD;
r = t;
LEAVE
}
Tracev((stderr, "inflate: trees ok\n"));
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
s->sub.decode.codes = c;
}
s->mode = CODES;
case CODES:
UPDATE
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
return inflate_flush(s, z, r);
r = Z_OK;
inflate_codes_free(s->sub.decode.codes, z);
LOAD
Tracev((stderr, "inflate: codes end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :
(s->end - s->read) + (q - s->window))));
if (!s->last)
{
s->mode = TYPE;
break;
}
s->mode = DRY;
case DRY:
FLUSH
if (s->read != s->write)
LEAVE
s->mode = DONE;
case DONE:
r = Z_STREAM_END;
LEAVE
case BAD:
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
LEAVE
}
}
int inflate_blocks_free(s, z)
inflate_blocks_statef *s;
z_streamp z;
{
inflate_blocks_reset(s, z, Z_NULL);
ZFREE(z, s->window);
ZFREE(z, s->hufts);
ZFREE(z, s);
Tracev((stderr, "inflate: blocks freed\n"));
return Z_OK;
}
void inflate_set_dictionary(s, d, n)
inflate_blocks_statef *s;
const Bytef *d;
uInt n;
{
zmemcpy(s->window, d, n);
s->read = s->write = s->window + n;
}
/* Returns true if inflate is currently at the end of a block generated
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
* IN assertion: s != Z_NULL
*/
int inflate_blocks_sync_point(s)
inflate_blocks_statef *s;
{
return s->mode == LENS;
}

View file

@ -0,0 +1,39 @@
/* infblock.h -- header to use infblock.c
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
struct inflate_blocks_state;
typedef struct inflate_blocks_state FAR inflate_blocks_statef;
extern inflate_blocks_statef * inflate_blocks_new OF((
z_streamp z,
check_func c, /* check function */
uInt w)); /* window size */
extern int inflate_blocks OF((
inflate_blocks_statef *,
z_streamp ,
int)); /* initial return code */
extern void inflate_blocks_reset OF((
inflate_blocks_statef *,
z_streamp ,
uLongf *)); /* check value on output */
extern int inflate_blocks_free OF((
inflate_blocks_statef *,
z_streamp));
extern void inflate_set_dictionary OF((
inflate_blocks_statef *s,
const Bytef *d, /* dictionary */
uInt n)); /* dictionary length */
extern int inflate_blocks_sync_point OF((
inflate_blocks_statef *s));

View file

@ -0,0 +1,257 @@
/* infcodes.c -- process literals and length/distance pairs
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#include "infblock.h"
#include "infcodes.h"
#include "infutil.h"
#include "inffast.h"
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
START, /* x: set up for LEN */
LEN, /* i: get length/literal/eob next */
LENEXT, /* i: getting length extra (have base) */
DIST, /* i: get distance next */
DISTEXT, /* i: getting distance extra */
COPY, /* o: copying bytes in window, waiting for space */
LIT, /* o: got literal, waiting for output space */
WASH, /* o: got eob, possibly still output waiting */
END, /* x: got eob and all data flushed */
BADCODE} /* x: got error */
inflate_codes_mode;
/* inflate codes private state */
struct inflate_codes_state {
/* mode */
inflate_codes_mode mode; /* current inflate_codes mode */
/* mode dependent information */
uInt len;
union {
struct {
inflate_huft *tree; /* pointer into tree */
uInt need; /* bits needed */
} code; /* if LEN or DIST, where in tree */
uInt lit; /* if LIT, literal */
struct {
uInt get; /* bits to get for extra */
uInt dist; /* distance back to copy from */
} copy; /* if EXT or COPY, where and how much */
} sub; /* submode */
/* mode independent information */
Byte lbits; /* ltree bits decoded per branch */
Byte dbits; /* dtree bits decoder per branch */
inflate_huft *ltree; /* literal/length/eob tree */
inflate_huft *dtree; /* distance tree */
};
inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
uInt bl, bd;
inflate_huft *tl;
inflate_huft *td; /* need separate declaration for Borland C++ */
z_streamp z;
{
inflate_codes_statef *c;
if ((c = (inflate_codes_statef *)
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
{
c->mode = START;
c->lbits = (Byte)bl;
c->dbits = (Byte)bd;
c->ltree = tl;
c->dtree = td;
Tracev((stderr, "inflate: codes new\n"));
}
return c;
}
int inflate_codes(s, z, r)
inflate_blocks_statef *s;
z_streamp z;
int r;
{
uInt j; /* temporary storage */
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
Bytef *f; /* pointer to copy strings from */
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
/* copy input/output information to locals (UPDATE macro restores) */
LOAD
/* process input and output based on current state */
while (1) switch (c->mode)
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
case START: /* x: set up for LEN */
#ifndef SLOW
if (m >= 258 && n >= 10)
{
UPDATE
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
LOAD
if (r != Z_OK)
{
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
break;
}
}
#endif /* !SLOW */
c->sub.code.need = c->lbits;
c->sub.code.tree = c->ltree;
c->mode = LEN;
case LEN: /* i: get length/literal/eob next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e == 0) /* literal */
{
c->sub.lit = t->base;
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", t->base));
c->mode = LIT;
break;
}
if (e & 16) /* length */
{
c->sub.copy.get = e & 15;
c->len = t->base;
c->mode = LENEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
if (e & 32) /* end of block */
{
Tracevv((stderr, "inflate: end of block\n"));
c->mode = WASH;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid literal/length code";
r = Z_DATA_ERROR;
LEAVE
case LENEXT: /* i: getting length extra (have base) */
j = c->sub.copy.get;
NEEDBITS(j)
c->len += (uInt)b & inflate_mask[j];
DUMPBITS(j)
c->sub.code.need = c->dbits;
c->sub.code.tree = c->dtree;
Tracevv((stderr, "inflate: length %u\n", c->len));
c->mode = DIST;
case DIST: /* i: get distance next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e & 16) /* distance */
{
c->sub.copy.get = e & 15;
c->sub.copy.dist = t->base;
c->mode = DISTEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid distance code";
r = Z_DATA_ERROR;
LEAVE
case DISTEXT: /* i: getting distance extra */
j = c->sub.copy.get;
NEEDBITS(j)
c->sub.copy.dist += (uInt)b & inflate_mask[j];
DUMPBITS(j)
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
c->mode = COPY;
case COPY: /* o: copying bytes in window, waiting for space */
#ifndef __TURBOC__ /* Turbo C bug for following expression */
f = (uInt)(q - s->window) < c->sub.copy.dist ?
s->end - (c->sub.copy.dist - (q - s->window)) :
q - c->sub.copy.dist;
#else
f = q - c->sub.copy.dist;
if ((uInt)(q - s->window) < c->sub.copy.dist)
f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
#endif
while (c->len)
{
NEEDOUT
OUTBYTE(*f++)
if (f == s->end)
f = s->window;
c->len--;
}
c->mode = START;
break;
case LIT: /* o: got literal, waiting for output space */
NEEDOUT
OUTBYTE(c->sub.lit)
c->mode = START;
break;
case WASH: /* o: got eob, possibly more output */
if (k > 7) /* return unused byte, if any */
{
Assert(k < 16, "inflate_codes grabbed too many bytes")
k -= 8;
n++;
p--; /* can always return one */
}
FLUSH
if (s->read != s->write)
LEAVE
c->mode = END;
case END:
r = Z_STREAM_END;
LEAVE
case BADCODE: /* x: got error */
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
LEAVE
}
#ifdef NEED_DUMMY_RETURN
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
#endif
}
void inflate_codes_free(c, z)
inflate_codes_statef *c;
z_streamp z;
{
ZFREE(z, c);
Tracev((stderr, "inflate: codes free\n"));
}

View file

@ -0,0 +1,27 @@
/* infcodes.h -- header to use infcodes.c
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
struct inflate_codes_state;
typedef struct inflate_codes_state FAR inflate_codes_statef;
extern inflate_codes_statef *inflate_codes_new OF((
uInt, uInt,
inflate_huft *, inflate_huft *,
z_streamp ));
extern int inflate_codes OF((
inflate_blocks_statef *,
z_streamp ,
int));
extern void inflate_codes_free OF((
inflate_codes_statef *,
z_streamp ));

View file

@ -0,0 +1,170 @@
/* inffast.c -- process literals and length/distance pairs fast
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#include "infblock.h"
#include "infcodes.h"
#include "infutil.h"
#include "inffast.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
/* macros for bit input with no checking and for returning unused bytes */
#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
/* Called with number of bytes left to write in window at least 258
(the maximum string length) and number of input bytes available
at least ten. The ten bytes are six bytes for the longest length/
distance pair plus four bytes for overloading the bit buffer. */
int inflate_fast(bl, bd, tl, td, s, z)
uInt bl, bd;
inflate_huft *tl;
inflate_huft *td; /* need separate declaration for Borland C++ */
inflate_blocks_statef *s;
z_streamp z;
{
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
uInt ml; /* mask for literal/length tree */
uInt md; /* mask for distance tree */
uInt c; /* bytes to copy */
uInt d; /* distance back to copy from */
Bytef *r; /* copy source pointer */
/* load input, output, bit values */
LOAD
/* initialize masks */
ml = inflate_mask[bl];
md = inflate_mask[bd];
/* do until not enough input or output space for fast loop */
do { /* assume called with m >= 258 && n >= 10 */
/* get literal/length code */
GRABBITS(20) /* max bits for literal/length code */
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
{
DUMPBITS(t->bits)
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: * literal '%c'\n" :
"inflate: * literal 0x%02x\n", t->base));
*q++ = (Byte)t->base;
m--;
continue;
}
do {
DUMPBITS(t->bits)
if (e & 16)
{
/* get extra bits for length */
e &= 15;
c = t->base + ((uInt)b & inflate_mask[e]);
DUMPBITS(e)
Tracevv((stderr, "inflate: * length %u\n", c));
/* decode distance base of block to copy */
GRABBITS(15); /* max bits for distance code */
e = (t = td + ((uInt)b & md))->exop;
do {
DUMPBITS(t->bits)
if (e & 16)
{
/* get extra bits to add to distance base */
e &= 15;
GRABBITS(e) /* get extra bits (up to 13) */
d = t->base + ((uInt)b & inflate_mask[e]);
DUMPBITS(e)
Tracevv((stderr, "inflate: * distance %u\n", d));
/* do the copy */
m -= c;
if ((uInt)(q - s->window) >= d) /* offset before dest */
{ /* just copy */
r = q - d;
*q++ = *r++; c--; /* minimum count is three, */
*q++ = *r++; c--; /* so unroll loop a little */
}
else /* else offset after destination */
{
e = d - (uInt)(q - s->window); /* bytes from offset to end */
r = s->end - e; /* pointer to offset */
if (c > e) /* if source crosses, */
{
c -= e; /* copy to end of window */
do {
*q++ = *r++;
} while (--e);
r = s->window; /* copy rest from start of window */
}
}
do { /* copy all or what's left */
*q++ = *r++;
} while (--c);
break;
}
else if ((e & 64) == 0)
{
t += t->base;
e = (t += ((uInt)b & inflate_mask[e]))->exop;
}
else
{
z->msg = (char*)"invalid distance code";
UNGRAB
UPDATE
return Z_DATA_ERROR;
}
} while (1);
break;
}
if ((e & 64) == 0)
{
t += t->base;
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
{
DUMPBITS(t->bits)
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: * literal '%c'\n" :
"inflate: * literal 0x%02x\n", t->base));
*q++ = (Byte)t->base;
m--;
break;
}
}
else if (e & 32)
{
Tracevv((stderr, "inflate: * end of block\n"));
UNGRAB
UPDATE
return Z_STREAM_END;
}
else
{
z->msg = (char*)"invalid literal/length code";
UNGRAB
UPDATE
return Z_DATA_ERROR;
}
} while (1);
} while (m >= 258 && n >= 10);
/* not enough input or output--restore pointers and return */
UNGRAB
UPDATE
return Z_OK;
}

View file

@ -0,0 +1,17 @@
/* inffast.h -- header to use inffast.c
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
extern int inflate_fast OF((
uInt,
uInt,
inflate_huft *,
inflate_huft *,
inflate_blocks_statef *,
z_streamp ));

View file

@ -0,0 +1,151 @@
/* inffixed.h -- table for decoding fixed codes
* Generated automatically by the maketree.c program
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
local uInt fixed_bl = 9;
local uInt fixed_bd = 5;
local inflate_huft fixed_tl[] = {
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
};
local inflate_huft fixed_td[] = {
{{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
{{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
{{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
{{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
{{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
{{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
{{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
{{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
};

View file

@ -0,0 +1,366 @@
/* inflate.c -- zlib interface to inflate modules
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "infblock.h"
struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
typedef enum {
METHOD, /* waiting for method byte */
FLAG, /* waiting for flag byte */
DICT4, /* four dictionary check bytes to go */
DICT3, /* three dictionary check bytes to go */
DICT2, /* two dictionary check bytes to go */
DICT1, /* one dictionary check byte to go */
DICT0, /* waiting for inflateSetDictionary */
BLOCKS, /* decompressing blocks */
CHECK4, /* four check bytes to go */
CHECK3, /* three check bytes to go */
CHECK2, /* two check bytes to go */
CHECK1, /* one check byte to go */
DONE, /* finished check, done */
BAD} /* got an error--stay here */
inflate_mode;
/* inflate private state */
struct internal_state {
/* mode */
inflate_mode mode; /* current inflate mode */
/* mode dependent information */
union {
uInt method; /* if FLAGS, method byte */
struct {
uLong was; /* computed check value */
uLong need; /* stream check value */
} check; /* if CHECK, check values to compare */
uInt marker; /* if BAD, inflateSync's marker bytes count */
} sub; /* submode */
/* mode independent information */
int nowrap; /* flag for no wrapper */
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
inflate_blocks_statef
*blocks; /* current inflate_blocks state */
};
int ZEXPORT inflateReset(z)
z_streamp z;
{
if (z == Z_NULL || z->state == Z_NULL)
return Z_STREAM_ERROR;
z->total_in = z->total_out = 0;
z->msg = Z_NULL;
z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
inflate_blocks_reset(z->state->blocks, z, Z_NULL);
Tracev((stderr, "inflate: reset\n"));
return Z_OK;
}
int ZEXPORT inflateEnd(z)
z_streamp z;
{
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
return Z_STREAM_ERROR;
if (z->state->blocks != Z_NULL)
inflate_blocks_free(z->state->blocks, z);
ZFREE(z, z->state);
z->state = Z_NULL;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
}
int ZEXPORT inflateInit2_(z, w, version, stream_size)
z_streamp z;
int w;
const char *version;
int stream_size;
{
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != sizeof(z_stream))
return Z_VERSION_ERROR;
/* initialize state */
if (z == Z_NULL)
return Z_STREAM_ERROR;
z->msg = Z_NULL;
if (z->zalloc == Z_NULL)
{
z->zalloc = zcalloc;
z->opaque = (voidpf)0;
}
if (z->zfree == Z_NULL) z->zfree = zcfree;
if ((z->state = (struct internal_state FAR *)
ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
return Z_MEM_ERROR;
z->state->blocks = Z_NULL;
/* handle undocumented nowrap option (no zlib header or check) */
z->state->nowrap = 0;
if (w < 0)
{
w = - w;
z->state->nowrap = 1;
}
/* set window size */
if (w < 8 || w > 15)
{
inflateEnd(z);
return Z_STREAM_ERROR;
}
z->state->wbits = (uInt)w;
/* create inflate_blocks state */
if ((z->state->blocks =
inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
== Z_NULL)
{
inflateEnd(z);
return Z_MEM_ERROR;
}
Tracev((stderr, "inflate: allocated\n"));
/* reset state */
inflateReset(z);
return Z_OK;
}
int ZEXPORT inflateInit_(z, version, stream_size)
z_streamp z;
const char *version;
int stream_size;
{
return inflateInit2_(z, DEF_WBITS, version, stream_size);
}
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
int ZEXPORT inflate(z, f)
z_streamp z;
int f;
{
int r;
uInt b;
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
return Z_STREAM_ERROR;
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
r = Z_BUF_ERROR;
while (1) switch (z->state->mode)
{
case METHOD:
NEEDBYTE
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
{
z->state->mode = BAD;
z->msg = (char*)"unknown compression method";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
{
z->state->mode = BAD;
z->msg = (char*)"invalid window size";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
z->state->mode = FLAG;
case FLAG:
NEEDBYTE
b = NEXTBYTE;
if (((z->state->sub.method << 8) + b) % 31)
{
z->state->mode = BAD;
z->msg = (char*)"incorrect header check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib header ok\n"));
if (!(b & PRESET_DICT))
{
z->state->mode = BLOCKS;
break;
}
z->state->mode = DICT4;
case DICT4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = DICT3;
case DICT3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = DICT2;
case DICT2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = DICT1;
case DICT1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
z->adler = z->state->sub.check.need;
z->state->mode = DICT0;
return Z_NEED_DICT;
case DICT0:
z->state->mode = BAD;
z->msg = (char*)"need dictionary";
z->state->sub.marker = 0; /* can try inflateSync */
return Z_STREAM_ERROR;
case BLOCKS:
r = inflate_blocks(z->state->blocks, z, r);
if (r == Z_DATA_ERROR)
{
z->state->mode = BAD;
z->state->sub.marker = 0; /* can try inflateSync */
break;
}
if (r == Z_OK)
r = f;
if (r != Z_STREAM_END)
return r;
r = f;
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
if (z->state->nowrap)
{
z->state->mode = DONE;
break;
}
z->state->mode = CHECK4;
case CHECK4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = CHECK3;
case CHECK3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = CHECK2;
case CHECK2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = CHECK1;
case CHECK1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
if (z->state->sub.check.was != z->state->sub.check.need)
{
z->state->mode = BAD;
z->msg = (char*)"incorrect data check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib check ok\n"));
z->state->mode = DONE;
case DONE:
return Z_STREAM_END;
case BAD:
return Z_DATA_ERROR;
default:
return Z_STREAM_ERROR;
}
#ifdef NEED_DUMMY_RETURN
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
#endif
}
int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
z_streamp z;
const Bytef *dictionary;
uInt dictLength;
{
uInt length = dictLength;
if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
return Z_STREAM_ERROR;
if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
z->adler = 1L;
if (length >= ((uInt)1<<z->state->wbits))
{
length = (1<<z->state->wbits)-1;
dictionary += dictLength - length;
}
inflate_set_dictionary(z->state->blocks, dictionary, length);
z->state->mode = BLOCKS;
return Z_OK;
}
int ZEXPORT inflateSync(z)
z_streamp z;
{
uInt n; /* number of bytes to look at */
Bytef *p; /* pointer to bytes */
uInt m; /* number of marker bytes found in a row */
uLong r, w; /* temporaries to save total_in and total_out */
/* set up */
if (z == Z_NULL || z->state == Z_NULL)
return Z_STREAM_ERROR;
if (z->state->mode != BAD)
{
z->state->mode = BAD;
z->state->sub.marker = 0;
}
if ((n = z->avail_in) == 0)
return Z_BUF_ERROR;
p = z->next_in;
m = z->state->sub.marker;
/* search */
while (n && m < 4)
{
static const Byte mark[4] = {0, 0, 0xff, 0xff};
if (*p == mark[m])
m++;
else if (*p)
m = 0;
else
m = 4 - m;
p++, n--;
}
/* restore */
z->total_in += p - z->next_in;
z->next_in = p;
z->avail_in = n;
z->state->sub.marker = m;
/* return no joy or set up to restart on a new block */
if (m != 4)
return Z_DATA_ERROR;
r = z->total_in; w = z->total_out;
inflateReset(z);
z->total_in = r; z->total_out = w;
z->state->mode = BLOCKS;
return Z_OK;
}
/* Returns true if inflate is currently at the end of a block generated
* by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
* implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
* but removes the length bytes of the resulting empty stored block. When
* decompressing, PPP checks that at the end of input packet, inflate is
* waiting for these length bytes.
*/
int ZEXPORT inflateSyncPoint(z)
z_streamp z;
{
if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
return Z_STREAM_ERROR;
return inflate_blocks_sync_point(z->state->blocks);
}

View file

@ -0,0 +1,455 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#if !defined(BUILDFIXED) && !defined(STDC)
# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
#endif
const char inflate_copyright[] =
" inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product.
*/
struct internal_state {int dummy;}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
local int huft_build OF((
uIntf *, /* code lengths in bits */
uInt, /* number of codes */
uInt, /* number of "simple" codes */
const uIntf *, /* list of base values for non-simple codes */
const uIntf *, /* list of extra bits for non-simple codes */
inflate_huft * FAR*,/* result: starting table */
uIntf *, /* maximum lookup bits (returns actual) */
inflate_huft *, /* space for trees */
uInt *, /* hufts used in space */
uIntf * )); /* space for values */
/* Tables for deflate from PKZIP's appnote.txt. */
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
/* see note #13 above about 258 */
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
local const uInt cpdext[30] = { /* Extra bits for distance codes */
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
/*
Huffman code decoding is performed using a multi-level table lookup.
The fastest way to decode is to simply build a lookup table whose
size is determined by the longest code. However, the time it takes
to build this table can also be a factor if the data being decoded
is not very long. The most common codes are necessarily the
shortest codes, so those codes dominate the decoding time, and hence
the speed. The idea is you can have a shorter table that decodes the
shorter, more probable codes, and then point to subsidiary tables for
the longer codes. The time it costs to decode the longer codes is
then traded against the time it takes to make longer tables.
This results of this trade are in the variables lbits and dbits
below. lbits is the number of bits the first level table for literal/
length codes can decode in one step, and dbits is the same thing for
the distance codes. Subsequent tables are also less than or equal to
those sizes. These values may be adjusted either when all of the
codes are shorter than that, in which case the longest code length in
bits is used, or when the shortest code is *longer* than the requested
table size, in which case the length of the shortest code in bits is
used.
There are two different values for the two tables, since they code a
different number of possibilities each. The literal/length table
codes 286 possible values, or in a flat code, a little over eight
bits. The distance table codes 30 possible values, or a little less
than five bits, flat. The optimum values for speed end up being
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
The optimum values may differ though from machine to machine, and
possibly even between compilers. Your mileage may vary.
*/
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
#define BMAX 15 /* maximum bit length of any code */
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
uInt n; /* number of codes (assumed <= 288) */
uInt s; /* number of simple-valued codes (0..s-1) */
const uIntf *d; /* list of base values for non-simple codes */
const uIntf *e; /* list of extra bits for non-simple codes */
inflate_huft * FAR *t; /* result: starting table */
uIntf *m; /* maximum lookup bits, returns actual */
inflate_huft *hp; /* space for trees */
uInt *hn; /* hufts used in space */
uIntf *v; /* working area: values in order of bit length */
/* Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
if the given code set is incomplete (the tables are still built in this
case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
lengths), or Z_MEM_ERROR if not enough memory. */
{
uInt a; /* counter for codes of length k */
uInt c[BMAX+1]; /* bit length count table */
uInt f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
register uInt i; /* counter, current code */
register uInt j; /* counter */
register int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
register uIntf *p; /* pointer into c[], b[], or v[] */
inflate_huft *q; /* points to current table */
struct inflate_huft_s r; /* table entry for structure assignment */
inflate_huft *u[BMAX]; /* table stack */
register int w; /* bits before this table == (l * h) */
uInt x[BMAX+1]; /* bit offsets, then code stack */
uIntf *xp; /* pointer into x */
int y; /* number of dummy codes added */
uInt z; /* number of entries in current table */
/* Generate counts for each bit length */
p = c;
#define C0 *p++ = 0;
#define C2 C0 C0 C0 C0
#define C4 C2 C2 C2 C2
C4 /* clear c[]--assume BMAX+1 is 16 */
p = b; i = n;
do {
c[*p++]++; /* assume all entries <= BMAX */
} while (--i);
if (c[0] == n) /* null input--all zero length codes */
{
*t = (inflate_huft *)Z_NULL;
*m = 0;
return Z_OK;
}
/* Find minimum and maximum length, bound *m by those */
l = *m;
for (j = 1; j <= BMAX; j++)
if (c[j])
break;
k = j; /* minimum code length */
if ((uInt)l < j)
l = j;
for (i = BMAX; i; i--)
if (c[i])
break;
g = i; /* maximum code length */
if ((uInt)l > i)
l = i;
*m = l;
/* Adjust last length count to fill out codes, if needed */
for (y = 1 << j; j < i; j++, y <<= 1)
if ((y -= c[j]) < 0)
return Z_DATA_ERROR;
if ((y -= c[i]) < 0)
return Z_DATA_ERROR;
c[i] += y;
/* Generate starting offsets into the value table for each length */
x[1] = j = 0;
p = c + 1; xp = x + 2;
while (--i) { /* note that i == g from above */
*xp++ = (j += *p++);
}
/* Make a table of values in order of bit lengths */
p = b; i = 0;
do {
if ((j = *p++) != 0)
v[x[j]++] = i;
} while (++i < n);
n = x[g]; /* set n to length of v */
/* Generate the Huffman codes and for each, make the table entries */
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
q = (inflate_huft *)Z_NULL; /* ditto */
z = 0; /* ditto */
/* go through the bit lengths (k already is bits in shortest code) */
for (; k <= g; k++)
{
a = c[k];
while (a--)
{
/* here i is the Huffman code of length k bits for value *p */
/* make tables up to required level */
while (k > w + l)
{
h++;
w += l; /* previous table always l bits */
/* compute minimum size table less than or equal to l bits */
z = g - w;
z = z > (uInt)l ? l : z; /* table size upper limit */
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
{ /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */
xp = c + k;
if (j < z)
while (++j < z) /* try smaller tables up to z bits */
{
if ((f <<= 1) <= *++xp)
break; /* enough codes to use up j bits */
f -= *xp; /* else deduct codes from patterns */
}
}
z = 1 << j; /* table entries for j-bit table */
/* allocate new table */
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
return Z_MEM_ERROR; /* not enough memory */
u[h] = q = hp + *hn;
*hn += z;
/* connect to last table, if there is one */
if (h)
{
x[h] = i; /* save pattern for backing up */
r.bits = (Byte)l; /* bits to dump before this table */
r.exop = (Byte)j; /* bits in this table */
j = i >> (w - l);
r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
u[h-1][j] = r; /* connect to last table */
}
else
*t = q; /* first table is returned result */
}
/* set up table entry in r */
r.bits = (Byte)(k - w);
if (p >= v + n)
r.exop = 128 + 64; /* out of values--invalid code */
else if (*p < s)
{
r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
r.base = *p++; /* simple code is just the value */
}
else
{
r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
r.base = d[*p++ - s];
}
/* fill code-like entries with r */
f = 1 << (k - w);
for (j = i >> w; j < z; j += f)
q[j] = r;
/* backwards increment the k-bit code i */
for (j = 1 << (k - 1); i & j; j >>= 1)
i ^= j;
i ^= j;
/* backup over finished tables */
mask = (1 << w) - 1; /* needed on HP, cc -O bug */
while ((i & mask) != x[h])
{
h--; /* don't need to update q */
w -= l;
mask = (1 << w) - 1;
}
}
}
/* Return Z_BUF_ERROR if we were given an incomplete table */
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
}
int inflate_trees_bits(c, bb, tb, hp, z)
uIntf *c; /* 19 code lengths */
uIntf *bb; /* bits tree desired/actual depth */
inflate_huft * FAR *tb; /* bits tree result */
inflate_huft *hp; /* space for trees */
z_streamp z; /* for messages */
{
int r;
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
tb, bb, hp, &hn, v);
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
else if (r == Z_BUF_ERROR || *bb == 0)
{
z->msg = (char*)"incomplete dynamic bit lengths tree";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
return r;
}
int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
uInt nl; /* number of literal/length codes */
uInt nd; /* number of distance codes */
uIntf *c; /* that many (total) code lengths */
uIntf *bl; /* literal desired/actual bit depth */
uIntf *bd; /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */
inflate_huft * FAR *td; /* distance tree result */
inflate_huft *hp; /* space for trees */
z_streamp z; /* for messages */
{
int r;
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
/* allocate work area */
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
/* build literal/length tree */
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
if (r != Z_OK || *bl == 0)
{
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed literal/length tree";
else if (r != Z_MEM_ERROR)
{
z->msg = (char*)"incomplete literal/length tree";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
return r;
}
/* build distance tree */
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
if (r != Z_OK || (*bd == 0 && nl > 257))
{
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed distance tree";
else if (r == Z_BUF_ERROR) {
#ifdef PKZIP_BUG_WORKAROUND
r = Z_OK;
}
#else
z->msg = (char*)"incomplete distance tree";
r = Z_DATA_ERROR;
}
else if (r != Z_MEM_ERROR)
{
z->msg = (char*)"empty distance tree with lengths";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
return r;
#endif
}
/* done */
ZFREE(z, v);
return Z_OK;
}
/* build fixed tables only once--keep them here */
#ifdef BUILDFIXED
local int fixed_built = 0;
#define FIXEDH 544 /* number of hufts used by fixed tables */
local inflate_huft fixed_mem[FIXEDH];
local uInt fixed_bl;
local uInt fixed_bd;
local inflate_huft *fixed_tl;
local inflate_huft *fixed_td;
#else
#include "inffixed.h"
#endif
int inflate_trees_fixed(bl, bd, tl, td, z)
uIntf *bl; /* literal desired/actual bit depth */
uIntf *bd; /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */
inflate_huft * FAR *td; /* distance tree result */
z_streamp z; /* for memory allocation */
{
#ifdef BUILDFIXED
/* build fixed tables if not already */
if (!fixed_built)
{
int k; /* temporary variable */
uInt f = 0; /* number of hufts used in fixed_mem */
uIntf *c; /* length list for huft_build */
uIntf *v; /* work area for huft_build */
/* allocate memory */
if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
{
ZFREE(z, c);
return Z_MEM_ERROR;
}
/* literal table */
for (k = 0; k < 144; k++)
c[k] = 8;
for (; k < 256; k++)
c[k] = 9;
for (; k < 280; k++)
c[k] = 7;
for (; k < 288; k++)
c[k] = 8;
fixed_bl = 9;
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
fixed_mem, &f, v);
/* distance table */
for (k = 0; k < 30; k++)
c[k] = 5;
fixed_bd = 5;
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
fixed_mem, &f, v);
/* done */
ZFREE(z, v);
ZFREE(z, c);
fixed_built = 1;
}
#endif
*bl = fixed_bl;
*bd = fixed_bd;
*tl = fixed_tl;
*td = fixed_td;
return Z_OK;
}

View file

@ -0,0 +1,58 @@
/* inftrees.h -- header to use inftrees.c
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
/* Huffman code lookup table entry--this entry is four bytes for machines
that have 16-bit pointers (e.g. PC's in the small or medium model). */
typedef struct inflate_huft_s FAR inflate_huft;
struct inflate_huft_s {
union {
struct {
Byte Exop; /* number of extra bits or operation */
Byte Bits; /* number of bits in this code or subcode */
} what;
uInt pad; /* pad structure to a power of 2 (4 bytes for */
} word; /* 16-bit, 8 bytes for 32-bit int's) */
uInt base; /* literal, length base, distance base,
or table offset */
};
/* Maximum size of dynamic tree. The maximum found in a long but non-
exhaustive search was 1004 huft structures (850 for length/literals
and 154 for distances, the latter actually the result of an
exhaustive search). The actual maximum is not known, but the
value below is more than safe. */
#define MANY 1440
extern int inflate_trees_bits OF((
uIntf *, /* 19 code lengths */
uIntf *, /* bits tree desired/actual depth */
inflate_huft * FAR *, /* bits tree result */
inflate_huft *, /* space for trees */
z_streamp)); /* for messages */
extern int inflate_trees_dynamic OF((
uInt, /* number of literal/length codes */
uInt, /* number of distance codes */
uIntf *, /* that many (total) code lengths */
uIntf *, /* literal desired/actual bit depth */
uIntf *, /* distance desired/actual bit depth */
inflate_huft * FAR *, /* literal/length tree result */
inflate_huft * FAR *, /* distance tree result */
inflate_huft *, /* space for trees */
z_streamp)); /* for messages */
extern int inflate_trees_fixed OF((
uIntf *, /* literal desired/actual bit depth */
uIntf *, /* distance desired/actual bit depth */
inflate_huft * FAR *, /* literal/length tree result */
inflate_huft * FAR *, /* distance tree result */
z_streamp)); /* for memory allocation */

View file

@ -0,0 +1,87 @@
/* inflate_util.c -- data and routines common to blocks and codes
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "infblock.h"
#include "inftrees.h"
#include "infcodes.h"
#include "infutil.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
/* And'ing with mask[n] masks the lower n bits */
uInt inflate_mask[17] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
/* copy as much as possible from the sliding window to the output area */
int inflate_flush(s, z, r)
inflate_blocks_statef *s;
z_streamp z;
int r;
{
uInt n;
Bytef *p;
Bytef *q;
/* local copies of source and destination pointers */
p = z->next_out;
q = s->read;
/* compute number of bytes to copy as far as end of window */
n = (uInt)((q <= s->write ? s->write : s->end) - q);
if (n > z->avail_out) n = z->avail_out;
if (n && r == Z_BUF_ERROR) r = Z_OK;
/* update counters */
z->avail_out -= n;
z->total_out += n;
/* update check information */
if (s->checkfn != Z_NULL)
z->adler = s->check = (*s->checkfn)(s->check, q, n);
/* copy as far as end of window */
zmemcpy(p, q, n);
p += n;
q += n;
/* see if more to copy at beginning of window */
if (q == s->end)
{
/* wrap pointers */
q = s->window;
if (s->write == s->end)
s->write = s->window;
/* compute bytes to copy */
n = (uInt)(s->write - q);
if (n > z->avail_out) n = z->avail_out;
if (n && r == Z_BUF_ERROR) r = Z_OK;
/* update counters */
z->avail_out -= n;
z->total_out += n;
/* update check information */
if (s->checkfn != Z_NULL)
z->adler = s->check = (*s->checkfn)(s->check, q, n);
/* copy */
zmemcpy(p, q, n);
p += n;
q += n;
}
/* update pointers */
z->next_out = p;
s->read = q;
/* done */
return r;
}

View file

@ -0,0 +1,98 @@
/* infutil.h -- types and macros common to blocks and codes
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
#ifndef _INFUTIL_H
#define _INFUTIL_H
typedef enum {
TYPE, /* get type bits (3, including end bit) */
LENS, /* get lengths for stored */
STORED, /* processing stored block */
TABLE, /* get table lengths */
BTREE, /* get bit lengths tree for a dynamic block */
DTREE, /* get length, distance trees for a dynamic block */
CODES, /* processing fixed or dynamic block */
DRY, /* output remaining window bytes */
DONE, /* finished last block, done */
BAD} /* got a data error--stuck here */
inflate_block_mode;
/* inflate blocks semi-private state */
struct inflate_blocks_state {
/* mode */
inflate_block_mode mode; /* current inflate_block mode */
/* mode dependent information */
union {
uInt left; /* if STORED, bytes left to copy */
struct {
uInt table; /* table lengths (14 bits) */
uInt index; /* index into blens (or border) */
uIntf *blens; /* bit lengths of codes */
uInt bb; /* bit length tree depth */
inflate_huft *tb; /* bit length decoding tree */
} trees; /* if DTREE, decoding info for trees */
struct {
inflate_codes_statef
*codes;
} decode; /* if CODES, current state */
} sub; /* submode */
uInt last; /* true if this block is the last block */
/* mode independent information */
uInt bitk; /* bits in bit buffer */
uLong bitb; /* bit buffer */
inflate_huft *hufts; /* single malloc for tree space */
Bytef *window; /* sliding window */
Bytef *end; /* one byte after sliding window */
Bytef *read; /* window read pointer */
Bytef *write; /* window write pointer */
check_func checkfn; /* check function */
uLong check; /* check on output */
};
/* defines for inflate input/output */
/* update pointers and return */
#define UPDBITS {s->bitb=b;s->bitk=k;}
#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
#define UPDOUT {s->write=q;}
#define UPDATE {UPDBITS UPDIN UPDOUT}
#define LEAVE {UPDATE return inflate_flush(s,z,r);}
/* get bytes and bits */
#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
#define NEXTBYTE (n--,*p++)
#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
#define DUMPBITS(j) {b>>=(j);k-=(j);}
/* output bytes */
#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
/* load local pointers */
#define LOAD {LOADIN LOADOUT}
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
extern uInt inflate_mask[17];
/* copy as much as possible from the sliding window to the output area */
extern int inflate_flush OF((
inflate_blocks_statef *,
z_streamp ,
int));
struct internal_state {int dummy;}; /* for buggy compilers */
#endif

View file

@ -0,0 +1,275 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 0.15 beta, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip */
#ifndef _unz_H
#define _unz_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagunzFile__ { int unused; } unzFile__;
typedef unzFile__ *unzFile;
#else
typedef voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
} unz_file_info;
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
const char* fileName2,
int iCaseSensitivity));
/*
Compare two filename (fileName1,fileName2).
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
or strcasecmp)
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
(like 1 on Unix, 2 on Windows)
*/
extern unzFile ZEXPORT unzOpen OF((const char *path));
/*
Open a Zip file. path contain the full pathname (by example,
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
"zlib/zlib111.zip".
If the zipfile cannot be opened (file don't exist or in not valid), the
return value is NULL.
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
extern int ZEXPORT unzClose OF((unzFile file));
/*
Close a ZipFile opened with unzipOpen.
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
unz_global_info *pglobal_info));
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
char *szComment,
uLong uSizeBuf));
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0
*/
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
/*
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
/*
Set the current file of the zipfile to the next file.
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
extern int ZEXPORT unzLocateFile OF((unzFile file,
const char *szFileName,
int iCaseSensitivity));
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
unz_file_info *pfile_info,
char *szFileName,
uLong fileNameBufferSize,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
uLong commentBufferSize));
/*
Get Info about the current file
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
/***************************************************************************/
/* for reading the content of the current zipfile, you can open it, read data
from it, and close it (you can close it before reading all the file)
*/
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
/*
Open for reading data the current file in the zipfile.
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
/*
Close the file in zip opened with unzOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
voidp buf,
unsigned len));
/*
Read bytes from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
extern z_off_t ZEXPORT unztell OF((unzFile file));
/*
Give the current position in uncompressed data
*/
extern int ZEXPORT unzeof OF((unzFile file));
/*
return 1 if the end of file was reached, 0 elsewhere
*/
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
voidp buf,
unsigned len));
/*
Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of bytes copied in buf, or (if <0)
the error code
*/
#ifdef __cplusplus
}
#endif
#endif /* _unz_H */

1295
Contrib/zip2exe/zlib/Unzip.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,279 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef _ZCONF_H
#define _ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateReset z_inflateReset
# define compress z_compress
# define compress2 z_compress2
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
# ifndef __32BIT__
# define __32BIT__
# endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
# define STDC
#endif
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
# ifndef STDC
# define STDC
# endif
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Old Borland C incorrectly complains about missing returns: */
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
# define NEED_DUMMY_RETURN
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
# define FAR _far
# endif
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
#if defined(ZLIB_DLL)
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR _cdecl _export
# endif
# endif
# if defined (__BORLANDC__)
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
# include <windows.h>
# define ZEXPORT __declspec(dllexport) WINAPI
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
# else
# if defined (_Windows) && defined (__DLL__)
# define ZEXPORT _export
# define ZEXPORTVA _export
# endif
# endif
# endif
#endif
#if defined (__BEOS__)
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#ifdef HAVE_UNISTD_H
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(inflate_blocks,"INBL")
# pragma map(inflate_blocks_new,"INBLNE")
# pragma map(inflate_blocks_free,"INBLFR")
# pragma map(inflate_blocks_reset,"INBLRE")
# pragma map(inflate_codes_free,"INCOFR")
# pragma map(inflate_codes,"INCO")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_flush,"INFLU")
# pragma map(inflate_mask,"INMA")
# pragma map(inflate_set_dictionary,"INSEDI2")
# pragma map(inflate_copyright,"INCOPY")
# pragma map(inflate_trees_bits,"INTRBI")
# pragma map(inflate_trees_dynamic,"INTRDY")
# pragma map(inflate_trees_fixed,"INTRFI")
# pragma map(inflate_trees_free,"INTRFR")
#endif
#endif /* _ZCONF_H */

893
Contrib/zip2exe/zlib/ZLIB.H Normal file
View file

@ -0,0 +1,893 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.3, July 9th, 1998
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
#ifndef _ZLIB_H
#define _ZLIB_H
#include "zconf.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ZLIB_VERSION "1.1.3"
/*
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
(deflation) but other algorithms will be added later and will have the same
stream interface.
Compression can be done in a single step if the buffers are large
enough (for example if an input file is mmap'ed), or can be done by
repeated calls of the compression function. In the latter case, the
application must provide more input and/or consume the output
(providing more output space) before each call.
The library also supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio.
The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never
crash even in case of corrupted input.
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
/*
The application must update next_in and avail_in when avail_in has
dropped to zero. It must update next_out and avail_out when avail_out
has dropped to zero. The application must initialize zalloc, zfree and
opaque before calling the init function. All other fields are set by the
compression library and must not be updated by the application.
The opaque value provided by the application will be passed as the first
parameter for calls of zalloc and zfree. This can be useful for custom
memory management. The compression library attaches no meaning to the
opaque value.
zalloc must return Z_NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be
thread safe.
On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
pointers returned by zalloc for objects of exactly 65536 bytes *must*
have their offset normalized to zero. The default allocation function
provided by this library ensures this (see zutil.c). To reduce memory
requirements and avoid any allocation of 64K objects, at the expense of
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
The fields total_in and total_out can be used for statistics or
progress reports. After compression, total_in holds the total size of
the uncompressed data and may be saved for use in the decompressor
(particularly if the decompressor wants to decompress everything in
a single step).
*/
/* constants */
#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
/* Allowed flush values; see deflate() below for details */
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
#define Z_BINARY 0
#define Z_ASCII 1
#define Z_UNKNOWN 2
/* Possible values of the data_type field */
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */
/* basic functions */
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
This check is automatically made by deflateInit and inflateInit.
*/
/*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
use default allocation functions.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at
all (the input data is simply copied a block at a time).
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
compression (currently equivalent to level 6).
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
with the version assumed by the caller (ZLIB_VERSION).
msg is set to null if there is no error message. deflateInit does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/*
deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce some
output latency (reading input without producing any output) except when
forced to flush.
The detailed semantics are as follows. deflate performs one or both of the
following actions:
- Compress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications).
Some output may be provided even if flush is not set.
Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating avail_in or avail_out accordingly; avail_out
should never be zero before the call. The application can consume the
compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
and with zero avail_out, it must be called again after making room in the
output buffer because there might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
flushed to the output buffer and the output is aligned on a byte boundary, so
that the decompressor can get all input data available so far. (In particular
avail_in is zero after the call if enough output space has been provided
before the call.) Flushing may degrade compression for some compression
algorithms and so it should be used only when necessary.
If flush is set to Z_FULL_FLUSH, all output is flushed as with
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
restart from this point if previous compressed data has been damaged or if
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
the compression.
If deflate returns with avail_out == 0, this function must be called again
with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero
avail_out).
If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there
was enough output space; if deflate returns with Z_OK, this function must be
called again with Z_FINISH and more output space (updated avail_out) but no
more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the
stream are deflateReset or deflateEnd.
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least
0.1% larger than avail_in plus 12 bytes. If deflate does not return
Z_STREAM_END, then it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
deflate() may update data_type if it can make a good guess about
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
binary. This field is only for information purposes and does not affect
the compression algorithm in any manner.
deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
(for example avail_in or avail_out was zero).
*/
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded). In the error case,
msg may be set but then points to a static string (which must not be
deallocated).
*/
/*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
value depends on the compression method), inflateInit determines the
compression method from the zlib header and allocates all data structures
accordingly; otherwise the allocation will be deferred to the first call of
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
use default allocation functions.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller. msg is set to null if there is no error
message. inflateInit does not perform any decompression apart from reading
the zlib header if present: this will be done by inflate(). (So next_in and
avail_in may be modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/*
inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may some
introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. inflate performs one or both of the
following actions:
- Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in is updated and processing
will resume at this point for the next call of inflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there
is no more input data or no more space in the output buffer (see below
about the flush parameter).
Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly.
The application can consume the uncompressed output when it wants, for
example when the output buffer is full (avail_out == 0), or after each
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
must be called again after making room in the output buffer because there
might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
output as possible to the output buffer. The flushing behavior of inflate is
not specified for values of the flush parameter other than Z_SYNC_FLUSH
and Z_FINISH, but the current implementation actually flushes as much output
as possible anyway.
inflate() should normally be called until it returns Z_STREAM_END or an
error. However if all decompression is to be performed in a single step
(a single call of inflate), the parameter flush should be set to
Z_FINISH. In this case all pending input is processed and all pending
output is flushed; avail_out must be large enough to hold all the
uncompressed data. (The size of the uncompressed data may have been saved
by the compressor for this purpose.) The next operation on this stream must
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
is never required, but can be used to inform inflate that a faster routine
may be used for the single inflate() call.
If a preset dictionary is needed at this point (see inflateSetDictionary
below), inflate sets strm-adler to the adler32 checksum of the
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
it sets strm->adler to the adler32 checksum of all output produced
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
an error code as described below. At the end of the stream, inflate()
checks that its computed adler32 checksum is equal to that saved by the
compressor and returns Z_STREAM_END only if the checksum is correct.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
corrupted (input stream not conforming to the zlib format or incorrect
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
case, the application may then call inflateSync to look for a good
compression block.
*/
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
was inconsistent. In the error case, msg may be set but then points to a
static string (which must not be deallocated).
*/
/* Advanced functions */
/*
The following functions are needed only in some special applications.
*/
/*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy));
This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by
the caller.
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library.
The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this
version of the library. Larger values of this parameter result in better
compression at the expense of memory usage. The default value is 15 if
deflateInit is used instead.
The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but
is slow and reduces compression ratio; memLevel=9 uses maximum memory
for optimal speed. The default value is 8. See zconf.h for total memory
usage as a function of windowBits and memLevel.
The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
string match). Filtered data consists mostly of small values with a
somewhat random distribution. In this case, the compression algorithm is
tuned to compress them better. The effect of Z_FILTERED is to force more
Huffman coding and less string matching; it is somewhat intermediate
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
the compression ratio but not the correctness of the compressed output even
if it is not set appropriately.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
method). msg is set to null if there is no error message. deflateInit2 does
not perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence
without producing any compressed output. This function must be called
immediately after deflateInit, deflateInit2 or deflateReset, before any
call of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and can be
predicted with good accuracy; the data can then be compressed better than
with the default empty dictionary.
Depending on the size of the compression data structures selected by
deflateInit or deflateInit2, a part of the dictionary may in effect be
discarded, for example if the dictionary is larger than the window size in
deflate or deflate2. Thus the strings most likely to be useful should be
put at the end of the dictionary, not at the front.
Upon return of this function, strm->adler is set to the Adler32 value
of the dictionary; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.)
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent (for example if deflate has already been called for this stream
or if the compression method is bsort). deflateSetDictionary does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.
This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed
by calling deflateEnd. Note that deflateCopy duplicates the internal
compression state which can be quite large, so this strategy is slow and
can consume lots of memory.
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being NULL). msg is left unchanged in both source and
destination.
*/
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state.
The stream will keep the same compression level and any other attributes
that may have been set by deflateInit2.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level,
int strategy));
/*
Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in deflateInit2. This can be
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different
strategy. If the compression level is changed, the input available so far
is compressed with the old level (and may be flushed); the new level will
take effect only at the next call of deflate().
Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to
be compressed and flushed. In particular, strm->avail_out must be non-zero.
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
if strm->avail_out was zero.
*/
/*
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits));
This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
before by the caller.
The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if inflateInit is used
instead. If a compressed stream with a larger window size is given as
input, inflate() will return with the error code Z_DATA_ERROR instead of
trying to allocate a larger window.
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
memLevel). msg is set to null if there is no error message. inflateInit2
does not perform any decompression apart from reading the zlib header if
present: this will be done by inflate(). (So next_in and avail_in may be
modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the Adler32 value returned by this call of
inflate. The compressor and decompressor must use exactly the same
dictionary (see deflateSetDictionary).
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
expected one (incorrect Adler32 value). inflateSetDictionary does not
perform any decompression: this will be done by subsequent calls of
inflate().
*/
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until a full flush point (see above the
description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
case, the application may save the current current value of total_in which
indicates where valid compressed data was found. In the error case, the
application may repeatedly call inflateSync, providing more input each time,
until success or end of the input data.
*/
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state.
The stream will keep attributes that may have been set by inflateInit2.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
/* utility functions */
/*
The following utility functions are implemented on top of the
basic stream-oriented functions. To simplify the interface, some
default options are assumed (compression level and memory usage,
standard memory allocation functions). The source code of these
utility functions can easily be modified if you need special options.
*/
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be at least 0.1% larger than
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
compressed buffer.
This function can be used to compress a whole file at once if the
input file is mmap'ed.
compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer.
*/
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen,
int level));
/*
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
typedef voidp gzFile;
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
Huffman only compression as in "wb1h". (See the description
of deflateInit2 for more information about the strategy parameter.)
gzopen can be used to read a file which is not in gzip format; in this
case gzread will directly read from the file without decompression.
gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR). */
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
fileno (in the file has been previously opened with fopen).
The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
gzdopen returns NULL if there was insufficient memory to allocate
the (de)compression state.
*/
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
Dynamically update the compression level or strategy. See the description
of deflateInit2 for the meaning of these parameters.
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
opened for writing.
*/
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number
of bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
const voidp buf, unsigned len));
/*
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written
(0 in case of error).
*/
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the args to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written (0 in case of error).
*/
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/*
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
*/
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/*
Reads bytes from the compressed file until len-1 characters are read, or
a newline character is read and transferred to buf, or an end-of-file
condition is encountered. The string is then terminated with a null
character.
gzgets returns buf, or Z_NULL in case of error.
*/
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/*
Writes c, converted to an unsigned char, into the compressed file.
gzputc returns the value that was written, or -1 in case of error.
*/
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte
or -1 in case of end of file or error.
*/
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function. The return value is the zlib
error number (see function gzerror below). gzflush returns Z_OK if
the flush parameter is Z_FINISH and all output could be flushed.
gzflush should be called only when strictly necessary because it can
degrade compression.
*/
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
/*
Sets the starting position for the next gzread or gzwrite on the
given compressed file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported.
If the file is opened for reading, this function is emulated but can be
extremely slow. If the file is opened for writing, only forward seeks are
supported; gzseek then compresses a sequence of zeroes up to the new
starting position.
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position
would be before the current position.
*/
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/*
Rewinds the given file. This function is supported only for reading.
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
*/
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
Returns the starting position for the next gzread or gzwrite on the
given compressed file. This position represents a number of bytes in the
uncompressed data stream.
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/*
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
*/
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state. The return value is the zlib
error number (see function gzerror below).
*/
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
error occurred in the file system and not in the compression library,
errnum is set to Z_ERRNO and the application may consult errno
to get the exact error code.
*/
/* checksum functions */
/*
These functions are not related to compression but are exported
anyway because they might be useful in applications using the
compression library.
*/
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is NULL, this function returns
the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
uLong adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
*/
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value
for the crc. Pre- and post-conditioning (one's complement) is performed
within this function so it shouldn't be done by the application.
Usage example:
uLong crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
*/
/* various hacks, don't look :) */
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size));
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel,
int strategy, const char *version,
int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
ZEXTERN const char * ZEXPORT zError OF((int err));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
#ifdef __cplusplus
}
#endif
#endif /* _ZLIB_H */

View file

@ -0,0 +1,220 @@
/* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
/* @(#) $Id$ */
#ifndef _Z_UTIL_H
#define _Z_UTIL_H
#include "zlib.h"
#ifdef STDC
# include <stddef.h>
# include <string.h>
# include <stdlib.h>
#endif
#ifdef NO_ERRNO_H
extern int errno;
#else
# include <errno.h>
#endif
#ifndef local
# define local static
#endif
/* compile with -Dlocal if your debugger can't find static symbols */
typedef unsigned char uch;
typedef uch FAR uchf;
typedef unsigned short ush;
typedef ush FAR ushf;
typedef unsigned long ulg;
extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
#define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */
/* common constants */
#ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
/* default memLevel */
#define STORED_BLOCK 0
#define STATIC_TREES 1
#define DYN_TREES 2
/* The three kinds of block type */
#define MIN_MATCH 3
#define MAX_MATCH 258
/* The minimum and maximum match lengths */
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
/* target dependencies */
#ifdef MSDOS
# define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
/* Allow compilation with ANSI keywords only enabled */
void _Cdecl farfree( void *block );
void *_Cdecl farmalloc( unsigned long nbytes );
# else
# include <alloc.h>
# endif
# else /* MSC or DJGPP */
# include <malloc.h>
# endif
#endif
#ifdef OS2
# define OS_CODE 0x06
#endif
#ifdef WIN32 /* Window 95 & Windows NT */
# define OS_CODE 0x0b
#endif
#if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02
# define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
#ifdef AMIGA
# define OS_CODE 0x01
#endif
#if defined(ATARI) || defined(atarist)
# define OS_CODE 0x05
#endif
#if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */
# else
# ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */
# endif
# endif
#endif
#ifdef __50SERIES /* Prime/PRIMOS */
# define OS_CODE 0x0F
#endif
#ifdef TOPS20
# define OS_CODE 0x0a
#endif
#if defined(_BEOS_) || defined(RISCOS)
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif
#if (defined(_MSC_VER) && (_MSC_VER > 600))
# define fdopen(fd,type) _fdopen(fd,type)
#endif
/* Common defaults */
#ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
#endif
#ifndef F_OPEN
# define F_OPEN(name, mode) fopen((name), (mode))
#endif
/* functions */
#ifdef HAVE_STRERROR
extern char *strerror OF((int));
# define zstrerror(errnum) strerror(errnum)
#else
# define zstrerror(errnum) ""
#endif
#if defined(pyr)
# define NO_MEMCPY
#endif
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
/* Use our own functions for small and medium model with MSC <= 5.0.
* You may have to use the same strategy for Borland C (untested).
* The __SC__ check is for Symantec.
*/
# define NO_MEMCPY
#endif
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
# define HAVE_MEMCPY
#endif
#ifdef HAVE_MEMCPY
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
# define zmemcpy _fmemcpy
# define zmemcmp _fmemcmp
# define zmemzero(dest, len) _fmemset(dest, 0, len)
# else
# define zmemcpy memcpy
# define zmemcmp memcmp
# define zmemzero(dest, len) memset(dest, 0, len)
# endif
#else
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
extern void zmemzero OF((Bytef* dest, uInt len));
#endif
/* Diagnostic functions */
#ifdef DEBUG
# include <stdio.h>
extern int z_verbose;
extern void z_error OF((char *m));
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
#else
# define Assert(cond,msg)
# define Trace(x)
# define Tracev(x)
# define Tracevv(x)
# define Tracec(c,x)
# define Tracecv(c,x)
#endif
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
uInt len));
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
void zcfree OF((voidpf opaque, voidpf ptr));
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
#endif /* _Z_UTIL_H */

View file

@ -0,0 +1,226 @@
/* zutil.c -- target dependent utility functions for the compression library
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include <windows.h>
#include "zutil.h"
struct internal_state {int dummy;}; /* for buggy compilers */
#ifndef STDC
extern void exit OF((int));
#endif
const char *z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */
"file error", /* Z_ERRNO (-1) */
"stream error", /* Z_STREAM_ERROR (-2) */
"data error", /* Z_DATA_ERROR (-3) */
"insufficient memory", /* Z_MEM_ERROR (-4) */
"buffer error", /* Z_BUF_ERROR (-5) */
"incompatible version",/* Z_VERSION_ERROR (-6) */
""};
const char * ZEXPORT zlibVersion()
{
return ZLIB_VERSION;
}
#ifdef DEBUG
# ifndef verbose
# define verbose 0
# endif
int z_verbose = verbose;
void z_error (m)
char *m;
{
fprintf(stderr, "%s\n", m);
exit(1);
}
#endif
/* exported to allow conversion of error code to string for compress() and
* uncompress()
*/
const char * ZEXPORT zError(err)
int err;
{
return ERR_MSG(err);
}
#ifndef HAVE_MEMCPY
void zmemcpy(dest, source, len)
Bytef* dest;
const Bytef* source;
uInt len;
{
if (len == 0) return;
do {
*dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0);
}
int zmemcmp(s1, s2, len)
const Bytef* s1;
const Bytef* s2;
uInt len;
{
uInt j;
for (j = 0; j < len; j++) {
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
}
return 0;
}
void zmemzero(dest, len)
Bytef* dest;
uInt len;
{
if (len == 0) return;
do {
*dest++ = 0; /* ??? to be unrolled */
} while (--len != 0);
}
#endif
#ifdef __TURBOC__
#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
/* Small and medium model in Turbo C are for now limited to near allocation
* with reduced MAX_WBITS and MAX_MEM_LEVEL
*/
# define MY_ZCALLOC
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
* and farmalloc(64K) returns a pointer with an offset of 8, so we
* must fix the pointer. Warning: the pointer must be put back to its
* original form in order to free it, use zcfree().
*/
#define MAX_PTR 10
/* 10*64K = 640K */
local int next_ptr = 0;
typedef struct ptr_table_s {
voidpf org_ptr;
voidpf new_ptr;
} ptr_table;
local ptr_table table[MAX_PTR];
/* This table is used to remember the original form of pointers
* to large buffers (64K). Such pointers are normalized with a zero offset.
* Since MSDOS is not a preemptive multitasking OS, this table is not
* protected from concurrent access. This hack doesn't work anyway on
* a protected system like OS/2. Use Microsoft C instead.
*/
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{
voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size;
/* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized.
*/
if (bsize < 65520L) {
buf = farmalloc(bsize);
if (*(ush*)&buf != 0) return buf;
} else {
buf = farmalloc(bsize + 16L);
}
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
table[next_ptr].org_ptr = buf;
/* Normalize the pointer to seg:0 */
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
*(ush*)&buf = 0;
table[next_ptr++].new_ptr = buf;
return buf;
}
void zcfree (voidpf opaque, voidpf ptr)
{
int n;
if (*(ush*)&ptr != 0) { /* object < 64K */
farfree(ptr);
return;
}
/* Find the original pointer */
for (n = 0; n < next_ptr; n++) {
if (ptr != table[n].new_ptr) continue;
farfree(table[n].org_ptr);
while (++n < next_ptr) {
table[n-1] = table[n];
}
next_ptr--;
return;
}
ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found");
}
#endif
#endif /* __TURBOC__ */
#if defined(M_I86) && !defined(__32BIT__)
/* Microsoft C in 16-bit mode */
# define MY_ZCALLOC
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
# define _halloc halloc
# define _hfree hfree
#endif
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{
if (opaque) opaque = 0; /* to make compiler happy */
return _halloc((long)items, size);
}
void zcfree (voidpf opaque, voidpf ptr)
{
if (opaque) opaque = 0; /* to make compiler happy */
_hfree(ptr);
}
#endif /* MSC */
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC
extern voidp calloc OF((uInt items, uInt size));
extern void free OF((voidpf ptr));
#endif
voidpf zcalloc (opaque, items, size)
voidpf opaque;
unsigned items;
unsigned size;
{
if (opaque) items += size - size; /* make compiler happy */
return (voidpf)GlobalAlloc(GPTR,items*size);
}
void zcfree (opaque, ptr)
voidpf opaque;
voidpf ptr;
{
if (ptr) GlobalFree(ptr);
if (opaque) return; /* make compiler happy */
}
#endif /* MY_ZCALLOC */

164
Examples/WinMessages.NSH Normal file
View file

@ -0,0 +1,164 @@
; KiCHiK put together this list of WM_ messages.
!define WM_NULL 0x0
!define WM_CREATE 0x1
!define WM_DESTROY 0x2
!define WM_MOVE 0x3
!define WM_SIZE 0x5
!define WM_SETFOCUS 0x7
!define WM_KILLFOCUS 0x8
!define WM_ENABLE 0xA
!define WM_SETREDRAW 0xB
!define WM_SETTEXT 0xC
!define WM_GETTEXT 0xD
!define WM_GETTEXTLENGTH 0xE
!define WM_PAINT 0xF
!define WM_CLOSE 0x10
!define WM_QUERYENDSESSION 0x11
!define WM_QUIT 0x12
!define WM_QUERYOPEN 0x13
!define WM_ERASEBKGND 0x14
!define WM_SYSCOLORCHANGE 0x15
!define WM_ENDSESSION 0x16
!define WM_SHOWWINDOW 0x18
!define WM_WININICHANGE 0x1A
!define WM_DEVMODECHANGE 0x1B
!define WM_ACTIVATEAPP 0x1C
!define WM_FONTCHANGE 0x1D
!define WM_TIMECHANGE 0x1E
!define WM_CANCELMODE 0x1F
!define WM_SETCURSOR 0x20
!define WM_MOUSEACTIVATE 0x21
!define WM_CHILDACTIVATE 0x22
!define WM_QUEUESYNC 0x23
!define WM_GETMINMAXINFO 0x24
!define WM_PAINTICON 0x26
!define WM_ICONERASEBKGND 0x27
!define WM_NEXTDLGCTL 0x28
!define WM_SPOOLERSTATUS 0x2A
!define WM_DRAWITEM 0x2B
!define WM_MEASUREITEM 0x2C
!define WM_DELETEITEM 0x2D
!define WM_VKEYTOITEM 0x2E
!define WM_CHARTOITEM 0x2F
!define WM_SETFONT 0x30
!define WM_GETFONT 0x31
!define WM_SETHOTKEY 0x32
!define WM_GETHOTKEY 0x33
!define WM_QUERYDRAGICON 0x37
!define WM_COMPAREITEM 0x39
!define WM_COMPACTING 0x41
!define WM_WINDOWPOSCHANGING 0x46
!define WM_WINDOWPOSCHANGED 0x47
!define WM_POWER 0x48
!define WM_COPYDATA 0x4A
!define WM_CANCELJOURNAL 0x4B
!define WM_NCCREATE 0x81
!define WM_NCDESTROY 0x82
!define WM_NCCALCSIZE 0x83
!define WM_NCHITTEST 0x84
!define WM_NCPAINT 0x85
!define WM_NCACTIVATE 0x86
!define WM_GETDLGCODE 0x87
!define WM_NCMOUSEMOVE 0xA0
!define WM_NCLBUTTONDOWN 0xA1
!define WM_NCLBUTTONUP 0xA2
!define WM_NCLBUTTONDBLCLK 0xA3
!define WM_NCRBUTTONDOWN 0xA4
!define WM_NCRBUTTONUP 0xA5
!define WM_NCRBUTTONDBLCLK 0xA6
!define WM_NCMBUTTONDOWN 0xA7
!define WM_NCMBUTTONUP 0xA8
!define WM_NCMBUTTONDBLCLK 0xA9
!define WM_KEYFIRST 0x100
!define WM_KEYDOWN 0x100
!define WM_KEYUP 0x101
!define WM_CHAR 0x102
!define WM_DEADCHAR 0x103
!define WM_SYSKEYDOWN 0x104
!define WM_SYSKEYUP 0x105
!define WM_SYSCHAR 0x106
!define WM_SYSDEADCHAR 0x107
!define WM_KEYLAST 0x108
!define WM_INITDIALOG 0x110
!define WM_COMMAND 0x111
!define WM_SYSCOMMAND 0x112
!define WM_TIMER 0x113
!define WM_HSCROLL 0x114
!define WM_VSCROLL 0x115
!define WM_INITMENU 0x116
!define WM_INITMENUPOPUP 0x117
!define WM_MENUSELECT 0x11F
!define WM_MENUCHAR 0x120
!define WM_ENTERIDLE 0x121
!define WM_CTLCOLORMSGBOX 0x132
!define WM_CTLCOLOREDIT 0x133
!define WM_CTLCOLORLISTBOX 0x134
!define WM_CTLCOLORBTN 0x135
!define WM_CTLCOLORDLG 0x136
!define WM_CTLCOLORSCROLLBAR 0x137
!define WM_CTLCOLORSTATIC 0x138
!define WM_MOUSEFIRST 0x200
!define WM_MOUSEMOVE 0x200
!define WM_LBUTTONDOWN 0x201
!define WM_LBUTTONUP 0x202
!define WM_LBUTTONDBLCLK 0x203
!define WM_RBUTTONDOWN 0x204
!define WM_RBUTTONUP 0x205
!define WM_RBUTTONDBLCLK 0x206
!define WM_MBUTTONDOWN 0x207
!define WM_MBUTTONUP 0x208
!define WM_MBUTTONDBLCLK 0x209
!define WM_MOUSELAST 0x209
!define WM_PARENTNOTIFY 0x210
!define WM_ENTERMENULOOP 0x211
!define WM_EXITMENULOOP 0x212
!define WM_MDICREATE 0x220
!define WM_MDIDESTROY 0x221
!define WM_MDIACTIVATE 0x222
!define WM_MDIRESTORE 0x223
!define WM_MDINEXT 0x224
!define WM_MDIMAXIMIZE 0x225
!define WM_MDITILE 0x226
!define WM_MDICASCADE 0x227
!define WM_MDIICONARRANGE 0x228
!define WM_MDIGETACTIVE 0x229
!define WM_MDISETMENU 0x230
!define WM_DROPFILES 0x233
!define WM_MDIREFRESHMENU 0x234
!define WM_CUT 0x300
!define WM_COPY 0x301
!define WM_PASTE 0x302
!define WM_CLEAR 0x303
!define WM_UNDO 0x304
!define WM_RENDERFORMAT 0x305
!define WM_RENDERALLFORMATS 0x306
!define WM_DESTROYCLIPBOARD 0x307
!define WM_DRAWCLIPBOARD 0x308
!define WM_PAINTCLIPBOARD 0x309
!define WM_VSCROLLCLIPBOARD 0x30A
!define WM_SIZECLIPBOARD 0x30B
!define WM_ASKCBFORMATNAME 0x30C
!define WM_CHANGECBCHAIN 0x30D
!define WM_HSCROLLCLIPBOARD 0x30E
!define WM_QUERYNEWPALETTE 0x30F
!define WM_PALETTEISCHANGING 0x310
!define WM_PALETTECHANGED 0x311
!define WM_HOTKEY 0x312
!define WM_PENWINFIRST 0x380
!define WM_PENWINLAST 0x38F
!define WM_USER 0x400
!define WM_DDE_FIRST 0x3E0
!define WM_CONVERTREQUESTEX 0x108
!define WM_IME_STARTCOMPOSITION 0x10D
!define WM_IME_ENDCOMPOSITION 0x10E
!define WM_IME_COMPOSITION 0x10F
!define WM_IME_KEYLAST 0x10F
!define WM_IME_SETCONTEXT 0x281
!define WM_IME_NOTIFY 0x282
!define WM_IME_CONTROL 0x283
!define WM_IME_COMPOSITIONFULL 0x284
!define WM_IME_SELECT 0x285
!define WM_IME_CHAR 0x286
!define WM_IME_KEYDOWN 0x290
!define WM_IME_KEYUP 0x291

239
Examples/bigtest.nsi Normal file
View file

@ -0,0 +1,239 @@
; bigtest.nsi
;
; This script attempts to test most of the functionality of NSIS.
;
!ifdef HAVE_UPX
!packhdr tmp.dat "upx\upx -9 tmp.dat"
!endif
!ifdef NOCOMPRESS
SetCompress off
!endif
SetDateSave on
SetDatablockOptimize on
CRCCheck on
SilentInstall normal
BGGradient 000000 800000 FFFFFF
InstallColors FF8080 000030
Name "BigNSISTest"
Caption "NSIS Big Test"
Icon "..\contrib\Icons\normal-install.ico"
OutFile "bigtest.exe"
LicenseText "make sure this license text is all there (it's about 28k last I checked). The last line is a simple '}'."
LicenseData "..\source\exehead\main.c"
InstallDir "$PROGRAMFILES\NSISCrap\BigNSISTest"
InstallDirRegKey HKLM SOFTWARE\NSISCrap\BigNSISTest "Install_Dir"
DirText "Choose a directory to install in to:"
; uninstall stuff
UninstallText "This will uninstall example2. Hit next to continue."
UninstallIcon "..\contrib\Icons\normal-uninstall.ico"
ComponentText "This will install the test on your computer. Select which optional things you want installed."
CheckBitmap ..\contrib\Icons\checksX.bmp
!ifndef NOINSTTYPES ; only if not defined
InstType "Most"
InstType "Full"
InstType "More"
InstType "Base"
;InstType /NOCUSTOM
;InstType /COMPONENTSONLYONCUSTOM
!endif
AutoCloseWindow false
ShowInstDetails show
Section "" ; empty string makes it hidden, so would starting with -
; write reg crap
StrCpy $1 "POOOOOOOOOOOP"
DetailPrint "I like to f*ck sheep $1"
WriteRegStr HKLM SOFTWARE\NSISCrap\BigNSISTest "Install_Dir" "$INSTDIR"
; write uninstall strings
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "DisplayName" "BigNSISTest (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "UninstallString" '"$INSTDIR\bt-uninst.exe"'
#File /oname=poop.exe makensisw.exe
SetOutPath $INSTDIR
File /a "..\source\exehead\bin2h.exe"
CreateDirectory "$INSTDIR\shiz\crap" ; 2 recursively create a directory for fun.
WriteUninstaller "bt-uninst.exe"
Nop ; for fun
SectionEnd
Section "TempTest"
SectionIn 1 2 3
Start: MessageBox MB_OK "Start:"
MessageBox MB_YESNO "Goto Poop" IDYES Poop
MessageBox MB_OK "Right before Poop:"
Poop: MessageBox MB_OK "Poop:"
MessageBox MB_OK "Right after Poop:"
MessageBox MB_YESNO "Goto Start:?" IDYES Start
SectionEnd
Function poopTest
ReadINIStr $1 "$INSTDIR\test.ini" "MySectionShit" "Value1"
StrCmp $1 $8 NoFailedMsg
MessageBox MB_OK "WriteINIStr failed"
NoFailedMsg: FunctionEnd
SubSection /e SubSection1
Section "Test Registry/INI functions"
SectionIn 1 4 3
WriteRegStr HKLM SOFTWARE\NSISCrap\BigNSISTest "StrTest_INSTDIR" "$INSTDIR"
WriteRegDword HKLM SOFTWARE\NSISCrap\BigNSISTest "DwordTest_0xDEADBEEF" 0xdeadbeef
WriteRegDword HKLM SOFTWARE\NSISCrap\BigNSISTest "DwordTest_123456" 123456
WriteRegDword HKLM SOFTWARE\NSISCrap\BigNSISTest "DwordTest_0123" 0123
WriteRegBin HKLM SOFTWARE\NSISCrap\BigNSISTest "BinTest_deadbeef01f00dbeef" "DEADBEEF01F00DBEEF"
StrCpy $8 "$SYSDIR\Poop"
WriteINIStr "$INSTDIR\test.ini" "MySection" "Value1" $8
WriteINIStr "$INSTDIR\test.ini" "MySectionShit" "Value1" $8
WriteINIStr "$INSTDIR\test.ini" "MySectionShit" "Value2" $8
WriteINIStr "$INSTDIR\test.ini" "POOPon" "Value1" $8
Call poopTest
DeleteINIStr "$INSTDIR\test.ini" "POOPon" "Value1"
DeleteINISec "$INSTDIR\test.ini" "MySectionShit"
ReadINIStr $1 "$INSTDIR\test.ini" "MySectionShit" "Value1"
StrCmp $1 "" INIDelSuccess
MessageBox MB_OK "DeleteINISec failed"
INIDelSuccess:
ClearErrors
ReadRegStr $1 HKCR "software\microsoft" shit
IfErrors 0 NoError
MessageBox MB_OK "could not read from HKCR\software\microsoft\shit"
Goto ErrorYay
NoError:
MessageBox MB_OK "read '$1' from HKCR\software\microsoft\shit"
ErrorYay:
SectionEnd
Function "CSCTest"
CreateDirectory "$SMPROGRAMS\Big NSIS Test"
SetOutPath $INSTDIR ; for working directory
CreateShortCut "$SMPROGRAMS\Big NSIS Test\Uninstall BIG NSIS Test.lnk" "$INSTDIR\bt-uninst.exe" ; use defaults for parameters, icon, etc.
; this one will use notepad's icon, start it minimized, and give it a hotkey (of Ctrl+Shift+Q)
CreateShortCut "$SMPROGRAMS\Big NSIS Test\bin2h.exe.lnk" "$INSTDIR\bin2h.exe" "" "$WINDIR\notepad.exe" 0 SW_SHOWMINIMIZED CONTROL|SHIFT|Q
CreateShortCut "$SMPROGRAMS\Big NSIS Test\TheDir.lnk" "$INSTDIR\" "" "" 0 SW_SHOWMAXIMIZED CONTROL|SHIFT|Z
FunctionEnd
Section "Test CreateShortCut"
SectionIn 1 2 3
Call CSCTest
SectionEnd
SubSection Sub2
Function myfunc
StrCpy $2 "poop=$1"
MessageBox MB_OK "myfunc: $2"
FunctionEnd
Section "Test Branching"
BeginTestSection:
SectionIn 1 2 3
SetOutPath $INSTDIR
IfFileExists "$INSTDIR\bin2h.c" 0 BranchTest69
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to overwrite $INSTDIR\bin2h.c?" IDNO NoOverwrite ; skipped if file doesn't exist
BranchTest69:
SetOverwrite ifnewer ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
NoOverwrite:
File "..\source\exehead\bin2h.c" ; skipped if answered no
SetOverwrite try ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to skip the rest of this section?" IDYES EndTestBranch
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to go back to the beginning of this section?" IDYES BeginTestSection
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to hide the installer and wait five seconds?" IDNO NoHide
HideWindow
Sleep 5000
BringToFront
NoHide:
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to call the function 5 times?" IDNO NoRecurse
StrCpy $1 "x"
LoopPoop:
Call myfunc
StrCpy $1 "x$1"
StrCmp $1 "xxxxxx" 0 LoopPoop
NoRecurse:
EndTestBranch:
SectionEnd
SubSectionEnd
Section "Test CopyFiles"
SectionIn 1 2 3
SetOutPath $INSTDIR\cpdest
CopyFiles "$WINDIR\*.ini" "$INSTDIR\cpdest" 0
SectionEnd
SubSectionEnd
Section "Test Exec functions" CRAPIDX
SectionIn 1 2 3
SearchPath $1 notepad.exe
MessageBox MB_OK "notepad.exe=$1"
Exec '"$1"'
ExecShell "open" '"$INSTDIR"'
Sleep 500
BringToFront
SectionEnd
Section "Test ActiveX control registration"
SectionIn 2
UnRegDLL "$SYSDIR\spin32.ocx"
Sleep 1000
RegDLL "$SYSDIR\spin32.ocx"
Sleep 1000
SectionEnd
; special uninstall section.
Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest"
DeleteRegKey HKLM "SOFTWARE\NSISCrap\BigNSISTest"
Delete "$INSTDIR\bin2h.exe"
Delete "$INSTDIR\bin2h.c"
Delete "$INSTDIR\bt-uninst.exe"
Delete "$INSTDIR\test.ini"
Delete "$SMPROGRAMS\Big NSIS Test\*.*"
RMDir "$SMPROGRAMS\BiG NSIS Test"
MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to remove the directory $INSTDIR\cpdest?" IDNO NoDelete
Delete "$INSTDIR\cpdest\*.*"
RMDir "$INSTDIR\cpdest" ; skipped if no
NoDelete:
RMDir "$INSTDIR\shiz\crap"
RMDir "$INSTDIR\shiz"
RMDir "$INSTDIR"
IfFileExists "$INSTDIR" 0 NoErrorMsg
MessageBox MB_OK "Note: $INSTDIR could not be removed!" IDOK 0 ; skipped if file doesn't exist
NoErrorMsg:
SectionEnd
; eof
Function .onSelChange
SectionGetText ${CRAPIDX} $0
StrCmp $0 "" e
SectionSetText ${CRAPIDX} ""
Goto e2
e:
SectionSetText ${CRAPIDX} "Doop"
e2:
FunctionEnd

104
Examples/branding.nsh Normal file
View file

@ -0,0 +1,104 @@
; Written by Amir Szekely 24th July 2002
; Please see gfx.nsi for example of usage
!verbose 3
; If we haven't included this as install macros yet
!ifndef BI_MACROS_USED
; If this isn't supposed to be uninstall macros
!ifndef BI_UNINSTALL
!define BI_MACROS_USED
; Undefine BI_FUNC if already defined by uninstaller macros
!ifdef BI_FUNC
!undef BI_FUNC
!endif
; Define BI_FUNC
!define BI_FUNC "BIChange"
; If BI_VAR or BI_TEMPFILE was already defined undefine it so BI_INIT can redefine it
!ifdef BI_VAR
!undef BI_VAR
!endif
!ifdef BI_TEMPFILE
!undef BI_TEMPFILE
!endif
; If macros aren't defined yet, define them
!ifndef UBI_MACROS_USED
!define BI_OK
!endif
; Done
!endif
!endif
; If we haven't included this as uninstall macros yet
!ifndef UBI_MACROS_USED
; If this is supposed to be uninstall macros
!ifdef BI_UNINSTALL
!define UBI_MACROS_USED
; Undefine BI_FUNC if already defined by installer macros
!ifdef BI_FUNC
!undef BI_FUNC
!endif
; Define BI_FUNC
!define BI_FUNC "un.BIChange"
; If BI_VAR or BI_TEMPFILE was already defined undefine it so BI_INIT can redefine it
!ifdef BI_VAR
!undef BI_VAR
!endif
!ifdef BI_TEMPFILE
!undef BI_TEMPFILE
!endif
; If macros aren't defined yet, define them
!ifndef BI_MACROS_USED
!define BI_OK
!endif
; Done
!endif
!endif
!ifdef BI_OK
!macro BI_INIT VAR
!define BI_VAR ${VAR}
StrCpy ${BI_VAR} 0
!macroend
!macro BI_NEXT
IntOp ${BI_VAR} ${BI_VAR} + 1
Call ${BI_FUNC}
!macroend
!macro BI_PREV
IntOp ${BI_VAR} ${BI_VAR} - 1
Call ${BI_FUNC}
!macroend
!macro BI_LIST
Function ${BI_FUNC}
Push $0
Push $1
StrCpy $0 0
GetTempFileName $1
!macroend
!macro BI_LIST_ADD IMAGE PARMS
IntOp $0 $0 + 1
StrCmp ${BI_VAR} $0 0 +4
File /oname=$1 "${IMAGE}"
SetBrandingImage ${PARMS} $1
Goto BI_done
!macroend
!macro BI_LIST_END
BI_done:
Delete $1
Pop $1
Pop $0
FunctionEnd
!macroend
!undef BI_OK
!endif ; ifdef BI_OK
!verbose 4
!echo "Branding macros defined successfully!"

29
Examples/example1.nsi Normal file
View file

@ -0,0 +1,29 @@
; example1.nsi
;
; This script is perhaps one of the simplest NSIs you can make. All of the
; optional settings are left to their default settings. The instalelr simply
; prompts the user asking them where to install, and drops of makensisw.exe
; there.
;
; The name of the installer
Name "Example1"
; The file to write
OutFile "example1.exe"
; The default installation directory
InstallDir $PROGRAMFILES\Example1
; The text to prompt the user to enter a directory
DirText "This will install the very simple example1 on your computer. Choose a directory"
; The stuff to install
Section "ThisNameIsIgnoredSoWhyBother?"
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File ..\makensisw.exe
SectionEnd ; end the section
; eof

67
Examples/example2.nsi Normal file
View file

@ -0,0 +1,67 @@
; example2.nsi
;
; This script is based on example1.nsi, but adds uninstall support
; and (optionally) start menu shortcuts.
;
; It will install notepad.exe into a directory that the user selects,
;
; The name of the installer
Name "Example2"
; The file to write
OutFile "example2.exe"
; The default installation directory
InstallDir $PROGRAMFILES\Example2
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM SOFTWARE\NSIS_Example2 "Install_Dir"
; The text to prompt the user to enter a directory
ComponentText "This will install the less simple example2 on your computer. Select which optional things you want installed."
; The text to prompt the user to enter a directory
DirText "Choose a directory to install in to:"
; The stuff to install
Section "Example2 (required)"
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File "..\makensisw.exe"
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_Example2 "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "DisplayName" "NSIS Example2 (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteUninstaller "uninstall.exe"
SectionEnd
; optional section
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\Example2"
CreateShortCut "$SMPROGRAMS\Example2\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\Example2\Example2 (notepad).lnk" "$INSTDIR\notepad.exe" "" "$INSTDIR\makensisw.exe" 0
SectionEnd
; uninstall stuff
UninstallText "This will uninstall example2. Hit next to continue."
; special uninstall section.
Section "Uninstall"
; remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2"
DeleteRegKey HKLM SOFTWARE\NSIS_Example2
; remove files
Delete $INSTDIR\makensisw.exe
; MUST REMOVE UNINSTALLER, too
Delete $INSTDIR\uninstall.exe
; remove shortcuts, if any.
Delete "$SMPROGRAMS\Example2\*.*"
; remove directories used.
RMDir "$SMPROGRAMS\Example2"
RMDir "$INSTDIR"
SectionEnd
; eof

614
Examples/functions.htm Normal file
View file

@ -0,0 +1,614 @@
<HTML><HEAD><TITLE>NSIS utility functions</TITLE>
<BODY>
<H1>NSIS utility functions</H1>
<H3>Contents:</H3>
<UL>
<li><a href="#General">General utility</a>
<ul>
<li><a href="#GetParent">GetParent</a>
<li><a href="#TrimNewlines">TrimNewlines</a>
<li><a href="#GetParameters">GetParameters</a>
<li><a href="#StrStr">StrStr</a>
</ul>
<LI><A href="#Versions">System version checking</A>
<UL>
<LI><A href="#GetWindowsVersion">GetWindowsVersion</A>
<LI><A href="#GetIEVersion">GetIEVersion</A>
<LI><A href="#IsFlashInstalled">IsFlashInstalled</A>
</UL>
<LI><A href="#SharedDLL">Shared DLL functions</A>
<UL>
<LI><A href="#un.RemoveSharedDLL">un.RemoveSharedDLL</A>
<LI><A href="#AddSharedDLL">AddSharedDLL</A>
<LI><A href="#UpgradeDLL">UpgradeDLL</A> (macro)
</UL>
<LI><A href="#Winamp">Winamp functions</A>
<UL>
<LI><A href="#GetWinampInstPath">GetWinampInstPath</A>
<LI><A href="#GetWinampVisPath">GetWinampVisPath</A>
<LI><A href="#GetWinampDSPPath">GetWinampDSPPath</A>
<LI><A href="#GetWinampSkinPath">GetWinampSkinPath</A>
<LI><A href="#CloseWinamp">CloseWinamp</A>
</UL>
<LI><A href="#Netscape">Netscape functions</A>
<UL>
<LI><A href="#InstallNetscapePlugin">InstallNetscapePlugin</A>
<LI><A href="#un.RemoveNetscapePlugin">un.RemoveNetscapePlugin</A>
</UL>
</UL>
<hr>
<A name=General>General utility: <PRE>
;<A name=GetParent>------------------------------------------------------------------------------
; GetParent
; input, top of stack (i.e. C:\Program Files\Poop)
; output, top of stack (replaces, with i.e. C:\Program Files)
; modifies no other variables.
;
; Usage:
; Push "C:\Program Files\Directory\Whatever"
; Call GetParent
; Pop $0
; ; at this point $0 will equal "C:\Program Files\Directory"
Function GetParent
Exch $0 ; old $0 is on top of stack
Push $1
Push $2
StrCpy $1 -1
loop:
StrCpy $2 $0 1 $1
StrCmp $2 "" exit
StrCmp $2 "\" exit
IntOp $1 $1 - 1
Goto loop
exit:
StrCpy $0 $0 $1
Pop $2
Pop $1
Exch $0 ; put $0 on top of stack, restore $0 to original value
FunctionEnd
;<A name=TrimNewlines>------------------------------------------------------------------------------
; TrimNewlines
; input, top of stack (i.e. whatever$\r$\n)
; output, top of stack (replaces, with i.e. whatever)
; modifies no other variables.
;
Function TrimNewlines
Exch $0
Push $1
Push $2
StrCpy $1 0
loop:
IntOp $1 $1 - 1
StrCpy $2 $0 1 $1
StrCmp $2 "$\r" loop
StrCmp $2 "$\n" loop
IntOp $1 $1 + 1
StrCpy $0 $0 $1
Pop $2
Pop $1
Exch $0
FunctionEnd
;<A name=GetParameters>------------------------------------------------------------------------------
; GetParameters
; input, none
; output, top of stack (replaces, with i.e. whatever)
; modifies no other variables.
Function GetParameters
Push $0
Push $1
Push $2
StrCpy $0 $CMDLINE 1
StrCpy $1 '"'
StrCpy $2 1
StrCmp $0 '"' loop
StrCpy $1 ' ' ; we're scanning for a space instead of a quote
loop:
StrCpy $0 $CMDLINE 1 $2
StrCmp $0 $1 loop2
StrCmp $0 "" loop2
IntOp $2 $2 + 1
Goto loop
loop2:
IntOp $2 $2 + 1
StrCpy $0 $CMDLINE 1 $2
StrCmp $0 " " loop2
StrCpy $0 $CMDLINE "" $2
Pop $2
Pop $1
Exch $0
FunctionEnd
;<a name=StrStr>------------------------------------------------------------------------------
; StrStr
; input, top of stack = string to search for
; top of stack-1 = string to search in
; output, top of stack (replaces with the portion of the string remaining)
; modifies no other variables.
;
; Usage:
; Push "this is a long ass string"
; Push "ass"
; Call StrStr
; Pop $0
; ($0 at this point is "ass string")
Function StrStr
Exch $1 ; st=haystack,old$1, $1=needle
Exch ; st=old$1,haystack
Exch $2 ; st=old$1,old$2, $2=haystack
Push $3
Push $4
Push $5
StrLen $3 $1
StrCpy $4 0
; $1=needle
; $2=haystack
; $3=len(needle)
; $4=cnt
; $5=tmp
loop:
StrCpy $5 $2 $3 $4
StrCmp $5 $1 done
StrCmp $5 "" done
IntOp $4 $4 + 1
Goto loop
done:
StrCpy $1 $2 "" $4
Pop $5
Pop $4
Pop $3
Pop $2
Exch $1
FunctionEnd
</PRE>
<HR>
<A name=Versions>System version checking: <PRE>
<A name=GetWindowsVersion>;------------------------------------------------------------------------------
; GetWindowsVersion
;
; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
; Returns on top of stack
;
; Windows Version (95, 98, ME, NT x.x, 2000)
; or
; '' (Unknown Windows Version)
;
; Usage:
; Call GetWindowsVersion
; Pop $0
; ; at this point $0 is "NT 4.0" or whatnot
Function GetWindowsVersion
Push $0
Push $9
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
StrCmp $0 "" 0 lbl_winnt
; we are not NT.
ReadRegStr $0 HKLM SOFTWARE\Microsoft\Windows\CurrentVersion VersionNumber
StrCpy $9 $0 1
StrCmp $9 '4' 0 lbl_error
StrCpy $9 $0 3
StrCmp $9 '4.0' lbl_win32_95
StrCmp $9 '4.9' lbl_win32_ME lbl_win32_98
lbl_win32_95:
StrCpy $0 '95'
Goto lbl_done
lbl_win32_98:
StrCpy $0 '98'
Goto lbl_done
lbl_win32_ME:
StrCpy $0 'ME'
Goto lbl_done
lbl_winnt:
StrCpy $9 $0 1
StrCmp $9 '3' lbl_winnt_x
StrCmp $9 '4' lbl_winnt_x
StrCmp $9 '5' lbl_winnt_5 lbl_error
lbl_winnt_x:
StrCpy $0 "NT $0" 6
Goto lbl_done
lbl_winnt_5:
Strcpy $0 '2000'
Goto lbl_done
lbl_error:
Strcpy $0 ''
lbl_done:
Pop $9
Exch $0
FunctionEnd
<A name=GetIEVersion>;------------------------------------------------------------------------------
; GetIEVersion
;
; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
; Returns on top of stack
; 1-6 (Installed IE Version)
; or
; '' (IE is not installed)
;
; Usage:
; Call GetIEVersion
; Pop $0
; ; at this point $0 is "5" or whatnot
Function GetIEVersion
Push $0
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\Internet Explorer" "Version"
IfErrors lbl_123 lbl_456
lbl_456: ; ie 4+
Strcpy $0 $0 1
Goto lbl_done
lbl_123: ; older ie version
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\Internet Explorer" "IVer"
IfErrors lbl_error
StrCpy $0 $0 3
StrCmp $0 '100' lbl_ie1
StrCmp $0 '101' lbl_ie2
StrCmp $0 '102' lbl_ie2
StrCpy $0 '3' ; default to ie3 if not 100, 101, or 102.
Goto lbl_done
lbl_ie1:
StrCpy $0 '1'
Goto lbl_done
lbl_ie2:
StrCpy $0 '2'
Goto lbl_done
lbl_error:
StrCpy $0 ''
lbl_done:
Exch $0
FunctionEnd
<A name=IsFlashInstalled>;------------------------------------------------------------------------------
; IsFlashInstalled
;
; By Yazno, http://yazno.tripod.com/powerpimpit/
; Returns on top of stack
; 0 (Flash is not installed)
; or
; 1 (Flash is installed)
;
; Usage:
; Call IsFlashInstalled
; Pop $0
; ; $0 at this point is "1" or "0"
Function IsFlashInstalled
Push $0
ClearErrors
ReadRegStr $0 HKCR "CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}" ""
IfErrors lbl_na
StrCpy $0 1
Goto lbl_end
lbl_na:
StrCpy $0 0
lbl_end:
Exch $0
FunctionEnd
</PRE>
<HR>
<A name=SharedDLL>Shared DLL functions:
<PRE><A name="un.RemoveSharedDLL">;------------------------------------------------------------------------------
; un.RemoveSharedDLL
;
; Decrements a shared DLLs reference count, and removes if necessary.
; Use by passing one item on the stack (the full path of the DLL).
; Note: for use in the main installer (not the uninstaller), rename the
; function to RemoveSharedDLL.
;
; Usage:
; Push $SYSDIR\myDll.dll
; Call un.RemoveShareDLL
;
Function un.RemoveSharedDLL
Exch $9
Push $0
ReadRegDword $0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $9
StrCmp $0 "" remove
IntOp $0 $0 - 1
IntCmp $0 0 rk rk uk
rk:
DeleteRegValue HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $9
goto Remove
uk:
WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $9 $0
Goto noremove
remove:
Delete /REBOOTOK $9
noremove:
Pop $0
Pop $9
FunctionEnd
<A name=AddSharedDLL>;------------------------------------------------------------------------------
; AddSharedDLL
;
; Increments a shared DLLs reference count.
; Use by passing one item on the stack (the full path of the DLL).
;
; Usage:
; Push $SYSDIR\myDll.dll
; Call AddSharedDLL
;
Function AddSharedDLL
Exch $9
Push $0
ReadRegDword $0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $9
IntOp $0 $0 + 1
WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $9 $0
Pop $0
Pop $9
FunctionEnd
<A name=UpgradeDLL>;------------------------------------------------------------------------------
; UpgradeDLL (macro)
;
; Updates a DLL (or executable) based on version resource information.
;
; Input: param = input source file.
; top of stack = full path on system to install file to.
;
; Output: none (removes full path from stack)
;
; Usage:
;
; Push "$SYSDIR\atl.dll"
; !insertmacro UpgradeDLL "atl.dll"
;
!macro UpgradeDLL DLL_NAME
Exch $0
Push $1
Push $2
Push $3
Push $4
ClearErrors
GetDLLVersionLocal ${DLL_NAME} $1 $2
GetDLLVersion $0 $3 $4
IfErrors upgrade_${DLL_NAME}
IntCmpU $1 $3 "" noupgrade_${DLL_NAME} upgrade_${DLL_NAME}
IntCmpU $2 $4 noupgrade_${DLL_NAME} noupgrade_${DLL_NAME}
upgrade_${DLL_NAME}:
UnRegDLL $0
File /oname=$0 ${DLL_NAME}
RegDLL $0
noupgrade_${DLL_NAME}:
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
!macroend
</PRE>
<HR>
<A name=Winamp>Winamp functions: <PRE><A name=GetWinampInstPath>;------------------------------------------------------------------------------
; GetWinampInstPath
;
; takes no parameters
; returns with the winamp install directory on the stack (it will be
; an empty string if winamp is not detected).
;
; modifies no other variables
;
; Usage:
; Call GetWinampInstPath
; Pop $0
; MessageBox MB_OK "Winamp installed at: $0"
Function GetWinampInstPath
Push $0
Push $1
Push $2
ReadRegStr $0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp" \
"UninstallString"
StrCmp $0 "" fin
StrCpy $1 $0 1 0 ; get firstchar
StrCmp $1 '"' "" getparent
; if first char is ", let's remove "'s first.
StrCpy $0 $0 "" 1
StrCpy $1 0
rqloop:
StrCpy $2 $0 1 $1
StrCmp $2 '"' rqdone
StrCmp $2 "" rqdone
IntOp $1 $1 + 1
Goto rqloop
rqdone:
StrCpy $0 $0 $1
getparent:
; the uninstall string goes to an EXE, let's get the directory.
StrCpy $1 -1
gploop:
StrCpy $2 $0 1 $1
StrCmp $2 "" gpexit
StrCmp $2 "\" gpexit
IntOp $1 $1 - 1
Goto gploop
gpexit:
StrCpy $0 $0 $1
StrCmp $0 "" fin
IfFileExists $0\winamp.exe fin
StrCpy $0 ""
fin:
Pop $2
Pop $1
Exch $0
FunctionEnd
<A name=GetWinampVisPath>;------------------------------------------------------------------------------
; GetWinampVisPath
;
; requires $INSTDIR to point to the Winamp directory.
; sets $OUTDIR with vis plug-in path
;
; modifies no other variables
Function GetWinampVisPath
ReadINIStr $OUTDIR $INSTDIR\winamp.ini Winamp VisDir
StrCmp $OUTDIR "" NoINISetting
IfFileExists $OUTDIR Good
NoINISetting:
StrCpy $OUTDIR $INSTDIR\Plugins
Good:
FunctionEnd
<A name=GetWinampDSPPath>;------------------------------------------------------------------------------
; GetWinampDSPPath
;
; requires $INSTDIR to point to the Winamp directory.
; sets $OUTDIR with dsp plug-in path
;
; modifies no other variables
Function GetWinampDSPPath
ReadINIStr $OUTDIR $INSTDIR\winamp.ini Winamp DSPDir
StrCmp $OUTDIR "" NoINISetting
IfFileExists $OUTDIR Good
NoINISetting:
StrCpy $OUTDIR $INSTDIR\Plugins
Good:
FunctionEnd
<A name=GetWinampSkinPath>;------------------------------------------------------------------------------
; GetWinampSkinPath
;
; requires $INSTDIR to point to the Winamp directory.
; sets $OUTDIR with skin plug-in path
;
; modifies no other variables
Function GetWinampSkinPath
ReadINIStr $OUTDIR $INSTDIR\winamp.ini Winamp SkinDir
StrCmp $OUTDIR "" NoINISetting
IfFileExists $OUTDIR Good
NoINISetting:
StrCpy $OUTDIR $INSTDIR\Skins
Good:
FunctionEnd
<A name=CloseWinamp>;------------------------------------------------------------------------------
; CloseWinamp
;
; Closes all running instances of Winamp 1.x/2.x
;
; modifies no other variables
Function CloseWinamp
Push $0
loop:
FindWindow $0 "Winamp v1.x"
IntCmp $0 0 done
SendMessage $0 16 0 0
Sleep 100
Goto loop
done:
Pop $0
FunctionEnd
</PRE>
<HR>
<A name=Netscape>Netscape functions: <PRE>
<A name=InstallNetscapePlugin>;------------------------------------------------------------------------------
; InstallNetscapePlugin
;
; Replace 'mynetscapeplugin.dll' with the name of your DLL to extract.
;
; (pretty much untested, but should work)
;
; you may want to add is-netscape-running and error checking (if the file isn't writable)
Function InstallNetscapePlugin
Push $OUTDIR
Push $0
Push $1
StrCpy $0 0
outer_loop:
EnumRegKey $1 HKLM "Software\Netscape\Netscape Navigator" $0
StrCmp $1 "" abort
ReadRegStr $1 HKLM "Software\Netscape\Netscape Navigator\$1\Main" "Plugins Directory"
StrCmp $1 "" abort
SetOutPath $1
File mynetscapeplugin.dll
IntOp $0 $0 + 1
Goto outer_loop
abort:
Pop $1
Pop $0
Pop $OUTDIR
FunctionEnd
<A name=RemoveNetscapePlugin>;------------------------------------------------------------------------------
; un.RemoveNetscapePlugin
;
; input: top of stack = dll name of plugin to remove
; output: none
;
; Usage:
; Push mynetscapepluging.dll
; Call un.RemoveNetscapePlugin
;
; you may want to add is-netscape-running and error checking (if the delete doesn't work).
Function un.RemoveNetscapePlugin
Exch $2
Push $0
Push $1
StrCpy $0 0
outer_loop:
EnumRegKey $1 HKLM "Software\Netscape\Netscape Navigator" $0
StrCmp $1 "" abort
ReadRegStr $1 HKLM "Software\Netscape\Netscape Navigator\$1\Main" "Plugins Directory"
StrCmp $1 "" abort
Delete /REBOOTOK $1\$2
IntOp $0 $0 + 1
Goto outer_loop
abort:
Pop $1
Pop $0
Pop $2
FunctionEnd
</PRE></A></BODY></HTML>

86
Examples/gfx.nsi Normal file
View file

@ -0,0 +1,86 @@
; gfx.nsi
;
; This script shows some examples of using all of the new
; graphic related additions made in NSIS 1.99
;
; Written by Amir Szkeley 22nd July 2002
;
Name "Graphical effects"
OutFile "gfx.exe"
; Adds an XP manifest to the installer
XPStyle on
; Add branding image to the installer (an image on the side)
AddBrandingImage left 100
; Sets the font of the installer
SetFont "Comic Sans MS" 8
; Just to make it three pages...
SubCaption 0 ": Yet another page..."
SubCaption 2 ": Yet another page..."
LicenseText "Second page"
LicenseData "gfx.nsi"
DirText "Lets make a third page!"
; Install dir
InstallDir "${NSISDIR}\Examples"
; Branding helper functions
!include "branding.nsh"
Function .onInit
!insertmacro BI_INIT $R0
FunctionEnd
Function .onNextPage
!insertmacro BI_NEXT
FunctionEnd
Function .onPrevPage
!insertmacro BI_PREV
FunctionEnd
!insertmacro BI_LIST
!insertmacro BI_LIST_ADD "${NSISDIR}\Contrib\Icons\checks1.bmp" /RESIZETOFIT
!insertmacro BI_LIST_ADD "${NSISDIR}\Contrib\Icons\checks2.bmp" /RESIZETOFIT
!insertmacro BI_LIST_ADD "${NSISDIR}\Contrib\Icons\checks4.bmp" /RESIZETOFIT
!insertmacro BI_LIST_END
Section
; You can also use the BI_NEXT macro here...
MessageBox MB_YESNO "We can change the branding image from within a section too!$\nDo you want me to change it?" IDNO done
GetTempFileName $1
File /oname=$1 "${NSISDIR}\Contrib\Icons\checksX2.bmp"
SetBrandingImage $1
Delete $1
done:
WriteUninstaller uninst.exe
SectionEnd
; Another page for uninstaller
UninstallText "Another page..."
; Uninstall branding helper functions
!define BI_UNINSTALL
!include "branding.nsh"
Function un.onInit
!insertmacro BI_INIT $R0
FunctionEnd
Function un.onNextPage
!insertmacro BI_NEXT
FunctionEnd
!insertmacro BI_LIST
!insertmacro BI_LIST_ADD "${NSISDIR}\Contrib\Icons\checksX.bmp" /RESIZETOFIT
!insertmacro BI_LIST_ADD "${NSISDIR}\Contrib\Icons\jarsonic-checks.bmp" /RESIZETOFIT
!insertmacro BI_LIST_END
Section uninstall
MessageBox MB_OK "Bla"
SectionEnd

420
Examples/makensis.nsi Normal file
View file

@ -0,0 +1,420 @@
!define VER_MAJOR 2
!define VER_MINOR 0a2
!ifdef NO_COMPRESSION
SetCompress off
SetDatablockOptimize off
!endif
!ifdef NO_CRC
CRCCheck off
!endif
Name "NSIS"
Caption "Nullsoft Install System - Setup"
OutFile nsis${VER_MAJOR}${VER_MINOR}.exe
SetCompressor bzip2
!ifdef uglyinstaller
BGGradient 000000 308030 FFFFFF
InstallColors FF8080 000000
InstProgressFlags smooth colored
XPStyle on
!else
WindowIcon off
!endif
!ifdef NSIS_CONFIG_LICENSEPAGE
LicenseText "You must read the following license before installing:"
LicenseData ..\license.txt
!endif
!ifdef NSIS_CONFIG_COMPONENTPAGE
ComponentText "This will install the Nullsoft Install System v${VER_MAJOR}.${VER_MINOR} on your computer:"
InstType "Full (w/ Source and Contrib)"
InstType "Normal (w/ Contrib, w/o Source)"
InstType "Lite (w/o Source or Contrib)"
!endif
AutoCloseWindow false
ShowInstDetails show
ShowUninstDetails show
DirText "Please select a location to install NSIS (or use the default):"
SetOverwrite on
SetDateSave on
!ifdef HAVE_UPX
!packhdr tmp.dat "upx\upx --best --compress-icons=1 tmp.dat"
!endif
InstallDir $PROGRAMFILES\NSIS
InstallDirRegKey HKLM SOFTWARE\NSIS ""
Section "NSIS development system (required)"
SectionIn 1 2 3 RO
SetOutPath $INSTDIR
SetOverwrite try
File ..\makensis.exe
File ..\makensisw.exe
File ..\makensis.htm
File ..\license.txt
SetOverwrite off
File ..\nsisconf.nsi
SectionEnd
Section "NSIS Examples (recommended)"
SectionIn 1 2 3
SetOutPath $INSTDIR\Examples
SetOverwrite try
Delete $INSTDIR\*.nsh
Delete $INSTDIR\viewhtml.nsi
Delete $INSTDIR\waplugin.nsi
Delete $INSTDIR\example*.nsi
Delete $INSTDIR\*test.nsi
Delete $INSTDIR\primes.nsi
Delete $INSTDIR\functions.htm
File ..\Examples\makensis.nsi
File ..\Examples\example1.nsi
File ..\Examples\example2.nsi
File ..\Examples\viewhtml.nsi
File ..\Examples\waplugin.nsi
File ..\Examples\bigtest.nsi
File ..\Examples\primes.nsi
File ..\Examples\rtest.nsi
File ..\Examples\gfx.nsi
File ..\Examples\WinMessages.nsh
File ..\Examples\branding.nsh
File ..\Examples\functions.htm
SectionEnd
Section "NSI Development Shell Extensions"
SectionIn 1 2 3
; back up old value of .nsi
ReadRegStr $1 HKCR ".nsi" ""
StrCmp $1 "" Label1
StrCmp $1 "NSISFile" Label1
WriteRegStr HKCR ".nsi" "backup_val" $1
Label1:
WriteRegStr HKCR ".nsi" "" "NSISFile"
WriteRegStr HKCR "NSISFile" "" "NSI Script File"
WriteRegStr HKCR "NSISFile\shell" "" "open"
WriteRegStr HKCR "NSISFile\DefaultIcon" "" $INSTDIR\makensis.exe,0
WriteRegStr HKCR "NSISFile\shell\open\command" "" 'notepad.exe "%1"'
WriteRegStr HKCR "NSISFile\shell\compile" "" "Compile NSI"
WriteRegStr HKCR "NSISFile\shell\compile\command" "" '"$INSTDIR\makensisw.exe" "$INSTDIR\makensis.exe" /CD "%1"'
WriteRegStr HKCR "NSISFile\shell\compile-bz2" "" "Compile NSI (with bz2)"
WriteRegStr HKCR "NSISFile\shell\compile-bz2\command" "" '"$INSTDIR\makensisw.exe" "$INSTDIR\makensis.exe" /CD /X"SetCompressor bzip2" "%1"'
SectionEnd
Section "Start Menu + Desktop Icons"
SectionIn 1 2 3
SetOutPath $SMPROGRAMS\NSIS
Delete "$SMPROGRAMS\NSIS\NSIS Home Page.lnk"
WriteINIStr "$SMPROGRAMS\NSIS\NSIS Home Page.url" "InternetShortcut" "URL" "http://www.nullsoft.com/free/nsis/"
CreateShortCut "$SMPROGRAMS\NSIS\Uninstall NSIS.lnk" "$INSTDIR\uninst-nsis.exe"
CreateShortCut "$SMPROGRAMS\NSIS\NSIS Documentation.lnk" "$INSTDIR\makensis.htm"
CreateShortCut "$SMPROGRAMS\NSIS\NSIS Program Directory.lnk" "$INSTDIR"
Delete "$SMPROGRAMS\NSIS\NSI Online Template Generator.lnk"
WriteINIStr "$SMPROGRAMS\NSIS\NSI Online Template Generator.url" "InternetShortcut" "URL" "http://www.firehose.net/free/nsis/makensitemplate.phtml"
SetOutPath $INSTDIR
CreateShortCut "$DESKTOP\MakeNSIS.lnk" "$INSTDIR\Makensisw.exe" '"$INSTDIR\makensis.exe" /CD'
SectionEnd
!ifndef NO_CONTRIB
SubSection "Additional utilities"
SubSection "Contrib"
Section "Extra Icons"
SectionIn 1 2
SetOutPath $INSTDIR\Contrib\Icons
SetOverwrite try
Delete $INSTDIR\Contrib\*.ico
Delete $INSTDIR\Contrib\*.bmp
File ..\Contrib\Icons\*.ico
File ..\Contrib\Icons\*.bmp
SetOutPath $INSTDIR
SectionEnd
Section "Extra UIs"
SectionIn 1 2
SetOutPath $INSTDIR\Contrib\UIs
SetOverwrite try
File ..\Contrib\UIs\*.exe
SetOutPath $INSTDIR
SectionEnd
Section "Splash"
SectionIn 1 2
SetOutPath $INSTDIR\Contrib\Splash
SetOverwrite try
File ..\Contrib\Splash\splash.c
File ..\Contrib\Splash\splash.dsp
File ..\Contrib\Splash\splash.dsw
File ..\Contrib\splash\splash.txt
SetOutPath $INSTDIR\Bin
File ..\Bin\splash.exe
IfFileExists $SMPROGRAMS\NSIS 0 NoShortCuts
CreateDirectory $SMPROGRAMS\NSIS\Contrib
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\Splash Screen Help.lnk" "$INSTDIR\contrib\splash\splash.txt"
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\Splash project workspace.lnk" "$INSTDIR\source\splash\splash.dsw"
NoShortCuts:
SectionEnd
Section "Zip2Exe"
SectionIn 1 2
DetailPrint "Extracting zip2exe source"
SetDetailsPrint textonly
RMDir /r $INSTDIR\Source\Zip2Exe
SetOutPath $INSTDIR\Contrib\zip2exe
SetOverwrite try
File ..\Contrib\zip2exe\*.cpp
File ..\Contrib\zip2exe\*.ico
File ..\Contrib\zip2exe\*.h
File ..\Contrib\zip2exe\*.rc
File ..\Contrib\zip2exe\*.dsw
File ..\Contrib\zip2exe\*.dsp
SetOutPath $INSTDIR\Contrib\zip2exe\zlib
File ..\Contrib\zip2exe\zlib\*.*
SetOutPath $INSTDIR\Bin
File ..\Bin\zip2exe.exe
SetDetailsPrint both
IfFileExists $SMPROGRAMS\NSIS 0 NoShortCuts
CreateDirectory $SMPROGRAMS\NSIS\Contrib
Delete "$SMPROGRAMS\Bin\NSIS\ZIP2EXE converter.lnk"
Delete "$SMPROGRAMS\NSIS\ZIP2EXE project workspace.lnk"
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\ZIP2EXE converter.lnk" "$INSTDIR\Bin\zip2exe.exe"
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\ZIP2EXE project workspace.lnk" "$INSTDIR\source\zip2exe\zip2exe.dsw"
NoShortCuts:
SectionEnd
Section "InstallOptions"
SectionIn 1 2
SetOutPath $INSTDIR\Contrib\InstallOptions
SetOverwrite try
File ..\contrib\installoptions\io.dsp
File ..\contrib\installoptions\io.dsw
File ..\contrib\installoptions\test.ini
File ..\contrib\installoptions\test.nsi
File ..\contrib\installoptions\InstallerOptions.cpp
File ..\contrib\installoptions\*.rc
File ..\contrib\installoptions\*.h
File "..\contrib\installoptions\Install Options.html"
SetOutPath $INSTDIR\Bin
File ..\Bin\InstallOptions.dll
IfFileExists $SMPROGRAMS\NSIS 0 NoShortCuts
CreateDirectory $SMPROGRAMS\NSIS\Contrib
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\InstallOptions Readme.lnk" "$INSTDIR\contrib\InstallOptions\install options.html"
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\InstallOptions project workspace.lnk" "$INSTDIR\contrib\InstallOptions\io.dsw"
NoShortCuts:
SectionEnd
Section "NSIS-DL"
SectionIn 1 2
SetOutPath $INSTDIR\Contrib\NSISdl
SetOverwrite try
File ..\contrib\NSISdl\nsisdl.dsw
File ..\contrib\NSISdl\nsisdl.dsp
File ..\contrib\NSISdl\*.cpp
File ..\contrib\NSISdl\*.h
File ..\contrib\NSISdl\*.rc
File ..\contrib\NSISdl\ReadMe.txt
SetOutPath $INSTDIR\Bin
File ..\Bin\nsisdl.dll
IfFileExists $SMPROGRAMS\NSIS 0 NoShortCuts
CreateDirectory $SMPROGRAMS\NSIS\Contrib
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\NSIS-DL Readme.lnk" "$INSTDIR\contrib\NSISDL\ReadMe.txt"
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\NSIS-DL project workspace.lnk" "$INSTDIR\contrib\NSISDL\nsisdl.dsw"
NoShortCuts:
SectionEnd
SubSectionEnd
SubSectionEnd
!endif
!ifndef NO_SOURCE
SubSection "Source code"
Section "NSIS Source Code"
SectionIn 1
DetailPrint "Extracting source code...."
SetDetailsPrint textonly
SetOutPath $INSTDIR\Source
SetOverwrite try
File ..\Source\*.cpp
File ..\Source\*.c
File ..\Source\*.h
File ..\Source\script1.rc
File ..\Source\Makefile
File ..\Source\makenssi.dsp
File ..\Source\makenssi.dsw
File ..\Source\icon.ico
SetOutPath $INSTDIR\Source\zlib
File ..\Source\zlib\*.*
SetOutPath $INSTDIR\Source\bzip2
File ..\Source\bzip2\*.*
SetOutPath $INSTDIR\Source\exehead
File ..\Source\exehead\*.c
File ..\Source\exehead\*.h
File ..\Source\exehead\exehead.xml
File ..\Source\exehead\resource.rc
File ..\Source\exehead\*.dsp
File ..\Source\exehead\Makefile
File ..\Source\exehead\nsis.ico
File ..\Source\exehead\uninst.ico
File ..\Source\exehead\bitmap1.bmp
File ..\Source\exehead\bin2h.exe
IfFileExists $SMPROGRAMS\NSIS 0 NoSourceShortCuts
CreateShortCut "$SMPROGRAMS\NSIS\MakeNSIS project workspace.lnk" "$INSTDIR\source\makenssi.dsw"
NoSourceShortCuts:
SetDetailsPrint both
SectionEnd
SubSection "Contrib"
Section "ExDLL Source"
SectionIn 1
SetOutPath $INSTDIR\Contrib\ExDLL
SetOverwrite try
File ..\contrib\exdll\exdll.c
File ..\contrib\exdll\exdll.dpr
File ..\contrib\exdll\exdll.dsp
File ..\contrib\exdll\exdll.dsw
SetOutPath $INSTDIR
IfFileExists $SMPROGRAMS\NSIS 0 NoShortCuts
CreateDirectory $SMPROGRAMS\NSIS\Contrib
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\ExDLL project workspace.lnk" "$INSTDIR\contrib\ExDLL\exdll.dsw"
NoShortCuts:
SectionEnd
Section "MakeNSISW Source"
SectionIn 1
SetOutPath $INSTDIR\Contrib\Makensisw
SetOverwrite try
File ..\contrib\makensisw\*.cpp
File ..\contrib\makensisw\*.xml
File ..\contrib\makensisw\*.h
File ..\contrib\makensisw\*.ds?
File ..\contrib\makensisw\*.rc
File ..\contrib\makensisw\*.txt
#File ..\contrib\makensisw\Makefile
IfFileExists $SMPROGRAMS\NSIS 0 NoShortCuts
CreateDirectory $SMPROGRAMS\NSIS\Contrib
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\MakeNSISW project workspace.lnk" "$INSTDIR\contrib\MakeNsisw\makensisw.dsw"
CreateShortCut "$SMPROGRAMS\NSIS\Contrib\MakeNSISW readme.lnk" "$INSTDIR\contrib\MakeNsisw\readme.txt"
NoShortCuts:
SectionEnd
SubSectionEnd
SubSectionEnd
!endif
Section -post
WriteRegStr HKLM SOFTWARE\NSIS "" $INSTDIR
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NSIS" "DisplayName" "NSIS Development Kit (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NSIS" "UninstallString" '"$INSTDIR\uninst-nsis.exe"'
SetOutPath $INSTDIR
IfFileExists $SMPROGRAMS\NSIS "" nofunshit
ExecShell open '$SMPROGRAMS\NSIS'
Sleep 500
BringToFront
nofunshit:
; since the installer is now created last (in 1.2+), this makes sure
; that any old installer that is readonly is overwritten.
Delete $INSTDIR\uninst-nsis.exe
WriteUninstaller $INSTDIR\uninst-nsis.exe
SectionEnd
Function .onInstSuccess
MessageBox MB_YESNO|MB_ICONQUESTION "Setup has completed. View readme file now?" IDNO NoReadme
ExecShell open '$INSTDIR\makensis.htm'
NoReadme:
FunctionEnd
!ifndef NO_UNINST
UninstallText "This will uninstall NSIS from your system:"
Section Uninstall
IfFileExists $INSTDIR\makensis.exe skip_confirmation
MessageBox MB_YESNO "It does not appear that NSIS is installed in the directory '$INSTDIR'.$\r$\nContinue anyway (not recommended)" IDYES skip_confirmation
Abort "Uninstall aborted by user"
skip_confirmation:
ReadRegStr $1 HKCR ".nsi" ""
StrCmp $1 "NSISFile" 0 NoOwn ; only do this if we own it
ReadRegStr $1 HKCR ".nsi" "backup_val"
StrCmp $1 "" 0 RestoreBackup ; if backup == "" then delete the whole key
DeleteRegKey HKCR ".nsi"
Goto NoOwn
RestoreBackup:
WriteRegStr HKCR ".nsi" "" $1
DeleteRegValue HKCR ".nsi" "backup_val"
NoOwn:
DeleteRegKey HKCR "NSISFile"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NSIS"
DeleteRegKey HKLM SOFTWARE\NSIS
Delete $SMPROGRAMS\NSIS\Contrib\*.lnk
Delete $SMPROGRAMS\NSIS\Contrib\*.url
RMDir $SMPROGRAMS\NSIS\Contrib
RMDir /r $INSTDIR\Contrib
Delete $SMPROGRAMS\NSIS\*.lnk
Delete $SMPROGRAMS\NSIS\*.url
RMDir $SMPROGRAMS\NSIS
Delete $DESKTOP\MakeNSIS.lnk
Delete $INSTDIR\makensis*.exe
Delete $INSTDIR\Bin\zip2exe.exe
Delete $INSTDIR\Bin\installoptions.exe
Delete $INSTDIR\Bin\installoptions.dll
Delete $INSTDIR\Bin\splash.txt
Delete $INSTDIR\Bin\splash.exe
Delete $INSTDIR\Bin\nsisdl.dll
Delete $INSTDIR\makensis.htm
Delete $INSTDIR\Examples\functions.htm
Delete $INSTDIR\makensis.rtf
Delete $INSTDIR\uninst-nsis.exe
Delete $INSTDIR\nsisconf.nsi
Delete $INSTDIR\Examples\makensis.nsi
Delete $INSTDIR\Examples\example1.nsi
Delete $INSTDIR\Examples\example2.nsi
Delete $INSTDIR\Examples\waplugin.nsi
Delete $INSTDIR\Examples\viewhtml.nsi
Delete $INSTDIR\Examples\bigtest.nsi
Delete $INSTDIR\Examples\primes.nsi
Delete $INSTDIR\Examples\rtest.nsi
Delete $INSTDIR\Examples\uglytest.nsi
Delete $INSTDIR\Examples\spin.nsi
Delete $INSTDIR\Examples\wafull.nsi
Delete $INSTDIR\Examples\upgradedll.nsh
Delete $INSTDIR\Examples\WinMessages.nsh
Delete $INSTDIR\main.ico
Delete $INSTDIR\makensis-license.txt
Delete $INSTDIR\license.txt
Delete $INSTDIR\uninst.ico
Delete $INSTDIR\bitmap1.bmp
Delete $INSTDIR\bitmap2.bmp
RMDir /r $INSTDIR\Source
RMDir /r $INSTDIR\Bin
RMDir /r $INSTDIR\Examples
RMDir $INSTDIR
; if $INSTDIR was removed, skip these next ones
IfFileExists $INSTDIR 0 Removed
MessageBox MB_YESNO|MB_ICONQUESTION \
"Remove all files in your NSIS directory? (If you have anything you created that you want to keep, click No)" IDNO Removed
Delete $INSTDIR\*.* ; this would be skipped if the user hits no
RMDir /r $INSTDIR
IfFileExists $INSTDIR 0 Removed
MessageBox MB_OK|MB_ICONEXCLAMATION "Note: $INSTDIR could not be removed."
Removed:
SectionEnd
!endif

48
Examples/primes.nsi Normal file
View file

@ -0,0 +1,48 @@
Name "primes"
AllowRootDirInstall true
OutFile "primes.exe"
Caption "Prime number generator"
ShowInstDetails show
AllowRootDirInstall true
InstallDir "$EXEDIR"
DirText "Select directory to write primes.txt"
Section "crap"
SetOutPath $INSTDIR
Call DoPrimes
SectionEnd
Function DoPrimes
; we put this in here so it doesn't update the progress bar (faster)
!define PPOS $0 ; position in prime searching
!define PDIV $1 ; divisor
!define PMOD $2 ; the result of the modulus
!define PCNT $3 ; count of how many we've printed
FileOpen $9 $INSTDIR\primes.txt w
DetailPrint "2 is prime!"
FileWrite $9 "2 is prime!$\r$\n"
DetailPrint "3 is prime!"
FileWrite $9 "3 is prime!$\r$\n"
Strcpy ${PPOS} 3
Strcpy ${PCNT} 2
outerloop:
StrCpy ${PDIV} 3
innerloop:
IntOp ${PMOD} ${PPOS} % ${PDIV}
IntCmp ${PMOD} 0 notprime
IntOp ${PDIV} ${PDIV} + 2
IntCmp ${PDIV} ${PPOS} 0 innerloop 0
DetailPrint "${PPOS} is prime!"
FileWrite $9 "${PPOS} is prime!$\r$\n"
IntOp ${PCNT} ${PCNT} + 1
IntCmp ${PCNT} 100 0 innerloop
StrCpy ${PCNT} 0
MessageBox MB_YESNO "Process more?" IDNO stop
notprime:
IntOp ${PPOS} ${PPOS} + 2
Goto outerloop
stop:
FileClose $9
FunctionEnd

56
Examples/rtest.nsi Normal file
View file

@ -0,0 +1,56 @@
Name "rtest"
OutFile "rtest.exe"
InstallDir $TEMP
BGGradient 0 FFFF00 00FFFF
DirShow hide
ComponentText "select tests."
Section "test 1"
StrCpy $0 "a"
Call test1
StrCmp $0 "a182345678" success
DetailPrint "Test 1 failed (output: $0)"
Goto end
success:
DetailPrint "Test 1 succeded (output: $0)"
end:
SectionEnd
Function test1
GetLabelAddress $9 skip8
IntOp $9 $9 - 1
StrCpy $0 $01
Call $9
StrCpy $0 $02
StrCpy $0 $03
StrCpy $0 $04
StrCpy $0 $05
StrCpy $0 $06
StrCpy $0 $07
StrCpy $0 $08
skip8:
FunctionEnd
Section "test 2"
StrCpy $0 "0"
StrCpy $1 "11"
GetFunctionAddress $9 test2
Call $9
StrCmp $1 "11,10,9,8,7,6,5,4,3,2,1" success
DetailPrint "Test 2 failed (output: $1)"
Goto end
success:
DetailPrint "Test 2 succeded (output: $1)"
end:
SectionEnd
Function test2
IntOp $0 $0 + 1
IntCmp $0 10 done
Push $0
Call test2
Pop $0
done:
StrCpy $1 "$1,$0"
FunctionEnd

43
Examples/viewhtml.nsi Normal file
View file

@ -0,0 +1,43 @@
; viewhtml.nsi
;
; This script creates a silent installer which extracts one (or more) HTML
; files to a temporary directory, opens Internet Explorer to view the file(s),
; and when Internet Explorer has quit, deletes the file(s).
;
; The name of the installer (not really used in a silent install)
Name "ViewHTML"
; Set to silent mode
SilentInstall silent
; The file to write
OutFile "viewhtml.exe"
; The installation directory (the user never gets to change this)
InstallDir "$TEMP\ViewHTML"
; The stuff to install
Section ""
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Extract file
File "..\makensis.htm"
; View file
ExecWait '"$PROGRAMFILES\Internet Explorer\iexplore.exe" "$INSTDIR\makensis.htm"'
; Delete the files
Delete $INSTDIR\Makensis.htm
RMDir $INSTDIR
SectionEnd
; Note: another way of doing this would be to use ExecShell, but then you
; really couldn't get away with deleting the files. Here is the ExecShell
; line that you would want to use:
;
; ExecShell "open" '"$INSTDIR\makensis.htm"'
;
; The advantage of this way is that it would use the default browser to
; open the HTML.
;
; eof

153
Examples/waplugin.nsi Normal file
View file

@ -0,0 +1,153 @@
; waplugin.nsi
;
; This script will generate an installer that installs a Winamp plug-in.
; It also puts a license page on, for shits and giggles.
;
; This installer will automatically alert the user that installation was
; successful, and ask them whether or not they would like to make the
; plug-in the default and run Winamp.
;
; The name of the installer
Name "TinyVis Plug-in"
; The file to write
OutFile "waplugin.exe"
; License page
; LicenseText "This installer will install the Nullsoft Tiny Visualization 2000 Plug-in for Winamp. Please read the license below."
; use the default makensis license :)
; LicenseData license.txt
; The default installation directory
InstallDir $PROGRAMFILES\Winamp
; detect winamp path from uninstall string if available
InstallDirRegKey HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp" \
"UninstallString"
; The text to prompt the user to enter a directory
DirText "Please select your Winamp path below (you will be able to proceed when Winamp is detected):"
DirShow hide
; automatically close the installer when done.
AutoCloseWindow true
; hide the "show details" box
ShowInstDetails nevershow
Function .onVerifyInstDir
!ifndef WINAMP_AUTOINSTALL
IfFileExists $INSTDIR\Winamp.exe Good
Abort
Good:
!endif ; WINAMP_AUTOINSTALL
FunctionEnd
Function QueryWinampVisPath ; sets $1 with vis path
StrCpy $1 $INSTDIR\Plugins
; use DSPDir instead of VISDir to get DSP plugins directory
ReadINIStr $9 $INSTDIR\winamp.ini Winamp VisDir
StrCmp $9 "" End
IfFileExists $9 0 End
StrCpy $1 $9 ; update dir
End:
FunctionEnd
!ifdef WINAMP_AUTOINSTALL
Function GetWinampInstPath
Push $0
Push $1
Push $2
ReadRegStr $0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp" \
"UninstallString"
StrCmp $0 "" fin
StrCpy $1 $0 1 0 ; get firstchar
StrCmp $1 '"' "" getparent
; if first char is ", let's remove "'s first.
StrCpy $0 $0 "" 1
StrCpy $1 0
rqloop:
StrCpy $2 $0 1 $1
StrCmp $2 '"' rqdone
StrCmp $2 "" rqdone
IntOp $1 $1 + 1
Goto rqloop
rqdone:
StrCpy $0 $0 $1
getparent:
; the uninstall string goes to an EXE, let's get the directory.
StrCpy $1 -1
gploop:
StrCpy $2 $0 1 $1
StrCmp $2 "" gpexit
StrCmp $2 "\" gpexit
IntOp $1 $1 - 1
Goto gploop
gpexit:
StrCpy $0 $0 $1
StrCmp $0 "" fin
IfFileExists $0\winamp.exe fin
StrCpy $0 ""
fin:
Pop $2
Pop $1
Exch $0
FunctionEnd
Function MakeSureIGotWinamp
Call GetWinampInstPath
Pop $0
StrCmp $0 "" getwinamp
Return
getwinamp:
StrCpy $1 $TEMP\porearre1.dll
StrCpy $2 "$TEMP\Winamp Installer.exe"
File /oname=$1 nsisdl.dll
Push http://download.nullsoft.com/winamp/client/winamp277_lite.exe
Push $2
CallInstDLL $1 download
Delete $1
StrCmp $0 success success
SetDetailsView show
DetailPrint "download failed: $0"
Abort
success:
ExecWait '"$2" /S'
Delete $2
Call GetWinampInstPath
Pop $0
StrCmp $0 "" skip
StrCpy $INSTDIR $0
skip:
FunctionEnd
!endif ; WINAMP_AUTOINSTALL
; The stuff to install
Section "ThisNameIsIgnoredSoWhyBother?"
!ifdef WINAMP_AUTOINSTALL
Call MakeSureIGotWinamp
!endif
Call QueryWinampVisPath
SetOutPath $1
; File to extract
File "C:\program files\winamp\plugins\vis_nsfs.dll"
; prompt user, and if they select no, skip the following 3 instructions.
MessageBox MB_YESNO|MB_ICONQUESTION \
"The plug-in was installed. Would you like to run Winamp now with TinyVis as the default plug-in?" \
IDNO NoWinamp
WriteINIStr "$INSTDIR\Winamp.ini" "Winamp" "visplugin_name" "vis_nsfs.dll"
WriteINIStr "$INSTDIR\Winamp.ini" "Winamp" "visplugin_num" "0"
Exec '"$INSTDIR\Winamp.exe"'
NoWinamp:
SectionEnd
; eof

463
Source/DialogTemplate.cpp Normal file
View file

@ -0,0 +1,463 @@
/*
Copyright (C) 2002 Amir Szekely <kichik@netvision.net.il>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "DialogTemplate.h"
//////////////////////////////////////////////////////////////////////
// Utilities
//////////////////////////////////////////////////////////////////////
#define ALIGN(dwToAlign, dwAlignOn) dwToAlign = (dwToAlign%dwAlignOn == 0) ? dwToAlign : dwToAlign - (dwToAlign%dwAlignOn) + dwAlignOn
// returns the number of WCHARs in str including null charcter
inline DWORD WCStrLen(WCHAR* szwStr) {
int i;
for (i = 0; szwStr[i]; i++);
return i+1;
}
// Reads a variany length array from seeker into readInto and advances seeker
void ReadVarLenArr(BYTE* &seeker, char* &readInto) {
WORD* arr = (WORD*)seeker;
switch (arr[0]) {
case 0x0000:
readInto = 0;
seeker += sizeof(WORD);
break;
case 0xFFFF:
readInto = MAKEINTRESOURCE(arr[1]);
seeker += 2*sizeof(WORD);
break;
default:
{
DWORD dwStrLen = WCStrLen((WCHAR*)arr);
readInto = new char[dwStrLen];
WideCharToMultiByte(CP_ACP, 0, (WCHAR*)arr, dwStrLen, readInto, dwStrLen, 0, 0);
seeker += (dwStrLen)*sizeof(WORD);
}
break;
}
}
// A macro that writes a given string (that can be a number too) into the buffer
#define WriteStringOrId(x) \
if (x) \
if (IS_INTRESOURCE(x)) { \
*(WORD*)seeker = 0xFFFF; \
seeker += sizeof(WORD); \
*(WORD*)seeker = WORD(x); \
seeker += sizeof(WORD); \
} \
else { \
MultiByteToWideChar(CP_ACP, 0, x, -1, (WCHAR*)seeker, dwSize); \
seeker += (lstrlen(x)+1)*sizeof(WCHAR); \
} \
else \
seeker += sizeof(WORD);
// A macro that adds the size of x (which can be a string a number, or nothing) to dwSize
#define AddStringOrIdSize(x) dwSize += x ? (IS_INTRESOURCE(x) ? sizeof(DWORD) : (lstrlen(x)+1)*sizeof(WCHAR)) : sizeof(WORD)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDialogTemplate::CDialogTemplate(BYTE* pbData) {
m_szClass = 0;
m_szFont = 0;
m_szMenu = 0;
m_szTitle = 0;
WORD wItems = 0;
if (*(DWORD*)pbData == 0xFFFF0001) { // Extended dialog template signature
m_bExtended = true;
DLGTEMPLATEEX* dTemplateEx = (DLGTEMPLATEEX*)pbData;
m_dwHelpId = dTemplateEx->helpID;
m_dwStyle = dTemplateEx->style;
m_dwExtStyle = dTemplateEx->exStyle;
m_sX = dTemplateEx->x;
m_sY = dTemplateEx->y;
m_sWidth = dTemplateEx->cx;
m_sHeight = dTemplateEx->cy;
wItems = dTemplateEx->cDlgItems;
}
else {
m_bExtended = false;
DLGTEMPLATE* dTemplate = (DLGTEMPLATE*)pbData;
m_dwStyle = dTemplate->style;
m_dwExtStyle = dTemplate->dwExtendedStyle;
m_sX = dTemplate->x;
m_sY = dTemplate->y;
m_sWidth = dTemplate->cx;
m_sHeight = dTemplate->cy;
wItems = dTemplate->cdit;
}
BYTE* seeker = pbData + (m_bExtended ? sizeof(DLGTEMPLATEEX) : sizeof(DLGTEMPLATE));
// Read menu variant length array
ReadVarLenArr(seeker, m_szMenu);
// Read class variant length array
ReadVarLenArr(seeker, m_szClass);
// Read title variant length array
ReadVarLenArr(seeker, m_szTitle);
// Read font size and variant length array (only if style DS_SETFONT is used!)
if (m_dwStyle & DS_SETFONT) {
m_sFontSize = *(short*)seeker;
seeker += sizeof(short);
ReadVarLenArr(seeker, m_szFont);
}
// Read items
for (int i = 0; i < wItems; i++) {
// DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundry
if (DWORD(seeker - pbData) % sizeof(DWORD))
seeker += sizeof(WORD);
DialogItemTemplate* item = new DialogItemTemplate;
ZeroMemory(item, sizeof(DialogItemTemplate));
if (m_bExtended) {
DLGITEMTEMPLATEEX* rawItem = (DLGITEMTEMPLATEEX*)seeker;
item->dwHelpId = rawItem->helpID;
item->dwStyle = rawItem->style;
item->dwExtStyle = rawItem->exStyle;
item->sX = rawItem->x;
item->sY = rawItem->y;
item->sWidth = rawItem->cx;
item->sHeight = rawItem->cy;
item->wId = rawItem->id;
seeker += sizeof(DLGITEMTEMPLATEEX);
}
else {
DLGITEMTEMPLATE* rawItem = (DLGITEMTEMPLATE*)seeker;
item->dwStyle = rawItem->style;
item->dwExtStyle = rawItem->dwExtendedStyle;
item->sX = rawItem->x;
item->sY = rawItem->y;
item->sWidth = rawItem->cx;
item->sHeight = rawItem->cy;
item->wId = rawItem->id;
seeker += sizeof(DLGITEMTEMPLATE);
}
// Read class variant length array
ReadVarLenArr(seeker, item->szClass);
// Read title variant length array
ReadVarLenArr(seeker, item->szTitle);
// Read creation data variant length array
// First read the size of the array (no null termination)
item->wCreateDataSize = *(WORD*)seeker;
seeker += sizeof(WORD);
// Then read the array it self (if size is not 0)
if (item->wCreateDataSize) {
item->wCreateDataSize -= sizeof(WORD); // Size includes size field itself...
item->szCreationData = new char[item->wCreateDataSize];
CopyMemory(item->szCreationData, seeker, item->wCreateDataSize);
seeker += item->wCreateDataSize;
}
// Add the item to the vector
m_vItems.push_back(item);
}
}
CDialogTemplate::~CDialogTemplate() {
if (m_szMenu && !IS_INTRESOURCE(m_szMenu))
delete [] m_szMenu;
if (m_szClass && !IS_INTRESOURCE(m_szClass))
delete [] m_szClass;
if (m_szTitle)
delete [] m_szTitle;
if (m_szFont)
delete [] m_szTitle;
for (int i = 0; i < m_vItems.size(); i++) {
if (m_vItems[i]->szClass && !IS_INTRESOURCE(m_vItems[i]->szClass))
delete [] m_vItems[i]->szClass;
if (m_vItems[i]->szTitle && !IS_INTRESOURCE(m_vItems[i]->szTitle))
delete [] m_vItems[i]->szTitle;
if (m_vItems[i]->szCreationData)
delete [] m_vItems[i]->szCreationData;
}
}
//////////////////////////////////////////////////////////////////////
// Methods
//////////////////////////////////////////////////////////////////////
// Returns info about the item with the id wId
DialogItemTemplate* CDialogTemplate::GetItem(WORD wId) {
for (int i = 0; i < m_vItems.size(); i++)
if (m_vItems[i]->wId == wId)
return m_vItems[i];
return 0;
}
// Returns info about the item with the indexed i
DialogItemTemplate* CDialogTemplate::GetItemByIdx(DWORD i) {
if (i > m_vItems.size()) return 0;
return m_vItems[i];
}
// Removes an item
void CDialogTemplate::RemoveItem(WORD wId) {
for (int i = 0; i < m_vItems.size(); i++)
if (m_vItems[i]->wId == wId)
m_vItems.erase(m_vItems.begin() + i);
}
// Sets the font of the dialog
void CDialogTemplate::SetFont(char* szFaceName, WORD wFontSize) {
m_dwStyle |= DS_SETFONT;
if (m_szFont) delete [] m_szFont;
m_szFont = new char[lstrlen(szFaceName)];
lstrcpy(m_szFont, szFaceName);
m_sFontSize = wFontSize;
}
// Adds an item to the dialog
void CDialogTemplate::AddItem(DialogItemTemplate item) {
DialogItemTemplate* newItem = new DialogItemTemplate;
CopyMemory(newItem, &item, sizeof(DialogItemTemplate));
if (item.szClass && !IS_INTRESOURCE(item.szClass)) {
newItem->szClass = new char[lstrlen(item.szClass)+1];
lstrcpy(newItem->szClass, item.szClass);
}
if (item.szTitle && !IS_INTRESOURCE(item.szTitle)) {
newItem->szTitle = new char[lstrlen(item.szTitle)+1];
lstrcpy(newItem->szTitle, item.szTitle);
}
if (item.wCreateDataSize) {
newItem->szCreationData = new char[item.wCreateDataSize];
memcpy(newItem->szCreationData, item.szCreationData, item.wCreateDataSize);
}
m_vItems.push_back(newItem);
}
// Moves all of the items in the dialog by (x,y) and resizes the dialog by (x,y)
void CDialogTemplate::MoveAllAndResize(short x, short y) {
// Move all items
for (int i = 0; i < m_vItems.size(); i++) {
m_vItems[i]->sX += x;
m_vItems[i]->sY += y;
}
// Resize
m_sWidth += x;
m_sHeight += y;
}
// Converts pixels to this dialog's units
void CDialogTemplate::PixelsToDlgUnits(short& x, short& y) {
DWORD dwTemp;
BYTE* pbDlg = Save(dwTemp);
HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0);
delete [] pbDlg;
if (!hDlg)
throw runtime_error("Can't create dialog from template!");
RECT r = {0, 0, 1024, 1024};
MapDialogRect(hDlg, &r);
DestroyWindow(hDlg);
x = float(x) / (float(r.right)/1024);
y = float(y) / (float(r.bottom)/1024);
}
// Converts pixels to this dialog's units
void CDialogTemplate::DlgUnitsToPixels(short& x, short& y) {
DWORD dwTemp;
BYTE* pbDlg = Save(dwTemp);
HWND hDlg = CreateDialogIndirect(GetModuleHandle(0), (DLGTEMPLATE*)pbDlg, 0, 0);
delete [] pbDlg;
if (!hDlg)
throw runtime_error("Can't create dialog from template!");
RECT r = {0, 0, 1024, 1024};
MapDialogRect(hDlg, &r);
DestroyWindow(hDlg);
x = float(x) * (float(r.right)/1024);
y = float(y) * (float(r.bottom)/1024);
}
// Saves the dialog in the form of DLGTEMPLATE[EX]
BYTE* CDialogTemplate::Save(DWORD& dwSize) {
// We need the size first to know how much memory to allocate
dwSize = GetSize();
BYTE* pbDlg = new BYTE[dwSize];
ZeroMemory(pbDlg, dwSize);
BYTE* seeker = pbDlg;
if (m_bExtended) {
DLGTEMPLATEEX dh = {
0x0001,
0xFFFF,
m_dwHelpId,
m_dwExtStyle,
m_dwStyle,
m_vItems.size(),
m_sX,
m_sY,
m_sWidth,
m_sHeight
};
CopyMemory(seeker, &dh, sizeof(DLGTEMPLATEEX));
seeker += sizeof(DLGTEMPLATEEX);
}
else {
DLGTEMPLATE dh = {
m_dwStyle,
m_dwExtStyle,
m_vItems.size(),
m_sX,
m_sY,
m_sWidth,
m_sHeight
};
CopyMemory(seeker, &dh, sizeof(DLGTEMPLATE));
seeker += sizeof(DLGTEMPLATE);
}
// Write menu variant length array
WriteStringOrId(m_szMenu);
// Write class variant length array
WriteStringOrId(m_szClass);
// Write title variant length array
WriteStringOrId(m_szTitle);
// Write font variant length array, size, and extended info (if needed)
if (m_dwStyle & DS_SETFONT) {
*(short*)seeker = m_sFontSize;
seeker += sizeof(short);
if (m_bExtended) {
*(short*)seeker = m_sFontWeight;
seeker += sizeof(short);
*(short*)seeker = m_bItalic ? TRUE : FALSE;
seeker += sizeof(short);
}
WriteStringOrId(m_szFont);
}
// Write all of the items
for (int i = 0; i < m_vItems.size(); i++) {
// DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundry
if (DWORD(seeker - pbDlg) % sizeof(DWORD))
seeker += sizeof(WORD);
if (m_bExtended) {
DLGITEMTEMPLATEEX dih = {
m_vItems[i]->dwHelpId,
m_vItems[i]->dwExtStyle,
m_vItems[i]->dwStyle,
m_vItems[i]->sX,
m_vItems[i]->sY,
m_vItems[i]->sWidth,
m_vItems[i]->sHeight,
m_vItems[i]->wId
};
CopyMemory(seeker, &dih, sizeof(DLGITEMTEMPLATEEX));
seeker += sizeof(DLGITEMTEMPLATEEX);
}
else {
DLGITEMTEMPLATE dih = {
m_vItems[i]->dwStyle,
m_vItems[i]->dwExtStyle,
m_vItems[i]->sX,
m_vItems[i]->sY,
m_vItems[i]->sWidth,
m_vItems[i]->sHeight,
m_vItems[i]->wId
};
CopyMemory(seeker, &dih, sizeof(DLGITEMTEMPLATE));
seeker += sizeof(DLGITEMTEMPLATE);
}
// Write class variant length array
WriteStringOrId(m_vItems[i]->szClass);
// Write title variant length array
WriteStringOrId(m_vItems[i]->szTitle);
// Write creation data variant length array
// First write its size
if (m_vItems[i]->wCreateDataSize) m_vItems[i]->wCreateDataSize += sizeof(WORD);
*(WORD*)seeker = m_vItems[i]->wCreateDataSize;
seeker += sizeof(WORD);
// If size is nonzero write the data too
if (m_vItems[i]->wCreateDataSize) {
CopyMemory(seeker, m_vItems[i]->szCreationData, m_vItems[i]->wCreateDataSize);
seeker += m_vItems[i]->wCreateDataSize;
}
}
// DONE!
return pbDlg;
}
// Returns the size that the DLGTEMPLATE[EX] will take when saved
DWORD CDialogTemplate::GetSize() {
DWORD dwSize = m_bExtended ? sizeof(DLGTEMPLATEEX) : sizeof(DLGTEMPLATE);
// Menu
AddStringOrIdSize(m_szMenu);
// Class
AddStringOrIdSize(m_szClass);
// Title
AddStringOrIdSize(m_szTitle);
// Font
if (m_dwStyle & DS_SETFONT) {
dwSize += sizeof(WORD) + (m_bExtended ? 2*sizeof(short) : 0);
AddStringOrIdSize(m_szFont);
}
for (int i = 0; i < m_vItems.size(); i++) {
// DLGITEMTEMPLATE[EX]s must be aligned on DWORD boundry
ALIGN(dwSize, sizeof(DWORD));
dwSize += m_bExtended ? sizeof(DLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE);
// Class
AddStringOrIdSize(m_vItems[i]->szClass);
// Title
AddStringOrIdSize(m_vItems[i]->szTitle);
dwSize += sizeof(WORD) + m_vItems[i]->wCreateDataSize;
}
return dwSize;
}

121
Source/DialogTemplate.h Normal file
View file

@ -0,0 +1,121 @@
/*
Copyright (C) 2002 Amir Szekely <kichik@netvision.net.il>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#if !defined(AFX_DIALOGTEMPLATE_H__C5A973AF_0F56_4BEC_814A_79318E2EB4AC__INCLUDED_)
#define AFX_DIALOGTEMPLATE_H__C5A973AF_0F56_4BEC_814A_79318E2EB4AC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <Windows.h>
#include <Vector>
#include <StdExcept>
using namespace std;
struct DialogItemTemplate {
DWORD dwHelpId; // Extended only
short sX;
short sY;
short sWidth;
short sHeight;
DWORD dwExtStyle;
DWORD dwStyle;
WORD wId;
char *szClass;
char *szTitle;
char *szCreationData;
WORD wCreateDataSize;
};
typedef struct {
WORD dlgVer;
WORD signature;
DWORD helpID;
DWORD exStyle;
DWORD style;
WORD cDlgItems;
short x;
short y;
short cx;
short cy;
} DLGTEMPLATEEX;
typedef struct {
DWORD helpID;
DWORD exStyle;
DWORD style;
short x;
short y;
short cx;
short cy;
WORD id;
} DLGITEMTEMPLATEEX;
class CDialogTemplate {
public:
CDialogTemplate(BYTE* pbData);
virtual ~CDialogTemplate();
DialogItemTemplate* GetItem(WORD wId);
DialogItemTemplate* GetItemByIdx(DWORD i);
void RemoveItem(WORD wId);
void SetFont(char* szFaceName, WORD wFontSize);
void AddItem(DialogItemTemplate item);
void MoveAllAndResize(short x, short y);
void PixelsToDlgUnits(short& x, short& y);
void DlgUnitsToPixels(short& x, short& y);
BYTE* Save(DWORD& dwSize);
DWORD GetSize();
private:
bool m_bExtended;
DWORD m_dwHelpId; // Extended only
short m_sX;
short m_sY;
short m_sWidth;
short m_sHeight;
DWORD m_dwExtStyle;
DWORD m_dwStyle;
char* m_szMenu;
char* m_szClass;
char* m_szTitle;
// Only if DS_FONT style is set
short m_sFontSize;
short m_sFontWeight; // Extended only
bool m_bItalic; // Extended only
char* m_szFont;
// Items vector
vector<DialogItemTemplate*> m_vItems;
};
#endif // !defined(AFX_DIALOGTEMPLATE_H__C5A973AF_0F56_4BEC_814A_79318E2EB4AC__INCLUDED_)

74
Source/Makefile Normal file
View file

@ -0,0 +1,74 @@
#
# This makefile for mingw32 by Nels. Thanks, Nels
#
#
# -- Subdirs --
SUBDIRS = exehead
# -- Objects and source files --
SRCS = crc32.c build.cpp exedata.cpp makenssi.cpp script.cpp tokens.cpp util.cpp ResourceEditor.cpp DialogTemplate.cpp ./zlib/deflate.c ./zlib/trees.c ./bzip2/blocksort.c ./bzip2/bzlib.c ./bzip2/compress.c ./bzip2/huffman.c
OBJS = build.o exedata.o makenssi.o script.o tokens.o util.o script1.res crc32.o ResourceEditor.o DialogTemplate.o deflate.o trees.o blocksort.o bzlib.o compress.o huffman.o
LIBS = -lgdi32 -lversion
# -- Programs --
MAKE = make
CC = gcc
RC = windres
RM = del
# -- Compilers and linker flags --
DEFINES = -DWIN32 -D_WINDOWS_
CFLAGS = -O2 $(DEFINES)
CPPFLAGS = -O2 -fvtable-thunks $(DEFINES)
LFLAGS = -s
RCFLAGS = --input-format rc --output-format coff
all : subdirs makensis
subdirs: $(SUBDIRS)
$(SUBDIRS)::
$(MAKE) -C $@ all
makensis : $(OBJS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LFLAGS) -o makensis.exe $(OBJS) $(LIBS)
# -- Dependencies --
build.o : build.cpp ./zlib/zlib.h ./exehead/config.h ./exehead/fileform.h ./exehead/resource.h exedata.h build.h util.h strlist.h lineparse.h ResourceEditor.h Makefile
exedata.o : exedata.cpp exedata.h ./exehead/Release/bitmap1.h ./exehead/Release/bitmap2.h ./exehead/Release/icon.h ./exehead/Release/unicon.h ./exehead/Release/exehead.h Makefile
makenssi.o : makenssi.cpp build.h util.h exedata.h strlist.h lineparse.h ./exehead/fileform.h ./exehead/config.h Makefile
script.o : script.cpp tokens.h build.h util.h exedata.h strlist.h lineparse.h ResourceEditor.h DialogTemplate.h ./exehead/resource.h ./exehead/fileform.h ./exehead/config.h Makefile
tokens.o : tokens.cpp build.h tokens.h Makefile
util.o : util.cpp ./exehead/fileform.h util.h strlist.h ResourceEditor.h Makefile
crc32.o : crc32.c ./exehead/config.h Makefile
ResourceEditor.o : ResourceEditor.cpp
DialogTemplate.o : DialogTemplate.cpp
# -- Special command line for the resource file --
script1.res : script1.rc resource.h Makefile
$(RC) $(RCFLAGS) -o script1.res -i script1.rc
# -- Special command lines for zlib --
deflate.o : ./zlib/deflate.c ./zlib/deflate.h ./zlib/zutil.h ./zlib/zlib.h ./zlib/zconf.h Makefile ./exehead/config.h
$(CC) $(CFLAGS) -c ./zlib/deflate.c -o deflate.o
trees.o : ./zlib/trees.c ./zlib/deflate.h ./zlib/zutil.h ./zlib/zlib.h ./zlib/zconf.h Makefile ./exehead/config.h
$(CC) $(CFLAGS) -c ./zlib/trees.c -o trees.o
# -- Special command lines for bzip2 --
blocksort.o : ./bzip2/blocksort.c ./bzip2/bzlib.h ./bzip2/bzlib_private.h ./exehead/config.h
$(CC) $(CFLAGS) -c ./bzip2/blocksort.c -o blocksort.o
bzlib.o : ./bzip2/bzlib.c ./bzip2/bzlib.h ./bzip2/bzlib_private.h ./exehead/config.h
$(CC) $(CFLAGS) -c ./bzip2/bzlib.c -o bzlib.o
compress.o : ./bzip2/compress.c ./bzip2/bzlib.h ./bzip2/bzlib_private.h ./exehead/config.h
$(CC) $(CFLAGS) -c ./bzip2/compress.c -o compress.o
huffman.o : ./bzip2/huffman.c ./bzip2/bzlib.h ./bzip2/bzlib_private.h ./exehead/config.h
$(CC) $(CFLAGS) -c ./bzip2/huffman.c -o huffman.o
# -- Clean script --
clean ::
$(MAKE) -C exehead clean
$(RM) *.o
$(RM) script1.res
$(RM) makensis.exe

Some files were not shown because too many files have changed in this diff Show more