//using System; //using System.Text; //using System.Text.RegularExpressions; //using System.Timers; //using System.Windows.Forms; //using MinorShift.Emuera.GameView; //using Timer = System.Timers.Timer; //namespace MinorShift.Emuera.GameProc.Function //{ // internal class ClipboardProcessor // { // private readonly bool useCB; // private readonly bool classicMode; // New Lines Only mode // private readonly MainWindow mainWin; // private bool minTimePassed; //Has enough time passed since the last Clipboard update? // private bool postWaiting; //Is there text waiting to be sent to clipboard? // private static Timer minTimer; //Minimum timer for refrehsing the clipboard to prevent spam // private readonly int MaxCB; //Max length in lines of the output to clipboard // private int ScrollPos; //Position of the clipboard output in the buffer // private readonly int ScrollCount; //Lines to scroll at a time // private int NewLineCount; //Number of new lines // private int OldNewLineCount; //Number of lines in the last update, used for Classic mode + scrolling back to bottom // private StringBuilder OldText; //Last set of lines sent to the clipboard // private readonly CircularBuffer lineBuffer; //Buffer for processed strings ready for clipboard // public string GetLatestString => OldText.ToString(); // internal enum CBTriggers // { // LeftClick, // MiddleClick, // DoubleLeftClick, // AnyKeyWait, // InputWait // } // private delegate void SetClipboardDelegate(string text, bool copy, int times, int delay); //Just for using the timer to set the clipboard. // public ClipboardProcessor(MainWindow parent) // { // useCB = Config.CBUseClipboard; // classicMode = Config.CBNewLinesOnly; // mainWin = parent; // minTimePassed = true; // postWaiting = false; // MaxCB = Config.CBMaxCB; // ScrollPos = 0; //FIXIT - Expand it, add a button, etc // ScrollCount = Config.CBScrollCount; //FIXIT - Actually use it // NewLineCount = 0; // OldNewLineCount = 0; // if (!useCB) return; // lineBuffer = new CircularBuffer(Config.CBBufferSize); // minTimer = new Timer(Config.CBMinTimer) {AutoReset = false}; // minTimer.Elapsed += MinTimerDone; // OldText = new StringBuilder(); // } // public bool ScrollUp(int value) // { // if (!useCB) return false; // if (ScrollPos == 0 && classicMode && ScrollCount > OldNewLineCount) ScrollPos = OldNewLineCount; // else ScrollPos += ScrollCount * value; // if (lineBuffer.Count < ScrollPos) ScrollPos = lineBuffer.Count - ScrollCount; // SendToCB(true); // return true; // } // public bool ScrollDown(int value) // { // if (!useCB) return false; // ScrollPos -= ScrollCount; // if (ScrollPos < 0) ScrollPos = 0; // SendToCB(true); // return true; // } // private void MinTimerDone(object source, ElapsedEventArgs e) // { // minTimePassed = true; // if (postWaiting) SendToCB(true); // } // private bool MinTimeCheck() // { // if (minTimePassed) // { // minTimePassed = false; // minTimer.Start(); // return true; // } // return false; // } // //FIXIT - Autoprocess old lines or just ditch? // public void AddLine(ConsoleDisplayLine inputLine, bool left) // { // if (!useCB) return; // NewLineCount++; // string processed = ProcessLine(inputLine.ToString()); // lineBuffer.Enqueue(processed); // } // public void DelLine(int count) // { // if (!useCB || count <= 0) return; // NewLineCount = Math.Max(0, NewLineCount - count); // if (count >= lineBuffer.Count) lineBuffer.Clear(); // else // { // while (count > 0) // { // lineBuffer.Dequeue(); // count--; // } // } // } // public void ClearScreen() // { // if (!useCB) return; // if (Config.CBClearBuffer) // { // lineBuffer.Clear(); // ScrollPos = 0; // NewLineCount = 0; // } // else // { // lineBuffer.Enqueue(""); // } // } // public void Check(CBTriggers type) // { // if (!useCB) return; // switch (type) // { // case CBTriggers.LeftClick: // if (!Config.CBTriggerLeftClick) return; // break; // case CBTriggers.MiddleClick: // if (!Config.CBTriggerMiddleClick) return; // break; // case CBTriggers.DoubleLeftClick: // if (!Config.CBTriggerDoubleLeftClick) return; // break; // case CBTriggers.AnyKeyWait: // if (!Config.CBTriggerAnyKeyWait) return; // break; // case CBTriggers.InputWait: // if (!Config.CBTriggerInputWait) return; // break; // default: // return; // } // ScrollPos = 0; // SendToCB(false); // } // private void SendToCB(bool force) // { // if (!useCB) return; // if (NewLineCount == 0 && !force) return; // if (!MinTimeCheck()) // { // postWaiting = true; // return; // } // if (NewLineCount == 0 && ScrollPos == 0) NewLineCount = OldNewLineCount; // int length; // if (classicMode && ScrollPos == 0) length = Math.Min(NewLineCount, lineBuffer.Count); // else length = Math.Min(MaxCB, lineBuffer.Count - ScrollPos); // if (length <= 0) return; // var newText = new StringBuilder(); // for (int count = 0; count < length; count++) // { // newText.AppendLine(lineBuffer[lineBuffer.Count - length - ScrollPos + count]); // } // if (newText.ToString().Equals(OldText.ToString())) return; // var scpDelegate = new SetClipboardDelegate(Clipboard.SetDataObject); // try // { // mainWin.Invoke(scpDelegate, newText.ToString(), false, 3, 200); // if (ScrollPos == 0) OldNewLineCount = NewLineCount; // NewLineCount = 0; // OldText = newText; // postWaiting = false; // } // catch (Exception) // { // //FIXIT - For now it just fails silently // } // } // private const string HTML_TAG_PATTERN = "<.*?>"; // public static string StripHTML(string input) // { // // still faster to use String.Contains to check if we need to do this at all first, supposedly // if (Config.CBIgnoreTags && input.Contains("<")) // { // // regex is faster and simpler than a for loop you nerds // return Regex.Replace(input, HTML_TAG_PATTERN, Config.CBReplaceTags); // } // return input; // } // private static string ProcessLine(string input) // { // return StripHTML(input); // } // } //}