コード例 #1
0
ファイル: Form1.cs プロジェクト: NickNirus/EchoprintRadioScan
        public bool ShowDialogBox(Code fromDb, Code newCode)
        {
            var testDialog = new dialog();

            //from db
            testDialog.textBox1.Text = fromDb.metadata.artist;
            // Show testDialog as a modal dialog and determine if DialogResult = OK.
            if (testDialog.ShowDialog(this) == DialogResult.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
            testDialog.Dispose();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: NickNirus/EchoprintRadioScan
        private string[] repairMp3Tags(string[] files)
        {
            Program.Message("Start repair...");
            var  result   = new List <string>();
            bool isStoped = false;

            try
            {
                var index = 1;
                if (progressBar4.InvokeRequired)
                {
                    progressBar4.Invoke((MethodInvoker) delegate
                    {
                        progressBar4.Maximum = files.Count();
                        progressBar4.Minimum = 1;
                        progressBar4.Step    = 1;
                    });
                }
                else
                {
                    progressBar4.Maximum = files.Count();
                    progressBar4.Minimum = 1;
                    progressBar4.Step    = 1;
                }
                foreach (var f in files)
                {
                    var artist = string.Empty;
                    var title  = string.Empty;

                    var name = Path.GetFileName(f).Replace(".mp3", "");
                    //name = name.Substring(4);
                    var splitname = name.Split('-');

                    Program.Message(string.Format("{0:HH:mm:ss} - {1}", DateTime.Now, f));
                    doProgressImportedFields(index++);

                    if (splitname.Length > 2)
                    {
                        var testDialog = new dialog();
                        testDialog.StartPosition = FormStartPosition.CenterParent;
                        testDialog.textBox1.Text = name;
                        if (testDialog.InvokeRequired)
                        {
                            testDialog.Invoke(new MethodInvoker(delegate
                            {
                                var dialog = testDialog.ShowDialog(this);
                                if (dialog == DialogResult.Cancel)
                                {
                                    isStoped = true;
                                }

                                // Show testDialog as a modal dialog and determine if DialogResult = OK.
                                if (dialog == DialogResult.OK)
                                {
                                    name      = testDialog.textBox1.Text;
                                    splitname = name.Split('-');
                                }
                                testDialog.Close();
                            }));
                        }
                        else
                        {
                            var dialog = testDialog.ShowDialog(this);
                            if (dialog == DialogResult.Cancel)
                            {
                                isStoped = true;
                            }

                            // Show testDialog as a modal dialog and determine if DialogResult = OK.
                            if (dialog == DialogResult.OK)
                            {
                                name      = testDialog.textBox1.Text;
                                splitname = name.Split('-');
                            }

                            testDialog.Close();
                        }
                        // MessageBox.Show(string.Format("Contains multiple '-', Please rename file: {0}", f));
                    }
                    else if (splitname.Length == 1)
                    {
                        var testDialog = new dialog();
                        testDialog.StartPosition = FormStartPosition.CenterParent;
                        testDialog.textBox1.Text = name;

                        // Show testDialog as a modal dialog and determine if DialogResult = OK.
                        if (testDialog.ShowDialog(this) == DialogResult.OK)
                        {
                            name      = testDialog.textBox1.Text;
                            splitname = name.Split('-');
                        }

                        testDialog.Close();
                    }

                    artist = splitname[0];
                    title  = splitname[1];

                    if (string.IsNullOrWhiteSpace(artist))
                    {
                        MessageBox.Show(string.Format("IsNullOrWhiteSpace artist from file: {0}", f));
                        //  throw new Exception(string.Format("IsNullOrWhiteSpace artist from file: {0}", f));
                    }

                    if (string.IsNullOrWhiteSpace(title))
                    {
                        MessageBox.Show(string.Format("IsNullOrWhiteSpace title from file: {0}", f));
                        //   throw new Exception(string.Format("IsNullOrWhiteSpace title from file: {0}", f));
                    }
                    try
                    {
                        TagLib.File file = TagLib.File.Create(f);
                        file.Tag.Title      = CyrilicToLatin(title);
                        file.Tag.Artists    = new[] { CyrilicToLatin(artist) };
                        file.Tag.Performers = new[] { CyrilicToLatin(artist) };
                        file.Save();
                    }
                    catch (Exception ex)
                    {
                        Program.Message(ex.Message);
                        //MessageBox.Show(string.Format("save tag for: {0}-{1}", ex.Message, f));
                    }
                    result.Add(CyrilicToLatin(f));
                    var newFile = Path.Combine(Path.GetDirectoryName(f), CyrilicToLatin(name) + ".mp3");
                    if (!File.Exists(newFile))
                    {
                        File.Move(f, newFile);
                    }
                }
                if (isStoped)
                {
                    MessageBox.Show("Stoped");
                }
                else
                {
                    MessageBox.Show(string.Format("Success renamed files: {0}", files.Length));
                }
            }
            catch (Exception ex)
            {
                Program.Message(string.Format("{0:HH:mm:ss} - {1}", DateTime.Now, ex.Message));
            }
            return(result.ToArray <string>());
        }