Example #1
0
        /// <summary>
        /// Function that uses DeleteOldRowFromDatabase and AddNewPathToDatabase functions to update the path of the file
        /// or to remove movie from database
        /// </summary>
        /// <param name="file_name">A name of movie file that will be updated/removed</param>
        /// <param name="path">An old path to the file. It is needed to MessageBox information</param>
        public void ChangeDirectory(string file_name, string path)
        {
            var i = 0;

            while (i == 0)
            {
                FilePathChangeMessageBox MyMessageBox = new FilePathChangeMessageBox();
                MyMessageBox.MessageBox_File_Name.Text = "'" + file_name + "'";
                MyMessageBox.MessageBox_File_Path.Text = "'" + path + "'";



                if (MyMessageBox.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Stream         myStream = null;
                    OpenFileDialog open     = new OpenFileDialog();
                    open.Filter = "Movie file (*.mkv, *.mov, *.avi, *.mp4, *.divx, *.mpeg, *.mpg)|*.mkv;*mov;*.avi;*.mp4;*.divx;*.mpeg;*.mpg";

                    if (Properties.Settings.Default.FolderPath != null)
                    {
                        open.InitialDirectory = Properties.Settings.Default.FolderFilePath;
                    }

                    if (open.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            if ((myStream = open.OpenFile()) != null)
                            {
                                using (myStream)
                                {
                                    //string Name;
                                    FileStream fs = myStream as FileStream;

                                    if (fs != null)
                                    {
                                        Properties.Settings.Default.FolderFilePath = fs.Name;
                                        Properties.Settings.Default.Save();
                                        Name = System.IO.Path.GetFileNameWithoutExtension(fs.Name);
                                        if (Name == file_name)
                                        {
                                            i = 1;
                                            AddNewPathToDatabase(fs.Name, Name);
                                        }
                                        else
                                        {
                                            MessageBox.Show("You chose wrong file! \n \n Try again!");
                                            i = 0;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: Could not find file. Error: " + ex.Message);
                        }
                    }
                }
                else
                {
                    i = 1;
                    DeleteOldRowFromDatabase(file_name);
                }
            }
        }
        /// <summary>
        /// Function that uses DeleteOldRowFromDatabase and AddNewPathToDatabase functions to update the path of the file 
        /// or to remove movie from database
        /// </summary>
        /// <param name="file_name">A name of movie file that will be updated/removed</param>
        /// <param name="path">An old path to the file. It is needed to MessageBox information</param>
        public void ChangeDirectory(string file_name, string path)
        {
            var i = 0;

            while (i == 0)
            {

                FilePathChangeMessageBox MyMessageBox = new FilePathChangeMessageBox();
                MyMessageBox.MessageBox_File_Name.Text = "'" + file_name + "'";
                MyMessageBox.MessageBox_File_Path.Text = "'" + path + "'";

                if (MyMessageBox.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {

                    Stream myStream = null;
                    OpenFileDialog open = new OpenFileDialog();
                    open.Filter = "Movie file (*.mkv, *.mov, *.avi, *.mp4, *.divx, *.mpeg, *.mpg)|*.mkv;*mov;*.avi;*.mp4;*.divx;*.mpeg;*.mpg";

                    if (Properties.Settings.Default.FolderPath != null)
                    {
                        open.InitialDirectory = Properties.Settings.Default.FolderFilePath;
                    }

                    if (open.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            if ((myStream = open.OpenFile()) != null)
                            {
                                using (myStream)
                                {
                                    //string Name;
                                    FileStream fs = myStream as FileStream;

                                    if (fs != null)
                                    {
                                        Properties.Settings.Default.FolderFilePath = fs.Name;
                                        Properties.Settings.Default.Save();
                                        Name = System.IO.Path.GetFileNameWithoutExtension(fs.Name);
                                        if (Name == file_name)
                                        {
                                            i = 1;
                                            AddNewPathToDatabase(fs.Name, Name);
                                        }
                                        else
                                        {
                                            MessageBox.Show("You chose wrong file! \n \n Try again!");
                                            i = 0;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: Could not find file. Error: " + ex.Message);
                        }
                    }
                }
                else
                {
                    i = 1;
                    DeleteOldRowFromDatabase(file_name);
                }
            }
        }