private void UpdateTagInfo(string mp3File, string mp3MusicRootPath, bool useDirInfo, ref OperationResult op) { OperationResult _op = new OperationResult(); try { bool badfile = false; MP3FileDataType mp3 = BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(mp3File, mp3MusicRootPath, ref _op); if (!_op.Success) { badfile = true; } if (_op.Success) { BCHMP3Utilities.SaveMp3IdInfo(mp3, ref _op); } if (!_op.Success && !badfile) { badfile = true; } } catch (Exception ex) { _op.AddException(ex); } op.AddOperationResult(ref _op); }
private void CreateM3uFromResults(DataTable dt, string m3uFileName, ref OperationResult op) { try { if (dt == null || dt.Rows.Count < 1) { return; } List <string> songs = new List <string>(); foreach (DataRow row in dt.Rows) { songs.Add(Path.Combine((string)row["Path"], (string)row["File_Name"])); BCHFileIO.WriteFullFile(m3uFileName, songs, ref op); if (!op.Success) { return; } } } catch (Exception ex) { op.AddException(ex); return; } }
public void CreateDatabaseTables(ref OperationResult op) { string createArtistTableSql = "CREATE TABLE [tbArtist]([Artist_Id][INTEGER] PRIMARY KEY, [Mp3Info_Id] [INTEGER] NOT NULL, [Artist_Name] [nvarchar](255) NOT NULL)"; string createFileInfoTableSql = "CREATE TABLE [tbFileInfo]([FileInfo_Id][INTEGER] PRIMARY KEY, [File_Name] [nvarchar](250) NOT NULL, [Path] [nvarchar](255) NOT NULL)"; string createMp3InfoTableSql = "CREATE TABLE [tbMp3Info]( [Mp3Info_Id] [INTEGER] PRIMARY KEY, [FileInfo_Id] [INTEGER] NOT NULL, [Song_Title] [nvarchar](255) NOT NULL, [Album] [nvarchar](255) NULL, [Genre] [nvarchar](255) NULL, [Comments] [nvarchar](255) NULL, [Track] [INTEGER] NULL, [Song_Numeraton] [nvarchar](255) NULL) "; try { using (var conn = new SQLiteConnection($"Data Source={_dbFileName}; Version = 3; New = True; Compress = True; Journal Mode=Off;")) { conn.Open(); SQLiteCommand sqlite_cmd; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = createArtistTableSql; sqlite_cmd.ExecuteNonQuery(); sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = createFileInfoTableSql; sqlite_cmd.ExecuteNonQuery(); sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = createMp3InfoTableSql; sqlite_cmd.ExecuteNonQuery(); conn.Close(); } } catch (Exception ex) { op.AddException(ex); } }
private void btnCopyFiles_Click(object sender, EventArgs e) { Op = new OperationResult(); if (cbxDeleteToDir.Checked) { try { DeleteToDirContents(ucGetToPath.FileName); } catch (Exception ex) { Op.AddException(ex); ucResultDisplay1.DisplayText = Op.GetAllInfos("\n"); return; } } this.FileCnt = Directory.GetFiles(ucGetFromPath.FileName, "*.*", SearchOption.AllDirectories).Length; this.FileProcCnt = 0; timer1.Interval = 1000; progressBar1.Minimum = 0; progressBar1.Maximum = FileCnt; lblProgStat.Text = "1 of " + FileCnt.ToString(); timer1.Start(); backgroundWorker1.RunWorkerAsync(); }
private void LoadDbTableListBox(ref OperationResult op) { try { lbTables.Items.Clear(); DataTable dt = _mp3Repository.GetAllTables(ref op); if (!op.Success) { rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); return; } BCHWinFormUtilities.DataTableToListBox(dt, lbTables, "name"); lbTables.SelectedIndex = 0; LoadDbColumnListBox(lbTables.SelectedItem.ToString(), ref op); if (!op.Success) { return; } } catch (Exception ex) { op.AddException(ex); return; } }
private void btnLoadItunesLibraryData_Click(object sender, EventArgs e) { tbMessages.Text = ""; OperationResult op = new OperationResult(); try { var iTunesData = GetiTunesLibXml(); if (!op.Success) { tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } _mp3Repository = new Mp3Repository(ddtbDbFile.ItemText, ref op); if (!op.Success) { tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } _mp3Repository.DropAllITunesTables(ref op); if (!op.Success) { tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } _mp3Repository.CreateItunesTables(ref op); if (!op.Success) { tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } _mp3Repository.InsertITunesData(iTuneSongs, iTunesPlayLists, ref op); if (!op.Success) { tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } } catch (Exception ex) { op.AddException(ex); tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } if (!op.Success) { tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } tbMessages.Text = "Finished"; }
public DataTable ExecSql(string sql, ref OperationResult op) { if (string.IsNullOrEmpty(ConnectionString)) { op.AddError("The connection string is not set."); return(null); } string connStr = string.Empty; DataTable table = null; try { using (OleDbConnection conn = new OleDbConnection(ConnectionString)) { using (OleDbCommand cmd = conn.CreateCommand()) { cmd.CommandText = sql; conn.Open(); cmd.CommandType = this.CommandType; table = new DataTable(); new OleDbDataAdapter(cmd).Fill(table); return(table); } } } catch (Exception ex) { op.AddException(ex); } return(null); }
public List <T> ExecSql <T>(string sql, ref OperationResult op) { if (!op.Success) { return(null); } try { DataTable table = ExecSql(sql, ref op); if (!op.Success) { return(null); } List <T> ts = DataSchemaDataTableUtilities.ConvertTo <T>(table).ToList(); return(ts); } catch (Exception ex) { op.AddException(ex); } return(null); }
public void TruncateTable(string tableName, string idName, ref OperationResult op) { if (string.IsNullOrEmpty(ConnectionString)) { op.AddError("The connection string is not set."); return; } string connStr = string.Empty; try { using (OleDbConnection conn = new OleDbConnection(ConnectionString)) { using (OleDbCommand cmd = new OleDbCommand("ALTER TABLE [" + tableName + "] ALTER COLUMN " + idName + " COUNTER (1, 1)", conn)) { conn.Open(); cmd.ExecuteNonQuery(); return; } } } catch (Exception ex) { op.AddException(ex); } return; }
public DataTable RunSql(string sql, ref OperationResult op) { try { using (var conn = new SQLiteConnection($"Data Source={_dbFileName}; Version = 3; New = True; Compress = True; ")) { conn.Open(); SQLiteCommand sqlite_cmd; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = sql; sqlite_cmd.ExecuteNonQuery(); SQLiteDataAdapter sQLiteDataAdapter = new SQLiteDataAdapter(sqlite_cmd); DataTable dt = new DataTable(); sQLiteDataAdapter.Fill(dt); conn.Close(); return(dt); } } catch (Exception ex) { op.AddException(ex); } return(null); }
private void AfterFileTextDrop(string fName) { OperationResult op = new OperationResult(); try { dddtbM3uPath.ItemText = Path.GetDirectoryName(fName); tbM3UFileName.Text = Path.GetFileName(fName); if (File.Exists(fName)) { var mp3s = BCHFileIO.ReadFullFile(fName, ref op); if (op.Success) { uftM3U.AddItems(mp3s, BCHControls.UCFromToEnum.From, false, true); uftM3U.AddItems(mp3s, BCHControls.UCFromToEnum.To, false, true); } else { MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { op.AddException(ex); MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnReadLibraryFile_Click(object sender, EventArgs e) { tbMessages.Text = ""; OperationResult op = new OperationResult(); try { GetiTunesLibXml(); } catch (Exception ex) { op.AddException(ex); tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } if (!op.Success) { tbMessages.Text = op.GetAllErrorsAndExceptionsWthNl(); return; } tbMessages.Text = "Finished"; }
private void ProcessMp3DbFile(ref OperationResult op) { try { if (!File.Exists(ddtbMp3DbFile.ItemText) || !ddtbMp3DbFile.ItemText.ToUpper().EndsWith(".DB")) { throw new Exception("You must choose database (db) file!"); } CreateMp3Repository(ddtbMp3DbFile.ItemText, ref op); if (!op.Success) { rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); ddtbMp3DbFile.ItemText = string.Empty; return; } FillListBoxes(ref op); if (!op.Success) { rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); ddtbMp3DbFile.ItemText = string.Empty; return; } } catch (Exception ex) { op.AddException(ex); rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); return; } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { try { DirectoryCopy(ucGetFromPath.FileName, ucGetToPath.FileName, true); } catch (Exception ex) { Op.AddException(ex); } }
public void InsertMp3(MP3FileDataType mP3FileDataType, ref OperationResult op) { if (!mP3FileDataType.FileName.EndsWith("mp3", StringComparison.InvariantCultureIgnoreCase)) { return; } using (DbContextTransaction transaction = _mp3Context.Database.BeginTransaction()) { try { var tbFileInfo = new tbFileInfo { File_Name = mP3FileDataType.FileName, Path = mP3FileDataType.FilePath }; _mp3Context.FileInfo.Add(tbFileInfo); _mp3Context.SaveChanges(); var fiId = tbFileInfo.FileInfo_Id; tbMp3Info tbMp3Info = new tbMp3Info { Album = mP3FileDataType.Album, Comments = mP3FileDataType.Comments, FileInfo_Id = fiId, Genre = mP3FileDataType.Genre, Song_Numeraton = mP3FileDataType.SongNumeration, Song_Title = mP3FileDataType.SongTitle, Track = mP3FileDataType.Track }; _mp3Context.Mp3Info.Add(tbMp3Info); _mp3Context.SaveChanges(); var miId = tbMp3Info.Mp3Info_Id; foreach (var artist in mP3FileDataType.Artists) { tbArtist tbArtist = new tbArtist { Artist_Name = artist, Mp3Info_Id = miId }; _mp3Context.Artist.Add(tbArtist); _mp3Context.SaveChanges(); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); op.AddError($"Error inserting mp3 file: {mP3FileDataType.FilePath}"); op.AddException(ex); } } }
public void SetM3U(string fileNameAndPath, List <string> list, bool isNew, ref OperationResult op) { try { if (!isNew && !File.Exists(fileNameAndPath)) { op.AddError("The File: " + fileNameAndPath + " deos not exist!"); return; } if (Directory.Exists(Path.GetFullPath(fileNameAndPath))) { op.AddError("The Path: " + Path.GetFullPath(fileNameAndPath) + " deos not exist!"); return; } if (!isNew) { List <string> fileContents = BCHFileIO.ReadFullFile(fileNameAndPath, ref op); fileContents = ( from line in fileContents where !line.Trim().StartsWith("#") && line.Trim().Length > 1 select line ).ToList <string>(); if (!op.Success) { return; } this.M3USongList = fileContents; } else { this.M3USongList = new List <string>(); this.M3USongList.AddRange(list); } this.M3UFileNameAndPath = fileNameAndPath; this.M3UFileName = Path.GetFileName(fileNameAndPath); this.M3UPath = Path.GetFullPath(fileNameAndPath); _isSet = true; } catch (Exception ex) { op.AddException(ex); return; } }
private void FillListBoxes(ref OperationResult op) { try { MP3DBManager mdbmgr = new MP3DBManager(); mdbmgr.SetDataStore(ddtbMp3DbFile.ItemText, ref op); Dictionary <string, string> parms = new Dictionary <string, string>(); string none = "None"; DataTable dt = mdbmgr.RunSqlScript(ref parms, SqlScriptEnum.SelectAllAlbums, ref op); ucatAlbum.ClearListbox(); ucatAlbum.SetListboxList(dt, "Album"); ucatAlbum.InsertListBoxItem(0, none); ucatAlbum.SetSelectedIndex(0); dt = mdbmgr.RunSqlScript(ref parms, SqlScriptEnum.SelectAllArtists, ref op); ucatArtists.ClearListbox(); ucatArtists.SetListboxList(dt, "Artist_Name"); ucatArtists.InsertListBoxItem(0, none); ucatArtists.SetSelectedIndex(0); dt = mdbmgr.RunSqlScript(ref parms, SqlScriptEnum.SelectAllComments, ref op); ucatComment.ClearListbox(); ucatComment.SetListboxList(dt, "Comments"); ucatComment.InsertListBoxItem(0, none); ucatComment.SetSelectedIndex(0); dt = mdbmgr.RunSqlScript(ref parms, SqlScriptEnum.SelectAllFileNames, ref op); ucatFileName.ClearListbox(); ucatFileName.SetListboxList(dt, "File_Name"); ucatFileName.InsertListBoxItem(0, none); ucatFileName.SetSelectedIndex(0); dt = mdbmgr.RunSqlScript(ref parms, SqlScriptEnum.SelectAllGenres, ref op); ucatGenre.ClearListbox(); ucatGenre.SetListboxList(dt, "Genre"); ucatGenre.InsertListBoxItem(0, none); ucatGenre.SetSelectedIndex(0); dt = mdbmgr.RunSqlScript(ref parms, SqlScriptEnum.SelectAllSongs, ref op); ucatTitle.ClearListbox(); ucatTitle.SetListboxList(dt, "Song_Title"); ucatTitle.InsertListBoxItem(0, none); ucatTitle.SetSelectedIndex(0); } catch (Exception ex) { op.AddException(ex); rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); return; } }
private void btnLoadSqliteDb_Click(object sender, EventArgs e) { OperationResult op = new OperationResult(); rtbMessages.Text = ""; if (ddlbMp3s.LbList.Count < 1 && rbtnUseFileList.Checked) { rtbMessages.Text = "No mp3s to process!"; return; } if (!Directory.Exists(dddtbGetMp3RootDir.ItemText) && rbtnBHFileNameFormat.Checked) { rtbMessages.Text = "You must enter an MP3 Root Dir!"; return; } try { string dbFname = Path.Combine(dddtbGetDbDir.ItemText, tbSqliteDbFileName.Text); CreateMp3Repository(dbFname, ref op); if (!op.Success) { rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); } if (ckbMakeDbCopyIfExist.Checked) { CreateCopyOfDb(dbFname, ref op); if (!op.Success) { rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); } } } catch (Exception ex) { op.AddException(ex); return; } timer1.Interval = 1000; progressBar1.Minimum = 0; progressBar1.Maximum = ddlbMp3s.LbList.Count; this.CurrentCount = 0; StartTime = DateTime.Now; timer1.Start(); backgroundWorker1.RunWorkerAsync(); }
private void RenameFiles() { OperationResult op = new OperationResult(); int row = 0; int cnt = 0; List <string> output = new List <string>(); try { string newName = string.Empty; string m3RtDir = tbMP3RootDir.Text; foreach (DataGridViewRow dgvr in dataGridView1.Rows) { //MessageBox.Show(dgvr.Cells[0].Value.ToString() + "," + dataGridView1.Columns[0].Name + "\n" // + dgvr.Cells[1].Value.ToString() + "\n" + "," + dataGridView1.Columns[1].Name + "\n" // + dgvr.Cells[2].Value.ToString() + "\n" + "," + dataGridView1.Columns[2].Name + "\n" // + dgvr.Cells[3].Value.ToString() + "\n" + "," + dataGridView1.Columns[3].Name ); if (dgvr.Cells[2] != null && dgvr.Cells[2].Value.ToString().Trim().Length > 0 && !dgvr.Cells[1].Value.ToString().Trim().Equals(dgvr.Cells[2].Value.ToString().Trim())) { newName = Path.Combine(dgvr.Cells[3].Value.ToString().Trim(), dgvr.Cells[2].Value.ToString().Trim()); File.Move(BadMp3List[row].FileNamePath, newName); if (ckbUpdateTagInfo.Checked) { UpdateTagInfo(newName, m3RtDir, ckbUseDirInfo.Checked, ref op); } if (!op.Success) { break; } output.Add(dgvr.Cells[0].Value.ToString() + "; " + newName); cnt++; } row++; } } catch (Exception ex) { op.AddException(ex); } LoadGrid(); string msg = "File name changes complete. \nSuccessfull changes: " + cnt.ToString(); MessageBoxIcon mbi = op.Success ? MessageBoxIcon.Information : MessageBoxIcon.Error; string msgBxMsg = op.Success ? msg : msg + "\n" + "There were errors!\n" + op.GetAllErrorsAndExceptions("\n"); string msgCap = op.Success ? "INFORMATION" : "ERROR!"; MessageBox.Show(msgBxMsg, msgCap, MessageBoxButtons.OK, mbi); output.Insert(0, msg); }
private void MakeDatabaseReady(ref OperationResult op) { try { if (!ckbAddToDb.Checked) { _mp3Repository.DropAllMp3Tables(ref op); if (!op.Success) { return; } _mp3Repository.CreateDatabaseTables(ref op); if (!op.Success) { return; } } else { Mp3TableStatusGroup mp3TableStatusGroup = _mp3Repository.CheckIfAllMp3TablesExists(ref op); if (!op.Success) { return; } bool anyMissingTables = mp3TableStatusGroup.AnyMissngTables(ref op); if (!op.Success) { return; } if (anyMissingTables) { _mp3Repository.DropAllMp3Tables(ref op); if (!op.Success) { return; } _mp3Repository.CreateDatabaseTables(ref op); if (!op.Success) { return; } } } } catch (Exception ex) { op.AddException(ex); } }
public List <string> EditMP3Tags(List <string> mp3Files, string mp3MusicRootPath, bool useFileInfo, ref OperationResult op) { OperationResult _op = new OperationResult(); int cnt = 0; bool badfile = false; List <string> badMp3List = new List <string>(); foreach (string mp3File in mp3Files) { badfile = false; cnt++; if (ProgressUpdate != null) { ProgressUpdate(cnt); } try { MP3FileDataType mp3 = BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(mp3File, mp3MusicRootPath, ref _op); if (!_op.Success) { badMp3List.Add(mp3File); badfile = true; } if (_op.Success) { SaveMp3IdInfo(mp3, ref _op); } if (!_op.Success && !badfile) { badfile = true; badMp3List.Add(mp3File); } } catch (Exception ex) { _op.AddException(ex); if (!badfile) { badfile = true; badMp3List.Add(mp3File); } } } op.AddOperationResult(ref _op); return(badMp3List); }
public void CloseDBConn(ref OperationResult op) { try { if (this.DataStore != null && DataStore.Conn != null && DataStore.Conn.State == ConnectionState.Open) { DataStore.Conn.Close(); } } catch (Exception ex) { op.AddException(ex); } }
public void DropAllMp3Tables(ref OperationResult op) { try { using (var conn = new SQLiteConnection($"Data Source={_dbFileName}; Version = 3; New = True; Compress = True; Journal Mode=Off;")) { SQLiteCommand sqlite_cmd; var checkTables = CheckIfAllMp3TablesExists(ref op); if (!op.Success) { return; } string sql = ""; conn.Open(); if (checkTables.HasArtistTable) { sql = "DROP TABLE tbArtist;"; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = sql; sqlite_cmd.ExecuteNonQuery(); } if (checkTables.HasMp3InfoTable) { sql = "DROP TABLE tbMp3Info;"; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = sql; sqlite_cmd.ExecuteNonQuery(); } if (checkTables.HasFileInfoTable) { sql = "DROP TABLE tbFileInfo;"; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = sql; sqlite_cmd.ExecuteNonQuery(); } conn.Close(); } } catch (Exception ex) { op.AddException(ex); } }
private void CreateCopyOfDb(string dbName, ref OperationResult op) { try { if (File.Exists(dbName)) { BCHFileIO.CopyFile(dbName, true, ref op); } } catch (Exception ex) { op.AddException(ex); } }
public void Load(string xmlFileName, ref OperationResult op) { try { this.XmlDoc = new XmlDocument(); this.XmlDoc.Load(xmlFileName); XmlNodeList scriptList = XmlDoc.SelectNodes("/SqlScripts/SqlScript"); foreach (XmlElement script in scriptList) { string name = script.SelectSingleNode("Name").InnerText.Trim(); string sql = script.SelectSingleNode("Sql").InnerText; string type = script.SelectSingleNode("Type").InnerText; XmlNodeList paramList = script.SelectNodes("Parameters/Parameter"); SqlScriptMembers sm = new SqlScriptMembers(); sm.Parameters = new Dictionary <string, SqlScriptParameter>(); foreach (XmlElement param in paramList) { string pName = param.GetAttribute("name").Trim(); string pType = param.GetAttribute("type").Trim(); string pMarker = param.InnerText; SqlScriptParameter ssp = new SqlScriptParameter(); ssp.Type = GetParamType(pType); ssp.Marker = pMarker; sm.Parameters.Add(pName, ssp); } sm.Sql = sql; if (sm.Sql.Trim().Length > 1 && name.Trim().Length > 1) { this.SqlScriptDict.Add(name, sm); } sm.Type = type; } if (SqlScriptDict == null || SqlScriptDict.Count < 1) { op.AddError("Sql Scripts not set. Make sure there are valid scripts."); this.IsSet = false; return; } this.IsSet = true; } catch (Exception ex) { op.AddException(ex); } }
public void DropAllITunesTables(ref OperationResult op) { try { var checkTables = CheckIfAllITunesTablesExists(ref op); if (!op.Success) { return; } using (var conn = new SQLiteConnection($"Data Source={_dbFileName}; Version = 3; New = True; Compress = True; Journal Mode=Off;")) { conn.Open(); SQLiteCommand sqlite_cmd; string sql = ""; if (checkTables.HastunesSongTable) { sql = "DROP TABLE tbItunesSong;"; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = sql; sqlite_cmd.ExecuteScalar(); } if (checkTables.HasItunesPlaylistTable) { sql = "DROP TABLE tbItunesPlaylist;"; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = sql; sqlite_cmd.ExecuteScalar(); } if (checkTables.HasItunesPlaylistSongTable) { sql = "DROP TABLE tbItunesPlaylistSong;"; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = sql; sqlite_cmd.ExecuteScalar(); } conn.Close(); } } catch (Exception ex) { op.AddException(ex); } }
//private readonly SQLiteConnection conn; public AdminRepository(string dbFileName, ref OperationResult op) { try { _dbFileName = dbFileName; _adminContext = new AdminDbContext(dbFileName); // Create a new database connection: //conn = new SQLiteConnection($"Data Source={dbFileName}; Version = 3; New = True; Compress = True; "); } catch (Exception ex) { op.AddException(ex); } }
private void CreateDbFiles(ref OperationResult op) { if (!MP3DBExists()) { op.AddError("You must choose an Access 2000 to 2003 version database (mdb) file!"); return; } try { MP3DBManager mdbmgr = new MP3DBManager(); mdbmgr.SetDataStore(ddtbMp3DbFile.ItemText, ref op); if (!op.Success) { return; } string dirName = dddtbTargetDir.ItemText; string delimiter = rbtnTab.Checked ? "\t" : ","; List <string> tables = new List <string> { "tbFileInfo", "tbMp3Info", "tbArtist" }; foreach (var table in tables) { string sql = $"select * from {table}"; List <string> data = GetTableData(sql, table, delimiter, ref op); if (!op.Success) { return; } string fName = Path.Combine(dirName, $"{table}.txt"); BCHFileIO.WriteFullFile(fName, data, ref op); if (!op.Success) { return; } } } catch (Exception ex) { op.AddException(ex); rtbMessages.Text = op.GetAllErrorsAndExceptions("\n"); return; } }
private void btnGetMusicInfo_Click(object sender, EventArgs e) { if (!Path.GetExtension(ddtbMp3File.ItemText).ToLower().EndsWith(".mp3")) { MessageBox.Show("Please enter a valid MP3 file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dddtbGetRootDir.ItemText.Trim().Length < 1) { MessageBox.Show("You must choose a music root folder!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } OperationResult op = new OperationResult(); string mscRtDir = dddtbGetRootDir.ItemText; string fileNamePath = ddtbMp3File.ItemText; try { MP3FileDataType me = ckbUseDirForInfo.Checked ? BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(fileNamePath, mscRtDir, ref op) : BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmt(fileNamePath, ref op); if (!op.Success) { MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } tbCalcTrack.Text = me.Track != null?me.Track.ToString() : string.Empty; tbCalcTitle.Text = me.SongTitleAndNumeration ?? string.Empty; tbCalcArtists.Text = me.ArtistsStrList ?? string.Empty; tbCalcAlbum.Text = me.Album ?? string.Empty; tbcalcComment.Text = me.Comments ?? string.Empty; tbCalcGenre.Text = me.Genre ?? string.Empty; } catch (Exception ex) { op.AddException(ex); MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void SaveMp3IdInfo(MP3FileDataType mp3, ref OperationResult op) { try { ID3Info id3 = new ID3Info(mp3.FileNamePath, true); string track = mp3.Track != null?mp3.Track.ToString() : "1"; string title = !string.IsNullOrEmpty(mp3.SongTitleAndNumeration) ? GetMaxLen(mp3.SongTitleAndNumeration, 30) : string.Empty; string artists = !string.IsNullOrEmpty(mp3.ArtistsStrList) ? GetMaxLen(mp3.ArtistsStrList, 30) : string.Empty; string album = !string.IsNullOrEmpty(mp3.Album) ? GetMaxLen(mp3.Album, 30) : string.Empty; string comments = !string.IsNullOrEmpty(mp3.Comments) ? GetMaxLen(mp3.Comments, 28) : string.Empty; List <string> GenreList = BCHMP3Utilities.GetGenre(); int genreIndx = GenreList.Contains(mp3.Genre, StringComparer.CurrentCultureIgnoreCase) ? GenreList.FindIndex( s => s.Trim().Equals(mp3.Genre.Trim(), StringComparison.CurrentCultureIgnoreCase)) : GenreList.FindIndex( s => s.Trim().Equals("Other", StringComparison.CurrentCultureIgnoreCase)); id3.ID3v1Info.TrackNumber = byte.Parse(track); id3.ID3v1Info.Title = title; id3.ID3v1Info.Artist = artists; id3.ID3v1Info.Album = album; id3.ID3v1Info.Comment = comments; id3.ID3v1Info.Genre = Convert.ToByte(genreIndx); id3.ID3v2Info.SetTextFrame("TRCK", track); id3.ID3v2Info.SetTextFrame("TIT2", title); id3.ID3v2Info.SetTextFrame("TPE1", artists); id3.ID3v2Info.SetTextFrame("TALB", album); id3.ID3v2Info.SetTextFrame("WCOM", comments); id3.ID3v2Info.SetTextFrame("TCON", GenreList[genreIndx]); id3.ID3v2Info.HaveTag = true; id3.Save(); } catch (Exception ex) { op.AddException(ex); } }