[cil-strip] Upgrade to latest Mono.Cecil API
[mono.git] / mcs / tools / cil-strip / cilstrip.cs
index 4b56f2e16ae208caafe3be861ece4b358f220c36..b5d7ff13094ed08265f32c380850c127bc31644a 100644 (file)
@@ -8,7 +8,6 @@
 //
 
 using System;
-using System.IO;
 using System.Reflection;
 
 using Mono.Cecil;
@@ -17,7 +16,7 @@ namespace Mono.CilStripper {
 
        class Program {
 
-               static void Main (string [] args)
+               static int Main (string [] args)
                {
                        Header ();
 
@@ -26,20 +25,24 @@ namespace Mono.CilStripper {
 
                        string file = args [0];
                        string output = args.Length > 1 ? args [1] : file;
+                       bool replace = file == output;
 
                        try {
-                               AssemblyDefinition assembly = AssemblyFactory.GetAssembly (file);
-                               StripAssembly (assembly, output);
+                               using (var assembly = AssemblyDefinition.ReadAssembly (file, new ReaderParameters { ReadWrite = replace })) {
+                                       StripAssembly (assembly, replace ? null : output);
+                               }
 
-                               if (file != output)
-                                       Console.WriteLine ("Assembly {0} stripped out into {1}", file, output);
-                               else
+                               if (replace)
                                        Console.WriteLine ("Assembly {0} stripped", file);
+                               else
+                                       Console.WriteLine ("Assembly {0} stripped out into {1}", file, output);
+                               return 0;
                        } catch (TargetInvocationException tie) {
                                Console.WriteLine ("Error: {0}", tie.InnerException);
                        } catch (Exception e) {
                                Console.WriteLine ("Error: {0}", e);
                        }
+                       return 1;
                }
 
                static void StripAssembly (AssemblyDefinition assembly, string output)