Skip to content

Commit 49fc0b8

Browse files
committed
Remove useless DllImport & flags
1 parent be72bb7 commit 49fc0b8

File tree

1 file changed

+0
-226
lines changed

1 file changed

+0
-226
lines changed

Flow.Launcher/Helper/SingleInstance.cs

Lines changed: 0 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.IO;
5-
using System.Runtime.InteropServices;
62
using System.IO.Pipes;
7-
using System.Security;
8-
using System.Text;
93
using System.Threading;
104
using System.Threading.Tasks;
115
using System.Windows;
@@ -14,172 +8,6 @@
148
// modified to allow single instace restart
159
namespace Flow.Launcher.Helper
1610
{
17-
internal enum WM
18-
{
19-
NULL = 0x0000,
20-
CREATE = 0x0001,
21-
DESTROY = 0x0002,
22-
MOVE = 0x0003,
23-
SIZE = 0x0005,
24-
ACTIVATE = 0x0006,
25-
SETFOCUS = 0x0007,
26-
KILLFOCUS = 0x0008,
27-
ENABLE = 0x000A,
28-
SETREDRAW = 0x000B,
29-
SETTEXT = 0x000C,
30-
GETTEXT = 0x000D,
31-
GETTEXTLENGTH = 0x000E,
32-
PAINT = 0x000F,
33-
CLOSE = 0x0010,
34-
QUERYENDSESSION = 0x0011,
35-
QUIT = 0x0012,
36-
QUERYOPEN = 0x0013,
37-
ERASEBKGND = 0x0014,
38-
SYSCOLORCHANGE = 0x0015,
39-
SHOWWINDOW = 0x0018,
40-
ACTIVATEAPP = 0x001C,
41-
SETCURSOR = 0x0020,
42-
MOUSEACTIVATE = 0x0021,
43-
CHILDACTIVATE = 0x0022,
44-
QUEUESYNC = 0x0023,
45-
GETMINMAXINFO = 0x0024,
46-
47-
WINDOWPOSCHANGING = 0x0046,
48-
WINDOWPOSCHANGED = 0x0047,
49-
50-
CONTEXTMENU = 0x007B,
51-
STYLECHANGING = 0x007C,
52-
STYLECHANGED = 0x007D,
53-
DISPLAYCHANGE = 0x007E,
54-
GETICON = 0x007F,
55-
SETICON = 0x0080,
56-
NCCREATE = 0x0081,
57-
NCDESTROY = 0x0082,
58-
NCCALCSIZE = 0x0083,
59-
NCHITTEST = 0x0084,
60-
NCPAINT = 0x0085,
61-
NCACTIVATE = 0x0086,
62-
GETDLGCODE = 0x0087,
63-
SYNCPAINT = 0x0088,
64-
NCMOUSEMOVE = 0x00A0,
65-
NCLBUTTONDOWN = 0x00A1,
66-
NCLBUTTONUP = 0x00A2,
67-
NCLBUTTONDBLCLK = 0x00A3,
68-
NCRBUTTONDOWN = 0x00A4,
69-
NCRBUTTONUP = 0x00A5,
70-
NCRBUTTONDBLCLK = 0x00A6,
71-
NCMBUTTONDOWN = 0x00A7,
72-
NCMBUTTONUP = 0x00A8,
73-
NCMBUTTONDBLCLK = 0x00A9,
74-
75-
SYSKEYDOWN = 0x0104,
76-
SYSKEYUP = 0x0105,
77-
SYSCHAR = 0x0106,
78-
SYSDEADCHAR = 0x0107,
79-
COMMAND = 0x0111,
80-
SYSCOMMAND = 0x0112,
81-
82-
MOUSEMOVE = 0x0200,
83-
LBUTTONDOWN = 0x0201,
84-
LBUTTONUP = 0x0202,
85-
LBUTTONDBLCLK = 0x0203,
86-
RBUTTONDOWN = 0x0204,
87-
RBUTTONUP = 0x0205,
88-
RBUTTONDBLCLK = 0x0206,
89-
MBUTTONDOWN = 0x0207,
90-
MBUTTONUP = 0x0208,
91-
MBUTTONDBLCLK = 0x0209,
92-
MOUSEWHEEL = 0x020A,
93-
XBUTTONDOWN = 0x020B,
94-
XBUTTONUP = 0x020C,
95-
XBUTTONDBLCLK = 0x020D,
96-
MOUSEHWHEEL = 0x020E,
97-
98-
99-
CAPTURECHANGED = 0x0215,
100-
101-
ENTERSIZEMOVE = 0x0231,
102-
EXITSIZEMOVE = 0x0232,
103-
104-
IME_SETCONTEXT = 0x0281,
105-
IME_NOTIFY = 0x0282,
106-
IME_CONTROL = 0x0283,
107-
IME_COMPOSITIONFULL = 0x0284,
108-
IME_SELECT = 0x0285,
109-
IME_CHAR = 0x0286,
110-
IME_REQUEST = 0x0288,
111-
IME_KEYDOWN = 0x0290,
112-
IME_KEYUP = 0x0291,
113-
114-
NCMOUSELEAVE = 0x02A2,
115-
116-
DWMCOMPOSITIONCHANGED = 0x031E,
117-
DWMNCRENDERINGCHANGED = 0x031F,
118-
DWMCOLORIZATIONCOLORCHANGED = 0x0320,
119-
DWMWINDOWMAXIMIZEDCHANGE = 0x0321,
120-
121-
#region Windows 7
122-
DWMSENDICONICTHUMBNAIL = 0x0323,
123-
DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326,
124-
#endregion
125-
126-
USER = 0x0400,
127-
128-
// This is the hard-coded message value used by WinForms for Shell_NotifyIcon.
129-
// It's relatively safe to reuse.
130-
TRAYMOUSEMESSAGE = 0x800, //WM_USER + 1024
131-
APP = 0x8000
132-
}
133-
134-
[SuppressUnmanagedCodeSecurity]
135-
internal static class NativeMethods
136-
{
137-
/// <summary>
138-
/// Delegate declaration that matches WndProc signatures.
139-
/// </summary>
140-
public delegate IntPtr MessageHandler(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled);
141-
142-
[DllImport("shell32.dll", EntryPoint = "CommandLineToArgvW", CharSet = CharSet.Unicode)]
143-
private static extern IntPtr _CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string cmdLine, out int numArgs);
144-
145-
146-
[DllImport("kernel32.dll", EntryPoint = "LocalFree", SetLastError = true)]
147-
private static extern IntPtr _LocalFree(IntPtr hMem);
148-
149-
150-
public static string[] CommandLineToArgvW(string cmdLine)
151-
{
152-
IntPtr argv = IntPtr.Zero;
153-
try
154-
{
155-
int numArgs = 0;
156-
157-
argv = _CommandLineToArgvW(cmdLine, out numArgs);
158-
if (argv == IntPtr.Zero)
159-
{
160-
throw new Win32Exception();
161-
}
162-
var result = new string[numArgs];
163-
164-
for (int i = 0; i < numArgs; i++)
165-
{
166-
IntPtr currArg = Marshal.ReadIntPtr(argv, i * Marshal.SizeOf(typeof(IntPtr)));
167-
result[i] = Marshal.PtrToStringUni(currArg);
168-
}
169-
170-
return result;
171-
}
172-
finally
173-
{
174-
175-
IntPtr p = _LocalFree(argv);
176-
// Otherwise LocalFree failed.
177-
// Assert.AreEqual(IntPtr.Zero, p);
178-
}
179-
}
180-
181-
}
182-
18311
public interface ISingleInstanceApp
18412
{
18513
void OnSecondAppStarted();
@@ -219,10 +47,6 @@ public static class SingleInstance<TApplication>
21947

22048
#endregion
22149

222-
#region Public Properties
223-
224-
#endregion
225-
22650
#region Public Methods
22751

22852
/// <summary>
@@ -264,56 +88,6 @@ public static void Cleanup()
26488

26589
#region Private Methods
26690

267-
/// <summary>
268-
/// Gets command line args - for ClickOnce deployed applications, command line args may not be passed directly, they have to be retrieved.
269-
/// </summary>
270-
/// <returns>List of command line arg strings.</returns>
271-
private static IList<string> GetCommandLineArgs( string uniqueApplicationName )
272-
{
273-
string[] args = null;
274-
275-
try
276-
{
277-
// The application was not clickonce deployed, get args from standard API's
278-
args = Environment.GetCommandLineArgs();
279-
}
280-
catch (NotSupportedException)
281-
{
282-
283-
// The application was clickonce deployed
284-
// Clickonce deployed apps cannot recieve traditional commandline arguments
285-
// As a workaround commandline arguments can be written to a shared location before
286-
// the app is launched and the app can obtain its commandline arguments from the
287-
// shared location
288-
string appFolderPath = Path.Combine(
289-
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), uniqueApplicationName);
290-
291-
string cmdLinePath = Path.Combine(appFolderPath, "cmdline.txt");
292-
if (File.Exists(cmdLinePath))
293-
{
294-
try
295-
{
296-
using (TextReader reader = new StreamReader(cmdLinePath, Encoding.Unicode))
297-
{
298-
args = NativeMethods.CommandLineToArgvW(reader.ReadToEnd());
299-
}
300-
301-
File.Delete(cmdLinePath);
302-
}
303-
catch (IOException)
304-
{
305-
}
306-
}
307-
}
308-
309-
if (args == null)
310-
{
311-
args = new string[] { };
312-
}
313-
314-
return new List<string>(args);
315-
}
316-
31791
/// <summary>
31892
/// Creates a remote server pipe for communication.
31993
/// Once receives signal from client, will activate first instance.

0 commit comments

Comments
 (0)