public static void Commit(MontageAction action) { var now = DateTime.Now; var time = (int)(now - recordStartTime).TotalMilliseconds; var cmd = new MontageCommand { Action = action, Time = time, Id = Log.Id, }; MontageCommandIO.AppendCommand(cmd, FileName); Id++; if (action == MontageAction.Commit) { goodSplitTime += now - lastCommitTime; } if (action == MontageAction.CommitAndSplit) { goodStartTime += goodSplitTime; goodSplitTime = new TimeSpan(); } lastCommitTime = now; }
public static void AppendCommand(MontageCommand command, string filename) { using (var writer = new StreamWriter(filename, true)) { WriteCommand(writer, command); } }
static void WriteCommand(StreamWriter writer, MontageCommand command) { writer.WriteLine(command.Id.ToString()); writer.WriteLine(command.Time.ToString()); writer.WriteLine(command.Action.ToString()); writer.WriteLine(); }
static void ExportV0(DirectoryInfo rootFolder, DirectoryInfo videoFolder, MontageModelV4 model) { File.WriteAllLines(videoFolder.FullName+"\\titles.txt", model.Information.Episodes.Select(z => z.Name).Where(z => z != null).ToArray(), Encoding.UTF8); var file = videoFolder.FullName+"\\log.txt"; MontageCommandIO.Clear(file); MontageCommandIO.AppendCommand(new MontageCommand { Action = MontageAction.StartFace, Id = 1, Time = 0 }, file); MontageCommandIO.AppendCommand(new MontageCommand { Action = MontageAction.StartScreen, Id = 2, Time = model.Shift }, file); int id = 3; var list = model.Chunks.ToList(); list.Add(new ChunkDataV4 { StartTime = list[list.Count - 1].StartTime + list[list.Count - 1].Length, Length = 0, Mode = Mode.Undefined }); var oldMode = Mode.Drop; for (int i = 0; i < list.Count; i++) { var e = list[i]; bool newEp = false; if (e.Mode != oldMode || e.StartsNewEpisode || i == list.Count - 1) { var cmd = new MontageCommand(); cmd.Id = id++; cmd.Time = e.StartTime; switch (oldMode) { case Mode.Drop: cmd.Action = MontageAction.Delete; break; case Mode.Face: cmd.Action = MontageAction.Commit; break; case Mode.Screen: cmd.Action = MontageAction.Commit; break; case Mode.Undefined: cmd.Action = MontageAction.Delete; break; } MontageCommandIO.AppendCommand(cmd, file); oldMode = e.Mode; newEp = true; } if (e.StartsNewEpisode) { MontageCommandIO.AppendCommand( new MontageCommand { Id = id++, Action = MontageAction.CommitAndSplit, Time = e.StartTime }, file ); newEp = true; } if (newEp) { if (e.Mode == Mode.Face || e.Mode == Mode.Screen) { var cmd = new MontageCommand(); cmd.Id = id++; cmd.Time = e.StartTime; switch (e.Mode) { case Mode.Face: cmd.Action = MontageAction.Face; break; case Mode.Screen: cmd.Action = MontageAction.Screen; break; } MontageCommandIO.AppendCommand(cmd, file); } } } }