From 21ae6ee98368cfda96e07955f20fb82e05fef02a Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 11 Sep 2011 17:13:43 +1200 Subject: [PATCH] convert FileExtractor into a Utility cmdlet --- FileExtractor/FileExtractor.cs | 62 ------------------- FileExtractor/FileExtractor.csproj | 43 ------------- FileExtractor/Main.cs | 23 ------- Makefile | 11 +--- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 3 +- .../OpenRA.Renderer.SdlCommon.csproj | 2 +- OpenRA.Utility/Command.cs | 19 ++++++ OpenRA.Utility/Program.cs | 2 + OpenRA.sln | 10 --- RALint/RALint.csproj | 2 +- 10 files changed, 25 insertions(+), 152 deletions(-) delete mode 100644 FileExtractor/FileExtractor.cs delete mode 100644 FileExtractor/FileExtractor.csproj delete mode 100644 FileExtractor/Main.cs diff --git a/FileExtractor/FileExtractor.cs b/FileExtractor/FileExtractor.cs deleted file mode 100644 index 4325994d59..0000000000 --- a/FileExtractor/FileExtractor.cs +++ /dev/null @@ -1,62 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; -using System.IO; -using OpenRA.FileFormats; - -namespace FileExtractor -{ - public class FileExtractor - { - int Length = 256; - - public FileExtractor (string[] args) - { - if (args.Length != 2) - { - Console.WriteLine("usage: FileExtractor mod[,mod]* filename"); - return; - } - - var mods = args[0].Split(','); - var manifest = new Manifest(mods); - FileSystem.LoadFromManifest( manifest ); - - try - { - var readStream = FileSystem.Open(args[1]); - var writeStream = new FileStream(args[1], FileMode.OpenOrCreate, FileAccess.Write); - - WriteOutFile(readStream, writeStream); - - } - catch (FileNotFoundException) - { - Console.WriteLine(String.Format("No Such File {0}", args[1])); - } - } - - void WriteOutFile (Stream readStream, Stream writeStream) - { - Byte[] buffer = new Byte[Length]; - int bytesRead = readStream.Read(buffer,0,Length); - - while( bytesRead > 0 ) - { - writeStream.Write(buffer,0,bytesRead); - bytesRead = readStream.Read(buffer,0,Length); - } - readStream.Close(); - writeStream.Close(); - } - } -} - diff --git a/FileExtractor/FileExtractor.csproj b/FileExtractor/FileExtractor.csproj deleted file mode 100644 index cc2b94ef25..0000000000 --- a/FileExtractor/FileExtractor.csproj +++ /dev/null @@ -1,43 +0,0 @@ - - - - Debug - AnyCPU - 9.0.21022 - 2.0 - {210645C7-E99E-46B6-863E-E211AE6C7D70} - Exe - FileExtractor - FileExtractor - v3.5 - - - true - full - false - ..\ - DEBUG - prompt - 4 - false - - - none - false - ..\ - prompt - 4 - false - - - - {BDAEAB25-991E-46A7-AF1E-4F0E03358DAA} - OpenRA.FileFormats - - - - - - - - \ No newline at end of file diff --git a/FileExtractor/Main.cs b/FileExtractor/Main.cs deleted file mode 100644 index 31015ea947..0000000000 --- a/FileExtractor/Main.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; - -namespace FileExtractor -{ - public class MainClass - { - public static void Main (string[] args) - { - new FileExtractor(args); - } - } -} - diff --git a/Makefile b/Makefile index 84b4f268f2..d2d486dda2 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ PHONY = core tools package all mods clean distclean .SUFFIXES: core: game renderers mod_ra mod_cnc utility -tools: editor ralint seqed filex tsbuild +tools: editor ralint seqed tsbuild package: core editor mods: mod_ra mod_cnc all: core tools @@ -137,15 +137,6 @@ ralint_LIBS = $(COMMON_LIBS) $(ralint_DEPS) PROGRAMS += ralint ralint: $(ralint_TARGET) -# Extracts files from packages (mixfiles, zips, etc) -filex_SRCS := $(shell find FileExtractor/ -iname '*.cs') -filex_TARGET = FileExtractor.exe -filex_KIND = exe -filex_DEPS = $(fileformats_TARGET) -filex_LIBS = $(COMMON_LIBS) $(filex_DEPS) -PROGRAMS += filex -filex: $(filex_TARGET) - # Builds and exports tilesets from a bitmap tsbuild_SRCS := $(shell find OpenRA.TilesetBuilder/ -iname '*.cs') tsbuild_TARGET = TilesetBuilder.exe diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index db6d0d8a17..99dc45a675 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -302,7 +302,6 @@ - diff --git a/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj b/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj index e67866e7cb..786a453847 100644 --- a/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj +++ b/OpenRA.Renderer.SdlCommon/OpenRA.Renderer.SdlCommon.csproj @@ -1,4 +1,4 @@ - + Debug diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index fda30f8c51..9507159560 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -128,5 +128,24 @@ namespace OpenRA.Utility ShpWriter.Write(destStream, size.Width, size.Height, srcImage.Select( im => im.Image )); } + + public static void ExtractFiles(string[] args) + { + var mods = args[1].Split(','); + var files = args.Skip(2); + + var manifest = new Manifest(mods); + FileSystem.LoadFromManifest(manifest); + + foreach( var f in files ) + { + var src = FileSystem.Open(f); + if (src == null) + throw new InvalidOperationException("File not found: {0}".F(f)); + var data = src.ReadAllBytes(); + + File.WriteAllBytes( f, data ); + } + } } } diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 112d3313cb..fcf60b7a24 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -25,6 +25,7 @@ namespace OpenRA.Utility { "--shp", Command.ConvertPngToShp }, { "--png", Command.ConvertShpToPng }, { "--fromd2", Command.ConvertFormat2ToFormat80 }, + { "--extract", Command.ExtractFiles }, }; if (args.Length == 0) { PrintUsage(); return; } @@ -57,6 +58,7 @@ namespace OpenRA.Utility Console.WriteLine(" --settings-value KEY Get value of KEY from settings.yaml"); Console.WriteLine(" --shp PNGFILE FRAMEWIDTH Convert a PNG containing one or more frames to a SHP"); Console.WriteLine(" --png SHPFILE PALETTE Convert a SHP to a PNG containing all of its frames"); + Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages"); } static T WithDefault(T def, Func f) diff --git a/OpenRA.sln b/OpenRA.sln index 5ba83944cb..1c6684f816 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -25,8 +25,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.TilesetBuilder", "Op EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RALint", "RALint\RALint.csproj", "{F9FA4D9F-2302-470A-8A07-6E37F488C124}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileExtractor", "FileExtractor\FileExtractor.csproj", "{210645C7-E99E-46B6-863E-E211AE6C7D70}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Utility", "OpenRA.Utility\OpenRA.Utility.csproj", "{F33337BE-CB69-4B24-850F-07D23E408DDF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Renderer.Null", "OpenRA.Renderer.Null\OpenRA.Renderer.Null.csproj", "{0C4AEC1A-E7D5-4114-8CCD-3EEC82872981}" @@ -66,14 +64,6 @@ Global {0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Any CPU.ActiveCfg = Release|x86 {0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Mixed Platforms.ActiveCfg = Release|x86 {0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Mixed Platforms.Build.0 = Release|x86 - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Debug|Any CPU.Build.0 = Debug|Any CPU - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Release|Any CPU.ActiveCfg = Release|Any CPU - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Release|Any CPU.Build.0 = Release|Any CPU - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {210645C7-E99E-46B6-863E-E211AE6C7D70}.Release|Mixed Platforms.Build.0 = Release|Any CPU {230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 diff --git a/RALint/RALint.csproj b/RALint/RALint.csproj index 7139a86074..710e319278 100644 --- a/RALint/RALint.csproj +++ b/RALint/RALint.csproj @@ -1,4 +1,4 @@ - + Debug