Ejemplo n.º 1
0
        private void cmdCopy_Click(object sender, EventArgs e)
        {
            lbLoading.BringToFront();
            lbLoading.Text = "Preparing dump..."; Application.DoEvents();

            int iTotal = 0;

            bool[] bCopy = new bool[DB.Length];
            for (int a = 0; a < DG.RowCount; a++)
            {
                if (DG[0, a].Selected)
                {
                    int i = Convert.ToInt32(DG[0, a].Value.ToString()) - 1;
                    bCopy[i] = true; iTotal++;
                }
            }

            lbLoading.TextAlign = ContentAlignment.TopLeft;
            lbLoading.Text      = "Dumping " + iTotal + " songs..."; Application.DoEvents();
            for (int a = 0; a < DB.Length; a++)
            {
                if (bCopy[a])
                {
                    DB[a].n01_Title  = DB[a].n01_Title.Trim(new char[] { ' ', '\t', '\r', '\n' });
                    DB[a].n03_Album  = DB[a].n03_Album.Trim(new char[] { ' ', '\t', '\r', '\n' });
                    DB[a].n04_Artist = DB[a].n04_Artist.Trim(new char[] { ' ', '\t', '\r', '\n' });

                    lbLoading.Text = "Song [" + a + "] of [" + iTotal + "]" +
                                     "\r\n\r\n" +
                                     "  [TITLE] " + DB[a].n01_Title + "\r\n" +
                                     "[ARTIST] " + DB[a].n04_Artist + "\r\n" +
                                     "[ALBUM] " + DB[a].n03_Album + "\r\n\r\n";
                    Application.DoEvents();

                    string sFName = "";
                    string sPath  = txtPath.Text;
                    string sFType = "." + DB[a].n02_Path.Split('.')[1];

                    string sFPath = DB[a].n03_Album
                                    .Replace("\\", "[bs]").Replace("/", "[fs]").Replace(":", "[co]")
                                    .Replace("\"", "[qt]").Replace("*", "[as]").Replace("?", "[qm]")
                                    .Replace("<", "[lt]").Replace(">", "[gt]").Replace("|", "[pi]");

                    if (DB[a].n03_Album != "")
                    {
                        sPath += sFPath + "\\";
                    }
                    else
                    {
                        sPath += "no!album" + "\\";
                    }
                    if (DB[a].n04_Artist != "")
                    {
                        sFName += DB[a].n04_Artist + " - ";
                    }
                    else
                    {
                        sFName += "no!artist" + " - ";
                    }
                    if (DB[a].n01_Title != "")
                    {
                        sFName += DB[a].n01_Title;
                    }
                    else
                    {
                        sFName += "no!title";
                    }

                    sFName = sFName
                             .Replace("\\", "[bs]").Replace("/", "[fs]").Replace("?", "[qm]")
                             .Replace("<", "[lt]").Replace(">", "[gt]").Replace("|", "[pi]")
                             .Replace("*", "[as]").Replace("\"", "''").Replace(":", "[co]");

                    bool bAddNum = false; int iNum = 2;
                    if (System.IO.File.Exists(sPath + sFName + sFType))
                    {
                        bAddNum = true;
                    }
                    while (System.IO.File.Exists(sPath + sFName + " (" + iNum + ")" + sFType))
                    {
                        iNum++;
                    }

                    lbLoading.Text += (sPath + sFName + sFType)
                                      .Replace("\\", " \\ ").Replace("/", " / ");
                    Application.DoEvents();
                    if (!System.IO.Directory.Exists(sPath))
                    {
                        System.IO.Directory.CreateDirectory(sPath);
                    }

                    if (bAddNum)
                    {
                        sFName += " (" + iNum + ")";
                    }
                    System.IO.File.Copy(Path_Pod.Substring(0, 2) +
                                        DB[a].n02_Path.Replace(':', '\\'), sPath + sFName + sFType);
                }
            }

            lbLoading.TextAlign = ContentAlignment.MiddleCenter;
            lbLoading.Text      = "Done."; Application.DoEvents();
            System.Threading.Thread.Sleep(1000);
            DG.BringToFront();
        }