From 7c09ca4ae36fb1ba0876263b41ee03bbc6e7c518 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Mon, 4 Jul 2011 17:01:17 +0000 Subject: [PATCH] improvements to subtitle parsing --- BizHawk.MultiClient/movie/Subtitle.cs | 2 +- BizHawk.MultiClient/movie/SubtitleList.cs | 42 ++++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/BizHawk.MultiClient/movie/Subtitle.cs b/BizHawk.MultiClient/movie/Subtitle.cs index 2c08e7a360..7a8c9e9999 100644 --- a/BizHawk.MultiClient/movie/Subtitle.cs +++ b/BizHawk.MultiClient/movie/Subtitle.cs @@ -19,7 +19,7 @@ namespace BizHawk.MultiClient Message = ""; X = 0; Y = 0; - Duration = 0; + Duration = 120; Frame = 0; Color = 0xFFFFFFFF; } diff --git a/BizHawk.MultiClient/movie/SubtitleList.cs b/BizHawk.MultiClient/movie/SubtitleList.cs index e3800036e8..4c47a7c4ed 100644 --- a/BizHawk.MultiClient/movie/SubtitleList.cs +++ b/BizHawk.MultiClient/movie/SubtitleList.cs @@ -95,20 +95,52 @@ namespace BizHawk.MultiClient int x = subtitleStr.IndexOf(' '); if (x <= 0) return false; + //remove "subtitle" string str = subtitleStr.Substring(x + 1, subtitleStr.Length - x - 1); - string frame = str.Substring(0, str.IndexOf(' ')); + + x = str.IndexOf(' '); + if (x <= 0) return false; + + string frame = str.Substring(0, x); + str = str.Substring(x + 1, str.Length - x - 1); + try { - s.Frame = Int16.Parse(frame); + s.Frame = int.Parse(frame); + } + catch + { + return false; + } + + x = str.IndexOf(' '); + if (x <= 0) return false; + string X = str.Substring(0, x); + str = str.Substring(x + 1, str.Length - x - 1); + try + { + s.X = int.Parse(X); + } + catch + { + s.Message = str; //Assume it is a FCEUX subtitle + subs.Add(s); + return true; + } + + x = str.IndexOf(' '); + if (x <= 0) return false; + string Y = str.Substring(0, x); + str = str.Substring(x + 1, str.Length - x - 1); + try + { + s.Y = int.Parse(Y); } catch { return false; } - //TODO: actually attempt to parse these things and supply with default values if they don't exist - s.X = 0; - s.Y = 0; s.Duration = 120; s.Message = str; s.Color = 0xFFFFFFFF;