Skip to content

Commit

Permalink
Added preset persistance for custom programs
Browse files Browse the repository at this point in the history
Custom program paths, arguments, read output toggle, and order will now persist between compile pal sessions.

Custom order is now being stored in warning instead of parameter so it would play nice with the existing system for initializing presets.
  • Loading branch information
Exactol committed Jun 28, 2018
1 parent 4f3306d commit 06f9d54
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
8 changes: 4 additions & 4 deletions CompilePalX/Compilers/CustomProcess.cs
Expand Up @@ -28,9 +28,9 @@ public List<CustomProgram> BuildProgramList()
//Set default order to 15
int order = 15;

//Use parameter to hold custom order
if (!string.IsNullOrWhiteSpace(parameter.Parameter))
Int32.TryParse(parameter.Parameter, out order);
//Use warning to hold custom order
if (!string.IsNullOrWhiteSpace(parameter.Warning))
Int32.TryParse(parameter.Warning, out order);

if (string.IsNullOrWhiteSpace(path))
continue;
Expand Down Expand Up @@ -198,7 +198,7 @@ protected bool Equals(ConfigItem other)
if (other == null)
return false;

return (ReadOutput == other.ReadOutput && string.Equals(Path, other.Value) && string.Equals(CustomOrder.ToString(), other.Parameter) && Equals(Args, other.Value2));
return (ReadOutput == other.ReadOutput && string.Equals(Path, other.Value) && string.Equals(CustomOrder.ToString(), other.Warning) && Equals(Args, other.Value2));
}

public override int GetHashCode()
Expand Down
25 changes: 21 additions & 4 deletions CompilePalX/Configuration/ConfigurationManager.cs
Expand Up @@ -108,7 +108,7 @@ private static void AssemblePresets()

foreach (var line in lines)
{
var item = ParsePresetLine(line);
var item = ParsePresetLine(line);

if (process.ParameterList.Any(c => c.Parameter == item.Parameter))
{
Expand All @@ -117,6 +117,14 @@ private static void AssemblePresets()

equivalentItem.Value = item.Value;

//Copy extra information stored for custom programs
if (item.Parameter == "program")
{
equivalentItem.Value2 = item.Value2;
equivalentItem.Warning = item.Warning;
}


process.PresetDictionary[preset].Add(equivalentItem);
}
}
Expand Down Expand Up @@ -278,16 +286,25 @@ private static ConfigItem ParsePresetLine(string line)
item.Parameter = pieces[0];
if (pieces.Count() >= 2)
item.Value = pieces[1];
//Handle extra information stored for custom programs
if (pieces.Count() >= 3)
item.Value2 = pieces[2];
if (pieces.Length >= 4)
item.ReadOutput = Convert.ToBoolean(pieces[3]);
if (pieces.Length >= 5)
item.Warning = pieces[4];
}
return item;
}

private static string WritePresetLine(ConfigItem item)
private static string WritePresetLine(ConfigItem item)
{
return string.Format("{0},{1}", item.Parameter, item.Value);
//Handle extra information stored for custom programs
if (item.Name == "Run Program")
return $"{item.Parameter},{item.Value},{item.Value2},{item.ReadOutput},{item.Warning}";
return $"{item.Parameter},{item.Value}";
}


private static ConfigItem ParseBaseLine(string line)
{
var item = new ConfigItem();
Expand Down
9 changes: 4 additions & 5 deletions CompilePalX/MainWindow.xaml.cs
Expand Up @@ -213,7 +213,6 @@ void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExce
void SetSources()
{
CompileProcessesListBox.ItemsSource = CompileProcessesSubList;

PresetConfigListBox.ItemsSource = ConfigurationManager.KnownPresets;

MapListBox.ItemsSource = CompilingManager.MapFiles;
Expand Down Expand Up @@ -481,7 +480,9 @@ private void UpdateConfigGrid()
ProcessDataGrid.BeginAnimation(OpacityProperty, new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(50))));
processModeEnabled = true;

ConfigDataGrid.IsEnabled = false;
ProcessDataGrid.ItemsSource = selectedProcess.PresetDictionary[ConfigurationManager.CurrentPreset];

ConfigDataGrid.IsEnabled = false;
ConfigDataGrid.Visibility = Visibility.Hidden;
ParametersTextBox.Visibility = Visibility.Hidden;

Expand All @@ -491,8 +492,6 @@ private void UpdateConfigGrid()
ProcessTab.IsEnabled = true;
ProcessTab.Visibility = Visibility.Visible;

ProcessDataGrid.ItemsSource = selectedProcess.PresetDictionary[ConfigurationManager.CurrentPreset];

//Hide parameter buttons if ORDER is the current tab
if ((string)(ProcessTab.SelectedItem as TabItem)?.Header == "ORDER")
{
Expand Down Expand Up @@ -703,7 +702,7 @@ public void SetOrder<T>(T target, int newOrder)
return;

program.CustomOrder = newOrder;
programConfig.Parameter = newOrder.ToString();
programConfig.Warning = newOrder.ToString();
}


Expand Down
4 changes: 2 additions & 2 deletions CompilePalX/Parameters/CUSTOM/parameters.json
@@ -1,13 +1,13 @@
[
{
"Name": "Run Program",
"Parameter": "15",
"Parameter": "program",
"Description": "Run a program with command line arguments",
"Value": null,
"Value2": null,
"ReadOutput": true,
"CanHaveValue": true,
"CanBeUsedMoreThanOnce": true,
"Warning": ""
"Warning": "15"
}
]

0 comments on commit 06f9d54

Please sign in to comment.