Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Top Part
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // EncryptDecryptContext.cs v6.9.9.92
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // Extended Class Visible To All 3 Apps.
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // v6.9.9.92 20210416213021 Context Menu
- // Items Split Out and EnDecrypt Begun.
- // v6.9.9.93 202104202306 MoreOver Context.
- // v6.9.9.93b 0426020112 Isolated Detailing.
- // v6.9.9.94 202104280033 Additional Items
- // added to Context Menu and Developed out.
- // v6.9.9.94b 20210503045146 Wrapup & polish
- // v6.9.9.95 20210529005228 Reenvisioned!!!
- // v6.9.9.96 202106020121 MultiMove Stickler
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Windows.Forms;
- using MCC = MyCustomControls.CustomControl;
- using MCD = MyCustomLibrary.Dialogs;
- using MCT = MyCustomLibrary.MyToolbox;
- using SMF = ShowMe.ShowMeForm;
- using SPR = ShowMe.Properties.Resources;
- using SPS = ShowMe.Properties.Settings;
- #endregion Pop Tart
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- namespace ShowMe
- {
- public partial class EncryptDecrypt
- {
- #region Active Form members
- /* DOC: Relationship of Method Groups
- * =====================================
- * Form Buttons are clickEvents, but the
- * CheckBoxes use CheckChanged Events;
- * Giving those this-^-Event would then
- * cause stack overflow errors and Hang.
- *
- * So, those toolstrip items cannot use
- * that mechanism. They instead, are now
- * 'Click' Events. They flip the switch
- * and let it's CheckChanged Event do
- * the rest. These merely change those
- * values and no such event is required.
- * =====================================
- */
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // Connected to Save for New Files To
- // Encrypt Automagically if Auto = true.
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // PROPERTIES:
- public static bool AutoEncrypt
- {
- get { return Auto; }
- set { Auto = value; }
- }
- static bool Auto
- {
- get
- {
- return
- SPS.Default.AutoCheckBoxChecked;
- }
- set
- {
- SPS.Default
- .AutoCheckBoxChecked = value;
- SPS.Default.Save();
- }
- }
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // CheckBox.CheckChanged EVENTHANDLERS:
- void AutoEncryptCheckedChanged(
- object sender, EventArgs e)
- {
- // Gets saved at the property setter.
- Auto =
- autoEncryptItem.Checked =
- autoEncryptCheckBox.Checked;
- }
- /* This just toggles it...
- * back to what it wasn't. And the
- * condition gets used to branch in
- * the SetupListBox1Text() method.
- *
- * If fullPathCheckBox.Checked = checked
- * it only shows the filename. If not
- * checked it goes back to the FullPath.
- * So don't forget that the fullpath is
- * always in that Indice of FileList[g]
- * global. Then just use the CheckBox or
- * Setting to feel it. Etc.
- *
- */
- void FullPath(
- object sender, EventArgs e)
- {
- GetSelectedNames();
- var cb = sender as CheckBox;
- if (cb == null) return;
- SPS.Default
- .FileNameChckBxChckd =
- fileNameItem.Checked =
- cb.Checked;
- SPS.Default.Save();
- SetupListView1();
- }
- void StayOnTopCheckedChanged(
- object sender, EventArgs e)
- {
- TopMost =
- SPS.Default.TopMost =
- stayOnTopItem.Checked =
- stayOnTopCheckBox.Checked;
- SPS.Default.Save();
- }
- #endregion Active Form members
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region ToolStrip MenuItem Settings
- /* DOC: Relationship of Method Groups
- * =====================================
- * Form Buttons are clickEvents, but the
- * CheckBoxes ^ use CheckChanged Events;
- * Giving these that ^ Event would then
- * cause stack overflow errors and Hang.
- *
- * So, these toolstrip items cannot use
- * that mechanism. They instead, are now
- * 'Click' Events. These flip the switch
- * and lets it's CheckChanged Event do
- * the rest. Those ^ merely change these
- * values and no such event is required.
- * =====================================
- */
- void SortPrefClicked(
- object sender, EventArgs e)
- {
- GetSelectedNames();
- var toolStripMenuItem =
- sender as ToolStripMenuItem;
- if (toolStripMenuItem ==
- null) return;
- sortFileListItem.Checked =
- toolStripMenuItem.Checked;
- SetupListView1();
- }
- void AutoEncryptItemClicked(
- object sender, EventArgs e)
- {
- autoEncryptCheckBox.Checked =
- autoEncryptItem.Checked;
- }
- void FullPathItemClicked(
- object sender, EventArgs e)
- {
- fileNameCheckBox.Checked =
- fileNameItem.Checked;
- }
- void StayOnTopItemClicked(
- object sender, EventArgs e)
- {
- stayOnTopCheckBox.Checked =
- stayOnTopItem.Checked;
- }
- #endregion ToolStripMenu Item Settings
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region Context Menu Items
- void AddFilesButton(
- object sender, EventArgs e)
- {
- OpenFileDialog o;
- listView1.SelectedIndices.Clear();
- using (var c = new MCC())
- { o = c.O1; } // My Custom OFD
- o.FileName = "";
- o.Filter = SPR.OdFilter;
- o.FilterIndex = 2;
- o.InitialDirectory =
- Environment.GetFolderPath(
- Environment.SpecialFolder
- .MyDocuments);
- o.Title = SPR.MyAdHd;
- var rslt = o.ShowDialog(); // <=====<<
- var files = o.FileNames;
- o.Dispose();
- if (rslt != DialogResult.OK) return;
- AddFiles(files);
- // v6.9.9.95 mods 20210603
- foreach(var file in files.Where(file=>
- !SPS.Default.Selected.Contains(file)
- ))
- SPS.Default.Selected.Add(file);
- SPS.Default.Save();
- SetupListView1();
- }
- void AddFiles(IEnumerable files)
- {
- if (listView1.InvokeRequired)
- Invoke(new Invoker12(
- AddFiles2), (object) files);
- else
- AddFiles2(files);
- }
- /// <summary> Doc
- /// For Thread and Process Safety
- /// while in Debug mode. It doesn't
- /// trigger when the Debugger is
- /// NOT Attached to the Process.
- /// </summary>
- /// <param name="o"></param>
- delegate void Invoker12(object o);
- void AddFiles2(object strArr)
- {
- var arr = strArr as string[];
- if (arr == null ||
- arr.Length < 1) return;
- foreach (var str in arr
- .Where(str => !string
- .IsNullOrEmpty(str) &&
- File.Exists(str) &&
- // new line to check for dups.
- !FileList.Contains(str))
- )
- FileList.Add(str);
- }
- void RemoveFileNames(
- object sender, EventArgs e)
- {
- if (listView1 == null || listView1
- .SelectedItems.Count < 1
- || !MCD.YesNoDialog(SPR.RmvTxt)
- )
- return;
- // Remove bottomUp avoid offsetting ea
- var t = listView1.SelectedIndices;
- var c = listView1.SelectedIndices.Count;
- for (var f = c-1; f >= 0; --f)
- {
- var z = t[f];
- listView1.Items.RemoveAt(z);
- FileList.RemoveAt(z);
- }
- SetupListView1();
- }
- void ViewTheseItems(
- object sender, EventArgs e)
- {
- if (listView1.SelectedItems.Count < 1
- || !MCD.YesNoDialog(SPR.VewTxt)
- ) return;
- var ins = listView1.SelectedIndices;
- var c = ins.Count;
- var strs = new string[c];
- for (var n = c-1; n >= 0; --n)
- strs[n] = FileList[ins[n]];
- foreach (var str in strs)
- {
- Thread.Sleep(200);
- MCT.RunApp(str,
- SPR.PrevFile + str,
- MCT.GetRoot + SPR.Sme);
- }
- }
- void SkipAySItemClicked(
- object sender, EventArgs e)
- {
- MCT.Skip = skipAyS.Checked;
- }
- #endregion Context Menu Items
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region Move Item(s)
- // newer v6.9.9.95 20210603
- // See also ReSelectItems() and also
- // GetNewIndices(); as well, sorta.
- // which, this scheme, all tie into
- // our SetupListView1(); method.
- void GetSelectedNames()
- {
- var n = listView1.SelectedItems.Count;
- if (n < 1) return;
- var k = new int[n];
- listView1.SelectedIndices.CopyTo(k,0);
- SPS.Default.Selected =
- new StringCollection();
- for (var i = 0; i < n; ++i)
- SPS.Default.Selected.Add(
- FileList[k[i]]);
- SPS.Default.Save();
- }
- // works great EVEN with roll over
- // or roll under and multiSelected!
- // v6.9.9.96 20210606024314 ModZ!!
- List<int> GetNewIndicas(int m)
- {
- var l = new List<int>();
- var x = FileList.Count -1;
- var c = listView1.SelectedItems.Count;
- for (var n = 0; n < c; ++n)
- {
- var i =listView1.SelectedIndices[n];
- if (i.Equals(null)) continue;
- var k = i + m;
- if (k < 0) k = x;// make 1st last
- if (k > x) k = 0;// make last 1st
- l.Add(k);
- }
- return l;
- }
- // if Up then subtract 1 from the
- // indice, if it's Down then add 1
- // to the indice to move it.
- void MoveItemsClicked(
- object sender, EventArgs e)
- {
- var b = sender as ToolStripMenuItem;
- if (b == null || (sortFileListItem
- .Checked && !Flip())) return;
- GetSelectedNames();
- var m = b.Text.Contains("Up")? -1:1;
- var l = GetNewIndicas(m);
- MoveItems(m, l);
- SetupListView1();
- }
- void MoveItems(int m, IList<int> l)
- {
- var t = new string[
- FileList.Count];
- FileList.CopyTo(t,0);
- var c = l.Count -1;
- if (m < 0)
- for (var i = 0; i <= c; ++i)
- ItemMoveLoop(l,i,t); // UP
- else
- for (var i = c; i >= 0; --i)
- ItemMoveLoop(l,i,t); // Down
- }
- void ItemMoveLoop(IList<int> l,
- int i, IList<string> filelist2)
- {
- var t = l[i];
- var f = FileList.Count;
- if (f < 2||t < 0||t >= f) return;
- var n = filelist2[ listView1
- .SelectedIndices[i] ];
- FileList.Remove(n);
- FileList.Insert(t, n);
- }
- bool Flip()
- {
- var rslt =
- MessageBox.Show(
- SPR.FlipTxt, SPR.FlipTtl,
- MessageBoxButtons.OKCancel,
- MessageBoxIcon.Question,
- MessageBoxDefaultButton.Button1)
- == DialogResult.OK;
- if (!rslt) return false;
- sortFileListItem.Checked =
- SPS.Default.Sort = false;
- SPS.Default.Save();
- return true;
- }
- #endregion Move Item(s)
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- }
- }
- // 100% -JpE-
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement