Hi,
I think i've found a bug where the tool will crash (unhandled exception) if the user does not contain any USER (or SYSTEM) environment variables. On my system I do not have any USER variables and as soon as it starts i get greeted by a program crash.
Looking at the code the problem appears to be here:
private void LoadEnvironmentVariables ( DataGridView dgv, EnvironmentVariableTarget target )
{
EnvVarValueValidator validator = new EnvVarValueValidator();
int currentRowIndex = (dgv.CurrentRow != null ? dgv.CurrentRow.Index : 0);
dgv.Rows.Clear();
int rowIndex = 0;
IDictionary environmentVariables = variableManger.GetEnvVariables( target );
foreach ( DictionaryEntry de in environmentVariables )
{
string[ ] row = { de.Key.ToString(), de.Value.ToString() };
rowIndex = dgv.Rows.Add( row );
// validate variable value and show row in red if invalid
if (!validator.Validate(de.Value.ToString()))
{
dgv.Rows[rowIndex].Cells[0].Style.ForeColor = Color.Red;
dgv.Rows[rowIndex].Cells[1].Style.ForeColor = Color.Red;
}
}
dgv.Sort( dgv.Columns[ 0 ], ListSortDirection.Ascending );
try
{
dgv.CurrentCell = dgv[ 0, currentRowIndex ]; // This throws as there are no items in the grid view
dgv.FirstDisplayedScrollingRowIndex = currentRowIndex;
}
catch
{ // if row was deleted this will set it to first one
// TODO: Implement this by searching for var name in the grid.
// Catching Exceptions makes program slow
dgv.CurrentCell = dgv[ 0, 0 ]; // This throws again for the same reason - it's almost like you predicted that global catch-all would come back and bite you in the ass :)
dgv.FirstDisplayedScrollingRowIndex = 0;
}
}
Anyway I hope this helps. For now I have recompiled myself a working copy so no rush for me.
Great little tool by the way - simple been useful for me while i'm setting up a Java development environment.
Thanks,
Jack