Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | { |
michael@0 | 2 | Original Code from |
michael@0 | 3 | (C) 2001 - Peter Windridge |
michael@0 | 4 | |
michael@0 | 5 | Code in seperate unit and some changes |
michael@0 | 6 | 2003 by Bernhard Mayer |
michael@0 | 7 | |
michael@0 | 8 | Fixed and formatted by Brett Dever |
michael@0 | 9 | http://editor.nfscheats.com/ |
michael@0 | 10 | |
michael@0 | 11 | simply include this unit in your plugin project and export |
michael@0 | 12 | functions as needed |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | |
michael@0 | 16 | unit nsis; |
michael@0 | 17 | |
michael@0 | 18 | interface |
michael@0 | 19 | |
michael@0 | 20 | uses |
michael@0 | 21 | windows; |
michael@0 | 22 | |
michael@0 | 23 | type |
michael@0 | 24 | VarConstants = ( |
michael@0 | 25 | INST_0, // $0 |
michael@0 | 26 | INST_1, // $1 |
michael@0 | 27 | INST_2, // $2 |
michael@0 | 28 | INST_3, // $3 |
michael@0 | 29 | INST_4, // $4 |
michael@0 | 30 | INST_5, // $5 |
michael@0 | 31 | INST_6, // $6 |
michael@0 | 32 | INST_7, // $7 |
michael@0 | 33 | INST_8, // $8 |
michael@0 | 34 | INST_9, // $9 |
michael@0 | 35 | INST_R0, // $R0 |
michael@0 | 36 | INST_R1, // $R1 |
michael@0 | 37 | INST_R2, // $R2 |
michael@0 | 38 | INST_R3, // $R3 |
michael@0 | 39 | INST_R4, // $R4 |
michael@0 | 40 | INST_R5, // $R5 |
michael@0 | 41 | INST_R6, // $R6 |
michael@0 | 42 | INST_R7, // $R7 |
michael@0 | 43 | INST_R8, // $R8 |
michael@0 | 44 | INST_R9, // $R9 |
michael@0 | 45 | INST_CMDLINE, // $CMDLINE |
michael@0 | 46 | INST_INSTDIR, // $INSTDIR |
michael@0 | 47 | INST_OUTDIR, // $OUTDIR |
michael@0 | 48 | INST_EXEDIR, // $EXEDIR |
michael@0 | 49 | INST_LANG, // $LANGUAGE |
michael@0 | 50 | __INST_LAST |
michael@0 | 51 | ); |
michael@0 | 52 | TVariableList = INST_0..__INST_LAST; |
michael@0 | 53 | pstack_t = ^stack_t; |
michael@0 | 54 | stack_t = record |
michael@0 | 55 | next: pstack_t; |
michael@0 | 56 | text: PChar; |
michael@0 | 57 | end; |
michael@0 | 58 | |
michael@0 | 59 | var |
michael@0 | 60 | g_stringsize: integer; |
michael@0 | 61 | g_stacktop: ^pstack_t; |
michael@0 | 62 | g_variables: PChar; |
michael@0 | 63 | g_hwndParent: HWND; |
michael@0 | 64 | |
michael@0 | 65 | procedure Init(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); |
michael@0 | 66 | function PopString(): string; |
michael@0 | 67 | procedure PushString(const str: string=''); |
michael@0 | 68 | function GetUserVariable(const varnum: TVariableList): string; |
michael@0 | 69 | procedure SetUserVariable(const varnum: TVariableList; const value: string); |
michael@0 | 70 | procedure NSISDialog(const text, caption: string; const buttons: integer); |
michael@0 | 71 | |
michael@0 | 72 | implementation |
michael@0 | 73 | |
michael@0 | 74 | procedure Init(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); |
michael@0 | 75 | begin |
michael@0 | 76 | g_stringsize := string_size; |
michael@0 | 77 | g_hwndParent := hwndParent; |
michael@0 | 78 | g_stacktop := stacktop; |
michael@0 | 79 | g_variables := variables; |
michael@0 | 80 | end; |
michael@0 | 81 | |
michael@0 | 82 | function PopString(): string; |
michael@0 | 83 | var |
michael@0 | 84 | th: pstack_t; |
michael@0 | 85 | begin |
michael@0 | 86 | if integer(g_stacktop^) <> 0 then begin |
michael@0 | 87 | th := g_stacktop^; |
michael@0 | 88 | Result := PChar(@th.text); |
michael@0 | 89 | g_stacktop^ := th.next; |
michael@0 | 90 | GlobalFree(HGLOBAL(th)); |
michael@0 | 91 | end; |
michael@0 | 92 | end; |
michael@0 | 93 | |
michael@0 | 94 | procedure PushString(const str: string=''); |
michael@0 | 95 | var |
michael@0 | 96 | th: pstack_t; |
michael@0 | 97 | begin |
michael@0 | 98 | if integer(g_stacktop) <> 0 then begin |
michael@0 | 99 | th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize)); |
michael@0 | 100 | lstrcpyn(@th.text, PChar(str), g_stringsize); |
michael@0 | 101 | th.next := g_stacktop^; |
michael@0 | 102 | g_stacktop^ := th; |
michael@0 | 103 | end; |
michael@0 | 104 | end; |
michael@0 | 105 | |
michael@0 | 106 | function GetUserVariable(const varnum: TVariableList): string; |
michael@0 | 107 | begin |
michael@0 | 108 | if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then |
michael@0 | 109 | Result := g_variables + integer(varnum) * g_stringsize |
michael@0 | 110 | else |
michael@0 | 111 | Result := ''; |
michael@0 | 112 | end; |
michael@0 | 113 | |
michael@0 | 114 | procedure SetUserVariable(const varnum: TVariableList; const value: string); |
michael@0 | 115 | begin |
michael@0 | 116 | if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then |
michael@0 | 117 | lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value)) |
michael@0 | 118 | end; |
michael@0 | 119 | |
michael@0 | 120 | procedure NSISDialog(const text, caption: string; const buttons: integer); |
michael@0 | 121 | begin |
michael@0 | 122 | MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons); |
michael@0 | 123 | end; |
michael@0 | 124 | |
michael@0 | 125 | begin |
michael@0 | 126 | end. |