Commits

Jason McKesson committed 193cd18

Can download externals.

  • Participants
  • Parent commits 15b3e3b

Comments (0)

Files changed (1)

get_externals.lua

+--[[
+This script downloads all of the external dependencies and unzips them to the proper directory. You will need to have 7z in your path to run this, as well as the LuaSocket, UFS, and EX Lua modules.
+]]
+
+local io = require("io")
+local http = require("socket.http")
+local ltn12 = require("ltn12")
+require("ex")
+require "ufs"
+require "_FindFileInPath"
+
+
+local externals =
+{
+	{
+		"OpenGL SDK 0.3.0",		--The name of the component.
+		"glsdk",					--The output directory to copy the component's data.
+		"glsdk.7z",				--The filename that will be created in the download director.
+		"glsdk_0.3.0",			--If the zip file has a base directory, then name it here. If it doesn't, then just use ""
+		[==[http://downloads.sourceforge.net/project/glsdk/GLSDK%200.3.0/glsdk_0.3.0.7z?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fglsdk%2Ffiles%2FGLSDK%25200.3.0%2F&ts=1317700021&use_mirror=cdnetworks-us-2]==]
+	},
+}
+
+local zipFullName = FindFileInPath("7z.exe");
+
+if(zipFullName == nil) then
+	return
+end
+
+local function RecursiveCopy(fromDir, toDir)
+	for entry in ufs.directory_iterator(fromDir) do
+		local es = entry:status();
+		local srcPath = entry:path();
+		
+		local pathDestName = toDir / srcPath:filename();
+		if(ufs.is_regular_file(es)) then
+			ufs.copy_file(srcPath, pathDestName, ufs.copy_option_overwrite_if_exists);
+		end
+		
+		if(ufs.is_directory(es)) then
+			local bDidCreate, ec = ufs.create_directory(pathDestName);
+			RecursiveCopy(srcPath, pathDestName);
+		end
+	end
+end
+
+local decompressDir = ".\\extract";
+ufs.create_directory(ufs.path(decompressDir));
+
+for i, ext in ipairs(externals) do
+	print("Downloading: " .. ext[1]);
+	
+	local compressFile = decompressDir .. "\\" .. ext[3];
+	
+	local hFile = assert(io.open(compressFile, "wb"));
+	http.request {url = ext[5], sink = ltn12.sink.file(hFile)}
+	
+	local unzipDir = decompressDir .. "\\dir" .. i;
+	ufs.create_directory(ufs.path(unzipDir));
+	
+	print("Extracting: " .. ext[1]);
+	if(ext[3]:match("%.tar%.gz$")) then
+		local proc = ex.spawn(zipFullName, {
+			args={"x", "-y", "-o" .. decompressDir, compressFile},
+			});
+			
+		local tarFile = compressFile:match("(.+)%.gz$");
+		proc:wait(proc);
+
+		proc = ex.spawn(zipFullName, {
+			args={"x", "-y", "-o" .. unzipDir, tarFile},
+			});
+		proc:wait(proc);
+	else
+		proc = ex.spawn(zipFullName, {
+			args={"x", "-y", "-o" .. unzipDir, compressFile},
+			});
+		proc:wait(proc);
+	end
+	
+	print("Copying: " .. ext[1]);
+	local pathSrc = ufs.path(unzipDir);
+	if(#ext[4] ~= 0) then
+		pathSrc = pathSrc / ext[4]
+	end
+
+	local pathOut = ufs.path(".\\" .. ext[2]);
+	ufs.create_directory(pathOut);
+	RecursiveCopy(pathSrc, pathOut);
+end
+
+ufs.remove_all(ufs.path(decompressDir));
+
+