<commit_before>﻿using BrewLib.Audio;
using BrewLib.Graphics;
using BrewLib.Graphics.Cameras;
using BrewLib.Graphics.Textures;
using BrewLib.Util;
using OpenTK;
using StorybrewCommon.Scripting;
using StorybrewCommon.Storyboarding;
using StorybrewCommon.Util;
using StorybrewEditor.Mapset;
using StorybrewEditor.Scripting;
using StorybrewEditor.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

namespace StorybrewEditor.Storyboarding
{
    public class Project : IDisposable
    {
        public const string Extension = ".sbp";
        public const string DefaultFilename = "project" + Extension;
        public const string ProjectsFolder = "projects";

        public const string FileFilter = "project files (*" + Extension + ")|*" + Extension;

        private ScriptManager<StoryboardObjectGenerator> scriptManager;

        private string projectPath;
        public string ProjectFolderPath => Path.GetDirectoryName(projectPath);

        private string scriptsSourcePath;
        public string ScriptsPath => scriptsSourcePath;

        private string commonScriptsSourcePath;
        public string CommonScriptsPath => commonScriptsSourcePath;

        private string scriptsLibraryPath;
        public string ScriptsLibraryPath => scriptsLibraryPath;

        public string AudioPath
        {
            get
            {
                if (!Directory.Exists(MapsetPath))
                    return null;

                foreach (var beatmap in mapsetManager.Beatmaps)
                {
                    var path = Path.Combine(MapsetPath, beatmap.AudioFilename);
                    if (!File.Exists(path)) continue;
                    return path;
                }

                foreach (var mp3Path in Directory.GetFiles(MapsetPath, "*.mp3", SearchOption.TopDirectoryOnly))
                    return mp3Path;

                return null;
            }
        }<commit_msg>Fix crash when an .osu file is missing AudioFilename.<commit_after>﻿using BrewLib.Audio;
using BrewLib.Graphics;
using BrewLib.Graphics.Cameras;
using BrewLib.Graphics.Textures;
using BrewLib.Util;
using OpenTK;
using StorybrewCommon.Scripting;
using StorybrewCommon.Storyboarding;
using StorybrewCommon.Util;
using StorybrewEditor.Mapset;
using StorybrewEditor.Scripting;
using StorybrewEditor.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

namespace StorybrewEditor.Storyboarding
{
    public class Project : IDisposable
    {
        public const string Extension = ".sbp";
        public const string DefaultFilename = "project" + Extension;
        public const string ProjectsFolder = "projects";

        public const string FileFilter = "project files (*" + Extension + ")|*" + Extension;

        private ScriptManager<StoryboardObjectGenerator> scriptManager;

        private string projectPath;
        public string ProjectFolderPath => Path.GetDirectoryName(projectPath);

        private string scriptsSourcePath;
        public string ScriptsPath => scriptsSourcePath;

        private string commonScriptsSourcePath;
        public string CommonScriptsPath => commonScriptsSourcePath;

        private string scriptsLibraryPath;
        public string ScriptsLibraryPath => scriptsLibraryPath;

        public string AudioPath
        {
            get
            {
                if (!Directory.Exists(MapsetPath))
                    return null;

                foreach (var beatmap in mapsetManager.Beatmaps)
                {
                    if (beatmap.AudioFilename == null)
                        continue;

                    var path = Path.Combine(MapsetPath, beatmap.AudioFilename);
                    if (!File.Exists(path))
                        continue;

                    return path;
                }

                return Directory.GetFiles(MapsetPath, "*.mp3", SearchOption.TopDirectoryOnly).FirstOrDefault();
            }
        }
{'fraction_non_alphanumeric': 0.07117267733460712, 'fraction_numerical': 0.0009553379508000956, 'mean_word_length': 2.5431472081218276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055208', 'n_tokens_mistral': 1046, 'n_tokens_neox': 980, 'n_words': 273}