PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/win/nsi/nsis_uac/NSISUtil.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 149 lines | 113 code | 24 blank | 12 comment | 6 complexity | afa86128ade9e22ff94bcac262b07f10 MD5 | raw file
  1/*
  2Alternative to ExDll.h
  3
  4v0.0.1 - 20060811 (AndersK)
  5*/
  6
  7#pragma once

  8#include <TChar.h>

  9
 10
 11typedef TCHAR NSISCH;
 12#define NSISCALL      __stdcall

 13
 14namespace NSIS {
 15
 16__forceinline void* NSISCALL MemAlloc(SIZE_T cb) {return GlobalAlloc(LPTR,cb);}
 17__forceinline void NSISCALL MemFree(void* p) {GlobalFree(p);}
 18
 19enum {
 20INST_0,         // $0
 21INST_1,         // $1
 22INST_2,         // $2
 23INST_3,         // $3
 24INST_4,         // $4
 25INST_5,         // $5
 26INST_6,         // $6
 27INST_7,         // $7
 28INST_8,         // $8
 29INST_9,         // $9
 30INST_R0,        // $R0
 31INST_R1,        // $R1
 32INST_R2,        // $R2
 33INST_R3,        // $R3
 34INST_R4,        // $R4
 35INST_R5,        // $R5
 36INST_R6,        // $R6
 37INST_R7,        // $R7
 38INST_R8,        // $R8
 39INST_R9,        // $R9
 40INST_CMDLINE,   // $CMDLINE
 41INST_INSTDIR,   // $INSTDIR
 42INST_OUTDIR,    // $OUTDIR
 43INST_EXEDIR,    // $EXEDIR
 44INST_LANG,      // $LANGUAGE
 45__INST_LAST,
 46
 47VIDX_TEMP=(INST_LANG+1), //#define state_temp_dir            g_usrvars[25]
 48VIDX_PLUGINSDIR,//#  define state_plugins_dir       g_usrvars[26]
 49VIDX_EXEPATH,//#define state_exe_path            g_usrvars[27]
 50VIDX_EXEFILENAME,//#define state_exe_file            g_usrvars[28]
 51VIDX_STATECLICKNEXT,//#define state_click_next          g_usrvars[30]
 52__VIDX_UNDOCLAST
 53};
 54
 55
 56
 57typedef struct _stack_t {
 58  struct _stack_t *next;
 59  NSISCH text[ANYSIZE_ARRAY];
 60} stack_t;
 61
 62typedef struct {
 63  int autoclose;
 64  int all_user_var;
 65  int exec_error;
 66  int abort;
 67  int exec_reboot;
 68  int reboot_called;
 69  int XXX_cur_insttype; // deprecated
 70  int XXX_insttype_changed; // deprecated
 71  int silent;
 72  int instdir_error;
 73  int rtl;
 74  int errlvl;
 75//NSIS v2.3x ?
 76  int alter_reg_view;
 77  int status_update;
 78} exec_flags_type;
 79
 80typedef struct {
 81  exec_flags_type *exec_flags;
 82  int (NSISCALL *ExecuteCodeSegment)(int, HWND);
 83  void (NSISCALL *validate_filename)(char *);
 84} extra_parameters;
 85
 86extern UINT StrSize;
 87extern stack_t **StackTop;
 88extern NSISCH*Vars;
 89
 90inline bool NSISCALL SetErrLvl(extra_parameters*pExtraParams,int ErrLevel) {return pExtraParams? ((pExtraParams->exec_flags->errlvl=ErrLevel)||true):false;}
 91inline bool NSISCALL SetErrorFlag(extra_parameters*pExtraParams) {return pExtraParams? ((pExtraParams->exec_flags->exec_error=1)||true):false;}
 92inline bool NSISCALL ClearErrorFlag(extra_parameters*pExtraParams) {return pExtraParams?((pExtraParams->exec_flags->exec_error=0)||true):false;}
 93
 94__forceinline int NSISCALL ExecuteCodeSegment(extra_parameters*pExtraParams,int pos,HWND hwndProgress=NULL) {
 95	return pExtraParams?pExtraParams->ExecuteCodeSegment(pos,hwndProgress):(/*EXEC_ERROR*/0x7FFFFFFF);
 96}
 97
 98static NSISCH* __fastcall GetVar(const int varnum) 
 99{
100	//ASSERT(NSIS::Vars && NSIS::StrSize);
101	if (varnum < 0 || varnum >= __VIDX_UNDOCLAST) return NULL;
102	return NSIS::Vars+(varnum*NSIS::StrSize);
103}
104
105inline void NSISCALL SetVarUINT(const int varnum,UINT Value) {
106	wsprintf(GetVar(varnum),_T("%u"),Value);
107}
108
109static stack_t* NSISCALL StackPop() {
110	if (NSIS::StackTop && *NSIS::StackTop) {
111		stack_t*s=(*NSIS::StackTop);
112		*NSIS::StackTop=(*NSIS::StackTop)->next;
113		return s;
114	}
115	return 0;
116}
117__forceinline void NSISCALL StackFreeItem(stack_t*pStackItem) {NSIS::MemFree(pStackItem);}
118
119static DWORD NSISCALL StackPush(NSISCH*InStr,UINT StackStrSize=NSIS::StrSize) {
120	if (!NSIS::StackTop)return ERROR_INVALID_PARAMETER;
121	stack_t*sNew=(stack_t*)NSIS::MemAlloc(sizeof(stack_t)+(StackStrSize*sizeof(NSISCH)));
122	if (!sNew)return ERROR_OUTOFMEMORY;
123	lstrcpyn(sNew->text,InStr,StackStrSize);
124	sNew->next=*NSIS::StackTop;
125	*NSIS::StackTop=sNew;
126	return NO_ERROR;
127}
128
129}; /* namespace */
130
131#define NSISUTIL_INIT() namespace NSIS {static UINT StrSize;static stack_t **StackTop;static NSISCH*Vars;}//Call in only ONE source file
132#define NSISUTIL_INITEXPORT(_v,_strsize,_stackt) NSIS::Vars=_v;NSIS::StrSize=_strsize;NSIS::StackTop=_stackt

133
134//#define NSISEXPORT4(_func,_h,_strsize,_v,_stackt) extern "C" void __declspec(dllexport) __cdecl \
135//	_func (HWND _h,int _strsize,NSISCH*_v,NSIS::stack_t **_stackt) { NSISUTIL_INITEXPORT(_v,_strsize,_stackt); TRACE("EXPORT::" #_func "\n"); 
136//#define NSISEXPORT5(_func,_h,_strsize,_v,_stackt,_eparams) extern "C" void __declspec(dllexport) __cdecl \
137//	_func (HWND _h,int _strsize,NSISCH*_v,NSIS::stack_t **_stackt,NSIS::extra_parameters* _eparams) {  NSISUTIL_INITEXPORT(_v,_strsize,_stackt); TRACE("EXPORT::" #_func "\n"); 
138//#define NSISEXPORT NSISEXPORT5
139
140#ifdef _MSC_VER

141#	define EXPORTNSISFUNC extern "C" void __declspec(dllexport) __cdecl

142#	else

143#	error EXPORTNSISFUNC needs compiler goo, you are on your own!

144#	endif

145#define NSISFUNCSTART4(_h,_strsize,_v,_stackt) {NSISUTIL_INITEXPORT(_v,_strsize,_stackt);

146#define NSISFUNCSTART5(_h,_strsize,_v,_stackt,_eparams) NSISFUNCSTART4(_h,_strsize,_v,_stackt)

147#define NSISFUNCSTART NSISFUNCSTART5

148#define NSISFUNCEND() }

149