Add a switch for exporting settings

As suggested by #6
This commit is contained in:
Mike Griese 2017-08-14 13:29:39 -07:00
parent 7899586b81
commit 067cf3a29b
4 changed files with 66 additions and 4 deletions

View file

@ -17,7 +17,7 @@ namespace ColorTool
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
// These are in Windows Color table order - BRG, not RGB.
static string[] COLOR_NAMES = {
public static string[] COLOR_NAMES = {
"DARK_BLACK",
"DARK_BLUE",
"DARK_GREEN",

View file

@ -89,6 +89,11 @@ namespace ColorTool
Console.WriteLine(Resources.Usage);
}
static void OutputUsage()
{
Console.WriteLine(Resources.OutputUsage);
}
static void Version()
{
//System.Reflection.Assembly.GetEntryAssembly();
@ -196,6 +201,7 @@ namespace ColorTool
}
return success;
}
static bool SetDefaults(uint[] colorTable)
{
RegistryKey consoleKey = Registry.CurrentUser.OpenSubKey("Console", true);
@ -208,6 +214,37 @@ namespace ColorTool
return true;
}
static bool ExportCurrentAsIni(string outputPath)
{
CONSOLE_SCREEN_BUFFER_INFO_EX csbiex = CONSOLE_SCREEN_BUFFER_INFO_EX.Create();
int STD_OUTPUT_HANDLE = -11;
IntPtr hOut = GetStdHandle(STD_OUTPUT_HANDLE);
bool success = GetConsoleScreenBufferInfoEx(hOut, ref csbiex);
if (success)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(outputPath))
{
file.WriteLine("[table]");
for (int i = 0; i < 16; i++)
{
string line = IniSchemeParser.COLOR_NAMES[i];
line += " = ";
uint color = csbiex.ColorTable[i];
uint r = color & (0x000000ff);
uint g = (color & (0x0000ff00)) >> 8;
uint b = (color & (0x00ff0000)) >> 16;
line += r + "," + g + "," + b;
file.WriteLine(line);
}
}
}
else
{
Console.WriteLine("Failed to get conosle information.");
}
return success;
}
static void Main(string[] args)
{
@ -216,9 +253,9 @@ namespace ColorTool
Usage();
return;
}
foreach (string arg in args)
for (int i = 0; i < args.Length; i++)
{
string arg = args[i];
switch (arg)
{
case "-c":
@ -247,6 +284,17 @@ namespace ColorTool
case "--version":
Version();
return;
case "-o":
case "--output":
if (i+1 < args.Length)
{
ExportCurrentAsIni(args[i + 1]);
}
else
{
OutputUsage();
}
return;
default:
break;
}

View file

@ -98,6 +98,15 @@ namespace ColorTool {
}
}
/// <summary>
/// Looks up a localized string similar to Usage: colortool -o &lt;filename&gt;.
/// </summary>
public static string OutputUsage {
get {
return ResourceManager.GetString("OutputUsage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not find or load &quot;{0}&quot;.
/// </summary>

View file

@ -131,6 +131,9 @@
<data name="InvalidNumberOfColors" xml:space="preserve">
<value>Invalid scheme - did not find 16 colors</value>
</data>
<data name="OutputUsage" xml:space="preserve">
<value>Usage: colortool -o &lt;filename&gt;</value>
</data>
<data name="SchemeNotFound" xml:space="preserve">
<value>Could not find or load "{0}"</value>
</data>
@ -151,7 +154,9 @@ Options:
-q, --quiet : Don't print the color table after applying
-d, --defaults : Apply the scheme to only the defaults in the registry
-b, --both : Apply the scheme to both the current console and the defaults.
-v, --version : Display the version number</value>
-v, --version : Display the version number
-o, --output &lt;filename&gt; : output the current color table to an file (in .ini format)
</value>
</data>
<data name="WroteToDefaults" xml:space="preserve">
<value>Wrote selected scheme to the defaults.</value>