/*
* a simple assembly information display application .. bla
* (c) 2004 Alexander Schuc <aschuc@furred.net>
*
* free for use and distribution .. ;)
*
*/
using System;
using System.IO;
using System.Reflection;
namespace furred.Tools
{
public class AssemblyInformation
{
public static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("usage resinfo [options] asssembly.(exe|dll)");
return;
}
else
new AssemblyInformation(args[args.Length-1]);
}
private string asm_path;
private Assembly asm;
private static string NL = Environment.NewLine;
public AssemblyInformation(string file)
{
asm_path = file;
if (init())
loop();
}
private void loop()
{
while (true)
{
for (int i = 0; i < 6; i++)
Console.Write(NL);
Console.Write("\t## Assembly Information{0}\t1) File Info{1}\t2) Ressource Information{2}\t3) Save Ressource{3}{4}\t0) Quit{5}"
, NL, NL, NL, NL, NL, NL);
int code = -1;
Console.Write("\t> ");
try
{
code = int.Parse(Console.ReadLine());
Console.WriteLine();
}
catch (Exception ex)
{
Console.WriteLine("\tINVALID COMMAND");
continue;
}
if (processCode(code))
break;
}
}
private bool processCode(int code)
{
switch (code)
{
case 1: showFileInfo(); break;
case 2: listRessources(); break;
case 3: saveRessource(); break;
case 0: return true;
}
return false;
}
private void showFileInfo()
{
Console.WriteLine("\tCurrent file:\t{0}", asm_path);
Console.WriteLine("\tLocation:\t{0}", asm.Location);
Console.WriteLine("\tFull name:\t{0}", asm.FullName);
Console.WriteLine("\tImage Runtime Version:\t", asm.ImageRuntimeVersion);
}
private void listRessources()
{
string[] names = asm.GetManifestResourceNames();
for (int i = 0; i < names.Length; i++)
{
Console.WriteLine("\t#{0} - {1}", i, names[i]);
}
Console.WriteLine();
Console.WriteLine("To save one of these files in a file, remember the number of the file and use the 'Save Ressource' command");
}
private void saveRessource()
{
Console.WriteLine("\t### Save Ressource");
Console.Write("\tPlease enter the number of the file: ");
int num;
try
{
num = int.Parse(Console.ReadLine());
}
catch (Exception ex)
{
Console.WriteLine("INVALID ARGUMENT!");
return;
}
if (num >= asm.GetManifestResourceNames().Length)
{
Console.WriteLine("INVALID ARGUMENT!");
return;
}
string filename = asm.GetManifestResourceNames()[num];
int bytes;
using (FileStream fs = File.Create(filename))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
using (Stream strm = asm.GetManifestResourceStream(filename))
{
bytes = (int)strm.Length;
byte[] buffer = new byte[bytes];
strm.Read(buffer, 0, bytes);
bw.Write(buffer);
}
}
}
Console.WriteLine("\t{0} Bytes written to \"{1}\"", bytes, filename);
}
private bool init()
{
if (!File.Exists(asm_path))
{
Console.WriteLine("File not found!");
return false;
}
asm = Assembly.LoadFrom(asm_path);
return true;
}
}
}