private async void CheckBox_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            string data = "0";
            
            string urlAddress = "http://sync.seakecommerce.com/xapi/generate?collection_type=mods&type=xml&limit=all&mod_packagename=" + cb.Tag;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = null;
                if (response.CharacterSet == null)
                    readStream = new StreamReader(receiveStream);
                else
                    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                data = readStream.ReadToEnd();
                response.Close();
                readStream.Close();

                //var Web_Browser = new WebBrowser {};
                //Web_Browser.write("<html><body style=\"background: #f0f0f0\"></body></html>");
                //Web_Browser.NavigateToString("<html><body style=\"background: #f0f0f0\">" + data + "</body></html>");

                var stackPanel = new StackPanel { Orientation = Orientation.Vertical };

                XDocument itemz = XDocument.Load(urlAddress);

                string name_title = "";
                foreach (var item in itemz.Descendants("item"))
                {
                    string name = item.Element("mod_name").Value;
                    string name_namespace = item.Element("mod_namespace").Value;
                    name_title = item.Element("mod_name").Value;
                    string mod_size = item.Element("mod_size").Value;
                    string updatedat = item.Element("mod_updatedat").Value;
                    string type = item.Element("mod_type").Value;

                    string updatedat_time = "Updated " + (TimeAgo(DateTime.Parse(updatedat)));
                    string createdat_time = "" + (TimeAgo(DateTime.Parse(item.Element("mod_createdat").Value)));

                    BitmapImage map_image = new BitmapImage(new Uri(item.Element("mod_image").Value, UriKind.Absolute));

                    stackPanel.Children.Add(new Image { Source = map_image, Width = 500, Height = 250, Stretch = Stretch.Fill, HorizontalAlignment = System.Windows.HorizontalAlignment.Left });

                    stackPanel.Children.Add(new TextBlock { Text = name + " (" + name_namespace + ")", FontSize = 14, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Margin = new System.Windows.Thickness(0, 15, 0, 0) });
                    stackPanel.Children.Add(new Separator { HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 20, 0, 20), });
                    stackPanel.Children.Add(new TextBlock { Text = updatedat_time, FontSize = 12, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Margin = new System.Windows.Thickness(0, 10, 0, 0), });


                    stackPanel.Children.Add(new TextBlock { FontWeight = FontWeights.Bold, Text = "Mod Info", FontSize = 14, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 5, 0, 0), Margin = new System.Windows.Thickness(0, 5, 0, 0), });
                    stackPanel.Children.Add(new Separator { Opacity = 0.2, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 20, 0, 20), });

                    if (item.Element("mod_dependencies").Value == null)
                    {
                        stackPanel.Children.Add(new TextBlock { Text = "No Mod Dependencies", FontSize = 12, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 0, 0, 5), Margin = new System.Windows.Thickness(0, 5, 0, 0), });
                        stackPanel.Children.Add(new Separator { Opacity = 0.2, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 20, 0, 20), });

                    }
                    else
                    {
                        stackPanel.Children.Add(new TextBlock { Text = "Required Mods: " + item.Element("mod_dependencies").Value, FontSize = 12, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 0, 0, 5), Margin = new System.Windows.Thickness(0, 5, 0, 0), });
                        stackPanel.Children.Add(new Separator { HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 20, 0, 20), });
                        
                    }

                    stackPanel.Children.Add(new TextBlock { Text = "Mod Size | " + mod_size, FontSize = 12, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 0, 0, 5), Margin = new System.Windows.Thickness(0, 5, 0, 0), });
                    stackPanel.Children.Add(new Separator { Opacity = 0.2, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 20, 0, 20), });


                    stackPanel.Children.Add(new TextBlock { Text = "Mod Created | " + createdat_time, FontSize = 12, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 0, 0, 5), Margin = new System.Windows.Thickness(0, 5, 0, 0), });
                    stackPanel.Children.Add(new Separator { Opacity = 0.2, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 500, Padding = new System.Windows.Thickness(0, 20, 0, 20), });


                }

                await Task.Run(() => Thread.Sleep(2000));

                var wnd = new FirstFloor.ModernUI.Windows.Controls.ModernWindow
                {


                    Style = (Style)App.Current.Resources["BlankWindow"],
                    Title = "Viewing " + cb.Tag + " Mod info",
                    Topmost = true,
                    
                    IsTitleVisible = true,
                    Content = stackPanel,
                    Width = 510,
                    Height = 510
                };
                wnd.ResizeMode = ResizeMode.NoResize;
                wnd.Show();

                string appfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string AusTacQuick2Launch_Log = System.IO.Path.Combine(appfolder, "AusTacQuick2Launch/Log");
                using (StreamWriter sw = File.AppendText(AusTacQuick2Launch_Log + "/log.txt"))
                {
                    string time = DateTime.Now.ToString();

                    sw.WriteLine(time + " | Success Fetching XML - URL: " + urlAddress);


                }

            }
            else
            {

                var wnd = new FirstFloor.ModernUI.Windows.Controls.ModernWindow
                {
                    Style = (Style)App.Current.Resources["BlankWindow"],
                    Title = "Server Connection Error",
                    IsTitleVisible = true,
                    Content = "Error! Server Down",
                    Width = 280,
                    Height = 280
                };
                wnd.Show();

                string appfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string AusTacQuick2Launch_Log = System.IO.Path.Combine(appfolder, "AusTacQuick2Launch/Log");
                using (StreamWriter sw = File.AppendText(AusTacQuick2Launch_Log + "/log.txt"))
                {
                    string time = DateTime.Now.ToString();

                    sw.WriteLine(time + " | Error Fetching XML - Server Down - URL: " + urlAddress);


                }
            }
        }
        private async void Launch_Click(object sender, RoutedEventArgs e)
        {
            //Get a List<BoolStringClass> that contains all selected items:
            var res = (
                    from item in TheList
                    where item.IsSelected == true
                    select item
                ).ToList<BoolStringClass>();

            //Convert all items to a concatenated string:
            var res2 =
            from item in TheList
            select item.IsSelected ? item.TheText : "";

            string ip_address_connect = "";
            string port_address_connect = "";
            string password_connect = "";

            if (string.IsNullOrEmpty(ip_address.Text))
            {
                //IP Empty
            }
            else
            {
                if (string.IsNullOrEmpty(port_address.Text))
                {
                    //Port Empty
                }
                else
                {
                    ip_address_connect = "-connect=" + ip_address.Text;
                    port_address_connect = "-port=" + port_address.Text;
                    password_connect = "-password="******"AusTacQuick2Launch/Settings");
            string arma_2_path_value = "";
            try
            {
                if (!System.IO.File.Exists(AusTacQuick2Launch_Settings + @"\Arma2Path.txt"))
                {
                    arma_2_path_value = AusTacQuick2Launch.Properties.Settings.Default.Arma2Path;
                }
                else
                {
                    arma_2_path_value = System.IO.File.ReadLines(AusTacQuick2Launch_Settings + @"\Arma2Path.txt").First();
                }
            }
            catch (Exception)
            {
                // Fail silently
                //logging
                //string appfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string AusTacQuick2Launch_Log = System.IO.Path.Combine(appfolder, "AusTacQuick2Launch/Log");
                using (StreamWriter sw = File.AppendText(AusTacQuick2Launch_Log + "/log.txt"))
                {
                    string time = DateTime.Now.ToString();
                    sw.WriteLine(time + " | Error Checking Arma 2 Path File");
                }
            }

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            string arma2_mods_folder_value = "";
            try
            {
                if (!System.IO.File.Exists(AusTacQuick2Launch_Settings + @"\Arma2ModsPath.txt"))
                {
                    arma2_mods_folder_value = AusTacQuick2Launch.Properties.Settings.Default.Arma2ModsPath;
                }
                else
                {
                    arma2_mods_folder_value = System.IO.File.ReadLines(AusTacQuick2Launch_Settings + @"\Arma2ModsPath.txt").First();
                }
            }
            catch (Exception)
            {
                // Fail silently
                //logging
                //string appfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string AusTacQuick2Launch_Log = System.IO.Path.Combine(appfolder, "AusTacQuick2Launch/Log");
                using (StreamWriter sw = File.AppendText(AusTacQuick2Launch_Log + "/log.txt"))
                {
                    string time = DateTime.Now.ToString();
                    sw.WriteLine(time + " | Error Checking Arma 2 Mods Path File");
                }
            }

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            string arma_2_path = arma_2_path_value;
            string arma_2_mods_path = arma2_mods_folder_value;

            string arma_2_exe = "";
            if(true == allow_battleye.IsChecked) { arma_2_exe = "ArmA2OA_BE.exe"; } else { arma_2_exe = "ArmA2OA.exe"; }


            string mods = "-mod=";
            string Arma2ExtrasOriginal = SteamFolder() + @"\SteamApps\Common\Arma 2;" + SteamFolder() + @"\SteamApps\Common\Arma 2 operation arrowhead;" + "expansion;";
            string Arma2Extras = "";
            Arma2Extras = Arma2ExtrasOriginal.Replace(@"\", "/");

            StringBuilder sb = new StringBuilder();

            //sb.AppendFormat(SteamFolder() + @"\SteamApps\Common\Arma 2;");
            //sb.AppendFormat(SteamFolder() + @"\SteamApps\Common\Arma 2 Operation Arrowhead;");
            //sb.AppendFormat("expansion");
            /*
            foreach (var item in TheList)
            {
                if (item.IsSelected == true)
                {
                    if (item.TheText == "ACR")
                    {
                        string seperator = @"\";
                        sb.AppendFormat(arma_2_path + seperator + "{0};", item.TheText);

                    }
                    else
                    {
                        if (item.TheText == "ACRLite")
                        {
                            string seperator = @"\";
                            sb.AppendFormat(arma_2_path + seperator + "{0};", item.TheText);

                        }
                        else
                        {

                            string seperator = @"\";
                            sb.AppendFormat(arma_2_mods_path + seperator + "{0};", item.TheText);
                        }

                    }


                }
            }
            */

            foreach (var item in ModsListBox.Items)
            {
                
                    if (item.ToString() == "ACR")
                    {
                        string seperator = @"\";
                        sb.AppendFormat(arma_2_path + seperator + "{0};", item.ToString());

                    }
                    else
                    {
                        if (item.ToString() == "ACRLite")
                        {
                            string seperator = @"\";
                            sb.AppendFormat(arma_2_path + seperator + "{0};", item.ToString());

                        }
                        else
                        {

                            string seperator = @"\";
                            sb.AppendFormat(arma_2_mods_path + seperator + "{0};", item.ToString());
                        }

                    }


            }


            string app_ouput = sb.ToString();
            //get start up params
            string nosplash = "";
            if (true == launch_setting_nosplash.IsChecked) { nosplash = "-nosplash"; }
            string scripterrors = "";
            if (true == launch_setting_scripterrors.IsChecked) { scripterrors = "-showscripterrors"; }
            string intro = "";
            if (true == launch_setting_intro.IsChecked) { intro = "-skipIntro"; }
            string nopause = "";
            if (true == launch_setting_nopause.IsChecked) { nopause = "-noPause"; }

            if (true == allow_steamurl.IsChecked){
                string steamPath = "";
                RegistryKey steamkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Valve\Steam");
                if (steamkey != null){steamPath = steamkey.GetValue("installPath").ToString() + "\\steam.exe";}

               //string steamurl = steamPath +  "-applaunch 33930 " + Process.StartInfo.Arguments;
               //string app_params = ip_address_connect + port_address_connect + password_connect + '"' + mods + Arma2Extras + app_ouput + '"' + nosplash + scripterrors + nopause + intro;
               //string steamurl = "steam://run/33930//" + app_params;
                Process.StartInfo.Arguments = "-applaunch 33930 " + ip_address_connect + port_address_connect + password_connect + '"' + mods + Arma2Extras + app_ouput + '"' + nosplash + scripterrors + nopause + intro;
                Process.StartInfo.FileName = steamPath;


                try { Process.Start(); }

            catch (Exception)
            {
                var wnd = new FirstFloor.ModernUI.Windows.Controls.ModernWindow
                {


                    Style = (Style)App.Current.Resources["BlankWindow"],
                    Title = "Error",
                    Topmost = true,

                    IsTitleVisible = true,
                    Content = "Can't launch Game using Steam URL Paramters.",
                    Width = 510,
                    Height = 510
                };
                wnd.ResizeMode = ResizeMode.NoResize;
                wnd.Show();
            }
             


            }else{

            //Launch using Arma EXE
            Process.StartInfo.Arguments = ip_address_connect + port_address_connect + password_connect + '"' + mods + Arma2Extras + app_ouput + '"' + nosplash + scripterrors + nopause + intro;
            string combined = System.IO.Path.Combine(arma_2_path, arma_2_exe);
            Process.StartInfo.FileName = combined;
            Process.Start();
            }
            //string launchparams = "steam://run/33930//" + mods + Arma2Extras + app_ouput + nosplash + scripterrors + nopause + intro;
            //System.Diagnostics.Process.Start(launchparams);
            
            
            /*
            Process process = new Process();
            string combined = System.IO.Path.Combine(arma_2_path, arma_2_exe);
            process.StartInfo.FileName = combined;
            //process.StartInfo.FileName = "arma2oa.exe";
            process.StartInfo.Arguments = "" + nosplash +  "-mod=M:/Steam/SteamApps/common/Arma 2;M:/Steam/SteamApps/common/Arma 2 Operation Arrowhead;expansion;M:/ArmaMods/@ACE;M:/ArmaMods/@ACEX;M:/ArmaMods/@CBA_CO;";
            //process.StartInfo.WorkingDirectory = gameDir + "/Expansion/beta/";
            process.Start();
            */


            //logging
            //string appfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string AusTacQuick2Launch_Log2 = System.IO.Path.Combine(appfolder, "AusTacQuick2Launch/Log");
            using (StreamWriter sw = File.AppendText(AusTacQuick2Launch_Log2 + "/log.txt"))
            {
                string time = DateTime.Now.ToString();
                sw.WriteLine(time + " | Launching Arma 2 with Params: " + Process.StartInfo.Arguments);
                sw.WriteLine(time + " | Launching Arma 2 from: " + Process.StartInfo.FileName);

            }

            Random rnd = new Random();
            int rand = rnd.Next(999, 9999);
            int rand2 = rnd.Next(999, 9999);

            string AusTacQuick2Launch_Recent = System.IO.Path.Combine(appfolder, "AusTacQuick2Launch/Recent");
            using (StreamWriter sw = File.CreateText(AusTacQuick2Launch_Recent + "/Arma2/" + rand + rand2 + ".params"))
            {

                sw.WriteLine(Process.StartInfo.Arguments);

            }

            using (StreamWriter sw = File.CreateText(AusTacQuick2Launch_Recent + "/Arma2/" + rand + rand2 + ".yml"))
            {

                sw.WriteLine("---");
                sw.WriteLine(" ");
                sw.WriteLine("# Name Generated for File");
                sw.WriteLine(":name:" + rand + rand2 + ".yml");
                sw.WriteLine(" ");
                if (string.IsNullOrEmpty(ip_address.Text))
                {
                    //IP Empty
                    sw.WriteLine("# IP Address");
                    sw.WriteLine(":ip:");
                    sw.WriteLine(" ");
                }
                else
                {
                    if (string.IsNullOrEmpty(port_address.Text))
                    {
                        //Port Empty
                        sw.WriteLine("# Port");
                        sw.WriteLine(":port:");
                        sw.WriteLine(" ");
                    }
                    else
                    {

                        sw.WriteLine("# IP Address");
                        sw.WriteLine(":ip:" + ip_address.Text);
                        sw.WriteLine(" ");
                        sw.WriteLine("# Port");
                        sw.WriteLine(":port:" + port_address.Text);
                        sw.WriteLine(" ");

                        sw.WriteLine("# Password");
                        sw.WriteLine(":password:"******" ");

                    }
                }

                sw.WriteLine("# Arma Game Version");
                sw.WriteLine(":game: arma2co");
                sw.WriteLine(" ");

                sw.WriteLine("# Selected Arma Mods");
                sw.WriteLine(":mods:");
                sw.WriteLine(" ");
                /*
                foreach (var item in TheList)
                {
                    if (item.IsSelected == true)
                    {

                        sw.WriteLine("- " + '"' + item.TheText + '"');

                    }
                }
                */

                foreach (var item in ModsListBox.Items)
                {
                     sw.WriteLine("- " + '"' + item.ToString() + '"');

                }

            }


            //Save to Recent
            if (launch_setting_allowrecent.IsChecked == true)
            {

                
                //logging
                //string appfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                //string AusTacQuick2Launch_Recent = System.IO.Path.Combine(appfolder, "AusTacQuick2Launch/Recent");
                using (StreamWriter sw = File.CreateText(AusTacQuick2Launch_Recent + "/Arma2/" + rand + rand2 + ".recent"))
                {

                    foreach (var item in TheList)
                    {
                        if (item.IsSelected == true)
                        {
                            sw.WriteLine(item.TheText);

                        }
                    }


                }

                

            }

            if (AfterLaunchMinimizeselected.IsChecked == true)
            {

               

            }
            else if (AfterLaunchCloseselected.IsChecked == true)
            {

                //Folder is Not Set Correctly
                panelhide.Visibility = Visibility.Hidden;
                panelnofile.Visibility = Visibility.Hidden;
                panelclosing.Visibility = Visibility.Visible;
                ModsListPanel.Visibility = Visibility.Hidden;
                
                await Task.Run(() => Thread.Sleep(5000)); 
                Application.Current.Shutdown();

            }


        }