Templates working
This commit is contained in:
@ -6,9 +6,10 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.IO;
|
||||
|
||||
namespace WGneu {
|
||||
class Utils {
|
||||
public static class Utils {
|
||||
public static void SetInputChanged(Control input) {
|
||||
input.BorderBrush = Brushes.Orange;
|
||||
}
|
||||
@ -44,5 +45,46 @@ namespace WGneu {
|
||||
throw new ArgumentException("First argument has to be a decimal string");
|
||||
return a.Select(ch => ch - '0').Aggregate((sum, n) => (sum * 10 + n) % b);
|
||||
}
|
||||
|
||||
public sealed class TemporaryFile : IDisposable {
|
||||
private int Usages = 0;
|
||||
public string FilePath { get; private set; }
|
||||
|
||||
public TemporaryFile() : this("") {}
|
||||
|
||||
public TemporaryFile(string ext) : this(Path.GetTempPath(), ext) {}
|
||||
|
||||
public TemporaryFile(string dir, string ext) {
|
||||
FilePath = Path.Combine(dir, Path.GetRandomFileName() + ext);
|
||||
Usages++;
|
||||
Create();
|
||||
}
|
||||
|
||||
~TemporaryFile() {
|
||||
Delete();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
if (--Usages == 0) {
|
||||
Delete();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public TemporaryFile NewReference() {
|
||||
Usages++;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Create() {
|
||||
using (File.Create(FilePath)) {};
|
||||
}
|
||||
|
||||
private void Delete() {
|
||||
if (FilePath == null) return;
|
||||
File.Delete(FilePath);
|
||||
FilePath = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user