Skip to content

Commit b1e4561

Browse files
committed
...
1 parent 0eb9fcb commit b1e4561

File tree

14 files changed

+317
-440
lines changed

14 files changed

+317
-440
lines changed

SmartImage.Lib 3/Engines/BaseSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected virtual bool VerifyQuery(SearchQuery q)
8787
return false;
8888
}
8989

90-
bool b, b2;
90+
bool b;
9191

9292
if (MaxSize == NA_SIZE || q.Size == NA_SIZE) {
9393
b = true;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">UI</s:String></wpf:ResourceDictionary>

SmartImage.UI/App.xaml.cs

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,103 @@
11
using System;
2+
using System.Collections;
23
using System.Diagnostics;
4+
using System.Diagnostics.CodeAnalysis;
35
using System.IO;
46
using System.IO.Pipes;
57
using System.Threading;
68
using System.Windows;
79
using Microsoft.VisualBasic.Logging;
810
using System.Windows.Interop;
11+
using JetBrains.Annotations;
912
using Novus.Utilities;
1013
using Novus.Win32;
11-
14+
#nullable disable
1215
namespace SmartImage.UI;
1316

1417
/// <summary>
1518
/// Interaction logic for App.xaml
1619
/// </summary>
1720
public partial class App : Application
1821
{
22+
1923
/// <summary>
2024
/// This identifier must be unique for each application.
2125
/// </summary>
22-
public const string SingleGuid = "{910e8c27-ab31-4043-9c5d-1382707e6c93}";
26+
public const string SINGLE_GUID = "{910e8c27-ab31-4043-9c5d-1382707e6c93}";
2327

2428
public const string IPC_PIPE_NAME = "SIPC";
2529

2630
public const char ARGS_DELIM = '\0';
2731

28-
private static Mutex SingleMutex;
32+
private static Mutex _singleMutex;
2933

3034
public NamedPipeServerStream PipeServer { get; private set; }
3135

3236
public Thread PipeThread { get; private set; }
3337

34-
private void Application_Startup(object sender, StartupEventArgs e)
38+
private void Application_Startup(object sender, StartupEventArgs startupArgs)
3539
{
40+
bool multipleInstances = false, pipeServer = false;
41+
42+
var enumerator = startupArgs.Args.GetEnumerator();
43+
using var unknown = enumerator as IDisposable;
44+
45+
while (enumerator.MoveNext()) {
46+
var el = enumerator.Current;
47+
var els = el?.ToString();
48+
49+
switch (els) {
50+
case "-mi":
51+
multipleInstances = true;
52+
break;
53+
case "-ms":
54+
pipeServer = true;
55+
break;
56+
default:
57+
break;
58+
}
59+
}
3660

37-
SingleMutex = new Mutex(true, SingleGuid);
38-
var isOnlyInstance = SingleMutex.WaitOne(TimeSpan.Zero, true);
39-
40-
var multipleInstances = false;
61+
_singleMutex = new Mutex(true, SINGLE_GUID);
62+
var isOnlyInstance = _singleMutex.WaitOne(TimeSpan.Zero, true);
4163

4264
if (multipleInstances || isOnlyInstance) {
4365
// Show main window
4466
StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
4567

4668
// Release SingleInstance Mutex
47-
SingleMutex.ReleaseMutex();
48-
49-
StartServer();
69+
_singleMutex.ReleaseMutex();
70+
if (pipeServer) {
71+
StartServer();
5072

73+
}
5174
}
5275
else {
5376
// Bring the already running application into the foreground
5477
// Native.PostMessage(0xffff, AppUtil.m_registerWindowMessage, 0, 0);
55-
SendMessage(e);
78+
SendMessage(startupArgs);
5679

5780
Shutdown();
5881

5982
}
83+
6084
}
6185

6286
private static void SendMessage(StartupEventArgs e)
6387
{
6488

65-
using (var pipe = new NamedPipeClientStream(".", IPC_PIPE_NAME, PipeDirection.Out))
66-
using (var stream = new StreamWriter(pipe)) {
67-
pipe.Connect();
89+
using var pipe = new NamedPipeClientStream(".", IPC_PIPE_NAME, PipeDirection.Out);
6890

69-
foreach (var s in e.Args) {
70-
stream.WriteLine(s);
71-
}
91+
using var stream = new StreamWriter(pipe);
92+
93+
pipe.Connect();
7294

73-
stream.Write($"{ARGS_DELIM}{ProcessHelper.GetParent().Id}");
95+
foreach (var s in e.Args) {
96+
stream.WriteLine(s);
7497
}
98+
99+
stream.Write($"{ARGS_DELIM}{ProcessHelper.GetParent().Id}");
100+
75101
}
76102

77103
public delegate void PipeMessageCallback(string s);
@@ -102,4 +128,5 @@ private void StartServer()
102128
};
103129
PipeThread.Start();
104130
}
131+
105132
}

SmartImage.UI/AppUtil.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,23 @@ public static double CalculateMSE(Bitmap image1, Bitmap image2)
285285
mse /= (width * height);
286286
return mse;
287287
}
288+
289+
[AM]
290+
[CA("null => halt")]
291+
private static void Assert1(object o)
292+
{
293+
var b = o != null;
294+
295+
Trace.Assert(b, $"{nameof(o)} was {null}!");
296+
}
297+
298+
[AM]
299+
[CA("false => halt")]
300+
public static void Assert2(bool b)
301+
{
302+
Trace.Assert(b, $"{b} was {false}!");
303+
}
304+
288305
}
289306

290307
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]

0 commit comments

Comments
 (0)