Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Top Part
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
- // Smesa.cs v1.0.1.00 02-Oct-2017
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
- // Created by Jp Edwards as Shareware
- // and as a Fresher Course in Windows
- // Forms Apps, OOP and C#.NET
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
- // This is an Early Version meant to
- // inspire freshers to dive right in
- // and away from mere console Apps, etc.
- // I've left many many things for you to
- // code and experiment with. Just beware
- // of the standard license and rights.
- // i.e. Share your improvements!
- // Ask questions, Collaborate!
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
- // v1.0.1.02 02-Oct-17 @ 0455
- // v1.0.1.03 03-Oct-17 @ 0643
- // v1.0.1.05 07-Oct-17 @ 0000 RC1
- // v1.0.1.09 11-Oct-17 @ 0505 RC2b
- // v1.0.1.16 23-Oct-17 @ 1220 BRC1
- // v1.0.1.20 28-Oct-17 @ 2231 ReDesigns
- // v1.0.2.21 29-Oct-17 @ 0116 ReDesigns
- // v1.0.2.25 12-Nov-17 @ 0130 Stabilize.
- // v1.0.3.26 25-Nov-17 @ 2344 Perfected.
- // v1.1.4.26 10-Dec-17 Newest Mods & Ver
- // Ready for complete Isolation
- // v2.2.5.26zz 28-Dec-2017 Set to fully
- // pound on Rev2. Mods are in Tests are
- // going well, but a few last things to
- // resolve before I can truly call it 27
- // v2.2.6.27agate 07-Jan-2018 Minor Rev.
- // Fully Working with Multi-Tab and
- // ready for Serious Beta-Testing and
- // further modification & enhancements.
- // v2.3.6.27alaru 10-Dec-18 Behavior.
- // v2.3.7.28alfy 22-Jan-18 Integration
- // and major mods here and there for
- // Multi-Tab. Then, BAM! WOW!
- // v2.3.8.29algor 24-Jan-18 Multiple
- // fixes and upgrades, evolved in testin
- // and is the best I've seen so far!
- // v2.5.9.30 04-Feb-2018 Multi-Load and
- // Multi-Load-WHILE-RUNNING mods finish!
- // v2.5.9.31 08-Feb-2018 MultiLoad Mods!
- // v2.6.1.32 20-Feb-2018 0145 Threading.
- // v2.6.1.33 22-Feb-2018 MMF & Trigger.
- // v3.0.0.01 25-feb-2018 As WPF App.
- // Experimental to pass args to an
- // active 1st instance Smesa from a
- // 2nd Instance AppLaunch2 MyOtherApp.
- // v3.0.0.36 28-Feb-2018 0420 MyApp WPF
- // v3.0.1.37 01-Mar-2018 Reverted Hybrid
- // v3.1.1.39 10-Mar-2018 Fully Working++
- // v3.2.3.43 28-Mar-2018 Preferences2+
- // v3.2.3.43 29-Mar-2018 GetCharCount();
- // v4.3.5.49 22-Apr-2018 Integrated.
- // v4.5.7.59 05-Jul-2018 MyToolbox
- // v4.5.8.60 18-Jul-18 Shared Info!
- // v4.5.8.60 23-Jul-18 FULLY TESTED!
- // v4.5.8.60 26-Jul 4 Hooks 4 Shared.sme
- // Search usages of WriteSharedData();
- // v4.5.8.61 30-Jul-2018 ^ Perfecting.
- // v4.5.8.61 03-Aug Integration w/ Shared.sme
- // v4.5.9.63 Omega Plan 11-Aug-2018
- // v4.5.9.63 15-Aug-2018 Complete & TestsWell.
- // v4.5.9.64 21-Aug Fixed and finalized
- // v4.6.9.65 To Keep Smesa simple: (Kiss mods)
- // v4.6.9.66 05-Sep WriteShared Mods.
- // v4.6.9.68 10-Sep-2018 Final Wipe Testing.
- // v4.6.9.69 17- " " Perfected PathPb
- // v4.7.0.70 18-" " Assy Thread Safe / IO Safe.
- // v4.7.0.71 19-Sep About Colors.
- // v4.7.0.72 21-Sep-2018 RC
- // v4.8.0.76 30-Sep MCT.SaveList & GetList mods
- // v4.8.2.82 26-Oct-2018 Wrap Mod integration.
- // v4.9.3.88 16-Nov-2018 Removals / Favorites.
- // v4.9.4.89 Fellback to 49488G01RC but only
- // for MyEditor Project no others. (Removals)
- // v4.9.4.90 27-Nov-2018 ReadRemovals() and
- // GetSelectedIndex() integration completed.
- // NOTE: See calls to GetSelectedIndex();
- // v4.9.4.91 01-Dec-2018 Integration ^
- // v5.0.6.00 21-Feb-19 List<T> to Collection<T>
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
- using System;
- using System.Collections.ObjectModel;
- using System.Collections.Specialized;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Windows.Forms;
- // Shortcut Class Aliases
- using MCD = MyCustomLibrary.Dialogs;
- using MCT = MyCustomLibrary.MyToolbox;
- using MWS = MyEditor.WriteShared;
- using SMF = ShowMe.ShowMeForm;
- // Local Properties Shortcut Aliases
- using SMR = MyEditor.Properties.Resources;
- using SMS = MyEditor.Properties.Settings;
- namespace MyEditor
- {
- public partial class Smesa : Form
- {
- /****************************************/
- /* See SmasaHeader.cs for Class Globals */
- /****************************************/
- // Class Constructor 1st Instance Only.
- public Smesa(string[] args, string memo)
- {
- #region Release version testcode
- //MessageBox.Show(string.Format(
- // "Smesa Constructor:\n\n" +
- // "memo contains:\n{0}", memo));
- #endregion
- Mapped = memo;
- Args = MCT.GetCommandLine(args);
- Watcher = new FileSystemWatcher();
- InitializeComponent();
- ProgressBar1.Value = 0;
- StatusLabel.Text = SMR.Status_Hello;
- }
- #endregion Top Part
- //\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region Startup Code
- /// <summary> Form Loading Eventhandler
- /// Called as the Form First Opens.
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SmesaLoading
- (object sender, EventArgs e)
- {
- ProgressBar1.Value = 6;
- Size = SMS.Default.AppSize;
- Location = SMS.Default.AppLocation;
- BackColor = SMS.Default.AppColor;
- _index = TabControl.TabPages[0]
- .Controls.IndexOf(RichTextBox1);
- ReadRemovals();
- // ^ v49488 Hook
- // (see also: GetSelectedIndex)
- if (Args != null && Args.Length > 0)
- ParmsPassedInAtStart();
- ProgressBar1.Value = 24;
- CheckDataFiles();
- ProgressBar1.Value = 69;
- SetPaths(Mapped);
- SetDirectory();
- // ^v Switched order v4.9.4.91b
- SetupOpenFiles();
- GetCharCount();
- MWS.WriteSharedFile(BackColor);
- CheckPref2Collections();
- MmfEventDelegate();
- TestCodeVisibility();
- }
- private void TestCodeVisibility()
- {
- TestCode1.Visible =
- nowTestingToolStripMenuItem
- .Visible = MCT.Testing;
- }
- #region Get everything setup & ready.
- /// <summary> For Resources Tab in Preferences.
- /// Make Their Documents v Folder Home for Now.
- /// But I want to make this The Reminder to setup
- /// a Prefered Folder or something. -Des
- /// </summary>
- public static void SetDirectory()
- {
- string path;
- if (SMS.Default.EnableRes)
- {
- path = Path.GetDirectoryName(
- SMS.Default.FileNames[
- GetSelectedIndex()]);
- } // Index Bugg ^ Fix.
- else path = MCT.GetDocFolder;
- if (!string.IsNullOrEmpty(path)
- && Directory.Exists(path))
- Directory.SetCurrentDirectory(path);
- }
- /// <summary> Checks the last used index
- /// if it has been removed or deleted we
- /// adjust SMS.Default.Index accordingly.
- /// v4.9.4.89 24-Nov-2018 -JpE-
- /// </summary>
- /// <returns></returns>
- private static int GetSelectedIndex()
- {
- // Updated to v4.9.4.90
- var tab = SMS.Default.Index;
- var las = SMS.Default.FileNames.Count-1;
- if (las < 1) return 0;
- while ( tab > las || tab < 0)
- { while (tab > las) --tab;
- while (tab < 0) ++tab; }
- SMS.Default.Index = tab;
- SMS.Default.Save();
- return tab;
- }
- /// <summary> Called when the Form is
- /// First Shown, but, After FormLoading.
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ShownForm(
- object sender, EventArgs e)
- {
- var t = TabControl.SelectedIndex =
- GetSelectedIndex();
- #region Event ^ Note
- // ^ This lil guy Triggers TabChange() event:
- // Then Editing and everything does the rest.
- // Makes sure the Filename is the Tab-text &
- // all that stuff, Colors per extension, etc.
- #endregion
- // Startup Focus Mods.
- SaveButton.Enabled =
- SaveAllButton.Enabled = false;
- var c = SMS.Default.FileNames.Count - 1;
- if (t > c) t = c;
- RichTextBox rtb;
- try { var b = TabControl.TabPages.Count;
- while (t > b && t > -1) --t;
- rtb = TabControl.TabPages[t]
- .Controls[_index] as RichTextBox;
- } catch (ArgumentOutOfRangeException)
- { if (MCT.Testing && !MCT.Skip)
- MessageBox.Show(SMR.Range);
- return; }
- catch (ArgumentException)
- { if (MCT.Testing && !MCT.Skip)
- MessageBox.Show(SMR.Argument);
- return; }
- WordWrap.Checked = MCT.Wrap;
- if (rtb == null) return;
- rtb.Focus();
- GetCharCount(null, true);
- ProgressBar1.Value = 100;
- }
- /// <summary> Checks FileName Collection
- /// Initiating it if necessary, adding default
- /// FileName to the Collection for first tab.
- /// </summary>
- private void CheckDataFiles()
- {
- if (SMS.Default.FileNames == null)
- SMS.Default.FileNames =
- new StringCollection();
- var i = SMS.Default.FileNames.Count;
- // Rev2 Multi-Tab
- if (i >= 1) return;
- var r = TabControl.TabPages[i]
- .Controls[_index] as RichTextBox;
- if (r == null) throw new
- ArgumentException(
- "CheckDataFiles");
- r.Clear();
- SMS.Default.FileNames.Add(
- GetDefaultFileName(i));
- }
- /// <summary> Adds the tab number to the
- /// Default FileName for this Application
- /// where tab number == index + 1;
- /// </summary>
- /// <param name="tab"></param>
- /// <returns>
- /// default filename for this tab number.
- /// </returns>
- public static string
- GetDefaultFileName(int tab)
- {
- var dflt = SMS.Default.DefaultFile;
- var fnmn = Path
- .GetFileNameWithoutExtension(dflt);
- if ( tab > int.MaxValue -1) tab = 0;
- var nmbr = string.Format(
- "({0})", Convert.ToString(tab + 1));
- var exts = Path.GetExtension(dflt);
- if (SMS.Default.PrefRTF)
- exts = SMS.Default.SpecialExt;
- return fnmn + nmbr + exts;
- }
- /// <summary> Brings relevant collections
- /// up or down to the same Count as the
- /// FileName collection.
- /// </summary>
- private void Check5()
- {
- CheckForDuplicates();
- // ^ filenames only.
- EvenUpData();
- // split it out to call separately.
- }
- private void EvenUpData()
- {
- var f = SMS.Default.FileNames.Count;
- var s = SMS.Default.SaveMe.Count;
- var c = SMS.Default.BarValue.Count;
- var z = SMS.Default.Zoo.Count;
- var p = SMS.Default.Curses.Count;
- var u = SMS.Default.Status.Count;
- if (f == s && f == c && f == z
- && f == p && f == u) return;
- var i = s;
- while (i++ < f)
- SMS.Default.SaveMe.Add("0.00");
- while (s-- > f)
- SMS.Default.SaveMe.RemoveAt(s);
- i = c;
- while (i++ < f)
- SMS.Default.BarValue.Add("100");
- while (c-- > f)
- SMS.Default.BarValue.RemoveAt(c);
- i = z;
- while (i++ < f)
- SMS.Default.Zoo.Add("1.0");
- while (z-- > f)
- SMS.Default.Zoo.RemoveAt(z);
- i = p;
- while (i++ < f)
- SMS.Default.Curses.Add("0, 0");
- while (p-- > f)
- SMS.Default.Curses.RemoveAt(p);
- i = u;
- while (i++ < f)
- SMS.Default.Status.Add(StatusLabel.Text);
- while (u-- > f)
- SMS.Default.Status.RemoveAt(u);
- SMS.Default.Save();
- }
- /// <summary> Last ones first removal
- /// as first ones first would change index,
- /// dropping everything down 1 for each one.
- /// Updated to Assure File Exists. v2.2.5.27
- /// </summary>
- private void CheckForDuplicates()
- {
- var idx = -1;
- var tab = new Collection<int>();
- var cpy = new StringCollection();
- foreach (var fn in SMS.Default.FileNames)
- {
- ++idx;
- if (!cpy.Contains(fn)) cpy.Add(fn);
- else tab.Add(idx);
- }
- var c = tab.Count;
- var t = c > 0;
- while (c > 0)
- SMS.Default.FileNames.RemoveAt(tab[--c]);
- // Rev2 Evolutions.
- if (!t) return;
- // if (first) File Not Found.
- if (SMS.Default.FileNames.Count < 1)
- {
- SMS.Default.FileNames.Add(
- GetDefaultFileName(0));
- ZeroSaveMeItem(0);
- }
- SMS.Default.Save();
- }
- #endregion Get everything setup & ready.
- //\\//\\//\\//\\//\\//\\//\\//\\//\\
- #endregion Startup
- //\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region Form Active Code
- /// <summary> Keydown Eventhandler detects
- /// keystrokes as part of the current scheme.
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SmesaKeyDown
- (object sender, KeyEventArgs e)
- {
- var key = e.KeyValue;
- if (_lastKey == 17 &&
- (key == 107 || key == 109))
- { // + is 107 & - is 109
- if (key == 107) ZoomIn();
- else ZoomOut();
- }
- _lastKey = key;
- if (MCT.NoCount(e))
- {
- if (ProgressBar1.Value < 100)
- UnshadyMethod();
- return;
- }
- SaveOrNot();
- if (ProgressBar1.Value < 100)
- UnshadyMethod();
- GetCharCount(e);
- }
- private void GetCharCount(
- KeyEventArgs e = null,
- bool context = false)
- {
- var tab = TabControl.SelectedIndex;
- var rtb = TabControl.TabPages[tab]
- .Controls[_index] as RichTextBox;
- if (rtb == null) return;
- var offset = 1; // v3.2.3.46
- if (context) offset = 0;// YES!
- // Count Fixed ^v w/ offset thusly:
- var d = Keys.F22;// or any Random Key.
- if (e != null) d = e.KeyData;
- if (Keys.Delete.Equals(d)
- || Keys.Back.Equals(d)) offset = -1;
- CharacterCountLabel.Text = string.Format(
- "{0} chars.", rtb.Text.Length + offset);
- }
- /// <summary> Determines the Users Preference
- /// for Saving File Automatically or Manually.
- /// </summary>
- private void SaveOrNot()
- {
- var tab = TabControl.SelectedIndex;
- if (tab < 0) tab = 0;
- if (ProgressBar1.Value <= 0)
- ZeroedOut(tab);
- else
- StepDown(tab);
- SMS.Default.BarValue[tab] =
- Convert.ToString(
- ProgressBar1.Value);
- SMS.Default.Save();
- }
- /// <summary> Increments the ProgressBar
- /// and SaveMe values every 1/sms.step
- /// keystrokes. OR from 100 to 99 v26.
- /// Also Sets the Status Label Message.
- /// </summary>
- /// <param name="tab"></param>
- private void StepDown(int tab)
- {
- var num = GetDecimal(tab);
- var whole = MCT.GetWhole(num);
- if (num != whole
- && ProgressBar1.Value
- != 100) return;
- if (ProgressBar1.Value > 0)
- ProgressBar1.Value--;
- UnshadyMethod();
- }
- private decimal GetDecimal(int tab)
- {
- decimal num;
- var c = SMS.Default.SaveMe.Count;
- if (tab < c)
- { try
- { num = Convert.ToDecimal(
- SMS.Default.SaveMe[tab]); }
- catch (FormatException) { num = 0; }
- catch (OverflowException) { num = 0; }
- }
- else
- { Check5();
- return 00000; }
- SMS.Default.SaveMe[tab] =
- Convert.ToString(num += SMS.Default.Step);
- SMS.Default.Save();
- return num;
- }
- /// <summary> Handles Zeroed state of ProgressBar.
- /// SaveMe is a Collection of Decimals, 1 for each tab.
- /// Increments the decimal, converts it back to a...
- /// string & assigns it to the SaveMe[indx] Collection.
- /// So...
- /// Note the dual incrementation of SaveMe[indx]
- /// & deci values. Adjust Step intervals in
- /// the Settings Designer, it's at 0.1 now.
- /// </summary>
- /// <param name="tab"></param>
- private void ZeroedOut(int tab)
- {
- // Resets ProgressBar & Status Text.
- if (SMS.Default.SaveSet)
- {
- if (SMS.Default.SaveIt)
- {
- SaveClick("KeyDown", EventArgs.Empty);
- ZeroSaveMeItem(tab);
- }
- }
- else SaveNotSet(tab);
- }
- private void SaveNotSet(int tab)
- {
- // If SaveSet then forget the below.
- var deci = Convert.ToDecimal(
- SMS.Default.SaveMe[tab]);
- SMS.Default.SaveMe[tab] =
- Convert.ToString(deci +=
- SMS.Default.Step);
- var hits = 0;
- var past = Convert.ToString(
- 250 + SMS.Default.Step);
- // Move past ^ once hit.
- if (deci > 125 && deci < 250)
- hits = PromptForSave(tab, past);
- past = Convert.ToString(
- 600 + SMS.Default.Step);
- if (deci > 400 && deci < 600)
- hits = PromptForSave(tab, past);
- if (SMS.Default.SaveIt
- && SMS.Default.SaveSet)
- SaveClick("KeyDown", EventArgs.Empty);
- if (hits > 0)
- SetSavePref(hits, tab);
- SMS.Default.Save();
- }
- private int PromptForSave(
- int tab, string past)
- {
- SMS.Default.SaveMe[tab] = past;
- KeyDown -= SmesaKeyDown;
- var test = MCD.GetSavePreference();
- KeyDown += SmesaKeyDown;
- return test;
- }
- /// <summary> Handles Input from GetSavePref:
- /// YesNoAlways Legend: 1 = Yes, 2 = No,
- /// 3 = Yes as Pref. 4 = No as Pref.
- /// </summary>
- /// <param name="state"></param>
- /// <param name="tab"> </param>
- private void SetSavePref(int state, int tab)
- {
- switch (state)
- {
- case 1: SaveCurrentFile(tab);
- break;
- case 2: // do nothing
- break;
- case 3: SaveCurrentFile(tab);
- SMS.Default.SaveIt = true;
- break;
- case 4: SMS.Default.SaveIt = false;
- break;
- }
- SMS.Default.SaveSet = state > 2;
- SMS.Default.Save();
- }
- #endregion Smeasa Form Active Code
- //\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region View And Zoom Menu Items
- private void ShowLists(
- object sender, EventArgs e)
- {
- string sl="", f = "";
- const string lf = "\n";
- sl = SMS.Default.Favorites
- .Cast<string>().Aggregate(
- sl, (current, file) =>
- current + (file + lf));
- var app = Path.GetDirectoryName(
- Mapped) + SMR.Sme;
- if (!File.Exists(app))
- { var cn = SMR.Show2;
- var nf = SMR.ShowList;
- var fn = SMR.Sme.Substring(1);
- var tx = string.Format(
- "{0}{1}{2}{3}", fn, cn, lf, nf);
- MessageBox.Show(tx);
- return; }
- var str = string.Format(
- "Files:{0}{1}", lf, sl);
- str = str.Replace("\\", "/");
- MCT.RunApp(str, SMR.Ttl1, app);
- Thread.Sleep(400);
- f = SMS.Default.DataFolders
- .Cast<string>().Aggregate(
- f, (current, dir) =>
- current + (dir + lf));
- var fldr = string.Format(
- "Folders:{0}{1}", lf, f);
- fldr = fldr.Replace("\\", "/");
- MCT.RunApp(fldr, SMR.Ttl2, app);
- }
- // Multi-Tab Upgraded.
- // MCT.Wrap v4.8.2.82 25-Oct-2018
- private void WordWrapClick
- (object sender, EventArgs e)
- {
- MCT.Wrap = // <-= 1 of 2 new lines.
- WordWrap.Checked =
- !WordWrap.Checked;
- for (var i = 0; i < SMS.Default
- .FileNames.Count; ++i)
- {
- var rtb = TabControl.TabPages[i]
- .Controls[_index] as RichTextBox;
- if (rtb == null) continue;
- SMS.Default.Zoo[i] =
- Convert.ToString(
- rtb.ZoomFactor);
- rtb.WordWrap = MCT.Wrap;// <-= 2 of 2
- rtb.ZoomFactor =
- Convert.ToSingle(
- SMS.Default.Zoo[i]);
- }
- SMS.Default.Save();
- }
- private void ZoomIndexChanged(
- object sender, EventArgs e)
- {
- if (Zoomed) return;
- Zoomed = true;
- var sgl = Convert.ToSingle(
- ZoomMenu.SelectedIndex + 1) / 10;
- // Multi-Tab updated Rev2.
- var tab = TabControl.SelectedIndex;
- var rtb = TabControl.TabPages[tab]
- .Controls[_index] as RichTextBox;
- if (rtb == null) return;
- rtb.ZoomFactor = sgl;
- Zoomed = false;
- }
- private void TabChange
- (object sender, EventArgs e)
- {
- var next = Convert.ToString(
- sender).Contains("Next");
- var c = TabControl.TabCount;
- var t = TabControl.SelectedIndex;
- if (next) TabControl.SelectedIndex =
- #region Event ^ Note
- // ^ This li guy Triggers TabChange() event:
- // Then Editing and everything does the rest.
- // Makes sure the Filename is the Tab-text &
- // all that stuff, Colors per extension, etc.
- #endregion
- ++t < c ? t : 0;
- // else PreviousTab then.
- else TabControl.SelectedIndex =
- t-- > 0 ? t : --c;
- #region Event ^ Note
- // ^ This li guy Triggers TabChange() event:
- // Then Editing and everything does the rest.
- // Makes sure the Filename is the Tab-text &
- // all that stuff, Colors per extension, etc.
- #endregion
- }
- #endregion View, WordWrap, & Zoom Menu Items
- //\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region Closing Code
- /// <summary> Form Closing EVenthandler
- /// triggered when the Form is ready to close.
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SmesaClosing
- (object sender, FormClosingEventArgs e)
- {
- if (Watcher != null) Watcher
- .EnableRaisingEvents = false;
- CheckSaveStatus();
- SaveZoomValues();
- ProgressBar1.Value = 18;
- StatusLabel.Text = SMR.Status_Closing;
- ProgressBar1.Value = 42;
- ProgressBar1.Value = 67;
- SMS.Default.AppSize = Size;
- SMS.Default.AppLocation = Location;
- SMS.Default.AppColor = BackColor;
- ProgressBar1.Value = 83;
- SMS.Default.Index =
- TabControl.SelectedIndex;
- // ^ Saves current tab number.
- LogOut();
- ProgressBar1.Value = 98;
- // Cuz at 100% closed you won't see it!
- StatusLabel.Text = SMR.Status_Bye;
- CheckPref2Collections();
- // ^ See Preferences2.cs
- MWS.WriteSharedFile(BackColor);
- SMS.Default.Save();
- Mx2.Dispose();
- }
- private static void CheckPref2Collections()
- { // On Exit.
- var dirs = new StringCollection();
- // First Files, but grab dirs on the fly.
- foreach (var file in SMS.Default.FileNames
- .Cast<string>().Where(file =>
- !string.IsNullOrEmpty(file)
- && File.Exists(file)))
- {
- dirs.Add(Path.GetDirectoryName(file));
- if (!SMS.Default.Favorites.Contains(file))
- SMS.Default.Favorites.Insert(0, file);
- }
- // Maintain Max Collection Count of 128
- while (SMS.Default.Favorites.Count > 128)
- SMS.Default.Favorites.RemoveAt(128);
- // Then do the dirs.
- foreach (var dir in dirs
- .Cast<string>().Where(dir =>
- !SMS.Default.DataFolders.Contains(dir)))
- SMS.Default.DataFolders.Insert(0, dir);
- // Maintain Max Collection Count of 64
- while (SMS.Default.DataFolders.Count > 64)
- SMS.Default.DataFolders.RemoveAt(64);
- var fn = Path.GetDirectoryName(
- BlasterPath) + SMR.Favs;
- if (!File.Exists(fn)) fn =
- Path.GetDirectoryName(Mapped) + SMR.Favs;
- if (!File.Exists(fn)) return;
- MCT.SaveList(
- SMS.Default.Favorites, fn);
- }
- /// <summary> Save Zoom Values to
- /// the Collection of same and More.
- /// </summary>
- private void SaveZoomValues()
- {
- Check5();
- for (var i = 0; i < SMS.Default
- .FileNames.Count; ++i)
- {
- // form closing
- var rtb = TabControl.TabPages[i]
- .Controls[_index] as RichTextBox;
- if (rtb == null) continue;
- SMS.Default.Zoo[i] =
- Convert.ToString(rtb.ZoomFactor);
- SMS.Default.Curses[i] =
- string.Format("{0}, {1}",
- Convert.ToString(rtb.SelectionStart),
- Convert.ToString(rtb.SelectionLength));
- }
- SMS.Default.Save();
- }
- #endregion Closing Code
- //\\//\\//\\//\\//\\//\\//\\//\\//\\
- // ALL test code Below here.
- #region TestCode
- private void NowTestingClick(
- object sender, EventArgs e)
- {
- const string t =
- "Now Testing Removals:\n\n";
- if (!MCD.YesNoDialog((string.Format(
- "{0}{1}", t, DateTime.Now)))) return;
- // This triggers the Watcher and so forth.
- var list = new Collection<string>
- {MCT.GetDocFolder + "\\About.txt"};
- if ( //list == null ||
- list.Count < 1) return;
- var file = Path.GetDirectoryName(
- EditorPath) + "\\Editor.sme";
- var path = Path.
- GetFileNameWithoutExtension(file);
- var args = new object[]
- {
- file, SMS.Default.EditorSize,
- SMS.Default.EditorOffset2,
- list, true, path, false,// Uses...
- SMS.Default.EditorView2//<-= ALL 8
- };
- if (!MyCustomLibrary.MemoryMapper
- .WriteStrings(args)) throw new
- ArgumentException(
- "Favorites Testing Failed!");
- }
- // These Methods for testing purposes
- // only & hidden when not testing.
- private void Test1Click
- (object sender, EventArgs e)
- {
- MessageBox.Show(string.Format("{0}{1}",
- "Test 1 Clicked:\n\n", DateTime.Now));
- //var args =
- // new object[]
- // {
- // Mapped, MySize, MyOffset-2,
- // new Collection<byte> {1}, true, Path
- // .GetFileNameWithoutExtension(
- // Mapped), false
- // };
- //const string txt =
- // "Write Bytes Failed!\n\n" +
- // "Please Report Error #5";
- //if (!MemoryMapper.
- // ReverseWriteBytes(args))
- // MessageBox.Show(txt);
- // Space For Rent.
- }
- #endregion TestCode
- //\\//\\//\\////\\//\\//\\////\\//\\
- #region Scrap Yard
- //private void ShowFileNamesListClick
- // (object sender, EventArgs e)
- //{
- // var msg =
- // SMS.Default.TestFiles.Cast<string>()
- // .Aggregate("", (current, fn) =>
- // current + (fn + ", "));
- // MessageBox.Show(msg);
- //}
- //if (SMS.Default.TestFiles == null)
- // SMS.Default.TestFiles =
- // new StringCollection();
- //if (SMS.Default.TestFiles != null
- // && SMS.Default.TestFiles
- // .Count.Equals(3))
- //{
- // var msg =
- // SMS.Default.TestFiles
- // .Cast<string>()
- // .Aggregate("", (current, fn)
- // => current + (fn + ", "));
- // MessageBox.Show(msg);
- //}
- //if (test Code.InitializeTestFiles())
- //{
- // Close();
- // return;
- //}
- //if (SMS.Default.TestFiles == null) return;
- //// Launcher Mods v2.6.1.33 21-Feb-2018
- //var c = SMS.Default.TestFiles.Count;//+ 2;
- //var args = new string[c];
- //for (var i = 0; i < c; ++i)
- // args[i] = SMS.Default.TestFiles[i];
- //if (!YesNoDialog(
- // "Run the Simulation Now?", "", 1)) return;
- //if (Watcher != null)
- // Watcher.EnableRaisingEvents = false;
- //MmfClientSideWrite(args, Mapped);
- //if (!YesNoDialog(
- // "Run the Reader Now?", "", 1)) return;
- //MmfServerSide(true);
- //if (Watcher != null)
- // Watcher.EnableRaisingEvents = true;
- //MyCustomLibrary.MCT.RunApp(args);
- //const string p =
- // "Nothing Pending.";
- //MessageBox.Show(p);
- //private static void Msg()
- //{
- // const string msg =
- // // as are Calls to it.
- // "Under Construction, Please Return.";
- // MessageBox.Show(msg);
- //}
- //private void Test2()
- //{
- // var c = SMS.Default.TestFiles.Count;
- // Args = new string[c];
- // for (var i = 0; i < c; ++i)
- // Args[i] = SMS.Default.TestFiles[i];
- // ParmsPassedInAtStart();
- //}
- //var t = new test Code(1);
- //switch (t.Tested)
- //{
- // case 3:
- // Close();
- // break;
- // case 1:
- // ShowFileNamesListClick(
- // "", EventArgs.Empty);
- // break;
- //}
- //if (YesNoDialog(
- // "Test Parameters Passed In Now?",
- // "Beta Testers Only:"))
- //Test2();
- //const string txt = "Result: \n\n";
- //var test = TabPrompt(
- // TabControl.SelectedIndex);
- ////var test = MCD.GetSavePref();
- //MessageBox.Show(txt + test);
- //MmfClientSideWrite(args);
- ////test Code for ByteReader
- //MmfServerSide(true);
- #endregion Scrap Yard
- //\\//\\//\\////\\//\\//\\////\\//\\
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement