1 | /*
|
---|
2 | * Copyright (C) 1995-2009 Contributors
|
---|
3 | * More detailed copyright information can be found in the individual source code files.
|
---|
4 | *
|
---|
5 | * This software is provided 'as-is', without any express or implied warranty.
|
---|
6 | * In no event will the authors be held liable for any damages arising from the use of this software.
|
---|
7 | *
|
---|
8 | * Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter
|
---|
9 | * it and redistribute it freely, subject to the following restrictions:
|
---|
10 | *
|
---|
11 | * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
|
---|
12 | * If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
---|
13 | * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
---|
14 | * 3. This notice may not be removed or altered from any source distribution.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /** Taken from:
|
---|
18 | * http://nsis.sourceforge.net/Examples/Plugin/exdll.h
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h
|
---|
22 | #define GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h
|
---|
23 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
24 | # pragma once
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | #include <iprt/win/windows.h>
|
---|
28 |
|
---|
29 | #if defined(__GNUC__)
|
---|
30 | #define UNUSED __attribute__((unused))
|
---|
31 | #else
|
---|
32 | #define UNUSED
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | // Starting with NSIS 2.42, you can check the version of the plugin API in exec_flags->plugin_api_version
|
---|
36 | // The format is 0xXXXXYYYY where X is the major version and Y is the minor version (MAKELONG(y,x))
|
---|
37 | // When doing version checks, always remember to use >=, ex: if (pX->exec_flags->plugin_api_version >= NSISPIAPIVER_1_0) {}
|
---|
38 |
|
---|
39 | #define NSISPIAPIVER_1_0 0x00010000
|
---|
40 | #define NSISPIAPIVER_CURR NSISPIAPIVER_1_0
|
---|
41 |
|
---|
42 | // NSIS Plug-In Callback Messages
|
---|
43 | enum NSPIM
|
---|
44 | {
|
---|
45 | NSPIM_UNLOAD, // This is the last message a plugin gets, do final cleanup
|
---|
46 | NSPIM_GUIUNLOAD, // Called after .onGUIEnd
|
---|
47 | };
|
---|
48 |
|
---|
49 | /** Defines the maximum string length NSIS can handle.
|
---|
50 | * Note: This depends on the NSIS build being used, e.g. there are different builds which can also handle larger strings.
|
---|
51 | * So to play safe go with the minimum (default) string length here. */
|
---|
52 | #define NSIS_MAX_STRLEN 1024
|
---|
53 |
|
---|
54 | // Prototype for callbacks registered with extra_parameters->RegisterPluginCallback()
|
---|
55 | // Return NULL for unknown messages
|
---|
56 | // Should always be __cdecl for future expansion possibilities
|
---|
57 | typedef UINT_PTR (*NSISPLUGINCALLBACK)(enum NSPIM);
|
---|
58 |
|
---|
59 | #ifndef NSISCALL
|
---|
60 | # define NSISCALL __stdcall
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #ifndef VBOX
|
---|
64 | // only include this file from one place in your DLL.
|
---|
65 | // (it is all static, if you use it in two places it will fail)
|
---|
66 |
|
---|
67 | #define EXDLL_INIT() { \
|
---|
68 | g_stringsize=string_size; \
|
---|
69 | g_stacktop=stacktop; \
|
---|
70 | g_variables=variables; }
|
---|
71 | #endif /* !VBOX */
|
---|
72 |
|
---|
73 | typedef struct _stack_t
|
---|
74 | {
|
---|
75 | struct _stack_t *next;
|
---|
76 | TCHAR text[1]; // this should be the length of string_size
|
---|
77 | } stack_t;
|
---|
78 |
|
---|
79 | // extra_parameters data structures containing other interesting stuff
|
---|
80 | // but the stack, variables and HWND passed on to plug-ins.
|
---|
81 | typedef struct
|
---|
82 | {
|
---|
83 | int autoclose;
|
---|
84 | int all_user_var;
|
---|
85 | int exec_error;
|
---|
86 | int abort;
|
---|
87 | int exec_reboot; // NSIS_SUPPORT_REBOOT
|
---|
88 | int reboot_called; // NSIS_SUPPORT_REBOOT
|
---|
89 | int XXX_cur_insttype; // depreacted
|
---|
90 | int plugin_api_version; // see NSISPIAPIVER_CURR
|
---|
91 | // used to be XXX_insttype_changed
|
---|
92 | int silent; // NSIS_CONFIG_SILENT_SUPPORT
|
---|
93 | int instdir_error;
|
---|
94 | int rtl;
|
---|
95 | int errlvl;
|
---|
96 | int alter_reg_view;
|
---|
97 | int status_update;
|
---|
98 | } exec_flags_t;
|
---|
99 |
|
---|
100 | typedef struct
|
---|
101 | {
|
---|
102 | exec_flags_t *exec_flags;
|
---|
103 | int (NSISCALL *ExecuteCodeSegment)(int, HWND);
|
---|
104 | void (NSISCALL *validate_filename)(TCHAR *);
|
---|
105 | BOOL (NSISCALL *RegisterPluginCallback)(HMODULE, NSISPLUGINCALLBACK);
|
---|
106 | } extra_parameters;
|
---|
107 |
|
---|
108 | #ifndef VBOX
|
---|
109 | static unsigned int g_stringsize;
|
---|
110 | static stack_t **g_stacktop;
|
---|
111 | static TCHAR *g_variables;
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | enum
|
---|
115 | {
|
---|
116 | INST_0, // $0
|
---|
117 | INST_1, // $1
|
---|
118 | INST_2, // $2
|
---|
119 | INST_3, // $3
|
---|
120 | INST_4, // $4
|
---|
121 | INST_5, // $5
|
---|
122 | INST_6, // $6
|
---|
123 | INST_7, // $7
|
---|
124 | INST_8, // $8
|
---|
125 | INST_9, // $9
|
---|
126 | INST_R0, // $R0
|
---|
127 | INST_R1, // $R1
|
---|
128 | INST_R2, // $R2
|
---|
129 | INST_R3, // $R3
|
---|
130 | INST_R4, // $R4
|
---|
131 | INST_R5, // $R5
|
---|
132 | INST_R6, // $R6
|
---|
133 | INST_R7, // $R7
|
---|
134 | INST_R8, // $R8
|
---|
135 | INST_R9, // $R9
|
---|
136 | INST_CMDLINE, // $CMDLINE
|
---|
137 | INST_INSTDIR, // $INSTDIR
|
---|
138 | INST_OUTDIR, // $OUTDIR
|
---|
139 | INST_EXEDIR, // $EXEDIR
|
---|
140 | INST_LANG, // $LANGUAGE
|
---|
141 | __INST_LAST
|
---|
142 | };
|
---|
143 |
|
---|
144 | #ifndef VBOX
|
---|
145 |
|
---|
146 | // utility functions (not required but often useful)
|
---|
147 | int popstringn(TCHAR *str, int maxlen)
|
---|
148 | {
|
---|
149 | stack_t *th;
|
---|
150 | if (!g_stacktop || !*g_stacktop) return 1;
|
---|
151 | th=(*g_stacktop);
|
---|
152 | if (str) lstrcpyn(str,th->text,maxlen?maxlen:g_stringsize);
|
---|
153 | *g_stacktop = th->next;
|
---|
154 | GlobalFree((HGLOBAL)th);
|
---|
155 | return 0;
|
---|
156 | }
|
---|
157 |
|
---|
158 | static void __stdcall pushstring(const TCHAR *str)
|
---|
159 | {
|
---|
160 | stack_t *th;
|
---|
161 | if (!g_stacktop)
|
---|
162 | return;
|
---|
163 | th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
|
---|
164 | lstrcpyn(th->text,str,g_stringsize);
|
---|
165 | th->next=*g_stacktop;
|
---|
166 | *g_stacktop=th;
|
---|
167 | }
|
---|
168 |
|
---|
169 | static TCHAR* __stdcall getuservariable(const int varnum)
|
---|
170 | {
|
---|
171 | if (varnum < 0 || varnum >= __INST_LAST)
|
---|
172 | return NULL;
|
---|
173 | return g_variables+varnum*g_stringsize;
|
---|
174 | }
|
---|
175 |
|
---|
176 | static void __stdcall setuservariable(const int varnum, const TCHAR *var)
|
---|
177 | {
|
---|
178 | if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
|
---|
179 | lstrcpy(g_variables + varnum*g_stringsize, var);
|
---|
180 | }
|
---|
181 |
|
---|
182 | #endif /* ! VBOX */
|
---|
183 |
|
---|
184 | #endif /* !GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h */
|
---|