public bool ParseLineFromFile(string line) { if (!string.IsNullOrWhiteSpace(line)) { var splitLine = line.Split(new[] { ' ' }, 2); if (HeaderKeys.Contains(splitLine[0]) && !this.ContainsKey(splitLine[0])) { Add(splitLine[0], splitLine[1]); } else if (line.StartsWith("subtitle") || line.StartsWith("sub")) { Subtitles.AddFromString(line); } else if (line.StartsWith("comment")) { Comments.Add(line.Substring(8, line.Length - 8)); } else if (line.StartsWith("|")) { return(false); } } return(true); }
public override bool Load() { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); ClearTasprojExtras(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { SyncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) // Note: ExtractInputLog will clear Lag and State data potentially, this must come before loading those { var errorMessage = string.Empty; IsCountingRerecords = false; ExtractInputLog(tr, out errorMessage); IsCountingRerecords = true; }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } // TasMovie enhanced information if (bl.HasLump(BinaryStateLump.LagLog)) { bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br, long length) { LagLog.Load(br); }); } bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr) { StateManager.Settings.PopulateFromString(tr.ReadToEnd()); }); if (StateManager.Settings.SaveStateHistory) { bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length) { StateManager.Load(br); }); } // Movie should always have a state at frame 0. if (!this.StartsFromSavestate) { StateManager.Capture(); } bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); if (GetClientSettingsOnLoad != null && bl.HasLump(BinaryStateLump.ClientSettings)) { string clientSettings = string.Empty; bl.GetLump(BinaryStateLump.ClientSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { clientSettings = line; } } }); GetClientSettingsOnLoad(clientSettings); } if (bl.HasLump(BinaryStateLump.VerificationLog)) { bl.GetLump(BinaryStateLump.VerificationLog, true, delegate(TextReader tr) { VerificationLog.Clear(); while (true) { var line = tr.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } if (line.StartsWith("|")) { VerificationLog.Add(line); } } }); } } Changes = false; return(true); }
public virtual bool Load(bool preload) { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { if (!Header.ContainsKey(pair[0])) { Header.Add(pair[0], pair[1]); } } } } }); bl.GetLump(BinaryStateLump.Comments, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } Subtitles.Sort(); }); bl.GetLump(BinaryStateLump.SyncSettings, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { _syncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) { IsCountingRerecords = false; ExtractInputLog(tr, out _); IsCountingRerecords = true; }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); bl.GetLump(BinaryStateLump.Framebuffer, false, delegate(BinaryReader br, long length) { SavestateFramebuffer = new int[length / sizeof(int)]; for (int i = 0; i < SavestateFramebuffer.Length; i++) { SavestateFramebuffer[i] = br.ReadInt32(); } }); } else if (StartsFromSaveRam) { bl.GetLump(BinaryStateLump.MovieSaveRam, false, delegate(BinaryReader br, long length) { SaveRam = br.ReadBytes((int)length); }); } } Changes = false; return(true); }
protected void LoadBk2Fields(ZipStateLoader bl) { bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { if (!Header.ContainsKey(pair[0])) { Header.Add(pair[0], pair[1]); } } } } }); bl.GetLump(BinaryStateLump.Comments, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } Subtitles.Sort(); }); bl.GetLump(BinaryStateLump.SyncSettings, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { _syncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) { IsCountingRerecords = false; ExtractInputLog(tr, out _); IsCountingRerecords = true; }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); bl.GetLump(BinaryStateLump.Framebuffer, false, delegate(BinaryReader br, long length) { SavestateFramebuffer = new int[length / sizeof(int)]; for (int i = 0; i < SavestateFramebuffer.Length; i++) { SavestateFramebuffer[i] = br.ReadInt32(); } }); } else if (StartsFromSaveRam) { bl.GetLump(BinaryStateLump.MovieSaveRam, false, delegate(BinaryReader br, long length) { SaveRam = br.ReadBytes((int)length); }); } }
public override bool Load(bool preload) { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); ClearTasprojExtras(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { SyncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) // Note: ExtractInputLog will clear Lag and State data potentially, this must come before loading those { IsCountingRerecords = false; ExtractInputLog(tr, out _); IsCountingRerecords = true; }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } else if (StartsFromSaveRam) { bl.GetLump(BinaryStateLump.MovieSaveRam, false, delegate(BinaryReader br, long length) { SaveRam = br.ReadBytes((int)length); }); } // TasMovie enhanced information bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr) { LagLog.Load(tr); }); bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { TasStateManager.Settings = JsonConvert.DeserializeObject <TasStateManagerSettings>(json); } catch { // Do nothing, and use default settings instead } }); bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); if (GetClientSettingsOnLoad != null) { string clientSettings = ""; bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { clientSettings = line; } } }); if (!string.IsNullOrWhiteSpace(clientSettings)) { GetClientSettingsOnLoad(clientSettings); } } bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr) { VerificationLog.Clear(); while (true) { var line = tr.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } if (line.StartsWith("|")) { VerificationLog.Add(line); } } }); Branches.Load(bl, this); bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr) { var json = tr.ReadToEnd(); try { Session = JsonConvert.DeserializeObject <TasSession>(json); } catch { // Do nothing, and use default settings instead } }); if (!preload) { if (TasStateManager.Settings.SaveStateHistory) { bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length) { TasStateManager.Load(br); }); } } } Changes = false; return(true); }
public override bool Load() { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); ClearTasprojExtrasBeforeLoad(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { SyncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) { var errorMessage = string.Empty; ExtractInputLog(tr, out errorMessage); }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } // TasMovie enhanced information bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br, long length) { LagLog = br.ReadBytes((int)length).ToBools().ToList(); }); bl.GetLump(BinaryStateLump.GreenzoneSettings, false, delegate(TextReader tr) { StateManager.Settings.PopulateFromString(tr.ReadToEnd()); }); if (StateManager.Settings.SaveGreenzone) { bl.GetLump(BinaryStateLump.Greenzone, false, delegate(BinaryReader br, long length) { StateManager.FromArray(br.ReadBytes((int)length)); }); } bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Markers.Add(new TasMovieMarker(line)); } } }); } Changes = false; return(true); }
public virtual bool Load() { var file = new FileInfo(Filename); if (!file.Exists) { return(false); } using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true)) { if (bl == null) { return(false); } ClearBeforeLoad(); bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (pair.Length > 1) { Header.Add(pair[0], pair[1]); } } } }); bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Comments.Add(line); } } }); bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { Subtitles.AddFromString(line); } } }); bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr) { string line; while ((line = tr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(line)) { _syncSettingsJson = line; } } }); bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr) { var errorMessage = string.Empty; ExtractInputLog(tr, out errorMessage); }); if (StartsFromSavestate) { bl.GetCoreState( delegate(BinaryReader br, long length) { BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { TextSavestate = tr.ReadToEnd(); }); } } Changes = false; return(true); }