Downloaded packages extracted. Added SharpZipLib in order to extract them.

This commit is contained in:
Matthew
2010-10-16 00:50:28 +13:00
parent 90d1d3e053
commit 50860614cf
4 changed files with 65 additions and 12 deletions

View File

@@ -82,7 +82,7 @@ tsbuild_EXTRA = -resource:OpenRA.TilesetBuilder.Form1.resources
utility_SRCS = $(shell find OpenRA.Utility/ -iname '*.cs')
utility_TARGET = OpenRA.Utility.exe
utility_KIND = exe
utility_DEPS = $(fileformats_TARGET)
utility_DEPS = $(fileformats_TARGET) thirdparty/ICSharpCode.SharpZipLib.dll
utility_LIBS = $(COMMON_LIBS) $(utility_DEPS)
@@ -130,6 +130,7 @@ install: all
@cp *.ttf $(INSTALL_DIR)
@cp --parents -r thirdparty/Tao $(INSTALL_DIR)
@$(INSTALL_PROGRAM) thirdparty/WindowsBase.dll $(INSTALL_DIR)
@$(INSTALL_PROGRAM) thirdparty/ICSharpCode.SharpZipLib.dll $(INSTALL_DIR)
@-$(INSTALL_PROGRAM) VERSION $(INSTALL_DIR)
@echo "#!/bin/sh" > openra

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -44,6 +44,10 @@
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
@@ -56,6 +60,7 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@@ -16,6 +16,8 @@ using OpenRA.FileFormats;
using System.IO;
using System.Net;
using System.Threading;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
namespace OpenRA.Utility
{
@@ -54,11 +56,11 @@ namespace OpenRA.Utility
{
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION]");
Console.WriteLine();
Console.WriteLine(" --list-mods List currently installed mods");
Console.WriteLine(" --mod-info=MODS List metadata for MODS (comma separated list of mods)");
Console.WriteLine(" --install-ra-music=PATH Install scores.mix from PATH to Red Alert CD");
Console.WriteLine(" --install-cnc-music=PATH Install scores.mix from PATH to Command & Conquer CD");
Console.WriteLine(" --download-packages=MOD Download and install the packages for MOD");
Console.WriteLine(" --list-mods List currently installed mods");
Console.WriteLine(" --mod-info=MODS List metadata for MODS (comma separated list of mods)");
Console.WriteLine(" --install-ra-music=PATH Install scores.mix from PATH to Red Alert CD");
Console.WriteLine(" --install-cnc-music=PATH Install scores.mix from PATH to Command & Conquer CD");
Console.WriteLine(" --download-packages=MOD{,PATH} Download packages for MOD to PATH (def: system temp folder) and install them");
}
static void ListMods(string _)
@@ -117,15 +119,35 @@ namespace OpenRA.Utility
Console.WriteLine("Done");
}
static void DownloadPackage(string mod)
static void DownloadPackage(string argValue)
{
string[] args = argValue.Split(',');
string mod = "";
string destPath = Path.GetTempPath();
if (args.Length >= 1)
mod = args[0];
if (args.Length >= 2)
destPath = args[1];
string destFile = string.Format("{0}{1}{2}-packages.zip", destPath, Path.DirectorySeparatorChar, mod);
if (File.Exists(destFile))
{
Console.WriteLine ("Downloaded file already exists, using it instead.");
DownloadFileCompleted(null,
new System.ComponentModel.AsyncCompletedEventArgs(null, false, new string[] { mod, destPath }));
return;
}
WebClient wc = new WebClient();
wc.DownloadProgressChanged += DownloadProgressChanged;
wc.DownloadFileCompleted += DownloadFileCompleted;
Console.WriteLine("Downloading {0}-packages.zip to {1}", mod, destPath);
wc.DownloadFileAsync(
new Uri(string.Format("http://open-ra.org/get-dependency.php?file={0}-packages", mod)),
string.Format("{0}{1}{2}-packages.zip", Path.GetTempPath(), Path.DirectorySeparatorChar, mod),
mod);
destFile,
new string[] { mod, destPath });
while (wc.IsBusy)
Thread.Sleep(500);
@@ -140,8 +162,33 @@ namespace OpenRA.Utility
}
Console.WriteLine("Download Completed");
//TODO: Extract packages into mod dir
string[] modAndDest = (string[])e.UserState;
string mod = modAndDest[0];
string dest = modAndDest[1];
string filepath = string.Format("{0}{1}{2}-packages.zip", dest, Path.DirectorySeparatorChar, mod);
string modPackageDir = string.Format("mods{0}{1}{0}packages{0}", Path.DirectorySeparatorChar, mod);
using (var z = new ZipInputStream(File.OpenRead(filepath)))
{
ZipEntry entry;
while ((entry = z.GetNextEntry()) != null)
{
if (!entry.IsFile) continue;
Console.WriteLine ("Extracting {0}", entry.Name);
using (var f = File.Create(modPackageDir + entry.Name))
{
int bufSize = 2048;
byte[] buf = new byte[bufSize];
while ((bufSize = z.Read(buf, 0, buf.Length)) > 0)
{
f.Write(buf, 0, bufSize);
}
}
}
}
Console.WriteLine ("Done");
}
static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)

BIN
thirdparty/ICSharpCode.SharpZipLib.dll vendored Normal file

Binary file not shown.