public void OpenFolderMethod(List<string> paths) { LogMessage.Log("Loading Macro Files"); recurse_form = new RecursingSubDirs(); Thread myThread = new Thread(new ThreadStart(this.ShowRecursingForm)); string tempFolderName = String.Empty; MacroFiles.Clear(); BookList.Clear(); DeleteRenameChanges.Clear(); DirectoryInfo temp_di = new DirectoryInfo(Preferences.TemplatesFolderName); bool TemplateFolderOK = true; try { List<string> tempfileList = null; List<string> mcrfileList = null; myThread.Start(); Thread.Sleep(500); tempFolderName = temp_di.FullName; foreach (string x in paths) { String path = x; if (path == String.Empty) continue; DirectoryInfo di = new DirectoryInfo(path); FileInfo fi = new FileInfo(path); if (di.Exists && ((di.Attributes & FileAttributes.Directory) == FileAttributes.Directory)) { List<string> temp = GetFilesNonRecursive(di, "*.*", false); if (mcrfileList == null) { mcrfileList = new List<string>(); mcrfileList.Clear(); } if (temp != null) mcrfileList.AddRange(temp); } else if (fi.Exists && ((fi.Attributes & FileAttributes.Directory) != FileAttributes.Directory)) { if (IsMacroFile(fi)) { try { if (!recurse_form.Disposing) recurse_form.Invoke(new UpdateUIHandler(recurse_form.UpdateUI), new object[] { "Examining File :\r\n'" + Utilities.EllipsifyPath(fi.FullName, 35) + "'" }); } catch { // (System.ObjectDisposedException) && (System.InvalidOperationException) } if (mcrfileList == null) { mcrfileList = new List<string>(); mcrfileList.Clear(); } mcrfileList.Add(fi.FullName); } } if ((temp_di.Exists) && (!path.Contains(temp_di.FullName)) && (!temp_di.FullName.Contains(path))) // Templates path isn't contained in main path. { //foreach (string s in tempfileList) // Log("tempfileList item: " + s); } else if (!temp_di.Exists) { } else { if (TemplateFolderOK) { TemplateFolderOK = false; LogMessage.Log("..Templates folder exists as part of the Selected directory, ignoring"); } } } if (!temp_di.Exists) { LogMessage.Log(".." + temp_di.FullName + " doesn't exist at all and doesn't conflict with existing selected paths (creating empty node)"); } if ((mcrfileList != null) && (mcrfileList.Count > 0)) { LogMessage.Log("..Generating List of Selected Directories Macro Files"); foreach (String mcr in mcrfileList) //for (int i = 0; i < mcrfileList.Count; i++) { //if (File.Exists(mcrfileList[i]) && IsMacroFile(mcrfileList[i])) //{ // MacroFiles.Add(new CMacroFile(mcrfileList[i], this.ATPhraseLoader)); //} MacroFiles.Add(new CMacroFile(mcr, this.ATPhraseLoader)); } } if (TemplateFolderOK) { // Only one templates folder, all templates should be a sub-folder of that one // This way, I don't have to do what I did above (mcrfileList.AddRange()) LogMessage.Log("..Templates folder name: '" + temp_di.FullName + "'"); tempfileList = GetFilesNonRecursive(temp_di, "*.*", true); } if ((tempfileList != null) && (tempfileList.Count > 0)) { LogMessage.Log("..Generating List of Template Directories Macro Files"); foreach(String tempfn in tempfileList) //for (int i = 0; i < tempfileList.Count; i++) { // LOAD TEMPLATES HERE if (File.Exists(tempfn) && IsMacroFile(tempfn)) { MacroFiles.Add(new CMacroFile(tempfn, this.ATPhraseLoader)); } //MacroFiles.Add(new CMacroFile(tempfn, this.ATPhraseLoader)); } } LogMessage.Log("..Building TreeView Nodes from file lists"); BuildTree(paths, tempFolderName); LogMessage.Log("..Building TreeView Nodes completed"); } catch (OutOfMemoryException e) { LogMessage.Log("Out of Memory Exception: " + e.Message); this.Close(); } try { recurse_form.Invoke(new RecurseCloseHandler(recurse_form.Close)); } catch { // (System.ObjectDisposedException) && (System.InvalidOperationException) } recurse_form = null; FillForm((CMacro)null); }
private bool AddLocations(String[] location) { String lowerloc = String.Empty; this.treeView.BeginUpdate(); if (recurse_form != null) { LogMessage.Log("Recursing Subdirectory form is still assigned to, Invoking Close, reassigning"); try { recurse_form.Invoke(new RecurseCloseHandler(recurse_form.Close)); } catch (Exception ex) { LogMessage.Log("Invoke failed: {0}", ex.Message); //return false;// (System.ObjectDisposedException) && (System.InvalidOperationException) TRY TO CONTINUE } } recurse_form = new RecursingSubDirs(); foreach (String data in location) { if (File.Exists(data)) { // easy peezy if (AddFileToTreeNode(data)) LogMessage.Log("AddLocation: Added file to treeView"); else LogMessage.Log("AddLocation: Location exists '{0}', skipping.", data); } else if (Directory.Exists(data)) { } } this.treeView.EndUpdate(); return true; }