private int DeleteFilesForNotepad(Notepad notepad) { int numDeleted = 0; try { lock (notepad.FileLock) { foreach ( string filename in Directory.GetFiles(SavedTextDirectory, string.Format("{0} *.txt", notepad.NotepadId))) { try { File.Delete(Path.Combine(SavedTextDirectory, filename)); } catch (Exception ex) { Log("Exception trying to delete notepad at " + filename, ex); } numDeleted++; } } } catch (Exception ex) { Log("Exception when deleting files for notepad " + notepad.NotepadId, ex); } return numDeleted; }
public bool SaveSnapshot(Notepad notepad) { try { string text = notepad.GetWindowText(); string notepadTitle = notepad.GetNotepadTitle(); string filename = string.Format("{0} {1}.txt", notepad.NotepadId, notepadTitle); string fullpath = Path.Combine(SavedTextDirectory, filename); DeleteFilesForNotepad(notepad); lock (notepad.FileLock) { File.WriteAllText(fullpath, text); } return true; } catch (Notepad.NotepadDeadException) { } catch (Exception ex) { Log("Exception saving notepad snapshot", ex, notepad.Pid); } return false; }
public Notepad RegisterNewNotepad(Notepad notepad) { Notepad gotten = _notepads.GetOrAdd(notepad.NotepadId, notepad); if (!object.ReferenceEquals(gotten, notepad)) { gotten.Pid = notepad.Pid; } NotepadCountMayHaveChanged(); return gotten; }
public void OnProcessExit(Notepad notepad, int exitCode) { if (exitCode == 0 && !_sessionEnded) { DeleteFilesForNotepad(notepad); } Notepad removed; _notepads.TryRemove(notepad.NotepadId, out removed); NotepadCountMayHaveChanged(); }
public void OnPingFailure(Notepad notepad) { Notepad removed; _notepads.TryRemove(notepad.NotepadId, out removed); NotepadCountMayHaveChanged(); }
public NotepadHookInstalledEventArgs(Notepad notepad) { this.Notepad = notepad; }