From 3a2c3add3241457c0ec23e41bb2ac9324b451570 Mon Sep 17 00:00:00 2001 From: Baggykiin Date: Fri, 11 Nov 2016 11:22:43 +0100 Subject: [PATCH] Remove file change detection 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. --- pass-winmenu/src/Program.cs | 41 +------------------------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/pass-winmenu/src/Program.cs b/pass-winmenu/src/Program.cs index a8770ad..696f84d 100644 --- a/pass-winmenu/src/Program.cs +++ b/pass-winmenu/src/Program.cs @@ -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) {