Instantly share code, notes, and snippets.

Embed
What would you like to do?
The decompiled source of my lost script profile manager.
// Decompiled with JetBrains decompiler
// Type: ScriptProfileManager.Program
// Assembly: ScriptProfileManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FE955248-3D94-490C-97D2-DB7ACE4D9DC9
// Assembly location: C:\dev\Tools\ScriptProfileManager\ScriptProfileManager.dll
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ScriptProfileManager
{
internal class Program
{
private static string FindFilePath(string fileName)
{
for (string str = Directory.GetCurrentDirectory(); str != null; str = Directory.GetParent(str)?.FullName)
{
string path = Path.Combine(str, fileName);
if (File.Exists(path))
return path;
}
return (string) null;
}
private static string DecorateCommand(string filePath, string powershellCommand)
{
return string.Format("pushd {0}; {1}; popd", (object) Path.GetDirectoryName(filePath), (object) powershellCommand);
}
private static void Main(string[] args)
{
Dictionary<string, string> dictionary1 = new Dictionary<string, string>();
string filePath1 = Program.FindFilePath(".ok");
if (filePath1 != null)
{
foreach (string readAllLine in File.ReadAllLines(filePath1))
{
char[] separator = new char[1]{ ':' };
List<string> list = ((IEnumerable<string>) readAllLine.Split(separator, 2)).Select<string, string>((Func<string, string>) (part => part.Trim())).ToList<string>();
dictionary1[list[0]] = Program.DecorateCommand(filePath1, list[1]);
}
}
string filePath2 = Program.FindFilePath("package.json");
if (filePath2 != null)
{
Dictionary<string, string> dictionary2 = JObject.Parse(File.ReadAllText(filePath2))["scripts"]?.ToObject<Dictionary<string, string>>();
if (dictionary2 != null)
{
foreach (string key in dictionary2.Keys)
{
string index = key;
if (dictionary1.ContainsKey(key))
index = string.Format("npm/{0}", (object) key);
dictionary1[index] = Program.DecorateCommand(filePath2, string.Format("npm run {0}", (object) key));
}
}
}
if (args.Length >= 1)
{
string str = args[0];
string index = (string) null;
double num1 = 0.0;
foreach (string key in dictionary1.Keys)
{
if (key.ToLower().StartsWith(str.ToLower()))
{
double num2 = (double) str.Length / (double) key.Length;
if (num2 > num1)
{
index = key;
num1 = num2;
}
}
}
if (index == null)
return;
Console.WriteLine(dictionary1[index]);
}
else
{
foreach (object key in dictionary1.Keys)
Console.WriteLine(string.Format("{0}", key));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment