Allow argument chaining.

Example to extract test.gma into test and afterwards overwriting test.gma using files in test2:
  gmadsharp extract test.gma test create test2 test.gma
lua-bytecode
Icedream 2014-12-11 03:39:31 +01:00
parent ca52705a04
commit d7661343bb
1 changed files with 120 additions and 109 deletions

View File

@ -2,6 +2,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using GarrysMod.AddonCreator.Addon; using GarrysMod.AddonCreator.Addon;
namespace GarrysMod.AddonCreator namespace GarrysMod.AddonCreator
@ -9,6 +10,8 @@ namespace GarrysMod.AddonCreator
internal static class Program internal static class Program
{ {
private static void Main(string[] args) private static void Main(string[] args)
{
while (args.Any())
{ {
switch (args.Length == 0 ? "" : args[0]) switch (args.Length == 0 ? "" : args[0])
{ {
@ -34,8 +37,8 @@ namespace GarrysMod.AddonCreator
foreach (var file in folder.EnumerateFiles("*", SearchOption.AllDirectories)) foreach (var file in folder.EnumerateFiles("*", SearchOption.AllDirectories))
{ {
var relpath = var relpath =
MakeRelativePath(folder.FullName, file.FullName).Replace(Path.DirectorySeparatorChar, '/'); MakeRelativePath(folder.FullName, file.FullName)
Console.WriteLine("Adding: {0}", relpath); .Replace(Path.DirectorySeparatorChar, '/');
addon.Files.Add(relpath, new PhysicalAddonFileInfo(file.FullName)); addon.Files.Add(relpath, new PhysicalAddonFileInfo(file.FullName));
} }
@ -45,8 +48,10 @@ namespace GarrysMod.AddonCreator
addon.Export(output); addon.Export(output);
Console.WriteLine("Done."); Console.WriteLine("Done.");
args = args.Skip(3).ToArray();
break; break;
} }
case "extract": case "extract":
{ {
if (args.Length < 3) if (args.Length < 3)
@ -90,7 +95,8 @@ namespace GarrysMod.AddonCreator
{ {
var relpath = file.Key; var relpath = file.Key;
var targetFile = var targetFile =
new FileInfo(Path.Combine(folder.FullName, relpath.Replace('/', Path.DirectorySeparatorChar))); new FileInfo(Path.Combine(folder.FullName,
relpath.Replace('/', Path.DirectorySeparatorChar)));
Console.WriteLine("Extracting: {0}", relpath); Console.WriteLine("Extracting: {0}", relpath);
@ -116,12 +122,16 @@ namespace GarrysMod.AddonCreator
} }
fs.Write(toWriteBuf.ToArray(), 0, toWrite); fs.Write(toWriteBuf.ToArray(), 0, toWrite);
} }
fs.Flush();
} }
} }
Console.WriteLine("Done."); Console.WriteLine("Done.");
args = args.Skip(3).ToArray();
break; break;
} }
default: default:
Console.WriteLine("Usage: {0} <command> <arguments>", Process.GetCurrentProcess().ProcessName); Console.WriteLine("Usage: {0} <command> <arguments>", Process.GetCurrentProcess().ProcessName);
Console.WriteLine(); Console.WriteLine();
@ -131,7 +141,8 @@ namespace GarrysMod.AddonCreator
Console.WriteLine("\t{0}\t{1}", "create", "Creates a GMA file."); Console.WriteLine("\t{0}\t{1}", "create", "Creates a GMA file.");
Console.WriteLine("\t\tArguments: Input folder path, output GMA file path"); Console.WriteLine("\t\tArguments: Input folder path, output GMA file path");
Console.WriteLine(); Console.WriteLine();
break; return;
}
} }
} }