Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

BSEtunes

, 24 Apr 2010 CPOL
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten.zip
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
Settings.settings
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
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
Settings.settings
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
Settings.settings
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
Settings.settings
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.Platten_en.zip
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
Settings.settings
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
Settings.settings
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
Settings.settings
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
Settings.settings
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
Settings.settings
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.zip
MySQL.chm
MySqlCreateDataBase5x.sql.zip
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using BSE.CDDrives;
using BSE.Platten.BO;
using BSE.Platten.Common;
using BSE.Windows.Forms;
using BSE.Shell;
using System.Reflection;
using System.IO;
using System.Collections.ObjectModel;
using BSE.Platten.Ripper.Properties;
using System.Globalization;

namespace BSE.Platten.Ripper
{
    public partial class CMain : BaseForm, IConfigurationSettings
    {
        #region Constants

        private const string m_strSettingsFileNameSettingsPart = ".Settings";

        #endregion
        
        #region Delegates

        private delegate void RipTrackHandler(CTrack track);

        #endregion

        #region FieldsPrivate

        private bool m_bExternalOutPutConfiguration;
        private bool m_bWarningIfCancelButtonClicked;
        private uint m_iQueryCancelAutoPlay;
        private RippingOptionsConfigurationData m_rippingOptionsConfigurationObject;
        private FileConfigurationData m_fileConfigurationObject;
        private CDDrive m_cdDrive;
        private CAlbum m_currentAlbum;
        private CAlbum m_albumFromFreeDb;
        private List<CTrack> m_rippedTrackCollection;
        private CEnvironment m_environment;
        private string m_strHomeDirectory;
        private string m_strTrackName;
        private string m_strInterpret;
        private string m_strAlbum;

        #endregion

        #region Properties

        #region IConfigurationSettings

        public string ConfigurationFolder
        {
            get { return this.GetType().Namespace; }
        }

        public string ConfigurationFileName
        {
            get { return this.GetType().Namespace; }
        }

        public string SettingsFileName
        {
            get { return ConfigurationFileName + m_strSettingsFileNameSettingsPart; }
        }
        #endregion

        [Description("external configuration: home directory for audio files"),
		Category("Appearance")]
		public string HomeDirectory
		{
			get { return this.m_strHomeDirectory; }
			set { this.m_strHomeDirectory = value; }
		}
		
		[Description("external configuration: output- trackname"),
		Category("Appearance")]
		public string TrackName
		{
			get { return this.m_strTrackName; }
			set {this.m_strTrackName = value; }
		}

        public BSE.Platten.BO.CAlbum Album
		{
            get { return this.m_currentAlbum; }
			set
			{
                if (value != null)
                {
                    if (value != this.m_currentAlbum)
                    {
                        this.m_currentAlbum = value;
                        this.m_strInterpret = this.m_currentAlbum.Interpret;
                        if (this.m_strInterpret != null)
                        {
                            this.m_strInterpret = CEnvironment.ParseOutInvalidFileNameChars(
                                this.m_strInterpret);
                            if (!this.m_strInterpret.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                            {
                                this.m_strInterpret += System.IO.Path.DirectorySeparatorChar;
                            }
                        }
                        this.m_strAlbum = this.m_currentAlbum.Title;
                        if (this.m_strAlbum != null)
                        {
                            this.m_strAlbum = CEnvironment.ParseOutInvalidFileNameChars(
                                this.m_strAlbum);
                            if (!this.m_strAlbum.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                            {
                                this.m_strAlbum += System.IO.Path.DirectorySeparatorChar;
                            }
                        }
                    }
                }
			}
		}
        /// <summary>
        /// Gets the tracklist for importing
        /// </summary>
        public List<CTrack> ImportTrackCollection
        {
            get { return this.m_rippedTrackCollection; }
        }

        #endregion

        #region MethodsPublic

        public CMain()
        {
            InitializeComponent();
            this.m_environment = new CEnvironment();
            this.m_pnlAction.Visible = false;
            this.m_configuration.ApplicationSubDirectory = this.ConfigurationFolder;
            this.m_configuration.ConfigFileName = this.ConfigurationFileName;

            this.m_settings.ApplicationSubDirectory = this.ConfigurationFolder;
            this.m_settings.ConfigFileName = this.SettingsFileName;

            this.m_lstvMain.AlternatingBackColor = BSE.Platten.Common.BSEColors.AlternatingBackColor;
            this.m_lstvCopied.AlternatingBackColor = BSE.Platten.Common.BSEColors.AlternatingBackColor;

            this.m_rippingOptionsConfigurationObject = new RippingOptionsConfigurationData();
            this.m_fileConfigurationObject = new FileConfigurationData();

            this.m_cdDrive = new CDDrive();
            this.m_cdDrive.CDInserted += new EventHandler(this.m_CDDrive_CDInserted);
            this.m_cdDrive.CDRemoved += new EventHandler(this.m_CDDrive_CDRemoved);

            this.AllowDrop = true;
            this.KeyPreview = true;
        }

        public CMain(BSE.Configuration.CConfiguration configuration)
            : this()
        {
            this.m_bExternalOutPutConfiguration = true;
            this.m_configuration = configuration;
            this.m_pnlAction.Visible = true;
        }

        #endregion

        #region MethodsProtected

        protected override void WndProc(ref Message m)
        {
            if (this.m_iQueryCancelAutoPlay == 0)
            {
                this.m_iQueryCancelAutoPlay = BSE.CDDrives.W32.Win32.RegisterWindowMessage("QueryCancelAutoPlay");
            }
            if (m.Msg == this.m_iQueryCancelAutoPlay)
            {
                m.Result = (IntPtr)1;
            }
            else
            {
                base.WndProc(ref m);
            }
        }

        #endregion

        #region MethodsPrivate

        private void m_mnuDatei_End_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void m_mnuBearbeiten_OpenDrive_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            ClearAllControls();
            if (this.m_cdDrive.EjectCD())
            {
                this.m_ssMain.Text = string.Format(CultureInfo.CurrentUICulture, Resources.IDS_EjectCD);
            }
            Cursor.Current = Cursors.Default;
        }

        private void m_mnuBearbeiten_CopyTracks_Click(object sender, EventArgs e)
        {
            int iCountTracks = this.m_lstvMain.SelectedItems.Count;
            if (iCountTracks > 0)
            {
                Collection<CTrack> tracksToRipCollection = new Collection<CTrack>();

                for (int i = 0; i < iCountTracks; i++)
                {
                    CTrack track = this.m_lstvMain.SelectedItems[i].Tag as CTrack;
                    if (track != null)
                    {
                        tracksToRipCollection.Add(track);
                    }
                }
                RipTracks(tracksToRipCollection);
            }
        }

        private void MnuHelpShowHelpClick(object sender, EventArgs e)
        {
            Help.ShowHelp(this, "BSEripper.chm", HelpNavigator.Topic, "HTML/BSEripper5.html");
        }

        private void m_mnuExtras_Optionen_Click(object sender, EventArgs e)
        {
            COptions options = new COptions(this.m_configuration);
            options.ConfigurationChanged += new System.EventHandler(this.OptionsChanged);
            options.ShowDialog(this);
        }

        private void OptionsChanged(object sender, System.EventArgs e)
        {
            this.m_rippingOptionsConfigurationObject =
                RippingConfigurationControl.GetConfiguration(this.m_configuration) as RippingOptionsConfigurationData;

            this.m_fileConfigurationObject =
                FileConfigurationControl.GetConfiguration(this.m_configuration) as FileConfigurationData;

            LoadCDIntoListView();
        }

        private void m_cboCDDrives_SelectedIndexChanged(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.m_btnBrowseFreeDb.Enabled = false;
            ClearAllControls();
            this.m_cboCDDrives.Enabled = false;
            this.m_cdDrive.Close();
            LoadCDIntoListView();
            this.m_cboCDDrives.Enabled = true;
            Cursor.Current = Cursors.Default;
        }

        private void m_btnCancel_Click(object sender, EventArgs e)
        {
            if (this.m_bExternalOutPutConfiguration)
            {
                if (this.m_lstvCopied.Items.Count > 0)
                {
                    this.m_bWarningIfCancelButtonClicked = true;
                }
            }
        }

        private void m_btnBrowseFreeDb_Click(object sender, EventArgs e)
        {
            if (this.m_cdDrive.IsCDReady())
            {
                Cursor.Current = Cursors.WaitCursor;
                BSE.Platten.FreeDb.CFreeDb freeDb = new BSE.Platten.FreeDb.CFreeDb();
                try
                {
                    BSE.Platten.BO.CAlbum albumFromFreeDb = freeDb.GetMediaDataForCD(this.m_cdDrive.GetQueryStringOfDisc());
                    if (albumFromFreeDb != null)
                    {
                        this.m_albumFromFreeDb = albumFromFreeDb;
                        //Nur wenn FreeDb Tracks vorhanden sind, wird die ListView neu gebaut
                        if (this.m_albumFromFreeDb.Tracks != null)
                        {
                            LoadCDIntoListView();
                        }
                    }
                }
                catch (BSE.Platten.FreeDb.FreeDbMatchNoneException freeDbMatchNoneException)
                {
                    GlobalizedMessageBox.Show(this, freeDbMatchNoneException.Message, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this,exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }

        private void m_txtStartIndex_TextChanged(object sender, EventArgs e)
        {
            GetTrackStartIndex();
            LoadCDIntoListView();
        }

        private void m_lstvCopied_SubItemEndEditing(object sender, BSE.Windows.Forms.SubItemEndEditingEventArgs e)
        {
            ListViewItem listViewItem = e.ListViewItem;
            CTrack track = (CTrack)listViewItem.Tag;
            System.Reflection.PropertyInfo propertyInfo = track.GetType().GetProperty("Title");
            if (e.DisplayText != propertyInfo.GetValue(track, null).ToString())
            {
                track.Title = e.DisplayText;
            }
        }

        private void m_lstvCopied_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Delete:
                    int iCountSelectedItems = this.m_lstvCopied.SelectedItems.Count;
                    int iItemsCounter = 0;
                    string[] aDelete = new String[iCountSelectedItems];
                    foreach (ListViewItem listViewItem in this.m_lstvCopied.SelectedItems)
                    {
                        CTrack trackToRemove = (CTrack)listViewItem.Tag;
                        if (trackToRemove != null)
                        {
                            aDelete[iItemsCounter] = trackToRemove.FileFullName;
                            iItemsCounter++;
                        }
                        this.m_lstvCopied.Items.Remove(listViewItem);
                    }
                    if (this.m_lstvCopied.Items.Count == 0)
                    {
                        this.m_btnOK.Enabled = false;
                    }
                    ShellFileOperation fileOperation = new ShellFileOperation();
                    fileOperation.SourceFiles = aDelete;
                    fileOperation.Operation = ShellFileOperation.FileOperations.FO_DELETE;
                    fileOperation.DoOperation();
                    break;
            }
        }

        private void m_lstvCopied_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data is CDataObject)
            {
                //Get the dataobject
                CDataObject dataObject = (CDataObject)e.Data;
                CDraggedListViewObjects draggedListViewObjects = null;
                //check the overload of the dataobject
                if (dataObject.GetDataPresent(typeof(CDraggedListViewObjects).ToString()))
                {
                    draggedListViewObjects
                        = (CDraggedListViewObjects)dataObject.GetData(
                        typeof(CDraggedListViewObjects).ToString());
                    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.GetType() == typeof(System.Windows.Forms.ListViewItem))
                    {
                        int iCountTracks = draggedListViewObjects.DragObjects.Count;
                        if (iCountTracks > 0)
                        {
                            Collection<CTrack> tracksToRipCollection = new Collection<CTrack>();
                            for (int i = 0; i < iCountTracks; i++)
                            {
                                ListViewItem listViewItem = draggedListViewObjects.DragObjects[i] as ListViewItem;
                                if (listViewItem != null)
                                {
                                    CTrack track = listViewItem.Tag as CTrack;
                                    if (track != null)
                                    {
                                        tracksToRipCollection.Add(track);
                                    }
                                }
                            }
                            RipTracks(tracksToRipCollection);
                        }
                    }
                }
            }
        }

        private void m_lstvMain_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateViewState();
        }

        private void m_lstvMain_SubItemEndEditing(object sender, BSE.Windows.Forms.SubItemEndEditingEventArgs e)
        {
            ListViewItem listViewItem = e.ListViewItem;
            CTrack track = (CTrack)listViewItem.Tag;
            PropertyInfo propertyInfo = track.GetType().GetProperty("Title");
            if (e.DisplayText != propertyInfo.GetValue(track, null).ToString())
            {
                try
                {
                    bool bTitleAsFileName = false;
                    string strTitle = e.DisplayText;
                    string strDirectory = GetFileFullNameByOptionSettings();

                    track.Title = strTitle;

                    if (bTitleAsFileName)
                    {
                        strTitle = CEnvironment.ParseOutInvalidFileNameChars(strTitle);
                        track.FileName = string.Format(
                            CultureInfo.InvariantCulture,
                            "({0}) {1}{2}",
                            track.TrackNumber.ToString("00"),strTitle,track.Extension);

                    }

                    //Wenn FreeDb Tracks vorhanden sind..
                    if ((this.m_albumFromFreeDb != null) && (this.m_albumFromFreeDb.Tracks != null))
                    {
                        //wird der ge�nderte Text in den zugeh�renden FreeDb Track geschrieben
                        //damit wird sichergestellt, dass diese Text�nderung beim �ndern des Trackindexes nicht
                        //verloren geht
                        this.m_albumFromFreeDb.Tracks[track.Index].Title = e.DisplayText;
                    }
                    track.FileFullName = strDirectory + track.FileName;
                    listViewItem.SubItems[4].Text = track.FileFullName;
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this,exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void CMain_Load(object sender, EventArgs e)
        {
            this.m_rippingOptionsConfigurationObject =
                RippingConfigurationControl.GetConfiguration(this.m_configuration) as RippingOptionsConfigurationData;

            this.m_fileConfigurationObject =
                FileConfigurationControl.GetConfiguration(this.m_configuration) as FileConfigurationData;

            char[] cdDrives = CDDrive.GetCDDriveLetters();
            foreach (char cdDrive in cdDrives)
            {
                this.m_cboCDDrives.Items.Add(cdDrive.ToString());
            }
            this.m_cboCDDrives.SelectedIndex = 0;

            //die Properties der Controls werden gesetzt
            LoadSettings();
        }
        
        private void CMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            //die Properties der Controls werden gespeichert
            SaveSettings();
        }
        
        private void CMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.m_bWarningIfCancelButtonClicked)
            {
                DialogResult dialogResult = GlobalizedMessageBox.Show(
                    this,
                    Resources.IDS_RippingAbortInformation,
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning);

                if (dialogResult == DialogResult.No)
                {
                    //Wenn der Benutzer Nein w�hlt wird das Formular nicht geschlossen
                    e.Cancel = true;
                    this.m_bWarningIfCancelButtonClicked = false;
                }
            }

            if (this.m_cdDrive.IsOpened)
            {
                this.m_cdDrive.Close();
            }
        }
        
        private void m_btnOK_Click(object sender, EventArgs e)
        {
            int iRippedTrackCounter = this.m_lstvCopied.Items.Count;
            if (iRippedTrackCounter > 0)
            {
                if (this.m_rippedTrackCollection == null)
                {
                    this.m_rippedTrackCollection = new List<CTrack>();
                }
                this.m_rippedTrackCollection.Clear();
                foreach (ListViewItem listViewItem in this.m_lstvCopied.Items)
                {
                    CTrack rippedTrack = listViewItem.Tag as CTrack;
                    if (rippedTrack != null)
                    {
                        this.m_rippedTrackCollection.Add(rippedTrack);
                    }
                }
                if (this.m_rippedTrackCollection != null)
                {
                    PropertyDescriptorCollection propertyDescriptorCollection = TypeDescriptor.GetProperties(typeof(CTrack));
                    PropertyDescriptor propertyDescriptor = propertyDescriptorCollection.Find("TrackNumber", false);
                    this.m_rippedTrackCollection.Sort(new PropertyComparer<CTrack>(propertyDescriptor, ListSortDirection.Ascending));
                }
            }
        }
        
        private void m_CDDrive_CDInserted(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (this.m_cdDrive.Open(char.Parse(this.m_cboCDDrives.Items[this.m_cboCDDrives.SelectedIndex].ToString())))
            {
                LoadCDIntoListView();
            }
            Cursor.Current = Cursors.Default;
        }

        private void m_CDDrive_CDRemoved(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.m_btnBrowseFreeDb.Enabled = false;
            ClearAllControls();
            this.m_ssMain.Text = string.Format(CultureInfo.CurrentUICulture, Resources.IDS_CDEjected);
            Cursor.Current = Cursors.Default;
        }

        private void ClearAllControls()
        {
            this.m_lstvMain.Items.Clear();
            if (this.m_albumFromFreeDb != null)
            {
                this.m_albumFromFreeDb = null;
            }
            this.m_ssMain.Text = string.Empty;
            if (this.m_lstvCopied.Items.Count == 0)
            {
                this.m_btnOK.Enabled = false;
            }
        }

        private void UpdateViewState()
        {
            this.m_mnuBearbeiten_CopyTracks.Enabled = false;
            if (this.m_lstvMain.SelectedItems.Count > 0)
            {
                this.m_mnuBearbeiten_CopyTracks.Enabled = true;
            }
        }

        private void LoadCDIntoListView()
        {
            Cursor.Current = Cursors.WaitCursor;
            string strDiskId = string.Empty;
            this.m_cboCDDrives.Enabled = false;
            this.m_btnBearbeiten_OpenDrive.Enabled = this.m_mnuBearbeiten_OpenDrive.Enabled = false;
            this.m_lstvMain.Items.Clear();
            UpdateViewState();

            if (this.m_cdDrive.Open(char.Parse(this.m_cboCDDrives.Items[this.m_cboCDDrives.SelectedIndex].ToString())))
            {
                if (this.m_cdDrive.IsCDReady())
                {
                    this.m_ssMain.Text = string.Format(CultureInfo.CurrentUICulture, Resources.IDS_LoadCD);
                    if (this.m_cdDrive.Refresh())
                    {
                        this.m_btnBrowseFreeDb.Enabled = true;
                        int iTracks = this.m_cdDrive.GetNumTracks();
                        int iTrackIndex = GetTrackStartIndex();
                        strDiskId = this.m_cdDrive.GetDiskId();

                        for (int i = 0; i < iTracks; i++)
                        {
                            BSE.Platten.BO.CTrack track = new BSE.Platten.BO.CTrack();
                            track.Index = i;
                            track.CDIndex = i + 1;
                            track.Identifier = string.Format(CultureInfo.InvariantCulture,"{0}{1}", strDiskId, track.CDIndex.ToString("_00"));
                            track.TrackNumber = iTrackIndex;
                            track.Title = string.Format(CultureInfo.InvariantCulture,"{0}_{1}", this.TrackName, iTrackIndex.ToString("00"));
                            track.Duration = Convert.ToDateTime(this.m_cdDrive.Duration(track.CDIndex),CultureInfo.CurrentUICulture);
                            track.TrackSize = this.m_cdDrive.TrackSize(track.CDIndex);
                            track.UsedAudioFormat = this.m_rippingOptionsConfigurationObject.UsedAudioFormat;
                            if (track.UsedAudioFormat == CAudioFormat.AudioFormat.Mp3)
                            {
                                track.Extension = AudioformatExtensions.Mp3;
                            }
                            else if (track.UsedAudioFormat == CAudioFormat.AudioFormat.Wav)
                            {
                                track.Extension = AudioformatExtensions.Wav;
                            }
                            track.FileName = string.Format(CultureInfo.InvariantCulture,"{0}_{1}{2}",this.TrackName, iTrackIndex.ToString("00"), track.Extension);
                            string strDirectory = GetFileFullNameByOptionSettings();

                            if (this.m_albumFromFreeDb != null)
                            {
                                if (this.m_albumFromFreeDb.Tracks != null)
                                {
                                    track.Identifier = string.Format(CultureInfo.InvariantCulture,"{0}{1}", this.m_albumFromFreeDb.MediaId, track.CDIndex.ToString("_00"));
                                    track.Title = this.m_albumFromFreeDb.Tracks[track.Index].Title;
                                    if (this.m_fileConfigurationObject.TitleAsFileName == true)
                                    {
                                        string strTitle = track.Title;
                                        strTitle = CEnvironment.ParseOutInvalidFileNameChars(track.Title);
                                        track.FileName = string.Format(CultureInfo.InvariantCulture,"({0}) {1}{2}", iTrackIndex.ToString("00"), strTitle, track.Extension);
                                    }
                                }
                            }

                            track.FileFullName = strDirectory + track.FileName;

                            if (this.m_cdDrive.IsAudioTrack(track.CDIndex))
                            {

                                ListViewItem listViewItem = new ListViewItem();
                                listViewItem.Text = track.Title;
                                listViewItem.Tag = track;

                                listViewItem.SubItems.AddRange(new string[] {track.TrackSize.ToString("N0"),
                                                                                this.m_cdDrive.IsAudioTrack(track.CDIndex)?"audio":"data",
                                                                                track.Duration.ToLongTimeString(),
                                                                                track.FileFullName});

                                m_lstvMain.Items.Add(listViewItem);
                                m_lstvMain.UpdateItem(listViewItem.Index);
                            }
                            iTrackIndex++;
                        }
                        //wird ben�tigt damit die ListView die Items beim neuladen nicht durcheinander bringt
                        this.m_lstvMain.Refresh();
                        this.m_ssMain.Text = string.Format(CultureInfo.CurrentUICulture, Resources.IDS_CDReady);
                    }
                }
                else
                {
                    this.m_ssMain.Text = string.Format(CultureInfo.CurrentUICulture, Resources.IDS_CDNotReady);
                    this.m_btnBrowseFreeDb.Enabled = false;
                }
            }
            this.m_cboCDDrives.Enabled = true;
            this.m_btnBearbeiten_OpenDrive.Enabled = this.m_mnuBearbeiten_OpenDrive.Enabled = true;
            Cursor.Current = Cursors.Default;
        }

        private void RipTracks(Collection<CTrack> tracksToRipCollection)
        {
            if (tracksToRipCollection != null)
            {
                if (tracksToRipCollection.Count > 0)
                {
                    string strDirectory = GetFileFullNameByOptionSettings();
                    DirectoryInfo directoryInfo = new DirectoryInfo(strDirectory);
                    if (directoryInfo.Exists == false)
                    {
                        try
                        {
                            directoryInfo.Create();
                        }
                        catch (System.UnauthorizedAccessException unauthorizedAccessException)
                        {
                            GlobalizedMessageBox.Show(
                                this,
                                unauthorizedAccessException.Message,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                        }
                    }

                    RipTracks ripTracks = new RipTracks(this.m_configuration, tracksToRipCollection);
                    ripTracks.CDDrive = this.m_cdDrive;
                    ripTracks.ProfessionalColorTable = this.ProfessionalColorTable;
                    ripTracks.PanelStyle = this.PanelStyle;
                    ripTracks.PanelColors = this.PanelColors;
                    ripTracks.RippingComplete -= new System.EventHandler(this.RippingComplete);
                    ripTracks.RippingComplete += new System.EventHandler(this.RippingComplete);
                    ripTracks.TrackRipped -= new EventHandler<TrackRippingEventArgs>(this.TrackRipped);
                    ripTracks.TrackRipped += new EventHandler<TrackRippingEventArgs>(this.TrackRipped);
                    ripTracks.ShowDialog();
                }
            }
        }

        private void RippingComplete(object sender, System.EventArgs e)
        {
            if (this.m_lstvCopied.Items.Count > 0)
            {
                this.m_btnOK.Enabled = true;
            }
            foreach (ListViewItem listViewItem in this.m_lstvMain.SelectedItems)
            {
                listViewItem.Selected = false;
            }
        }

        private void TrackRipped(object sender, TrackRippingEventArgs e)
        {
            this.Invoke(new RipTrackHandler(RippTrackEvent), e.Track);
        }

        private void RippTrackEvent(CTrack rippedTrack)
        {
            if (rippedTrack != null)
            {
                ListViewItem listViewItem = new ListViewItem(rippedTrack.FileFullName);
                listViewItem.SubItems.Add(rippedTrack.TrackNumber.ToString());
                listViewItem.SubItems.Add(rippedTrack.Title);
                listViewItem.SubItems.Add(rippedTrack.Duration.ToLongTimeString());
                listViewItem.Tag = rippedTrack;
                this.m_lstvCopied.Items.Add(listViewItem);
                //mit EnsureVisible wird sichergestellt, dass das neue ListViewItem sichtbar bleibt
                listViewItem.EnsureVisible();
            }
        }

        private string GetFileFullNameByOptionSettings()
        {
            string strFileFullName = string.Empty;
            string strInterpret = string.Empty;
            string strAlbum = string.Empty;
            if (this.m_fileConfigurationObject.EachAlbumGetsDirectory == true)
            {
                if (this.m_bExternalOutPutConfiguration)
                {
                    strInterpret = this.m_strInterpret;
                    strAlbum = this.m_strAlbum;
                }
                else
                {
                    if (this.m_albumFromFreeDb != null)
                    {
                        strInterpret = CEnvironment.ParseOutInvalidFileNameChars(this.m_albumFromFreeDb.Interpret);
                        if (!strInterpret.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                        {
                            strInterpret += System.IO.Path.DirectorySeparatorChar;
                        }
                        strAlbum = CEnvironment.ParseOutInvalidFileNameChars(this.m_albumFromFreeDb.Title);
                        if (!strAlbum.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                        {
                            strAlbum += System.IO.Path.DirectorySeparatorChar;
                        }
                    }
                }
            }

            string strHomeDirectory = this.HomeDirectory;
            if (!strHomeDirectory.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
            {
                strHomeDirectory += System.IO.Path.DirectorySeparatorChar;
            }

            strFileFullName = strHomeDirectory + strInterpret + strAlbum;
            if (string.IsNullOrEmpty(strFileFullName) == false)
            {
                if (!strFileFullName.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                {
                    strFileFullName += System.IO.Path.DirectorySeparatorChar;
                }
            }

            return strFileFullName;
        }

        private int GetTrackStartIndex()
        {
            string strException = String.Format(CultureInfo.CurrentUICulture,Resources.IDS_TrackStartIndexEception);
            int iTrackIndex = 1;
            if (int.TryParse(this.m_txtStartIndex.Text, out iTrackIndex) == false)
            {
                GlobalizedMessageBox.Show(this, strException, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.m_txtStartIndex.Text = string.Format(CultureInfo.InvariantCulture, "1");
            }
            else
            {
                if (iTrackIndex < 1)
                {
                    GlobalizedMessageBox.Show(this, strException, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.m_txtStartIndex.Text = string.Format(CultureInfo.InvariantCulture,"1");
                }
            }
            return iTrackIndex;
        }

        private void LoadSettings()
        {
            RipperSettingsData ripperSettingsData = new RipperSettingsData();
            //-------------------------------------------------------------------------------
            // Default Values
            //-------------------------------------------------------------------------------
            ripperSettingsData.HeightPnlRipper = this.m_pnlRipper.Height;
            ripperSettingsData.HeightPnlCopied = this.m_pnlCopied.Height;
            
            ripperSettingsData = ripperSettingsData.LoadSettings(this, this.m_settings, ripperSettingsData) as RipperSettingsData;
            if (ripperSettingsData != null)
            {
                //-------------------------------------------------------------------------------
                // Background Image des Contents
                //-------------------------------------------------------------------------------
                this.ContentPanel.BackgroundImage = ripperSettingsData.BackgroundImage;
                if (this.ContentPanel.BackgroundImage != null)
                {
                    this.ContentPanel.BackgroundImageLayout = ImageLayout.Tile;
                }
                //-------------------------------------------------------------------------------
                // H�he des Ripper Panels neu setzen.
                //
                if (ripperSettingsData.HeightPnlRipper > 0)
                {
                    this.m_pnlRipper.Height = ripperSettingsData.HeightPnlRipper;
                }
                //-------------------------------------------------------------------------------
                // H�he des Copied Panels neu setzen.
                //
                if (ripperSettingsData.HeightPnlCopied > 0)
                {
                    this.m_pnlCopied.Height = ripperSettingsData.HeightPnlCopied;
                }
                //-------------------------------------------------------------------------------
                // Spaltenbreite der ListView Main neu setzen.
                //-------------------------------------------------------------------------------
                int iSizeMain = this.m_lstvMain.Columns.Count;
                int[] columnWidthsMain = ripperSettingsData.ColumnWidthsLvwMain;
                if (columnWidthsMain != null)
                {
                    int iSizeIntArray = columnWidthsMain.Length;
                    for (int i = 0; i < iSizeMain; ++i)
                    {
                        if (i < iSizeIntArray)
                        {
                            this.m_lstvMain.Columns[i].Width = columnWidthsMain[i];
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                //-------------------------------------------------------------------------------
                // Spaltenbreite der ListView Copied neu setzen.
                //-------------------------------------------------------------------------------
                int iSizeLvwCopied = this.m_lstvCopied.Columns.Count;
                int[] columnWidthsLvwCopied = ripperSettingsData.ColumnWidthsLvwCopied;
                if (columnWidthsLvwCopied != null)
                {
                    int iSizeIntArray = columnWidthsLvwCopied.Length;
                    for (int i = 0; i < iSizeLvwCopied; ++i)
                    {
                        if (i < iSizeIntArray)
                        {
                            this.m_lstvCopied.Columns[i].Width = columnWidthsLvwCopied[i];
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }

        private void SaveSettings()
        {
            RipperSettingsData ripperSettingsData = new RipperSettingsData();

            ripperSettingsData.BackgroundImage = this.ContentPanel.BackgroundImage;

            if (this.WindowState == FormWindowState.Normal)
            {
                ripperSettingsData.HeightPnlRipper = this.m_pnlRipper.Height;
                ripperSettingsData.HeightPnlCopied = this.m_pnlCopied.Height;
            }

            int iSizeLvwMain = this.m_lstvMain.Columns.Count;
            int[] columnWidthsLvwMain = new int[iSizeLvwMain];
            for (int i = 0; i < iSizeLvwMain; ++i)
            {
                columnWidthsLvwMain[i] = this.m_lstvMain.Columns[i].Width;
            }
            ripperSettingsData.ColumnWidthsLvwMain = columnWidthsLvwMain;

            int iSizeLvwCopied = this.m_lstvCopied.Columns.Count;
            int[] columnWidthsLvwCopied = new int[iSizeLvwCopied];
            for (int i = 0; i < iSizeLvwCopied; ++i)
            {
                columnWidthsLvwCopied[i] = this.m_lstvCopied.Columns[i].Width;
            }
            ripperSettingsData.ColumnWidthsLvwCopied = columnWidthsLvwCopied;

            ripperSettingsData.SaveSettings(this, this.m_settings, ripperSettingsData);
        }

        #endregion

        #region internal class CTrackSorter

        //internal class CTrackSorter<T> : IComparer<T>
        //{
        //    private SortOrder m_sortOrder;

        //    public CTrackSorter(SortOrder sortOrder)
        //    {
        //        this.m_sortOrder = sortOrder;
        //    }
        //    public int Compare(T x, T y)
        //    {
        //        object xValue = value.GetType().GetProperty("TrackNumber");
        //        object yValue = value.GetType().GetProperty("TrackNumber");
        //        IComparable value = x as IComparable;
        //        if (value != null)
        //        {
        //            switch (this.m_sortOrder)
        //            {

        //                case SortOrder.Ascending:
        //                    IComparable value = x as IComparable;
        //                    return x.TrackNumber.CompareTo(((CTrack)y).TrackNumber);
        //                case SortOrder.Descending:
        //                    return ((CTrack)x).TrackNumber.CompareTo(((CTrack)y).TrackNumber);
        //                default:
        //                    return ((CTrack)x).TrackNumber.CompareTo(((CTrack)y).TrackNumber);
        //            }
        //        }
        //    }
        //}

        //internal class CTrackSorter : System.Collections.IComparer
        //{
        //    private SortOrder m_sortOrder;

        //    public CTrackSorter(SortOrder sortOrder)
        //    {
        //        this.m_sortOrder = sortOrder;
        //    }
        //    public int Compare(object x, object y)
        //    {
        //        switch (this.m_sortOrder)
        //        {
        //            case SortOrder.Ascending:
        //                return ((CTrack)x).TrackNumber.CompareTo(((CTrack)y).TrackNumber);
        //            case SortOrder.Descending:
        //                return ((CTrack)x).TrackNumber.CompareTo(((CTrack)y).TrackNumber);
        //            default:
        //                return ((CTrack)x).TrackNumber.CompareTo(((CTrack)y).TrackNumber);
        //        }
        //    }
        //}

        #endregion
        
    }

    public class RipperSettingsData : BaseFormSettingsData
    {
        #region FieldsPrivate
        /// <summary>
        /// Spaltenbreiten f�r ListView Main
        /// </summary>
        private int[] m_iarColumnWidthslvwMain;
        /// <summary>
        /// Spaltenbreiten f�r ListView Copied
        /// </summary>
        private int[] m_iarColumnWidthslvwCopied;
        /// <summary>
        /// H�he des Main Panels
        /// </summary>
        private int m_iHeightPnlRipper;
        /// <summary>
        /// H�he des Copied Panels
        /// </summary>
        private int m_iHeightPnlCopied;
        #endregion

        #region Properties

        /// <summary>
        /// Spaltenbreiten f�r ListView Main
        /// </summary>
        public int[] ColumnWidthsLvwMain
        {
            get { return this.m_iarColumnWidthslvwMain; }
            set { this.m_iarColumnWidthslvwMain = value; }
        }
        /// <summary>
        /// Spaltenbreiten f�r ListView HomeDirectory
        /// </summary>
        public int[] ColumnWidthsLvwCopied
        {
            get { return this.m_iarColumnWidthslvwCopied; }
            set { this.m_iarColumnWidthslvwCopied = value; }
        }
        /// <summary>
        /// H�he des ImportDirectory Panels
        /// </summary>
        public int HeightPnlRipper
        {
            get { return this.m_iHeightPnlRipper; }
            set { this.m_iHeightPnlRipper = value; }
        }
        /// <summary>
        /// H�he des HomeDirectory Panels
        /// </summary>
        public int HeightPnlCopied
        {
            get { return this.m_iHeightPnlCopied; }
            set { this.m_iHeightPnlCopied = value; }
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Eichkorn

Switzerland Switzerland
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150301.1 | Last Updated 24 Apr 2010
Article Copyright 2009 by Uwe Eichkorn
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid