Skip to content

Commit 3cc172a

Browse files
Merge pull request #3 from robvanoostenrijk/WireSockUI
WireSock UI
2 parents 7b027f3 + 197e1c8 commit 3cc172a

File tree

6 files changed

+75
-48
lines changed

6 files changed

+75
-48
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ jobs:
1818
- name: Add msbuild to PATH
1919
uses: microsoft/setup-msbuild@v1
2020

21+
- name: Parse Version
22+
shell: bash
23+
run: |
24+
# Strip "v" prefix from tag name
25+
VERSION=$(echo ${{ github.ref_name }} | sed -e 's/^v//')
26+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
27+
2128
- name: Build
22-
run: msbuild WireSockUI/WireSockUI.csproj -t:rebuild -verbosity:minimal -property:Configuration=Release
29+
run: msbuild WireSockUI/WireSockUI.csproj -t:rebuild -verbosity:minimal -property:Configuration=Release -property:Version=${{ env.VERSION }}
2330

2431
- name: Package Release
2532
uses: thedoctor0/zip-release@0.7.1

WireSockUI/Forms/MainForm.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using WireSockUI.Extensions;
1212
using WireSockUI.Native;
1313
using WireSockUI.Properties;
14-
using static System.Windows.Forms.AxHost;
1514
using static WireSockUI.Native.WireguardBoosterExports;
1615

1716
namespace WireSockUI.Forms
@@ -79,8 +78,6 @@ private BackgroundWorker InitTunnelStateWorker()
7978
{
8079
Thread.Sleep(1000);
8180

82-
Debug.WriteLine("Doing work.");
83-
8481
if (_wiresock.Connected)
8582
{
8683
WgbStats stats = _wiresock.GetState();
@@ -304,27 +301,28 @@ public frmMain()
304301
LoadProfiles();
305302

306303
// Create a new WireSockManager instance, attached to the logging control
307-
_wiresock = new WireSockManager(lstLog, this.OnWireSockLogMessage);
304+
_wiresock = new WireSockManager(this.OnWireSockLogMessage);
305+
_wiresock.LogLevel = _wiresock.LogLevelSetting;
308306
}
309307

310308
protected override void OnLoad(EventArgs e)
311309
{
312310
base.OnLoad(e);
313311

314-
if (Properties.Settings.Default.AutoMinimize)
312+
if (Settings.Default.AutoMinimize)
315313
{
316314
this.WindowState = FormWindowState.Minimized;
317315
this.ShowInTaskbar = false;
318316
Hide();
319317
}
320318

321-
if (lstProfiles.Items.ContainsKey(Properties.Settings.Default.LastProfile))
322-
lstProfiles.Items[Properties.Settings.Default.LastProfile].Selected = true;
319+
if (lstProfiles.Items.ContainsKey(Settings.Default.LastProfile))
320+
lstProfiles.Items[Settings.Default.LastProfile].Selected = true;
323321

324322
// Connect to the last used configuration, if required.
325-
if (!Properties.Settings.Default.AutoConnect) return;
323+
if (!Settings.Default.AutoConnect) return;
326324

327-
if (lstProfiles.Items.ContainsKey(Properties.Settings.Default.LastProfile))
325+
if (lstProfiles.Items.ContainsKey(Settings.Default.LastProfile))
328326
OnProfileClick(lstProfiles, EventArgs.Empty);
329327
else
330328
MessageBox.Show(Resources.LastProfileNotFound, Resources.DialogAutoConnect, MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -444,7 +442,7 @@ private void OnProfileClick(object sender, EventArgs e)
444442
}
445443
else
446444
{
447-
_wiresock.TunnelMode = Properties.Settings.Default.UseAdapter ? WireSockManager.Mode.VirtualAdapter : WireSockManager.Mode.Transparent;
445+
_wiresock.TunnelMode = Settings.Default.UseAdapter ? WireSockManager.Mode.VirtualAdapter : WireSockManager.Mode.Transparent;
448446

449447
string profile = lstProfiles.SelectedItems[0].Text;
450448

@@ -685,10 +683,12 @@ private void OnLogDrawHeader(object sender, DrawListViewItemEventArgs e)
685683

686684
if ((e.ItemIndex % 2) == 1)
687685
{
686+
Color color = Color.FromKnownColor(KnownColor.Window);
687+
688688
e.Item.BackColor = Color.FromArgb(
689-
(int)(e.Item.BackColor.R * 0.95),
690-
(int)(e.Item.BackColor.G * 0.95),
691-
(int)(e.Item.BackColor.B * 0.95));
689+
(int)(color.R * 0.95),
690+
(int)(color.G * 0.95),
691+
(int)(color.B * 0.95));
692692

693693
e.Item.UseItemStyleForSubItems = true;
694694
}

WireSockUI/Forms/SettingsForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public frmSettings()
2525
ddlLogLevel.SelectedItem = Settings.Default.LogLevel;
2626

2727
// If the shortcut exists, and the setting does not match update it to reflect the actual status
28-
chkAutoConnect.Checked = File.Exists(linkFile);
28+
chkAutorun.Checked = File.Exists(linkFile);
2929
}
3030

3131
private void OnProfilesFolderClick(object sender, EventArgs e)

WireSockUI/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.2.0")]
35-
[assembly: AssemblyFileVersion("1.0.2.0")]

WireSockUI/WireSockManager.cs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using System.ComponentModel;
34
using System.Runtime.InteropServices;
4-
using System.Threading.Tasks;
55
using System.Windows.Forms;
66
using WireSockUI.Config;
77
using WireSockUI.Properties;
@@ -40,10 +40,7 @@ internal class WireSockManager : IDisposable
4040
private GCHandle _logPrinterHandle;
4141

4242
private readonly LogPrinter _logPrinter;
43-
4443
private WgbLogLevel _logLevel;
45-
private readonly Control _logControl;
46-
private readonly LogMessageCallback _logMessageCallback;
4744

4845
/// <summary>
4946
/// LogMessage function delegate
@@ -142,7 +139,7 @@ public WgbLogLevel LogLevelSetting
142139
{
143140
get
144141
{
145-
switch (Properties.Settings.Default.LogLevel)
142+
switch (Settings.Default.LogLevel)
146143
{
147144
case "Info":
148145
return WgbLogLevel.Info;
@@ -207,37 +204,44 @@ private void PrintLog(string message)
207204
}
208205

209206
/// <summary>
210-
/// Initializes a new instance of the <see cref="WireSockManager" />.
207+
/// Initialize a <see cref="T:BackgroundWorker" /> which retrieves log messages from the logging queue
211208
/// </summary>
212-
/// <param name="logControl"><see cref="T:Control" /> owning the <paramref name="logMessageCallback"/></param>
213-
/// <param name="logMessageCallback"><see cref="T:LogMessageCallback" /></param>
214-
public WireSockManager(Control logControl = null, LogMessageCallback logMessageCallback = null)
209+
/// <param name="logMessageCallback"><see cref="T:LogMessageCallback" /> to call for each log message</param>
210+
/// <returns><see cref="T:BackgroundWorker" /></returns>
211+
private BackgroundWorker InitializeLogWorker(LogMessageCallback logMessageCallback)
215212
{
216-
_logQueue = new BlockingCollection<LogMessage>(new ConcurrentQueue<LogMessage>());
217-
_logControl = logControl;
218-
_logMessageCallback = logMessageCallback;
213+
BackgroundWorker worker = new BackgroundWorker()
214+
{
215+
WorkerReportsProgress = true
216+
};
219217

220-
Task.Run(() =>
218+
worker.DoWork += (object s, DoWorkEventArgs e) =>
221219
{
222-
try
220+
// Exit when the logQueue is done adding and empty
221+
while (!_logQueue.IsCompleted)
223222
{
224-
while (true)
225-
{
226-
LogMessage message = _logQueue.Take();
227-
228-
if (_logControl != null && _logMessageCallback != null)
229-
{
230-
if (_logControl.InvokeRequired)
231-
_logControl.BeginInvoke(_logMessageCallback, new object[] { message });
232-
else
233-
_logMessageCallback(message);
234-
}
235-
}
223+
LogMessage message = _logQueue.Take();
224+
worker.ReportProgress(0, message);
236225
}
237-
catch (InvalidOperationException)
238-
{
239-
}
240-
});
226+
};
227+
228+
worker.ProgressChanged += (object s, ProgressChangedEventArgs e) =>
229+
{
230+
if (e.UserState is LogMessage message)
231+
logMessageCallback(message);
232+
};
233+
234+
return worker;
235+
}
236+
237+
/// <summary>
238+
/// Initializes a new instance of the <see cref="WireSockManager" />.
239+
/// </summary>
240+
/// <param name="logMessageCallback"><see cref="T:LogMessageCallback" /></param>
241+
public WireSockManager(LogMessageCallback logMessageCallback = null)
242+
{
243+
_logQueue = new BlockingCollection<LogMessage>(new ConcurrentQueue<LogMessage>());
244+
InitializeLogWorker(logMessageCallback).RunWorkerAsync();
241245

242246
this.TunnelMode = Mode.Transparent;
243247

WireSockUI/WireSockUI.csproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<Version Condition="'$(Version)' == ''">1.0.0</Version>
78
<ProjectGuid>{C309F359-DAFF-42D0-8379-70ECC9688943}</ProjectGuid>
89
<OutputType>WinExe</OutputType>
910
<RootNamespace>WireSockUI</RootNamespace>
@@ -164,4 +165,21 @@
164165
<Content Include="Resources\wiresock.ico" />
165166
</ItemGroup>
166167
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
167-
</Project>
168+
<Target Name="BeforeBuild">
169+
<ItemGroup>
170+
<AssemblyAttributes Include="AssemblyVersion">
171+
<_Parameter1>$(Version)</_Parameter1>
172+
</AssemblyAttributes>
173+
<AssemblyAttributes Include="AssemblyFileVersion">
174+
<_Parameter1>$(Version)</_Parameter1>
175+
</AssemblyAttributes>
176+
</ItemGroup>
177+
<MakeDir Directories="$(IntermediateOutputPath)" />
178+
<WriteCodeFragment Language="C#"
179+
OutputFile="$(IntermediateOutputPath)Version.cs"
180+
AssemblyAttributes="@(AssemblyAttributes)" />
181+
<ItemGroup>
182+
<Compile Include="$(IntermediateOutputPath)Version.cs" />
183+
</ItemGroup>
184+
</Target>
185+
</Project>

0 commit comments

Comments
 (0)