public ShareRunDialog(LiveSplitState state, ISettings settings, Func<Image> screenShotFunction) { State = state; if (State.CurrentPhase != TimerPhase.Ended) Run = state.Run; else { var model = new TimerModel(); model.CurrentState = State; model.SetRunAsPB(); model.UpdateAttemptHistory(); Run = State.Run; } ScreenShotFunction = screenShotFunction; Settings = settings; InitializeComponent(); }
private void SaveSplits(bool promptPBMessage) { var savePath = CurrentState.Run.FilePath; if (savePath == null) { SaveSplitsAs(promptPBMessage); return; } CurrentState.Run.FixSplits(); var stateCopy = CurrentState.Clone() as LiveSplitState; var modelCopy = new TimerModel(); modelCopy.CurrentState = stateCopy; var result = DialogResult.No; if (promptPBMessage && ((CurrentState.CurrentPhase == TimerPhase.Ended && CurrentState.Run.Last().PersonalBestSplitTime[CurrentState.CurrentTimingMethod] != null && CurrentState.Run.Last().SplitTime[CurrentState.CurrentTimingMethod] >= CurrentState.Run.Last().PersonalBestSplitTime[CurrentState.CurrentTimingMethod]) || CurrentState.CurrentPhase == TimerPhase.Running || CurrentState.CurrentPhase == TimerPhase.Paused)) { DontRedraw = true; result = MessageBox.Show(this, "This run did not beat your current splits. Would you like to save this run as a Personal Best?", "Save as Personal Best?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); DontRedraw = false; if (result == DialogResult.Yes) { Model.Reset(); modelCopy.SetRunAsPB(); modelCopy.UpdateAttemptHistory(); modelCopy.UpdateBestSegments(); modelCopy.UpdateSegmentHistory(); SetRun(stateCopy.Run); } else if (result == DialogResult.Cancel) return; } if (result == DialogResult.Yes) modelCopy.Reset(false); else modelCopy.Reset(); try { if (!File.Exists(savePath)) File.Create(savePath).Close(); using (var memoryStream = new MemoryStream()) { RunSaver.Save(stateCopy.Run, memoryStream); using (var stream = File.Open(savePath, FileMode.Create, FileAccess.Write)) { var buffer = memoryStream.GetBuffer(); stream.Write(buffer, 0, (int)memoryStream.Length); } CurrentState.Run.HasChanged = false; } AddSplitsFileToLRU(savePath, stateCopy.Run, CurrentState.CurrentTimingMethod); } catch (Exception ex) { MessageBox.Show(this, "Splits could not be saved!", "Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); Log.Error(ex); } }