public ImportResult Import(
            IDialogParent dialogParent,
            IMovieSession session,
            IEmulator emulator,
            string path,
            Config config)
        {
            _dialogParent = dialogParent;
            SourceFile    = new FileInfo(path);
            Config        = config;

            if (!SourceFile.Exists)
            {
                Result.Errors.Add($"Could not find the file {path}");
                return(Result);
            }

            var newFileName = $"{SourceFile.FullName}.{Bk2Movie.Extension}";

            Result.Movie = session.Get(newFileName);
            Result.Movie.Attach(emulator);
            RunImport();

            if (!Result.Errors.Any())
            {
                Result.Movie.Save();
            }

            return(Result);
        }
예제 #2
0
        private IMovie PreLoadMovieFile(HawkFile hf, bool force)
        {
            var movie = _movieSession.Get(hf.CanonicalFullPath);

            try
            {
                movie.PreLoadHeaderAndLength();

                // Don't do this from browse
                if (movie.Hash == _game.Hash ||
                    _config.PlayMovieMatchHash == false || force)
                {
                    return(movie);
                }
            }
            catch (Exception ex)
            {
                // TODO: inform the user that a movie failed to parse in some way
                Console.WriteLine(ex.Message);
            }

            return(null);
        }
예제 #3
0
        private void Ok_Click(object sender, EventArgs e)
        {
            var path = MakePath();

            if (!string.IsNullOrWhiteSpace(path))
            {
                var test = new FileInfo(path);
                if (test.Exists)
                {
                    var result = DialogController.ShowMessageBox2($"{path} already exists, overwrite?", "Confirm overwrite", EMsgBoxIcon.Warning, useOKCancel: true);
                    if (!result)
                    {
                        return;
                    }
                }

                var movieToRecord = _movieSession.Get(path);

                var fileInfo = new FileInfo(path);
                if (!fileInfo.Exists)
                {
                    Directory.CreateDirectory(fileInfo.DirectoryName);
                }

                if (StartFromCombo.SelectedItem.ToString() == "Now" && _emulator.HasSavestates())
                {
                    var core = _emulator.AsStatable();

                    movieToRecord.StartsFromSavestate = true;

                    if (_config.Savestates.Type == SaveStateType.Binary)
                    {
                        movieToRecord.BinarySavestate = core.CloneSavestate();
                    }
                    else
                    {
                        using var sw = new StringWriter();
                        core.SaveStateText(sw);
                        movieToRecord.TextSavestate = sw.ToString();
                    }

                    // TODO: do we want to support optionally not saving this?
                    movieToRecord.SavestateFramebuffer = Array.Empty <int>();
                    if (_emulator.HasVideoProvider())
                    {
                        movieToRecord.SavestateFramebuffer = (int[])_emulator.AsVideoProvider().GetVideoBuffer().Clone();
                    }
                }
                else if (StartFromCombo.SelectedItem.ToString() == "SaveRam" && _emulator.HasSaveRam())
                {
                    var core = _emulator.AsSaveRam();
                    movieToRecord.StartsFromSaveRam = true;
                    movieToRecord.SaveRam           = core.CloneSaveRam();
                }

                movieToRecord.PopulateWithDefaultHeaderValues(
                    _emulator,
                    _game,
                    _firmwareManager,
                    AuthorBox.Text ?? _config.DefaultAuthor);
                movieToRecord.Save();
                _mainForm.StartNewMovie(movieToRecord, true);

                _config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked;
                if (DefaultAuthorCheckBox.Checked)
                {
                    _config.DefaultAuthor = AuthorBox.Text;
                }

                Close();
            }
            else
            {
                DialogController.ShowMessageBox("Please select a movie to record", "File selection error", EMsgBoxIcon.Error);
            }
        }