Click here to Skip to main content
12,349,582 members (27,391 online)
Click here to Skip to main content

Stats

38.8K views
3.9K downloads
57 bookmarked
Posted

BSEtunes

, 24 Apr 2010 CPOL
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten
BSE.Platten.vssscc
mssccprj.scc
vssver2.scc
BSE.CoverFlow.WPFLib
BSE.CoverFlow.WPFLib.csproj.user
BSE.CoverFlow.WPFLib.csproj.vspscc
mssccprj.scc
vssver2.scc
Images
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Properties
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp
BSE.Platten.Admin.WinApp.csproj.user
BSE.Platten.Admin.WinApp.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEadmin.ico
vssver2.scc
BSE.Platten.Audio
bse.ico
BSE.Platten.Audio.csproj.vspscc
mssccprj.scc
vssver2.scc
Options
vssver2.scc
Player
vssver2.scc
Properties
vssver2.scc
Resources
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
WinControls
vssver2.scc
WMFSDK
vssver2.scc
BSE.Platten.BO
BSE.Platten.BO.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Common
BSE.Platten.Common.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers
BSE.Platten.Covers.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.FreeDb
BSE.Platten.FreeDb.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
vssver2.scc
BSE.Platten.Ripper
BSE.Platten.Ripper.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik
BSE.Platten.Statistik.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Tunes
BSE.Platten.Tunes.csproj.user
BSE.Platten.Tunes.csproj.vspscc
mssccprj.scc
vssver2.scc
Filters
vssver2.scc
Properties
vssver2.scc
Resources
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup
BSEadminSetup.vdproj
BSEadminSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
BSEtunesSetup
BSEtunesSetup.vdproj
BSEtunesSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
dll
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.Windows.Forms.DLL
Lame
lame_enc.dll
vssver2.scc
lame-3.97
BSE.CoverFlow.WPFLib.csproj.user
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
vssver2.scc
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp.csproj.user
vssver2.scc
BSEadmin.ico
vssver2.scc
bse.ico
BSE.Platten.Audio.csproj.user
vssver2.scc
vssver2.scc
vssver2.scc
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.BO.csproj.user
vssver2.scc
BSE.Platten.Common.csproj.user
vssver2.scc
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers.csproj.user
vssver2.scc
BSE.Platten.FreeDb.csproj.user
vssver2.scc
OpenCD.png
vssver2.scc
AudioWriter
vssver2.scc
BSE.Platten.Ripper.csproj.user
Lame
vssver2.scc
vssver2.scc
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik.csproj.user
vssver2.scc
BSE.Platten.Tunes.csproj.user
vssver2.scc
vssver2.scc
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup.vdproj
BSEtunesSetup.vdproj
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.ThreadedShell.DLL
BSE.Windows.Forms.DLL
lame_enc.dll
MySQL.chm
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.IO;
using System.Collections.ObjectModel;
using BSE.Platten.Common;
using BSE.Platten.BO;
using BSE.Platten.Audio;
using System.Security.Permissions;

namespace BSE.Platten.Tunes
{
    public partial class XPanderPanelAudioDrive : BSE.Windows.Forms.XPanderPanel
    {
        #region Delegates
        private delegate void AddTreeNode(DirectoryInfo directoryInfo);
        private delegate void AddListViewItem(AudioMetaDataFile audioMetaDataFile);
        #endregion

        #region FieldsPrivate
        private CEnvironment m_environment;
        private BSE.RemovableDrives.RemovableDrive m_audioDrive;
        private Queue<DirectoryInfo> m_queueDirectoryInfos;
        private Queue<AudioMetaDataFile> m_queueFiles;
        private string m_strCurrentDirectoryName;
        private string m_strVolumeName;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the removable audiodrive.
        /// </summary>
        /// <value>
        /// Type: <see cref="BSE.RemovableDrives.RemovableDrive"/>
        /// The removable audiodrive.
        /// </value>
        public BSE.RemovableDrives.RemovableDrive AudioDrive
        {
            get { return this.m_audioDrive; }
            set
            {
                this.m_audioDrive = value;
                OnDriveChanges(this, new BSE.RemovableDrives.DriveChangeEventArgs(this.m_audioDrive));
            }
        }
        /// <summary>
        /// Gets the name of the volume.
        /// </summary>
        /// <value>
        /// Type: <see cref="System.IO.DriveInfo"/>
        /// The name of the volume.
        /// </value>
        public string VolumeName
        {
            get { return this.m_strVolumeName; }
        }
        public CEnvironment Environment
        {
            get { return this.m_environment; }
            set { this.m_environment = value; }
        }
        /// <summary>
        /// Gets or sets the settings for the control.
        /// </summary>
        /// <value>
        /// Type: <see cref="BSE.Configuration.CConfiguration"/>
        /// The settings for the control.
        /// </value>
        public BSE.Configuration.CConfiguration Settings
        {
            get { return this.m_settings; }
            set { this.m_settings = value; }
        }
        #endregion

        #region MethodsPublic
        public XPanderPanelAudioDrive()
        {
            InitializeComponent();
            this.m_trvDirectories.TreeViewNodeSorter = new TreeNodeSorter();
        }
        #endregion

        #region MethodsProtected
        /// <summary>
        /// Raises the CloseClick event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An EventArgs that contains the event data.</param>
        protected override void OnCloseClick(object sender, EventArgs e)
        {
            SaveSettings();
            base.OnCloseClick(sender, e);
        }
        /// <summary>
        /// Raises the DriveChanges event.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// Type: <see cref="BSE.RemovableDrives.DriveChangeEventArgs"/>
        /// A DriveChangeEventArgs that contains the event data.
        /// </param>
        [SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode = false)]
        protected virtual void OnDriveChanges(object sender, BSE.RemovableDrives.DriveChangeEventArgs e)
        {
            BSE.RemovableDrives.RemovableDrive removableDrive = e.RemovableDrive;
            if (removableDrive != null)
            {
                if (this.m_trvDirectories.Enabled == false)
                {
                    this.m_trvDirectories.Enabled = true;
                }
                if (this.m_lstvDirectoriesAndFiles.Enabled == false)
                {
                    this.m_lstvDirectoriesAndFiles.Enabled = true;
                }
                this.m_strVolumeName = removableDrive.VolumeName;
                string strVolume = string.Format(CultureInfo.InvariantCulture,
                                                "{0} ({1})",
                                                removableDrive.VolumeLabel,
                                                removableDrive.Name);
                this.Text = strVolume;
                this.m_lstvDirectoriesAndFiles.Items.Clear();
                this.m_trvDirectories.Nodes.Clear();
                
                SetProgressBarValues();
                SetRootNode(removableDrive.DriveInfo.RootDirectory);
                this.Cursor = Cursors.WaitCursor;
                if (this.m_queueDirectoryInfos == null)
                {
                    this.m_queueDirectoryInfos = new Queue<DirectoryInfo>();
                }
                this.m_queueDirectoryInfos.Clear();
                if (this.m_queueFiles == null)
                {
                    this.m_queueFiles = new Queue<AudioMetaDataFile>();
                }
                this.m_queueFiles.Clear();
                
                this.m_fileSystemWatcher.Path = removableDrive.DriveInfo.RootDirectory.FullName;
                this.m_trvDirectories.BeginUpdate();
                this.m_backgroundWorkerDirectories.RunWorkerAsync(removableDrive.DriveInfo.RootDirectory);
            }
            else
            {
                this.m_trvDirectories.Enabled = false;
                this.m_lstvDirectoriesAndFiles.Enabled = false;
            }
        }
        /// <summary>
        /// Raises the CreateControl method.
        /// </summary>
        protected override void OnCreateControl()
        {
            Form parentForm = this.FindForm();
            if (parentForm != null)
            {
                parentForm.FormClosing += new FormClosingEventHandler(PlayListFormClosing);
                LoadSettings();
            }
            base.OnCreateControl();
        }
        #endregion

        #region MethodsPrivate

        private void GetDirectories(DirectoryInfo rootDirectoryInfo)
        {
            DirectoryInfo[] directories = null;
            try
            {
                directories = rootDirectoryInfo.GetDirectories();
            }
            catch (UnauthorizedAccessException) { }

            if (directories != null)
            {
                DirectoryInfoComparer directoryInfoComparer = new DirectoryInfoComparer();
                Array.Sort(directories, directoryInfoComparer);
                foreach (DirectoryInfo directoryInfo in directories)
                {
                    lock (this.m_queueDirectoryInfos)
                    {
                        this.m_queueDirectoryInfos.Enqueue(directoryInfo);
                    }
                    this.m_backgroundWorkerDirectories.ReportProgress(int.MinValue);
                    DirectoryInfo[] subDirectories = null;
                    try
                    {
                        subDirectories = directoryInfo.GetDirectories();
                    }
                    catch (UnauthorizedAccessException)
                    {
                        continue;
                    }
                    if (subDirectories != null)
                    {
                        GetDirectories(directoryInfo);
                    }
                }
            }
        }

        private TreeNode GetParentTreeNode(DirectoryInfo directoryInfo)
        {
            TreeNode parentTreeNode = null;
            DirectoryInfo parentDirectory = directoryInfo.Parent;
            TreeNode[] treeNodes = this.m_trvDirectories.Nodes.Find(parentDirectory.FullName, true);
            if (treeNodes.Length > 0)
            {
                parentTreeNode = treeNodes[0];
            }
            return parentTreeNode;
        }

        private void SetRootNode(DirectoryInfo directoryInfo)
        {
            TreeNode rootTreeNode = new TreeNode();
            rootTreeNode.Name = directoryInfo.FullName;
            rootTreeNode.Text = directoryInfo.Name;
            this.m_trvDirectories.Nodes.Add(rootTreeNode);
        }

        private void SetProgressBarValues()
        {
            DriveInfo driveInfo = new DriveInfo(this.m_audioDrive.Name);
            if (driveInfo != null)
            {
                long lTotalSize = driveInfo.TotalSize;
                long lUsedSize = driveInfo.TotalSize - driveInfo.AvailableFreeSpace;

                int iPercent = (int)((float)lUsedSize / (float)lTotalSize * 100);
                this.m_progressBar.Value = iPercent;
                this.m_progressBar.Text = string.Format(CultureInfo.InvariantCulture, "{0}%", iPercent);
            }
        }

        private void TreeViewDirectoriesAfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode selectedTreeNode = e.Node;
            if (selectedTreeNode != null)
            {
                this.m_strCurrentDirectoryName = selectedTreeNode.Name;
                ListingDirectoriesAndFiles(this.m_strCurrentDirectoryName);
            }
        }

        private void TreeViewDirectoriesMouseDoubleClick(object sender, MouseEventArgs e)
        {
            TreeNode selectedTreeNode = this.m_trvDirectories.GetNodeAt(e.X, e.Y);
            if (selectedTreeNode != null)
            {
                if (selectedTreeNode.IsExpanded == false)
                {
                    selectedTreeNode.Expand();
                }
            }
        }

        private void TreeViewDirectoriesKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                TreeNode treeNode = this.m_trvDirectories.SelectedNode;
                if (treeNode != null)
                {
                    try
                    {
                        TreeNode rootTreeNode = this.m_trvDirectories.Nodes[0];
                        if (rootTreeNode.Equals(treeNode) == false)
                        {
                            DirectoryInfo directoryInfo = new DirectoryInfo(treeNode.Name);
                            if (directoryInfo.Exists == true)
                            {
                                String[] sourceFiles = new String[1];
                                sourceFiles[0] = directoryInfo.FullName;
                                if (DeleteFilesAndFolders(sourceFiles, this.Handle) == true)
                                {
                                    directoryInfo.Refresh();
                                    if (directoryInfo.Exists == false)
                                    {
                                        TreeNode[] treeNodes = this.m_trvDirectories.Nodes.Find(directoryInfo.FullName, true);
                                        if (treeNodes.Length > 0)
                                        {
                                            TreeNode treeNodeToRemove = treeNodes[0];
                                            if (treeNodeToRemove != null)
                                            {
                                                TreeNode parentTreeNode = treeNodes[0].Parent;
                                                if (parentTreeNode != null)
                                                {
                                                    //Erst nachdem der neue Knoten selektiert wurde,
                                                    this.m_trvDirectories.SelectedNode = parentTreeNode;
                                                    //darf der urspr�nglich selektierte Knoten entfernt werden
                                                    parentTreeNode.Nodes.Remove(treeNodeToRemove);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        private void FileSystemWatcherCreated(object sender, FileSystemEventArgs e)
        {
            SetProgressBarValues();
            DirectoryInfo directoryInfo = new DirectoryInfo(e.FullPath);
            if (directoryInfo.Exists == true)
            {
                AddDirectoryInfoToTreeView(directoryInfo);
                TreeNode parentTreeNode = this.GetParentTreeNode(directoryInfo);
                if (string.Equals(parentTreeNode.Name, this.m_strCurrentDirectoryName, StringComparison.OrdinalIgnoreCase) == true)
                {
                    ListingDirectoriesAndFiles(this.m_strCurrentDirectoryName);
                }
            }
        }

        private void FileSystemWatcherDeleted(object sender, FileSystemEventArgs e)
        {
            SetProgressBarValues();
        }

        private void ListingDirectoriesAndFiles(string strCurrentDirectory)
        {
            this.Cursor = Cursors.WaitCursor;
            this.m_lstvDirectoriesAndFiles.Items.Clear();
            if (string.IsNullOrEmpty(strCurrentDirectory) == false)
            {
                this.m_lstvDirectoriesAndFiles.BeginUpdate();
                DirectoryInfo rootDirectoryInfo = new DirectoryInfo(strCurrentDirectory);
                if ((rootDirectoryInfo != null) && (rootDirectoryInfo.Exists == true))
                {
                    DirectoryInfo[] directories = rootDirectoryInfo.GetDirectories();
                    if (directories != null)
                    {
                        DirectoryInfoComparer directoryInfoComparer = new DirectoryInfoComparer();
                        Array.Sort(directories, directoryInfoComparer);
                        foreach (DirectoryInfo directoryInfo in directories)
                        {
                            ListViewItem listViewItem = new ListViewItem();
                            listViewItem.Tag = directoryInfo;
                            listViewItem.Text = directoryInfo.Name;
                            listViewItem.ImageIndex = 1;
                            listViewItem.SubItems.Add(string.Empty);
                            listViewItem.SubItems.Add(string.Empty);
                            listViewItem.SubItems.Add(string.Empty);
                            listViewItem.SubItems.Add(string.Empty);
                            listViewItem.SubItems.Add(string.Empty);
                            listViewItem.SubItems.Add(string.Empty);
                            listViewItem.SubItems.Add(string.Empty);
                            this.m_lstvDirectoriesAndFiles.Items.Add(listViewItem);
                        }
                    }
                    this.m_backgroundWorkerFiles.RunWorkerAsync(rootDirectoryInfo);
                }
            }
        }

        private void ListViewDirectoriesAndFilesDoubleClick(object sender, EventArgs e)
        {
            if (this.m_lstvDirectoriesAndFiles.SelectedItems.Count != 0)
            {
                ListViewItem listViewItem = this.m_lstvDirectoriesAndFiles.SelectedItems[0];// .FocusedItem;
                if (listViewItem != null)
                {
                    DirectoryInfo directoryInfo = listViewItem.Tag as DirectoryInfo;
                    if (directoryInfo != null)
                    {
                        TreeNode[] treeNodes = this.m_trvDirectories.Nodes.Find(directoryInfo.FullName, true);
                        if (treeNodes.Length > 0)
                        {
                            TreeNode selectedNode = treeNodes[0];
                            if (selectedNode != null)
                            {
                                selectedNode.Expand();
                                this.m_trvDirectories.SelectedNode = selectedNode;
                            }
                        }
                    }
                }
            }
        }

        private void ListViewDirectoriesAndFilesKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                System.Collections.ArrayList filesAndDirectories = new System.Collections.ArrayList();
                foreach (ListViewItem listViewItem in this.m_lstvDirectoriesAndFiles.SelectedItems)
                {
                    DirectoryInfo directoryInfo = listViewItem.Tag as DirectoryInfo;
                    if (directoryInfo != null)
                    {
                        if (directoryInfo.Exists == true)
                        {
                            filesAndDirectories.Add(directoryInfo);
                        }
                    }
                    FileInfo fileInfo = listViewItem.Tag as FileInfo;
                    if (fileInfo != null)
                    {
                        if (fileInfo.Exists == true)
                        {
                            filesAndDirectories.Add(fileInfo);
                        }
                    }
                }
                int iCountItems = filesAndDirectories.Count;
                String[] sourceFiles = new String[iCountItems];
                iCountItems = 0;
                foreach (object fileOrDirectory in filesAndDirectories)
                {
                    DirectoryInfo directoryInfo = fileOrDirectory as DirectoryInfo;
                    if (directoryInfo != null)
                    {
                        sourceFiles[iCountItems] = directoryInfo.FullName;
                    }
                    FileInfo fileInfo = fileOrDirectory as FileInfo;
                    if (fileInfo != null)
                    {
                        sourceFiles[iCountItems] = fileInfo.FullName;
                    }
                    iCountItems++;
                }

                if (DeleteFilesAndFolders(sourceFiles, this.Handle) == true)
                {
                    foreach (ListViewItem listViewItem in this.m_lstvDirectoriesAndFiles.SelectedItems)
                    {
                        DirectoryInfo directoryInfo = listViewItem.Tag as DirectoryInfo;
                        if (directoryInfo != null)
                        {
                            directoryInfo.Refresh();
                            if (directoryInfo.Exists == false)
                            {
                                this.m_lstvDirectoriesAndFiles.Items.Remove(listViewItem);
                                TreeNode[] treeNodes = this.m_trvDirectories.Nodes.Find(directoryInfo.FullName, true);
                                if (treeNodes.Length > 0)
                                {
                                    TreeNode treeNodeToRemove = treeNodes[0];
                                    if (treeNodeToRemove != null)
                                    {
                                        this.m_trvDirectories.Nodes.Remove(treeNodeToRemove);
                                    }
                                }
                            }
                        }
                        FileInfo fileInfo = listViewItem.Tag as FileInfo;
                        if (fileInfo != null)
                        {
                            fileInfo.Refresh();
                            if (fileInfo.Exists == false)
                            {
                                this.m_lstvDirectoriesAndFiles.Items.Remove(listViewItem);
                            }
                        }
                    }
                }
            }
        }

        private void TreeViewDirectoriesDragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetType() == typeof(BSE.Windows.Forms.CDataObject))
            {
                e.Effect = DragDropEffects.All;
            }
        }

        private void DirectoriesAndFilesDragDrop(object sender, DragEventArgs e)
        {
            BSE.Windows.Forms.CDataObject dataObject = e.Data as BSE.Windows.Forms.CDataObject;
            if (dataObject != null)
            {
                try
                {
                    Control control = sender as Control;
                    object hoverItem = null;
                    // get the currently hovered row that the items will be dragged to
                    Point clientPoint = control.PointToClient(new Point(e.X, e.Y));
                    ListView listView = control as ListView;
                    if (listView != null)
                    {
                        hoverItem = listView.GetItemAt(clientPoint.X, clientPoint.Y);
                    }
                    TreeView treeView = control as TreeView;
                    if (treeView != null)
                    {
                        hoverItem = treeView.GetNodeAt(clientPoint.X, clientPoint.Y);
                    }

                    BSE.Windows.Forms.CDraggedListViewObjects draggedListViewObjects = null;
                    //check the overload of the dataobject
                    if (dataObject.GetDataPresent(typeof(BSE.Windows.Forms.CDraggedListViewObjects)))
                    {
                        draggedListViewObjects
                            = (BSE.Windows.Forms.CDraggedListViewObjects)dataObject.GetData(
                            typeof(BSE.Windows.Forms.CDraggedListViewObjects));
                        if (draggedListViewObjects.ParentListView == null)
                        {
                            return;
                        }
                    }
                    if (dataObject.DragData != null)
                    {
                        draggedListViewObjects
                            = (BSE.Windows.Forms.CDraggedListViewObjects)dataObject.DragData;

                        if (draggedListViewObjects.ParentListView == null)
                        {
                            return;
                        }
                    }
                    if (draggedListViewObjects != null)
                    {
                        object dragObject = draggedListViewObjects.DragObjects[0];
                        //Wenn das Object vom Typ ListViewItem ist werden die ListViewItems in die ListView eingef�gt
                        if (dragObject is System.Windows.Forms.ListViewItem)
                        {
                            InsertItems(control, hoverItem, draggedListViewObjects);
                        }

                        PlayListDragDropData playListDragDropData = dragObject as PlayListDragDropData;
                        if (playListDragDropData != null)
                        {
                            InsertAlbum(control, hoverItem, playListDragDropData.Id);
                        }
                    }
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void InsertItems(object sender, object hoverItem, BSE.Windows.Forms.CDraggedListViewObjects draggedListViewObjects)
        {
            string strCurrentDirectory = this.m_strCurrentDirectoryName;
            try
            {
                strCurrentDirectory = GetCurrentCopyDirectory(sender, hoverItem, strCurrentDirectory);

                Collection<CTrack> tracksToCopy = null;
                foreach (object dragObject in draggedListViewObjects.DragObjects)
                {
                    ListViewItem listViewItem = dragObject as ListViewItem;
                    if (listViewItem != null)
                    {
                        CTrack track = listViewItem.Tag as CTrack;
                        if (track != null)
                        {
                            FileInfo fileInfo = new FileInfo(track.FileFullName);
                            if (fileInfo.Exists == true)
                            {
                                if (tracksToCopy == null)
                                {
                                    tracksToCopy = new Collection<CTrack>();
                                }
                                track.Extension = fileInfo.Extension;
                                tracksToCopy.Add(track);
                            }
                        }
                    }
                }
                if (tracksToCopy != null)
                {
                    CopyFiles(tracksToCopy, strCurrentDirectory, this.Handle);
                    this.m_trvDirectories.Sort();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void InsertAlbum(object sender, object hoverItem, int iAlbumId)
        {
            if (this.m_environment != null)
            {
                CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.m_environment.GetConnectionString());
                try
                {
                    CTrack[] tracks = tunesBusinessObject.GetAlbumTracksForPlayListByTitelId(iAlbumId);
                    if (tracks != null)
                    {
                        string strAudioHomeDirectory = CAlbum.GetAudioHomeDirectory(this.m_environment);
                        string strCurrentDirectory = this.m_strCurrentDirectoryName;
                        strCurrentDirectory = GetCurrentCopyDirectory(sender, hoverItem, strCurrentDirectory);

                        Collection<CTrack> tracksToCopy = null;
                        foreach (CTrack track in tracks)
                        {
                            if (string.IsNullOrEmpty(track.FileName) == false)
                            {
                                string strFullName = System.IO.Path.Combine(strAudioHomeDirectory, track.FileName);
                                FileInfo fileInfo = new FileInfo(strFullName);
                                if (fileInfo.Exists == true)
                                {
                                    if (tracksToCopy == null)
                                    {
                                        tracksToCopy = new Collection<CTrack>();
                                    }
                                    track.FileFullName = strFullName;
                                    track.Extension = fileInfo.Extension;
                                    tracksToCopy.Add(track);
                                }
                            }
                        }

                        if (tracksToCopy != null)
                        {
                            CopyFiles(tracksToCopy, strCurrentDirectory, this.Handle);
                            this.m_trvDirectories.Sort();
                        }
                    }
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private static bool CopyFiles(Collection<CTrack> tracksCollection, string strCurrentDirectory, IntPtr pHandle)
        {
            if (tracksCollection != null)
            {
                int iCountTracks = tracksCollection.Count;
                if (iCountTracks > 0)
                {
                    String[] sourceFiles = new String[iCountTracks];
                    String[] destinationFiles = new String[iCountTracks];

                    iCountTracks = 0;
                    foreach (CTrack track in tracksCollection)
                    {
                        sourceFiles[iCountTracks] = track.FileFullName;

                        string strDestinationFile = string.Format(CultureInfo.InvariantCulture, "({0}) {1}{2}",
                            track.TrackNumber, track.Title, track.Extension);

                        strDestinationFile = CEnvironment.ParseOutInvalidFileNameChars(
                            strDestinationFile);

                        string strInterpret = track.Interpret;
                        strInterpret = CEnvironment.RemoveInvalidFolderChars(strInterpret);
                        string strRelativePath = System.IO.Path.Combine(strCurrentDirectory, strInterpret);

                        string strAlbum = track.Album;
                        strAlbum = CEnvironment.RemoveInvalidFolderChars(strAlbum);
                        strRelativePath = System.IO.Path.Combine(strRelativePath, strAlbum);

                        string strFullName = System.IO.Path.Combine(strRelativePath, strDestinationFile);

                        destinationFiles[iCountTracks] = strFullName;
                        iCountTracks++;
                    }

                    BSE.Shell.ShellFileOperation shellFileOperation = new BSE.Shell.ShellFileOperation();
                    shellFileOperation.Operation = BSE.Shell.ShellFileOperation.FileOperations.FO_COPY;
                    shellFileOperation.OperationFlags = BSE.Shell.ShellFileOperation.ShellFileOperationFlags.FOF_MULTIDESTFILES | BSE.Shell.ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMMKDIR;
                    shellFileOperation.OwnerWindow = pHandle;
                    shellFileOperation.SourceFiles = sourceFiles;
                    shellFileOperation.DestFiles = destinationFiles;

                    return shellFileOperation.DoOperation();
                }
            }

            return false;
        }

        private static bool DeleteFilesAndFolders(string[] strSourceFiles, IntPtr pHandle)
        {
            bool bDeleteOk = false;

            BSE.Shell.ShellFileOperation shellFileOperation = new BSE.Shell.ShellFileOperation();
            shellFileOperation.Operation = BSE.Shell.ShellFileOperation.FileOperations.FO_DELETE;
            shellFileOperation.OwnerWindow = pHandle;
            shellFileOperation.SourceFiles = strSourceFiles;

            bDeleteOk = shellFileOperation.DoOperation();

            return bDeleteOk;
        }

        private static string GetCurrentCopyDirectory(object sender, object hoverItem, string strCurrentDirectory)
        {
            // Wenn das Album ans Ende des Trees gezogen wird...
            if (hoverItem == null)
            {
                TreeView treeView = sender as TreeView;
                if (treeView != null)
                {
                    // muss das Rootverzeichnis verwendet werden
                    strCurrentDirectory = treeView.Nodes[0].Name;
                }
            }
            else
            {
                TreeNode treeNode = hoverItem as TreeNode;
                if (treeNode != null)
                {
                    strCurrentDirectory = treeNode.Name;
                }
                ListViewItem listViewItem = hoverItem as ListViewItem;
                if (listViewItem != null)
                {
                    DirectoryInfo directoryInfo = listViewItem.Tag as DirectoryInfo;
                    if (directoryInfo != null)
                    {
                        strCurrentDirectory = directoryInfo.FullName;
                    }
                }
            }
            return strCurrentDirectory;
        }

        private void AddDirectoryInfoToTreeView(DirectoryInfo directoryInfo)
        {
            TreeNode parentTreeNode = GetParentTreeNode(directoryInfo);
            if (parentTreeNode != null)
            {
                TreeNode treeNode = new TreeNode();
                treeNode.Name = directoryInfo.FullName;
                treeNode.Text = directoryInfo.Name;
                treeNode.ImageIndex = 1;
                treeNode.SelectedImageIndex = 2;
                parentTreeNode.Nodes.Add(treeNode);

                if (string.Equals(parentTreeNode.Name, this.m_audioDrive.DriveInfo.RootDirectory.FullName, StringComparison.OrdinalIgnoreCase) == true)
                {
                    parentTreeNode.Expand();
                }
            }
        }

        private void AddAudioMetaDataFilesToListView(AudioMetaDataFile audioMetaDataFile)
        {
            if (audioMetaDataFile != null)
            {
                FileInfo fileInfo = audioMetaDataFile.FileInfo;
                if (fileInfo != null)
                {
                    ListViewItem listViewItem = new ListViewItem();
                    listViewItem.Text = fileInfo.Name;
                    AudioMetaData audioMetaData = audioMetaDataFile.AudioMetaData;
                    if (audioMetaData != null)
                    {
                        DateTime dateTime = new DateTime(audioMetaData.Duration);
                        listViewItem.SubItems.Add(audioMetaData.WMTrackNumber);
                        listViewItem.SubItems.Add(audioMetaData.Author);
                        listViewItem.SubItems.Add(audioMetaData.WMAlbumTitle);
                        listViewItem.SubItems.Add(audioMetaData.Title);
                        listViewItem.SubItems.Add(dateTime.ToLongTimeString());
                        listViewItem.SubItems.Add(audioMetaData.WMGenre);
                        listViewItem.SubItems.Add(audioMetaData.WMYear);
                    }

                    if (this.m_imageList.Images.ContainsKey(fileInfo.Extension) == false)
                    {
                        using (Icon associatedIcon = System.Drawing.Icon.ExtractAssociatedIcon(fileInfo.FullName))
                        {
                            int iIconHeightAndWidth = 16;
                            if (associatedIcon.Height > iIconHeightAndWidth)
                            {
                                using (System.Drawing.Bitmap bitMap = associatedIcon.ToBitmap())
                                {
                                    Image thumNail = bitMap.GetThumbnailImage(iIconHeightAndWidth, iIconHeightAndWidth, null, IntPtr.Zero);
                                    this.m_imageList.Images.Add(fileInfo.Extension, thumNail);
                                }
                            }
                        }
                    }
                    listViewItem.ImageKey = fileInfo.Extension;
                    listViewItem.Tag = fileInfo;
                    this.m_lstvDirectoriesAndFiles.Items.Add(listViewItem);
                    this.m_lstvDirectoriesAndFiles.Update();
                }
            }
        }

        private void BackgroundWorkerDirectoriesDoWork(object sender, DoWorkEventArgs e)
        {
            DirectoryInfo rootDirectoryInfo = e.Argument as DirectoryInfo;
            if ((rootDirectoryInfo != null) && (rootDirectoryInfo.Exists == true))
            {
                GetDirectories(rootDirectoryInfo);
            }
        }

        private void BackgroundWorkerDirectoriesProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (this.m_queueDirectoryInfos.Count > 0)
            {
                lock (this.m_queueDirectoryInfos)
                {
                    DirectoryInfo directoryInfo = this.m_queueDirectoryInfos.Peek();
                    if (directoryInfo != null)
                    {
                        TreeNode parentTreeNode = GetParentTreeNode(directoryInfo);
                        if (parentTreeNode != null)
                        {
                            this.m_trvDirectories.Invoke(new AddTreeNode(this.AddDirectoryInfoToTreeView),
                                new object[] { directoryInfo });
                            this.m_queueDirectoryInfos.Dequeue();
                        }
                    }
                }
            }
        }

        private void BackgroundWorkerDirectoriesRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.m_trvDirectories.SelectedNode = this.m_trvDirectories.Nodes[0];
            this.m_trvDirectories.EndUpdate();
            this.Cursor = Cursors.Default;
        }

        private void BackgroundWorkerFilesDoWork(object sender, DoWorkEventArgs e)
        {
            DirectoryInfo directoryInfo = e.Argument as DirectoryInfo;
            if ((directoryInfo != null) && (directoryInfo.Exists == true))
            {
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                if (fileInfos != null)
                {
                    FileInfoComparer fileInfoComparer = new FileInfoComparer();
                    Array.Sort(fileInfos, fileInfoComparer);
                    foreach (FileInfo fileInfo in fileInfos)
                    {
                        lock (this.m_queueFiles)
                        {
                            AudioMetaDataFile audioMetaDataFile = new AudioMetaDataFile();
                            audioMetaDataFile.FullName = fileInfo.FullName;
                            audioMetaDataFile.FileInfo = fileInfo;
                            if ((string.Compare(fileInfo.Extension.ToLowerInvariant(), AudioformatExtensions.Mp3, StringComparison.OrdinalIgnoreCase) == 0) ||
                                (string.Compare(fileInfo.Extension.ToLowerInvariant(), AudioformatExtensions.Wma, StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                AudioData audioData = new CWMFMediaData();
                                try
                                {
                                    AudioMetaData audioMetaData = audioData.GetMediaMetaData(fileInfo.FullName);
                                    if (audioMetaData != null)
                                    {
                                        audioMetaDataFile.AudioMetaData = audioMetaData;
                                    }
                                }
                                catch (Exception) {}
                            }
                            this.m_queueFiles.Enqueue(audioMetaDataFile);
                        }
                        this.m_backgroundWorkerFiles.ReportProgress(int.MinValue);
                    }
                }
            }
        }

        private void BackgroundWorkerFilesProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (this.m_queueFiles.Count > 0)
            {
                lock (this.m_queueFiles)