home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Programming / nsis-2.46-setup.exe / Examples / Plugin / nsis.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2009-06-08  |  5.2 KB  |  202 lines

  1. {
  2.     Original Code from
  3.     (C) 2001 - Peter Windridge
  4.  
  5.     Code in seperate unit and some changes
  6.     2003 by Bernhard Mayer
  7.  
  8.     Fixed and formatted by Brett Dever
  9.     http://editor.nfscheats.com/
  10.  
  11.     simply include this unit in your plugin project and export
  12.     functions as needed
  13. }
  14.  
  15. unit nsis;
  16.  
  17. interface
  18.  
  19. uses
  20.   windows, CommCtrl, SysUtils;
  21.  
  22. type
  23.   VarConstants = (
  24.     INST_0,       // $0
  25.     INST_1,       // $1
  26.     INST_2,       // $2
  27.     INST_3,       // $3
  28.     INST_4,       // $4
  29.     INST_5,       // $5
  30.     INST_6,       // $6
  31.     INST_7,       // $7
  32.     INST_8,       // $8
  33.     INST_9,       // $9
  34.     INST_R0,      // $R0
  35.     INST_R1,      // $R1
  36.     INST_R2,      // $R2
  37.     INST_R3,      // $R3
  38.     INST_R4,      // $R4
  39.     INST_R5,      // $R5
  40.     INST_R6,      // $R6
  41.     INST_R7,      // $R7
  42.     INST_R8,      // $R8
  43.     INST_R9,      // $R9
  44.     INST_CMDLINE, // $CMDLINE
  45.     INST_INSTDIR, // $INSTDIR
  46.     INST_OUTDIR,  // $OUTDIR
  47.     INST_EXEDIR,  // $EXEDIR
  48.     INST_LANG,    // $LANGUAGE
  49.     __INST_LAST
  50.     );
  51.   TVariableList = INST_0..__INST_LAST;
  52.  
  53.   TExecuteCodeSegment = function (const funct_id: Integer; const parent: HWND): Integer;  stdcall;
  54.   Tvalidate_filename = procedure (const filename: PChar); cdecl;
  55.   TRegisterPluginCallback = function (const unknow: Integer; const uknown2: Integer): Integer; cdecl;
  56.  
  57.   pexec_flags_t = ^exec_flags_t;
  58.   exec_flags_t = record
  59.     autoclose: Integer;
  60.     all_user_var: Integer;
  61.     exec_error: Integer;
  62.     abort: Integer;
  63.     exec_reboot: Integer;
  64.     reboot_called: Integer;
  65.     XXX_cur_insttype: Integer;
  66.     plugin_api_version: Integer;
  67.     silent: Integer;
  68.     instdir_error: Integer;
  69.     rtl: Integer;
  70.     errlvl: Integer;
  71.     alter_reg_view: Integer;
  72.     status_update: Integer;
  73.   end;
  74.  
  75.   pextrap_t = ^extrap_t;
  76.   extrap_t = record
  77.     exec_flags: Pointer; // exec_flags_t;
  78.     exec_code_segment: Pointer; //  TFarProc;
  79.     validate_filename: Pointer; // Tvalidate_filename;
  80.     RegisterPluginCallback: Pointer; //TRegisterPluginCallback;
  81.   end;
  82.  
  83.   pstack_t = ^stack_t;
  84.   stack_t = record
  85.     next: pstack_t;
  86.     text: PChar;
  87.   end;
  88.  
  89. var
  90.   g_stringsize: integer;
  91.   g_stacktop: ^pstack_t;
  92.   g_variables: PChar;
  93.   g_hwndParent: HWND;
  94.   g_hwndList: HWND;
  95.   g_hwndLogList: HWND;
  96.  
  97.   g_extraparameters: pextrap_t;
  98.   func : TExecuteCodeSegment;
  99.   extrap : extrap_t;
  100.  
  101. procedure Init(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer; const extraparameters: pointer = nil);
  102.  
  103. function LogMessage(Msg : String): BOOL;
  104. function Call(NSIS_func : String) : Integer;
  105. function PopString(): string;
  106. procedure PushString(const str: string='');
  107. function GetUserVariable(const varnum: TVariableList): string;
  108. procedure SetUserVariable(const varnum: TVariableList; const value: string);
  109. procedure NSISDialog(const text, caption: string; const buttons: integer);
  110.  
  111. implementation
  112.  
  113. procedure Init(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer; const extraparameters: pointer = nil);
  114. begin
  115.   g_stringsize := string_size;
  116.   g_hwndParent := hwndParent;
  117.   g_stacktop   := stacktop;
  118.   g_variables  := variables;
  119.   g_hwndList := 0;
  120.   g_hwndList := FindWindowEx(FindWindowEx(g_hwndParent, 0, '#32770', nil), 0,'SysListView32', nil);
  121.   g_extraparameters := extraparameters;
  122.   extrap := g_extraparameters^;
  123. end;
  124.  
  125. function Call(NSIS_func : String) : Integer;
  126. var
  127.   NSISFun: Integer; //The ID of nsis function
  128. begin
  129.   Result := 0;
  130.   NSISFun := StrToIntDef(NSIS_func, 0);
  131.   if (NSISFun <> 0) and (g_extraparameters <> nil) then
  132.     begin
  133.     @func := extrap.exec_code_segment;
  134.     NSISFun := NSISFun - 1;
  135.     Result := func(NSISFun, g_hwndParent);
  136.     end;
  137. end;
  138.  
  139. function LogMessage(Msg : String): BOOL;
  140. var
  141.   ItemCount : Integer;
  142.   item: TLVItem;
  143. begin
  144.   Result := FAlse;
  145.   if g_hwndList = 0 then exit;
  146.   FillChar( item, sizeof(item), 0 );
  147.   ItemCount := SendMessage(g_hwndList, LVM_GETITEMCOUNT, 0, 0);
  148.   item.iItem := ItemCount;
  149.   item.mask := LVIF_TEXT;
  150.   item.pszText := PAnsiChar(Msg);
  151.   ListView_InsertItem(g_hwndList, item );
  152.   ListView_EnsureVisible(g_hwndList, ItemCount, TRUE);
  153. end;
  154.  
  155. function PopString(): string;
  156. var
  157.   th: pstack_t;
  158. begin
  159.   if integer(g_stacktop^) <> 0 then begin
  160.     th := g_stacktop^;
  161.     Result := PChar(@th.text);
  162.     g_stacktop^ := th.next;
  163.     GlobalFree(HGLOBAL(th));
  164.   end;
  165. end;
  166.  
  167. procedure PushString(const str: string='');
  168. var
  169.   th: pstack_t;
  170. begin
  171.   if integer(g_stacktop) <> 0 then begin
  172.     th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
  173.     lstrcpyn(@th.text, PChar(str), g_stringsize);
  174.     th.next := g_stacktop^;
  175.     g_stacktop^ := th;
  176.   end;
  177. end;
  178.  
  179. function GetUserVariable(const varnum: TVariableList): string;
  180. begin
  181.   if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
  182.     Result := g_variables + integer(varnum) * g_stringsize
  183.   else
  184.     Result := '';
  185. end;
  186.  
  187. procedure SetUserVariable(const varnum: TVariableList; const value: string);
  188. begin
  189.   if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
  190.     lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value))
  191. end;
  192.  
  193. procedure NSISDialog(const text, caption: string; const buttons: integer);
  194. begin
  195.   MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons);
  196. end;
  197.  
  198. begin
  199.  
  200. end.
  201.  
  202.