Advertisement
GlobalAccessSoftware

Encrypt Decrypt Context Menu

Jun 7th, 2021 (edited)
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.06 KB | None | 0 0
  1.  
  2. #region Top Part
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // EncryptDecryptContext.cs  v6.9.9.92
  5. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  6. // Extended Class Visible To All 3 Apps.
  7. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  8. // v6.9.9.92 20210416213021 Context Menu
  9. // Items Split Out and EnDecrypt Begun.
  10. // v6.9.9.93 202104202306 MoreOver Context.
  11. // v6.9.9.93b 0426020112 Isolated Detailing.
  12. // v6.9.9.94 202104280033 Additional Items
  13. // added to Context Menu and Developed out.
  14. // v6.9.9.94b 20210503045146 Wrapup & polish
  15. // v6.9.9.95 20210529005228 Reenvisioned!!!
  16. // v6.9.9.96 202106020121 MultiMove Stickler
  17. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  18.  
  19. using System;
  20. using System.Collections;
  21. using System.Collections.Generic;
  22. using System.Collections.Specialized;
  23. using System.IO;
  24. using System.Linq;
  25. using System.Threading;
  26. using System.Windows.Forms;
  27.  
  28. using MCC = MyCustomControls.CustomControl;
  29. using MCD = MyCustomLibrary.Dialogs;
  30. using MCT = MyCustomLibrary.MyToolbox;
  31. using SMF = ShowMe.ShowMeForm;
  32.  
  33. using SPR = ShowMe.Properties.Resources;
  34. using SPS = ShowMe.Properties.Settings;
  35.  
  36. #endregion Pop Tart
  37.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  38.  
  39.  
  40. namespace ShowMe
  41. {
  42.   public partial class EncryptDecrypt
  43.   {
  44. #region Active Form members
  45.  
  46.     /* DOC: Relationship of Method Groups
  47.      * =====================================
  48.      * Form Buttons are clickEvents, but the
  49.      * CheckBoxes use CheckChanged Events;  
  50.      * Giving those this-^-Event would then
  51.      * cause stack overflow errors and Hang.
  52.      *
  53.      * So, those toolstrip items cannot use
  54.      * that mechanism. They instead, are now
  55.      * 'Click' Events. They flip the switch
  56.      * and let it's CheckChanged Event do
  57.      * the rest. These merely change those
  58.      * values and no such event is required.
  59.      * =====================================
  60.      */
  61.  
  62.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  63.     // Connected to Save for New Files To
  64.     // Encrypt Automagically if Auto = true.
  65.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  66.  
  67.     // PROPERTIES:
  68.     public static bool AutoEncrypt
  69.     {
  70.       get { return Auto;  }
  71.       set { Auto = value; }
  72.     }
  73.     static bool Auto
  74.     {
  75.       get
  76.       {
  77.         return
  78.           SPS.Default.AutoCheckBoxChecked;
  79.       }
  80.       set
  81.       {
  82.         SPS.Default
  83.           .AutoCheckBoxChecked = value;
  84.         SPS.Default.Save();
  85.       }
  86.     }
  87.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  88.    
  89.  
  90.     // CheckBox.CheckChanged EVENTHANDLERS:
  91.     void AutoEncryptCheckedChanged(
  92.       object sender, EventArgs e)
  93.     {
  94.       // Gets saved at the property setter.
  95.       Auto =
  96.         autoEncryptItem.Checked =
  97.         autoEncryptCheckBox.Checked;
  98.     }
  99.  
  100.     /* This just toggles it...
  101.      * back to what it wasn't. And the
  102.      * condition gets used to branch in
  103.      * the SetupListBox1Text() method.
  104.      *
  105.      * If fullPathCheckBox.Checked = checked
  106.      * it only shows the filename. If not
  107.      * checked it goes back to the FullPath.
  108.      * So don't forget that the fullpath is
  109.      * always in that Indice of FileList[g]
  110.      * global. Then just use the CheckBox or
  111.      * Setting to feel it. Etc.
  112.      *
  113.      */
  114.     void FullPath(
  115.       object sender, EventArgs e)
  116.     {
  117.       GetSelectedNames();
  118.       var cb = sender as CheckBox;
  119.       if (cb == null) return;
  120.       SPS.Default
  121.         .FileNameChckBxChckd =
  122.         fileNameItem.Checked =
  123.           cb.Checked;
  124.       SPS.Default.Save();
  125.       SetupListView1();
  126.     }
  127.  
  128.     void StayOnTopCheckedChanged(
  129.       object sender, EventArgs e)
  130.     {
  131.       TopMost =
  132.         SPS.Default.TopMost =
  133.         stayOnTopItem.Checked =
  134.           stayOnTopCheckBox.Checked;
  135.       SPS.Default.Save();
  136.     }
  137. #endregion Active Form members
  138.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  139.  
  140.  
  141. #region ToolStrip MenuItem Settings
  142.  
  143.     /* DOC: Relationship of Method Groups
  144.      * =====================================
  145.      * Form Buttons are clickEvents, but the
  146.      * CheckBoxes ^ use CheckChanged Events;  
  147.      * Giving these that ^ Event would then
  148.      * cause stack overflow errors and Hang.
  149.      *
  150.      * So, these toolstrip items cannot use
  151.      * that mechanism. They instead, are now
  152.      * 'Click' Events. These flip the switch
  153.      * and lets it's CheckChanged Event do
  154.      * the rest. Those ^ merely change these
  155.      * values and no such event is required.
  156.      * =====================================
  157.      */
  158.  
  159.     void SortPrefClicked(
  160.       object sender, EventArgs e)
  161.     {
  162.       GetSelectedNames();
  163.       var toolStripMenuItem =
  164.         sender as ToolStripMenuItem;
  165.       if (toolStripMenuItem ==
  166.           null) return;
  167.  
  168.       sortFileListItem.Checked =
  169.         toolStripMenuItem.Checked;
  170.  
  171.       SetupListView1();
  172.     }
  173.  
  174.     void AutoEncryptItemClicked(
  175.       object sender, EventArgs e)
  176.     {
  177.       autoEncryptCheckBox.Checked =
  178.         autoEncryptItem.Checked;
  179.     }
  180.  
  181.     void FullPathItemClicked(
  182.       object sender, EventArgs e)
  183.     {
  184.       fileNameCheckBox.Checked =
  185.         fileNameItem.Checked;
  186.     }
  187.  
  188.     void StayOnTopItemClicked(
  189.       object sender, EventArgs e)
  190.     {
  191.       stayOnTopCheckBox.Checked =
  192.         stayOnTopItem.Checked;
  193.     }
  194. #endregion ToolStripMenu Item Settings
  195.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  196.  
  197.  
  198. #region Context Menu Items
  199.  
  200.     void AddFilesButton(
  201.       object sender, EventArgs e)
  202.     {
  203.       OpenFileDialog o;
  204.       listView1.SelectedIndices.Clear();
  205.       using (var c = new MCC())
  206.       { o = c.O1; } // My Custom OFD
  207.  
  208.       o.FileName = "";
  209.       o.Filter = SPR.OdFilter;
  210.       o.FilterIndex = 2;
  211.       o.InitialDirectory =
  212.         Environment.GetFolderPath(
  213.         Environment.SpecialFolder
  214.         .MyDocuments);
  215.       o.Title = SPR.MyAdHd;
  216.  
  217.       var rslt = o.ShowDialog(); // <=====<<
  218.  
  219.       var files = o.FileNames;
  220.       o.Dispose();
  221.  
  222.       if (rslt != DialogResult.OK) return;
  223.  
  224.       AddFiles(files);
  225.  
  226.       // v6.9.9.95 mods 20210603
  227.       foreach(var file in files.Where(file=>
  228.         !SPS.Default.Selected.Contains(file)
  229.         ))
  230.         SPS.Default.Selected.Add(file);
  231.  
  232.       SPS.Default.Save();
  233.       SetupListView1();
  234.     }
  235.  
  236.     void AddFiles(IEnumerable files)
  237.     {
  238.       if (listView1.InvokeRequired)
  239.         Invoke(new Invoker12(
  240.           AddFiles2), (object) files);
  241.       else
  242.         AddFiles2(files);
  243.     }
  244.     /// <summary> Doc
  245.     /// For Thread and Process Safety
  246.     /// while in Debug mode. It doesn't
  247.     /// trigger when the Debugger is
  248.     /// NOT Attached to the Process.
  249.     /// </summary>
  250.     /// <param name="o"></param>
  251.     delegate void Invoker12(object o);
  252.  
  253.     void AddFiles2(object strArr)
  254.     {
  255.       var arr = strArr as string[];
  256.       if (arr == null ||
  257.           arr.Length < 1) return;
  258.  
  259.       foreach (var str in arr
  260.         .Where(str => !string
  261.           .IsNullOrEmpty(str) &&
  262.           File.Exists(str)    &&
  263.           // new line to check for dups.
  264.           !FileList.Contains(str))
  265.           )
  266.           FileList.Add(str);
  267.     }
  268.  
  269.     void RemoveFileNames(
  270.       object sender, EventArgs e)
  271.     {
  272.       if (listView1 == null || listView1
  273.         .SelectedItems.Count < 1
  274.         || !MCD.YesNoDialog(SPR.RmvTxt)
  275.         )
  276.         return;
  277.  
  278.       // Remove bottomUp avoid offsetting ea
  279.       var t = listView1.SelectedIndices;
  280.       var c = listView1.SelectedIndices.Count;
  281.       for (var f = c-1; f >= 0; --f)
  282.       {
  283.         var z = t[f];
  284.         listView1.Items.RemoveAt(z);
  285.         FileList.RemoveAt(z);
  286.       }
  287.       SetupListView1();
  288.     }
  289.  
  290.     void ViewTheseItems(
  291.       object sender, EventArgs e)
  292.     {
  293.       if (listView1.SelectedItems.Count < 1
  294.         || !MCD.YesNoDialog(SPR.VewTxt)
  295.         ) return;
  296.  
  297.       var ins = listView1.SelectedIndices;
  298.       var c = ins.Count;
  299.       var strs = new string[c];
  300.       for (var n = c-1; n >= 0; --n)
  301.         strs[n] = FileList[ins[n]];
  302.  
  303.       foreach (var str in strs)
  304.       {
  305.         Thread.Sleep(200);
  306.         MCT.RunApp(str,
  307.           SPR.PrevFile + str,
  308.            MCT.GetRoot + SPR.Sme);
  309.       }
  310.     }
  311.  
  312.     void SkipAySItemClicked(
  313.       object sender, EventArgs e)
  314.     {
  315.       MCT.Skip = skipAyS.Checked;
  316.     }
  317. #endregion Context Menu Items
  318.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  319.  
  320.  
  321. #region Move Item(s)
  322.    
  323.     // newer v6.9.9.95 20210603
  324.     // See also ReSelectItems() and also
  325.     // GetNewIndices(); as well, sorta.
  326.     // which, this scheme, all tie into
  327.     // our SetupListView1(); method.
  328.     void GetSelectedNames()
  329.     {
  330.       var n = listView1.SelectedItems.Count;
  331.       if (n < 1) return;
  332.  
  333.       var k = new int[n];
  334.       listView1.SelectedIndices.CopyTo(k,0);
  335.  
  336.       SPS.Default.Selected =
  337.         new StringCollection();
  338.  
  339.       for (var i = 0; i < n; ++i)
  340.         SPS.Default.Selected.Add(
  341.           FileList[k[i]]);
  342.  
  343.       SPS.Default.Save();
  344.     }
  345.  
  346.     // works great EVEN with roll over
  347.     // or roll under and multiSelected!
  348.     // v6.9.9.96 20210606024314 ModZ!!
  349.     List<int> GetNewIndicas(int m)
  350.     {
  351.       var l = new List<int>();
  352.       var x = FileList.Count -1;
  353.       var c = listView1.SelectedItems.Count;
  354.  
  355.       for (var n = 0; n < c; ++n)
  356.       {
  357.         var i =listView1.SelectedIndices[n];
  358.         if (i.Equals(null)) continue;
  359.  
  360.         var k = i + m;  
  361.         if (k < 0) k = x;// make 1st last
  362.         if (k > x) k = 0;// make last 1st
  363.  
  364.         l.Add(k);
  365.       }
  366.       return l;
  367.     }
  368.  
  369.     // if Up then subtract 1 from the
  370.     // indice, if it's Down then add 1
  371.     // to the indice to move it.
  372.     void MoveItemsClicked(
  373.       object sender, EventArgs e)
  374.     {
  375.       var b = sender as ToolStripMenuItem;
  376.       if (b == null || (sortFileListItem
  377.         .Checked && !Flip())) return;
  378.  
  379.       GetSelectedNames();
  380.       var m = b.Text.Contains("Up")? -1:1;
  381.       var l = GetNewIndicas(m);
  382.  
  383.       MoveItems(m, l);
  384.       SetupListView1();
  385.     }
  386.    
  387.     void MoveItems(int m, IList<int> l)
  388.     {
  389.       var t = new string[
  390.         FileList.Count];
  391.       FileList.CopyTo(t,0);
  392.  
  393.       var c = l.Count -1;
  394.       if (m < 0)
  395.         for (var i = 0; i <= c; ++i)
  396.           ItemMoveLoop(l,i,t); // UP
  397.       else
  398.         for (var i = c; i >= 0; --i)
  399.           ItemMoveLoop(l,i,t); // Down
  400.     }
  401.  
  402.     void ItemMoveLoop(IList<int> l,
  403.       int i, IList<string> filelist2)
  404.     {
  405.       var t = l[i];
  406.       var f = FileList.Count;
  407.       if (f < 2||t < 0||t >= f) return;
  408.  
  409.       var n = filelist2[ listView1
  410.         .SelectedIndices[i] ];
  411.  
  412.       FileList.Remove(n);
  413.       FileList.Insert(t, n);
  414.     }
  415.  
  416.     bool Flip()
  417.     {
  418.       var rslt =
  419.         MessageBox.Show(
  420.           SPR.FlipTxt, SPR.FlipTtl,
  421.           MessageBoxButtons.OKCancel,
  422.           MessageBoxIcon.Question,
  423.           MessageBoxDefaultButton.Button1)
  424.          
  425.           == DialogResult.OK;
  426.  
  427.       if (!rslt) return false;
  428.  
  429.       sortFileListItem.Checked =
  430.         SPS.Default.Sort = false;
  431.       SPS.Default.Save();
  432.  
  433.       return true;
  434.     }
  435. #endregion Move Item(s)
  436.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  437.  
  438.  
  439.   }
  440. }
  441.  
  442. // 100% -JpE-
  443.  
  444.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement