/
gnuwin32.d
74 lines (62 loc) · 1.86 KB
/
gnuwin32.d
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* GnuWin32 installer
*
* License:
* This Source Code Form is subject to the terms of
* the Mozilla Public License, v. 2.0. If a copy of
* the MPL was not distributed with this file, You
* can obtain one at http://mozilla.org/MPL/2.0/.
*
* Authors:
* Vladimir Panteleev <ae@cy.md>
*/
module ae.sys.install.gnuwin32;
import std.file;
import std.path;
import std.string : format, split;
import ae.utils.meta : singleton, I;
public import ae.sys.install.common;
/// Installs a GnuWin32 component.
final class GnuWin32Component : Installer
{
/// Template for component .zip files.
string urlTemplate = "http://gnuwin32.sourceforge.net/downlinks/%s-%s-zip.php";
/// Component to install.
string componentName;
this(string componentName) { this.componentName = componentName; } ///
protected:
@property override string name() { return "%s (GnuWin32)".format(componentName); }
@property override string subdirectory() { return "gnuwin32"; }
@property override string[] binPaths() { return ["bin"]; }
override @property bool installedLocally()
{
auto manifestDir = directory.buildPath("manifest");
return manifestDir.exists && !manifestDir.dirEntries(componentName ~ "-*-bin.ver", SpanMode.shallow).empty;
}
override void atomicInstallImpl()
{
windowsOnly();
if (!directory.exists)
directory.mkdir();
installUrl(urlTemplate.format(componentName, "bin"));
installUrl(urlTemplate.format(componentName, "dep"));
assert(installedLocally);
}
void installUrl(string url)
{
url
.I!saveAs(url.split("/")[$-1][0..$-8] ~ ".zip")
.I!unpack()
.atomicMoveInto(directory);
}
}
/// `opDispatch` constructor for GnuWin32 component installers.
struct GnuWin32
{
/// Example: `GnuWin32.make.requireLocal(false);`.
static GnuWin32Component opDispatch(string name)()
{
alias component = singleton!(GnuWin32Component, name);
return component;
}
}