//添加到白名单 private void ToolStripMenuItemAddWhite_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { for (int i = 0; i < dataGridView1.SelectedRows.Count; i++) { string s = dataGridView1.SelectedRows[i].Cells[1].Value.ToString(); if (s != null) { MyProcess p = new MyProcess(s); if (!findProcessInWhite(p)) { //添加过程 whiteProcessList.processes.Add(new MyProcess(s)); XmlControl.SetWhite(GlobalConstants.WHITE_LIST_PATH, whiteProcessList); MessageBox.Show("添加成功!", "提示"); } else { MessageBox.Show("已存在。", "提示"); } } } } }
//寻找某个元素 private bool findProcessInWhite(MyProcess p) { foreach (MyProcess tmp in whiteProcessList.processes) { if (tmp.processName.Equals(p.processName)) return true; } return false; }
//进程监控 private void timer_Tick(object sender, EventArgs e) { sysProcess = Process.GetProcesses(); MyProcess mp = new MyProcess(); foreach (Process p in sysProcess) { if (p.ProcessName != null) { mp.processName = p.ProcessName; if (!findProcessInWhite(mp)) { //暂时将计时器停止 timer.Stop(); if (PopForm.popShow("提示", "进程" + mp.processName + "不在白名单中,是否关闭?\n\n点击是则将其关闭;\n点击否则将其加入白名单。\n不做任何处理则视为否。" ) == DialogResult.OK) { //强制进程退出,丢失所有的资源和数据 //结束没有图像界面的应用程序只能用这个方法 p.Kill(); } else { whiteProcessList.processes.Add(new MyProcess(mp.processName)); XmlControl.SetWhite(GlobalConstants.WHITE_LIST_PATH, whiteProcessList); } //重新开启 timer.Start(); } } } }
/// <summary> /// Ottiene i Metadata da un file Media in modalità sincrona /// </summary> /// <param name="Input">Path del file Media</param> /// <returns></returns> public static FFmpegMetadata GetMetadata(String Input) { if (!_Loaded) return null; if (CheckValidInput(Input)) { MyProcess p = new MyProcess(_PathFFmpeg, "-i \"" + Input + "\""); FFmpegMetadata temp = new FFmpegMetadata(); p.OnNewLine += (string line) => { if (line == null) return; else if (line.StartsWith(" LANGUAGE : ")) { temp.Language = line.RemoveLeft(" LANGUAGE : ").Trim(); } else if (line.StartsWith(" YEAR : ")) { temp.Year = line.RemoveLeft(" YEAR : ").Trim(); } else if (line.StartsWith(" TITLE : ")) { temp.Title = line.RemoveLeft(" TITLE : ").Trim(); } else if (line.StartsWith(" title : ")) { temp.Title = line.RemoveLeft(" title : ").Trim(); } else if (line.StartsWith(" ARTIST : ")) { temp.Artist = line.RemoveLeft(" ARTIST : ").Trim(); } else if (line.StartsWith(" artist :")) { temp.Artist = line.RemoveLeft(" artist :").Trim(); } else if (line.StartsWith(" ALBUM : ")) { temp.Album = line.RemoveLeft(" ALBUM : ").Trim(); } else if (line.StartsWith(" album :")) { temp.Album = line.RemoveLeft(" album :").Trim(); } else if (line.StartsWith(" DATE : ")) { temp.Date = line.RemoveLeft(" DATE : ").Trim(); } else if (line.StartsWith(" date : ")) { temp.Date = line.RemoveLeft(" date : ").Trim(); } else if (line.StartsWith(" GENRE : ")) { temp.Genre = line.RemoveLeft(" GENRE : ").Trim(); } else if (line.StartsWith(" genre :")) { temp.Genre = line.RemoveLeft(" genre :").Trim(); } else if (line.StartsWith(" COMMENT : ")) { temp.Comment = line.RemoveLeft(" COMMENT : ").Trim(); } else if (line.StartsWith(" track : ")) { temp.track = line.RemoveLeft(" track : ").Trim(); } else if (line.StartsWith(" ENSEMBLE : ")) { temp.Ensemble = line.RemoveLeft(" ENSEMBLE : ").Trim(); } else if (line.StartsWith(" Duration:")) { String[] sss = line.Split(','); if (sss.Length == 3) { temp.MediaMetadata.Duration = sss[0].RemoveLeft(" Duration: ").Trim(); temp.MediaMetadata.start = sss[1].RemoveLeft(" start: ").Trim(); temp.MediaMetadata.bitrate = sss[2].RemoveLeft(" bitrate: ").Trim(); } } else if (line.StartsWith(" Stream")) { String[] sss = line.Split(':'); if (sss.Length == 4 && sss[2].Contains("Audio")) { sss = sss[3].Split(','); if(sss.Length>1) { if(sss[0].Contains("flac")) { temp.MediaMetadata = new FFMpegMediaMetadataFlac(temp.MediaMetadata); try { (temp.MediaMetadata as FFMpegMediaMetadataFlac).SamplingRate= (SamplingRateInfo) Enum.Parse(typeof(SamplingRateInfo), "_" + sss[1].RemoveRight("Hz", " ").Trim()); if (sss[3].Contains("(")) { string bittemp = sss[3].Substring("(", ")").RemoveRight("bit", " ").Trim(); (temp.MediaMetadata as FFMpegMediaMetadataFlac).Bit = (BitInfo)Enum.Parse(typeof(BitInfo), "_" + bittemp); } } catch (Exception ex){ StreamWriter sw = File.AppendText("tetttmp.txt"); sw.WriteLine(Input + " " + ex.Message ); sw.Close(); } } else if (sss[0].Contains("mp3")) { temp.MediaMetadata = new FFMpegMediaMetadataMp3(temp.MediaMetadata); try { (temp.MediaMetadata as FFMpegMediaMetadataMp3).SamplingRate = (SamplingRateInfo)Enum.Parse(typeof(SamplingRateInfo), "_" + sss[1].RemoveRight("Hz", " ").Trim()); string bitrate = sss[4].RemoveRight("kb/s", " ").Trim(); int.TryParse(bitrate, out (temp.MediaMetadata as FFMpegMediaMetadataMp3).BitRateMp3); } catch (Exception ex) { //MessageBox.Show(ex.Message); StreamWriter sw = File.AppendText("tetttmp.txt"); sw.WriteLine(Input + " " + ex.Message); sw.Close(); } } else if (sss[0].Contains("pcm")) { temp.MediaMetadata = new FFMpegMediaMetadataWav(temp.MediaMetadata); try { (temp.MediaMetadata as FFMpegMediaMetadataWav).SamplingRate = (SamplingRateInfo)Enum.Parse(typeof(SamplingRateInfo), "_" + sss[1].RemoveRight("Hz", " ").Trim()); } catch (Exception ex) { StreamWriter sw = File.AppendText("tetttmp.txt"); sw.WriteLine(Input + " " + ex.Message); sw.Close(); } } } } } }; p.UseShellExecute = false; p.RedirectStandardOutput = true; p.RedirectStandardError = true; p.CreateNoWindow = true; p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.Async = false; p.Start(); return temp; } else return null; }
public static bool Mp3ToFlac(String Input, String Output, FFMpegMediaMetadataFlac ConversionParameters, bool OverrideIfExist, FFmpegConvertStatusChanged OnStatusChanged = null, FFmpegConvertProgressChanged OnProgressChanged = null, bool Async = true) { bool ret = true; Thread t = new Thread(() => { if (!_Loaded) { ret = false; return; } if (ConversionParameters == null || ConversionParameters.SamplingRate == SamplingRateInfo.nul || ConversionParameters.SamplingRate == 0 || ConversionParameters.Bit == BitInfo.nul) { ret = false; return; } if (CheckValidInput(Input) && CheckValidOutput(Output)) { if (File.Exists(Output)) { if (OverrideIfExist) File.Delete(Output); else { ret = false; return; } } if (OnStatusChanged != null) { OnStatusChanged(FFmpegStatus.Running, Input, Output); } MyProcess p = new MyProcess(_PathFFmpeg, "-i \"" + Input + "\" -map 0:1? -c copy " + JpgNameTemp+" -y"); p.UseShellExecute = false; p.RedirectStandardOutput = false; p.RedirectStandardError = false; p.CreateNoWindow = true; p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.Async = false; p.Start(); p = new MyProcess(_PathFFmpeg, "-i \"" + Input + "\" -map 0:0 -c:a:0 flac -map_metadata 0 -id3v2_version 3 -ar " + ConversionParameters.SamplingRate.ToStringReplace("_", "") + " \"" + Output + "\""); if (OnProgressChanged != null) { bool AspettaLaDurata = false; bool AspettaProgress = false; long TotalMilliSec = 0; p.OnNewLine += (string line) => { if (line == null) return; else if (line.StartsWith("Input")) { AspettaLaDurata = true; AspettaProgress = false; } else if (AspettaLaDurata && line.StartsWith(" Duration:")) { line = line.RemoveLeft(" Duration: "); line = line.SplitAndGetFirst(','); string[] ss = line.Split(':', '.'); if (ss.Length == 4) { AspettaLaDurata = false; AspettaProgress = true; TotalMilliSec = ss[3].ParseInt() * 10 + ss[2].ParseInt() * 1000 + ss[1].ParseInt() * 60000 + ss[0].ParseInt() * 3600000; } else { TotalMilliSec = -1; AspettaLaDurata = false; AspettaProgress = false; } } else if (AspettaProgress && line.Contains("No such file or directory")) { OnProgressChanged(-1, Input, Output, FFmpegError.DestFolderNotFound); } else if (AspettaProgress && (line.StartsWith("frame") || line.StartsWith("size"))) { line = line.Substring(line.IndexOf("time=") + 5, 11); string[] ss = line.Split(':', '.'); if (ss.Length == 4) { long current = ss[3].ParseInt() * 10 + ss[2].ParseInt() * 1000 + ss[1].ParseInt() * 60000 + ss[0].ParseInt() * 3600000; OnProgressChanged((int)((double)current / TotalMilliSec * 100), Input, Output); } } }; } p.UseShellExecute = false; p.RedirectStandardOutput = true; p.RedirectStandardError = true; p.CreateNoWindow = true; p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; SystemService.CreateFolderSecure(SystemService.GetParent(Output)); p.Async = false; p.Start(); if (SystemService.FileExist(JpgNameTemp)) { p = new MyProcess(_PathMetaflac, "--import-picture-from=\"" + JpgNameTemp + "\" \"" + Output+"\""); p.UseShellExecute = false; p.RedirectStandardOutput = false; p.RedirectStandardError = false; p.CreateNoWindow = true; p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.Async = false; p.Start(); } if (OnStatusChanged != null) { OnStatusChanged(FFmpegStatus.Stop, Input, Output); } } else { ret = false; return; } ret = true; }); t.Start(); if (!Async) t.Join(); return ret; /* ffmpeg.exe -i "07. Magic Box - Scream My Name (Radio Edit).mp3" -map 0:1? -c copy OUT.jpg ffmpeg.exe -i "07. Magic Box - Scream My Name (Radio Edit).mp3" -map 0:0 -c:a: 0 flac -map_metadata 0 -id3v2_version 3 out.flac metaflac --import-picture-from="OUT.jpg" out.flac */ }
public static bool CheckValidMetaflac(string pathMetaflac) { if (!SystemService.FileExist(pathMetaflac)) return false; MyProcess p = new MyProcess(pathMetaflac); bool valid = false; p.OnNewLine += (string line) => { if (line == null) return; else if (line.StartsWith("metaflac - Command-line FLAC metadata editor version")) { valid = true; } }; p.UseShellExecute = false; p.RedirectStandardOutput = true; p.RedirectStandardError = true; p.CreateNoWindow = true; p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.Async = false; p.Start(); return valid; }
public static bool FlacToMp3(String Input,String Output,FFMpegMediaMetadataMp3 ConversionParameters, bool OverrideIfExist,FFmpegConvertStatusChanged OnStatusChanged=null, FFmpegConvertProgressChanged OnProgressChanged=null, bool Async = true ) { if (!_Loaded) return false; if (ConversionParameters == null || ConversionParameters.SamplingRate == SamplingRateInfo.nul || ConversionParameters.SamplingRate == 0 || ConversionParameters.BitRateMp3 == 0) return false; if (CheckValidInput(Input) && CheckValidOutput(Output)) { if (File.Exists(Output)) { if (OverrideIfExist) File.Delete(Output); else return true; } MyProcess p = new MyProcess(_PathFFmpeg, "-i \"" + Input + "\" -map 0:0 -map 0:1? -c:a:0 libmp3lame -ab "+ ConversionParameters.BitRateMp3 + "k -ar "+ConversionParameters.SamplingRate.ToStringReplace("_","")+" -map_metadata 0 -id3v2_version 3 -c:v copy \"" + Output + "\""); if (OnStatusChanged != null) { p.OnStatusChanged += (ProcessStatus s) => { if (s == ProcessStatus.Running) OnStatusChanged(FFmpegStatus.Running, Input, Output); else if (s == ProcessStatus.Stop) OnStatusChanged(FFmpegStatus.Stop, Input, Output); }; } if (OnProgressChanged != null) { bool AspettaLaDurata = false; bool AspettaProgress = false; long TotalMilliSec = 0; p.OnNewLine += (string line) => { if (line == null) return; else if (line.StartsWith("Input")) { AspettaLaDurata = true; AspettaProgress = false; } else if (AspettaLaDurata && line.StartsWith(" Duration:")) { line = line.RemoveLeft(" Duration: "); line = line.SplitAndGetFirst(','); string[] ss=line.Split(':', '.'); if (ss.Length == 4) { AspettaLaDurata = false; AspettaProgress = true; TotalMilliSec = ss[3].ParseInt() * 10 + ss[2].ParseInt() * 1000 + ss[1].ParseInt() * 60000 + ss[0].ParseInt() * 3600000; } else { TotalMilliSec = -1; AspettaLaDurata = false; AspettaProgress = false; } } else if(AspettaProgress && line.Contains("No such file or directory")) { OnProgressChanged(-1, Input, Output,FFmpegError.DestFolderNotFound); } else if (AspettaProgress && ( line.StartsWith("frame") || line.StartsWith("size") )) { line = line.Substring(line.IndexOf("time=") + 5, 11); string[] ss = line.Split(':', '.'); if (ss.Length == 4) { long current = ss[3].ParseInt() * 10 + ss[2].ParseInt() * 1000 + ss[1].ParseInt() * 60000 + ss[0].ParseInt() * 3600000; OnProgressChanged((int)((double)current / TotalMilliSec * 100), Input, Output); } } }; } p.UseShellExecute = false; p.RedirectStandardOutput = true; p.RedirectStandardError = true; p.CreateNoWindow = true; p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; SystemService.CreateFolderSecure(SystemService.GetParent(Output)); p.Async = Async; p.Start(); } else return false; return true; }
public static bool CheckValidFFmpeg(String Path) { if (!SystemService.FileExist(Path)) return false; MyProcess p = new MyProcess(Path); bool valid = false; p.OnNewLine += (string line) => { if (line == null) return; else if (line.StartsWith("ffmpeg version")) { valid = true; } }; p.UseShellExecute = false; p.RedirectStandardOutput = true; p.RedirectStandardError = true; p.CreateNoWindow = true; p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; p.Async = false; p.Start(); return valid; }
public void CanNotDecreaseThePendingExecutionOfAFinishedProcess() { MyProcess process = WaitForProcessWithExecutionOfToFinish(720); process.decreasePenddingExecutionTime(10); }
public override void PlayAnswer(MyProcess chuck) { chuck.ExecuteCommand("chuck + Chuck_Scripts//PlayInterval.ck:70:.8:63:0:" + intervalStrings.IndexOf(answer)); }
public ModulesListView(MyProcess process) { InitializeComponent(); DataContext = new ModulesListViewModel(process); }
internal void Navigate(ViewType viewType, MyProcess process = null) { _navigationModel.Navigate(viewType, process); }