Ejemplo n.º 1
0
        /// <summary>
        /// Формирование и отправка сообщения на сайт разработчика
        ///
        /// Категории ответов:
        ///     OK - Сервер дал добро на добавление записи
        ///     ANSWER - Сервер вернул текстовый результат (ответил)
        ///     Hacking attempt! - Неавторизованный доступ к серверу
        ///     BANNED - Идентификатор пользователя заблокирован
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bSend_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (tbEmail.Text.Trim().Length > 0 && tbEmail.Text.Trim().IndexOf("@") == -1)
                {
                    MessageBox.Show(Lang.Set("PageFeedback", "UncorrectEmail", lang));
                }
                else
                if (tbMessage.Text.Length >= Convert.ToInt16(Properties.Resources.Developer_Feedback_Symbols))
                {
                    if (MessageBox.Show(Lang.Set("PageFeedback", "SendNow", lang), Application.Current.GetType().Assembly.GetName().Name, MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        Task.Factory.StartNew(() =>
                                              Dispatcher.BeginInvoke(new ThreadStart(delegate
                        {
                            string cat    = String.Empty;
                            string status = string.Empty;

                            try
                            {
                                Classes.POST POST = new Classes.POST();

                                /*
                                 *  Получаем тикет
                                 *
                                 *  api             код API
                                 *  user_id         идентификатор пользователя
                                 *  user_name       имя юзера, если авторизован
                                 *  user_email      мыло юзера, если авторизован
                                 *  modpack_type    тип мультипака
                                 *  modpack_ver     версия мультипака
                                 *  launcher        версия лаунчера
                                 *  youtube         канал ютуба (идентификатор мододела)
                                 *  lang            язык запроса
                                 *  os              версия ОС
                                 */

                                if (rbWishMultipack.IsChecked == true)
                                {
                                    cat = "WM";
                                }
                                else if (rbWishLauncher.IsChecked == true)
                                {
                                    cat = "WL";
                                }
                                else if (rbWishInstaller.IsChecked == true)
                                {
                                    cat = "WI";
                                }
                                else if (rbErrorMultipack.IsChecked == true)
                                {
                                    cat = "EM";
                                }
                                else if (rbErrorLauncher.IsChecked == true)
                                {
                                    cat = "EL";
                                }
                                else if (rbErrorInstaller.IsChecked == true)
                                {
                                    cat = "EI";
                                }

                                JObject json = new JObject(
                                    new JProperty("code", Properties.Resources.API),
                                    new JProperty("user_id", (string)MainWindow.JsonSettingsGet("info.user_id")),
                                    new JProperty("user_name", (string)MainWindow.JsonSettingsGet("info.user_name")),
                                    new JProperty("user_email", POST.Shield(tbEmail.Text.Trim())),
                                    new JProperty("modpack_type", (string)MainWindow.JsonSettingsGet("multipack.type")),
                                    new JProperty("modpack_ver", (string)MainWindow.JsonSettingsGet("multipack.version")),
                                    new JProperty("launcher", (string)MainWindow.JsonSettingsGet("info.ProductName")),
                                    new JProperty("youtube", Properties.Resources.Youtube_Channel),
                                    new JProperty("lang", lang),
                                    new JProperty("os", "disabled"),
                                    new JProperty("category", cat),
                                    new JProperty("message", POST.Shield(tbMessage.Text.Trim()))
                                    );

                                JObject answer = JObject.Parse(POST.Send(Properties.Resources.API_DEV_Address + Properties.Resources.API_DEV_Ticket, json));

                                if (answer["status"].ToString() != "FAIL" && answer["code"].ToString() == Properties.Resources.API)
                                {
                                    switch (answer["status"].ToString())
                                    {
                                    case "OK":
                                        status         = Lang.Set("PageFeedback", "OK", lang, answer["id"].ToString());
                                        tbMessage.Text = String.Empty;
                                        if (tbEmail.IsEnabled)
                                        {
                                            tbEmail.Text = String.Empty;
                                        }
                                        break;

                                    case "BANNED":
                                        status         = Lang.Set("PageFeedback", "BANNED", lang);
                                        tbMessage.Text = String.Empty;
                                        if (tbEmail.IsEnabled)
                                        {
                                            tbEmail.Text = String.Empty;
                                        }
                                        break;

                                    default:
                                        SaveTicket(json);             // Сохранение тикета для последующей отправки
                                        status = Lang.Set("PageFeedback", answer["status"].ToString(), lang) +
                                                 Lang.Set("PageFeedback", answer["content"].ToString(), lang, answer["message"].ToString());
                                        break;
                                    }
                                }
                                else
                                {
                                    SaveTicket(json);         // Сохранение тикета для последующей отправки
                                    status = Lang.Set("PageFeedback", "FAIL", lang, Lang.Set("PageFeedback", answer["content"].ToString(), lang));
                                }
                            }
                            catch (Exception ex)
                            {
                                Task.Factory.StartNew(() => Debugging.Save("Feedback.xaml", "bSend_Click()", "Intro function", ex.Message, ex.StackTrace));
                                status = Lang.Set("PageFeedback", "TICKET_ADD_ERROR", lang);
                            }

                            MessageBox.Show(status);
                        })));
                    }
                }
                else
                {
                    MessageBox.Show(Lang.Set("PageFeedback", "MinimumSymbols", lang, Properties.Resources.Developer_Feedback_Symbols));
                }
            }
            catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("Feedback.xaml", "bSend_Click()", ex.Message, ex.StackTrace)); }
        }
Ejemplo n.º 2
0
        private void GetInfo()
        {
            string ans = String.Empty;

            try
            {
                System.Net.NetworkInformation.Ping      ping  = new System.Net.NetworkInformation.Ping();
                System.Net.NetworkInformation.PingReply reply = ping.Send(Properties.Resources.API_DEV_Address.Split('/').Last());

                if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    if (File.Exists(Properties.Resources.Multipack_Config))
                    {
                        string path = Directory.GetCurrentDirectory() + @"\" + Properties.Resources.Multipack_Config;
                        ApiLauncher = new Classes.IniFile(path).IniReadValue(Properties.Resources.INI, "id").ToLower();
                    }

                    if (ApiLauncher != "")
                    {
                        Classes.POST POST = new Classes.POST();

                        ans = POST.Send(Properties.Resources.API_DEV_Address + Properties.Resources.API_DEV_Info,
                                        new JObject(
                                            new JProperty("secret", ApiLauncher),
                                            new JProperty("youtube", Properties.Resources.Youtube_Channel),

                                            new JProperty("user_id", (string)JsonSettingsGet("info.user_id")),
                                            new JProperty("user_name", (string)JsonSettingsGet("info.user_name")),
                                            new JProperty("user_email", (string)JsonSettingsGet("info.user_email")),
                                            new JProperty("modpack_type", (string)JsonSettingsGet("multipack.type")),
                                            new JProperty("modpack_ver", (string)JsonSettingsGet("multipack.version")),
                                            new JProperty("launcher", Application.Current.GetType().Assembly.GetName().Version.ToString()),
                                            new JProperty("game_ver", (string)JsonSettingsGet("game.version")),
                                            new JProperty("game_test", (bool)JsonSettingsGet("game.test")),
                                            new JProperty("lang", (string)JsonSettingsGet("info.language")),
                                            new JProperty("os", Environment.OSVersion.Version.ToString())
                                            ));

                        JObject answer = JObject.Parse(ans);

                        /*
                         * code
                         * status
                         * version
                         */

                        if ((string)answer["status"] == "ok" && (bool)answer["response"][0]["new_version"] == true)
                        {
                            // Проверяем корректность получения версии
                            Version verRgame;
                            try { verRgame = new Version((string)answer["response"][0]["game_ver"]); }
                            catch (Exception) { verRgame = new Version("0.0.0.0"); }

                            if (new Version((string)JsonSettingsGet("game.version")) < verRgame)
                            {
                                JsonSettingsSet("game.update", true, "bool");
                                JsonSettingsSet("game.new_version", (string)answer["version"]);
                            }
                            else
                            {
                                JsonSettingsSet("game.update", false, "bool");
                            }

                            verRgame = null;
                        }
                        else
                        {
                            JsonSettingsSet("game.update", false, "bool");
                        }
                    }
                }
            }
            catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("MainWindow", "GetInfo(0)", "Developer", ans, ex.Message, ex.StackTrace)); }


            /*
             *      Проверяем обновления мультипака
             */
            JObject json_upd = null;

            try
            {
                System.Net.NetworkInformation.Ping      ping  = new System.Net.NetworkInformation.Ping();
                System.Net.NetworkInformation.PingReply reply = ping.Send(Properties.Resources.Multipack_Address.Split('/').Last());

                if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    json_upd            = new Classes.POST().JsonResponse(Properties.Resources.Multipack_Address + Properties.Resources.Multipack_Updates);
                    json_upd["version"] = (string)json_upd.SelectToken("path") + "." + (string)json_upd.SelectToken((string)JsonSettingsGet("multipack.type") + ".version");

                    if (json_upd != null && (string)json_upd.SelectToken("version") != null)
                    {
                        if (new Version((string)JsonSettingsGet("multipack.version")) <
                            new Version((string)json_upd.SelectToken("version")))
                        {
                            string path = (string)JsonSettingsGet("multipack.type") + ".";

                            JsonSettingsSet("multipack.link", (string)json_upd.SelectToken(path + "download"));
                            JsonSettingsSet("multipack.changelog", (string)json_upd.SelectToken(path + "changelog." + (string)JsonSettingsGet("info.language")));
                            JsonSettingsSet("multipack.new_version", (string)json_upd.SelectToken("version"));
                            JsonSettingsSet("multipack.update", true, "bool");

                            try
                            {
                                if ((string)JsonSettingsGet("info.notification") != (string)json_upd.SelectToken("path"))
                                {
                                    if (JsonSettingsGet("info.session") == null)
                                    {
                                        Dispatcher.BeginInvoke(new ThreadStart(delegate
                                        {
                                            LoadingPanel.Visibility = System.Windows.Visibility.Visible;
                                            MainFrame.NavigationService.Navigate(new Uri("Update.xaml", UriKind.Relative));
                                        }));
                                    }
                                    else
                                    if ((int)JsonSettingsGet("info.session") != Process.GetCurrentProcess().Id)
                                    {
                                        Dispatcher.BeginInvoke(new ThreadStart(delegate
                                        {
                                            LoadingPanel.Visibility = System.Windows.Visibility.Visible;
                                            MainFrame.NavigationService.Navigate(new Uri("Update.xaml", UriKind.Relative));
                                        }));
                                    }
                                }
                            }
                            catch (Exception ex) { Task.Factory.StartNew(() => Debugging.Save("MainWindow", "GetInfo(0)", "OpenPage(Update)", ex.Message, ex.StackTrace)); }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Task.Factory.StartNew(() => Debugging.Save("MainWindow.xaml", "GetInfo(1)",
                                                           "This version: " + (string)JsonSettingsGet("multipack.version"),
                                                           "New version: " + (json_upd != null ? (string)json_upd["version"] : "null"),
                                                           ex.Message, ex.StackTrace));
            }
        }