ShowDialog() public method

public ShowDialog ( Form parent, MethodInvoker work ) : DialogResult
parent System.Windows.Forms.Form
work MethodInvoker
return DialogResult
Ejemplo n.º 1
0
        private DataSearch()
        {
            Dictionary<string, string[]> tableCols = new Dictionary<string, string[]>();
            tableCols.Add("downloads", new string[] { "name", "description" });

            if (this.NeedRebuild(tableCols))
            {
                // Close & clean up the connection used for testing
                dbConn.Close();
                dbConn.Dispose();
                dbConn = null;

                using (Status status = new Status())
                {
                    status.ShowDialog(delegate
                    {
                        this.RebuildIndex(status, tableCols);
                    });
                }
            }

            Model.Download.Added += this.Download_Added;
            Model.Download.Updated += this.Download_Updated;
            Model.Download.Removed += this.Download_Removed;
            DownloadManager.Progress += this.Download_Progress;
        }
Ejemplo n.º 2
0
        private void ButtonOk_Click(object sender, EventArgs e)
        {
            DateTime? olderThan = null;
            int? progid = null;

            if (this.CheckByDate.Checked)
            {
                // Just pass the date part and discard the time
                olderThan = new DateTime(this.DateOlderThan.Value.Year, this.DateOlderThan.Value.Month, this.DateOlderThan.Value.Day);
            }

            if (this.CheckByProgramme.Checked)
            {
                progid = ((ComboNameValue<int>)this.ListProgrammes.SelectedItem).Value;
            }

            using (Status status = new Status())
            {
                status.ShowDialog(
                    this,
                    () =>
                    {
                        Model.Download.Cleanup(status, olderThan, progid, this.CheckOrphan.Checked, this.CheckPlayed.Checked, this.CheckKeepFiles.Checked);
                    });
            }
        }
Ejemplo n.º 3
0
        private void ButtonOk_Click(object sender, EventArgs e)
        {
            DateTime?olderThan = null;
            int?     progid    = null;

            if (this.CheckByDate.Checked)
            {
                // Just pass the date part and discard the time
                olderThan = new DateTime(this.DateOlderThan.Value.Year, this.DateOlderThan.Value.Month, this.DateOlderThan.Value.Day);
            }

            if (this.CheckByProgramme.Checked)
            {
                progid = ((ComboNameValue <int>) this.ListProgrammes.SelectedItem).Value;
            }

            using (Status status = new Status())
            {
                status.ShowDialog(
                    this,
                    () =>
                {
                    Model.Download.Cleanup(status, olderThan, progid, this.CheckOrphan.Checked, this.CheckPlayed.Checked, this.CheckKeepFiles.Checked);
                });
            }
        }
Ejemplo n.º 4
0
        private DataSearch()
        {
            Dictionary <string, string[]> tableCols = new Dictionary <string, string[]>();

            tableCols.Add("downloads", new string[] { "name", "description" });

            if (this.NeedRebuild(tableCols))
            {
                // Close & clean up the connection used for testing
                dbConn.Close();
                dbConn.Dispose();
                dbConn = null;

                using (Status status = new Status())
                {
                    status.ShowDialog(() =>
                    {
                        this.RebuildIndex(status, tableCols);
                    });
                }
            }

            Model.Download.Added     += this.Download_Added;
            Model.Download.Updated   += this.Download_Updated;
            Model.Download.Removed   += this.Download_Removed;
            DownloadManager.Progress += this.Download_Progress;
        }
Ejemplo n.º 5
0
        private void ButtonOk_Click(object eventSender, EventArgs eventArgs)
        {
            if (string.IsNullOrEmpty(this.TextFileNameFormat.Text))
            {
                Interaction.MsgBox("Please enter a value for the downloaded programme file name format.", MsgBoxStyle.Exclamation);
                this.TextFileNameFormat.Focus();
                this.cancelClose = true;
                return;
            }

            bool formatChanged = Settings.FileNameFormat != this.TextFileNameFormat.Text;

            if (this.folderChanged || formatChanged)
            {
                string message = "Move existing downloads to \"" + this.TextSaveIn.Text + "\" and rename to new naming format?";

                if (!formatChanged)
                {
                    message = "Move existing downloads to \"" + this.TextSaveIn.Text + "\"?";
                }
                else if (!this.folderChanged)
                {
                    message = "Rename existing downloads to new naming format?";
                }

                if (MessageBox.Show(message, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    using (Status status = new Status())
                    {
                        status.ShowDialog(
                            this,
                            delegate
                        {
                            Model.Download.UpdatePaths(status, this.TextSaveIn.Text, this.TextFileNameFormat.Text);
                        });
                    }
                }

                Settings.SaveFolder     = this.TextSaveIn.Text;
                Settings.FileNameFormat = this.TextFileNameFormat.Text;
            }

            Settings.RunOnStartup      = this.CheckRunOnStartup.Checked;
            Settings.RunAfterCommand   = this.TextRunAfter.Text;
            Settings.ParallelDownloads = (int)this.NumberParallel.Value;
            Settings.RssServer         = this.CheckRssServer.Checked;

            if (this.CheckRssServer.Checked)
            {
                Settings.RssServerPort         = (int)this.NumberServerPort.Value;
                Settings.RssServerNumRecentEps = (int)this.NumberEpisodes.Value;
            }

            if (OsUtils.WinSevenOrLater())
            {
                Settings.CloseToSystray = this.CheckCloseToSystray.Checked;
            }

            OsUtils.ApplyRunOnStartup();
        }
Ejemplo n.º 6
0
        private DataSearch()
        {
            Dictionary <string, string[]> tableCols = new Dictionary <string, string[]>();

            tableCols.Add("downloads", new string[] { "name", "description" });

            bool rebuild = false;

            if (!this.CheckIndex(tableCols))
            {
                rebuild = true;
            }
            else
            {
                using (SQLiteCommand command = new SQLiteCommand("select count(*) from downloads", this.FetchDbConn()))
                {
                    if (Model.Download.Count() != (long)command.ExecuteScalar())
                    {
                        rebuild = true;
                    }
                }
            }

            if (rebuild)
            {
                // Close & clean up the connection used for testing
                dbConn.Close();
                dbConn.Dispose();
                dbConn = null;

                using (Status status = new Status())
                {
                    status.ShowDialog(delegate
                    {
                        this.RebuildIndex(status, tableCols);
                    });
                }
            }

            Model.Download.Added     += this.Download_Added;
            Model.Download.Updated   += this.Download_Updated;
            Model.Download.Removed   += this.Download_Removed;
            DownloadManager.Progress += this.Download_Progress;
        }
Ejemplo n.º 7
0
        private DataSearch()
        {
            Dictionary<string, string[]> tableCols = new Dictionary<string, string[]>();
            tableCols.Add("downloads", new string[] { "name", "description" });

            bool rebuild = false;

            if (!this.CheckIndex(tableCols))
            {
                rebuild = true;
            }
            else
            {
                using (SQLiteCommand command = new SQLiteCommand("select count(*) from downloads", this.FetchDbConn()))
                {
                    if (Model.Download.Count() != (long)command.ExecuteScalar())
                    {
                        rebuild = true;
                    }
                }
            }

            if (rebuild)
            {
                // Close & clean up the connection used for testing
                dbConn.Close();
                dbConn.Dispose();
                dbConn = null;

                using (Status status = new Status())
                {
                    status.ShowDialog(delegate
                    {
                        this.RebuildIndex(status, tableCols);
                    });
                }
            }

            Model.Download.Added += this.Download_Added;
            Model.Download.Updated += this.Download_Updated;
            Model.Download.Removed += this.Download_Removed;
            DownloadManager.Progress += this.Download_Progress;
        }
Ejemplo n.º 8
0
        public static bool Startup()
        {
            const string DbFileName = "store.db";
            string       specDbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DbFileName);
            string       appDbPath  = Path.Combine(FileUtils.GetAppDataFolder(), DbFileName);

            // Ensure that the template database exists
            if (!File.Exists(specDbPath))
            {
                MessageBox.Show("The Radio Downloader template database was not found at '" + specDbPath + "'." + Environment.NewLine + Environment.NewLine + "Try repairing the Radio Downloader installation or installing the latest version from nerdoftheherd.com", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            using (SQLiteConnection specConn = new SQLiteConnection("Data Source=" + specDbPath + ";Version=3;New=False;Read Only=True"))
            {
                specConn.Open();

                using (SQLiteCommand command = new SQLiteCommand("pragma integrity_check(1)", specConn))
                {
                    string result = (string)command.ExecuteScalar();

                    if (result.ToUpperInvariant() != "OK")
                    {
                        MessageBox.Show("The Radio Downloader template database at '" + specDbPath + "' appears to be corrupted." + Environment.NewLine + Environment.NewLine + "Try repairing the Radio Downloader installation or installing the latest version from nerdoftheherd.com", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return(false);
                    }
                }

                // Migrate old (pre 0.26) version databases from www.nerdoftheherd.com -> NerdoftheHerd.com
                string oldDbPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "www.nerdoftheherd.com"), Application.ProductName), DbFileName);

                if (File.Exists(oldDbPath) && !File.Exists(appDbPath))
                {
                    File.Move(oldDbPath, appDbPath);
                }

                // Test if there is an existing application database
                if (!File.Exists(appDbPath))
                {
                    // Start with a copy of the template database
                    File.Copy(specDbPath, appDbPath);

                    // Set the current database version in the new database
                    Settings.DatabaseVersion = Database.CurrentDbVersion;
                }
                else
                {
                    using (SQLiteCommand command = new SQLiteCommand("pragma integrity_check(1)", FetchDbConn()))
                    {
                        string result = (string)command.ExecuteScalar();

                        if (result.ToUpperInvariant() != "OK")
                        {
                            if (MessageBox.Show("Unfortunately Radio Downloader cannot start because your database has become corrupted." + Environment.NewLine + Environment.NewLine + "Would you like to view some help about resolving this issue?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
                            {
                                OsUtils.LaunchUrl(new Uri("https://nerdoftheherd.com/tools/radiodld/help/corrupt-database"), "corruptdb");
                            }

                            return(false);
                        }
                    }

                    // Start a transaction so we can roll back a half-completed upgrade on error
                    using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                    {
                        try
                        {
                            // Perform a check and automatic update of the database table structure
                            UpdateStructure(specConn, Database.FetchDbConn());

                            // Perform any updates required which were not handled by UpdateStructure
                            switch (Settings.DatabaseVersion)
                            {
                            case 4:
                                // Clear error details previously serialised as XML
                                using (SQLiteCommand command = new SQLiteCommand("update downloads set errordetails=null where errortype=@errortype", FetchDbConn()))
                                {
                                    command.Parameters.Add(new SQLiteParameter("errortype", ErrorType.UnknownError));
                                    command.ExecuteNonQuery();
                                }

                                break;

                            case Database.CurrentDbVersion:
                                // Nothing to do, this is the current version.
                                break;
                            }

                            // Set the current database version
                            Settings.DatabaseVersion = Database.CurrentDbVersion;
                        }
                        catch (SQLiteException)
                        {
                            transMon.Trans.Rollback();
                            throw;
                        }

                        transMon.Trans.Commit();
                    }
                }
            }

            // Prune the database once a week
            if (Settings.LastPrune.AddDays(7) < DateTime.Now)
            {
                using (Status status = new Status())
                {
                    status.ShowDialog(delegate
                    {
                        Prune(status);
                    });
                }
            }

            // Vacuum the database every three months
            if (Settings.LastVacuum.AddMonths(3) < DateTime.Now)
            {
                using (Status status = new Status())
                {
                    status.ShowDialog(delegate
                    {
                        Vacuum(status);
                    });
                }
            }

            return(true);
        }
Ejemplo n.º 9
0
        private void ButtonOk_Click(object eventSender, EventArgs eventArgs)
        {
            if (string.IsNullOrEmpty(this.TextFileNameFormat.Text))
            {
                Interaction.MsgBox("Please enter a value for the downloaded programme file name format.", MsgBoxStyle.Exclamation);
                this.TextFileNameFormat.Focus();
                this.cancelClose = true;
                return;
            }

            bool formatChanged = Settings.FileNameFormat != this.TextFileNameFormat.Text;

            if (this.folderChanged || formatChanged)
            {
                string message = "Move existing downloads to \"" + this.TextSaveIn.Text + "\" and rename to new naming format?";

                if (!formatChanged)
                {
                    message = "Move existing downloads to \"" + this.TextSaveIn.Text + "\"?";
                }
                else if (!this.folderChanged)
                {
                    message = "Rename existing downloads to new naming format?";
                }

                if (MessageBox.Show(message, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    using (Status status = new Status())
                    {
                        status.ShowDialog(
                            this,
                            () =>
                            {
                                Model.Download.UpdatePaths(status, this.TextSaveIn.Text, this.TextFileNameFormat.Text);
                            });
                    }
                }

                Settings.SaveFolder = this.TextSaveIn.Text;
                Settings.FileNameFormat = this.TextFileNameFormat.Text;
            }

            Settings.RunOnStartup = this.CheckRunOnStartup.Checked;
            Settings.RunAfterCommand = this.TextRunAfter.Text;
            Settings.ParallelDownloads = (int)this.NumberParallel.Value;
            Settings.RssServer = this.CheckRssServer.Checked;

            if (this.CheckRssServer.Checked)
            {
                Settings.RssServerPort = (int)this.NumberServerPort.Value;
                Settings.RssServerNumRecentEps = (int)this.NumberEpisodes.Value;
            }

            if (OsUtils.WinSevenOrLater())
            {
                Settings.CloseToSystray = this.CheckCloseToSystray.Checked;
            }

            OsUtils.ApplyRunOnStartup();
        }
Ejemplo n.º 10
0
        public static bool Startup()
        {
            const string DbFileName = "store.db";
            string specDbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DbFileName);
            string appDbPath = Path.Combine(FileUtils.GetAppDataFolder(), DbFileName);

            // Ensure that the template database exists
            if (!File.Exists(specDbPath))
            {
                MessageBox.Show("The Radio Downloader template database was not found at '" + specDbPath + "'." + Environment.NewLine + Environment.NewLine + "Try repairing the Radio Downloader installation or installing the latest version from nerdoftheherd.com", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return false;
            }

            // Migrate old (pre 0.26) version databases from www.nerdoftheherd.com -> NerdoftheHerd.com
            string oldDbPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "www.nerdoftheherd.com"), Application.ProductName), DbFileName);

            if (File.Exists(oldDbPath) && !File.Exists(appDbPath))
            {
                File.Move(oldDbPath, appDbPath);
            }

            // Test if there is an existing application database
            if (!File.Exists(appDbPath))
            {
                // Start with a copy of the template database
                File.Copy(specDbPath, appDbPath);

                // Set the current database version in the new database
                Settings.DatabaseVersion = Database.CurrentDbVersion;
            }
            else
            {
                // Start a transaction so we can roll back a half-completed upgrade on error
                using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                {
                    try
                    {
                        // Perform a check and automatic update of the database table structure
                        using (SQLiteConnection specConn = new SQLiteConnection("Data Source=" + specDbPath + ";Version=3;New=False;Read Only=True"))
                        {
                            specConn.Open();
                            UpdateStructure(specConn, Database.FetchDbConn());
                        }

                        // Perform any updates required which were not handled by UpdateStructure
                        switch (Settings.DatabaseVersion)
                        {
                            case 4:
                                // Clear error details previously serialised as XML
                                using (SQLiteCommand command = new SQLiteCommand("update downloads set errordetails=null where errortype=@errortype", FetchDbConn()))
                                {
                                    command.Parameters.Add(new SQLiteParameter("errortype", ErrorType.UnknownError));
                                    command.ExecuteNonQuery();
                                }

                                break;
                            case Database.CurrentDbVersion:
                                // Nothing to do, this is the current version.
                                break;
                        }

                        // Set the current database version
                        Settings.DatabaseVersion = Database.CurrentDbVersion;
                    }
                    catch (SQLiteException)
                    {
                        transMon.Trans.Rollback();
                        throw;
                    }

                    transMon.Trans.Commit();
                }
            }

            // Prune the database once a week
            if (Settings.LastPrune.AddDays(7) < DateTime.Now)
            {
                using (Status status = new Status())
                {
                    status.ShowDialog(delegate
                    {
                        Prune(status);
                    });
                }
            }

            // Vacuum the database every three months
            if (Settings.LastVacuum.AddMonths(3) < DateTime.Now)
            {
                using (Status status = new Status())
                {
                    status.ShowDialog(delegate
                    {
                        Vacuum(status);
                    });
                }
            }

            return true;
        }
Ejemplo n.º 11
0
        public static bool Startup()
        {
            const string DbFileName = "store.db";
            string specDbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DbFileName);
            string appDbPath = Path.Combine(FileUtils.GetAppDataFolder(), DbFileName);

            // Ensure that the template database exists
            if (!File.Exists(specDbPath))
            {
                MessageBox.Show("The Radio Downloader template database was not found at '" + specDbPath + "'." + Environment.NewLine + Environment.NewLine + "Try repairing the Radio Downloader installation or installing the latest version from nerdoftheherd.com", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return false;
            }

            using (SQLiteConnection specConn = new SQLiteConnection("Data Source=" + specDbPath + ";Version=3;New=False;Read Only=True"))
            {
                specConn.Open();

                using (SQLiteCommand command = new SQLiteCommand("pragma integrity_check(1)", specConn))
                {
                    string result = (string)command.ExecuteScalar();

                    if (result.ToUpperInvariant() != "OK")
                    {
                        MessageBox.Show("The Radio Downloader template database at '" + specDbPath + "' appears to be corrupted." + Environment.NewLine + Environment.NewLine + "Try repairing the Radio Downloader installation or installing the latest version from nerdoftheherd.com", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return false;
                    }
                }

                // Migrate old (pre 0.26) version databases from www.nerdoftheherd.com -> NerdoftheHerd.com
                string oldDbPath = Path.Combine(Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "www.nerdoftheherd.com"), Application.ProductName), DbFileName);

                if (File.Exists(oldDbPath) && !File.Exists(appDbPath))
                {
                    File.Move(oldDbPath, appDbPath);
                }

                // Test if there is an existing application database
                if (!File.Exists(appDbPath))
                {
                    // Start with a copy of the template database
                    File.Copy(specDbPath, appDbPath);

                    // Set the current database version in the new database
                    Settings.DatabaseVersion = CurrentDbVersion;
                }
                else
                {
                    using (SQLiteCommand command = new SQLiteCommand("pragma integrity_check(1)", FetchDbConn()))
                    {
                        string result = (string)command.ExecuteScalar();

                        if (result.ToUpperInvariant() != "OK")
                        {
                            if (MessageBox.Show("Unfortunately Radio Downloader cannot start because your database has become corrupted." + Environment.NewLine + Environment.NewLine + "Would you like to view some help about resolving this issue?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
                            {
                                OsUtils.LaunchUrl(new Uri("https://nerdoftheherd.com/tools/radiodld/help/corrupt-database"), "corruptdb");
                            }

                            return false;
                        }
                    }

                    // Start a transaction so we can roll back a half-completed upgrade on error
                    using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                    {
                        try
                        {
                            // Perform a check and automatic update of the database table structure
                            UpdateStructure(specConn, FetchDbConn());

                            // Perform any updates required which were not handled by UpdateStructure
                            switch (Settings.DatabaseVersion)
                            {
                                case 4:
                                    // Clear error details previously serialised as XML
                                    using (SQLiteCommand command = new SQLiteCommand("update downloads set errordetails=null where errortype=@errortype", FetchDbConn()))
                                    {
                                        command.Parameters.Add(new SQLiteParameter("errortype", ErrorType.UnknownError));
                                        command.ExecuteNonQuery();
                                    }

                                    break;
                                case CurrentDbVersion:
                                    // Nothing to do, this is the current version.
                                    break;
                            }

                            // Set the current database version
                            Settings.DatabaseVersion = CurrentDbVersion;
                        }
                        catch (SQLiteException)
                        {
                            transMon.Trans.Rollback();
                            throw;
                        }

                        transMon.Trans.Commit();
                    }
                }
            }

            // Prune the database once a week
            if (Settings.LastPrune.AddDays(7) < DateTime.Now)
            {
                using (Status status = new Status())
                {
                    status.ShowDialog(() =>
                    {
                        Prune(status);
                    });
                }
            }

            // Vacuum the database every three months
            if (Settings.LastVacuum.AddMonths(3) < DateTime.Now)
            {
                using (Status status = new Status())
                {
                    status.ShowDialog(() =>
                    {
                        Vacuum(status);
                    });
                }
            }

            return true;
        }