-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
87 lines (79 loc) · 3.19 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// Based on https://www.codeproject.com/Articles/290013/Formless-System-Tray-Application
using System;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
namespace TrayApp
{
internal static class Helper
{
public static bool NeedUpgrade = true;
public static System.Collections.Generic.List<string> Convert(System.Collections.Specialized.StringCollection collection)
{
System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
foreach (string item in collection)
{
list.Add(item);
}
return list;
}
public static System.Collections.Specialized.StringCollection Convert(System.Collections.Generic.List<string> list)
{
System.Collections.Specialized.StringCollection collection = new System.Collections.Specialized.StringCollection();
foreach (string item in list)
{
collection.Add(item);
}
return collection;
}
public static bool ValidateInput(string url)
{
return Uri.IsWellFormedUriString(url, UriKind.Absolute) && url.Contains(".") && url.Contains("http") && url.Contains("://");
}
}
internal static class Program
{
public static ProcessIcon currentIconInstance = new ProcessIcon();
public static string ProductName = ((AssemblyProductAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), true)[0]).Product;
internal static void ExceptionHandler(Exception exception)
{
// Meep.
System.Windows.Forms.MessageBox.Show(
exception.ToString(), ":( Sortahandled Exception! - " + ((AssemblyProductAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), true)[0]).Product.ToString(),
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
{
// Quit if already running
// https://stackoverflow.com/a/6392264
Mutex mutex = new System.Threading.Mutex(false, ProductName);
try
{
if (mutex.WaitOne(0, false))
{
// Run the application
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Show the system tray icon.
currentIconInstance.Display();
// Make sure the application runs!
Application.Run();
}
}
finally
{
if (mutex != null)
{
mutex.Close();
mutex = null;
}
}
}
}
}