MathgeomGLS

Форк
0
/
dwsMPIR.Bundle.pas 
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

19
   Bundles MPIR dll (http://www.mpir.org)
20

21
}
22
unit 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

39
interface
40

41
function UnBundle_MPIR_DLL : String;
42

43
// ------------------------------------------------------------------
44
// ------------------------------------------------------------------
45
// ------------------------------------------------------------------
46
implementation
47
// ------------------------------------------------------------------
48
// ------------------------------------------------------------------
49
// ------------------------------------------------------------------
50

51
uses
52
   Winapi.Windows, System.SysUtils, Classes, System.Zip,
53
   dwsSHA3, dwsXPlatform, dwsMPIR;
54

55
var
56
   vDLLFileName : String;
57
   vCS : TRTLCriticalSection;
58

59
// DoUnBundle
60
//
61
procedure DoUnBundle;
62
begin
63
   var zip := TZipFile.Create;
64
   try
65
      var stream := TResourceStream.Create(0, 'mpir', 'bundle');
66
      try
67
         zip.Open(stream, zmRead);
68
         var sha3Index := 0;
69
         if zip.FileInfo[0].UncompressedSize > 99 then
70
            sha3Index := 1;
71
         var buf : TBytes;
72
         zip.Read(sha3Index, buf);
73
         var sha3 := '';
74
         BytesToScriptString(Pointer(buf), Length(buf), sha3);
75
         var dllName := IncludeTrailingPathDelimiter(TPath.GetTempPath) + Copy(sha3, 1, 40)  + '.dll';
76
         var diskDllData := LoadRawBytesFromFile(dllName);
77
         if diskDllData <> '' then begin
78
            if HashSHA3_256(diskDllData) <> Trim(sha3) then
79
               diskDllData := '';
80
         end;
81
         if diskDllData = '' then begin
82
            zip.Read(1-sha3Index, buf);
83
            SaveDataToFile(dllName, buf);
84
         end;
85
         vDLLFileName := dllName;   // only set if successful
86
      finally
87
         stream.Free
88
      end;
89
   finally
90
      zip.Free;
91
   end;
92
end;
93

94
// UnBundle_MPIR_DLL
95
//
96
function UnBundle_MPIR_DLL : String;
97
begin
98
   if vDLLFileName = '' then begin
99
      EnterCriticalSection(vCS);
100
      try
101
         if vDLLFileName = '' then
102
            DoUnBundle;
103
      finally
104
         LeaveCriticalSection(vCS);
105
      end;
106
   end;
107
   Result := vDLLFileName;
108
end;
109

110
// ------------------------------------------------------------------
111
// ------------------------------------------------------------------
112
// ------------------------------------------------------------------
113
initialization
114
// ------------------------------------------------------------------
115
// ------------------------------------------------------------------
116
// ------------------------------------------------------------------
117

118
   InitializeCriticalSection(vCS);
119
   vOnNeedMPIRDynamicDLLName := UnBundle_MPIR_DLL;
120

121
finalization
122

123
   vOnNeedMPIRDynamicDLLName := nil;
124
   DeleteCriticalSection(vCS);
125

126
end.
127

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.