Skip to content

Commit 4ca303f

Browse files
committed
3.0.1.3
Fixed The Ability To Launch More Than 1 Instance Of USM. Fixed TickTimer Form Showing When Doing Alt+Tab.
1 parent bc0c1e8 commit 4ca303f

File tree

7 files changed

+68
-37
lines changed

7 files changed

+68
-37
lines changed

Data/USMVer.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.1.2
1+
3.0.1.3

Data/Versions.zip

0 Bytes
Binary file not shown.

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
----------- Unturned Server Manager -----------
22

3-
Version: Public 3.0.1.2
3+
Version: Public 3.0.1.3
44

55
[![Github Releases](https://img.shields.io/github/downloads/persiafighter/UnturnedServerManager/latest/total.svg?style=plastic)](https://github.com/persiafighter/UnturnedServerManager/releases/tag/v3.0.0.5) [![GitHub issues](https://img.shields.io/github/issues/persiafighter/UnturnedServerManager.svg?style=plastic)](https://github.com/persiafighter/UnturnedServerManager/issues) [![GitHub closed issues](https://img.shields.io/github/issues-closed/persiafighter/UnturnedServerManager.svg?style=plastic)]()
66

@@ -55,6 +55,11 @@ https://www.reddit.com/r/unturned/comments/546y67/unturned_server_manager/
5555

5656
#Changelog:
5757

58+
**V3.0.1.3** -
59+
60+
* Fixed The Ability To Launch More Than 1 Instance Of USM.
61+
* Fixed TickTimer Form Showing When Doing Alt+Tab.
62+
5863
**V3.0.1.2** -
5964

6065
* Fixed A Problem With Plugin Integrity Update.

USM/Boot.cs

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
42
using System.IO;
5-
using System.Linq;
6-
using System.Net;
3+
using System.Reflection;
4+
using System.Runtime.InteropServices;
5+
using System.Security.AccessControl;
6+
using System.Security.Principal;
77
using System.Threading;
8-
using System.Threading.Tasks;
98
using System.Windows.Forms;
109

1110
namespace USM
@@ -17,7 +16,7 @@ static void Main()
1716
{
1817
Application.EnableVisualStyles();
1918
Application.SetCompatibleTextRenderingDefault(false);
20-
new TickTimer().Show();
19+
new TickTimer();
2120
if (Directory.Exists(Comms.DataPath) == false)
2221
{
2322
Directory.CreateDirectory(Comms.DataPath);
@@ -30,22 +29,47 @@ static void Main()
3029
Logger.Log("Created log file.");
3130
StartApp();
3231
}
32+
3333
private static void StartApp()
3434
{
35-
string appGuid = "2d1dcd0a-9719-44f5-8f0e-2fd79d918fb5";
35+
string appGuid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString();
36+
string mutexId = string.Format("Global\\{{{0}}}", appGuid);
37+
var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow);
38+
var securitySettings = new MutexSecurity();
39+
securitySettings.AddAccessRule(allowEveryoneRule);
3640
try
3741
{
38-
using (Mutex mutex = new Mutex(false, "Global\\" + appGuid))
42+
bool createdNew;
43+
using (var mutex = new Mutex(false, mutexId, out createdNew, securitySettings))
3944
{
40-
if (!mutex.WaitOne(0, false))
45+
var hasHandle = false;
46+
try
47+
{
48+
try
49+
{
50+
hasHandle = mutex.WaitOne(0, false);
51+
if (hasHandle == false)
52+
{
53+
MessageBox.Show("Another instance of unturned server manager is already running!", "Unturned Server Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
54+
return;
55+
}
56+
}
57+
catch (AbandonedMutexException)
58+
{
59+
hasHandle = true;
60+
}
61+
Logger.Log("Started main application.");
62+
Application.Run(new Manager());
63+
Logger.Log("Main application was closed.");
64+
}
65+
finally
4166
{
42-
MessageBox.Show("Another instance of unturned server manager is already running!", "Unturned Server Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
43-
return;
67+
if (hasHandle)
68+
{
69+
mutex.ReleaseMutex();
70+
}
4471
}
4572
}
46-
Logger.Log("Started main application.");
47-
Application.Run(new Manager());
48-
Logger.Log("Main application was closed.");
4973
}
5074
catch (Exception e)
5175
{
@@ -59,37 +83,39 @@ private static void StartApp()
5983
}
6084
}
6185

62-
public class TickTimer : Form
86+
public class TickTimer
6387
{
64-
public System.ComponentModel.IContainer components;
6588
public System.Windows.Forms.Timer Timer;
6689
public static decimal ProgramTime = 0.00M;
6790
public TickTimer()
6891
{
69-
Opacity = 0;
70-
ShowInTaskbar = false;
71-
ShowIcon = false;
72-
Hide();
73-
components = new System.ComponentModel.Container();
7492
Timer = new System.Windows.Forms.Timer();
7593
Timer.Interval = 10;
7694
Timer.Tick += new EventHandler(Timer_tick);
7795
Timer.Start();
96+
Logger.Log("Started timer to keep the program time.");
7897
}
7998

80-
private void Timer_tick(object Sender, EventArgs e)
99+
public void Dispose()
81100
{
82-
ProgramTime += 0.01M;
101+
Dispose(true);
102+
GC.SuppressFinalize(this);
83103
}
84104

85-
protected override void Dispose(bool disposing)
105+
bool disposed = false;
106+
protected virtual void Dispose(bool disposing)
86107
{
87-
// Clean up any components being used.
88-
if (disposing)
89-
if (components != null)
90-
components.Dispose();
108+
if (disposed)
109+
{
110+
return;
111+
}
112+
Timer.Dispose();
113+
disposed = true;
114+
}
91115

92-
base.Dispose(disposing);
116+
private void Timer_tick(object Sender, EventArgs e)
117+
{
118+
ProgramTime += 0.01M;
93119
}
94120
}
95121
}

USM/Manager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ private void CheckLatestVersion()
186186
Downloader.Extract("USM.zip", Downloader.Temp);
187187
string LatestVersion = File.ReadAllLines(Downloader.Temp + @"\Versions.dat")[2];
188188
Logger.Log("Read data from latest USM version.");
189-
if (LatestVersion != "3.0.1.2")
189+
if (LatestVersion != "3.0.1.3")
190190
{
191191
Logger.Log("Version of the program is different than the latest one. Opened notification of a new update.");
192-
Notifier.ShowBalloonTip(5000, "New Version", "A new version for Unturned Server Manager is available! Head over to the github page for more information. Your version: 3.0.1.2, Latest Version: " + LatestVersion + ".", ToolTipIcon.None);
192+
Notifier.ShowBalloonTip(5000, "New Version", "A new version for Unturned Server Manager is available! Head over to the github page for more information. Your version: 3.0.1.3, Latest Version: " + LatestVersion + ".", ToolTipIcon.None);
193193
}
194194
Downloader.ShutOff();
195195
Logger.Log("Deleted temp download folder.");

USM/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
[assembly: AssemblyCulture("")]
1111
[assembly: ComVisible(false)]
1212
[assembly: Guid("2d1dcd0a-9719-44f5-8f0e-2fd79d918fb5")]
13-
[assembly: AssemblyVersion("3.0.1.2")]
14-
[assembly: AssemblyFileVersion("3.0.1.2")]
13+
[assembly: AssemblyVersion("3.0.1.3")]
14+
[assembly: AssemblyFileVersion("3.0.1.3")]

USM/Updater.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)