private void processdirectory(DirectoryInfo newdir) { if (!isactive) { return; } String directoryis = "Entering Directory: " + newdir.FullName; SubGenEventArgs neweventargs = new SubGenEventArgs(directoryis, false, ""); if (OnDirectoryChange != null) { OnDirectoryChange(this, neweventargs); } foreach (FileInfo file in newdir.GetFiles()) { processfile(file); } if (isrecursive) { foreach (DirectoryInfo nextdir in newdir.GetDirectories()) { processdirectory(nextdir); } } }
private void directoryevent(object sender, SubGenEventArgs e) { btn_start.Invoke((MethodInvoker) delegate() { String temp = e.resultstring; lb_results.Items.Add(temp); }); //methodinvoker is HANDY! }
private void processfile(FileInfo file) { if (!isactive) { return; } if ((file.Extension == ".mts") || (file.Extension == ".m2ts")) { try { String message = " Opening File: " + file.FullName; SubGenEventArgs neweventargs = new SubGenEventArgs(message, false, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } SubFile newvideofile = new SubFile(); newvideofile.FpsType = cameratype; newvideofile.VideoFile = file.FullName; newvideofile.MakeSubTitles(); newvideofile.RemoveSubTime(); String filename = " Processed File: " + file.FullName; neweventargs = new SubGenEventArgs(filename, false, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } if (showsubtime) { savesubtitles(file, newvideofile.FullSubOutput); } else { savesubtitles(file, newvideofile.NoTimeSubOutput); } } catch { String filename = " Error Processing File: " + file.FullName; SubGenEventArgs neweventargs = new SubGenEventArgs(filename, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } // // add code to actually generate and save the subtitles in here // try/catch to find errors and trigger appropriate event // //Thread.Sleep(2000); //to simulate reading a real file - erase when code wired up. } }
private void fileprocessed(object sender, SubGenEventArgs e) { btn_start.Invoke((MethodInvoker) delegate() { String temp = e.resultstring; lb_results.Items.Add(temp); //Cursor = Cursors.Default; }); //methodinvoker is HANDY! //counter++; }
//remember parentmtsfile is the name of the video file, not the output file private void savesubtitles(FileInfo parentmtsfile, string subtitles) { String videofilename = parentmtsfile.FullName; Regex rx = new Regex(@".m2{0,1}ts\z", RegexOptions.IgnoreCase); String savefilename = rx.Replace(videofilename, ".srt"); //for safety sake check to ensure that this is not the mts or m2ts file!!! FileInfo temp = new FileInfo(savefilename); if (temp.Extension == ".mts" || temp.Extension == ".m2ts") return; if (File.Exists(savefilename) && overwrite == true) { try { StreamWriter subfile_stream = new StreamWriter(savefilename, false); subfile_stream.Write(subtitles); subfile_stream.Close(); String message = " Saved file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, false, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } catch { String message = " Unalbe to write file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } } else if (File.Exists(savefilename) && overwrite == false) { String message = " File already exists: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } else { try { StreamWriter subfile_stream = new StreamWriter(savefilename, false); subfile_stream.Write(subtitles); subfile_stream.Close(); String message = " Saved file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } catch { String message = " Unalbe to write file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } } //Console.WriteLine(savefilename); }
private void processfile(FileInfo file) { if (!isactive) return; if ((file.Extension == ".mts") || (file.Extension == ".m2ts")) { try { String message = " Opening File: " + file.FullName; SubGenEventArgs neweventargs = new SubGenEventArgs(message, false, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } SubFile newvideofile = new SubFile(); newvideofile.FpsType = cameratype; newvideofile.VideoFile = file.FullName; newvideofile.MakeSubTitles(); newvideofile.RemoveSubTime(); String filename = " Processed File: " + file.FullName; neweventargs = new SubGenEventArgs(filename, false, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } if (showsubtime) { savesubtitles(file, newvideofile.FullSubOutput); } else { savesubtitles(file, newvideofile.NoTimeSubOutput); } } catch { String filename = " Error Processing File: " + file.FullName; SubGenEventArgs neweventargs = new SubGenEventArgs(filename, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } // // add code to actually generate and save the subtitles in here // try/catch to find errors and trigger appropriate event // //Thread.Sleep(2000); //to simulate reading a real file - erase when code wired up. } }
private void processdirectory(DirectoryInfo newdir) { if (!isactive) return; String directoryis = "Entering Directory: " + newdir.FullName; SubGenEventArgs neweventargs = new SubGenEventArgs(directoryis, false, ""); if (OnDirectoryChange != null) { OnDirectoryChange(this, neweventargs); } foreach (FileInfo file in newdir.GetFiles()) { processfile(file); } if (isrecursive) { foreach (DirectoryInfo nextdir in newdir.GetDirectories()) { processdirectory(nextdir); } } }
private void fileprocessed(object sender, SubGenEventArgs e) { btn_start.Invoke((MethodInvoker)delegate() { String temp = e.resultstring; lb_results.Items.Add(temp); //Cursor = Cursors.Default; }); //methodinvoker is HANDY! //counter++; }
private void directoryevent(object sender, SubGenEventArgs e) { btn_start.Invoke((MethodInvoker)delegate() { String temp = e.resultstring; lb_results.Items.Add(temp); }); //methodinvoker is HANDY! }
private void savesubtitles(FileInfo parentmtsfile, string subtitles) //remember parentmtsfile is the name of the video file, not the output file { String videofilename = parentmtsfile.FullName; Regex rx = new Regex(@".m2{0,1}ts\z", RegexOptions.IgnoreCase); String savefilename = rx.Replace(videofilename, ".srt"); //for safety sake check to ensure that this is not the mts or m2ts file!!! FileInfo temp = new FileInfo(savefilename); if (temp.Extension == ".mts" || temp.Extension == ".m2ts") { return; } if (File.Exists(savefilename) && overwrite == true) { try { StreamWriter subfile_stream = new StreamWriter(savefilename, false); subfile_stream.Write(subtitles); subfile_stream.Close(); String message = " Saved file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, false, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } catch { String message = " Unalbe to write file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } } else if (File.Exists(savefilename) && overwrite == false) { String message = " File already exists: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } else { try { StreamWriter subfile_stream = new StreamWriter(savefilename, false); subfile_stream.Write(subtitles); subfile_stream.Close(); String message = " Saved file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } catch { String message = " Unalbe to write file: " + savefilename; SubGenEventArgs neweventargs = new SubGenEventArgs(message, true, ""); if (OnSubgenResult != null) { OnSubgenResult(this, neweventargs); } } } //Console.WriteLine(savefilename); }