1 /**
2  * GnuWin32 installer
3  *
4  * License:
5  *   This Source Code Form is subject to the terms of
6  *   the Mozilla Public License, v. 2.0. If a copy of
7  *   the MPL was not distributed with this file, You
8  *   can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * Authors:
11  *   Vladimir Panteleev <vladimir@thecybershadow.net>
12  */
13 
14 module ae.sys.install.gnuwin32;
15 
16 import std.file;
17 import std.path;
18 import std.string : format, split;
19 
20 import ae.utils.meta : singleton, I;
21 
22 public import ae.sys.install.common;
23 
24 final class GnuWin32Component : Installer
25 {
26 	string urlTemplate = "http://gnuwin32.sourceforge.net/downlinks/%s-%s-zip.php";
27 
28 	string componentName;
29 	this(string componentName) { this.componentName = componentName; }
30 
31 	@property override string name() { return "%s (GnuWin32)".format(componentName); }
32 	@property override string subdirectory() { return "gnuwin32"; }
33 	@property override string[] binPaths() { return ["bin"]; }
34 
35 	override @property bool installedLocally()
36 	{
37 		auto manifestDir = directory.buildPath("manifest");
38 		return manifestDir.exists && !manifestDir.dirEntries(componentName ~ "-*-bin.ver", SpanMode.shallow).empty;
39 	}
40 
41 	override void atomicInstallImpl()
42 	{
43 		windowsOnly();
44 		if (!directory.exists)
45 			directory.mkdir();
46 		installUrl(urlTemplate.format(componentName, "bin"));
47 		installUrl(urlTemplate.format(componentName, "dep"));
48 		assert(installedLocally);
49 	}
50 
51 	void installUrl(string url)
52 	{
53 		url
54 			.I!saveAs(url.split("/")[$-1][0..$-8] ~ ".zip")
55 			.I!unpack()
56 			.atomicMoveInto(directory);
57 	}
58 }
59 
60 struct GnuWin32
61 {
62 	static GnuWin32Component opDispatch(string name)()
63 	{
64 		alias component = singleton!(GnuWin32Component, name);
65 		return component;
66 	}
67 }