/// <summary> /// Write transcript for the clip if it available. /// </summary> /// <param name="clipId">Clip Id</param> /// <param name="clipPath">Path of current clip</param> public void WriteTranscriptFile(Clip clipId, string clipPath) { // Get all transcript to list List <ClipTranscript> clipTranscripts = clipId.Subtitle; if (clipTranscripts.Count > 0) { // Create transcript path with the same name of the clip string transcriptPath = Path.Combine(Path.GetDirectoryName(clipPath), Path.GetFileNameWithoutExtension(clipPath) + ".srt"); if (!File.Exists(transcriptPath)) { using (FileStream transcriptStream = File.OpenWrite(transcriptPath)) { using (StreamWriter writer = new StreamWriter(transcriptStream)) { // Write it to file with stream writer int i = 1; foreach (var clipTranscript in clipTranscripts) { var start = TimeSpan.FromMilliseconds(clipTranscript.StartTime).ToString(@"hh\:mm\:ss\,fff"); var end = TimeSpan.FromMilliseconds(clipTranscript.EndTime).ToString(@"hh\:mm\:ss\,fff"); writer.WriteLine(i++); writer.WriteLine(start + " --> " + end); writer.WriteLine(clipTranscript.Text); writer.WriteLine(); } } } bgwDecrypt.ReportProgress(1, new { Text = $"Transcript of {Path.GetFileName(clipPath)} generated.", Color = Color.Purple, newLine = false }); } } }
public void TestOpenWrite() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString(); try { using (File.Create(tempLongPathFilename)) { } using (var stream = File.OpenWrite(tempLongPathFilename)) { stream.WriteByte(42); } using (var stream = File.OpenRead(tempLongPathFilename)) { Assert.AreEqual(42, stream.ReadByte()); } } finally { File.Delete(tempLongPathFilename); } }
public static FileStream OpenWrite(string path) { return(File.OpenWrite(path)); }