MathgeomGLS
126 строк · 4.0 Кб
1{**********************************************************************}
2{ }
3{ "The contents of this file are subject to the Mozilla Public }
4{ License Version 1.1 (the "License"); you may not use this }
5{ file except in compliance with the License. You may obtain }
6{ a copy of the License at http://www.mozilla.org/MPL/ }
7{ }
8{ Software distributed under the License is distributed on an }
9{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express }
10{ or implied. See the License for the specific language }
11{ governing rights and limitations under the License. }
12{ }
13{ Copyright Creative IT. }
14{ Current maintainer: Eric Grange }
15{ }
16{**********************************************************************}
17{
18
19Bundles MPIR dll (http://www.mpir.org)
20
21}
22unit dwsMPIR.Bundle;
23
24{$I dws.inc}
25
26{$define USE_MPIR3}
27
28{$ifdef USE_MPIR3}
29{$ifdef WIN64}
30{$R mpir3-64.RES}
31{$endif}
32{$ifdef WIN32}
33{$R mpir3-32.RES}
34{$endif}
35{$else}
36{$R mpir.RES}
37{$endif}
38
39interface
40
41function UnBundle_MPIR_DLL : String;
42
43// ------------------------------------------------------------------
44// ------------------------------------------------------------------
45// ------------------------------------------------------------------
46implementation
47// ------------------------------------------------------------------
48// ------------------------------------------------------------------
49// ------------------------------------------------------------------
50
51uses
52Winapi.Windows, System.SysUtils, Classes, System.Zip,
53dwsSHA3, dwsXPlatform, dwsMPIR;
54
55var
56vDLLFileName : String;
57vCS : TRTLCriticalSection;
58
59// DoUnBundle
60//
61procedure DoUnBundle;
62begin
63var zip := TZipFile.Create;
64try
65var stream := TResourceStream.Create(0, 'mpir', 'bundle');
66try
67zip.Open(stream, zmRead);
68var sha3Index := 0;
69if zip.FileInfo[0].UncompressedSize > 99 then
70sha3Index := 1;
71var buf : TBytes;
72zip.Read(sha3Index, buf);
73var sha3 := '';
74BytesToScriptString(Pointer(buf), Length(buf), sha3);
75var dllName := IncludeTrailingPathDelimiter(TPath.GetTempPath) + Copy(sha3, 1, 40) + '.dll';
76var diskDllData := LoadRawBytesFromFile(dllName);
77if diskDllData <> '' then begin
78if HashSHA3_256(diskDllData) <> Trim(sha3) then
79diskDllData := '';
80end;
81if diskDllData = '' then begin
82zip.Read(1-sha3Index, buf);
83SaveDataToFile(dllName, buf);
84end;
85vDLLFileName := dllName; // only set if successful
86finally
87stream.Free
88end;
89finally
90zip.Free;
91end;
92end;
93
94// UnBundle_MPIR_DLL
95//
96function UnBundle_MPIR_DLL : String;
97begin
98if vDLLFileName = '' then begin
99EnterCriticalSection(vCS);
100try
101if vDLLFileName = '' then
102DoUnBundle;
103finally
104LeaveCriticalSection(vCS);
105end;
106end;
107Result := vDLLFileName;
108end;
109
110// ------------------------------------------------------------------
111// ------------------------------------------------------------------
112// ------------------------------------------------------------------
113initialization
114// ------------------------------------------------------------------
115// ------------------------------------------------------------------
116// ------------------------------------------------------------------
117
118InitializeCriticalSection(vCS);
119vOnNeedMPIRDynamicDLLName := UnBundle_MPIR_DLL;
120
121finalization
122
123vOnNeedMPIRDynamicDLLName := nil;
124DeleteCriticalSection(vCS);
125
126end.
127