/* * * Copyright (C) 2007 Jmaxxz * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /** * Sorry for the bad formating, Visual Studios 2003 in Vista seems to have a glitch where * it randomly inserts tabs into strings, to save myself the trouble of trying to find all * of these goof ups I just replace tabs with "" everynow and then. Resulting in the ugly * formating you see here. */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Text; namespace Samsung_Playlist_Creator { /// /// This application allows the user to create and modify playlist files /// for Samsung's yp-t8 player (and possibly other Samsung players). /// /// public class playlistManager : System.Windows.Forms.Form { /// Version(build date) public const String BUILD_DATE = "5-23-2007"; private System.Windows.Forms.MainMenu menuBar; private System.Windows.Forms.Panel pnlButtons; private System.Windows.Forms.Button cmdSave; private System.Windows.Forms.Button cmdNew; private System.Windows.Forms.MenuItem menuItem6; private System.Windows.Forms.MenuItem menuItem14; private System.Windows.Forms.MenuItem menuItem18; private System.Windows.Forms.Button cmdOpen; private System.Windows.Forms.MenuItem menFile; private System.Windows.Forms.MenuItem menEdit; private System.Windows.Forms.MenuItem menNew; private System.Windows.Forms.MenuItem menOpen; private System.Windows.Forms.MenuItem menSave; private System.Windows.Forms.MenuItem menSaveAs; private System.Windows.Forms.MenuItem menExit; private System.Windows.Forms.MenuItem menUp; private System.Windows.Forms.MenuItem menDown; private System.Windows.Forms.MenuItem menAll; private System.Windows.Forms.MenuItem menNone; private System.Windows.Forms.Button cmdSelectFolder; private System.Windows.Forms.TextBox txtCurrentDir; private System.Windows.Forms.Panel pnlFileList; private System.Windows.Forms.Panel pnlPlaylist; private System.Windows.Forms.ListBox fileList; private System.Windows.Forms.ListBox playList; private System.Windows.Forms.OpenFileDialog openPlaylist; private System.Windows.Forms.SaveFileDialog savePlaylist; private System.Windows.Forms.FolderBrowserDialog openDirectory; private System.Windows.Forms.TextBox txtPlaylistName; private System.Windows.Forms.Panel pnlPlaylistButtons; private System.Windows.Forms.Button cmdAdd; private System.Windows.Forms.Button cmdRemove; private System.Windows.Forms.Button cmdUp; private System.Windows.Forms.Button cmdDown; private System.Windows.Forms.MenuItem menOptions; private System.Windows.Forms.MenuItem menFileList; private System.Windows.Forms.MenuItem menRecursive; private System.Windows.Forms.MenuItem menMp3; private System.Windows.Forms.MenuItem menOgg; private System.Windows.Forms.MenuItem menWma; private System.Windows.Forms.MenuItem menSort; private System.Windows.Forms.MenuItem menError; private bool playlistChangedSinceSave = false; private bool hasBeenSaved = false; private System.Windows.Forms.MenuItem menHelp; private System.Windows.Forms.MenuItem menAbout; private System.Windows.Forms.MenuItem menPlaylist; private System.Windows.Forms.MenuItem menPlaylistSort; private System.Windows.Forms.Timer showSplash; private System.ComponentModel.IContainer components; private static string[] passedInArgs; public playlistManager() { // // Required for Windows Form Designer support // InitializeComponent(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.menuBar = new System.Windows.Forms.MainMenu(this.components); this.menFile = new System.Windows.Forms.MenuItem(); this.menNew = new System.Windows.Forms.MenuItem(); this.menOpen = new System.Windows.Forms.MenuItem(); this.menuItem6 = new System.Windows.Forms.MenuItem(); this.menSave = new System.Windows.Forms.MenuItem(); this.menSaveAs = new System.Windows.Forms.MenuItem(); this.menuItem14 = new System.Windows.Forms.MenuItem(); this.menExit = new System.Windows.Forms.MenuItem(); this.menEdit = new System.Windows.Forms.MenuItem(); this.menUp = new System.Windows.Forms.MenuItem(); this.menDown = new System.Windows.Forms.MenuItem(); this.menuItem18 = new System.Windows.Forms.MenuItem(); this.menAll = new System.Windows.Forms.MenuItem(); this.menNone = new System.Windows.Forms.MenuItem(); this.menOptions = new System.Windows.Forms.MenuItem(); this.menFileList = new System.Windows.Forms.MenuItem(); this.menRecursive = new System.Windows.Forms.MenuItem(); this.menMp3 = new System.Windows.Forms.MenuItem(); this.menOgg = new System.Windows.Forms.MenuItem(); this.menWma = new System.Windows.Forms.MenuItem(); this.menSort = new System.Windows.Forms.MenuItem(); this.menPlaylist = new System.Windows.Forms.MenuItem(); this.menPlaylistSort = new System.Windows.Forms.MenuItem(); this.menError = new System.Windows.Forms.MenuItem(); this.menHelp = new System.Windows.Forms.MenuItem(); this.menAbout = new System.Windows.Forms.MenuItem(); this.fileList = new System.Windows.Forms.ListBox(); this.pnlButtons = new System.Windows.Forms.Panel(); this.cmdNew = new System.Windows.Forms.Button(); this.cmdOpen = new System.Windows.Forms.Button(); this.cmdSave = new System.Windows.Forms.Button(); this.pnlFileList = new System.Windows.Forms.Panel(); this.txtCurrentDir = new System.Windows.Forms.TextBox(); this.cmdSelectFolder = new System.Windows.Forms.Button(); this.pnlPlaylist = new System.Windows.Forms.Panel(); this.playList = new System.Windows.Forms.ListBox(); this.txtPlaylistName = new System.Windows.Forms.TextBox(); this.openPlaylist = new System.Windows.Forms.OpenFileDialog(); this.savePlaylist = new System.Windows.Forms.SaveFileDialog(); this.openDirectory = new System.Windows.Forms.FolderBrowserDialog(); this.pnlPlaylistButtons = new System.Windows.Forms.Panel(); this.cmdDown = new System.Windows.Forms.Button(); this.cmdUp = new System.Windows.Forms.Button(); this.cmdRemove = new System.Windows.Forms.Button(); this.cmdAdd = new System.Windows.Forms.Button(); this.showSplash = new System.Windows.Forms.Timer(this.components); this.pnlButtons.SuspendLayout(); this.pnlFileList.SuspendLayout(); this.pnlPlaylist.SuspendLayout(); this.pnlPlaylistButtons.SuspendLayout(); this.SuspendLayout(); // // menuBar // this.menuBar.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menFile, this.menEdit, this.menOptions, this.menHelp}); // // menFile // this.menFile.Index = 0; this.menFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menNew, this.menOpen, this.menuItem6, this.menSave, this.menSaveAs, this.menuItem14, this.menExit}); this.menFile.Text = "&File"; // // menNew // this.menNew.Index = 0; this.menNew.Text = "&New"; this.menNew.Click += new System.EventHandler(this.menNew_Click); // // menOpen // this.menOpen.Index = 1; this.menOpen.Text = "&Open"; this.menOpen.Click += new System.EventHandler(this.menOpen_Click); // // menuItem6 // this.menuItem6.Index = 2; this.menuItem6.Text = "-"; // // menSave // this.menSave.Index = 3; this.menSave.Text = "&Save"; this.menSave.Click += new System.EventHandler(this.menSave_Click); // // menSaveAs // this.menSaveAs.Index = 4; this.menSaveAs.Text = "Save &As"; this.menSaveAs.Click += new System.EventHandler(this.menSaveAs_Click); // // menuItem14 // this.menuItem14.Index = 5; this.menuItem14.Text = "-"; // // menExit // this.menExit.Index = 6; this.menExit.Text = "E&xit"; this.menExit.Click += new System.EventHandler(this.menExit_Click); // // menEdit // this.menEdit.Index = 1; this.menEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menUp, this.menDown, this.menuItem18, this.menAll, this.menNone}); this.menEdit.Text = "&Edit"; // // menUp // this.menUp.Index = 0; this.menUp.Text = "Move &Up"; this.menUp.Click += new System.EventHandler(this.menUp_Click); // // menDown // this.menDown.Index = 1; this.menDown.Text = "Move &Down"; this.menDown.Click += new System.EventHandler(this.menDown_Click); // // menuItem18 // this.menuItem18.Index = 2; this.menuItem18.Text = "-"; // // menAll // this.menAll.Index = 3; this.menAll.Text = "Select &All"; this.menAll.Click += new System.EventHandler(this.menAll_Click); // // menNone // this.menNone.Index = 4; this.menNone.Text = "Select &None"; this.menNone.Click += new System.EventHandler(this.menNone_Click); // // menOptions // this.menOptions.Index = 2; this.menOptions.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menFileList, this.menPlaylist, this.menError}); this.menOptions.Text = "Options"; // // menFileList // this.menFileList.Index = 0; this.menFileList.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menRecursive, this.menMp3, this.menOgg, this.menWma, this.menSort}); this.menFileList.Text = "File List"; // // menRecursive // this.menRecursive.Checked = global::Samsung_Playlist_Creator.Properties.Settings.Default.RecursivelySearch; this.menRecursive.Index = 0; this.menRecursive.Text = "Recursively Find Music"; this.menRecursive.Click += new System.EventHandler(this.menRecursive_Click); // // menMp3 // this.menMp3.Checked = global::Samsung_Playlist_Creator.Properties.Settings.Default.FindMP3; this.menMp3.Index = 1; this.menMp3.Text = "Find mp3\'s"; this.menMp3.Click += new System.EventHandler(this.menMp3_Click); // // menOgg // this.menOgg.Checked = global::Samsung_Playlist_Creator.Properties.Settings.Default.FindOGG; this.menOgg.Index = 2; this.menOgg.Text = "Find ogg\'s"; this.menOgg.Click += new System.EventHandler(this.menOgg_Click); // // menWma // this.menWma.Checked = global::Samsung_Playlist_Creator.Properties.Settings.Default.FindWMA; this.menWma.Index = 3; this.menWma.Text = "Find wma\'s"; this.menWma.Click += new System.EventHandler(this.menWma_Click); // // menSort // this.menSort.Checked = global::Samsung_Playlist_Creator.Properties.Settings.Default.AlphabatizeFileList; this.menSort.Index = 4; this.menSort.Text = "Alphabatize List"; this.menSort.Click += new System.EventHandler(this.menSort_Click); // // menPlaylist // this.menPlaylist.Index = 1; this.menPlaylist.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menPlaylistSort}); this.menPlaylist.Text = "Playlist"; // // menPlaylistSort // this.menPlaylistSort.Checked = global::Samsung_Playlist_Creator.Properties.Settings.Default.AlphabatizePlayList; this.menPlaylistSort.Index = 0; this.menPlaylistSort.Text = "Alphabatize Playlist"; this.menPlaylistSort.Click += new System.EventHandler(this.menPlaylistSort_Click); // // menError // this.menError.Checked = global::Samsung_Playlist_Creator.Properties.Settings.Default.SuppressErrors; this.menError.Index = 2; this.menError.Text = "Suppress Errors"; this.menError.Click += new System.EventHandler(this.menError_Click); // // menHelp // this.menHelp.Index = 3; this.menHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menAbout}); this.menHelp.Text = "&Help"; // // menAbout // this.menAbout.Index = 0; this.menAbout.Text = "&About"; this.menAbout.Click += new System.EventHandler(this.menAbout_Click); // // fileList // this.fileList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.fileList.BorderStyle = System.Windows.Forms.BorderStyle.None; this.fileList.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.fileList.Location = new System.Drawing.Point(0, 24); this.fileList.Name = "fileList"; this.fileList.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; this.fileList.Size = new System.Drawing.Size(216, 455); this.fileList.TabIndex = 3; // // pnlButtons // this.pnlButtons.BackColor = System.Drawing.Color.SteelBlue; this.pnlButtons.Controls.Add(this.cmdNew); this.pnlButtons.Controls.Add(this.cmdOpen); this.pnlButtons.Controls.Add(this.cmdSave); this.pnlButtons.Dock = System.Windows.Forms.DockStyle.Bottom; this.pnlButtons.Location = new System.Drawing.Point(0, 489); this.pnlButtons.Name = "pnlButtons"; this.pnlButtons.Size = new System.Drawing.Size(592, 48); this.pnlButtons.TabIndex = 4; // // cmdNew // this.cmdNew.Anchor = System.Windows.Forms.AnchorStyles.Top; this.cmdNew.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdNew.ForeColor = System.Drawing.Color.Linen; this.cmdNew.Location = new System.Drawing.Point(360, 6); this.cmdNew.Name = "cmdNew"; this.cmdNew.Size = new System.Drawing.Size(96, 32); this.cmdNew.TabIndex = 2; this.cmdNew.Text = "&New"; this.cmdNew.Click += new System.EventHandler(this.cmdNew_Click); // // cmdOpen // this.cmdOpen.Anchor = System.Windows.Forms.AnchorStyles.Top; this.cmdOpen.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdOpen.ForeColor = System.Drawing.Color.Linen; this.cmdOpen.Location = new System.Drawing.Point(248, 6); this.cmdOpen.Name = "cmdOpen"; this.cmdOpen.Size = new System.Drawing.Size(96, 32); this.cmdOpen.TabIndex = 1; this.cmdOpen.Text = "&Open"; this.cmdOpen.Click += new System.EventHandler(this.cmdOpen_Click); // // cmdSave // this.cmdSave.Anchor = System.Windows.Forms.AnchorStyles.Top; this.cmdSave.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdSave.ForeColor = System.Drawing.Color.Linen; this.cmdSave.Location = new System.Drawing.Point(136, 6); this.cmdSave.Name = "cmdSave"; this.cmdSave.Size = new System.Drawing.Size(96, 32); this.cmdSave.TabIndex = 0; this.cmdSave.Text = "&Save"; this.cmdSave.Click += new System.EventHandler(this.cmdSave_Click); // // pnlFileList // this.pnlFileList.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pnlFileList.Controls.Add(this.fileList); this.pnlFileList.Controls.Add(this.txtCurrentDir); this.pnlFileList.Controls.Add(this.cmdSelectFolder); this.pnlFileList.Dock = System.Windows.Forms.DockStyle.Right; this.pnlFileList.Location = new System.Drawing.Point(376, 0); this.pnlFileList.Name = "pnlFileList"; this.pnlFileList.Size = new System.Drawing.Size(216, 489); this.pnlFileList.TabIndex = 5; // // txtCurrentDir // this.txtCurrentDir.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtCurrentDir.Location = new System.Drawing.Point(0, 0); this.txtCurrentDir.Name = "txtCurrentDir"; this.txtCurrentDir.Size = new System.Drawing.Size(192, 20); this.txtCurrentDir.TabIndex = 2; this.txtCurrentDir.Text = "No directory has been selected"; // // cmdSelectFolder // this.cmdSelectFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.cmdSelectFolder.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdSelectFolder.Location = new System.Drawing.Point(189, 0); this.cmdSelectFolder.Name = "cmdSelectFolder"; this.cmdSelectFolder.Size = new System.Drawing.Size(23, 20); this.cmdSelectFolder.TabIndex = 1; this.cmdSelectFolder.Text = "..."; this.cmdSelectFolder.Click += new System.EventHandler(this.cmdSelectFolder_Click); // // pnlPlaylist // this.pnlPlaylist.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.pnlPlaylist.Controls.Add(this.playList); this.pnlPlaylist.Controls.Add(this.txtPlaylistName); this.pnlPlaylist.Dock = System.Windows.Forms.DockStyle.Left; this.pnlPlaylist.Location = new System.Drawing.Point(0, 0); this.pnlPlaylist.Name = "pnlPlaylist"; this.pnlPlaylist.Size = new System.Drawing.Size(216, 489); this.pnlPlaylist.TabIndex = 6; // // playList // this.playList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.playList.BorderStyle = System.Windows.Forms.BorderStyle.None; this.playList.Location = new System.Drawing.Point(0, 24); this.playList.Name = "playList"; this.playList.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; this.playList.Size = new System.Drawing.Size(216, 455); this.playList.TabIndex = 1; this.playList.SelectedIndexChanged += new System.EventHandler(this.playList_SelectedIndexChanged); // // txtPlaylistName // this.txtPlaylistName.Dock = System.Windows.Forms.DockStyle.Top; this.txtPlaylistName.Location = new System.Drawing.Point(0, 0); this.txtPlaylistName.Name = "txtPlaylistName"; this.txtPlaylistName.ReadOnly = true; this.txtPlaylistName.Size = new System.Drawing.Size(212, 20); this.txtPlaylistName.TabIndex = 0; this.txtPlaylistName.Text = "No name has been set"; // // openPlaylist // this.openPlaylist.Filter = "Samsung\tPlaylist Files|*.spl"; this.openPlaylist.Title = "Open\tPlaylist File"; // // savePlaylist // this.savePlaylist.Filter = "Samsung\tPlaylist Files|*.spl"; this.savePlaylist.Title = "Save\tPlaylist"; // // openDirectory // this.openDirectory.Description = "Select Music Directory"; this.openDirectory.ShowNewFolderButton = false; // // pnlPlaylistButtons // this.pnlPlaylistButtons.BackColor = System.Drawing.Color.SteelBlue; this.pnlPlaylistButtons.Controls.Add(this.cmdDown); this.pnlPlaylistButtons.Controls.Add(this.cmdUp); this.pnlPlaylistButtons.Controls.Add(this.cmdRemove); this.pnlPlaylistButtons.Controls.Add(this.cmdAdd); this.pnlPlaylistButtons.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlPlaylistButtons.Location = new System.Drawing.Point(216, 0); this.pnlPlaylistButtons.Name = "pnlPlaylistButtons"; this.pnlPlaylistButtons.Size = new System.Drawing.Size(160, 489); this.pnlPlaylistButtons.TabIndex = 10; // // cmdDown // this.cmdDown.Anchor = System.Windows.Forms.AnchorStyles.Top; this.cmdDown.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdDown.ForeColor = System.Drawing.Color.Linen; this.cmdDown.Location = new System.Drawing.Point(32, 208); this.cmdDown.Name = "cmdDown"; this.cmdDown.Size = new System.Drawing.Size(96, 32); this.cmdDown.TabIndex = 5; this.cmdDown.Text = "Move &Down"; this.cmdDown.Click += new System.EventHandler(this.cmdDown_Click); // // cmdUp // this.cmdUp.Anchor = System.Windows.Forms.AnchorStyles.Top; this.cmdUp.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdUp.ForeColor = System.Drawing.Color.Linen; this.cmdUp.Location = new System.Drawing.Point(32, 168); this.cmdUp.Name = "cmdUp"; this.cmdUp.Size = new System.Drawing.Size(96, 32); this.cmdUp.TabIndex = 4; this.cmdUp.Text = "Move &Up"; this.cmdUp.Click += new System.EventHandler(this.cmdUp_Click); // // cmdRemove // this.cmdRemove.Anchor = System.Windows.Forms.AnchorStyles.Top; this.cmdRemove.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdRemove.ForeColor = System.Drawing.Color.Linen; this.cmdRemove.Location = new System.Drawing.Point(32, 128); this.cmdRemove.Name = "cmdRemove"; this.cmdRemove.Size = new System.Drawing.Size(96, 32); this.cmdRemove.TabIndex = 3; this.cmdRemove.Text = "(X) &Remove"; this.cmdRemove.Click += new System.EventHandler(this.cmdRemove_Click); // // cmdAdd // this.cmdAdd.Anchor = System.Windows.Forms.AnchorStyles.Top; this.cmdAdd.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdAdd.ForeColor = System.Drawing.Color.Linen; this.cmdAdd.Location = new System.Drawing.Point(32, 88); this.cmdAdd.Name = "cmdAdd"; this.cmdAdd.Size = new System.Drawing.Size(96, 32); this.cmdAdd.TabIndex = 2; this.cmdAdd.Text = "<-- &Add"; this.cmdAdd.Click += new System.EventHandler(this.cmdAdd_Click); // // playlistManager // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(592, 537); this.Controls.Add(this.pnlPlaylistButtons); this.Controls.Add(this.pnlPlaylist); this.Controls.Add(this.pnlFileList); this.Controls.Add(this.pnlButtons); this.Menu = this.menuBar; this.MinimumSize = new System.Drawing.Size(360, 573); this.Name = "playlistManager"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Playlist Manager"; this.Load += new System.EventHandler(this.playlistManager_Load); this.SizeChanged += new System.EventHandler(this.playlistManager_SizeChanged); this.Closing += new System.ComponentModel.CancelEventHandler(this.playlistManager_Closing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.playlistManager_FormClosing); this.pnlButtons.ResumeLayout(false); this.pnlFileList.ResumeLayout(false); this.pnlFileList.PerformLayout(); this.pnlPlaylist.ResumeLayout(false); this.pnlPlaylist.PerformLayout(); this.pnlPlaylistButtons.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// This application allows the user to create and modify playlist files /// for Samsung's yp-t8 player (and possibly other Samsung players). /// [STAThread] static void Main(string[] args) { passedInArgs = args; Application.Run(new playlistManager()); } private void cmdSelectFolder_Click(object sender, System.EventArgs e) { getMusicList(); } private void menOpen_Click(object sender, System.EventArgs e) { openPlaylistFromDisk(); } /// /// Adds the supported media files to the fileList from a /// directory specified by the user. Directories will be recursivly /// added if menRecursive /// is checked. /// /// Ogg files will be added if menOgg is checked /// Mp3's will be added if menMp3 is checked /// Wma's will be added if menWma is checked /// private void getMusicList() { this.Cursor = Cursors.WaitCursor;//updateFileList should have taken care of this, but for some reason it doesn't if(Directory.Exists(txtCurrentDir.Text)) openDirectory.SelectedPath = txtCurrentDir.Text; DialogResult results = openDirectory.ShowDialog(); if (results == DialogResult.OK) { fileList.BeginUpdate(); txtCurrentDir.Text = openDirectory.SelectedPath; updateFileList(); fileList.EndUpdate(); } this.Cursor = Cursors.Arrow; } /// /// Adds the supported media files to the fileList from a specified /// directory. Directories will be recursivly added if menRecursive /// is checked. /// /// Ogg files will be added if menOgg is checked /// Mp3's will be added if menMp3 is checked /// Wma's will be added if menWma is checked /// /// Directory to be added private void addDirectory(DirectoryInfo directory) { try { //This part seems terribly in efficent however do to the ease of implimentation //it was used. In future versions this code should be considered for replacement //If user wants add mp3's to fileList if (menMp3.Checked) foreach(FileInfo f in directory.GetFiles("*.mp3")) fileList.Items.Add(f.Name); //If user wants add ogg's to fileList if (menOgg.Checked) foreach(FileInfo f in directory.GetFiles("*.ogg")) fileList.Items.Add(f.Name); //If user wants add wma's to fileList if (menWma.Checked) foreach(FileInfo f in directory.GetFiles("*.wma")) fileList.Items.Add(f.Name); //Recursivly add directories if (menRecursive.Checked) foreach(DirectoryInfo d in directory.GetDirectories()) addDirectory(d); } catch(System.UnauthorizedAccessException e) { if(!menError.Checked)//if user wants to see errors MessageBox.Show("You do not have enough permissions to view some files in: " + directory.FullName, "Error",MessageBoxButtons.OK, MessageBoxIcon.Error); } } /// /// Gets the path of a playlist file from the user, and then updates the UI accordingly /// to reflect the content of the selected playlist file /// private void openPlaylistFromDisk() { if(playlistChangedSinceSave) //if playlist has been changed, and changes have not been saved { if (!confirmDiscard()) return; } //Get File from user DialogResult results = openPlaylist.ShowDialog(); if (results == DialogResult.OK) openPlaylistFromFile(new FileInfo(openPlaylist.FileName)); } /// /// Opens a specified file as if it was a playlist /// (Does not check to see if it is a playlist or confirm the replacement of an existing playlist) /// /// Clears playlist /// Adds songs to playlist List /// Sets approitaite variables to relect current state /// /// File to be opened private void openPlaylistFromFile(FileInfo fileToBeOpened) { playList.Items.Clear(); //Prepare to read from file TextReader file = new StreamReader(fileToBeOpened.OpenRead(), Encoding.Unicode); bool fileIsNotEmpty = true; //First two lines are not relevent so they are thrown out file.ReadLine(); file.ReadLine(); while (fileIsNotEmpty)//while the file is not empty { String s = file.ReadLine(); if (s == null)//if file is empty fileIsNotEmpty = false; else playList.Items.Add(s); } file.Close(); txtPlaylistName.Text = fileToBeOpened.FullName; savePlaylist.FileName = fileToBeOpened.FullName; openPlaylist.FileName = fileToBeOpened.FullName; playlistChangedSinceSave = false; hasBeenSaved = true; } /// /// Updates fileList using the last directory that was opened /// /// If directory no longer exists fileList will not be updated /// private void updateFileList() { if(Directory.Exists(openDirectory.SelectedPath)) { this.Cursor = Cursors.WaitCursor; //update list fileList.Items.Clear(); addDirectory(new DirectoryInfo(openDirectory.SelectedPath)); this.Cursor = Cursors.Arrow; } } private void menSaveAs_Click(object sender, System.EventArgs e) { savePlaylistToDisk(true); } private void cmdOpen_Click(object sender, System.EventArgs e) { openPlaylistFromDisk(); } private void playlistManager_SizeChanged(object sender, System.EventArgs e) { pnlPlaylist.Width = (this.Width-160)/2; pnlFileList.Width = (this.Width-160)/2; } private void cmdAdd_Click(object sender, System.EventArgs e) { foreach(string s in fileList.SelectedItems) { playList.Items.Add(s); playlistChangedSinceSave = true; } } private void cmdRemove_Click(object sender, System.EventArgs e) { while(playList.SelectedIndex != -1) { playList.Items.RemoveAt(playList.SelectedIndex); playlistChangedSinceSave = true; } } private void menError_Click(object sender, System.EventArgs e) { if (menError.Checked) menError.Checked = false; else menError.Checked = true; } private void menRecursive_Click(object sender, System.EventArgs e) { if(menRecursive.Checked) menRecursive.Checked = false; else menRecursive.Checked = true; updateFileList(); } private void menMp3_Click(object sender, System.EventArgs e) { if (menMp3.Checked) menMp3.Checked = false; else menMp3.Checked = true; updateFileList(); } private void menOgg_Click(object sender, System.EventArgs e) { if (menOgg.Checked) menOgg.Checked = false; else menOgg.Checked = true; updateFileList(); } private void menWma_Click(object sender, System.EventArgs e) { if (menWma.Checked) menWma.Checked = false; else menWma.Checked = true; updateFileList(); } private void menSort_Click(object sender, System.EventArgs e) { if (menSort.Checked) { menSort.Checked = false; fileList.Sorted = false; } else { menSort.Checked = true; fileList.Sorted = true; } updateFileList(); } private void menExit_Click(object sender, System.EventArgs e) { this.Close(); } private void cmdSave_Click(object sender, System.EventArgs e) { savePlaylistToDisk(false); } /// /// Saves playList either using the path the playlist was loaded from or last saved to, or /// prompting the user for a save path. /// /// The user will be prompted if neither the path the playlist was loaded from or last saved to exist, /// if the playlist has never been saved, or if the saveAs parameter is set to true /// /// If true behaves as a save as command, false behaves as a normal save command private bool savePlaylistToDisk(bool saveAs) { DialogResult results = DialogResult.OK; if(!File.Exists(savePlaylist.FileName) || !hasBeenSaved || saveAs)//if should behave as a Save As results = savePlaylist.ShowDialog();//get file from user else savePlaylist.FileName = txtPlaylistName.Text; if (results == DialogResult.OK)//If user has, or has previously selected a path { txtPlaylistName.Text = savePlaylist.FileName; //Prepare to read from file TextWriter file = new StreamWriter(savePlaylist.OpenFile(), Encoding.Unicode); //First two lines are not relevent so they are thrown out file.WriteLine("PL PLAYLIST"); file.WriteLine("VERSION 1.00"); foreach(String s in playList.Items)//Dump playlist to file { file.WriteLine(s); } file.Close(); //update attributes to reflect current state playlistChangedSinceSave = false; hasBeenSaved = true; return true; } return false; } private void menSave_Click(object sender, System.EventArgs e) { savePlaylistToDisk(false); } private void cmdUp_Click(object sender, System.EventArgs e) { moveSelectedUp(); } /// /// Displays a promt asking the user if they want to save current playlist. /// If the user hits yes it calls savePlaylist() and returns true /// If the user hiss no it returns true /// If the user hits cancel it returns false /// /// False if the user selects cancel, if the user selects yes or no true is returned private bool confirmDiscard() { DialogResult results = MessageBox.Show("Do you want to save the changes in the playlist?","Save?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); //If user wants to save before continuing if ( results == DialogResult.Yes) { if (!savePlaylistToDisk(false)) return confirmDiscard(); } //If user does not want to proceed if (results == DialogResult.Cancel) return false; //if cancel was not pressed return true return true; } /// /// Moves the selected items in playList up one position (If possible) /// private void moveSelectedUp() { if (playList.Items.Count > 1)//if playlist has more than 1 item foreach (int i in playList.SelectedIndices) if (i > 0 && !playList.SelectedIndices.Contains(i-1)) //if item is selected and can be moved up { playList.Items.Insert(i - 1, playList.Items[i]); playList.Items.RemoveAt(i + 1); playList.SetSelected(i - 1,true); playlistChangedSinceSave = true; } } /// /// Moves the selected items in playList down one position (If possible) /// private void moveSelectedDown() { if (playList.Items.Count > 1)//if playlist has more than 1 item { int[] reverseOrderOfSelected = new int[playList.SelectedIndices.Count]; int n = 1; foreach (int i in playList.SelectedIndices) { reverseOrderOfSelected[playList.SelectedIndices.Count - n] = i; n++; } foreach (int i in reverseOrderOfSelected) if (i < playList.Items.Count -1 && !playList.SelectedIndices.Contains(i+1)) //if item is selected and can be moved down { playList.Items.Insert(i + 2, playList.Items[i]); playList.Items.RemoveAt(i); playList.SetSelected(i + 1,true); playlistChangedSinceSave = true; } } } private void menUp_Click(object sender, System.EventArgs e) { moveSelectedUp(); } private void cmdDown_Click(object sender, System.EventArgs e) { moveSelectedDown(); } private void menDown_Click(object sender, System.EventArgs e) { moveSelectedDown(); } private void playList_SelectedIndexChanged(object sender, System.EventArgs e) { playlistChangedSinceSave = true; } private void cmdNew_Click(object sender, System.EventArgs e) { newPlaylist(); } /// /// Handles the creation of a new playlist, prompting the user if the /// current one has not been saved, updateing class attributes /// and related UI components /// /// If user confirms new playlist (if old playlist was changed since it was last saved) /// or if last playlist was not changed since it was last saved /// /// Clears playList items /// sets txtPlaylistName text to "No name has been set" /// sets playlistChangedSinceSave and hasBeenSaved to false /// /// private void newPlaylist() { if(playlistChangedSinceSave) //if playlist has been changed, and changes have not been saved { if (!confirmDiscard()) return; } //add saved check (create a specialized method to do this as it will be called elsewhere too) playList.Items.Clear(); txtPlaylistName.Text = "No name has been set"; hasBeenSaved = false; playlistChangedSinceSave = false; } private void menAbout_Click(object sender, System.EventArgs e) { showAboutInfo(false); } /// /// Shows licence and copyright info, along with the build date (Version since build dates /// are being used to distinguish between versions at this point) /// /// Whether about dialog should close on its own after a short period of time private void showAboutInfo(bool autoClose) { //Show Splash Screen SplashScreen splash = new SplashScreen(autoClose); splash.Show(); } private void playlistManager_Load(object sender, System.EventArgs e) { //Ensures that menus are in sync with actual values menPlaylistSort.Checked = playList.Sorted; menSort.Checked = fileList.Sorted; showAboutInfo(true); //Open passed in playlist foreach (String s in passedInArgs) { if (File.Exists(s)) { try { openPlaylistFromFile(new FileInfo(s)); break; } catch { playList.Items.Clear(); playlistChangedSinceSave = false; hasBeenSaved = false; } } } } private void menAll_Click(object sender, System.EventArgs e) { fileList.BeginUpdate(); //This method needs to be fixed so as to select all as fast as select none works //For each item in fileList for(int i =0; i < fileList.Items.Count; i++) fileList.SetSelected(i, true); fileList.EndUpdate(); playList.BeginUpdate(); //For each item in playList for(int i =0; i < playList.Items.Count; i++) playList.SetSelected(i, true); playList.EndUpdate(); } private void menNone_Click(object sender, System.EventArgs e) { playList.ClearSelected(); fileList.ClearSelected(); } private void menPlaylistSort_Click(object sender, System.EventArgs e) { if (menPlaylistSort.Checked) { menPlaylistSort.Checked = false; playList.Sorted = false; } else { menPlaylistSort.Checked = true; playList.Sorted = true; } } private void menNew_Click(object sender, System.EventArgs e) { newPlaylist(); } private void playlistManager_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if(playlistChangedSinceSave) //if playlist has been changed, and changes have not been saved if (!confirmDiscard()) e.Cancel = true; } private void playlistManager_FormClosing(object sender, FormClosingEventArgs e) { Properties.Settings.Default.Save(); } } }