Ejemplo n.º 1
0
        private void restoreDBBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string loc = String.Empty;

            foreach (string f in Directory.GetFiles(String.Format("{0}\\TrinityCore Manager\\backups", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))))
            {
                if (String.Format("{0:T}", GetDate(f)) == e.Argument.ToString())
                {
                    loc = f;
                }
            }

            if (loc != String.Empty && File.Exists(loc))
            {
                mysql = new SQLMethods(Settings.Default.MySQLHost, Settings.Default.MySQLPort, Settings.Default.MySQLUsername, Settings.Default.MySQLPassword);

                if (mysql != null)
                {
                    try
                    {
                        mysql.ExecuteMySQLScript(loc);

                        restoreSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        TaskDialog.Show(new TaskDialogInfo("Error", eTaskDialogIcon.Stop, "Error!", ex.Message, eTaskDialogButton.Ok));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void CreateMySQL()
        {
            if (mysql != null)
            {
                this.Invoke((MethodInvoker) delegate
                {
                    DBProgressBarX.ProgressType = eProgressItemType.Marquee;
                });

                string loc = String.Empty;

                if (Directory.Exists(Path.Combine(location, "sql")))
                {
                    loc = Path.Combine(location, "sql");
                }
                else if (Directory.Exists(Path.Combine(location, "TrinityCore", "sql")))
                {
                    loc = Path.Combine(location, "TrinityCore", "sql");
                }
                else
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            DBProgressBarX.Visible = false;

                            TaskDialog.Show(new TaskDialogInfo("Error!", eTaskDialogIcon.Stop, "An error has occured!", "Could not find sql folder!", eTaskDialogButton.Ok));
                        });
                    }

                    return;
                }

                mysql.MySQLStatementExecuted += new EventHandler(mysql_MySQLStatementExecuted);

                string mysqlDeleteLoc = Path.Combine(loc, "create", "drop_mysql.sql");


                if (!File.Exists(mysqlDeleteLoc))
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            DBProgressBarX.Visible = false;

                            TaskDialog.Show(new TaskDialogInfo("Error!", eTaskDialogIcon.Stop, "An error has occured!", "Could not find drop_mysql.sql!", eTaskDialogButton.Ok));
                        });
                    }

                    return;
                }

                try
                {
                    mysql.ExecuteMySQLScript(mysqlDeleteLoc);
                }
                catch (Exception ex)
                {
                    TaskDialog.Show(new TaskDialogInfo("Error", eTaskDialogIcon.Stop, "Error!", ex.Message, eTaskDialogButton.Ok));
                }

                string mysqlCreateLoc = Path.Combine(loc, "create", "create_mysql.sql");

                if (!File.Exists(mysqlCreateLoc))
                {
                    if (this.InvokeRequired)
                    {
                        DBProgressBarX.Visible = false;

                        TaskDialog.Show(new TaskDialogInfo("Error!", eTaskDialogIcon.Stop, "An error has occured!", "Could not find create_mysql.sql!", eTaskDialogButton.Ok));

                        return;
                    }
                }

                mysql.ExecuteMySQLScript(mysqlCreateLoc);



                string mysqlAuthDB = Path.Combine(loc, "base", "auth_database.sql");


                if (!File.Exists(mysqlAuthDB))
                {
                    if (this.InvokeRequired)
                    {
                        DBProgressBarX.Visible = false;

                        TaskDialog.Show(new TaskDialogInfo("Error!", eTaskDialogIcon.Stop, "An error has occured!", "Could not find auth_database.sql!", eTaskDialogButton.Ok));

                        return;
                    }
                }

                mysql.ExecuteMySQLScript(mysqlAuthDB, authDB);


                string mysqlCharDB = Path.Combine(loc, "base", "characters_database.sql");

                if (!File.Exists(mysqlCharDB))
                {
                    if (this.InvokeRequired)
                    {
                        DBProgressBarX.Visible = false;

                        TaskDialog.Show(new TaskDialogInfo("Error!", eTaskDialogIcon.Stop, "An error has occured!", "Could not find characters_database.sql!", eTaskDialogButton.Ok));

                        return;
                    }
                }

                mysql.ExecuteMySQLScript(mysqlCharDB, charDB);

                this.Invoke((MethodInvoker) delegate
                {
                    MySQLPercentLabelX.Visible = true;

                    DBProgressBarX.ProgressType = eProgressItemType.Standard;
                });

                WebClient downloadWorldDB = new WebClient();
                downloadWorldDB.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadWorldDB_DownloadProgressChanged);
                downloadWorldDB.DownloadFileCompleted   += new AsyncCompletedEventHandler(downloadWorldDB_DownloadFileCompleted);

                downloadWorldDB.DownloadFileAsync(new Uri("https://github.com/downloads/TrinityCore/TrinityCore/TDB_335.11.40_2011_05_09.rar"), Path.Combine(location, "TDB_335.11.40_2011_05_09.rar"));
            }
        }