Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalDb #969

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Try to delete LockFile on dispose
ideka committed Jul 22, 2024
commit b9167714817b2cd398b94eabad63b4bc0759c3fc
13 changes: 10 additions & 3 deletions Blish HUD/GameServices/LocalDb/LockFile.cs
Original file line number Diff line number Diff line change
@@ -5,22 +5,29 @@

namespace Blish_HUD.LocalDb {
internal class LockFile : IDisposable {
private readonly string _path;
private readonly FileStream _stream;

private LockFile(FileStream stream) {
_stream = stream;
private LockFile(string path) {
_path = path;
_stream = File.Open(_path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
}

public static LockFile? TryAcquire(string path) {
try {
return new LockFile(File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
return new LockFile(path);
} catch (IOException e) when (e.GetType() == typeof(IOException)) {
return null;
}
}

public void Dispose() {
_stream.Dispose();
try {
File.Delete(_path);
} catch {
// Ignore
}
}
}
}