Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeromusXYZ committed Apr 24, 2019
2 parents b6653e3 + 7d49cb9 commit eb70013
Show file tree
Hide file tree
Showing 21 changed files with 1,296 additions and 245 deletions.
3 changes: 3 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<setting name="ColSelectedFontUNK" serializeAs="String">
<value>White</value>
</setting>
<setting name="ExternalParseEditor" serializeAs="String">
<value>True</value>
</setting>
</PacketViewerLogViewer.Properties.Settings>
</userSettings>
</configuration>
90 changes: 90 additions & 0 deletions ClipboardHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PacketViewerLogViewer.ClipboardHelper
{
// Source: https://stackoverflow.com/questions/899350/how-do-i-copy-the-contents-of-a-string-to-the-clipboard-in-c
/// <summary>
/// Usage: new SetClipboardHelper( DataFormats.Text, "See, I'm on the clipboard" ).Go();
/// </summary>
class SetClipboardHelper : StaHelper
{
readonly string _format;
readonly object _data;

public SetClipboardHelper(string format, object data)
{
_format = format;
_data = data;
}

protected override void Work()
{
var obj = new System.Windows.Forms.DataObject(
_format,
_data
);

System.Windows.Forms.Clipboard.SetDataObject(obj, true);
}
}

abstract class StaHelper
{
readonly ManualResetEvent _complete = new ManualResetEvent(false);

public void Go()
{
var thread = new Thread(new ThreadStart(DoWork))
{
IsBackground = true,
};
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}

// Thread entry method
private void DoWork()
{
try
{
_complete.Reset();
Work();
}
catch (Exception ex)
{
if (DontRetryWorkOnFailed)
throw;
else
{
try
{
Thread.Sleep(1000);
Work();
}
catch
{
// ex from first exception
System.Windows.Forms.MessageBox.Show(ex.Message,"Copy to Clipboard",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
// LogAndShowMessage(ex);
}
}
}
finally
{
_complete.Set();
}
}

public bool DontRetryWorkOnFailed { get; set; }

// Implemented in base class to do actual work.
protected abstract void Work();
}


}
2 changes: 2 additions & 0 deletions LoadingForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eb70013

Please sign in to comment.