Skip to content
Permalink
Browse files

- added error handler for TreeViewOfd exceptions

  • Loading branch information...
cozy1 committed Apr 2, 2019
1 parent ec9ae02 commit e99dc5a5bafbc425ad286ac5a9143b37dbea593d
@@ -2494,7 +2494,7 @@ private void btnArrangementQuick_Click(object sender, EventArgs e)
ofd.Title = "Multiselect XML Arrangements and Arrange Order ...";
ofd.Filter = "Rocksmith Arrangement XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
ofd.Multiselect = true;

if (ofd.ShowDialog() != DialogResult.OK)
return;

@@ -2885,6 +2885,6 @@ private void ResetPackageCreatorForm(GameVersion oldGameVersion)
}



}
}
@@ -29,5 +29,5 @@
//
// THESE VALUES ARE PROGRAMMATICALLY GENERATED - DO NOT EDIT
[assembly: AssemblyVersion("2.9.2.0")]
[assembly: AssemblyInformationalVersion("378802d2")]
[assembly: AssemblyInformationalVersion("ec9ae02a")]
[assembly: AssemblyConfiguration("")]
@@ -1,5 +1,6 @@
Rocksmith Toolkit Release Notes

- added error handler for TreeViewOfd exceptions
- added additional flexibility to Quick Add feature
- only show the display setting warning on first run if applicable
- improved App.config file compatibility
@@ -672,6 +672,50 @@ public static string GetStringInBetween(this string strSource, string strBegin,
return result;
}

/// <summary>
/// Splits a text string so that it wraps to specified line length
/// </summary>
/// <param name="inputText"></param>
/// <param name="lineLength"></param>
/// <param name="splitOnSpace"></param>
/// <returns></returns>
public static string SplitString(string inputText, int lineLength, bool splitOnSpace = true)
{
var finalString = String.Empty;

if (splitOnSpace)
{
var delimiters = new[] { " " }; // , "\\" };
var stringSplit = inputText.Split(delimiters, StringSplitOptions.None);
var charCounter = 0;

for (int i = 0; i < stringSplit.Length; i++)
{
finalString += stringSplit[i] + " ";
charCounter += stringSplit[i].Length;

if (charCounter > lineLength)
{
finalString += Environment.NewLine;
charCounter = 0;
}
}
}
else
{
for (int i = 0; i < inputText.Length; i += lineLength)
{
if (i + lineLength > inputText.Length)
lineLength = inputText.Length - i;

finalString += inputText.Substring(i, lineLength) + Environment.NewLine;
}
finalString = finalString.TrimEnd(Environment.NewLine.ToCharArray());
}

return finalString;
}

#endregion
}
}
@@ -158,13 +158,14 @@ public TreeViewBrowser()
/// <summary>
/// Initialize a new browser TreeView
/// </summary>
public void InitTreeViewBrowser()
public string InitTreeViewBrowser()
{
var errMsg = String.Empty;
if (IsDesignerHosted)
return;
return errMsg;

if (DefaultFolders == null || DefaultFolders.Count == 0)
return;
return errMsg;

ImageList = new ImageList();
ImageList.ImageSize = new Size(16, 16);
@@ -177,11 +178,15 @@ public void InitTreeViewBrowser()
ToggleEventHandlers(true);
m_coll = new ArrayList(); // start with fresh ArrayList
InitDefaultFolders();
// de-activate EH's
// de-activate EH's
ToggleEventHandlers(false);
RestoreTreeView(new List<string>() { InitialDirectory });

RestoreTreeView(new List<string>() { InitialDirectory }, "\\", out errMsg);

// re- activate EH's
ToggleEventHandlers(true); // this trashes the InitialDirectory Restore

return errMsg;
}

private void ToggleEventHandlers(bool enable)
@@ -660,16 +665,18 @@ public void RestoreTreeViewState(List<string> expandedState)
}
}

public void RestoreTreeView(List<string> paths, string separator = @"\")
string errMsg;
public void RestoreTreeView(List<string> paths, string separator, out string errMsg)
{
errMsg = String.Empty;
if (paths == null || paths.Count == 0)
return;

foreach (var path in paths.Where(x => !string.IsNullOrEmpty(x.Trim())))
{
BeginUpdate(); // prevent TreeView flickering and scrolling

var pathParts = path.Split(new[] { separator }, StringSplitOptions.None);
var pathParts = path.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries);
var rootPath = Path.GetPathRoot(path);
var rootNode = Nodes.Cast<TreeNode>().FirstOrDefault(n => n.Text == rootPath);
if (rootNode != null)
@@ -679,11 +686,8 @@ public void RestoreTreeView(List<string> paths, string separator = @"\")
}
else
{
// accomodate user custom installations and Environmental Variables
// reset InitialDirectory instead of throwing exception
InitialDirectory = String.Empty;
Debug.WriteLine("<Reset InitialDirecotry> Did not find the rootNode text: " + rootPath);
// throw new DirectoryNotFoundException("Did not find the rootNode text: " + rootPath);
Debug.WriteLine("<WARNING> Did not find the rootNode text: " + rootPath);
errMsg = "Did not find the rootNode text: " + rootPath;
}

var childNode = rootNode;
@@ -699,20 +703,16 @@ public void RestoreTreeView(List<string> paths, string separator = @"\")
}
else
{
// reset InitialDirectory instead of throwing exception
InitialDirectory = String.Empty;
Debug.WriteLine("<Reset InitialDirecotry> Did not find node text: " + pathParts[i]);
// throw new DirectoryNotFoundException("Did not find node text: " + pathParts[i]);
Debug.WriteLine("<WARNING> Did not find node text: " + pathParts[i]);
errMsg = "Did not find node text: " + pathParts[i];
}
}

var restoreNode = FindNodeByTagRecursive(rootNode, childNode.Tag);
if (restoreNode == null)
{
// reset InitialDirectory instead of throwing exception
InitialDirectory = String.Empty;
Debug.WriteLine("<Reset InitialDirecotry> Could not restoreNode for: " + path);
// throw new DirectoryNotFoundException("Could not restoreNode for: " + path);
Debug.WriteLine("<WARNING> Could not restoreNode for: " + path);
errMsg = "Could not restoreNode for: " + path;
}

EndUpdate(); // enable TreeView redrawing and scrolling
@@ -281,7 +281,18 @@ private void TreeViewOfd_Load(object sender, EventArgs e)
{
PopulateComboFilesOfType();
// call InitBrowserTreeview ONLY after the form is fully loaded
treeViewBrowser.InitTreeViewBrowser();
var errMsg = treeViewBrowser.InitTreeViewBrowser();

if (!String.IsNullOrEmpty(errMsg))
{
var diaMsg = "Your OS Customizations have prevented the" + Environment.NewLine +
"TreeViewOfd feature from functioning normally ..." + Environment.NewLine + Environment.NewLine +
StringExtensions.SplitString(errMsg, 48, true);

BetterDialog2.ShowDialog(diaMsg, "TreeViewOfd Failed ...", null, null, "OK", Bitmap.FromHicon(SystemIcons.Warning.Handle), "Warning", 150, 150);
this.DialogResult = DialogResult.Abort;
this.Close();
}
}

private void cmbFilesOfType_SelectedIndexChanged(object sender, EventArgs e)
@@ -27,5 +27,5 @@
//
// THESE VALUES ARE PROGRAMMATICALLY GENERATED - DO NOT EDIT
[assembly: AssemblyVersion("2.9.2.0")]
[assembly: AssemblyInformationalVersion("378802d2")]
[assembly: AssemblyInformationalVersion("ec9ae02a")]
[assembly: AssemblyConfiguration("")]
@@ -29,5 +29,5 @@
//
// THESE VALUES ARE PROGRAMMATICALLY GENERATED - DO NOT EDIT
[assembly: AssemblyVersion("2.9.2.0")]
[assembly: AssemblyInformationalVersion("378802d2")]
[assembly: AssemblyInformationalVersion("ec9ae02a")]
[assembly: AssemblyConfiguration("")]
@@ -1,3 +1,3 @@
2.9.2.0
378802d2
ec9ae02a

0 comments on commit e99dc5a

Please sign in to comment.
You can’t perform that action at this time.