-
Notifications
You must be signed in to change notification settings - Fork 5
/
lea_gwin-installer.adb
56 lines (48 loc) · 1.66 KB
/
lea_gwin-installer.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
with GWindows.Message_Boxes;
with UnZip.Streams;
with Zip;
with Zip_Streams;
with Ada.Command_Line,
Ada.Strings.Unbounded;
with Interfaces.C;
with System;
package body LEA_GWin.Installer is
-- "MemoryModule is a library that can be used to load a DLL
-- completely from memory - without storing on the disk first."
--
-- https://github.com/fancycode/MemoryModule
--
pragma Linker_Options ("..\..\MemoryModule.o");
use Ada.Strings.Unbounded;
procedure Memory_Load_Library (pointer : System.Address; size : Interfaces.C.size_t);
pragma Import (C, Memory_Load_Library, "MemoryLoadLibrary");
procedure Load_Scintilla_DLL_from_Memory is
use Ada.Command_Line, GWindows.Message_Boxes;
lea_exe : constant String := Command_Name;
scintilla_dll : constant String := "SciLexer.dll";
z : Zip.Zip_Info;
m : Zip_Streams.Memory_Zipstream;
b : Unbounded_String;
p : String_Access;
begin
Zip.Load (z, lea_exe);
UnZip.Streams.Extract (m, z, scintilla_dll);
Zip_Streams.Get (m, b);
-- For pointer p, the memory is heap-allocated until
-- the termination of lea.exe:
p := new String (1 .. Length (b));
p.all := To_String (b);
Memory_Load_Library (p (1)'Address, p.all'Length);
exception
when others =>
Message_Box
("LEA startup",
"Installation error: cannot unpack """ & S2G (scintilla_dll) & '"' & NL &
"from Zip archive appended to ""lea.exe""." & NL &
"Path = " & S2G (Command_Name),
OK_Box,
Error_Icon
);
raise;
end Load_Scintilla_DLL_from_Memory;
end LEA_GWin.Installer;