Пример #1
0
        private void CmdProjectOpen_Executed(object sender, ExecutedEventArgs e)
        {
            openFileDialog.CheckFileExists = true;
            openFileDialog.ReadOnlyChecked = false;
            openFileDialog.ShowReadOnly    = false;
            openFileDialog.ValidateNames   = true;
            var filter = LanguageManager.TryGetString("misc.filter.sldproj") ?? "Starlight Director Project (*.sldproj)|*.sldproj";

            openFileDialog.Filter = filter;
            var r = openFileDialog.ShowDialog(this);

            if (r == DialogResult.Cancel)
            {
                return;
            }

            ProjectReader reader;
            var           projectVersion = ProjectReader.CheckFormatVersion(openFileDialog.FileName);

            if (projectVersion == 0)
            {
                var projectVersionErrorMessage = LanguageManager.TryGetString("messages.fmain.unknown_project_version") ?? "Unable to open this project. Maybe it is corrupted or it is a project of a no longer supported version. If you created this project file using a previous version of Starlight Director, you can try to open it in v0.7.5 and save it again.";
                MessageBox.Show(this, projectVersionErrorMessage, AssemblyHelper.GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                switch (projectVersion)
                {
                case ProjectVersion.V0_2:
                    reader = new SldprojV2Reader();
                    break;

                case ProjectVersion.V0_3:
                case ProjectVersion.V0_3_1:
                    reader = new SldprojV3Reader();
                    break;

                case ProjectVersion.V0_4:
                    reader = new SldprojV4Reader();
                    break;

                default:
                    MessageBox.Show(this, "You should not have seen this message.", AssemblyHelper.GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            var project         = reader.ReadProject(openFileDialog.FileName, null);
            var projectDocument = new ProjectDocument(project, openFileDialog.FileName);

            visualizer.Editor.Project = projectDocument;
            UpdateUIIndications();
        }
Пример #2
0
        public SourceScore ReadSourceScore(Stream stream, string fileName, ReadSourceOptions sourceOptions)
        {
            var projectVersion = ProjectReader.CheckFormatVersion(fileName);

            ProjectReader projectReader;

            switch (projectVersion)
            {
            case ProjectVersion.V0_2:
                projectReader = new SldprojV2Reader();
                break;

            case ProjectVersion.V0_3:
            case ProjectVersion.V0_3_1:
                projectReader = new SldprojV3Reader();
                break;

            case ProjectVersion.V0_4:
                projectReader = new SldprojV4Reader();
                break;

            default:
                throw new FormatException("Unsupported sldproj format version.");
            }

            var project    = projectReader.ReadProject(fileName, null);
            var difficulty = (Difficulty)(sourceOptions.ScoreIndex + 1);

            var score = project.GetScore(difficulty);

            if (score == null)
            {
                throw new FormatException($"Invalid project or invalid score index (\"{sourceOptions.ScoreIndex}\").");
            }

            return(ToSourceScore(project, score, sourceOptions));
        }