38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
|
using System;
|
||
|
using System.Threading;
|
||
|
using UpToolLib.DataStructures;
|
||
|
using UpToolLib.v1;
|
||
|
using UpToolLib.v2;
|
||
|
|
||
|
namespace UpToolLib
|
||
|
{
|
||
|
public class UpToolLibMain : IDisposable
|
||
|
{
|
||
|
private static Mutex _mutex;
|
||
|
public UpToolLibMain(IExternalFunctionality platform)
|
||
|
{
|
||
|
V1 = new UpToolLibV1(platform);
|
||
|
V2 = new UpToolLibV2(platform, V1.Installer, V1.AppExtras, V1.PathTool, V1.XmlTool, V1.Apps);
|
||
|
_mutex = new Mutex(false,
|
||
|
"Global\\{c0c1e002-9e13-4e8f-a035-dbdc5128e00e}",
|
||
|
out bool _);
|
||
|
try
|
||
|
{
|
||
|
if (_mutex.WaitOne(5000, false))
|
||
|
return;
|
||
|
throw new MutexLockLockedException();
|
||
|
}
|
||
|
catch (AbandonedMutexException)
|
||
|
{
|
||
|
#if DEBUG
|
||
|
_platform.Log("Mutex abandoned");
|
||
|
#endif
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public readonly UpToolLibV1 V1;
|
||
|
public readonly UpToolLibV2 V2;
|
||
|
public void Dispose() => _mutex.ReleaseMutex();
|
||
|
~UpToolLibMain() => Dispose();
|
||
|
}
|
||
|
}
|