Example #1
0
 private void ProcessWatcherOnNotepadSlowOpenEvent(object sender, ProcessWatcher.NotepadSlowOpenEventArgs notepadSlowOpenEventArgs)
 {
     int pid = notepadSlowOpenEventArgs.ProcessId;
     string realFilePath = Notepad.GetRealFilePath(pid);
     if (!string.IsNullOrEmpty(realFilePath) && Path.GetDirectoryName(realFilePath) != Path.Combine(SavedTextDirectory, "tmp"))
     {
         _notifyIcon.Tag = new BalloonTipData()
         {
             Reason = BalloonTipReason.LargeFileSlowOpen,
             RealFilePath = realFilePath,
             ProcessId = pid
         };
         _notifyIcon.ShowBalloonTip(10000, "Notepad is opening slowly", "Click to preview truncated text", ToolTipIcon.Warning);
     }
 }
Example #2
0
            private void TimerInitOnTick(object sender, EventArgs eventArgs)
            {
                ((Timer) sender).Stop();

                // message pump is pumping, so we can start up a few things now

                string startupMessage;
                if (!Notepad.CheckStartupSuccess(out startupMessage))
                {
                    StartupFailure(startupMessage);
                    return;
                }

                if (_startupException != null)
                {
                    StartupFailure(_startupException.Message, _startupException);
                    Trace.WriteLine(_startupException.ToString());
                    return;
                }

                try
                {
                    _processWatcher = new ProcessWatcher(_hiddenForm.Handle, true);
                    _processWatcher.NotepadHookInstalledEvent += ProcessWatcherOnNotepadHookInstalledEvent;
                    _processWatcher.NotepadSlowOpenEvent += ProcessWatcherOnNotepadSlowOpenEvent;
                    _processWatcher.NotepadReallySlowOpenEvent += ProcessWatcherOnNotepadReallySlowOpenEvent;
                }
                catch (Exception ex)
                {
                    StartupFailure("Could not start process watcher: " + ex.Message, ex);
                    Trace.WriteLine(ex.ToString());
                    return;
                }

                // wait for any existing notepads to be re-subclassed before prompting a restore
                try
                {
                    if (!CheckHookExistingComplete())
                    {
                        // start polling
                        Timer timerCheckHookExisting = new Timer {Interval = 500, Tag = Environment.TickCount};
                        timerCheckHookExisting.Tick += TimerCheckHookExistingOnTick;
                        timerCheckHookExisting.Start();
                        // safeguard: ensure Restore menu item is eventually enabled
                        Timer timerForceRestoreEnable = new Timer();
                        timerForceRestoreEnable.Interval = MAX_WAIT_FOR_HOOK_EXISTING;
                        timerForceRestoreEnable.Tick += delegate(object o, EventArgs args)
                        {
                            _menuRestoreAll.Enabled = true;
                            ((Timer) o).Stop();
                        };
                        timerForceRestoreEnable.Start();
                    }
                }
                catch (Exception ex)
                {
                    NotepadController.Log("Exception waiting for hook existing notepads", ex);
                }
            }
Example #3
0
 private void ProcessWatcherOnNotepadHookInstalledEvent(object sender, ProcessWatcher.NotepadHookInstalledEventArgs notepadHookInstalledEventArgs)
 {
     Notepad notepad = notepadHookInstalledEventArgs.Notepad;
     if (notepad.LooksUnixy())
     {
         string realFilePath = notepad.RealFilePath;
         if (!string.IsNullOrEmpty(realFilePath))
         {
             _notifyIcon.Tag = new BalloonTipData()
             {
                 Reason = BalloonTipReason.UnixyLineEndings,
                 RealFilePath = realFilePath,
                 ProcessId = notepad.Pid
             };
             _notifyIcon.ShowBalloonTip(10000, "Unix line endings detected", "Click to open this file in Wordpad", ToolTipIcon.Info);
         }
     }
 }