# encoding: ascii
# api: csharp
# title: WhatIs
# description: UNIX which and whatis tools analog.
# version: 0.1
# type: class
# author: greg zakharov
# license: CC0
# x-poshcode-id: 4515
# x-archived: 2013-10-16T20:22:58
# x-published: 2013-10-10T16:45:00
#
#
using System;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Globalization;

[assembly: AssemblyVersion("2.0.0.0")]

namespace WhatIsTool {
  internal sealed class Program {
    static string[] SplitVariable(string eVar) {
      return Environment.ExpandEnvironmentVariables(eVar).Split(new Char[] {';'});
    }
    
    static void Main(string[] args) {
      string query, desc;
      
      if (args.Length == 1) {
        foreach (string path in SplitVariable("%PATH%")) {
          foreach (string ext in SplitVariable("%PATHEXT%")) {
            query = path + @"\" + args[0] + ext.ToLower(CultureInfo.CurrentCulture);
            if (File.Exists(query)) {
              desc = FileVersionInfo.GetVersionInfo(query).FileDescription;
              Console.WriteLine("{0} - {1}", query, String.IsNullOrEmpty(desc) ? "n/a" : desc);
            }
          }
        }
      }
    }
  }
}
