public static String CheckRVCHash()
        {
            var logger = LogManager.GetLogger("Main");

            Newtonsoft.Json.Linq.JObject rvc_hash;

            logger.Info(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RVCHash_StartDownload"));
            try
            {
                using (WebClient client = new WebClient())
                {
                    client.Headers.Add("accept", "application/json");
                    client.Headers.Add("User-Agent", "request");

                    string downloadedString = client.DownloadString("https://api.github.com/repos/mtaku3/AutoMuteUs-Portable/contents/rvc.json");
                    rvc_hash = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(downloadedString);
                    logger.Debug(downloadedString);
                }
            }
            catch
            {
                logger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RVCHash_DownloadFailed"));
                return(null);
            }

            if (!rvc_hash.ContainsKey("sha"))
            {
                logger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RVCHash_DownloadFailed"));
                return(null);
            }

            return(rvc_hash.GetValue("sha").ToString());
        }
        private void CheckRVCUpdate()
        {
            var logger = LogManager.GetLogger("Main");

            var rvc_hash = SettingsWindow.CheckRVCHash();
            var rvc      = SettingsWindow.CheckRVC();

            if (rvc_hash == null || rvc == null)
            {
                return;
            }

            if (Properties.Settings.Default.RVC_Hash != rvc_hash || Properties.Settings.Default.RVC_Hash == "")
            {
                logger.Info($"{LocalizationProvider.GetLocalizedValue<string>("MainLogger_RVCHash_UpdateDetected")} \"{Properties.Settings.Default.RVC_Hash}\" => \"{rvc_hash}\"");
                String message = LocalizationProvider.GetLocalizedValue <string>("MainWindow_RVCUpdate_Text");

                foreach (var item in rvc)
                {
                    message += $"\n{item.Key.ToString()} : {item.Value.ToString()}";
                }

                MessageBox.Show(message, LocalizationProvider.GetLocalizedValue <string>("MainWindow_RVCUpdate_Title"), MessageBoxButton.OK);

                Properties.Settings.Default.RVC_Hash = rvc_hash;
                Properties.Settings.Default.Save();
            }
        }
示例#3
0
        private void RestartProc(KeyValuePair <string, Process> proc)
        {
            if (proc.Key == "postgres")
            {
                AddProc("postgres", CreateProcessFromArchive("postgres.zip", "postgres\\bin\\pg_ctl.exe", "start -D data", "postgres\\"));                         // postgres
            }
            if (proc.Key == "redis")
            {
                AddProc("redis", CreateProcessFromArchive("redis.zip", "redis\\redis-server.exe"));                      // redis
            }
            if (proc.Key == "galactus")
            {
                AddProc("galactus", CreateProcessFromExecutable("galactus.exe"));                         // galactus
            }
            if (proc.Key == "wingman")
            {
                AddProc("wingman", CreateProcessFromExecutable("wingman.exe"));                        // wingman
            }
            if (proc.Key == "automuteus")
            {
                AddProc("automuteus", CreateProcessFromExecutable("automuteus.exe"));                           // automuteus
            }
            var process = Procs[proc.Key];

            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            var ellipse = IndicatorControls[proc.Key]["Ellipse"] as Ellipse;

            ellipse.Dispatcher.Invoke((Action)(() => ellipse.Fill = Brushes.LimeGreen));
            logger["Main"].Info($"{proc.Key} {LocalizationProvider.GetLocalizedValue<string>("MainLogger_AutoRestarted")}");
        }
        public static Newtonsoft.Json.Linq.JObject CheckRVC()
        {
            var logger = LogManager.GetLogger("Main");

            Newtonsoft.Json.Linq.JObject rvc;

            logger.Info(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RVC_StartDownload"));
            try
            {
                using (WebClient client = new WebClient())
                {
                    string downloadedString = client.DownloadString("https://raw.githubusercontent.com/mtaku3/AutoMuteUs-Portable/main/rvc.json");
                    if (downloadedString.Contains("404"))
                    {
                        logger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RVC_DownloadFailed"));
                        return(null);
                    }
                    rvc = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(downloadedString);
                    logger.Debug(downloadedString);
                }
            }
            catch
            {
                logger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RVC_DownloadFailed"));
                return(null);
            }

            return(rvc);
        }
        private async void CheckUpdate()
        {
            var logger = LogManager.GetLogger("Main");

            var CurrentInformationalVersion = (string)Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;

            logger.Info($"{LocalizationProvider.GetLocalizedValue<string>("MainLogger_Version")} \"{CurrentInformationalVersion}\"");

            Newtonsoft.Json.Linq.JArray AppVersionList;

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("AutoMuteUs-Portable", CurrentInformationalVersion));
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                var httpResponse = await client.GetAsync("https://api.github.com/repos/mtaku3/AutoMuteUs-Portable/git/matching-refs/tags");

                if (!httpResponse.IsSuccessStatusCode)
                {
                    logger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_HttpClientRequestFailed"));
                    return;
                }

                var responseContent = await httpResponse.Content.ReadAsStringAsync();

                AppVersionList = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(responseContent);
            }

            var LatestVersion = AppVersionList.Last;
            var LatestTag     = ((string)LatestVersion["ref"]).Replace("refs/tags/", "");
            var LatestInformationalVersion = (string)LatestVersion["object"]["sha"];

            if (LatestInformationalVersion != CurrentInformationalVersion)
            {
                logger.Info($"{LocalizationProvider.GetLocalizedValue<string>("MainLogger_CheckUpdate_UpdateDetected")} \"{CurrentInformationalVersion}\" => \"{LatestInformationalVersion}\"");
                if (MessageBox.Show($"{LocalizationProvider.GetLocalizedValue<string>("MainWindow_CheckUpdate_UpdateDetected_Text#1")} \"{LatestTag}\"\n{LocalizationProvider.GetLocalizedValue<string>("MainWindow_CheckUpdate_UpdateDetected_Text#2")}", LocalizationProvider.GetLocalizedValue <string>("MainWindow_CheckUpdate_UpdateDetected_Title"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    string url = "https://github.com/mtaku3/AutoMuteUs-Portable/releases/latest";

                    try
                    {
                        Process.Start(url);
                    }
                    catch
                    {
                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                        {
                            url = url.Replace("&", "^&");
                            Process.Start(new ProcessStartInfo("cmd", $"/c start {url}")
                            {
                                CreateNoWindow = true
                            });
                        }
                    }
                }
            }
        }
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            Settings.SetUserVar("EnvPath", EnvPath.Text);

            if (!Directory.Exists(Settings.GetUserVar("EnvPath")))
            {
                MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("ChooseEnvPathWindow_EnvPath_RequiredToFill"));
                return;
            }

            Close();
        }
示例#7
0
 private void StartProcs()
 {
     foreach (var proc in Procs)
     {
         var process = proc.Value;
         process.Start();
         process.BeginErrorReadLine();
         process.BeginOutputReadLine();
         var ellipse = IndicatorControls[proc.Key]["Ellipse"] as Ellipse;
         ellipse.Dispatcher.Invoke((Action)(() => ellipse.Fill = Brushes.LimeGreen));
         logger["Main"].Info($"{proc.Key} {LocalizationProvider.GetLocalizedValue<string>("MainLogger_ProcessStarted")}");
     }
 }
示例#8
0
        private void DownloadRedisCli()
        {
            var requiredComponents = RequiredComponents[Settings.GetUserVar("ARCHITECTURE")];

            if (requiredComponents.Contains("redis") && Directory.Exists(Path.Combine(Properties.Settings.Default.EnvPath, "redis\\")) && !File.Exists(Path.Combine(Properties.Settings.Default.EnvPath, "redis\\redis-cli.exe")))
            {
                var envPath = Properties.Settings.Default.EnvPath;

                MainLogger.Info(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RedisCli_StartDownload"));
                using (WebClient client = new WebClient())
                {
                    var path = Path.Combine(envPath, "redis\\redis-cli.exe");
                    client.DownloadFile("https://github.com/mtaku3/AutoMuteUs-Portable/releases/download/v2.4.1/redis-cli.exe", path);
                    MainLogger.Info(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RedisCli_Loaded"));
                }
            }
        }
示例#9
0
        public void TerminateProcs()
        {
            CancelLoop = true;

            var requiredComponent = Main.RequiredComponents[Settings.GetUserVar("ARCHITECTURE")];

            Ellipse ellipse;

            foreach (var proc in Procs)
            {
                try
                {
                    if (proc.Key == "postgres")
                    {
                        TerminatePostgresServer();
                    }
                    else if (proc.Key == "redis")
                    {
                        TerminateRedisServer();
                    }

                    var process = proc.Value;
                    if (process.HasExited)
                    {
                        throw new Exception();
                    }

                    process.Kill();
                    process.WaitForExit();
                }
                catch
                {
                }

                try
                {
                    ellipse = IndicatorControls[proc.Key]["Ellipse"] as Ellipse;
                    ellipse.Dispatcher.Invoke((Action)(() => ellipse.Fill = Brushes.Red));
                }
                catch
                {
                }

                logger["Main"].Info($"{proc.Key} {LocalizationProvider.GetLocalizedValue<string>("MainLogger_ProcessClosed")}");
            }
        }
        private void DeleteAllBinaries(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("ResetWindow_DeleteAllBinaries_RequireRestart_Text"), LocalizationProvider.GetLocalizedValue <string>("ResetWindow_DeleteAllBinaries_RequireRestart_Title"), MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                return;
            }

            if (MainWindow.main != null)
            {
                MainWindow.main.TerminateProcs();
            }

            RMRF(Settings.GetUserVar("EnvPath"));

            MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("ResetWindow_RestartCaution_Text"), LocalizationProvider.GetLocalizedValue <string>("ResetWindow_RestartCaution_Title"), MessageBoxButton.OK);
            RestartApplication = true;
        }
        private void SettingsButton_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("MainWindow_SettingsBtn_Caution#1_Text"), LocalizationProvider.GetLocalizedValue <string>("MainWindow_SettingsBtn_Caution#1_Title"), MessageBoxButton.YesNo) != MessageBoxResult.Yes)
            {
                return;
            }

            if (main != null)
            {
                main.TerminateProcs();
            }
            Task.Run(() =>
            {
                MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("MainWindow_SettingsBtn_Caution#2_Text"), LocalizationProvider.GetLocalizedValue <string>("MainWindow_SettingsBtn_Caution#2_Title"), MessageBoxButton.OK);
                Settings.LoadSettings(true);
                LogManager.GetLogger("Main").Info(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RelaunchApp"));
                MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("MainWindow_SettingsBtn_Caution#3_Text"), LocalizationProvider.GetLocalizedValue <string>("MainWindow_SettingsBtn_Caution#3_Title"), MessageBoxButton.OK);
            });
        }
        public static void InitializeFileTarget()
        {
            var config = NLog.LogManager.Configuration;

            LogFilePath = $"{Path.Combine(Path.GetTempPath(), $"AutoMuteUs-Portable")}.log";

            var logger = NLog.LogManager.GetLogger("Main");

            logger.Info($"{LocalizationProvider.GetLocalizedValue<string>("MainLogger_LogOutputStarted")} \"{LogFilePath}\"");

            var fileTarget = new FileTarget()
            {
                FileName = LogFilePath,
                DeleteOldFileOnStartup = true
            };

            config.AddTarget("LogFile", fileTarget);
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, "LogFile", "*");

            NLog.LogManager.Configuration = config;
        }
        private void ResetAllProperties(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("ResetWindow_ResetAllProperties_RequireRestart_Text"), LocalizationProvider.GetLocalizedValue <string>("ResetWindow_ResetAllProperties_RequireRestart_Title"), MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                return;
            }

            if (MainWindow.main != null)
            {
                MainWindow.main.TerminateProcs();
            }

            Properties.Settings.Default.DeleteConfig();
            if (File.Exists(Path.Combine(Settings.GetUserVar("EnvPath"), ".env")))
            {
                File.Delete(Path.Combine(Settings.GetUserVar("EnvPath"), ".env"));
            }

            MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("ResetWindow_RestartCaution_Text"), LocalizationProvider.GetLocalizedValue <string>("ResetWindow_RestartCaution_Title"), MessageBoxButton.OK);
            RestartApplication = true;
        }
        private void ExportLogButton_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(LocalizationProvider.GetLocalizedValue <string>("MainWindow_ExportLogBtn_Caution_Text"), LocalizationProvider.GetLocalizedValue <string>("MainWindow_ExportLogBtn_Caution_Title"), MessageBoxButton.YesNo) != MessageBoxResult.Yes)
            {
                return;
            }

            if (main != null)
            {
                main.TerminateProcs();
            }
            var source = LogFilePath;
            var dist   = Path.Combine(AppContext.BaseDirectory, "AutoMuteUs-Portable.log");

            if (File.Exists(dist))
            {
                File.Delete(dist);
            }
            File.Move(source, dist);

            MessageBox.Show($"{LocalizationProvider.GetLocalizedValue<string>("MainWindow_ExportLogBtn_Result_Text")} \"{dist}\"", LocalizationProvider.GetLocalizedValue <string>("MainWindow_ExportLogBtn_Result_Title"), MessageBoxButton.OK);
        }
示例#15
0
        public static void TerminateRedisServer()
        {
            try
            {
                if (!File.Exists(Path.Combine(Settings.GetUserVar("EnvPath"), "redis\\redis-server.exe")))
                {
                    return;
                }
                var server_process = Main.CreateProcessFromArchive("redis.zip", "redis\\redis-cli.exe", "shutdown");
                Main.RedirectProcessStandardIO("redis", server_process);
                server_process.Start();
                server_process.BeginErrorReadLine();
                server_process.BeginOutputReadLine();
                server_process.WaitForExit();
                MainLogger.Info("redis closed.");

                Ellipse ellipse = null;
                try
                {
                    if (IndicatorControls != null && IndicatorControls.ContainsKey("redis"))
                    {
                        ellipse = IndicatorControls["redis"]["Ellipse"] as Ellipse;
                    }
                }
                catch
                {
                }
                if (ellipse != null)
                {
                    ellipse.Dispatcher.Invoke((Action)(() => ellipse.Fill = Brushes.Red));
                }
            }
            catch
            {
                MainLogger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_RedisFailToClose"));
                MainLogger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_TryCloseManually"));
            }
        }
        private void UpdateEnvVars()
        {
            var logger = LogManager.GetLogger("Main");

            logger.Debug("########## EnvVars Update ##########");

            foreach (var variable in OldEnvVars)
            {
                TextBox textBox = AllControls[variable.Key]["TextBox"] as TextBox;

                if (Settings.CheckRequiredVariable(variable.Key, textBox.Text) != null)
                {
                    if (variable.Key == "POSTGRES_PASS")
                    {
                        if (MessageBox.Show($"POSTGRESS_PASS {LocalizationProvider.GetLocalizedValue<string>("SettingsWindow_UpdateEnvVars_PostgresPass_RequiredToFill_Text")}", LocalizationProvider.GetLocalizedValue <string>("SettingsWindow_UpdateEnvVars_PostgresPass_RequiredToFill_Title"), MessageBoxButton.YesNo) == MessageBoxResult.No)
                        {
                            return;
                        }

                        textBox.Text = GeneratePassword();

                        MessageBox.Show($"POSTGRES_PASS {LocalizationProvider.GetLocalizedValue<string>("SettingsWindow_UpdateEnvVars_PostgresPass_AutoGenerated_Text")} \"{textBox.Text}\"", LocalizationProvider.GetLocalizedValue <string>("SettingsWindow_UpdateEnvVars_PostgresPass_AutoGenerated_Title"), MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBox.Show($"{variable.Key} {LocalizationProvider.GetLocalizedValue<string>("SettingsWindow_UpdateEnvVars_RequiredToFill_Text")}");
                        return;
                    }
                }

                if (OldEnvVars[variable.Key] != textBox.Text)
                {
                    Settings.SetEnvVar(variable.Key, textBox.Text);
                }
            }

            logger.Debug("####################################");
        }
示例#17
0
        public static void TerminatePostgresServer()
        {
            try
            {
                if (!File.Exists(Path.Combine(Settings.GetUserVar("EnvPath"), "postgres\\bin\\postgres.exe")))
                {
                    return;
                }
                var server_process = Main.CreateProcessFromArchive("postgres.zip", "postgres\\bin\\pg_ctl.exe", "stop -w -D data", "postgres\\");
                server_process.Start();
                _ = Main.ConsumeOutputReader("postgres", server_process.StandardOutput);
                _ = Main.ConsumeErrorReader("postgres", server_process.StandardError);
                server_process.WaitForExit();
                MainLogger.Info(LocalizationProvider.GetLocalizedValue <string>("MainLogger_PostgresClosed"));

                Ellipse ellipse = null;
                try
                {
                    if (IndicatorControls != null && IndicatorControls.ContainsKey("postgres"))
                    {
                        ellipse = IndicatorControls["postgres"]["Ellipse"] as Ellipse;
                    }
                }
                catch
                {
                }
                if (ellipse != null)
                {
                    ellipse.Dispatcher.Invoke((Action)(() => ellipse.Fill = Brushes.Red));
                }
            }
            catch
            {
                MainLogger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_PostgresFailedToClose"));
                MainLogger.Error(LocalizationProvider.GetLocalizedValue <string>("MainLogger_TryCloseManually"));
            }
        }
        private void UpdateUserVars()
        {
            var logger = LogManager.GetLogger("Main");

            logger.Debug("########## UserVars Update ##########");

            foreach (var variable in OldUserVars)
            {
                if (variable.Key == "AUTOMUTEUS_TAG" || variable.Key == "GALACTUS_TAG" || variable.Key == "WINGMAN_TAG" || variable.Key == "ARCHITECTURE")
                {
                    if (SkipComponent(variable.Key))
                    {
                        continue;
                    }
                    ComboBox comboBox = AllControls[variable.Key]["ComboBox"] as ComboBox;

                    if (Settings.CheckRequiredVariable(variable.Key, (string)comboBox.SelectedValue) != null)
                    {
                        MessageBox.Show($"{variable.Key} {LocalizationProvider.GetLocalizedValue<string>("SettingsWindow_UpdateUserVars_RequiredToFill_Text")}");
                        return;
                    }

                    if (OldUserVars[variable.Key] != (string)comboBox.SelectedValue)
                    {
                        Settings.SetUserVar(variable.Key, (string)comboBox.SelectedValue);
                    }
                }
                else if (variable.Key == "EnvPath")
                {
                    continue;
                }
                else if (variable.Key == "AUTOMUTEUS_AUTORESTART" || variable.Key == "GALACTUS_AUTORESTART" || variable.Key == "WINGMAN_AUTORESTART")
                {
                    if (SkipComponent(variable.Key))
                    {
                        continue;
                    }

                    CheckBox checkBox = AllControls[variable.Key]["CheckBox"] as CheckBox;

                    var Value = (bool)checkBox.IsChecked ? "True" : "False";

                    if (OldUserVars[variable.Key] != Value)
                    {
                        Settings.SetUserVar(variable.Key, Value);
                    }
                }
                else
                {
                    TextBox textBox = AllControls[variable.Key]["TextBox"] as TextBox;

                    if (Settings.CheckRequiredVariable(variable.Key, textBox.Text) != null)
                    {
                        MessageBox.Show($"{variable.Key} {LocalizationProvider.GetLocalizedValue<string>("SettingsWindow_UpdateUserVars_RequiredToFill_Text")}");
                        return;
                    }

                    if (OldUserVars[variable.Key] != textBox.Text)
                    {
                        Settings.SetUserVar(variable.Key, textBox.Text);
                    }
                }
            }

            logger.Debug("#####################################");
        }
        private void InitializeControls()
        {
            OldEnvVars  = new Dictionary <string, string>(Settings.EnvVars);
            OldUserVars = new Dictionary <string, string>(Settings.UserVars);
            var VersionList = Settings.VersionList;

            AllControls = new Dictionary <string, Dictionary <string, UIElement> >();

            var logger = LogManager.GetLogger("Main");

            logger.Debug("########## OldEnvVars Output ##########");
            logger.Debug(JsonConvert.SerializeObject(OldEnvVars));
            logger.Debug("#######################################");

            logger.Debug("########## OldUserVars Output ##########");
            logger.Debug(JsonConvert.SerializeObject(OldUserVars));
            logger.Debug("########################################");

            Grid grid;

            foreach (var variable in OldUserVars)
            {
                if (SkipComponent(variable.Key))
                {
                    continue;
                }

                var controls = new Dictionary <string, UIElement>();

                grid = new Grid();
                controls.Add("Grid", grid);

                for (var i = 0; i < 2; i++)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                }

                var textBlock = new TextBlock()
                {
                    Text   = variable.Key,
                    Margin = new Thickness(0, 0, 10, 0)
                };
                grid.Children.Add(textBlock);
                Grid.SetColumn(textBlock, 0);
                controls.Add("TextBlock", textBlock);

                if (variable.Key == "AUTOMUTEUS_TAG")
                {
                    var comboBox = new ComboBox()
                    {
                        Width = 300,
                        Name  = variable.Key
                    };

                    foreach (var item in Settings.VersionList["automuteus"])
                    {
                        comboBox.Items.Add(item.Key);
                    }

                    comboBox.SelectedValue = OldUserVars["AUTOMUTEUS_TAG"];

                    grid.Children.Add(comboBox);
                    Grid.SetColumn(comboBox, 1);
                    controls.Add("ComboBox", comboBox);
                }
                else if (variable.Key == "GALACTUS_TAG")
                {
                    var comboBox = new ComboBox()
                    {
                        Width = 300,
                        Name  = variable.Key
                    };

                    foreach (var item in Settings.VersionList["galactus"])
                    {
                        comboBox.Items.Add(item.Key);
                    }

                    comboBox.SelectedValue = OldUserVars["GALACTUS_TAG"];

                    grid.Children.Add(comboBox);
                    Grid.SetColumn(comboBox, 1);
                    controls.Add("ComboBox", comboBox);
                }
                else if (variable.Key == "WINGMAN_TAG")
                {
                    var comboBox = new ComboBox()
                    {
                        Width = 300,
                        Name  = variable.Key
                    };

                    foreach (var item in Settings.VersionList["wingman"])
                    {
                        comboBox.Items.Add(item.Key);
                    }

                    comboBox.SelectedValue = OldUserVars["WINGMAN_TAG"];

                    grid.Children.Add(comboBox);
                    Grid.SetColumn(comboBox, 1);
                    controls.Add("ComboBox", comboBox);
                }
                else if (variable.Key == "ARCHITECTURE")
                {
                    var comboBox = new ComboBox()
                    {
                        Width = 300,
                        Name  = variable.Key
                    };

                    comboBox.Items.Add("v7");
                    comboBox.Items.Add("v6");
                    comboBox.Items.Add("v5");
                    comboBox.Items.Add("v4");

                    comboBox.SelectedValue = OldUserVars["ARCHITECTURE"];

                    comboBox.DropDownClosed += ComboBox_DropDownClosed;

                    grid.Children.Add(comboBox);
                    Grid.SetColumn(comboBox, 1);
                    controls.Add("ComboBox", comboBox);
                }
                else if (variable.Key == "EnvPath")
                {
                    var changeEnvPathButton = new Button()
                    {
                        Width   = 300,
                        Content = LocalizationProvider.GetLocalizedValue <string>("SettingsWindow_ChangeEnvPathBtn"),
                        Name    = variable.Key
                    };
                    changeEnvPathButton.Click += ChangeEnvPathButton_Click;
                    grid.Children.Add(changeEnvPathButton);
                    Grid.SetColumn(changeEnvPathButton, 1);
                    controls.Add("Button", changeEnvPathButton);
                }
                else if (variable.Key == "AUTOMUTEUS_AUTORESTART" || variable.Key == "GALACTUS_AUTORESTART" || variable.Key == "WINGMAN_AUTORESTART")
                {
                    var checkBox = new CheckBox()
                    {
                        Name      = variable.Key,
                        IsChecked = variable.Value == "True"
                    };
                    grid.Children.Add(checkBox);
                    Grid.SetColumn(checkBox, 1);
                    controls.Add("CheckBox", checkBox);
                }
                else
                {
                    var textBox = new TextBox()
                    {
                        Width = 300,
                        Text  = variable.Value,
                        Name  = variable.Key
                    };
                    grid.Children.Add(textBox);
                    Grid.SetColumn(textBox, 1);
                    controls.Add("TextBox", textBox);
                }


                stackPanel.Children.Add(grid);

                var separetor = new Separator();
                stackPanel.Children.Add(separetor);
                controls.Add("Separator", separetor);

                AllControls.Add(variable.Key, controls);
            }

            for (var ind = 0; ind < OldEnvVars.Count(); ind++)
            {
                var variable = OldEnvVars.ElementAt(ind);

                var controls = new Dictionary <string, UIElement>();

                grid = new Grid();
                controls.Add("Grid", grid);

                for (var i = 0; i < 2; i++)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                }

                var textBlock = new TextBlock()
                {
                    Text   = variable.Key,
                    Margin = new Thickness(0, 0, 10, 0)
                };
                grid.Children.Add(textBlock);
                Grid.SetColumn(textBlock, 0);
                controls.Add("TextBlock", textBlock);

                var textBox = new TextBox()
                {
                    Width = 300,
                    Text  = variable.Value,
                    Name  = variable.Key
                };
                grid.Children.Add(textBox);
                Grid.SetColumn(textBox, 1);
                controls.Add("TextBox", textBox);


                stackPanel.Children.Add(grid);

                if (ind != OldEnvVars.Count() - 1)
                {
                    var separetor = new Separator();
                    stackPanel.Children.Add(separetor);
                    controls.Add("Separator", separetor);
                }

                AllControls.Add(variable.Key, controls);
            }

            var button = new Button()
            {
                Content = LocalizationProvider.GetLocalizedValue <string>("SettingsWindow_SaveBtn"),
                Name    = "SaveBtn",
                VerticalContentAlignment   = VerticalAlignment.Center,
                HorizontalContentAlignment = HorizontalAlignment.Center
            };

            button.AddHandler(Button.ClickEvent, new RoutedEventHandler(saveBtn_Click));

            stackPanel.Children.Add(button);

            button = new Button()
            {
                Content = LocalizationProvider.GetLocalizedValue <string>("SettingsWindow_CancelBtn"),
                Name    = "CancelBtn",
                VerticalContentAlignment   = VerticalAlignment.Center,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(0, 5, 0, 0)
            };

            button.AddHandler(Button.ClickEvent, new RoutedEventHandler(cancelBtn_Click));

            stackPanel.Children.Add(button);

            button = new Button()
            {
                Content = LocalizationProvider.GetLocalizedValue <string>("SettingsWindow_UseRVCBtn"),
                Name    = "UseRVCBtn",
                VerticalContentAlignment   = VerticalAlignment.Center,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(0, 5, 0, 0)
            };

            button.AddHandler(Button.ClickEvent, new RoutedEventHandler(useRVCBtn_Click));

            stackPanel.Children.Add(button);

            ApplyRecommendedVersionCombination();
        }
示例#20
0
        public static void LoadSettings(bool ForceToSet = false)
        {
            var ForceToLoad = ForceToSet;

            while (true)
            {
                EnvVars  = new Dictionary <string, string>();
                UserVars = new Dictionary <string, string>();
                EnvLines = new Dictionary <string, int>();

                GetListFromGithub();

                var properties = new[] { "EnvPath", "ARCHITECTURE", "AUTOMUTEUS_TAG", "GALACTUS_TAG", "WINGMAN_TAG", "AUTOMUTEUS_AUTORESTART", "GALACTUS_AUTORESTART", "WINGMAN_AUTORESTART" };

                foreach (string property in properties)
                {
                    if (property != "RVC_Hash")
                    {
                        UserVars.Add(property, (string)Properties.Settings.Default[property]);
                    }
                }

                logger.Debug("UserVars loaded.");
                logger.Debug("########## UserVars ##########");
                logger.Debug(JsonConvert.SerializeObject(UserVars));
                logger.Debug("##############################");

                if (!Directory.Exists(GetUserVar("EnvPath")))
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        var chooseEnvPathWindow = new ChooseEnvPathWindow();
                        chooseEnvPathWindow.ShowDialog();
                    });

                    SettingsWindow.useRecommendedVersionCombination = true;
                }

                logger.Info($"EnvPath: {GetUserVar("EnvPath")}");

                var requiredComponent = Main.RequiredComponents[GetUserVar("ARCHITECTURE")];

                if (!File.Exists(Path.Combine(GetUserVar("EnvPath"), ".env")))
                {
                    DownloadEnv(GetUserVar("EnvPath"), GetUserVar("ARCHITECTURE"));
                }

                if (!File.Exists(Path.Combine(GetUserVar("EnvPath"), "diffenvs.json")))
                {
                    LoadDiffEnvs(GetUserVar("EnvPath"), GetUserVar("ARCHITECTURE"));
                }

                EnvVars = LoadEnv(Path.Combine(GetUserVar("EnvPath"), ".env"));

                logger.Debug("EnvVars loaded.");
                logger.Debug("########## EnvVars ##########");
                logger.Debug(JsonConvert.SerializeObject(EnvVars));
                logger.Debug("#############################");

                if (CheckAllRequiredVariable(UserVars, EnvVars) || ForceToSet)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        var settingsWindow = new SettingsWindow();
                        if (!settingsWindow.hasClosed)
                        {
                            settingsWindow.ShowDialog();
                        }
                    });

                    ForceToSet = false;
                }
                else
                {
                    try
                    {
                        LoadBinaries(ForceToLoad);
                        if (requiredComponent.Contains("postgres"))
                        {
                            SetupPostgres();
                        }
                        return;
                    }
                    catch (Exception e)
                    {
                        logger.Error($"{LocalizationProvider.GetLocalizedValue<string>("MainLogger_FailToLoadBinary")} {e.Message}");
                        continue;
                    }
                }
            }
        }