Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca97ec2106 | ||
|
|
e347e00827 | ||
|
|
fa346725bc | ||
|
|
acf90704a8 | ||
|
|
845b733326 | ||
|
|
1823bb05a1 | ||
|
|
3988395c0a | ||
|
|
bcfb499bd0 |
+49
-38
@@ -3,45 +3,56 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BlubbFish.Utils
|
||||
{
|
||||
public class FileLogger
|
||||
{
|
||||
private static Dictionary<string, FileLogger> instances = new Dictionary<string, FileLogger>();
|
||||
private StreamWriter file;
|
||||
private FileLogger(string filename, bool append)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
string folder = Path.GetDirectoryName(Path.GetFullPath(filename));
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
}
|
||||
this.file = new StreamWriter(filename, append, Encoding.UTF8);
|
||||
this.file.AutoFlush = true;
|
||||
}
|
||||
public static FileLogger getInstance(string filename, bool append)
|
||||
{
|
||||
if (!instances.Keys.Contains(filename))
|
||||
{
|
||||
instances.Add(filename, new FileLogger(filename, append));
|
||||
}
|
||||
return instances[filename];
|
||||
}
|
||||
|
||||
public void setArray(string[] text)
|
||||
{
|
||||
this.file.Write(String.Join(file.NewLine, text) + file.NewLine);
|
||||
this.file.Flush();
|
||||
}
|
||||
|
||||
public void setLine(string text)
|
||||
{
|
||||
this.file.WriteLine(text);
|
||||
this.file.Flush();
|
||||
namespace BlubbFish.Utils {
|
||||
public class FileLogger {
|
||||
private static Dictionary<string, FileLogger> instances = new Dictionary<string, FileLogger>();
|
||||
private static String logDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
|
||||
private StreamWriter file;
|
||||
private FileLogger(string filename, bool append) {
|
||||
filename = logDir + filename;
|
||||
if(!File.Exists(filename)) {
|
||||
string folder = Path.GetDirectoryName(Path.GetFullPath(filename));
|
||||
if(!Directory.Exists(folder)) {
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
}
|
||||
this.file = new StreamWriter(filename, append, Encoding.UTF8);
|
||||
this.file.AutoFlush = true;
|
||||
}
|
||||
public static FileLogger getInstance(string filename, bool append) {
|
||||
if(!instances.Keys.Contains(filename)) {
|
||||
instances.Add(filename, new FileLogger(filename, append));
|
||||
}
|
||||
return instances[filename];
|
||||
}
|
||||
|
||||
public static void setLogDir(String v) {
|
||||
v = v.Replace("..", "");
|
||||
v = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + v;
|
||||
if(Directory.Exists(v)) {
|
||||
logDir = v;
|
||||
} else {
|
||||
Directory.CreateDirectory(v);
|
||||
logDir = v;
|
||||
}
|
||||
if(logDir.Substring(logDir.Length - 1) != Path.DirectorySeparatorChar.ToString()) {
|
||||
logDir = logDir + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
|
||||
public void setArray(string[] text) {
|
||||
this.file.Write(String.Join(file.NewLine, text) + file.NewLine);
|
||||
this.file.Flush();
|
||||
}
|
||||
|
||||
public void setLine(string text) {
|
||||
this.file.WriteLine(text);
|
||||
this.file.Flush();
|
||||
}
|
||||
public void setLine(string text, DateTime d) {
|
||||
this.setLine(d.ToString("[yyyy-MM-dd HH:mm:ss.ffff] ") + text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,6 @@ namespace BlubbFish.Utils
|
||||
this.init();
|
||||
}
|
||||
abstract protected void init();
|
||||
abstract public void Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Utils")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[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.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.2.1")]
|
||||
[assembly: AssemblyFileVersion("1.0.2.1")]
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="CmdArgs.cs" />
|
||||
<Compile Include="FileLogger.cs" />
|
||||
<Compile Include="FileMutex.cs" />
|
||||
<Compile Include="InIReader.cs" />
|
||||
<Compile Include="OwnController.cs" />
|
||||
<Compile Include="OwnModel.cs" />
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user