Skip to content

Commit

Permalink
Remove file change detection
Browse files Browse the repository at this point in the history
Turns out that there's no reliable way of figuring out whether a plaintext
file is no longer being edited in a text editor, so don't bother with it.
Instead, display a messagebox asking the user whether they want to encrypt
or discard their changes as soon as the file is opened, allowing them to
click yes or no when they're finished.

It's not exactly pretty, but it's better than running the risk of leaving
plaintext files in the password store without the user knowing.
  • Loading branch information
Baggykiin committed Nov 11, 2016
1 parent 2af1858 commit 3a2c3ad
Showing 1 changed file with 1 addition and 40 deletions.
41 changes: 1 addition & 40 deletions pass-winmenu/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,46 +502,7 @@ private void EditPassword()
// Open the file in the user's default editor
var proc = Process.Start(plaintextFile);

// Wait for the text file to be written to
while (File.GetLastWriteTime(plaintextFile) < startTime)
{
Thread.Sleep(1000);
if ((DateTime.Now - startTime).Hours >= 2)
{
try
{
File.Delete(plaintextFile);
}
catch (IOException) { }
return;
}
}
// Wait for the file to be closed
bool inUse = true;
while (inUse)
{
try
{
var stream = File.Open(plaintextFile, FileMode.Open, FileAccess.Read, FileShare.None);
inUse = false;
stream.Close();
}
catch (IOException)
{
Thread.Sleep(1000);
}
if ((DateTime.Now - startTime).Hours >= 2)
{
try
{
File.Delete(plaintextFile);
}
catch (IOException) { }
return;
}
}

var result = MessageBox.Show($"Do you want to encrypt and save your changes to {Path.GetFileName(selectedFile)}?", "Edit password file", MessageBoxButton.YesNo, MessageBoxImage.Question);
var result = MessageBox.Show("Please keep this window open until you're done editing the password file.\nThen click Yes to save your changes, or No to discard them.", $"Save changes to {Path.GetFileName(selectedFile)}?", MessageBoxButton.YesNo, MessageBoxImage.Information);

if (result != MessageBoxResult.Yes)
{
Expand Down

0 comments on commit 3a2c3ad

Please sign in to comment.