Advertisement
GlobalAccessSoftware

Dealing with ListBoxes and Collections, etc.

May 17th, 2017
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 103.43 KB | None | 0 0
  1.  
  2. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  3. // OptionsMiscAlternate.cs//\\//\\//\\//\\//\\//
  4. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  5. // Global  Access  Software  InTernational//\\//
  6. // Copyrighted (c)2013 by John P. Edwards/\\//\\
  7. // *** Sunday, July 21, 2013 8:01:09 AM/\\//\\//
  8. // M Saturday, July 27, 2013 10:45:09 PM//\\//\\
  9. // ReSharper7 Approved by -JpE- v1.4.1.2x\//\\//
  10. // Friday, August 09, 2013 11:19:04 PM\\//\\//\\
  11. // Friday,   July 25, 2014 08:25 PM/\\//\\//\\//
  12. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  13. // Split out from OptionsMisc.cs\\//\\//\\//\\//
  14. // v4.6.7.76 Jan 28 2017 Isolated to here!\\//\\
  15. // This Source File is like 150 Lines atm.//\\//
  16. // Including the Comments and Design Ideas\\//\\
  17. // and everything else roughed except that//\\//
  18. // The HelpButtonClick is pretty finished \\//\\
  19. // codewise. Just need to complete that file\\//
  20. // v4.6.7.78 Jan 30 2017 in Design Phase. \\//\\
  21. // v4.6.7.87 Feb 09 2017 Early Alpha 1st phase./
  22. // v4.6.7.95 Feb 11 2017 Alpha-Beta Stages. //\\
  23. // I am working on the ListBox Hovers or trying/
  24. // v4.6.7.98 Feb 11 2017 Everything works 4 AFF\
  25. // But it's not yet hooked up to anything in IF/
  26. // v4.6.8.23 Feb 27 2017 Touching Up Final. //\\
  27. // v4.6.8.43 Mar 15 2017 Reworked MoveExisting./
  28. // v4.6.9.63 Mar 26 Added "Select File" to\\//\\
  29. // Context Menu Items along with supporting/\\//
  30. // Methods. Tests Very Well Indeed.\//\\//\\//\\
  31. // v4.6.9.64 Added Context Menu Item that\//\\//
  32. // Lets the User Select a New Reports Folder//\\
  33. // For this Data Folder. Mar 26 2017\\//\\//\\//
  34. // v4.6.9.76 Mar 30 2017//\\//\\//\\//\\//\\//\\
  35. // v4.6.9.77 Mar 30 Upgraded to ObjectModel!\\//
  36. // Context Menu for Data Folders improved with\\
  37. // v4.6.9.82 Mar 31 2017 File Print Options.\\//
  38. // v4.6.9.87 Apr 04 2017 UpGraded Context Menus!
  39. // v4.7.0.04 Apr 12 2017 More On The End there!
  40. // v4.7.0.07 Apr 14 2017 Finishing ^ & DoW-Mods.
  41. // v4.7.1.24 Apr 20 Integration & Consolidation.
  42. // v4.7.1.31 Apr 22 Added List Restore Contexts.
  43. // v4.7.1.35 Apr 24 and perfected them & all.
  44. // v4.7.2.53 May 05 Restore methods almost done.
  45. // v4.7.2.61 May 09 Backup methods nearly done.
  46. // v4.7.3.65 May 11 Nearly Clear, Final Testing.
  47. // v4.7.3.77 May 17 ViewAllPrefs & ViewAllAss.
  48. // Revamped Overloads and such for DisplayResults
  49. // & DisplayResults() to work with ViewALL-Mods.
  50. // v4.7.3.78 Added the lil Quick-Launch Feature!
  51. // Resources straightened out and a new Icon for
  52. // the QS & fixed & organized right all around.
  53. // v4.7.3.85 Adds AYS to MinVerb YesNo's, etc.
  54. // Perfecting MoveUp-Data & Testing all more.
  55. // v4.7.3.93 May 30 2017 Better Default Mods
  56. // for the Selector index mods.
  57. // v4.7.3.96 May 31 2017 Fixed ViewAllAss!
  58. // v4.7.5.19 12Jun17 Caps a lot of mods here
  59. // including the Backup/Restore for Both Lists
  60. // and all the called methods therefor. i.e.
  61. // The Big 4 and Supporting Methods Regions.
  62. // and mostly in AppCode4 for the RecNum stuff.
  63. // OMA now @ 2776 Lines! BackupListsAuto added.
  64. // BLA is called from AppCode2.Restore4() now
  65. // as part of the Scheduled Maintenance now.
  66. // v4.7.5.20 12Jun Integration & Wipe Testings.
  67. // v4.7.5.25 14Jun Split the Big 4 n2 the Big 2!
  68. // with a few specific methods & reUses mostly.
  69. // v4.7.5.28 Final Details of Formatting Code
  70. // Files and make as readable as possible.
  71. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  72.  
  73. // "NameSpaces" Included.
  74. using System;
  75. using System.IO;
  76. using System.Linq;
  77. using System.Drawing;
  78. using System.Collections;
  79. using System.Windows.Forms;
  80. using System.Collections.Generic;
  81. using System.Collections.ObjectModel;
  82. using System.Collections.Specialized;
  83.  
  84. // Code File "Aliases" to shorten.
  85. using IF  = WhoAreYou.InfoForm;
  86. using AST = WhoAreYou.AppStatic;
  87. using APS = WhoAreYou.Properties.AppSettings;
  88. using OPS = WhoAreYou.Properties.OptionsSettings;
  89. using AUS = WhoAreYou.Properties.AppUserSettings;
  90. using ORS = WhoAreYou.Properties.OptionsResources;
  91. using PMS = WhoAreYou.Properties.PrintMasterSettings;
  92.  
  93. namespace WhoAreYou
  94. {
  95.   public partial class OptionsForm // <-= NOTE!
  96.   {
  97. #region Alternate Folder Finder
  98.  
  99.     /* Design Ideas and other imagineering:
  100.      * ************************************
  101.      * Okay, so like this Region and Methods herein are all about the
  102.      * AlternateFolderFinder or AFF. The ListBoxs will Allow a Collection
  103.      * of Paths to be Stored. So I need to "hook" it into the
  104.      * Data and Reports TextBoxes without altering anything there,
  105.      * but to Collect those paths, anytime there is a new one.
  106.      *
  107.      * So then, I'll need to compare those to Entries and so on.
  108.      * And I'll need Settings to store the Collections and retrieve them, etc.
  109.      *
  110.      * Then, when there is a Collection of at least the Current few we can know that
  111.      * the paths are valid or they  wouldn't be in the Data or ReportsTextBox.Text!
  112.      *
  113.      * Initial Values are the good old AppDir+"\\" + Home and...
  114.      * AppDir + "\\" + Home + "\\" + Reports
  115.      * that the App defaults-to on startup and so forth. (AppCode4.cs)
  116.      *
  117.      * Then DataSelect Button Click or Double Mouse Click on the Selected Index
  118.      * will simply put that Entry into the Data or ReportsTextBox.text, etc.
  119.      *
  120.      * Also, maybe, if the Open Button is Clicked when a Listbox Item is
  121.      * highlighted, it opens that folder. ***See Context Menu Items***
  122.      *
  123.      * Then I guess Clicking the Select Button will basically put the Selected
  124.      * index item into the DataTextBox.Text (or Reports L8r) and do the same
  125.      * basic things as happen after the folderBrowser Dialog; PopulateListBoxes, etc.
  126.      * SelectedPath returns to top of list, right below default.
  127.      *
  128.      * -JpE- (I totally love this phase when there's so much potential
  129.      *  and ideas are flowing freely and merging into real concepts and code.)
  130.      *  Feb 01-15 2017
  131.      *  Apr 04    2017 and nearly 1,000 lines of code later. IT'S FUCKING WONDERFUL!
  132.      *  Much more than I'd originally envisioned, with the new Context Menu Item
  133.      *  UpDates, at the Bottom, and so forth that all tie into everything nicely.
  134.      *  Great Job on Creating, Designing, Writing, Testing and Upgrading Integrations.
  135.      */
  136.  
  137.  
  138. #region Collection Methods
  139.  
  140.     /// <summary> Add initial default paths to BOTH Collections.
  141.     /// Called Once for Data Path, once for Reports Path.
  142.     /// called from OptionsFormLoad(); each instance if count
  143.     /// is less than 2.
  144.     /// </summary>
  145.     /// <param name="dataPath"></param>
  146.     private void AddDefaultsToPathCollectionsLocal(bool dataPath)
  147.     {
  148.       AddDefaultsToPathCollections(dataPath);
  149.       PopulateListBoxes();
  150.     }
  151.  
  152.     /// <summary> Add initial default paths to BOTH Collections.
  153.     /// True for Data Path, False for Reports Path.
  154.     /// as of v4.7.1.24 Apr 20 2017, ReUsed by AppCode5 Class.
  155.     /// </summary>
  156.     /// <param name="dataPath"></param>
  157.     public static void AddDefaultsToPathCollections(bool dataPath)
  158.     {
  159.       // adds defaults to initial collections...
  160.       string path;
  161.       // true if DataCollection, false if ReportsCollection.
  162.       if (dataPath.Equals(true))
  163.       {
  164.         path =
  165.           AUS.Default.AppDir +
  166.           "\\" + APS.Default.Home;
  167.         OPS.Default.dataListBoxItems.Add(path);
  168.       }
  169.       else
  170.       {
  171.         path =
  172.           AUS.Default.AppDir +
  173.           "\\" + APS.Default.Home +
  174.           "\\" + PMS.Default.Reports;
  175.         OPS.Default.reportsListBoxItems.Add(path);
  176.       }
  177.       OPS.Default.Save();
  178.       // doesn't have to be created, just added to as a Setting.
  179.     }
  180.  
  181.     private void AddToPathCollection(string path, bool which)
  182.     {
  183.       AddToPathCollectionPublic(path, which);
  184.       PopulateListBoxes(); // NOTE! Only difference locally.
  185.     }
  186.     /// <summary> Grabs the current path to see...
  187.     /// if it's in the collection and adds it to the
  188.     /// pertinent collection when it isn't already there.
  189.     ///  sender == true is DataList, sender == false is ReportsList.
  190.     /// </summary><param name="path"></param>
  191.     /// <param name="which"></param>
  192.     public static void AddToPathCollectionPublic(string path, bool which)
  193.     {
  194.       if (which.Equals(true))
  195.       {
  196.         if (CheckForItem(path, true).Equals(false))
  197.         {
  198.           // check if collection is full then delete least used if it is...
  199.           SizeCollection(true);
  200.           if (OPS.Default.dataListBoxItems.Count > 1)
  201.           {
  202.             OPS.Default.dataListBoxItems.Insert(1, path);
  203.           }
  204.           else OPS.Default.dataListBoxItems.Add(path);
  205.         }
  206.         else // otherwise it already exists and we...
  207.         {
  208.           MoveExistingItemTo2NdInList(path, true);
  209.         }
  210.       }
  211.       else // If path ^v is NOT already in collection, add it.
  212.       {
  213.         if (CheckForItem(path, false).Equals(false))
  214.         {
  215.           SizeCollection(false);
  216.           if (OPS.Default.reportsListBoxItems.Count > 1)
  217.           {
  218.             OPS.Default.reportsListBoxItems.Insert(1, path);
  219.           }
  220.           else OPS.Default.reportsListBoxItems.Add(path);
  221.         }
  222.         else // otherwise it already exists and we...
  223.         {
  224.           MoveExistingItemTo2NdInList(path, false);
  225.         }
  226.       }
  227.       OPS.Default.Save();
  228.     }
  229.  
  230.     /// <summary> Item is already in the collection,
  231.     /// move it to 2nd Unless already 1st or 2nd(default);
  232.     /// (i.e. Index 0 or 1 in the List.) -ed
  233.     /// Leaves 0 and 1 alone, no changes needed.
  234.     /// true to access dataListBoxItems,
  235.     /// false to access reportsListBoxItems. -JpE-
  236.     /// </summary>
  237.     /// <param name="path"></param>
  238.     /// <param name="which"></param>
  239.     private static void MoveExistingItemTo2NdInList(string path, bool which)
  240.     {
  241.       // Find index of Item and move it to Position 1.
  242.       // If which is true it's Data Path, if false it's Reports.
  243.       if (which.Equals(true))
  244.       {
  245.         if (OPS.Default // clone 2 of 3 v4.6.8.43
  246.           .dataListBoxItems.IndexOf(path) < 2) return;
  247.  
  248.         if (OPS.Default.dataListBoxItems.Count > 1)
  249.         {
  250.           OPS.Default.dataListBoxItems.Remove(path);
  251.           OPS.Default.dataListBoxItems.Insert(1, path);
  252.         }
  253.         else OPS.Default.dataListBoxItems.Add(path);
  254.       }
  255.       else // NOTE: Default is always kept at Position Zero.
  256.       {
  257.         if (OPS.Default // clone 3 of 3
  258.           .reportsListBoxItems.IndexOf(path) < 2) return;
  259.  
  260.         if (OPS.Default.reportsListBoxItems.Count > 1)
  261.         {
  262.           OPS.Default.reportsListBoxItems.Remove(path);
  263.           OPS.Default.reportsListBoxItems.Insert(1, path);
  264.         }
  265.         else OPS.Default.reportsListBoxItems.Add(path);
  266.       }
  267.       //OPS.Default.Save();
  268.     }
  269.  
  270.     /// <summary> Removes Items Beyond Default Item Count.
  271.     /// p = true is Data, p = false is Reports.
  272.     ///
  273.     /// v4.7.1.25 Apr 21 2017
  274.     /// Makes Count = 49 thus 50 paths stored. (see AppSettings)
  275.     /// </summary>
  276.     /// <param name="p"></param>
  277.     /// <returns></returns>
  278.     private static void SizeCollection(bool p)
  279.     {
  280.       if (p.Equals(true)) // Data Code Path.
  281.       {
  282.         var count = OPS.Default.dataListBoxItems.Count;
  283.         if (count > APS.Default.Count)
  284.         {
  285.           OPS.Default.dataListBoxItems.RemoveAt(count - 1);
  286.         } // Remove Last Path in List if Collection is "full."
  287.       }
  288.       else               // Reports Code Path.
  289.       {
  290.         var count = OPS.Default.reportsListBoxItems.Count;
  291.         if (count > APS.Default.Count) // testswell! // > 4
  292.         {
  293.           OPS.Default.reportsListBoxItems.RemoveAt(count - 1);
  294.         }
  295.       }
  296.     }
  297.  
  298.     /// <summary> return false if path is NOT already in collection.
  299.     /// If path "is" already in collection forget it, return true.
  300.     /// </summary>
  301.     /// <param name="path"></param>
  302.     /// <param name="which"></param>
  303.     /// <returns></returns>
  304.     private static bool CheckForItem(string path, bool which)
  305.     {
  306.       // if check is false, it is not in the collection.
  307.       if (which.Equals(true)) // it's a Data Path.
  308.       {
  309.         if (OPS.Default.dataListBoxItems.Contains(path)) return true;
  310.       }
  311.       else                   // it's a Reports Path.
  312.         if (OPS.Default.reportsListBoxItems.Contains(path)) return true;
  313.  
  314.       return false;
  315.     }
  316. #endregion Collection Methods
  317.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  318.  
  319.  
  320. #region Action Methods
  321.  
  322.     private void PopulateListBoxes()
  323.     {
  324.       OPS.Default.Save();
  325.       // Initialize and Populate both ListBoxes with appropriate collections.
  326.       var hasno = false;
  327.       var invalid = new Collection<string>();
  328.       dataListBox.Items.Clear();
  329.       reportsListBox.Items.Clear();
  330.  
  331.       if (OPS.Default.dataListBoxItems.Count < 1)
  332.         AddDefaultsToPathCollectionsLocal(true);
  333.  
  334.       if (OPS.Default.reportsListBoxItems.Count < 1)
  335.         AddDefaultsToPathCollectionsLocal(false);
  336.  
  337.       IF.CheckBothFolderCollections(); // <-= v4.7.1.33
  338.  
  339.       foreach (var item in OPS.Default.dataListBoxItems)
  340.       {
  341.         if (!ValidateItem(item, true))
  342.         {
  343.           hasno = true;
  344.           invalid.Add(item);
  345.           continue;
  346.         }
  347.         dataListBox.Items.Add(item);
  348.       }
  349.       dataListBox.SelectedIndex = OPS.Default.dataListBoxItems // v4.7.0.03
  350.         .IndexOf(OPS.Default.dataListBoxItems.Contains(PreviouslySelectedDir1)
  351.         ? PreviouslySelectedDir1 : OPS.Default.PrefRootDir);
  352.       if (hasno) RemoveInvalidFolders(true, invalid);
  353.       hasno = false;
  354.       invalid.Clear();
  355.  
  356.       // And do similarly for reportsListBox.Items.
  357.       if (OPS.Default.reportsListBoxItems.Count < 1)
  358.       {
  359.         OPS.Default.reportsListBoxItems
  360.           .Add(ReportsTextBox.Text);
  361.         OPS.Default.Save();
  362.       }
  363.       foreach (var item in OPS.Default.reportsListBoxItems)
  364.       {
  365.         if (!ValidateItem(item, false))
  366.         {
  367.           hasno = true;
  368.           invalid.Add(item);
  369.           continue;
  370.         }
  371.         reportsListBox.Items.Add(item);
  372.       }
  373.  
  374.       reportsListBox.SelectedIndex = OPS.Default.reportsListBoxItems // v4.7.0.03
  375.         .IndexOf(OPS.Default.reportsListBoxItems.Contains(PreviouslySelectedDir2)
  376.         ? PreviouslySelectedDir2 : OPS.Default.PrefReportsDir);
  377.       if (hasno) RemoveInvalidFolders(false, invalid);
  378.     }
  379.  
  380.     /// <summary> Select Previously Selected Index Mods; Set Previous.
  381.     /// v4.7.0.03 v  PSD1&2C vars Used Above ONLY. Set to Prefs on FormLoad.
  382.     /// These EVENT Handlers are called on changes and these vars only change herein.
  383.     /// </summary>
  384.     /// <param name="sender"></param>
  385.     /// <param name="e"></param>
  386.     private void SelectedIndex1Change(object sender, EventArgs e)
  387.     {
  388.       PreviouslySelectedDir1 =
  389.         dataListBox.SelectedItem.ToString();
  390.     }
  391.  
  392.     private void SelectedIndex2Change(object sender, EventArgs e)
  393.     {
  394.       PreviouslySelectedDir2 =
  395.         reportsListBox.SelectedItem.ToString();
  396.     }
  397.  
  398.     private void RemoveInvalidFolders
  399.       (bool data, ICollection<string> list)
  400.     {
  401.       if (list.Count < 1) return;
  402.       var default1 = OPS.Default.dataListBoxItems[0];
  403.       var default2 = OPS.Default.reportsListBoxItems[0];
  404.  
  405.       if (data)
  406.       {
  407.         if (list.Contains(default1)) list.Remove(default1);
  408.         foreach (var item in list)
  409.           OPS.Default.dataListBoxItems.Remove(item);
  410.       }
  411.       else
  412.       {
  413.         if (list.Contains(default2)) list.Remove(default2);
  414.         foreach (var item in list)
  415.           OPS.Default.reportsListBoxItems.Remove(item);
  416.       }
  417.       PopulateListBoxes();
  418.     }
  419.  
  420.     /// <summary> Verify Folder Exists and
  421.     /// in the case of DataFolder, that data files exist.
  422.     /// </summary>
  423.     /// <param name="item"></param>
  424.     /// <param name="path"></param>
  425.     /// <returns></returns>
  426.     private static bool ValidateItem(string item, bool path)
  427.     {
  428.       var test = false;
  429.       if (path.Equals(true)) // Data Folder.
  430.       {
  431.         if (Directory.Exists(item)
  432.           && HasDataFiles(item)) test = true;
  433.       }
  434.       else // Reports Folder.
  435.       {
  436.         if (Directory.Exists(item)) test = true;
  437.       }
  438.       return test;
  439.     }
  440.  
  441.     /// <summary> Make Sure Data Folder has data files.
  442.     /// Rev v4.7.1.24 April 20 2017 and made public.
  443.     /// </summary>
  444.     /// <param name="folder"></param>
  445.     /// <returns></returns>
  446.     public static bool HasDataFiles(string folder)
  447.     {
  448.       return
  449.         (from file in Directory.EnumerateFiles(folder)
  450.          let extension = Path.GetExtension(file)
  451.          where !string.IsNullOrEmpty(extension)
  452.            && !string.IsNullOrEmpty(file)
  453.          where extension.Equals(APS.Default.Ext)
  454.            && !file.Contains("Bac_")
  455.            && !file.Contains(APS.Default._drf)
  456.            && !file.Equals(APS.Default.NewFile)
  457.          select extension).Any();
  458.     }
  459.  
  460.     private void DataSelectButtonClick(object sender, EventArgs e)
  461.     {
  462.       var path = dataListBox.Text;
  463.       // NOTE: Every time a Path is reSelected, it needs be put back on top.
  464.       var test = OPS.Default.dataListBoxItems.IndexOf(path);
  465.       if (test > 1) // if default path or 2nd leave it alone.
  466.       {
  467.         MoveExistingItemTo2NdInList(path, true);
  468.       }
  469.       // Now put that path into the dataTextBox.Text and Save Changes.
  470.       folderBrowser.SelectedPath = path;
  471.       DataChanges();
  472.     }
  473.  
  474.     private void ReportsSelectButtonClick
  475.       (object sender, EventArgs e)
  476.     {
  477.       var path = reportsListBox.Text;
  478.       var test = OPS.Default.reportsListBoxItems.IndexOf(path);
  479.       if (test > 1) MoveExistingItemTo2NdInList(path, false);
  480.       folderBrowser.SelectedPath = path;
  481.       ReportsChanges();
  482.     }
  483. #endregion Action Methods
  484.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  485.  
  486.  
  487. #region Context Menu Items
  488.  
  489.     /* DOC:
  490.      *  \\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  491.      * The Context Menu 1 items and true args are DataFolder
  492.      * Specific and the Context Menu 2 items and false args
  493.      * are Reports Folder Specific throughout.
  494.      *
  495.      * NOTE: Numerous Updates were done after the initial code.
  496.      * See notes and Docs for each Below.
  497.      *  \\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  498.      */
  499.  
  500.  
  501. #region Original Context Menu Items
  502.  
  503.     private void ViewToolStrip1MenuItemClick(object sender, EventArgs e)
  504.     {
  505.       MessageBox.Show(dataListBox.SelectedItem.ToString());
  506.     }
  507.  
  508.     private void OpenToolStrip1MenuItemClick(object sender, EventArgs e)
  509.     {
  510.       if (!OPS.Default.MiniVerb && !OPS.Default.AreYouSure)
  511.         if (!AST.YesNoDialog("Open This Folder?")) return;
  512.       var folder = dataListBox.SelectedItem.ToString();
  513.       AST.OpenFolder(folder);
  514.     }
  515.  
  516.     private void RemoveToolStrip1MenuItemClick(object sender, EventArgs e)
  517.     {
  518.       var item = dataListBox.SelectedIndex;
  519.       if (item.Equals(0))
  520.       {
  521.         MessageBox.Show(ORS.OF_Remove);
  522.         return;
  523.       }
  524.       if (item.Equals(1))
  525.       {
  526.         MessageBox.Show(ORS.OF_Reselect);
  527.         return;
  528.       }
  529.       if (!OPS.Default.MiniVerb)// && !OPS.Default.AreYouSure)
  530.         if (!AST.YesNoDialog(string.Format(
  531.           "Remove this Folder from the List?\n{0}",
  532.             dataListBox.Items[item]))) return;
  533.  
  534.       OPS.Default.dataListBoxItems.RemoveAt(item);
  535.       PopulateListBoxes();
  536.     }
  537.  
  538.     private void ClearToolStrip1MenuItemClick(object sender, EventArgs e)
  539.     {
  540.       var test = OPS.Default.dataListBoxItems.Count;
  541.       if (test < 2) return; // Keep The Default.
  542.       if (!OPS.Default.MiniVerb)// && !OPS.Default.AreYouSure)
  543.         if (!AST.YesNoDialog("Clear This Entire List?")) return;
  544.  
  545.       OPS.Default.dataListBoxItems.Clear();
  546.       AddDefaultsToPathCollectionsLocal(true);
  547.       DataTextBox.Text =
  548.         OPS.Default.dataListBoxItems[0];
  549.     }
  550.  
  551.     private void OpenToolStrip2MenuItemClick(object sender, EventArgs e)
  552.     {
  553.       if (OPS.Default.reportsListBoxItems.Count < 2) return;
  554.       if (!OPS.Default.MiniVerb && !OPS.Default.AreYouSure)
  555.         if (!AST.YesNoDialog("Open This Folder?")) return;
  556.       var folder = reportsListBox.SelectedItem.ToString();
  557.       AST.OpenFolder(folder);
  558.     }
  559.  
  560.     private void RemoveToolStrip2MenuItemClick(object sender, EventArgs e)
  561.     {
  562.       var item = reportsListBox.SelectedIndex;
  563.       if (item.Equals(0))
  564.       {
  565.         MessageBox.Show(ORS.OF_Remove);
  566.         return;
  567.       }
  568.       if (item.Equals(1))
  569.       {
  570.         MessageBox.Show(ORS.OF_Reselect);
  571.         return;
  572.       }
  573.       if (!OPS.Default.MiniVerb)
  574.         if (!AST.YesNoDialog(string.Format(
  575.           "Remove this Folder from the List?\n{0}",
  576.             reportsListBox.Items[item]))) return;
  577.  
  578.       OPS.Default.reportsListBoxItems.RemoveAt(item);
  579.       PopulateListBoxes();
  580.     }
  581.  
  582.     private void ClearToolStrip2MenuItemClick(object sender, EventArgs e)
  583.     {
  584.       if (OPS.Default.reportsListBoxItems.Count < 2) return;
  585.       // ^ Keep The Default.
  586.       if (!OPS.Default.MiniVerb) //&& !OPS.Default.AreYouSure
  587.         if (!AST.YesNoDialog("Clear This Entire List?")) return;
  588.       OPS.Default.reportsListBoxItems.Clear();
  589.       AddDefaultsToPathCollectionsLocal(false);
  590.       ReportsTextBox.Text = OPS.Default.reportsListBoxItems[0];
  591.     }
  592.  
  593.     private void ViewToolStripMenuItem2Click(object sender, EventArgs e)
  594.     {
  595.       MessageBox.Show(reportsListBox.SelectedItem.ToString());
  596.     }
  597. #endregion Original Context Menu Items
  598.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  599.  
  600.  
  601. #region v4.6.9.67 Mar 27 2017
  602.  
  603.     private void SelectFileToolStrip1MenuItemClick
  604.       (object sender, EventArgs e)
  605.     {
  606.       if (!OPS.Default.MiniVerb && !OPS.Default.AreYouSure)
  607.         if (!AST.YesNoDialog(
  608.           "Select a Data File for this Folder?")) return;
  609.  
  610.       // Now do it!
  611.       var dir = dataListBox.SelectedItem.ToString();
  612.       if (!Directory.Exists(dir) || !HasDataFiles(dir))
  613.       { PopulateListBoxes(); return; }
  614.  
  615.       var files = GetDataFileList(dir);
  616.       // v4.7.3.93 May 30 2017 vvvvvvv
  617.       var index = 0;
  618.       var test = GetPrefFileName(dir);
  619.       if (files.Contains(test))
  620.         index = files.IndexOf(test);
  621.       else
  622.         if (files.Contains(OPS.Default.PrefFileName))
  623.           index = files.IndexOf(OPS.Default.PrefFileName);
  624.         else
  625.           if (files.Contains(AUS.Default.FileName))
  626.             index = files.IndexOf(AUS.Default.FileName);
  627.           else
  628.             if (files.Contains(PMS.Default.Bac_PrefFileName))
  629.               index = files.IndexOf(PMS.Default.Bac_PrefFileName);
  630.             else
  631.               if (files.Contains(APS.Default.defaultFilename))
  632.                 index = files.IndexOf(APS.Default.defaultFilename);
  633.       // Selected index Mods    ^^^^^^^^^
  634.  
  635.       var size = AUS.Default.OMA_FileSelect_Size;
  636.       var location = AUS.Default.OMA_FileSelect_Location;
  637.       var choice = SelectOne(files, ref size, ref location, "", index);
  638.       AUS.Default.OMA_FileSelect_Size = size;
  639.       AUS.Default.OMA_FileSelect_Location = location;
  640.       AUS.Default.Save();
  641.  
  642.       if (string.IsNullOrEmpty(choice)
  643.         || !File.Exists(dir + "\\" + choice)) return;
  644.       if (OPS.Default.dataListBoxItems.IndexOf(dir).Equals(1))
  645.       { OPS.Default.PrefFileName = FileName = choice; }
  646.       RememberThis2(choice, dir);
  647.       if (!OPS.Default.MiniVerb) Feedback();
  648.     }
  649.  
  650.     private static void Feedback()
  651.     {
  652.       const string
  653.         text = "Your Preferences Have Been Saved.";
  654.       MessageBox.Show(text);
  655.     }
  656.  
  657.     /// <summary> Get List of strings of DataFile Names
  658.     /// That Exist on this particular Directory. Linq vers.
  659.     /// </summary>
  660.     /// <returns></returns>
  661.     public static Collection<string> GetDataFileList(string folder)
  662.     {
  663.       #region Was
  664.       //// optimized only after testing and noting original.
  665.       //var list = new List<string>();
  666.       //foreach (var file in Directory.EnumerateFiles(
  667.       //  OPS.Default.PrefRootDir))
  668.       //{
  669.       //  var name = Path.GetFileName(file);
  670.       //  var extension = Path.GetExtension(file);
  671.       //  if ( string.IsNullOrEmpty(extension)
  672.       //    || string.IsNullOrEmpty(name)
  673.       //    || !extension.Equals(APS.Default.Ext)
  674.       //    || name.Contains(APS.Default._drf)
  675.       //    || name.Equals(APS.Default.NewFile)
  676.       //    || name.Contains("Bac_")) continue;
  677.  
  678.       //  list.Add(name);
  679.       //}
  680.       //return list;
  681.       //// Converted to Linq it's...
  682.       #endregion Was
  683.       return
  684.         new Collection<string>((from file in Directory.EnumerateFiles(folder)
  685.           let name = Path.GetFileName(file)
  686.           let extension = Path.GetExtension(file)
  687.           where !string.IsNullOrEmpty(extension)
  688.             && !string.IsNullOrEmpty(name)
  689.             && extension.Equals(APS.Default.Ext)
  690.             && !name.Contains(APS.Default._drf)
  691.             && !name.Equals(APS.Default.NewFile)
  692.             && !name.Contains("Bac_")
  693.           select name).ToList());
  694.     }
  695.  
  696.     // write file to dir indicating pref Filename for this Dir.
  697.     private static void RememberThis2(string filename, string dir)
  698.     {
  699.       var
  700.         contents =
  701.           filename +
  702.             "\n" + GetStoredReportsDirPref(dir) +
  703.               "\nOMA_RememberThis2();";
  704.       var
  705.         file = dir + "\\" + APS.Default.PrefFile;
  706.  
  707.       File.WriteAllText(file, contents);
  708.     }
  709.  
  710.     // Get it & put it right back in with different filename.
  711.     private static string GetStoredReportsDirPref(string dir)
  712.     {
  713.       var pref = OPS.Default.PrefReportsDir;
  714.       var file = dir + "\\" + APS.Default.PrefFile;
  715.  
  716.       if (File.Exists(file))
  717.       {
  718.         var path = File.ReadAllText(file).Split('\n')[1];
  719.         // grabs second line of file only.
  720.         if (!path.Contains("()")
  721.           && !path.Contains(";")
  722.           && Directory.Exists(path)
  723.           ) pref = path;
  724.       }
  725.       return pref;
  726.     }
  727.  
  728.     // v4.6.9.67 Mar 27 2017
  729.     private void SelectReportsFolderToolStrip1MenuItemClick
  730.         (object sender, EventArgs e)
  731.     {
  732.       if (!OPS.Default.MiniVerb && !OPS.Default.AreYouSure)
  733.         if (!AST.YesNoDialog(
  734.           "Select a Reports Folder" +
  735.           " for this Data Folder?")) return;
  736.       var dir = dataListBox.SelectedItem.ToString();
  737.       var list = OPS.Default.reportsListBoxItems;
  738.       var relist = new Collection<string>(); // <-= v4.6.9.77!
  739.       foreach (var path in list) // Convert from Specialized String Collection
  740.       { relist.Add(path); } // to a Generic ObjectModel.Collection<T>
  741.       // SelectorForm Use and Example thereof.
  742.  
  743.       // v4.7.3.95 Index Mods extended to these.
  744.       var index = 0;
  745.       var test  = GetStoredReportsDirPref(dir);
  746.       if (relist.Contains(test))
  747.         index   = relist.IndexOf(test);
  748.       else
  749.         if (relist.Contains(OPS.Default.PrefReportsDir))
  750.           index = relist.IndexOf(OPS.Default.PrefReportsDir);
  751.         else
  752.           if (relist.Contains(PMS.Default.ReportsFolder))
  753.             index = relist.IndexOf(PMS.Default.ReportsFolder);
  754.       // else default to the index[0] default.
  755.       // ^ v4.7.3.93 May 30 2017
  756.  
  757.       const string text = "Select a Reports Folder:";
  758.       var size = AUS.Default.OMA_ReportsSelect_Size;
  759.       var locate = AUS.Default.OMA_ReportsSelect_Location;
  760.       var selected = SelectOne(relist, ref size, ref locate, text, index);
  761.       AUS.Default.OMA_ReportsSelect_Size = size;
  762.       AUS.Default.OMA_ReportsSelect_Location = locate;
  763.       AUS.Default.Save();
  764.       if (string.IsNullOrEmpty(selected)) return;
  765.  
  766.       // v4.6.9.87 Apr 04 2017 - All Four Possibles Tested.
  767.       // If it's the default data dir it moves the pref reports
  768.       // folder to the 2nd-position* or leaves it alone if it's the
  769.       // default or pref reports dir already. (*2nd in the list, index[1].)
  770.       if (dir.Equals(OPS.Default.PrefRootDir))
  771.       {
  772.         if (selected != list[0])
  773.         {
  774.           MoveExistingItemTo2NdInList(selected, false);
  775.           PopulateListBoxes();
  776.         }
  777.         ReportsTextBox.Text =
  778.           PreviouslySelectedDir2 =
  779.             OPS.Default.PrefReportsDir = selected;
  780.       }
  781.       RememberThis3(selected, dir);
  782.       if (!OPS.Default.MiniVerb) Feedback();
  783.     }
  784.  
  785.     // write file to dataDir indicating selected ^
  786.     private void RememberThis3
  787.       (string selectedReportsDir, string dataDir)
  788.     {
  789.       var
  790.         contents = GetPrefFileName(dataDir) +
  791.                    "\n" + selectedReportsDir +
  792.                    "\n" + "OMA_RememberThis3();";
  793.       var
  794.         prefFile = dataDir + "\\" +
  795.                    APS.Default.PrefFile;
  796.  
  797.       File.WriteAllText(prefFile, contents);
  798.     }
  799.  
  800.     // Get it & put it right back in ^ with different Reports Pref.
  801.     private string GetPrefFileName(string dir)
  802.     {
  803.       var pref = FileName; // as default value.
  804.       var file = dir + "\\" + APS.Default.PrefFile;
  805.  
  806.       if (File.Exists(file))
  807.       {
  808.         var name = File.ReadAllText(file).Split('\n')[0];
  809.         // Reads First Line of File Only. ^
  810.         if (!string.IsNullOrEmpty(name)
  811.           && File.Exists(dir + "\\" + name)) pref = name;
  812.       }
  813.       return pref;
  814.     }
  815. #endregion v4.6.9.67 Mar 27 2017
  816.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  817.  
  818.  
  819. #region Upgrade 4.6.9.87 Apr 04 2017
  820.  
  821.     /* Upgrade adds two context menu items, to each context menu,
  822.      * For Move-Up & Move-Down of selected item. 1st item cannot
  823.      * be moved. 2nd Item cannot be moved. If 3rd item is moved to 2nd
  824.      * then we prompt them to make this the prefFolder or back out,
  825.      * leaving things be. Only if 3rd item is moved up AND made the pref
  826.      * does the 2nd (Pref) item fall to 3rd. Nothing can be moved higher than
  827.      * 2nd, the default stays on top no matter what. The pref is 2nd no matter
  828.      * what, except if default path. The bottom item cannot be moved down.
  829.      * Folder must exist. Data folders must contain data files.
  830.      */
  831.  
  832.     /// <summary> The ProtoType For All The Below.
  833.     /// Event handler for the Move Up Context Menus. Item
  834.     /// selected is moved up the list unless already 1st or 2nd.
  835.     /// If 3rd is moved up it requires approval to become Pref.
  836.     ///
  837.     /// See Called Methods below, some shared and so forth.
  838.     /// </summary>
  839.     /// <param name="sender"></param>
  840.     /// <param name="e"></param>
  841.     private void MoveUpToolStrip1MenuItemClick(object sender, EventArgs e)
  842.     { // Data Collection
  843.       if (dataListBox.Items.Count < 3)
  844.       {
  845.         MessageBox.Show(ORS.OMA_MoveItem);
  846.         return; // Remove Short Lists from the equation.
  847.       }
  848.       var dir = dataListBox.SelectedItem.ToString();
  849.       if (!Directory.Exists(dir) || !HasDataFiles(dir))
  850.       {
  851.         OPS.Default.dataListBoxItems.Remove(dir);
  852.         PopulateListBoxes();
  853.         MessageBox.Show(string.Format(
  854.           "The Directory:\n{0}\n\nDoes NOT Exist, or Data Files\n" +
  855.           " could no longer be found on it.\n\n" +
  856.           "It was removed from the list.", dir));
  857.         return; // Eliminate Non Existent Folders.
  858.       }
  859.       var index = OPS.Default.dataListBoxItems.IndexOf(dir);
  860.       if (index < 2)
  861.       { MessageBox.Show(ORS.OMA_Cannot); return; }
  862.       if (index.Equals(2))
  863.       { // 3rd Item needs approval to move up.
  864.         if (!MakeThisThePreference(dir, true)) return;
  865.       }
  866.       // A Last Chance to Abort.
  867.       if ( !OPS.Default.MiniVerb
  868.         && !OPS.Default.AreYouSure
  869.         && !index.Equals(2))
  870.           if (!AST.YesNoDialog(ORS.OMA_Up)) return;
  871.  
  872.       // Now do it!
  873.       MoveData(true, index);
  874.       if (index.Equals(2))
  875.       {
  876.         // Make it the Pref
  877.         folderBrowser.SelectedPath = dir;
  878.         DataChanges();
  879.       }
  880.       else
  881.         PopulateListBoxes();
  882.     }
  883.  
  884.     private void MoveUpToolStrip2MenuItemClick(object sender, EventArgs e)
  885.     {
  886.       // Reports Collection
  887.       if (reportsListBox.Items.Count < 3)
  888.       {
  889.         MessageBox.Show(ORS.OMA_MoveItem);
  890.         return; // Remove Short Lists from the equation.
  891.       }
  892.       var dir = reportsListBox.SelectedItem.ToString();
  893.       if (!Directory.Exists(dir))
  894.       {
  895.         OPS.Default.reportsListBoxItems.Remove(dir);
  896.         PopulateListBoxes();
  897.         MessageBox.Show(string.Format(
  898.           "The Directory:\n{0}\n\n" +
  899.           "Does NOT Exist and was removed from the list.", dir));
  900.         return; // Eliminate Non Existent Folders.
  901.       }
  902.       var index = OPS.Default.reportsListBoxItems.IndexOf(dir);
  903.       if (index < 2) { MessageBox.Show(ORS.OMA_Cannot); return; }
  904.       if (index.Equals(2))
  905.       { // 3rd Item needs approval to move up.
  906.         if (!MakeThisThePreference(dir, false)) return;
  907.       }
  908.       // A Last Chance to Abort.
  909.       if ( !OPS.Default.MiniVerb
  910.         && !OPS.Default.AreYouSure
  911.         && !index.Equals(2))
  912.          if (!AST.YesNoDialog(ORS.OMA_Up)) return;
  913.  
  914.       // Now do it!
  915.       MoveReports(true, index);
  916.       if (index.Equals(2))
  917.       {
  918.         // Making it the Pref if now 2nd in List.
  919.         folderBrowser.SelectedPath = dir;
  920.         ReportsChanges();
  921.       }
  922.       else
  923.         PopulateListBoxes();
  924.     }
  925.  
  926.     /// <summary> Event Handler for Move Down Context Menu Item
  927.     /// This version for the Data List. Clone below for Reports.
  928.     /// </summary>
  929.     /// <param name="sender"></param>
  930.     /// <param name="e"></param>
  931.     private void MoveDownToolStrip1MenuItemClick(object sender, EventArgs e)
  932.     {
  933.       // Data Collection
  934.       var count = dataListBox.Items.Count;
  935.       if (count < 3)
  936.       { // Remove Short Lists from the equation.
  937.         MessageBox.Show(ORS.OMA_MoveItem);
  938.         return;
  939.       }
  940.       var dir = dataListBox.SelectedItem.ToString();
  941.       if (!Directory.Exists(dir) || !HasDataFiles(dir))
  942.       {
  943.         OPS.Default.dataListBoxItems.Remove(dir);
  944.         MessageBox.Show(string.Format(
  945.           "The Directory:\n{0}\n\nDoes NOT Exist, or Data Files\n" +
  946.           " could no longer be found on it.\n\n" +
  947.           "It was removed from the list.", dir));
  948.         return; // Eliminate Non Existent Folders.
  949.       }
  950.       var index = OPS.Default.dataListBoxItems.IndexOf(dir);
  951.       if (index < 2)
  952.       {
  953.         MessageBox.Show(ORS.OMA_Cannot);
  954.         return; // Remove Items 1 and 2 from the equation. ^
  955.       }
  956.       if (index + 1 == count)
  957.       {
  958.         MessageBox.Show(ORS.OMA_Last);
  959.         return; // Can't Move Last item Down Msg.
  960.       }
  961.       if (!OPS.Default.MiniVerb && !OPS.Default.AreYouSure)
  962.         if (!AST.YesNoDialog(ORS.OMA_Down)) return;
  963.       // Last Chance to BackOut.
  964.       // And finally, if everything above checks out, Move it.
  965.       MoveData(false, index);
  966.       PopulateListBoxes();
  967.     }
  968.  
  969.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  970.     // Design Algorithm - Graphic for Move Down visualization.
  971.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  972.     // index[0] = item1 can't be moved. ***Handled***
  973.     // index[1] = item2 can't be moved. ***Handled***
  974.     // index[2] = item3 can be moved down, by removing and inserting.
  975.     // index[N] = itemN etc, etc. ^^^         ^^^^^^^^^^^^^^^^^^
  976.     // index[N] = by removing and inserting ***Handled*** v
  977.     // index[N]   by removing and inserting ***Handled*** v for N iterations.
  978.     // index[x] = item-x 3rd from End can be moved, by removing and inserting.
  979.     // index[y] = item-y 2nd from End can be moved, by removing & ADDING ONLY! ***OK***
  980.     // index[z] = item-z Last item can't be moved down. ***Handled***
  981.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  982.  
  983.     private void MoveDownToolStrip2MenuItemClick(object sender, EventArgs e)
  984.     {
  985.       // Reports Collection
  986.       var count = reportsListBox.Items.Count;
  987.       if (count < 3)
  988.       { // Remove Short Lists from the equation.
  989.         MessageBox.Show(ORS.OMA_MoveItem);
  990.         return;
  991.       } // <-= Show msg, do Nothing. ^
  992.       var dir = reportsListBox.SelectedItem.ToString();
  993.       if (!Directory.Exists(dir))
  994.       {
  995.         OPS.Default.reportsListBoxItems.Remove(dir);
  996.         MessageBox.Show(string.Format(
  997.           "The Directory:\n{0}\n\nDoes NOT Exist, or Data Files\n" +
  998.           " could no longer be found on it.\n\n" +
  999.           "It was removed from the list.", dir));
  1000.         return; // Eliminate Non Existent Folders.
  1001.       }
  1002.       var index = OPS.Default.reportsListBoxItems.IndexOf(dir);
  1003.       if (index < 2)
  1004.       {
  1005.         MessageBox.Show(ORS.OMA_Cannot);
  1006.         return; // Remove Items 1 and 2 from the equation.
  1007.       }
  1008.       if (index + 1 == count)
  1009.       {
  1010.         MessageBox.Show(ORS.OMA_Last);
  1011.         return; // Can't Move Last item Down Msg.
  1012.       }
  1013.       if (!OPS.Default.MiniVerb && !OPS.Default.AreYouSure)
  1014.         if (!AST.YesNoDialog(ORS.OMA_Down)) return;
  1015.       // Last Chance to BackOut if Not MiniVerb or AYS.
  1016.       // And finally, if everything above checks out, Move it.
  1017.       MoveReports(false, index);
  1018.       PopulateListBoxes();
  1019.     }
  1020.  
  1021.     /// <summary> Moves Data List Items Up or Down.
  1022.     /// Clone below does the same for the Reports List.
  1023.     /// </summary>
  1024.     /// <param name="up"></param>
  1025.     /// <param name="index"></param>
  1026.     private static void MoveData(bool up, int index)
  1027.     {
  1028.       var add = false;
  1029.       var dir = OPS.Default.dataListBoxItems[index];
  1030.       var count = OPS.Default.dataListBoxItems.Count;
  1031.       OPS.Default.dataListBoxItems.RemoveAt(index);
  1032.       if (up) index--;
  1033.       else
  1034.       { // if down...
  1035.         if (index + 2 == count) add = true;
  1036.         index++; // ^ 2nd to last has to be added not inserted. v
  1037.       }
  1038.       if (add) OPS.Default.dataListBoxItems.Add(dir);
  1039.       else OPS.Default.dataListBoxItems.Insert(index, dir);
  1040.     }
  1041.     private static void MoveReports(bool up, int index)
  1042.     {
  1043.       var add = false;
  1044.       var dir = OPS.Default.reportsListBoxItems[index];
  1045.       var count = OPS.Default.reportsListBoxItems.Count;
  1046.       OPS.Default.reportsListBoxItems.RemoveAt(index);
  1047.       if (up) index--;
  1048.       else
  1049.       { // down...
  1050.         if (index + 2 == count) add = true;
  1051.         index++;
  1052.       }
  1053.       if (add) OPS.Default.reportsListBoxItems.Add(dir);
  1054.       else OPS.Default.reportsListBoxItems.Insert(index, dir);
  1055.     }
  1056.  
  1057.     /// <summary> Specialized Dialog Gets Approval for Preference Setting.
  1058.     /// Used by both Reports and Data Move Up Methods. Not needed in down.
  1059.     /// </summary>
  1060.     /// <param name="dir"></param>
  1061.     /// <param name="data"></param>
  1062.     /// <returns></returns>
  1063.     private static bool MakeThisThePreference(string dir, bool data)
  1064.     {
  1065.       // New conditional v4.7.3.83
  1066.       if (OPS.Default.MiniVerb) return true;
  1067.  
  1068.       const string title =
  1069.         "Make This the Preference?";
  1070.       var text       = "Your New Reports Directory Preference.";
  1071.       if (data) text = "Your New Data-Directory-Preference.";
  1072.  
  1073.       return
  1074.         MessageBox.Show(string.Format(
  1075.           "This will make:\n{0}\n\n" + text +
  1076.           "\n\nAre You Sure?", dir), title,
  1077.           MessageBoxButtons.YesNo,
  1078.           MessageBoxIcon.Question,
  1079.           MessageBoxDefaultButton.Button2
  1080.         ).Equals(DialogResult.Yes);
  1081.     }
  1082. #endregion Upgrade 4.6.9.87 Apr 04 2017
  1083.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  1084.  
  1085.  
  1086. #region Upgrade v4.7.1.23 Upgrade SubSection Apr 19 2017
  1087.  
  1088.     private void RestoreOldPrefsClick(object sender, EventArgs e)
  1089.     {
  1090.       if (!OPS.Default.MiniVerb
  1091.         && !OPS.Default.AreYouSure)
  1092.           if (!AST.YesNoDialog(
  1093.             "Bring Back All preference files?")) return;
  1094.  
  1095.       var pref = APS.Default.PrefFile;
  1096.       foreach (var item in
  1097.         OPS.Default.dataListBoxItems)
  1098.       {
  1099.         if (!Directory.Exists(item)) continue;
  1100.         var source = item + "\\" + "old" + pref;
  1101.         if (!File.Exists(source)) continue;
  1102.         var destin = item + "\\" + pref;
  1103.         if (File.Exists(destin))
  1104.         {
  1105.           if ( !OPS.Default.MiniVerb
  1106.             && !OPS.Default.AreYouSure)
  1107.               if (!AST.YesNoDialog(
  1108.                 "Replace Existing preference file?"))
  1109.             continue;
  1110.           File.Delete(destin);
  1111.         }
  1112.         File.Move(source, destin);
  1113.       }
  1114.     }
  1115.  
  1116.     private void WipePrefsClick(object sender, EventArgs e)
  1117.     {
  1118.       int mover;
  1119.       bool preserver;
  1120.       if (!OPS.Default.MiniVerb)// && !OPS.Default.AreYouSure)
  1121.       {
  1122.         const string
  1123.           text1 = "Clear ALL preference files from entire\n" +
  1124.                   "Data Folder collection?",
  1125.           text2 = "This is not recommended.\n\n" +
  1126.                   "Do you really need to start fresh?",
  1127.           text3 = "Do you want to preserve the\n" +
  1128.                   "preferences for the default Directory?",
  1129.           text4 = "Rename instead of Delete,\n" +
  1130.                   "So they can be restored if needed?";
  1131.         if (!OPS.Default.AreYouSure)
  1132.           if (!AST.YesNoDialog(text1)) return;
  1133.         if (!AST.YesNoDialog(text2)) return;
  1134.         preserver = OPS.Default.AreYouSure
  1135.           || AST.YesNoDialog(text3);
  1136.         mover = AST.YesNoDialog(text4) ? 1 : 0;
  1137.       } // v made reUsable v4.7.1.23br
  1138.       else { preserver = true; mover = 1; }
  1139.  
  1140.       BackupPreferences(preserver, mover, false);
  1141.     }
  1142.  
  1143.     private void
  1144.       BackupAllPrefsToolStripMenuItemClick
  1145.       (object sender, EventArgs e)
  1146.     {
  1147.       if (!OPS.Default.MiniVerb)
  1148.         if (!AST.YesNoDialog(
  1149.           "Backup ALL preference files,\nOver Writing " +
  1150.           "any previous backups...\n\nAre You Sure?")) return;
  1151.       BackupPreferences(false, 2, true);
  1152.       ShowResult(2);
  1153.     }
  1154.  
  1155.     /// <summary> This 1 overload is not really connected
  1156.     /// to the others of nearly the same name here, which are,
  1157.     /// for the most part, interconnected and cross dependant.
  1158.     /// </summary>
  1159.     /// <param name="moveIt"></param>
  1160.     private static void ShowResult(int moveIt)
  1161.     {
  1162.       if (OPS.Default.MiniVerb) return;
  1163.       var msg = "";
  1164.       if (moveIt < 0
  1165.          || moveIt > 2) msg = "Error in OMA!";
  1166.       if (moveIt.Equals(0)) msg = "All Preference Files Have Been Deleted.";
  1167.       if (moveIt.Equals(1)) msg = "All Preference Files Have Been ReNamed.";
  1168.       if (moveIt.Equals(2)) msg = "All Preference Files Have Been Backed up.";
  1169.       MessageBox.Show(msg);
  1170.     }
  1171.  
  1172.     /// <summary> ReWritten to accomodate both of the above calls, etc.
  1173.     /// v4.7.1.23 Apr 19 2017 Could be called elsewhere:
  1174.     /// Also Called from Restore3() if Scheduled Maint is due.
  1175.     /// </summary>
  1176.     /// <param name="preserve"></param>
  1177.     /// <param name="moveIt"></param>
  1178.     /// <param name="auto"></param>
  1179.     public static void
  1180.       BackupPreferences(bool preserve, int moveIt, bool auto)
  1181.     {
  1182.       var pref = APS.Default.PrefFile;
  1183.       foreach (var dir in OPS.Default
  1184.         .dataListBoxItems.Cast<string>()
  1185.         .Where(Directory.Exists))
  1186.       {
  1187.         if (preserve.Equals(true))
  1188.         { preserve = false; continue; }
  1189.  
  1190.         var source = dir + "\\" + pref;
  1191.         var destin = dir + "\\" + "old" + pref;
  1192.         if (!File.Exists(source)) continue;
  1193.         if (File.Exists(destin))
  1194.         {
  1195.           if ( !OPS.Default.MiniVerb
  1196.             && !OPS.Default.AreYouSure
  1197.             && !auto)
  1198.               if (!AST.YesNoDialog(
  1199.                 "Delete old preference backup?"))
  1200.                   continue;
  1201.           File.Delete(destin);
  1202.         }
  1203.         if (moveIt == 0) File.Delete(source);
  1204.         if (moveIt == 1) File.Move(source, destin);
  1205.         if (moveIt == 2) File.Copy(source, destin);
  1206.       }
  1207.       if (!auto) ShowResult(moveIt);
  1208.     }
  1209. #endregion subregion v4.7.1.23 Upgrade SubSection
  1210.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  1211.  
  1212.    
  1213. #region Upgrade 4.7.3.73 Updates older & adds new "View-All Options".
  1214.  
  1215.     // ContextMenuStrip1 Item for Data Dirs.
  1216.     private void ViewPrefsToolStrip1MenuItemClick(object sender, EventArgs e)
  1217.     {
  1218.       const string
  1219.         text1 = "The Reports Folder Associated with this Data Folder is:",
  1220.         text2 = "The File Name Associated with this Data Folder is:";
  1221.       string
  1222.         dir   = dataListBox.SelectedItem.ToString(),
  1223.         text3 = "",
  1224.         test1 = OPS.Default.PrefRootDir,
  1225.         filename = GetPrefFileName(dir),
  1226.         reports  = GetStoredReportsDirPref(dir);
  1227.       if (dir.Equals(test1)) text3 =
  1228.         "\nThis is your Currently Preferred Folder and Data File.";
  1229.       var msg = string.Format(
  1230.         text1 + "\n{0}\n\n" + text2 + "\n{1}\n" + text3,
  1231.         reports, filename);
  1232.       DisplayResults(msg,"");
  1233.     }
  1234.  
  1235.     // Upgrade v4.7.3.71 May 17 2017,
  1236.     // Similar to above but foreach item in DataListBox.
  1237.     private void ViewAllPrefsClick(object sender, EventArgs e)
  1238.     {
  1239.       const string
  1240.         title   = "View ALL Preferences:",
  1241.         text1   = "The Reports Folder Associated with this Data Folder is:",
  1242.         text2   = "The File Name Associated with this Data Folder is:";
  1243.       var text  = "";
  1244.       var pref  = OPS.Default.PrefRootDir;
  1245.       var list  = OPS.Default.dataListBoxItems;
  1246.       foreach (var dir in list)
  1247.       {
  1248.         var top = string.Format("Results for:\n{0}\n\n", dir);
  1249.         var msg = "";
  1250.         if (dir.Equals(pref)) msg =
  1251.           "This is your Currently Preferred Folder and Data File.\n\n";
  1252.         msg     = top + msg;
  1253.         text   += string.Format(msg + text1 +
  1254.           "\n{0}\n\n" + text2 + "\n{1}\n\n\n",
  1255.           GetStoredReportsDirPref(dir), GetPrefFileName(dir));
  1256.       }
  1257.       var size  = AUS.Default.OMA_D1_Size;
  1258.       var loca  = AUS.Default.OMA_D1_Loca;
  1259.         DisplayResults(text, title, ref size, ref loca);
  1260.       AUS.Default.OMA_D1_Size = size;
  1261.       AUS.Default.OMA_D1_Loca = loca;
  1262.       AUS.Default.Save();
  1263.     }
  1264.  
  1265.     /// <summary> These are an interconnected group of
  1266.     /// overloaded methods to handle various needs.
  1267.     /// This one defaults to a Title of "View Preferences"
  1268.     /// and calls the next one down and so on.
  1269.     /// Combines: DisplayResult, DisplayResults & DisplayOutCome.
  1270.     /// if title is empty default as shown.
  1271.     /// This one has it's own Settings for Form Size & Location.
  1272.     /// </summary>
  1273.     /// <param name="text"></param>
  1274.     /// <param name="title"></param>
  1275.     private static void DisplayResults(string text, string title)
  1276.     {
  1277.       if (string.IsNullOrEmpty(title)) title = "View Preferences:";
  1278.  
  1279.       var size = AUS.Default.OMA_DOC_Size;
  1280.       var loca = AUS.Default.OMA_DOC_Loc;
  1281.         DisplayResults(text, title, ref size, ref loca);
  1282.       AUS.Default.OMA_DOC_Size = size;
  1283.       AUS.Default.OMA_DOC_Loc  = loca;
  1284.       AUS.Default.Save();
  1285.     }
  1286.  
  1287.     /// <summary> Original v4.6.9.95 Apr 07 2017
  1288.     /// Given a List of two strings, each, in a Generic Dictionary Collection,
  1289.     /// Call the common GetDisplayString() and then the DisplayResults();
  1290.     /// Rebuilt with OverLoads above for ViewAllAssociations v4.7.3.73 May 15
  1291.     /// It directly calls the Mother Method of them all below the next one,
  1292.     /// As does the next one.
  1293.     /// </summary>
  1294.     /// <param name="dic"></param>
  1295.     private void DisplayResults(Dictionary<string, string> dic)
  1296.     {
  1297.       var dir  = reportsListBox.SelectedItem.ToString();
  1298.       var text = GetDisplayString(dic, dir);
  1299.       var size = AUS.Default.OMA_Display_Size;
  1300.       var loca = AUS.Default.OMA_Display_Loc;
  1301.       const string title = "";
  1302.         DisplayResults(text, title, ref size, ref loca);
  1303.       AUS.Default.OMA_Display_Size = size;
  1304.       AUS.Default.OMA_Display_Loc  = loca;
  1305.       AUS.Default.Save();
  1306.     }
  1307.  
  1308.     /// <summary> This one accepts the Collection of Dictionaries for
  1309.     /// ViewAllAssociations(); Has it's own special Size & Location Settings.
  1310.     /// It directly calls the Mother Method of them all below this one.
  1311.     /// NOTE: "var x = ..." below does a ton of work,
  1312.     /// & faster because instead of a loop it's a LINQ query!
  1313.     /// </summary>
  1314.     /// <param name="listOfLists"></param>
  1315.     private static void DisplayResults
  1316.       (IEnumerable<Dictionary<string, string>> listOfLists)
  1317.     {
  1318.       #region was
  1319.       //var i = 0;
  1320.       //var x = "";
  1321.       //foreach (var dic in listOfLists)
  1322.       //  x += GetDisplayString(dic, OPS.Default.reportsListBoxItems[i++]);
  1323.       #endregion was
  1324.       var i = 0;
  1325.       var x = listOfLists.Aggregate("", (current, dic) => current   +
  1326.         GetDisplayString(dic, OPS.Default.reportsListBoxItems[i++]) +
  1327.         "========================");
  1328.  
  1329.       const string t = "";
  1330.       var s = AUS.Default.OMA_D4_S;
  1331.       var l = AUS.Default.OMA_D4_L;
  1332.         DisplayResults(x, t, ref s, ref l);
  1333.       AUS.Default.OMA_D4_S = s;
  1334.       AUS.Default.OMA_D4_L = l;
  1335.       AUS.Default.Save();
  1336.     }
  1337.  
  1338.     /// <summary> This overload is where all end up.
  1339.     /// It allows for total flexibility of usages for all args.
  1340.     /// While providing critical defaults to reduce duplicity.
  1341.     /// if title is empty it defaults to:
  1342.     /// "Folder Associations Information:"
  1343.     /// </summary>
  1344.     /// <param name="x"></param>
  1345.     /// <param name="t"></param>
  1346.     /// <param name="s"></param>
  1347.     /// <param name="l"></param>
  1348.     private static void DisplayResults
  1349.       (string x, string t, ref Size s, ref Point l)
  1350.     {
  1351.       if (string.IsNullOrEmpty(t)) t =
  1352.         "Folder Associations Information:";
  1353.       using (var f = new ShowMeForm(x, t))
  1354.       {
  1355.         f.Size     = s;
  1356.         f.Location = l;
  1357.           f.ShowDialog();
  1358.         l = f.Location;
  1359.         s = f.Size;
  1360.       }
  1361.     }
  1362.  
  1363.     /// <summary> This was split out so it can be used by both
  1364.     /// the View2Associations and the ViewAllAssociations: v4.7.3.75
  1365.     /// Added the string dir arg to the sig to interface it with both.
  1366.     /// </summary>
  1367.     /// <param name="dic"></param>
  1368.     /// <param name="dir"></param>
  1369.     /// <returns></returns>
  1370.     private static string GetDisplayString
  1371.       (Dictionary<string, string> dic, string dir)
  1372.     { // Sweet! Great integration.
  1373.       #region Was
  1374.       //foreach (var pair in list)
  1375.       //{
  1376.       //  // Concatenate the text string and show it.
  1377.       //  text += "The Data Folder:\n" + pair.Key +
  1378.       //    "\n\nWhich is set to the Data file: \n" +
  1379.       //    pair.Value + "\n\n";
  1380.       //}
  1381.       #endregion Was
  1382.       var
  1383.         text = string.Format("\nResults for: {0}\n\n" +
  1384.           "The following currently use this Reports Folder:\n\n", dir);
  1385.       return
  1386.         dic.Aggregate(text, (current, pair) => current +
  1387.           ("The Data Folder:\n" + pair.Key +
  1388.             "\n\nWhich is set to the Data file: \n" +
  1389.               pair.Value + "\n\n"));
  1390.     }
  1391.  
  1392.     /// <summary> Upgrade v4.7.3.96 May 30 2017
  1393.     /// Similar to the View2Ass but foreach item in ReportsListBox.
  1394.     /// Design hopped up the Engine below for usage here by splitting
  1395.     /// the existing EventHandler v into two parts,
  1396.     /// the 2nd of which (the engine) I can reuse here.
  1397.     /// NOTE use of Collection of Dictionaries. Very powerful and
  1398.     /// especially when you consider that Dictionaries are Generic!
  1399.     /// this calls a special overload of DisplayResults(list);
  1400.     /// </summary>
  1401.     /// <param name="sender"></param>
  1402.     /// <param name="e"></param>
  1403.     private void ViewAllAssociationsClick(object sender, EventArgs e)
  1404.     {
  1405.       var none = new Collection<string>();
  1406.       var list = new Collection<Dictionary<string, string>>();
  1407.       var dirs = OPS.Default.reportsListBoxItems;
  1408.       foreach (var dir in dirs.Cast<string>()
  1409.         .Where(dir => !string.IsNullOrEmpty(dir)
  1410.           && Directory.Exists(dir)))
  1411.       {
  1412.         var dict = new Dictionary<string, string>();
  1413.         View2AssociationsEngine(dir, ref dict, true);
  1414.         if (dict.Count < 1)
  1415.         {
  1416.           #region Rev Doc
  1417.           // collect the unused paths HERE and do the Yes/No-remove
  1418.           // later after this loop. The "true" in the call to the engine
  1419.           // (above View2Ass) skips that in there now. v4.7.3.72 -JpE-
  1420.           #endregion Rev Doc
  1421.           none.Add(dir);
  1422.           continue;
  1423.         }
  1424.         list.Add(dict);
  1425.       }
  1426.       if (list.Count > 0) DisplayResults(list);
  1427.       if (none.Count > 0) BatchRemove(none);
  1428.     }
  1429.  
  1430.     private void BatchRemove(ICollection<string> unused)
  1431.     {
  1432.       #region was
  1433.       //foreach (var path in unused)
  1434.       //{
  1435.       //  if (OPS.Default.reportsListBoxItems.IndexOf(path) < 1) continue;
  1436.       //  var text = ORS.OMA_ViewAss + "\n\nPath:\n" + path;
  1437.       //  if (MessageBox.Show(text, ORS.OMA_ViewAssTitle,
  1438.       //    MessageBoxButtons.YesNo, MessageBoxIcon.Question,
  1439.       //    MessageBoxDefaultButton.Button2)
  1440.       //      != DialogResult.Yes) continue;
  1441.       //  if (path.Equals(OPS.Default.PrefReportsDir))
  1442.       //  {
  1443.       //    var target =
  1444.       //      OPS.Default.reportsListBoxItems.IndexOf(path) + 1;
  1445.       //    // if Pref Adopt next in List automatically as new Pref.
  1446.       //    if (target == unused.Count) target = 0;
  1447.       //    ReportsTextBox.Text = WhatWasItB2 =
  1448.       //      OPS.Default.PrefReportsDir =
  1449.       //        OPS.Default.reportsListBoxItems[target];
  1450.       //    if (target < 1) continue;
  1451.       //  }
  1452.       //  OPS.Default.reportsListBoxItems.Remove(path);
  1453.       //}
  1454.       #endregion was
  1455.       foreach
  1456.         (var path in from path in unused
  1457.           where OPS.Default.reportsListBoxItems.IndexOf(path) >= 1
  1458.           let text = ORS.OMA_ViewAss + "\n\nPath:\n" + path
  1459.           where AST.YesNoDialog(text, ORS.OMA_ViewAssTitle)
  1460.           || OPS.Default.MiniVerb
  1461.           //|| OPS.Default.AreYouSure
  1462.           select path)
  1463.       {
  1464.         if (path.Equals(OPS.Default.PrefReportsDir))
  1465.         {
  1466.           var target =
  1467.             OPS.Default.reportsListBoxItems.IndexOf(path) + 1;
  1468.           // if Pref Adopt next in List automatically as new Pref.
  1469.           if (target == unused.Count) target = 0;
  1470.           ReportsTextBox.Text = WhatWasItB2 =
  1471.             OPS.Default.PrefReportsDir =
  1472.             OPS.Default.reportsListBoxItems[target];
  1473.           if (target < 1) continue;
  1474.         }
  1475.         OPS.Default.reportsListBoxItems.Remove(path);
  1476.       }
  1477.       PopulateListBoxes();
  1478.     }
  1479.  
  1480.     /// <summary> ContextMenuStrip2 Item for Reports Dirs. This one was funner,
  1481.     /// it will flip through the data folder list and get the prefs info for
  1482.     /// Reports Folder and Collate a list of those that use the Selected Reports Folder
  1483.     /// and the pref filename for each. plagarized from myself in this reWrite for
  1484.     /// Collections.Generic.Dictionary: v4.6.9.94 Apr 06 2017 -JpE-
  1485.     /// Split into this and the Engine below for ViewAll mods v4.7.3.73 May 15 2017
  1486.     /// </summary>
  1487.     /// <param name="sender"></param>
  1488.     /// <param name="e"></param>
  1489.     private void View2AssociationsToolStrip2MenuItemClick(object sender, EventArgs e)
  1490.     {
  1491.       var dir = reportsListBox.SelectedItem.ToString();
  1492.       var dic = new Dictionary<string, string>();
  1493.         View2AssociationsEngine(dir, ref dic, false); // !all = single path
  1494.       if (dic.Count > 0) DisplayResults(dic);
  1495.     }
  1496.  
  1497.     /// <summary> Split from the above for ReUse with ViewAllAss Mods v4.7.3.74
  1498.     /// NOTE that if all == true then it cuts short at the comment defering removals.
  1499.     /// Hand crafted to work with ViewAllAssociationsClick(); -JpE- May 17 2017
  1500.     /// </summary>
  1501.     /// <param name="selected"></param>
  1502.     /// <param name="dirFileNameList"></param>
  1503.     /// <param name="all"></param>
  1504.     private void View2AssociationsEngine
  1505.       (string selected, ref Dictionary<string, string> dirFileNameList, bool all)
  1506.     {
  1507.       var invalid = new Collection<string>();
  1508.       var nth = 0;
  1509.       try
  1510.       {
  1511.         foreach (var dataPath in OPS.Default.dataListBoxItems)
  1512.         {
  1513.           if (!Directory.Exists(dataPath)) { invalid.Add(dataPath); continue; }
  1514.           if (!selected.Equals(GetStoredReportsDirPref(dataPath)))  continue;
  1515.           // else it found one...
  1516.           var key = string.Format("{0}) ", ++nth) + dataPath;
  1517.           var prefsFilesName = GetPrefFileName(dataPath);
  1518.           if (string.IsNullOrEmpty(prefsFilesName))
  1519.           { prefsFilesName = "None Associated"; }
  1520.           dirFileNameList.Add(key, prefsFilesName);
  1521.         }
  1522.       } // <-= End of Loop.
  1523.       catch (ArgumentException exception)
  1524.       {
  1525.         if (IF.Testing)
  1526.           MessageBox.Show(exception.ToString()); return;
  1527.       }
  1528.       if (invalid.Count > 0) RemoveInvalidFolders(true, invalid); // Apt identifiers.
  1529.       //   v reworked to do a BatchRemove call in ViewAllAss v72...
  1530.       if (all || dirFileNameList.Count > 0) return;
  1531.       //   ^ ...& defer removes when "all" arg is true.
  1532.       // ViewALL returns here skipping the rest each iteration. So...
  1533.       //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  1534.  
  1535.       #region View2 call only sees the rest of this.
  1536.       if (!AST.YesNoDialog(ORS.OMA_ViewAss, ORS.OMA_ViewAssTitle)) return;
  1537.  
  1538.       if (OPS.Default.reportsListBoxItems.IndexOf(selected) < 1)
  1539.       { MessageBox.Show(ORS.OF_Remove); return; }
  1540.       if (selected.Equals(OPS.Default.PrefReportsDir))
  1541.       {
  1542.         var target = OPS.Default
  1543.           .reportsListBoxItems.IndexOf(selected) + 1;
  1544.         if (target == OPS.Default.reportsListBoxItems.Count)
  1545.           target = 0;
  1546.         // if Pref, Adopt next in List automatically as new Pref.
  1547.         ReportsTextBox.Text = WhatWasItB2 =
  1548.           OPS.Default.PrefReportsDir =
  1549.           OPS.Default.reportsListBoxItems[target];
  1550.         if (target == 0) return;
  1551.       }
  1552.       // either way, it's history...
  1553.       OPS.Default.reportsListBoxItems.Remove(selected);
  1554.       PopulateListBoxes();
  1555.       #endregion View2 call only section.
  1556.     }
  1557.  
  1558.     // v4.7.3.70 May 14 2017
  1559.     // Took these to a ShowMe calling DisplayResults()
  1560.     private void ViewBackupDataList(object sender, EventArgs e)
  1561.     {
  1562.       var flag = false;
  1563.       var text = "There is no Backup for this List.";
  1564.       if (PMS.Default.Bac_dataCollection != null
  1565.         && PMS.Default.Bac_dataCollection.Count > 0)
  1566.       {
  1567.         flag = true;
  1568.         text =
  1569.           PMS.Default.Bac_dataCollection.Cast<string>()
  1570.             .Aggregate("Data Collection:\n\n",
  1571.               (current, dir) => current + (dir + "\n"));
  1572.       }
  1573.       if (!flag) { MessageBox.Show(text); return; }
  1574.  
  1575.       const string title = "Backup Data Folder List";
  1576.       var size = AUS.Default.OMA_D2_Size;
  1577.       var loca = AUS.Default.OMA_D2_Loca;
  1578.         DisplayResults(text, title, ref size, ref loca);
  1579.       AUS.Default.OMA_D2_Size = size;
  1580.       AUS.Default.OMA_D2_Loca = loca;
  1581.       AUS.Default.Save();
  1582.     }
  1583.  
  1584.     private void ViewBackupReportsList(object sender, EventArgs e)
  1585.     {
  1586.       var flag = false;
  1587.       var text = "There is no Backup for this List.";
  1588.       if (PMS.Default.Bac_reportsCollection != null
  1589.         && PMS.Default.Bac_reportsCollection.Count > 0)
  1590.       {
  1591.         flag = true;
  1592.         text =
  1593.           PMS.Default.Bac_reportsCollection.Cast<string>()
  1594.             .Aggregate("Reports Collection:\n\n",
  1595.               (current, dir) => current + (dir + "\n"));
  1596.       }
  1597.       if (!flag) { MessageBox.Show(text); return; }
  1598.  
  1599.       const string title = "Backup Reports Folder List";
  1600.       var size = AUS.Default.OMA_D3_Size;
  1601.       var loca = AUS.Default.OMA_D3_Loca;
  1602.         DisplayResults(text, title, ref size, ref loca);
  1603.       AUS.Default.OMA_D3_Size = size;
  1604.       AUS.Default.OMA_D3_Loca = loca;
  1605.       AUS.Default.Save();
  1606.     }
  1607. #endregion Upgrade 4.7.3.73 Updates to existing and new.
  1608.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  1609.  
  1610.  
  1611. #region v4.7.5.25 14Jun17 -=[ THE BIG 2 ]=-
  1612.  
  1613.     /* Upgrade Adds The Context Menu Items to Backup & Restore
  1614.      * The Lists Which are already Saved in PrintMasterSettings.
  1615.      * The Save and Restore of Lists is already in & tested. -JpE-
  1616.      * Retain/Revert/Cancel is in and tested. The Big 2 methods here
  1617.      * are the EventHandlers for these Context Menu Options in each ListBox.
  1618.      * They are known here, affectionately, as the Big 2. Each Full Featured.
  1619.      *
  1620.      * The rest of the NEXT #region is the various ReUsable Methods that support
  1621.      * the Big 2. I wanted to make everything modular and these support methods are
  1622.      * very flexible and get used by all 4 of the EventHandlers. Each support method
  1623.      * has at least 2 code paths (data true or false) and most have 4 for each occasion.
  1624.      * BackupDataList, BackupReportsList, RestoreDataList & RestoreReportsList.
  1625.      * I was practicing making things compact and reusable and reducing total code.
  1626.      * Updated v4.7.5.28 Jun 16 2017 for the AutoBackup and everything called from
  1627.      * AppCode2.Restore4(); for Maintenance.
  1628.      *
  1629.      */
  1630.  
  1631. #region Backup & Backup Specific
  1632.  
  1633.     /// <summary> BackupDataList Context Menu EventHandler
  1634.     /// Split out & consolidated to BackupLists which
  1635.     /// now does both. v4.7.5.21 12Jun17
  1636.     /// </summary>
  1637.     /// <param name="sender"></param>
  1638.     /// <param name="e"></param>
  1639.     private void BackupDataList(object sender, EventArgs e)
  1640.     {
  1641.       const bool
  1642.         data = true,
  1643.         auto = false;
  1644.       BackupLists(data, auto);
  1645.     }
  1646.  
  1647.     /// <summary> AutoMode Tricks. v4.7.5.15 10Jun17
  1648.     /// v4.7.5.12.3 Jun 08 17 Mods adds BackupListsAuto();
  1649.     /// to Restore3, Scheduler Call. Setting sender here
  1650.     /// makes it auto-mode there.
  1651.     /// So... sig is (bool data, bool auto)
  1652.     /// v4.7.5.19 Perfected and Final Testing. 12Jun17
  1653.     /// Constructor in OF makes this possible though
  1654.     /// it is not static, through an instantiation.
  1655.     /// </summary>
  1656.     public void BackupListsAuto()
  1657.     {
  1658.     //BackupLists( data, auto); // por exemplar
  1659.       BackupLists( true, true); // datafolders
  1660.       BackupLists(false, true); // reportsfolders
  1661.     }
  1662.  
  1663.     /// <summary> BackupReportsList Context Menu EventHandler
  1664.     /// Split out & consolidated to BackupLists which
  1665.     /// now does both. v4.7.5.21 12Jun17
  1666.     /// </summary>
  1667.     /// <param name="sender"></param>
  1668.     /// <param name="e"></param>
  1669.     private void BackupReportsList(object sender, EventArgs e)
  1670.     {
  1671.       const bool
  1672.         data = false,
  1673.         auto = false;
  1674.       BackupLists(data, auto);
  1675.     }
  1676.  
  1677.     /// <summary> All-In-One Backup Module
  1678.     /// RetroFit for automode v4.7.5.23
  1679.     /// 12-Jun-2017
  1680.     /// </summary>
  1681.     /// <param name="data"></param>
  1682.     /// <param name="auto"></param>
  1683.     private void BackupLists(bool data, bool auto)
  1684.     {
  1685.       if (!AskUser(data, auto)) return;
  1686.       const bool backup = true;
  1687.       var merge = false;
  1688.       StringCollection unique;
  1689.       if (HasUniquePath(data, out unique, backup))
  1690.       { // Backup has something unique.
  1691.         if (auto) merge = true;
  1692.         else
  1693.           merge = OPS.Default.MiniVerb
  1694.             || AST.YesNoDialog(ORS.OMA_B1, 1);
  1695.       }
  1696.       var what = 0;
  1697.       var both = BothHaveBoth(ref what, data);
  1698.       if (!merge && unique.Count > 0)
  1699.       {
  1700.         var r = AST.YesNoCancel(ORS.OMA_B2, 1);
  1701.         if (r == 3) return; // Cancel Clicked.
  1702.         if (r == 1)
  1703.         {
  1704.           DontMerge(data);
  1705.           what = 1;
  1706.           both = false;
  1707.           unique.Clear();
  1708.         }
  1709.         if (r == 2) merge = true;
  1710.       }
  1711.       var rr = 0;
  1712.       if (!auto)
  1713.         if (both && merge)
  1714.           rr = RetainRevert(ORS.OMA_B3);
  1715.       if (rr > 2) return;
  1716.       var retain = rr < 2;
  1717.       if (!both)
  1718.       {
  1719.         if (what  < 2) retain = true;
  1720.         if (what == 2) retain = false;
  1721.       }
  1722.       // what == 1 (is) only in OS, 2 only in PMS, 0 == Neither.
  1723.       if (what < 1 && !auto)
  1724.       {
  1725.         if (data) SoWhat(); // and here
  1726.         else SoWhatElse();
  1727.       }
  1728.       Merger(retain, unique, backup, data, auto); // replace 2nd true for data var inside.
  1729.       OPS.Default.Save();
  1730.       PMS.Default.Save();
  1731.       if (OPS.Default.MiniVerb || auto) return;
  1732.       ShowBackupResult(true, merge, retain);
  1733.     }
  1734.  
  1735.     /// <summary> Ask for for User Input to Proceed.
  1736.     /// but there is no more Big Four it's the Big two now LoL
  1737.     /// The Big two each ate one of the Big 4 but didn't grow.
  1738.     /// </summary>
  1739.     /// <param name="data"></param>
  1740.     /// <param name="auto"></param>
  1741.     /// <returns></returns>
  1742.     private static bool AskUser(bool data, bool auto)
  1743.     {
  1744.       // Split out from BackupLists v4.7.5.21
  1745.       if (data)
  1746.       {
  1747.         if (OPS.Default.dataListBoxItems.Count < 1)
  1748.         {
  1749.           if (!auto) MessageBox.Show(ORS.OMA_E2);
  1750.           return false;
  1751.         }
  1752.         if (!OPS.Default.MiniVerb
  1753.           && !OPS.Default.AreYouSure
  1754.           && !auto)
  1755.             if (!AST.YesNoDialog(ORS.OMA_BDL))
  1756.               return false;
  1757.       }
  1758.       else // if not data it is reports calling.
  1759.       {
  1760.         if (OPS.Default.reportsListBoxItems.Count < 1)
  1761.         {
  1762.           if (!auto) MessageBox.Show(ORS.OMA_E3);
  1763.           return false;
  1764.         }
  1765.         if (!OPS.Default.MiniVerb
  1766.           && !OPS.Default.AreYouSure && !auto)
  1767.           if (!AST.YesNoDialog(ORS.OMA_BRL))
  1768.             return false; // Skips in AutoMode.
  1769.       }
  1770.       return true;
  1771.     }
  1772.  
  1773.     /// <summary> Straight Backup No Merge.
  1774.     /// Split out from BackupLists v4.7.5.24
  1775.     /// June 13 2017
  1776.     /// </summary>
  1777.     /// <param name="data"></param>
  1778.     private static void DontMerge(bool data)
  1779.     {
  1780.       if (data)
  1781.       {
  1782.         PMS.Default.Bac_PrefRootDir  =
  1783.           OPS.Default.PrefRootDir;
  1784.         PMS.Default.Bac_PrefFileName =
  1785.           OPS.Default.PrefFileName;
  1786.       }
  1787.       else
  1788.       {
  1789.         PMS.Default.ReportsFolder =
  1790.           OPS.Default.PrefReportsDir;
  1791.       }
  1792.       PMS.Default.Save();
  1793.     }
  1794.  
  1795.     /// <summary> Display results of Backup
  1796.     /// Works for either List retrofit and
  1797.     /// Split out v4.7.5.24 June 13 2017
  1798.     /// </summary>
  1799.     /// <param name="data"></param>
  1800.     /// <param name="merge"></param>
  1801.     /// <param name="retain"></param>
  1802.     private static void
  1803.       ShowBackupResult(bool data, bool merge, bool retain)
  1804.     {
  1805.       // Skip-All Setting & AutoMode skip Display Msg.
  1806.       var text = ORS.OMA_DLB; // only this var varies.
  1807.       if (!data) text = ORS.OMA_RLB;
  1808.       if (merge)
  1809.       {
  1810.         text = retain
  1811.           // True/False, Left to Right as assignment.
  1812.           ? ORS.OMA_B4 : ORS.OMA_B5;
  1813.         text += "\n\n" + ORS.OMA_B6;
  1814.       }
  1815.       MessageBox.Show(text);
  1816.     }
  1817. #endregion Backup & Backup Specific
  1818.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  1819.  
  1820. #region Restore & Restore Specific
  1821.  
  1822.     /* Early Analysis and Design Notes:
  1823.      *
  1824.      * 1) Which methods from DataList are reUseable?
  1825.      *  a) Houston()
  1826.      *  b) Obviously, YesNoDialog() LoL
  1827.      *  c) HasUniquePath(false, out unique) is it. (false is Reports)
  1828.      *  d) RetainRevert & the RetainRevertCancel Object are very reUsable.
  1829.      *  e) AddUnique() is reUsable with false for reports.
  1830.      *  f) A Reports-Folder-Select thingy exists somewhere in this source code file.
  1831.      *  
  1832.      * 2) Which are not, AND which will be needed? (ie. rewritten for Reports.)
  1833.      *  a) BothHaveBoth can be BothHaveIt() for reports List.
  1834.      *  b) Merger(), RevertPrefs and MergeLists() will all have to be at-least
  1835.      *  edited for ReportsList. Maybe modified to do both or cloned out to it's own method.
  1836.      *  c) A desperate call to SoWhat() may be needed. The else branch of
  1837.      *  the DataList version seems reUsable enough maybe?
  1838.      *  d) SelectRootDir() can be cloned and edited easily enough.
  1839.      *  
  1840.      * 3) Which are not, but will not be needed?
  1841.      *  b) I'm not sure ReCheck() in any form will be needed. Maybe something else?
  1842.      *  
  1843.      * 4) What methods will be completely new in ReportsList?
  1844.      *  a) All of them LOL, they evolved to be 4 function each for backups and restores
  1845.      *  b) and for data and reports. Most go all four ways LoL. v4.7.3.65 May 11 2017
  1846.      *  By:
  1847.      *   John.P.Edwards dba Global Access Software Intl.
  1848.      *   Designed, Produced, Coded, Tested and Developed by -JpE- (C) 2011-2026
  1849.      */
  1850.  
  1851.     private void RestoreDataList(object sender, EventArgs e)
  1852.     {
  1853.       const bool data = true;
  1854.       RestoreLists(data);
  1855.     }
  1856.  
  1857.     private void RestoreReportsList(object sender, EventArgs e)
  1858.     {
  1859.       const bool data = false;
  1860.       RestoreLists(data);
  1861.     }
  1862.  
  1863.     private void RestoreLists(bool data)
  1864.     {
  1865.       // Store & Retrieve PrefRoot, Reports and FileName as well.
  1866.       // Retain members of this list that do not appear in the backup?
  1867.       if (!AskUser2(data)) return;
  1868.       const bool backup = false, auto = false;
  1869.       var merge = false;
  1870.       StringCollection unique;
  1871.       if (HasUniquePath(data, out unique, backup))
  1872.         merge = OPS.Default.MiniVerb
  1873.           || AST.YesNoDialog(ORS.OMA_R1, 1);
  1874.       var what = 0;
  1875.       var both = BothHaveBoth(ref what, data);
  1876.       // if (!both && which == 1 = only in OS, 2 = only in PMS,
  1877.       // 0 = Neither has needed Info.
  1878.       if (!merge && unique.Count > 0)
  1879.       {
  1880.         //  v added v4.7.2.55 May 05
  1881.         var r = AST.YesNoCancel(ORS.OMA_R2, 1);
  1882.         if (r == 3) return;
  1883.         if (r == 1)
  1884.         {
  1885.           DontMerge2(data);
  1886.           what = 2;
  1887.           both = false;
  1888.           unique.Clear();
  1889.         }
  1890.         if (r == 2) merge = true;
  1891.       }
  1892.       var rr = 0; // Retain the Preferred Folders
  1893.       // ...and FileName or revert to backup?
  1894.       if (both && merge) rr = RetainRevert();
  1895.       // ^ returns 1 if retain & 2 if revert, 3 if Cancel.
  1896.       if (rr > 2) return; // Cancel.
  1897.       // Which leaves only 0, 1 & 2 on the table.
  1898.       var retain = rr < 2;// == 1;
  1899.       //  retain = true is retain, false is revert.
  1900.       if (!both)
  1901.       {
  1902.         if (what  < 2) retain = true;
  1903.         if (what == 2) retain = false;
  1904.       }
  1905.       if (what.Equals(0))
  1906.       {
  1907.         if (data) SoWhat();
  1908.         else SoWhatElse();
  1909.       }
  1910.       // All set, let's do it!
  1911.       Merger(retain, unique, backup, data, auto);
  1912.       Changes(data);
  1913.       // And now that it is restored...
  1914.       if (OPS.Default.MiniVerb) return;
  1915.       ShowRestoreResult(data, merge, retain);
  1916.     }
  1917.  
  1918.     private void Changes(bool data)
  1919.     {
  1920.       if (data)
  1921.       {
  1922.         folderBrowser.SelectedPath =
  1923.           OPS.Default.PrefRootDir;
  1924.         DataChanges();
  1925.       }
  1926.       else
  1927.       {
  1928.         folderBrowser.SelectedPath =
  1929.           OPS.Default.PrefReportsDir;
  1930.         ReportsChanges();
  1931.       }
  1932.     }
  1933.  
  1934.     private static void DontMerge2(bool data)
  1935.     {
  1936.       if (data)
  1937.       {
  1938.         OPS.Default.PrefFileName = PMS.Default.Bac_PrefFileName;
  1939.         OPS.Default.PrefRootDir = PMS.Default.Bac_PrefRootDir;
  1940.         OPS.Default.PrefReportsDir = PMS.Default.ReportsFolder;
  1941.       }
  1942.       else
  1943.         OPS.Default.PrefReportsDir = PMS.Default.ReportsFolder;
  1944.     }
  1945.  
  1946.     private static bool AskUser2(bool data)
  1947.     {
  1948.       if (Houston())
  1949.       { // aka We have a problem!
  1950.         MessageBox.Show(ORS.OMA_E1);
  1951.         return false;
  1952.       }
  1953.       var msg = ORS.OMA_RDL;
  1954.       if (!data) msg = ORS.OMA_RRL;
  1955.       if ( !OPS.Default.MiniVerb
  1956.         && !OPS.Default.AreYouSure)
  1957.           if (!AST.YesNoDialog(msg)) return false;
  1958.       return true;
  1959.     }
  1960.  
  1961.     private static void ShowRestoreResult
  1962.       (bool data, bool merge, bool retain)
  1963.     {
  1964.       var text = ORS.OMA_DLR;
  1965.       if (!data) text = ORS.OMA_RLR;
  1966.       if (merge)
  1967.       {
  1968.         text  = retain ? ORS.OMA_R3 : ORS.OMA_R4;
  1969.         text += "\n\n" + ORS.OMA_R5;
  1970.       }
  1971.       MessageBox.Show(text);
  1972.     }
  1973.  
  1974. #endregion Restore & Restore Specific
  1975.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  1976.    
  1977. #endregion v4.7.2.56-65 May 06-11 2017 -=[ THE BIG 2 ]=-
  1978.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  1979.  
  1980.  
  1981. #region Supporting Methods FOR 4 way w/ -=[ THE BIG 2 ]=-
  1982.  
  1983.     // NOTE: retain == true to retain, false to revert.
  1984.     // what == 1 means only in OS, 2 means only in PMS,
  1985.     // (retain defaults to true if what==1, false if what==2)
  1986.     // both == true means Both Have BOTH PrefRootDir & PrefFileName.
  1987.  
  1988.     /// <summary> Quad Function Router for the Big 2 Method Groups:
  1989.     /// BackupDataList, RestoreDataList, BackupReports & RestoreReports.
  1990.     /// Retain and Revert Logic Switched up on Backups and Worded differently
  1991.     /// in the RetainRevert() call. Feature adds full functionality for Lists.
  1992.     /// 4 code paths for backup and data, true or false as illustrated.
  1993.     /// backup true - data true, backup true - data false, backup false - data true,
  1994.     /// and backup false - data false. Are all covered here for the Big 4 Methods.
  1995.     /// And further switched herein by retain. For 8 possible code paths in one here.
  1996.     /// auto is only true if this is an Automatic-Backup of either List.
  1997.     /// v4.7.5.25 Compatible, nothing changed down here, just in the Big 2 above.
  1998.     /// </summary>
  1999.     /// <param name="retain"></param>
  2000.     /// <param name="unique"></param>
  2001.     /// <param name="backup"></param>
  2002.     /// <param name="data"></param>
  2003.     /// <param name="auto"></param>
  2004.     private void Merger(
  2005.       bool retain, StringCollection unique,
  2006.       bool backup, bool data, bool auto)
  2007.     {
  2008.       if (!backup) { if (!retain) RevertPrefs(data); }
  2009.       // if retain we're already set.
  2010.       else
  2011.       { // backup == true
  2012.         if (retain)
  2013.         {
  2014.           if (data)
  2015.           { // DataList, Backup, Retain.
  2016.             PMS.Default.Bac_PrefRootDir  = OPS.Default.PrefRootDir;
  2017.             PMS.Default.Bac_PrefFileName = OPS.Default.PrefFileName;
  2018.           }
  2019.           else PMS.Default.ReportsFolder = OPS.Default.PrefReportsDir; // Rprts.
  2020.         }
  2021.         else
  2022.         { // if (!retain && backup) Revert Backup to Backup Prefs.
  2023.           var c = unique.Count;
  2024.           if (data)
  2025.           { // Data List, Backup, Revert. (True/False v)
  2026.             var dir = c > 0 ? unique[0] : PMS.Default.Bac_PrefRootDir;
  2027.             if (Directory.Exists(dir)) PMS.Default.Bac_PrefRootDir = dir;
  2028.             else if (!auto) SoWhat();
  2029.             var fn  = GetPrefFileName(dir);
  2030.             if (File.Exists(dir + "\\" + fn))
  2031.               PMS.Default.Bac_PrefFileName = fn;
  2032.             else if (!auto) SoWhat();
  2033.           }
  2034.           else
  2035.           { // Reports List Backup, Revert.
  2036.             var dir = c > 0 ? unique[0] : PMS.Default.ReportsFolder;
  2037.             if (Directory.Exists(dir)) PMS.Default.ReportsFolder = dir;
  2038.             else if (!auto) SoWhatElse();
  2039.           }
  2040.         } // Then just flip it on Backups, for best affect. ;-)
  2041.         retain = !retain;
  2042.       }
  2043.       // Now Merge them according to retain, backup & data.
  2044.       if (data) MergeDataLists(retain, unique, backup);
  2045.       else   MergeReportsLists(retain, unique, backup);
  2046.       // ^ Data/Reports Differs here+Backup/Restore ^ differs there.
  2047.     }
  2048.  
  2049.     /// <summary> Runs only from the 2 Restore Tasks.
  2050.     /// Reverts the Current Prefs to the Backup Prefs.
  2051.     /// data == true is Data LIst, false is Reports.
  2052.     /// </summary>
  2053.     /// <param name="data"></param>
  2054.     private void RevertPrefs(bool data)
  2055.     {
  2056.       if (data)
  2057.       {
  2058.         // Use Prefs from PMS.
  2059.         var dir = DataTextBox.Text = WhatWasItB4 =
  2060.           OPS.Default.PrefRootDir  = PMS.Default.Bac_PrefRootDir;
  2061.         var fnp = GetPrefFileName(dir);
  2062.         var rec = GetStoredReportsDirPref(dir);
  2063.         var tea = false;
  2064.         if (!File.Exists(dir + "\\" + fnp)) { SoWhat(); tea = true; }
  2065.         if (!Directory.Exists(rec)) { SoWhatElse(); tea = true; }
  2066.         if (tea) return;// tea time, bye!
  2067.         // ^^^^ I bet flow never gets to either, but Justin Case.
  2068.         OPS.Default.PrefFileName = fnp;
  2069.         ReportsTextBox.Text = OPS.Default.PrefReportsDir = rec;
  2070.       }
  2071.       else
  2072.       {
  2073.         var or = OPS.Default.PrefReportsDir;
  2074.         var pr = PMS.Default.ReportsFolder;
  2075.         if (Directory.Exists(pr)) ReportsTextBox.Text =
  2076.           OPS.Default.PrefReportsDir = WhatWasItB2 = pr;
  2077.         else
  2078.         {
  2079.           if (Directory.Exists(or)) return;
  2080.             SoWhatElse();
  2081.           if (Directory.Exists(OPS.Default.PrefReportsDir)) return;
  2082.           var ok = ReportsTextBox.Text = OPS.Default.PrefReportsDir =
  2083.             OPS.Default.PrefRootDir + "\\" +
  2084.               PMS.Default.Reports;
  2085.           if (!Directory.Exists(ok))
  2086.             Directory.CreateDirectory(ok);
  2087.         }
  2088.       }
  2089.     }
  2090.  
  2091.     /// <summary> if backup == false then it's a Restore Task.
  2092.     /// If Revert, it tacks the diffs on the end, (retain==false)
  2093.     /// if Retain, it puts them up top. NOTE: Reversed for Backups!
  2094.     /// if backup == true then it's a little different logic circuit:
  2095.     /// Retain puts the diffs from backup at the bottom, keeping the Current.
  2096.     /// Revert puts the diffs from backup at the Top of the List.
  2097.     /// Merges the two Data Folder Lists.
  2098.     /// </summary>
  2099.     /// <param name="retain"></param>
  2100.     /// <param name="unique"></param>
  2101.     /// <param name="backup"></param>
  2102.     private static void MergeDataLists
  2103.       (bool retain, IEnumerable unique, bool backup)
  2104.     {
  2105.       if (backup) // We're backing up the Current List.
  2106.       {
  2107.         if (PMS.Default.Bac_dataCollection == null)
  2108.           PMS.Default.Bac_dataCollection = new StringCollection();
  2109.         var _default = OPS.Default.dataListBoxItems[0];
  2110.         PMS.Default.Bac_dataCollection.Clear();
  2111.         PMS.Default.Bac_dataCollection.Add(_default);
  2112.         var enumerable = unique as object[]
  2113.           ?? unique.Cast<object>().ToArray();
  2114.         if (retain) AddUnique(true, enumerable, true);
  2115.         foreach (var dir in OPS.Default
  2116.           .dataListBoxItems.Cast<string>()
  2117.           .Where(Directory.Exists)
  2118.           .Where(dir => !dir.Equals(_default)))
  2119.             PMS.Default.Bac_dataCollection.Add(dir);
  2120.         if (!retain) AddUnique(true, enumerable, true);
  2121.       }
  2122.       else // It's a Restore Task.
  2123.       {
  2124.         // Either way, We will clear and refill the List.
  2125.         // But grab the default and keep it up Top always.
  2126.         if (PMS.Default.Bac_dataCollection == null)
  2127.           PMS.Default.Bac_dataCollection = new StringCollection();
  2128.         var _default = OPS.Default.dataListBoxItems[0];
  2129.         OPS.Default.dataListBoxItems.Clear();
  2130.         OPS.Default.dataListBoxItems.Add(_default);
  2131.         // if Retain, Put the diffs up Top.
  2132.         var enumerable = unique as object[]
  2133.           ?? unique.Cast<object>().ToArray();
  2134.         if (retain) AddUnique(true, enumerable, false);
  2135.         foreach (var dir in PMS.Default
  2136.           .Bac_dataCollection.Cast<string>()
  2137.           .Where(Directory.Exists)
  2138.           .Where(dir => !dir.Equals(_default)))
  2139.             OPS.Default.dataListBoxItems.Add(dir);
  2140.         // Else, Tack diffs on the end.
  2141.         if (!retain) AddUnique(true, enumerable, false);
  2142.       }
  2143.     }
  2144.  
  2145.     /// <summary> if backup == false then it's a Restore Task.
  2146.     /// If Revert, it tacks the diffs on the end, (retain==false)
  2147.     /// if Retain, it puts them up top. NOTE: Reversed for Backups!
  2148.     /// if backup == true then it's a little different logic circuit:
  2149.     /// Retain puts the diffs from backup at the bottom, keeping the Current.
  2150.     /// Revert puts the diffs from backup at the Top of the List.
  2151.     /// Merges the two Reports Folder Lists.
  2152.     /// </summary>
  2153.     /// <param name="retain"></param>
  2154.     /// <param name="unique"></param>
  2155.     /// <param name="backup"></param>
  2156.     private static void MergeReportsLists
  2157.       (bool retain, IEnumerable unique, bool backup)
  2158.     {
  2159.       if (backup) // it's a Backup Task.
  2160.       {
  2161.         if (PMS.Default.Bac_reportsCollection.Equals(null))
  2162.           PMS.Default.Bac_reportsCollection = new StringCollection();
  2163.         var d = OPS.Default.reportsListBoxItems[0];
  2164.         PMS.Default.Bac_reportsCollection.Clear();
  2165.         PMS.Default.Bac_reportsCollection.Add(d);
  2166.         var e = unique as object[]
  2167.           ?? unique.Cast<object>().ToArray();
  2168.         if (retain) AddUnique(false, e, true);
  2169.         foreach (var dir in OPS.Default
  2170.           .reportsListBoxItems.Cast<string>()
  2171.           .Where(Directory.Exists)
  2172.           .Where(dir => !dir.Equals(d)))
  2173.             PMS.Default.Bac_reportsCollection.Add(dir);
  2174.         if (!retain) AddUnique(false, e, true);
  2175.       }
  2176.       else // it's a restore task. (already tested below)
  2177.       {
  2178.         if (PMS.Default.Bac_reportsCollection.Equals(null))
  2179.           PMS.Default.Bac_reportsCollection = new StringCollection();
  2180.         var d = OPS.Default.reportsListBoxItems[0];
  2181.         OPS.Default.reportsListBoxItems.Clear();
  2182.         OPS.Default.reportsListBoxItems.Add(d);
  2183.         var e = unique as object[]
  2184.           ?? unique.Cast<object>().ToArray();
  2185.         if (retain) AddUnique(false, e, false);
  2186.         foreach (var dir in PMS.Default
  2187.           .Bac_reportsCollection.Cast<string>()
  2188.           .Where(Directory.Exists)
  2189.           .Where(dir => !dir.Equals(d)))
  2190.             OPS.Default.reportsListBoxItems.Add(dir);
  2191.         if (!retain) AddUnique(false, e, false);
  2192.       }
  2193.     }
  2194.  
  2195.     /// <summary> Adds the unique paths to the appropriate collection:
  2196.     /// if data == true then it's Data Folders, if false it's Reports.
  2197.     /// if backup == true it's a backup Task, if false it's a Restore Task.
  2198.     /// NOTE: The if (backup) lines and their else makes it quad function.
  2199.     /// </summary>
  2200.     /// <param name="data"></param>
  2201.     /// <param name="unique"></param>
  2202.     /// <param name="backup"></param>
  2203.     private static void AddUnique
  2204.       (bool data, IEnumerable unique, bool backup)
  2205.     {
  2206.       if (data) // Data List.
  2207.       {
  2208.         foreach (var dir in unique.Cast<string>()
  2209.           .Where(dir => Directory.Exists(dir)
  2210.             && HasDataFiles(dir)))
  2211.         {
  2212.           // if added to make universal v4.7.2.58
  2213.           if (backup) PMS.Default.Bac_dataCollection.Add(dir);
  2214.           else OPS.Default.dataListBoxItems.Add(dir);
  2215.         }
  2216.       }
  2217.       else // Reports List.
  2218.       {
  2219.         foreach (var dir in unique.Cast<string>()
  2220.           .Where(Directory.Exists))
  2221.         {
  2222.           // if added to make universal v4.7.2.58
  2223.           if (backup) PMS.Default.Bac_reportsCollection.Add(dir);
  2224.           else OPS.Default.reportsListBoxItems.Add(dir);
  2225.         }
  2226.       }
  2227.     }
  2228.  
  2229.     /// <summary> 1 = only in OS, 2 = only in PMS, 0 = Neither.
  2230.     /// What's up with what: True = Yes, Both. what = 0; in call btw.
  2231.     /// Just Check; that current and backup collections both have;
  2232.     /// both PrefFileName and PrefRootDir. (BothHaveBoth!)
  2233.     /// For Reports (data==false); it Checks if Both Have IT.
  2234.     /// (PrefReportsDir) Same Logic. And Same for Backup & Restore.
  2235.     /// So that doesn't matter here. All 4 of the Big 4 call this method.
  2236.     /// It's results are just interpreted differently during a Backup
  2237.     /// back in the calling methods. No differentiation here for that.
  2238.     /// </summary>
  2239.     /// <param name="what"></param>
  2240.     /// <param name="data"></param>
  2241.     /// <returns></returns>
  2242.     private bool BothHaveBoth(ref int what, bool data)
  2243.     {
  2244.       var result = false;
  2245.       if (!data)
  2246.       {
  2247.         var or = OPS.Default.PrefReportsDir;
  2248.         var pr = PMS.Default.ReportsFolder;
  2249.         var ol = OPS.Default.reportsListBoxItems;
  2250.         var pl = PMS.Default.Bac_reportsCollection;
  2251.  
  2252.         if (Directory.Exists(or) && ol.Contains(or)) what = 1;
  2253.         if (Directory.Exists(pr) && pl.Contains(pr))
  2254.         {
  2255.           if (what == 1) result = true;
  2256.           what = 2;
  2257.         }
  2258.         return result;
  2259.       } // else it is Data...
  2260.       var osF = OPS.Default.PrefFileName;
  2261.       var osR = OPS.Default.PrefRootDir;
  2262.       var psF = PMS.Default.Bac_PrefFileName;
  2263.       var psR = PMS.Default.Bac_PrefRootDir;
  2264.       if (Directory.Exists(osR))
  2265.       { if (File.Exists(osR + "\\" + osF)) what = 1;}
  2266.       if (Directory.Exists(psR))
  2267.       {
  2268.         if (File.Exists(psR + "\\" + psF))
  2269.         {
  2270.           if (what.Equals(1)) result = true;
  2271.           what = 2;
  2272.         }
  2273.       } // If one does not, try to use the pref.lbs before final assessment.
  2274.       if (what == 1) // (2) pms does not. Backup does not. False.
  2275.       { if (ReCheck(false)) result = true; }
  2276.       if (what == 2 && result.Equals(false)) // (1) os does not. True.
  2277.       // Fat chance but I'll cover it anyway. LoL.
  2278.       { if (ReCheck(true))  result = true; }
  2279.       return result;
  2280.     }
  2281.  
  2282.     // os false is re check pms,
  2283.     // os true  is re check os. Hello!!!
  2284.     // (not likely, but covered anyway.)
  2285.     private bool ReCheck(bool ops)
  2286.     {
  2287.       var found1 = false;
  2288.       if (ops) found1 = ReCheckOps();
  2289.       else
  2290.       { // pms
  2291.         var list = PMS.Default.Bac_dataCollection;
  2292.         int count = list.Count,
  2293.             index = 1;
  2294.         if (count < 1) return false;
  2295.         for (; index < count; ++index)
  2296.         {
  2297.           var dir = list[index];
  2298.           var filename = FileName;
  2299.           FileName = "";
  2300.           var file = GetPrefFileName(dir);
  2301.           FileName = filename;
  2302.           var path = PMS.Default.ReportsFolder;
  2303.           PMS.Default.ReportsFolder = "";
  2304.           var repo = GetStoredReportsDirPref(dir);
  2305.           PMS.Default.ReportsFolder = path;
  2306.           if (!Directory.Exists(dir) || !HasDataFiles(dir)
  2307.             || !File.Exists(dir + "\\" + file)
  2308.             || string.IsNullOrEmpty(file)
  2309.             || string.IsNullOrEmpty(repo)) continue;
  2310.  
  2311.           PMS.Default.Bac_PrefFileName  = file;
  2312.           PMS.Default.Bac_PrefRootDir   = dir;
  2313.           found1 = true;
  2314.           if (Directory.Exists(repo))
  2315.             PMS.Default.ReportsFolder   = repo;
  2316.           else
  2317.           {
  2318.             var test = OPS.Default.PrefReportsDir;
  2319.             if (Directory.Exists(test))
  2320.             {
  2321.               PMS.Default.ReportsFolder = test;
  2322.             }
  2323.             else
  2324.             {
  2325.               test = AUS.Default.RootDir;
  2326.               if (Directory.Exists(test))
  2327.                 PMS.Default.ReportsFolder = test;
  2328.               else
  2329.               {
  2330.                 var check = AUS.Default.AppDir +
  2331.                   "\\" + APS.Default.Home +
  2332.                   "\\" + PMS.Default.Reports;
  2333.                 if (Directory.Exists(check))
  2334.                   PMS.Default.ReportsFolder = check;
  2335.                 else found1 = false;
  2336.               }
  2337.             }
  2338.           }
  2339.           break;
  2340.         } // end of For Loop.
  2341.       }
  2342.       return found1;
  2343.     }
  2344.  
  2345.     private bool ReCheckOps()
  2346.     {
  2347.       var found = false;
  2348.       var list  = OPS.Default.dataListBoxItems;
  2349.       var count = list.Count;
  2350.       if (count < 1) return false;
  2351.       var index = 1;
  2352.       for (;index < count; ++index)
  2353.       {
  2354.         var dir  = list[index];
  2355.         var filename = FileName;
  2356.         FileName = "";
  2357.         var file = GetPrefFileName(dir);
  2358.         FileName = filename;
  2359.         var path = OPS.Default.PrefReportsDir;
  2360.         OPS.Default.PrefReportsDir = "";
  2361.         var repo = GetStoredReportsDirPref(dir);
  2362.         OPS.Default.PrefReportsDir = path;
  2363.         if (!Directory.Exists(dir) || !HasDataFiles(dir)
  2364.           || !File.Exists(dir + "\\" + file)
  2365.           || string.IsNullOrEmpty(file)
  2366.           || string.IsNullOrEmpty(repo)) continue;
  2367.  
  2368.         OPS.Default.PrefFileName = file;
  2369.         OPS.Default.PrefRootDir = dir;
  2370.         found = true;
  2371.         if (Directory.Exists(repo))
  2372.           OPS.Default.PrefReportsDir = repo;
  2373.         else
  2374.         {
  2375.           var test = OPS.Default.PrefReportsDir;
  2376.           if (Directory.Exists(test))
  2377.             OPS.Default.PrefReportsDir = test;
  2378.           else
  2379.           {
  2380.             test = AUS.Default.RootDir;
  2381.             if (Directory.Exists(test))
  2382.               OPS.Default.PrefReportsDir = test;
  2383.             else
  2384.             {
  2385.               var check =
  2386.                 AUS.Default.AppDir +
  2387.                 "\\" + APS.Default.Home +
  2388.                 "\\" + PMS.Default.Reports;
  2389.               if (Directory.Exists(check))
  2390.                 OPS.Default.PrefReportsDir = check;
  2391.               else found = false;
  2392.             }
  2393.           }
  2394.         }
  2395.         break;
  2396.       } // end of For Loop.
  2397.       return found;
  2398.     }
  2399.  
  2400.     private void SoWhat()
  2401.     {
  2402.       var x = OPS.Default.dataListBoxItems.Count < 2 ? 0 : 1;
  2403.       var d = OPS.Default.PrefRootDir = OPS.Default.dataListBoxItems[x];
  2404.       // this ^ one has already been tested for Dir.Exists and HasDataFiles.
  2405.       if (string.IsNullOrEmpty(d) // All 3 If Needed <-= v
  2406.         || !Directory.Exists(d)) d = SelectRootDir(); // <-= TestsWell!
  2407.       var f = GetPrefFileName(d);
  2408.       var r = GetStoredReportsDirPref(d);
  2409.       var t = false;
  2410.       if (File.Exists(d + "\\" + f))
  2411.       {
  2412.         t = true; // true testswell, false too.
  2413.         OPS.Default.PrefFileName = f;
  2414.       }
  2415.       if (!t)
  2416.       {
  2417.         var size = AUS.Default.OMA_FileSelect_Size;
  2418.         var location = AUS.Default.OMA_FileSelect_Location;
  2419.         var list = GetDataFileList(d);
  2420.  
  2421.         // v4.7.3.93 index mods
  2422.         var index = 0;
  2423.         var test = GetPrefFileName(OPS.Default.PrefRootDir);
  2424.         if (list.Contains(test))
  2425.           index = list.IndexOf(test);
  2426.         else
  2427.           if (list.Contains(OPS.Default.PrefFileName))
  2428.             index = list.IndexOf(OPS.Default.PrefFileName);
  2429.           else
  2430.             if (list.Contains(PMS.Default.Bac_PrefFileName))
  2431.               index = list.IndexOf(PMS.Default.Bac_PrefFileName);
  2432.             else
  2433.               if (list.Contains(AUS.Default.FileName))
  2434.                 index = list.IndexOf(AUS.Default.FileName);
  2435.               else
  2436.                 if (list.Contains(APS.Default.defaultFilename))
  2437.                   index = list.IndexOf(APS.Default.defaultFilename);
  2438.                 // else default to the index[0] default.
  2439.         // ^ v4.7.3.93 May 30 2017
  2440.         var choice = SelectOne(list, ref size, ref location, "", index); // <-=/\/\/\/\/\
  2441.         AUS.Default.OMA_FileSelect_Size = size;
  2442.         AUS.Default.OMA_FileSelect_Location = location;
  2443.         AUS.Default.Save();
  2444.         if (string.IsNullOrEmpty(choice)) choice = list[index];
  2445.         OPS.Default.PrefFileName = choice;
  2446.       }
  2447.       if (Directory.Exists(r)) OPS.Default.PrefReportsDir = r;
  2448.       else SoWhatElse();
  2449.     }
  2450.  
  2451.     /// <summary> Split out and ReUsed by RestoreReportsList() v4.7.2.51
  2452.     /// This was the else portion of SoWhat() btw. LoL
  2453.     /// Aptly named therefor.
  2454.     /// </summary>
  2455.     private void SoWhatElse()
  2456.     {
  2457.       var list7 = OPS.Default.reportsListBoxItems;
  2458.       var list8 = new Collection<string>();
  2459.       const string title = "Select a Reports Folder:";
  2460.       foreach (var path in list7.Cast<string>()
  2461.         .Where(Directory.Exists)) list8.Add(path);
  2462.  
  2463.       // vvvvvvvvvv v4.7.3.93 May 30 2017
  2464.       var index = 0;
  2465.       var test  = GetStoredReportsDirPref(OPS.Default.PrefRootDir);
  2466.       if (list8.Contains(test)) index = list8.IndexOf(test);
  2467.       else
  2468.         if (list8.Contains(OPS.Default.PrefReportsDir))
  2469.           index = list8.IndexOf(OPS.Default.PrefReportsDir);
  2470.         else
  2471.           if (list8.Contains(PMS.Default.ReportsFolder))
  2472.             index = list8.IndexOf(PMS.Default.ReportsFolder);
  2473.           // else default to the index[0] default.
  2474.       // ^ v4.7.3.93 May 30 2017
  2475.  
  2476.       var size   = AUS.Default.OMA_ReportsSelect_Size;
  2477.       var locate = AUS.Default.OMA_ReportsSelect_Location;
  2478.       var report = SelectOne(list8, ref size, ref locate, title, index); // <-=/\/\/\/\/\
  2479.       AUS.Default.OMA_ReportsSelect_Size = size;
  2480.       AUS.Default.OMA_ReportsSelect_Location = locate;
  2481.       AUS.Default.Save();
  2482.       if (string.IsNullOrEmpty(report)) report = list8[index];
  2483.       OPS.Default.PrefReportsDir = report;
  2484.     }
  2485.  
  2486.     private string SelectRootDir()
  2487.     {
  2488.       var d = AUS.Default.AppDir + "\\" + APS.Default.Home;
  2489.       var c = OPS.Default.dataListBoxItems.Count;
  2490.       if (c == 1) d = OPS.Default.dataListBoxItems[0];
  2491.       if (c < 2) return d;
  2492.       // So, whereever there are two or more.
  2493.       var list = new Collection<string>();
  2494.       foreach (var dir in OPS.Default.dataListBoxItems
  2495.         .Cast<string>().Where(dir => Directory.Exists(dir)
  2496.           && HasDataFiles(dir))) list.Add(dir);
  2497.       if (list.Count < 2) return list.Count == 1 ? list[0] : d;
  2498.  
  2499.       // vvvvvvvvvv v4.7.3.93
  2500.       var index = 0;
  2501.       var test  = OPS.Default.PrefRootDir;
  2502.       if (list.Contains(test))
  2503.         index   = list.IndexOf(test);
  2504.       else
  2505.         if (list.Contains(AUS.Default.RootDir))
  2506.           index = list.IndexOf(AUS.Default.RootDir);
  2507.         else
  2508.           if (list.Contains(PMS.Default.Bac_PrefRootDir))
  2509.             index = list.IndexOf(PMS.Default.Bac_PrefRootDir);
  2510.           // else default to the index[0] default.
  2511.       // ^^^^^ v4.7.3.93 May 30 2017
  2512.  
  2513.  
  2514.       const string title = "Please Select a Data Folder:";
  2515.       var s = AUS.Default.OMA_ReportsSelect_Size;
  2516.       var l = AUS.Default.OMA_ReportsSelect_Location;
  2517.       var a = SelectOne(list, ref s, ref l, title, index); // <<=====<<
  2518.       AUS.Default.OMA_ReportsSelect_Location = l;
  2519.       AUS.Default.OMA_ReportsSelect_Size = s;
  2520.       AUS.Default.Save();
  2521.       if (string.IsNullOrEmpty(a)
  2522.         || !Directory.Exists(a)) a = list[index];
  2523.  
  2524.       return a;
  2525.     }
  2526.  
  2527.     /// <summary> See if the Current List has anything Unique,
  2528.     /// / Not in the Backup. Adds these to the unique Collection.
  2529.     /// bool = true is Data Folders, false is Reports folder lists.
  2530.     /// </summary>
  2531.     /// <param name="data"></param>
  2532.     /// <param name="unique"></param>
  2533.     /// <param name="backup"> </param>
  2534.     /// <returns></returns>
  2535.     private bool HasUniquePath
  2536.       (bool data, out StringCollection unique, bool backup)
  2537.     {
  2538.       CheckPrefs();
  2539.         unique  = new StringCollection();
  2540.       var list1 = OPS.Default.dataListBoxItems;
  2541.       var list2 = PMS.Default.Bac_dataCollection;
  2542.  
  2543.       if (!data) // Defaults ^ to Data, false for Reports Collection.
  2544.       {
  2545.         list1 = OPS.Default.reportsListBoxItems;
  2546.         list2 = PMS.Default.Bac_reportsCollection;
  2547.       }
  2548.  
  2549.       if (backup) // Then just...
  2550.       {
  2551.         foreach (var path in from string path in list2
  2552.           where !list1.Contains(path)
  2553.           where Directory.Exists(path)
  2554.             select path) unique.Add(path);
  2555.       }
  2556.       else // Below Well Tested Restore Mods.
  2557.       {
  2558.         foreach (var path in from string path in list1
  2559.           where !list2.Contains(path)
  2560.           where Directory.Exists(path)
  2561.             select path) unique.Add(path);
  2562.       }
  2563.       return unique.Count > 0;
  2564.     }
  2565.  
  2566.     /// <summary> Check for any Problems
  2567.     /// with the Collections & PrefFileName, etc.
  2568.     /// </summary>
  2569.     /// <returns></returns>
  2570.     private static bool Houston()
  2571.     { // Justin Case it's a WipEd RuN.
  2572.       if (PMS.Default.Bac_dataCollection.Equals(null))
  2573.         PMS.Default.Bac_dataCollection = new StringCollection();
  2574.       if (PMS.Default.Bac_reportsCollection.Equals(null))
  2575.         PMS.Default.Bac_reportsCollection = new StringCollection();
  2576.  
  2577.       return
  2578.            PMS.Default.Bac_dataCollection.Count < 1
  2579.         || PMS.Default.Bac_reportsCollection.Count < 1
  2580.         || string.IsNullOrEmpty(PMS.Default.Bac_PrefFileName)
  2581.         || string.IsNullOrEmpty(PMS.Default.Bac_PrefRootDir)
  2582.         || string.IsNullOrEmpty(PMS.Default.ReportsFolder);
  2583.       // Check for string.nullorempty ^ in which case: show msg.
  2584.     }
  2585.  
  2586.     /// <summary> returns 1 if Retain, 2 if Revert, 3 if Cancel.
  2587.     /// Send it the public Properties LabelText, FormLocation,
  2588.     /// FormForeColor, FormBackColor. LabelText is Optional as
  2589.     /// are the others of course. TestsWell! v4.7.1.38
  2590.     /// </summary>
  2591.     /// <returns></returns>
  2592.     private int RetainRevert()
  2593.     {
  2594.       const string txt = "";
  2595.       return RetainRevert(txt);
  2596.     }
  2597.     private int RetainRevert(string txt)
  2598.     {
  2599.       int chosen;
  2600.       using (var rrc = new RetainRevertCancel())
  2601.       { // ReUsable Custom Class ^ Object Instantiation.
  2602.         rrc.LabelText     = txt; // default if empty.
  2603.         rrc.FormLocation  = AUS.Default.RRC_Location;
  2604.         rrc.FormForeColor = TabForeColor;
  2605.         rrc.FormBackColor = TabBackColor;
  2606.         rrc.ShowDialog(); // <-=/\/\/\/\/\/\/\/\/\/****
  2607.         AUS.Default.RRC_Location = rrc.Location;
  2608.         AUS.Default.Save();
  2609.         chosen = rrc.ButtonClicked;
  2610.       }
  2611.       return chosen;
  2612.     }
  2613. #endregion Supporting Methods for the Big 2 Above.
  2614.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2615.  
  2616.  
  2617. #endregion Context Menu Items
  2618.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2619.  
  2620.  
  2621. #region Upgrade 4.7.0.07 Apr 13 2017
  2622.  
  2623.     /// <summary> Checks for a pref.lbs and gets the pref Reports folder from it.
  2624.     /// Then AddsToPathCollection(path, false) or whatever.
  2625.     ///
  2626.     /// Called only in OptionsFormLoad(); on entry.
  2627.     /// </summary>
  2628.     private void CheckReportsCollection()
  2629.     {
  2630.       var invalid = new List<string>();
  2631.       var missing = new List<string>();
  2632.       foreach (var dataPath in OPS.Default.dataListBoxItems)
  2633.       {
  2634.         if (!Directory.Exists(dataPath)) { invalid.Add(dataPath); continue; }
  2635.         // else...
  2636.         var reports = GetStoredReportsDirPref(dataPath);
  2637.         if (!OPS.Default.reportsListBoxItems.Contains(reports)
  2638.           && Directory.Exists(reports)
  2639.           && !missing.Contains(reports)) { missing.Add(reports); }
  2640.       }   // Last line here ^ should fix dup reports dirs. v4.7.0.05 Apr 13
  2641.       if (missing.Count > 0)
  2642.       {
  2643.         if (AST.YesNoDialog("Add Missing Reports Folders to the Collection?"))
  2644.         {
  2645.           var _default = AUS.Default.AppDir + "\\" +
  2646.             APS.Default.Home + "\\" + PMS.Default.Reports;
  2647.  
  2648.           var count = OPS.Default.reportsListBoxItems.Count;
  2649.           if (count < 2
  2650.             || !OPS.Default.reportsListBoxItems.Contains(_default))
  2651.           {
  2652.             if (OPS.Default.reportsListBoxItems.Contains(_default)
  2653.               && OPS.Default.reportsListBoxItems.IndexOf(_default) > 0)
  2654.             {
  2655.               OPS.Default.reportsListBoxItems.Remove(_default);
  2656.               --count;
  2657.             }
  2658.             if (!OPS.Default.reportsListBoxItems.Contains(_default))
  2659.             {
  2660.               if (count.Equals(0)) OPS.Default.reportsListBoxItems.Add(_default);
  2661.               else OPS.Default.reportsListBoxItems.Insert(0, _default);
  2662.             }
  2663.           }
  2664.           if (missing.Contains(_default)) missing.Remove(_default);
  2665.           foreach (var dir in missing)
  2666.           {
  2667.             OPS.Default.reportsListBoxItems.Add(dir);
  2668.           }
  2669.         }
  2670.       }
  2671.       RemoveInvalidFolders(true, invalid);
  2672.     }
  2673.  
  2674.     /// <summary> Stores everything in OMA Settings Wise on FormLoad.
  2675.     /// so it can be brought back on Cancel/Abort/Red-X.
  2676.     /// </summary>
  2677.     private void SaveInitialSettings()
  2678.     {
  2679.       CreateNewDetectionStrings();
  2680.       // ^ Added v4.7.0.07
  2681.       _data.Clear();
  2682.       foreach (var str in OPS.Default.dataListBoxItems)
  2683.       { _data.Add(str); }
  2684.  
  2685.       _reports.Clear();
  2686.       foreach (var str in OPS.Default.reportsListBoxItems)
  2687.       { _reports.Add(str); }
  2688.  
  2689.       if (!OPS.Default.Schedule1
  2690.         || OPS.Default.Scheduled1 < DateTime.Now.AddYears(-1))
  2691.       { // wipe bugg fixed ^v v4.7.2.44 Apr 29 2017
  2692.         OPS.Default.Schedule1  = true;
  2693.         OPS.Default.Scheduled1 = DateTime.Now;
  2694.         OPS.Default.Save();
  2695.       }
  2696.       _scheduler[0] = OPS.Default.Schedule1;
  2697.       _scheduler[1] = OPS.Default.Schedule3;
  2698.       _scheduler[2] = OPS.Default.Schedule5;
  2699.       if (_scheduler[0]) _scheduled[0] = OPS.Default.Scheduled1;
  2700.       if (_scheduler[1]) _scheduled[1] = OPS.Default.Scheduled3;
  2701.       if (_scheduler[2]) _scheduled[2] = OPS.Default.Scheduled5;
  2702.  
  2703.       CheckPrefs(); // <-= WipeSchedule Bugg Fixed v4.7.2.44
  2704.       // v v4.7.0.07 Scheduler Upgrade Apr 14 2017
  2705.       DayOfWeekCheckBox.Checked = DayOfWeek = OPS.Default.DoW;
  2706.       Change = false;
  2707.     }
  2708.  
  2709.     private void CreateNewDetectionStrings()
  2710.     {
  2711.       Data = OPS.Default.dataListBoxItems.Cast<string>()
  2712.         .Aggregate((current, str) => current + str);
  2713.  
  2714.       Reports = OPS.Default.reportsListBoxItems.Cast<string>()
  2715.         .Aggregate((current, str) => current + str);
  2716.     }
  2717.  
  2718.     /// <summary> Then comes back here from FormClosing for the Below.
  2719.     /// Because of Change == false; above, But only if !ForReal == true;
  2720.     /// If (ForReal == true) then nothing needs to be brought back at-all.
  2721.     /// </summary>
  2722.     private void AbortChanges()
  2723.     {
  2724.       OPS.Default.dataListBoxItems.Clear();
  2725.       foreach (var str in _data)
  2726.       { OPS.Default.dataListBoxItems.Add(str); }
  2727.  
  2728.       OPS.Default.reportsListBoxItems.Clear();
  2729.       foreach (var str in _reports)
  2730.       { OPS.Default.reportsListBoxItems.Add(str); }
  2731.  
  2732.       OPS.Default.Schedule1  = _scheduler[0];
  2733.       OPS.Default.Schedule3  = _scheduler[1];
  2734.       OPS.Default.Schedule5  = _scheduler[2];
  2735.  
  2736.       OPS.Default.Scheduled1 = _scheduled[0];
  2737.       OPS.Default.Scheduled3 = _scheduled[1];
  2738.       OPS.Default.Scheduled5 = _scheduled[2];
  2739.  
  2740.       if (!string.IsNullOrEmpty(PrefFilename))
  2741.         OPS.Default.PrefFileName = PrefFilename;
  2742.       if (!string.IsNullOrEmpty(PrefRootDir))
  2743.         OPS.Default.PrefRootDir  = PrefRootDir;
  2744.       if (!string.IsNullOrEmpty(PrefReports))
  2745.         OPS.Default.PrefReportsDir = PrefReports;
  2746.       OPS.Default.DoW = DayOfWeek;
  2747.       OPS.Default.Save();
  2748.     }
  2749.  
  2750.     /// <summary> returns true if anything changed this run.
  2751.     /// </summary>
  2752.     /// <returns></returns>
  2753.     private bool SettingsChanged()
  2754.     {
  2755.       if (CheckPrefs()) return true;
  2756.       bool
  2757.         s1 = _scheduler[0],
  2758.         s3 = _scheduler[1],
  2759.         s5 = _scheduler[2];
  2760.       DateTime
  2761.         t1 = _scheduled[0],
  2762.         t3 = _scheduled[1],
  2763.         t5 = _scheduled[2];
  2764.       return
  2765.            !s1.Equals(OPS.Default.Schedule1)
  2766.         || !s3.Equals(OPS.Default.Schedule3)
  2767.         || !s5.Equals(OPS.Default.Schedule5)
  2768.         ||  s1 && !t1.Equals(OPS.Default.Scheduled1)
  2769.         ||  s3 && !t3.Equals(OPS.Default.Scheduled3)
  2770.         ||  s5 && !t5.Equals(OPS.Default.Scheduled5)
  2771.         ||   CheckCollections()
  2772.         || !PrefFilename.Equals(OPS.Default.PrefFileName)
  2773.         || !PrefRootDir .Equals(OPS.Default.PrefRootDir)
  2774.         || !PrefReports .Equals(OPS.Default.PrefReportsDir)
  2775.         || !DayOfWeek   .Equals(OPS.Default.DoW);
  2776.     }
  2777.  
  2778.     // Added v4.7.2.44 Apr 29 2017
  2779.     private bool CheckPrefs()
  2780.     {
  2781.       var result = false;
  2782.       if (string.IsNullOrEmpty(PrefFilename))
  2783.       {
  2784.         result = true;
  2785.         var pf = AUS.Default.FileName;
  2786.         if (!string.IsNullOrEmpty(pf)
  2787.           && File.Exists(AUS.Default.RootDir + "\\" + pf))
  2788.           PrefFilename = OPS.Default.PrefFileName = pf;
  2789.         else
  2790.           PrefFilename = OPS.Default.PrefFileName =
  2791.             APS.Default.defaultFilename;
  2792.       }
  2793.       if (string.IsNullOrEmpty(PrefRootDir))
  2794.       {
  2795.         result = true;
  2796.         var pr = AUS.Default.RootDir;
  2797.         if (!string.IsNullOrEmpty(pr)
  2798.           && Directory.Exists(pr))
  2799.             PrefRootDir = OPS.Default.PrefRootDir = pr;
  2800.         else
  2801.           PrefRootDir = OPS.Default.PrefRootDir =
  2802.             AUS.Default.AppDir + "\\" + APS.Default.Home;
  2803.       }
  2804.       if (string.IsNullOrEmpty(PrefReports))
  2805.       {
  2806.         result = true;
  2807.         var rp = PMS.Default.ReportsFolder;
  2808.         if (!string.IsNullOrEmpty(rp)
  2809.           && Directory.Exists(rp))
  2810.             PrefReports = OPS.Default.PrefReportsDir = rp;
  2811.         else
  2812.           PrefReports = OPS.Default.PrefReportsDir =
  2813.             AUS.Default.AppDir + "\\" + APS.Default.Home +
  2814.             "\\" + PMS.Default.Reports;
  2815.       }
  2816.       if (PMS.Default.Bac_dataCollection.Equals(null))
  2817.       {
  2818.         result = true;
  2819.         PMS.Default.Bac_dataCollection = new StringCollection();
  2820.       }
  2821.       if (PMS.Default.Bac_reportsCollection.Equals(null))
  2822.       {
  2823.         result = true;
  2824.         PMS.Default.Bac_reportsCollection = new StringCollection();
  2825.       }
  2826.       if (result) OPS.Default.Save();
  2827.  
  2828.       return result;
  2829.     }
  2830.  
  2831.     // ^v Both Return true if anything has changed.
  2832.     private bool CheckCollections()
  2833.     {
  2834.       var line1 = Data;
  2835.       var line2 = Reports;
  2836.       CreateNewDetectionStrings();
  2837.       return !line1.Equals(Data) || !line2.Equals(Reports);
  2838.     }
  2839. #endregion Upgrade 4.7.0.07 Apr 13 2017
  2840.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2841.  
  2842.  
  2843. #endregion Alternate Folder Finder
  2844.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  2845.  
  2846.  
  2847.   }
  2848. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement