private void Options_Load(object sender, EventArgs e)
        {
            ftpDeXpand.Visible = false;
            FtpExpand.Visible  = true;

            #region textbox loading

            Xml_Reader XML   = new Xml_Reader();
            string     World = XML.GetWorld();
            BackupFrom.Text = World;
            string BackupTime = XML.GetBackupTime();
            BackuptimeText.Text = BackupTime;

            #endregion


            #region load Backup to folder
            string WorldTo = XML.GetBackupTo();
            BackupTo.Text = WorldTo;
            #endregion


            #region ftp loading

            string ftpUser    = XML.GetFtpUser();
            string ftpPass    = XML.GetFtpPass();
            string ftpServer  = XML.GetFtpServer();
            string ftpFolder  = XML.GetFtpFolder();
            string ftpFolder2 = XML.GetFtpFolder2();
            ftpUserText.Text    = ftpUser;
            ftpPassText.Text    = ftpPass;
            ftpServerText.Text  = ftpServer;
            ftpFolderText.Text  = ftpFolder;
            ftpFolder2Text.Text = ftpFolder2;

            #endregion


            #region load checkbox config

            string Compression = XML.UseCompression();
            if (Compression == "yes")
            {
                UseCompression.Checked = true;
            }

            string Update = XML.GetUpdateSettings();
            if (Update == "yes")
            {
                UpdatingCheckBox.Checked = true;
            }

            #endregion
        }
        private void Options_Load(object sender, EventArgs e)
        {
            ftpDeXpand.Visible = false;
            FtpExpand.Visible = true;

            #region textbox loading

            Xml_Reader XML = new Xml_Reader();
            string World = XML.GetWorld();
            BackupFrom.Text = World;
            string BackupTime = XML.GetBackupTime();
            BackuptimeText.Text = BackupTime;

            #endregion

            #region load Backup to folder
            string WorldTo = XML.GetBackupTo();
            BackupTo.Text = WorldTo;
            #endregion

            #region ftp loading

            string ftpUser = XML.GetFtpUser();
            string ftpPass = XML.GetFtpPass();
            string ftpServer = XML.GetFtpServer();
            string ftpFolder = XML.GetFtpFolder();
            string ftpFolder2 = XML.GetFtpFolder2();
            ftpUserText.Text = ftpUser;
            ftpPassText.Text = ftpPass;
            ftpServerText.Text = ftpServer;
            ftpFolderText.Text = ftpFolder;
            ftpFolder2Text.Text = ftpFolder2;

            #endregion

            #region load checkbox config

            string Compression = XML.UseCompression();
            if (Compression == "yes")
            {
                UseCompression.Checked = true;
            }

            string Update = XML.GetUpdateSettings();
            if (Update == "yes")
            {
                UpdatingCheckBox.Checked = true;
            }

            #endregion
        }
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Backup());
            }
            else
            {
                NativeMethods.AllocConsole();
                if (args[0].ToLower() == "b" || args[0].ToLower() == "/b")
                #region backup
                {
                    Error_Logging Log  = new Error_Logging();
                    Xml_Reader    read = new Xml_Reader();

                    if (!Directory.Exists(Environment.GetEnvironmentVariable("appdata") + "\\returnzork\\") || !File.Exists(Environment.GetEnvironmentVariable("appdata") + "\\returnzork\\Settings.config"))
                    {
                        Log.MakeLog(null, "  Settings do not exist, cannot continue.");
                        Console.WriteLine("The settings file does not exist. Cannot continue without the settings file.");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }



                    string FROM        = read.GetWorld();
                    string TO          = read.GetBackupTo();
                    string Compression = read.UseCompression();
                    string DateNTime   = DateTime.Now.ToString("MM.dd.yyyy  hh-mm-ss");


                    if (!FROM.EndsWith("\\") && FROM != "FTP")
                    {
                        FROM = FROM + "\\";
                    }
                    if (!TO.EndsWith("\\") && TO != "FTP")
                    {
                        TO = TO + "\\";
                    }


                    if (!Directory.Exists(FROM) && FROM != "FTP")
                    {
                        Console.WriteLine("CANNOT RUN WHEN THE WORLD FOLDER DOES NOT EXIST, AND WHEN NOT RUNNING ON FTP.\r\nTest");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }

                    #region copy world
                    #region Non FTP
                    #region not exist
                    if (!Directory.Exists(TO) && TO != "FTP")
                    {
                        Directory.CreateDirectory(TO);

                        if (!Directory.Exists(TO + DateNTime))
                        {
                            Directory.CreateDirectory(TO + DateNTime);
                        }

                        foreach (string dirPath in Directory.GetDirectories(FROM, "*", SearchOption.AllDirectories))
                        {
                            Directory.CreateDirectory(dirPath.Replace(FROM, TO + DateNTime + "\\"));
                        }


                        foreach (string newPath in Directory.GetFiles(FROM, "*.*", SearchOption.AllDirectories))
                        {
                            File.Copy(newPath, newPath.Replace(FROM, TO + DateNTime + "\\"));
                        }

                        Console.WriteLine("Finished copying world.");



                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.DoWork += new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();

                        Console.ReadKey();
                        Application.Exit();


                        #region compression
                        if (Compression == "yes")
                        {
                            ZipFile zip = new ZipFile();

                            try
                            {
                                zip.AddDirectory(TO + DateNTime);
                                zip.Save(TO + DateNTime + ".zip");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("An error has occurred:r\n\"" + ex);
                                Console.ReadKey();
                                Log.MakeLog(ex, null);
                            }
                        }
                        #endregion
                    }
                    #endregion
                    #region Exists
                    else if (Directory.Exists(TO) && TO != "FTP")
                    {
                        if (!Directory.Exists(TO + DateNTime))
                        {
                            Directory.CreateDirectory(TO + DateNTime);
                        }

                        foreach (string dirPath in Directory.GetDirectories(FROM, "*", SearchOption.AllDirectories))
                        {
                            Directory.CreateDirectory(dirPath.Replace(FROM, TO + DateNTime + "\\"));
                        }


                        foreach (string newPath in Directory.GetFiles(FROM, "*.*", SearchOption.AllDirectories))
                        {
                            File.Copy(newPath, newPath.Replace(FROM, TO + DateNTime + "\\"));
                        }


                        #region compression
                        if (Compression == "yes")
                        {
                            ZipFile zip = new ZipFile();

                            try
                            {
                                zip.AddDirectory(TO + DateNTime);
                                zip.Save(TO + DateNTime + ".zip");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("An error has occurred:r\n\"" + ex);
                                Console.ReadKey();
                                Log.MakeLog(ex, null);
                            }
                        }
                        #endregion


                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.WorkerReportsProgress = false;
                        bgworker.DoWork += new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();



                        Console.WriteLine("Finished copying world.");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }
                    #endregion
                    #endregion
                    #region FTP
                    #region Upload
                    else if (TO == "FTP")
                    {
                        Ftp_Upload upload = new Ftp_Upload();
                        upload.Upload(DateNTime);

                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.WorkerReportsProgress = false;
                        bgworker.DoWork += new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();

                        Console.WriteLine("Finished");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }
                    #endregion
                    #region Download
                    else if (FROM == "FTP")
                    {
                        Ftp_Download download = new Ftp_Download();
                        download.main(DateNTime);
                        #region compression
                        if (Compression == "yes")
                        {
                            ZipFile zip = new ZipFile();

                            try
                            {
                                zip.AddDirectory(TO + DateNTime);
                                zip.Save(TO + DateNTime + ".zip");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("An error has occurred:r\n\"" + ex);
                                Console.ReadKey();
                                Log.MakeLog(ex, null);
                            }
                        }
                        #endregion

                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.WorkerReportsProgress = false;
                        bgworker.DoWork += new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();

                        Console.WriteLine("Finished");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }
                    #endregion
                    #endregion
                    #endregion
                }
                #endregion
                else if (args[0].ToLower() == "r" || args[0].ToLower() == "/r")
                #region reset settings
                {
                    if (Directory.Exists(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\"))
                    {
                        string[] FILES = Directory.GetFiles(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\");
                        foreach (string file in FILES)
                        {
                            File.Delete(file);
                        }
                    }
                    Console.WriteLine("Completed!");
                    Console.WriteLine("");
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                }
                #endregion
                else if (args[0].ToLower() == "settings" || args[0].ToLower() == "/s")
                #region Current settings
                {
                    Xml_Reader xml = new Xml_Reader();

                    Console.WriteLine("Current settings are:");
                    Console.WriteLine();
                    Console.WriteLine();



                    Console.WriteLine();
                    Console.WriteLine("Backup time is:  " + xml.GetBackupTime() + " minute(s)");
                    Console.WriteLine();
                    Console.WriteLine();

                    if (xml.GetBackupTo() == "ftp")
                    {
                        Console.WriteLine("Backup to ftp is:  on");
                    }
                    else
                    {
                        Console.WriteLine("Backup to ftp is:  off");
                    }
                    if (xml.GetWorld() == "ftp")
                    {
                        Console.WriteLine("Backup from ftp is:  on");
                    }
                    else
                    {
                        Console.WriteLine("Backup from ftp is:  off");
                    }



                    Console.WriteLine();
                    Console.WriteLine();
                    if (xml.GetWorld() != "ftp")
                    {
                        Console.WriteLine("Backup from directory is:   " + xml.GetWorld());
                    }
                    else
                    {
                        Console.WriteLine("Backup from directory is:   ftp:\\\\" + xml.GetFtpServer() + "\\" + xml.GetFtpFolder() + "\\" + xml.GetFtpFolder2());
                    }

                    if (xml.GetBackupTo() != "ftp")
                    {
                        Console.WriteLine("Backup to directory is:  " + xml.GetBackupTo());
                    }
                    else
                    {
                        Console.WriteLine("Backup to directory is:   ftp:\\\\" + xml.GetFtpServer() + "\\" + xml.GetFtpFolder() + "\\" + xml.GetFtpFolder2());
                    }

                    Console.WriteLine();
                    Console.WriteLine();

                    if (xml.GetUpdateSettings() == "no")
                    {
                        Console.WriteLine("Auto updating is:  " + "off");
                    }
                    else if (xml.GetUpdateSettings() == "yes")
                    {
                        Console.WriteLine("Auto updating is:  " + "on");
                    }
                    else
                    {
                        Console.WriteLine("Auto updating is:  " + "not defined");
                    }

                    Console.WriteLine();
                    Console.ReadLine();
                }
                #endregion
                else
                #region help
                {
                    if (args[0] != "/?")
                    {
                        Console.WriteLine("Invalid argument: " + args[0]);
                        Console.WriteLine("");
                        Console.WriteLine("");
                    }
                    Console.WriteLine("BackupV2.exe usage:");
                    Console.WriteLine("");
                    Console.WriteLine("/?: This help message");
                    Console.WriteLine("/B: Backup using the configuration files");
                    Console.WriteLine("/R: Delete all settings files. Start fresh.");
                    Console.WriteLine("");
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                }
                #endregion
            }
        }
        public static string[] GetFileList()
        {
            Error_Logging log  = new Error_Logging();
            Xml_Reader    Read = new Xml_Reader();

            #region string initialization

            string   Server  = Read.GetFtpServer();
            string   User    = Read.GetFtpUser();
            string   Pass    = Read.GetFtpPass();
            string   Folder  = Read.GetFtpFolder();
            string   Folder2 = Read.GetFtpFolder2();
            string[] downloadFiles;

            #endregion


            StringBuilder result   = new StringBuilder();
            WebResponse   responce = null;
            StreamReader  reader   = null;
            try
            {
                FtpWebRequest reqFTP;
                #region FTP details

                reqFTP             = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Server + "/" + Folder + "/" + Folder2));
                reqFTP.UseBinary   = true;
                reqFTP.Credentials = new NetworkCredential(User, Pass);
                reqFTP.Method      = WebRequestMethods.Ftp.ListDirectory;
                reqFTP.Proxy       = null;
                reqFTP.KeepAlive   = false;
                reqFTP.UsePassive  = false;
                responce           = reqFTP.GetResponse();

                #endregion
                reader = new StreamReader(responce.GetResponseStream());
                string line = reader.ReadLine();
                while (line != null)
                {
                    result.Append(line);
                    result.Append("\n");
                    line = reader.ReadLine();
                }
                result.Remove(result.ToString().LastIndexOf("\n"), 1);
                return(result.ToString().Split('\n'));
            }
            catch (Exception ex)
            {
                log.MakeLog(ex, null);
                #region cleanup

                if (reader != null)
                {
                    reader.Close();
                }
                if (responce != null)
                {
                    responce.Close();
                }
                downloadFiles = null;
                return(downloadFiles);

                #endregion
            }
        }
        private void Download(string file, string DateNTime)
        {
            #region string initialization

            string Server     = Read.GetFtpServer();
            string User       = Read.GetFtpUser();
            string Pass       = Read.GetFtpPass();
            string Folder     = Read.GetFtpFolder();
            string Folder2    = Read.GetFtpFolder2();
            string LocalDirTo = Read.GetBackupTo();

            #endregion


            if (!LocalDirTo.EndsWith("\\"))
            {
                LocalDirTo = LocalDirTo + "\\";
            }

            try
            {
                string uri       = "ftp://" + Server + "/" + Folder + "/" + file;
                Uri    serverUri = new Uri(uri);
                if (serverUri.Scheme != Uri.UriSchemeFtp)
                {
                    return;
                }
                FtpWebRequest reqFTP;

                #region FTP details

                reqFTP             = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Server + "/" + Folder + "/" + file));
                reqFTP.Credentials = new NetworkCredential(User, Pass);
                reqFTP.KeepAlive   = false;
                reqFTP.Method      = WebRequestMethods.Ftp.DownloadFile;
                reqFTP.UseBinary   = true;
                reqFTP.Proxy       = null;
                reqFTP.UsePassive  = false;
                FtpWebResponse responce       = (FtpWebResponse)reqFTP.GetResponse();
                Stream         responceStream = responce.GetResponseStream();

                #endregion

                if (!Directory.Exists(LocalDirTo + DateNTime + "\\" + Folder2))
                {
                    Directory.CreateDirectory(LocalDirTo + DateNTime + "\\" + Folder2);
                }
                FileStream writeStream = new FileStream(LocalDirTo + DateNTime + "\\" + file, FileMode.Create);



                //TODO Test with actual server


                int Length = 16; //tweaking this may give better performance, but when I was on 32 it gave tiny noise (playable but..) from a mp3 file, at 256 it was unplayable. Smaller value takes longer but yields nearly 1-1 ratio of size and quality.//


                Byte[] buffer    = new Byte[Length];
                int    bytesRead = responceStream.Read(buffer, 0, Length);
                while (bytesRead > 0)
                {
                    writeStream.Write(buffer, 0, Length);
                    bytesRead = responceStream.Read(buffer, 0, Length);
                }
                writeStream.Close();
                responce.Close();
            }
            #region Catching errors

            catch (WebException wEx)
            {
                Console.WriteLine("Error: " + wEx);
                log.MakeLog(wEx, null);
            }
            catch (AccessViolationException aEx)
            {
                Console.WriteLine("Error: " + aEx);
                log.MakeLog(aEx, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
                log.MakeLog(ex, null);
            }

            #endregion
        }
        public void Upload(string DateNTime)
        {
            string      LocalFolder = Read.GetWorld();
            string      Folder      = Read.GetFtpFolder();
            string      Folder2     = Read.GetFtpFolder2();
            string      User        = Read.GetFtpUser();
            string      Pass        = Read.GetFtpPass();
            string      Server      = Read.GetFtpServer();
            WebResponse responce;

            //throw new NotImplementedException();


            string[]   FILES   = Directory.GetFiles(LocalFolder);
            string[]   fold    = Directory.GetDirectories(LocalFolder);
            WebRequest Request = WebRequest.Create("ftp://" + Server + "/" + Folder + "/" + Folder2);

            Request.Method      = WebRequestMethods.Ftp.MakeDirectory;
            Request.Credentials = new NetworkCredential(User, Pass);


            try
            {
                responce = Request.GetResponse();
            }
            catch (Exception)
            {
                //creates error when the directory already exists, no need to log
                Console.WriteLine("FTP Directory root already exists, continuing...");
            }

            Request             = WebRequest.Create("ftp://" + Server + "/" + Folder + "/" + Folder2 + "/" + DateNTime);
            Request.Method      = WebRequestMethods.Ftp.MakeDirectory;
            Request.Credentials = new NetworkCredential(User, Pass);
            try
            {
                responce = Request.GetResponse();
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error has occured:r\n\"" + ex);
                Console.ReadKey();
                log.MakeLog(ex, null);
            }


            var path    = LocalFolder;
            var dirName = new DirectoryInfo(path).Name;

            #region Create Directories and copy files
            foreach (string dir in fold)
            {
                dirName = new DirectoryInfo(dir).Name;
                string[] Files = Directory.GetFiles(dir);


                Request             = WebRequest.Create("ftp://" + Server + "/" + Folder + "/" + Folder2 + "/" + DateNTime + "/" + dirName);
                Request.Method      = WebRequestMethods.Ftp.MakeDirectory;
                Request.Credentials = new NetworkCredential(User, Pass);
                try
                {
                    responce = Request.GetResponse();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An error has occurred:r\n\"" + ex);
                    Console.ReadKey();
                    log.MakeLog(ex, null);
                }

                foreach (string file1 in Files)
                {
                    if (file1 == null)
                    {
                        break;
                    }
                    WebClient client = new WebClient();
                    client.Credentials = new NetworkCredential(User, Pass);
                    try
                    {
                        client.UploadFile("ftp://" + Server + "/" + Folder + "/" + Folder2 + "/" + DateNTime + "/" +
                                          dirName + "/" + new FileInfo(file1).Name, "STOR", file1);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error has occured:r\n\"" + ex);
                        Console.ReadKey();
                        log.MakeLog(ex, null);
                    }
                }
            }
            #endregion

            #region Copy files from root folder
            foreach (string files in FILES)
            {
                WebClient client = new WebClient();
                client.Credentials = new NetworkCredential(User, Pass);
                try
                {
                    client.UploadFile("ftp://" + Server + "/" + Folder + "/" + Folder2 + "/" + DateNTime + "/" +
                                      new FileInfo(files).Name, "STOR", files);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An error has occured:r\n\"" + ex);
                    Console.ReadKey();
                    log.MakeLog(ex, null);
                }
            }
            #endregion
            Console.WriteLine("Finished FTP upload of world.");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Backup());
            }
            else
            {
                NativeMethods.AllocConsole();
                if (args[0].ToLower() == "b" || args[0].ToLower() == "/b")
                #region backup
                {

                    Error_Logging Log = new Error_Logging();
                    Xml_Reader read = new Xml_Reader();

                    if (!Directory.Exists(Environment.GetEnvironmentVariable("appdata") + "\\returnzork\\") || !File.Exists(Environment.GetEnvironmentVariable("appdata") + "\\returnzork\\Settings.config"))
                    {
                        Log.MakeLog(null, "  Settings do not exist, cannot continue.");
                        Console.WriteLine("The settings file does not exist. Cannot continue without the settings file.");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }

                    string FROM = read.GetWorld();
                    string TO = read.GetBackupTo();
                    string Compression = read.UseCompression();
                    string DateNTime = DateTime.Now.ToString("MM.dd.yyyy  hh-mm-ss");

                    if(!FROM.EndsWith("\\") && FROM != "FTP")
                    {
                        FROM = FROM + "\\";
                    }
                    if (!TO.EndsWith("\\") && TO != "FTP")
                    {
                        TO = TO + "\\";
                    }

                    if (!Directory.Exists(FROM) && FROM != "FTP")
                    {
                        Console.WriteLine("CANNOT RUN WHEN THE WORLD FOLDER DOES NOT EXIST, AND WHEN NOT RUNNING ON FTP.\r\nTest");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }

                    #region copy world
                    #region Non FTP
                    #region not exist
                    if (!Directory.Exists(TO) && TO != "FTP")
                    {
                        Directory.CreateDirectory(TO);

                        if (!Directory.Exists(TO + DateNTime))
                        {
                            Directory.CreateDirectory(TO + DateNTime);
                        }

                        foreach (string dirPath in Directory.GetDirectories(FROM, "*", SearchOption.AllDirectories))
                            Directory.CreateDirectory(dirPath.Replace(FROM, TO + DateNTime + "\\"));

                        foreach (string newPath in Directory.GetFiles(FROM, "*.*", SearchOption.AllDirectories))
                            File.Copy(newPath, newPath.Replace(FROM, TO + DateNTime + "\\"));

                        Console.WriteLine("Finished copying world.");

                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.DoWork +=new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();

                        Console.ReadKey();
                        Application.Exit();

                        #region compression
                        if (Compression == "yes")
                        {
                            ZipFile zip = new ZipFile();

                            try
                            {
                                zip.AddDirectory(TO + DateNTime);
                                zip.Save(TO + DateNTime + ".zip");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("An error has occurred:r\n\"" + ex);
                                Console.ReadKey();
                                Log.MakeLog(ex, null);
                            }
                        }
                        #endregion
                    }
                    #endregion
                    #region Exists
                    else if (Directory.Exists(TO) && TO != "FTP")
                    {
                        if (!Directory.Exists(TO + DateNTime))
                        {
                            Directory.CreateDirectory(TO + DateNTime);
                        }

                        foreach (string dirPath in Directory.GetDirectories(FROM, "*", SearchOption.AllDirectories))
                            Directory.CreateDirectory(dirPath.Replace(FROM, TO + DateNTime + "\\"));

                        foreach (string newPath in Directory.GetFiles(FROM, "*.*", SearchOption.AllDirectories))
                            File.Copy(newPath, newPath.Replace(FROM, TO + DateNTime + "\\"));

                        #region compression
                        if (Compression == "yes")
                        {
                            ZipFile zip = new ZipFile();

                            try
                            {
                                zip.AddDirectory(TO + DateNTime);
                                zip.Save(TO + DateNTime + ".zip");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("An error has occurred:r\n\"" + ex);
                                Console.ReadKey();
                                Log.MakeLog(ex, null);
                            }
                        }
                        #endregion

                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.WorkerReportsProgress = false;
                        bgworker.DoWork += new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();

                        Console.WriteLine("Finished copying world.");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }
                    #endregion
                    #endregion
                    #region FTP
                    #region Upload
                    else if (TO == "FTP")
                    {
                        Ftp_Upload upload = new Ftp_Upload();
                        upload.Upload(DateNTime);

                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.WorkerReportsProgress = false;
                        bgworker.DoWork += new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();

                        Console.WriteLine("Finished");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }
                    #endregion
                    #region Download
                    else if (FROM == "FTP")
                    {
                        Ftp_Download download = new Ftp_Download();
                        download.main(DateNTime);
                        #region compression
                        if (Compression == "yes")
                        {
                            ZipFile zip = new ZipFile();

                            try
                            {
                                zip.AddDirectory(TO + DateNTime);
                                zip.Save(TO + DateNTime + ".zip");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("An error has occurred:r\n\"" + ex);
                                Console.ReadKey();
                                Log.MakeLog(ex, null);
                            }
                        }
                        #endregion

                        System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
                        bgworker.WorkerReportsProgress = false;
                        bgworker.DoWork += new System.ComponentModel.DoWorkEventHandler(bgworker_DoWork);
                        bgworker.RunWorkerAsync();

                        Console.WriteLine("Finished");
                        Console.ReadKey();
                        Environment.Exit(0);
                    }
                    #endregion
                    #endregion
                    #endregion
                }
                #endregion
                else if (args[0].ToLower() == "r" || args[0].ToLower() == "/r")
                #region reset settings
                {
                    if (Directory.Exists(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\"))
                    {
                        string[] FILES = Directory.GetFiles(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\");
                        foreach (string file in FILES)
                        {
                            File.Delete(file);
                        }
                    }
                    Console.WriteLine("Completed!");
                    Console.WriteLine("");
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                }
                #endregion
                else if (args[0].ToLower() == "settings" || args[0].ToLower() == "/s")
                #region Current settings
                {
                    Xml_Reader xml = new Xml_Reader();

                    Console.WriteLine("Current settings are:");
                    Console.WriteLine();
                    Console.WriteLine();

                    Console.WriteLine();
                    Console.WriteLine("Backup time is:  " + xml.GetBackupTime() + " minute(s)");
                    Console.WriteLine();
                    Console.WriteLine();

                    if (xml.GetBackupTo() == "ftp")
                    {
                        Console.WriteLine("Backup to ftp is:  on");
                    }
                    else
                    {
                        Console.WriteLine("Backup to ftp is:  off");
                    }
                    if (xml.GetWorld() == "ftp")
                    {
                        Console.WriteLine("Backup from ftp is:  on");
                    }
                    else
                    {
                        Console.WriteLine("Backup from ftp is:  off");
                    }

                    Console.WriteLine();
                    Console.WriteLine();
                    if (xml.GetWorld() != "ftp")
                    {
                        Console.WriteLine("Backup from directory is:   " + xml.GetWorld());
                    }
                    else
                    {
                        Console.WriteLine("Backup from directory is:   ftp:\\\\" + xml.GetFtpServer() + "\\" + xml.GetFtpFolder() + "\\" + xml.GetFtpFolder2());
                    }

                    if (xml.GetBackupTo() != "ftp")
                    {
                        Console.WriteLine("Backup to directory is:  " + xml.GetBackupTo());
                    }
                    else
                    {
                        Console.WriteLine("Backup to directory is:   ftp:\\\\" + xml.GetFtpServer() + "\\" + xml.GetFtpFolder() + "\\" +xml.GetFtpFolder2());
                    }

                    Console.WriteLine();
                    Console.WriteLine();

                    if(xml.GetUpdateSettings() == "no")
                    {
                        Console.WriteLine("Auto updating is:  " + "off");
                    }
                    else if (xml.GetUpdateSettings() == "yes")
                    {
                        Console.WriteLine("Auto updating is:  " + "on");
                    }
                    else
                    {
                        Console.WriteLine("Auto updating is:  " + "not defined");
                    }

                    Console.WriteLine();
                    Console.ReadLine();
                }
                #endregion
                else
                #region help
                {
                    if (args[0] != "/?")
                    {
                        Console.WriteLine("Invalid argument: " + args[0]);
                        Console.WriteLine("");
                        Console.WriteLine("");
                    }
                    Console.WriteLine("BackupV2.exe usage:");
                    Console.WriteLine("");
                    Console.WriteLine("/?: This help message");
                    Console.WriteLine("/B: Backup using the configuration files");
                    Console.WriteLine("/R: Delete all settings files. Start fresh.");
                    Console.WriteLine("");
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                }
                #endregion
            }
        }
        public static string[] GetFileList()
        {
            Error_Logging log = new Error_Logging();
            Xml_Reader Read = new Xml_Reader();

            #region string initialization

            string Server = Read.GetFtpServer();
            string User = Read.GetFtpUser();
            string Pass = Read.GetFtpPass();
            string Folder = Read.GetFtpFolder();
            string Folder2 = Read.GetFtpFolder2();
            string[] downloadFiles;

            #endregion

            StringBuilder result = new StringBuilder();
            WebResponse responce = null;
            StreamReader reader = null;
            try
            {
                FtpWebRequest reqFTP;
                #region FTP details

                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Server + "/" + Folder + "/" + Folder2));
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(User, Pass);
                reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
                reqFTP.Proxy = null;
                reqFTP.KeepAlive = false;
                reqFTP.UsePassive = false;
                responce = reqFTP.GetResponse();

                #endregion
                reader = new StreamReader(responce.GetResponseStream());
                string line = reader.ReadLine();
                while (line != null)
                {
                    result.Append(line);
                    result.Append("\n");
                    line = reader.ReadLine();
                }
                result.Remove(result.ToString().LastIndexOf("\n"), 1);
                return result.ToString().Split('\n');
            }
            catch(Exception ex)
            {
                log.MakeLog(ex,null);
                #region cleanup

                if (reader != null)
                {
                    reader.Close();
                }
                if (responce != null)
                {
                    responce.Close();
                }
                downloadFiles = null;
                return downloadFiles;

                #endregion
            }
        }
        public Backup()
        {
            InitializeComponent();

            StopButton.Enabled = false;

            if (!Directory.Exists(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork"))
            {
                Directory.CreateDirectory(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork");
            }

            #region extract settings

            if (!File.Exists(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\Settings.config"))
            {
                Stream     stream     = Assembly.GetExecutingAssembly().GetManifestResourceStream("BackupV2.Text_Files.Settings.config");
                FileStream fileStream = new FileStream(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\Settings.config", FileMode.CreateNew);
                for (int i = 0; i < stream.Length; i++)
                {
                    fileStream.WriteByte((byte)stream.ReadByte());
                }
                fileStream.Close();
            }

            #endregion

            #region extract version file

            Folder2 = XmlReader.GetFtpFolder2();

            UpdateLabel.Visible = false;

            if (!File.Exists(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\Version.txt"))
            {
                Stream     stream     = Assembly.GetExecutingAssembly().GetManifestResourceStream("BackupV2.Text_Files.Version.txt");
                FileStream fileStream = new FileStream(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\Version.txt", FileMode.CreateNew);
                for (int i = 0; i < stream.Length; i++)
                {
                    fileStream.WriteByte((byte)stream.ReadByte());
                }
                fileStream.Close();
            }

            #endregion

            #region check if using mono

            Type Mono = Type.GetType("Mono.Runtime");

            if (Mono != null)  //if not null it is mono//
            {
                OS = "MONO";
            }
            else
            {
                OS = "NET";
            }

            #endregion

            #region app icon

            if (OS == "NET")
            {
                this.Icon = new Icon(Assembly.GetEntryAssembly().GetManifestResourceStream("BackupV2.Icons.Cloud.ico"));
            }

            #endregion

            #region Close to Tray

            if (OS == "NET")
            {
                Tray.Visible           = false;
                Tray.Text              = "Minecraft Server Backup";
                this.Resize           += new EventHandler(Form_Resize);
                Tray.MouseDoubleClick += new MouseEventHandler(Tray_MouseDoubleClick);

                menu.MenuItems.Add("Save World", new EventHandler(SaveWorld_CLICK));
                menu.MenuItems.Add("Check for updates", new EventHandler(CheckForUpdate));
                menu.MenuItems.Add("Quit", new System.EventHandler(QUIT_Click));
                Tray.ContextMenu = menu;
            }

            #endregion

            #region Save world process

            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName    = Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\save.vbs";
            p.StartInfo           = startInfo;

            #endregion
        }