private List <INSPECTPROCESS> fileReader(string path) { try { var seperator = new List <INSPECTPROCESS>(); var shouldRewrite = false; var line = ""; //var tempwriter = new List<string> { $"### ONLY PROCESSES NAME ARE GIVEN BELOW THIS LINE IN FORM OF NAME,PROCESS NAME.EXE , ANY LINE WITH SHARP(#) WOULD BE IGNORED [Note that the order of the processes is affect the performance, please set the first to be what often use] ###" }; var tempwriter = new List <string> { $"#Process Name,Application Name" }; using (var reader = new StreamReader(path)) { while ((line = reader.ReadLine()) != null) { if (line == "") { shouldRewrite = true; continue; } if (line.IndexOf("#") == -1) //line contain no # inside { var inspect = new INSPECTPROCESS(); inspect.process_name = line.Split(',')[0]; inspect.real_process = line.Split(',')[1]; seperator.Add(inspect); tempwriter.Add(string.Format("{0}", line)); } } } if (shouldRewrite) { using (var wr = new StreamWriter(settingfile)) { tempwriter.ForEach(x => wr.WriteLine(x)); } } return(seperator); } catch (FileNotFoundException ex) { MessageBox.Show("Settings file has not been generated yet, please restart the program."); Environment.Exit(0); return(null); }; }
private void ProcessScanner() { INSPECTPROCESS latestProcess = default(INSPECTPROCESS); while (true) { if (GoingOn) { var dataset = fileReader($@"{Path.Combine(Path.GetTempPath(), Properties.Settings.Default.SettngsFilePath)}"); //reloading the settings file INSPECTPROCESS currentProcess = default(INSPECTPROCESS); var shouldShowing = false; foreach (var proc in Process.GetProcesses()) { currentProcess = dataset.Find(process => process.real_process == $"{proc.ProcessName}.exe"); if (dataset.Contains(currentProcess)) { shouldShowing = true; if (!latestProcess.Equals(currentProcess)) { DeletePreviousPost(); dynamic param = new ExpandoObject(); param.message = $"Currently playing {currentProcess.process_name} on {Environment.MachineName}, started from {DateTime.Now.ToString("hh:mm tt")}!"; facebookClient.Post("me/feed", param); //facebookService.PostOnWallAsync(accessToken, $"Currently playing {currentProcess.process_name} on {Environment.MachineName}, started from {DateTime.Now.ToString("hh:mm tt")}!"); latestProcess = currentProcess; } break; } } fuckTheseObject(label1, Color.Green, $"Currently on {currentProcess.process_name ?? "Desktop"}"); ProcessFlag = currentProcess.real_process; ControlInvokeRequired(button3, () => button3.Visible = shouldShowing); } else { fuckTheseObject(label1, Color.Red, "inspecthelper is not running"); } Thread.Sleep(1000); } }