Install RA packages from CD. Fixes bug in case-sensitive filesystems for Folder.cs.

This commit is contained in:
Matthew
2010-10-20 05:20:22 +13:00
committed by Paul Chote
parent c3e79405f7
commit 850d26a628
2 changed files with 64 additions and 27 deletions

View File

@@ -38,11 +38,11 @@ namespace OpenRA.FileFormats
static IFolder OpenPackage(string filename) static IFolder OpenPackage(string filename)
{ {
if (filename.EndsWith(".mix")) if (filename.EndsWith(".mix", StringComparison.InvariantCultureIgnoreCase))
return new MixFile(filename, order++); return new MixFile(filename, order++);
else if (filename.EndsWith(".zip")) else if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
return new CompressedPackage(filename, order++); return new CompressedPackage(filename, order++);
else if (filename.EndsWith(".Z")) else if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase))
return new InstallShieldPackage(filename, order++); return new InstallShieldPackage(filename, order++);
else else
return new Folder(filename, order++); return new Folder(filename, order++);
@@ -50,7 +50,6 @@ namespace OpenRA.FileFormats
public static void Mount(string name) public static void Mount(string name)
{ {
name = name.ToLowerInvariant();
var optional = name.StartsWith("~"); var optional = name.StartsWith("~");
if (optional) name = name.Substring(1); if (optional) name = name.Substring(1);

View File

@@ -41,7 +41,9 @@ namespace OpenRA.Utility
argCallbacks.Add("--mod-info", ListModInfo); argCallbacks.Add("--mod-info", ListModInfo);
argCallbacks.Add("--install-ra-music", InstallRAMusic); argCallbacks.Add("--install-ra-music", InstallRAMusic);
argCallbacks.Add("--install-cnc-music", InstallCncMusic); argCallbacks.Add("--install-cnc-music", InstallCncMusic);
argCallbacks.Add("--download-packages", DownloadPackage); argCallbacks.Add("--download-packages", DownloadPackages);
argCallbacks.Add("--install-ra-packages", InstallRAPackages);
argCallbacks.Add("--install-cnc-packages", InstallCncPackages);
if (args.Length == 0) { PrintUsage(); return; } if (args.Length == 0) { PrintUsage(); return; }
var arg = SplitArgs(args[0]); var arg = SplitArgs(args[0]);
@@ -60,7 +62,9 @@ namespace OpenRA.Utility
Console.WriteLine(" --mod-info=MODS List metadata for MODS (comma separated list of 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-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(" --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"); Console.WriteLine(" --download-packages=MOD{,DEST} Download packages for MOD to DEST (def: system temp folder) and install them");
Console.WriteLine(" --install-ra-packages=PATH Install required packages for RA from PATH to CD");
Console.WriteLine(" --install-cnc-packages=PATH Install required packages for C&C from PATH to CD");
} }
static void ListMods(string _) static void ListMods(string _)
@@ -96,15 +100,8 @@ namespace OpenRA.Utility
static void InstallRAMusic(string path) static void InstallRAMusic(string path)
{ {
if (!Directory.Exists(path)) { Console.WriteLine("Error: Path {0} does not exist", path); return; } ExtractPackagesFromMix(path, string.Format("mods{0}ra{0}packages", Path.DirectorySeparatorChar),
FileSystem.Mount(path); "MAIN.MIX", "scores.mix");
if (!FileSystem.Exists("MAIN.MIX")) { Console.WriteLine("Error: Could not find MAIN.MIX in path {0}", path); return; }
FileSystem.Mount("MAIN.MIX");
using (var scoresStream = FileSystem.Open("scores.mix"))
using (var destStream = File.Create(string.Format("mods{0}ra{0}packages{0}scores.mix", Path.DirectorySeparatorChar)))
destStream.Write(scoresStream.ReadAllBytes());
Console.WriteLine("Done"); Console.WriteLine("Done");
} }
@@ -119,7 +116,7 @@ namespace OpenRA.Utility
Console.WriteLine("Done"); Console.WriteLine("Done");
} }
static void DownloadPackage(string argValue) static void DownloadPackages(string argValue)
{ {
string[] args = argValue.Split(','); string[] args = argValue.Split(',');
string mod = ""; string mod = "";
@@ -135,8 +132,7 @@ namespace OpenRA.Utility
if (File.Exists(destFile)) if (File.Exists(destFile))
{ {
Console.WriteLine ("Downloaded file already exists, using it instead."); Console.WriteLine ("Downloaded file already exists, using it instead.");
DownloadFileCompleted(null, ExtractPackagesFromZip(mod, destPath);
new System.ComponentModel.AsyncCompletedEventArgs(null, false, new string[] { mod, destPath }));
return; return;
} }
@@ -153,18 +149,30 @@ namespace OpenRA.Utility
Thread.Sleep(500); Thread.Sleep(500);
} }
static void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) static void ExtractPackagesFromMix(string srcPath, string destPath, string mix, params string[] packages)
{ {
if (e.Error != null) if (!Directory.Exists(srcPath)) { Console.WriteLine("Error: Path {0} does not exist", srcPath); return; }
FileSystem.Mount(srcPath);
if (!FileSystem.Exists(mix)) { Console.WriteLine("Error: Could not find {1} in path {0}", srcPath, mix); return; }
FileSystem.Mount(mix);
if (!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
foreach(string s in packages)
{ {
Console.WriteLine("Error: {0}", e.Error.Message); var destFile = "{0}{1}{2}".F(destPath, Path.DirectorySeparatorChar, s);
return; using (var sourceStream = FileSystem.Open(s))
using (var destStream = File.Create(destFile))
{
Console.WriteLine("Extracting {0}", s);
destStream.Write(sourceStream.ReadAllBytes());
}
}
} }
Console.WriteLine("Download Completed"); static void ExtractPackagesFromZip(string mod, string dest)
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 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); string modPackageDir = string.Format("mods{0}{1}{0}packages{0}", Path.DirectorySeparatorChar, mod);
@@ -194,9 +202,39 @@ namespace OpenRA.Utility
Console.WriteLine ("Done"); Console.WriteLine ("Done");
} }
static void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
Console.WriteLine("Error: {0}", e.Error.Message);
return;
}
Console.WriteLine("Download Completed");
string[] modAndDest = (string[])e.UserState;
ExtractPackagesFromZip(modAndDest[0], modAndDest[1]);
}
static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{ {
Console.WriteLine("{0}% {1}/{2} bytes", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive); Console.WriteLine("{0}% {1}/{2} bytes", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive);
} }
static void InstallRAPackages(string path)
{
ExtractPackagesFromMix(path, "mods{0}ra{0}packages".F(Path.DirectorySeparatorChar), "MAIN.MIX",
"conquer.mix", "russian.mix", "allies.mix", "sounds.mix", "scores.mix",
"snow.mix", "interior.mix", "temperat.mix");
var redalertMixPath = "{0}{1}INSTALL{1}REDALERT.MIX".F(path, Path.DirectorySeparatorChar);
if (!File.Exists(redalertMixPath)) { Console.WriteLine ("Error: REDALERT.MIX could not be found on the CD"); return; }
Console.WriteLine ("Copying REDALERT.MIX");
File.Copy(redalertMixPath, "mods{0}ra{0}packages{0}redalert.mix".F(Path.DirectorySeparatorChar));
Console.WriteLine ("Done");
}
static void InstallCncPackages(string path)
{
Console.WriteLine ("Error: NotI");
}
} }
} }