private static void BuildBdb(Project project, string bdbFileName, LiveMusicRecord record, Dictionary <Difficulty, Difficulty> difficultyMappings) { var connectionString = $"Data Source={bdbFileName}"; if (File.Exists(bdbFileName)) { File.Delete(bdbFileName); } else { SQLiteConnection.CreateFile(bdbFileName); } using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) { SQLiteCommand command; using (command = transaction.Connection.CreateCommand()) { command.CommandText = "CREATE TABLE blobs (name TEXT PRIMARY KEY, data BLOB NOT NULL);"; command.ExecuteNonQuery(); } using (command = transaction.Connection.CreateCommand()) { command.CommandText = "INSERT INTO blobs (name, data) VALUES (@name, @data);"; var nameParam = command.Parameters.Add("name", DbType.AnsiString); var dataParam = command.Parameters.Add("data", DbType.Binary); // update: Create Master+ entry, regardless of its existence in original BDB. for (var i = (int)Difficulty.Debut; i <= (int)Difficulty.MasterPlus; ++i) { var entryDifficulty = (Difficulty)i; var userDifficulty = difficultyMappings[entryDifficulty]; var score = project.GetScore(userDifficulty); var compiledScore = score.Compile(); var csv = compiledScore.GetCsvString(); var csvData = Encoding.ASCII.GetBytes(csv); nameParam.Value = string.Format(ScoreRecordFormat, record.LiveID, i); dataParam.Value = csvData; command.ExecuteNonQuery(); } nameParam.Value = string.Format(Score2DCharaFormat, record.LiveID); dataParam.Value = Encoding.ASCII.GetBytes(Score2DCharaText); command.ExecuteNonQuery(); nameParam.Value = string.Format(ScoreCyalumeFormat, record.LiveID); dataParam.Value = Encoding.ASCII.GetBytes(ScoreCyalumeText); command.ExecuteNonQuery(); nameParam.Value = string.Format(ScoreLyricsFormat, record.LiveID); dataParam.Value = Encoding.ASCII.GetBytes(ScoreLyricsText); command.ExecuteNonQuery(); } transaction.Commit(); } connection.Close(); } }
private void FSelectMusicID_Load(object sender, EventArgs e) { var initialMusicID = _musicID; var initialLiveID = _liveID; cboDatabaseItems.Items.Clear(); if (!File.Exists(MasterDatabasePath)) { var fileInfo = new FileInfo(MasterDatabasePath); var errorMessageTemplate = LanguageManager.TryGetString("messages.fselectmusicid.master_database_file_missing") ?? "The database file '{0}' is missing. Using the default music ID."; var errorMessage = string.Format(errorMessageTemplate, fileInfo.FullName); MessageBox.Show(this, errorMessage, AssemblyHelper.GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Warning); _musicID = 1001; _liveID = 1; Close(); } else { try { var csb = new SQLiteConnectionStringBuilder { DataSource = MasterDatabasePath }; var musicList = new List <LiveMusicRecord>(); using (var connection = new SQLiteConnection(csb.ToString())) { connection.Open(); using (var adapter = new SQLiteDataAdapter(FormatFilter, connection)) { using (var dataTable = new DataTable()) { adapter.Fill(dataTable); foreach (DataRow dataRow in dataTable.Rows) { var record = new LiveMusicRecord { LiveID = (int)(long)dataRow["live_id"], MusicID = (int)(long)dataRow["music_id"], MusicName = ((string)dataRow["music_name"]).Replace(@" \n", " ").Replace(@"\n", " "), DifficultyExists = new bool[5] }; for (var i = (int)Difficulty.Debut; i <= (int)Difficulty.MasterPlus; ++i) { var v = (int)(long)dataRow["d" + i]; record.DifficultyExists[i - 1] = v > 0; } var color = (int)(long)dataRow["live_type"]; if (color > 0) { record.Attribute |= (MusicColor)(1 << (color - 1)); } var isEvent = (long)dataRow["event_type"] > 0; if (isEvent) { record.Attribute |= MusicColor.Event; } // お願い!シンデレラ (solo ver.) if (record.MusicID == 1901) { record.Attribute |= MusicColor.Solo; } // TODO: some other temporary songs (e.g. for songs election) musicList.Add(record); } } } connection.Close(); } _musicList = musicList; var itemTextTemplate = LanguageManager.TryGetString("ui.fselectmusicid.combobox.item.text_template") ?? "{0} [{1}]"; foreach (var record in musicList) { var attributeDescription = DescribedEnumConverter.GetEnumDescription(record.Attribute); var str = string.Format(itemTextTemplate, record.MusicName, attributeDescription); cboDatabaseItems.Items.Add(str); } if (cboDatabaseItems.Items.Count > 0) { if (initialMusicID <= 0) { cboDatabaseItems.SelectedIndex = 0; } else { var targetSelectionIndex = musicList.FindIndex(record => { if (initialMusicID != 0 && initialMusicID != record.MusicID) { return(false); } if (initialLiveID != 0 && initialLiveID != record.LiveID) { return(false); } return(true); }); if (targetSelectionIndex < 0) { targetSelectionIndex = 0; } cboDatabaseItems.SelectedIndex = targetSelectionIndex; } } } catch (Exception ex) { MessageBox.Show(this, $"An error occurred while reading the database. Using the default music ID.{Environment.NewLine}Information: {ex.Message}", AssemblyHelper.GetTitle(), MessageBoxButtons.OK, MessageBoxIcon.Warning); _musicID = 1001; _liveID = 1; Close(); } } }
private void FillMusicComboBoxes() { var connectionString = $"Data Source={MasterMdbPath}"; var musicList = new List <LiveMusicRecord>(); try { using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); using (var adapter = new SQLiteDataAdapter(FormatFilter, connection)) { using (var dataTable = new DataTable()) { adapter.Fill(dataTable); foreach (DataRow dataRow in dataTable.Rows) { var record = new LiveMusicRecord { LiveID = (int)(long)dataRow["live_id"], MusicID = (int)(long)dataRow["music_id"], MusicName = ((string)dataRow["music_name"]).Replace(@" \n", " ").Replace(@"\n", " "), DifficultyExists = new bool[5] }; for (var i = (int)Difficulty.Debut; i <= (int)Difficulty.MasterPlus; ++i) { var v = (int)(long)dataRow["d" + i]; record.DifficultyExists[i - 1] = v > 0; } var color = (int)(long)dataRow["live_type"]; if (color > 0) { record.Attribute |= (MusicAttribute)(1 << (color - 1)); } var isEvent = (long)dataRow["event_type"] > 0; if (isEvent) { record.Attribute |= MusicAttribute.Event; } // お願い!シンデレラ (solo ver.) if (record.MusicID == 1901) { record.Attribute |= MusicAttribute.Solo; } musicList.Add(record); } } } connection.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, App.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation); } foreach (var record in musicList) { var item = new ComboBoxItem(); var extraDescription = DescribedEnumReader.Read(record.Attribute, typeof(MusicAttribute)); var textBlock = new TextBlock(new Run(record.MusicName)); if (!string.IsNullOrEmpty(extraDescription)) { var inline = new Run(" - " + extraDescription); inline.Foreground = SystemColors.GrayTextBrush; textBlock.Inlines.Add(inline); } item.Content = textBlock; item.Tag = record; CboSongList.Items.Add(item); } }