private void setOpeningFileHook() { string ChannelName = null; RemoteHooking.IpcCreateServer <FileOpenMonitorInterface>(ref ChannelName, WellKnownObjectMode.SingleCall); Process[] procs = Process.GetProcesses(); foreach (Process proc in procs) { if ((proc.MainWindowTitle.Length > 0 || proc.ProcessName.ToLower().Equals("explorer")) && !proc.ProcessName.ToLower().Equals("dropbox") && !proc.ProcessName.ToLower().Equals("ConflictReaperclient") && !proc.ProcessName.ToLower().Equals("ConflictReaperclient.vshost") && !proc.ProcessName.ToLower().Equals("shellexperiencehost") && !proc.ProcessName.ToLower().Equals("cmd") && !proc.ProcessName.ToLower().Equals("taskmgr") && !proc.ProcessName.ToLower().Equals("regedit")) { System.Diagnostics.Debug.WriteLine(proc.Id + " " + proc.ProcessName + " " + proc.MainWindowTitle); HookInjector injector = new HookInjector(proc.Id, ChannelName); injector.Inject(); } if ((proc.MainWindowTitle.Length > 0 && !proc.ProcessName.ToLower().Equals("explorer")) && !proc.ProcessName.ToLower().Equals("dropbox") && !proc.ProcessName.ToLower().Equals("ConflictReaperclient") && !proc.ProcessName.ToLower().Equals("ConflictReaperclient.vshost") && !proc.ProcessName.ToLower().Equals("shellexperiencehost") && !proc.ProcessName.ToLower().Equals("cmd") && !proc.ProcessName.ToLower().Equals("taskmgr") && !proc.ProcessName.ToLower().Equals("regedit")) { proc.Exited += (s, e) => { Thread.Sleep(500); global.files.ProcessExit(proc.Id); if (global.ProcessesThatOpenFile.Contains(proc.Id)) { global.ProcessesThatOpenFile.Remove(proc.Id); } }; } } }
public MainWindow() { InitializeComponent(); AppDomain.CurrentDomain.AssemblyResolve += Resolver; initNotifyIcon(); this.ResizeMode = ResizeMode.NoResize; this.Closing += (o, e) => { exitProgram(); }; this.Loaded += (o, e) => { mswin.Owner = this; Process[] procs = Process.GetProcessesByName("Dropbox"); if (procs.Length == 0) { MessageBox.Show("Dropbox is not running!", "ConflictReaper"); this.Hide(); exitProgram(); } DropBoxProcessIds = new int[procs.Length]; for (int i = 0; i < procs.Length; i++) { DropBoxProcessIds[i] = procs[i].Id; } keyboardHook = new KeyboardHook(); keyboardHook.InstallHook(); }; this.LocationChanged += (o, e) => { mswin.Left = Left + (Width - mswin.Width) / 2; mswin.Top = Top + (Height - mswin.Height) / 2; }; global.OnRefresh += RefreshDatagrid; global.files.OnProcessExit += (s, e) => { WatchDogMessage message = new WatchDogMessage(WatchDogMessageType.UnLock, global.User, e.filename, 0, 0, global.DropboxBasePath); sendMessage(message); }; global.files.OnFileEdit += (s, e) => { WatchDogMessage message = new WatchDogMessage(WatchDogMessageType.Lock, global.User, e.filename, global.DropboxBasePath); sendMessage(message); }; KeyboardHook.OnKeyboardInput += (s, e) => { KeyboardHook.HookStruct data = e.hookData; int key = data.vkCode; if (e.wParam == 256) { if (key == 162 || key == 163) { isCtrlDown = true; return; } if (key == 164 || key == 165) { isAltDown = true; return; } if (key == 160 || key == 161) { isShiftDown = true; return; } if ((isAltDown == false && isShiftDown == false && isCtrlDown == false && ((key >= 48 && key <= 57) || (key >= 65 && key <= 90) || (key >= 186 && key <= 192) || (key >= 219 && key <= 222) || key == 8 || key == 9 || key == 13 || key == 32 || key == 46)) || isCtrlDown == true && (key == 86 || key == 88)) { int FocusedProcessId; GetWindowThreadProcessId(GetForegroundWindow(), out FocusedProcessId); //if (global.ProcessesThatOpenFile.Contains(FocusedProcessId)) //{ string title = Process.GetProcessById(FocusedProcessId).MainWindowTitle; System.Diagnostics.Debug.WriteLine(title); global.files.FileEdit(title); //} } } if (e.wParam == 257) { if (key == 162 || key == 163) { isCtrlDown = false; return; } if (key == 164 || key == 165) { isAltDown = false; return; } if (key == 160 || key == 161) { isShiftDown = false; return; } } }; FileOpenMonitorInterface.OnFileOpening += (object sender, FileOpeningEventArg e) => { String Filename = null; int procId; if (e.filename.StartsWith("CreateFile")) { procId = e.id; Filename = e.filename.Substring(11); if (!File.Exists(Filename)) { return; } } else { string[] Args = e.filename.Split('|'); procId = int.Parse(Args[3]); HookInjector injector = new HookInjector(procId, Args[4]); injector.Inject(); int start = Args[2].IndexOf('\"', 1) + 2; Filename = praseFilename(Args[2], start); if (Filename != null && Filename.StartsWith(global.DropboxPath)) { Process proc = Process.GetProcessById(procId); if (global.ProcessesThatOpenFile.Contains(proc.Id)) { proc.Exited += (s, earg) => { Thread.Sleep(500); global.files.ProcessExit(proc.Id); global.ProcessesThatOpenFile.Remove(proc.Id); } } ; } } if (Filename != null && Filename.StartsWith(global.DropboxPath)) { if (!global.ProcessesThatOpenFile.Contains(procId)) { global.ProcessesThatOpenFile.Add(procId); } global.files.setStatus(Filename, FileStatus.Open, true); global.files.ProcessOpen(procId, Filename); } }; ConflictReaperWebSocketHandler.OnLockChange += OnWebSocketMessage; emailBox.Text = Properties.Settings.Default.email; passwordBox.Password = Properties.Settings.Default.pwd; pathBox.Text = Properties.Settings.Default.dropboxPath; global.User = Properties.Settings.Default.user; }