diff --git a/FileMutex.cs b/FileMutex.cs new file mode 100644 index 0000000..4d3b696 --- /dev/null +++ b/FileMutex.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace BlubbFish.Utils { + public class FileMutex { + private static FileMutex instance; + private String filename; + private StreamWriter file; + private FileMutex() { } + + public static FileMutex Instance { + get { + if(FileMutex.instance == null) { + FileMutex.instance = new FileMutex(); + } + return FileMutex.instance; + } + } + + public void setName(string name) { + string path = AppDomain.CurrentDomain.BaseDirectory; + this.filename = path + string.Join(string.Empty, Array.ConvertAll(new SHA512Managed().ComputeHash(Encoding.UTF8.GetBytes(name)), b => b.ToString("X2"))) + ".lock.txt"; + } + + public bool create() { + if(File.Exists(this.filename)) + return false; + this.file = new StreamWriter(this.filename); + this.initFile(); + return File.Exists(this.filename) && file != null; + } + + private void initFile() { + this.file.Write("Created: " + DateTime.Now.ToUniversalTime()+"\n"); + this.file.Flush(); + } + + public bool delete() { + this.file.Close(); + File.Delete(this.filename); + return !File.Exists(this.filename); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index f78913c..a08c1a0 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Utils")] -[assembly: AssemblyCopyright("Copyright © 2014 - 03.12.2016")] +[assembly: AssemblyCopyright("Copyright © 2014 - 03.03.2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.1")] -[assembly: AssemblyFileVersion("1.0.0.1")] +[assembly: AssemblyVersion("1.0.2.1")] +[assembly: AssemblyFileVersion("1.0.2.1")] diff --git a/Utils.csproj b/Utils.csproj index 22e3a26..7afa00f 100644 --- a/Utils.csproj +++ b/Utils.csproj @@ -42,6 +42,7 @@ + diff --git a/bin/Release/Utils.dll b/bin/Release/Utils.dll index ddf2ca2..e24b721 100644 Binary files a/bin/Release/Utils.dll and b/bin/Release/Utils.dll differ