Ejemplo n.º 1
0
        private async void BtnLoadJson_Click(object sender, RoutedEventArgs e)
        {
            string json_url = customJsonBox.Text;
            var    reserve  = deserializedRoot;

            try
            {
                string json;
                using (var wc = new WebClient())
                    json = wc.DownloadString(json_url);

                //textBox1.Text = "Got JSON from webserver";
                //textBox1.Text = "Got JSON from webserver";
                AppendTextBox1("Successfully connected to webserver", 1);
                deserializedRoot = JsonConvert.DeserializeObject <root_obj>(json);

                //textBox2.Text = deserializedRoot.ver;
                textBox2.Text = deserializedRoot.ver;
                langCombo.Items.Clear();
                foreach (ver_urls a in deserializedRoot.main_arr)
                {
                    //langCombo.Items.Add(a.lang);
                    langCombo.Items.Add(a.lang);
                }
                langCombo.SelectedItem = deserializedRoot.main_arr[0].lang;
                selected_item          = 0;
                outdated         = new file_url[deserializedRoot.main_arr[selected_item].arr.Length];
                cpbLabel.Content = 0 + "/" + deserializedRoot.main_arr[langCombo.SelectedIndex].arr.Length;
                //MessageBox.Show("JSON packages has been loaded successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                var myMessageQueue = new SnackbarMessageQueue(TimeSpan.FromMilliseconds(2000));
                SnackbarMain.MessageQueue = myMessageQueue;
                SnackbarMain.Opacity      = 0.85;
                //SnackbarMain.ActionButtonStyle = (Style)FindResource("MaterialDesignSnackbarActionDarkButton");
                var snackQueue   = SnackbarMain.MessageQueue;
                var snackMessage = SnackbarMain.Message;
                //

                //the message queue can be called from any thread
                // await Task.Factory.StartNew(() => snackQueue.Enqueue(".json packages has been loaded successfully!", "🙂", () => HandleUndoMethod()));
                if (showErr)
                {
                    DockColors("Normal");
                    showErr        = false;
                    statusBox.Text = "waiting for command";
                }
            }
            catch
            {
                showErr = true;
                showUpd = false;
                //MessageBox.Show("Check your internet connection! (cant load json)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                DockColors("Error");
                await ShowDialogHost("Check your internet connection! (cant load .json)");

                deserializedRoot = reserve;
            }
        }
Ejemplo n.º 2
0
 private void uc_init(object sender, EventArgs e)
 {
     download_cts.Cancel();
     mainForm = (MainWindow)Application.Current.MainWindow;
     this.deserializedRoot = mainForm.deserializedRoot;
     if (deserializedRoot != null)
     {
         textBox2.Text = deserializedRoot.ver;
         foreach (ver_urls a in deserializedRoot.main_arr)
         {
             langCombo.Items.Add(a.lang);
         }
         AppendTextBox1("Successfully connected to webserver", 1);
         langCombo.SelectedItem = mainForm.deserializedRoot.main_arr[0].lang;
         outdated         = new file_url[deserializedRoot.main_arr[langCombo.SelectedIndex].arr.Length];
         cpbLabel.Content = 0 + "/" + deserializedRoot.main_arr[langCombo.SelectedIndex].arr.Length;
     }
     else
     {
         showErr = true;
         return;
     }
 }
Ejemplo n.º 3
0
        private void window1_init(object sender, EventArgs e)
        {
            uc2 = new siege_wpf.controls.UserControl2();
            homeBtn.Background = (SolidColorBrush)FindResource("LeftDockButtonSelectedBrush");
            this.Resources["LeftDockHomeColor"]      = ((SolidColorBrush)FindResource("LeftDockButtonSelectedBrush")).Color;
            this.Resources["LeftDockHomeHoverColor"] = ((SolidColorBrush)FindResource("LeftDockButtonSelectedBrush")).Color;
            this.Resources["LeftDockInfoColor"]      = ((SolidColorBrush)FindResource("MainDockColor")).Color;
            this.Resources["LeftDockInfoHoverColor"] = ((SolidColorBrush)FindResource("DockButtonHoverBrush")).Color;

            download_cts.Cancel();
            //checkSem = new Semaphore(1, 1);

            titleBlock.Content = this.Title;
            //Init global variables
            selected_item = 0;
            root_dir      = "";

            ChangeDockColors();

            //url by default
            //json_urls.Add("https://gist.githubusercontent.com/Zipliks/ccffd954c6a687f3b7b54a60bd6a12f5/raw");
            json_urls.Add("https://pastebin.com/raw/iA8qrGkG");
            //json_urls.Add("https://gitlab.com/snippets/1922258/raw?line_ending=raw");


            //statusBox.Text = "Waiting for command";
            string json    = "";
            bool   success = false;

            foreach (string json_url in json_urls)
            {
                try
                {
                    using (var wc = new WebClient())
                        json = wc.DownloadString(json_url);
                    success = true;
                    break;
                }
                catch
                {
                    //MessageBox.Show("Check your internet connection! (cant load json)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    deserializedRoot = null;
                }
            }
            if (!success)
            {
                uc = new siege_wpf.controls.UserControl1();
                content1.Content = uc;
                DockColors("Error");
                showErr = true;
                return;
            }
            else
            {
                deserializedRoot = JsonConvert.DeserializeObject <root_obj>(json);
                uc = new siege_wpf.controls.UserControl1();
                content1.Content = uc;
            }
            //textBox1.Text = json;
            //textBox1.Text = "Got JSON from webserver";
            //AppendTextBox1("Successfully connected to webserver", 1);


            //textBox2.Text = deserializedRoot.ver;

            //langCombo.SelectedItem = deserializedRoot.main_arr[0].lang;
            //outdated = new file_url[deserializedRoot.main_arr[langCombo.SelectedIndex].arr.Length];
            //cpbLabel.Content = 0 + "/" + deserializedRoot.main_arr[langCombo.SelectedIndex].arr.Length;
        }
Ejemplo n.º 4
0
        private async Task <bool> CheckFiles(CancellationToken ct)  //private bool CheckFiles(object param)
        {
            checkSem.WaitOne();

            AppendStatusBox("calculating hash", 1);

            ChangeStatusEllipse("#FFEE1E1E", 1);
            ChangeStatusEllipse("#FF696969", 0);

            //AppendTextBox3("", 1);

            //currWnd.cpb.Value = 0;
            cpbEditValue(0, 1);

            if (deserializedRoot == null)
            {
                string json    = "";
                bool   success = false;
                foreach (string json_url in mainForm.json_urls)
                {
                    try
                    {
                        using (var wc = new WebClient())
                            json = wc.DownloadString(json_url);
                        success = true;
                        break;
                    }
                    catch
                    {
                        //MessageBox.Show("Check your internet connection! (cant load json)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        deserializedRoot = null;
                    }
                }
                if (!success)
                {
                    Application.Current.Dispatcher.Invoke((Action)async delegate {
                        DockColors("Error");
                        await ShowDialogHost("Error while fetching .json\nCheck your connection!");
                    });
                    showErr          = true;
                    deserializedRoot = null;
                    return(false);
                }

                //currWnd.textBox1.Text = "Got JSON from webserver";
                //AppendTextBox1("Got JSON from webserver", 1);
                AppendTextBox1("Successfully connected to webserver", 1);
                Application.Current.Dispatcher.Invoke((Action)async delegate {
                    var myMessageQueue        = new SnackbarMessageQueue(TimeSpan.FromMilliseconds(2000));
                    SnackbarMain.MessageQueue = myMessageQueue;
                    SnackbarMain.Opacity      = 0.85;
                    var snackQueue            = SnackbarMain.MessageQueue;
                    var snackMessage          = SnackbarMain.Message;

                    // await Task.Factory.StartNew(() => snackQueue.Enqueue(".json packages has been loaded successfully!", "🙂", () => HandleUndoMethod()));
                });
                deserializedRoot = JsonConvert.DeserializeObject <root_obj>(json);

                //currWnd.textBox2.Text = deserializedRoot.ver;
                AppendTextBox2(deserializedRoot.ver, 1);
                clearLangCombo();
                //currWnd.langCombo.Items.Clear();
                foreach (ver_urls a in deserializedRoot.main_arr)
                {
                    //currWnd.langCombo.Items.Add(a.lang);
                    AppendLangCombo(a.lang);
                }
                defaultIdLangCombo(deserializedRoot.main_arr[0].lang);
                //currWnd.langCombo.SelectedItem = deserializedRoot.main_arr[0].lang;
                selected_item = 0;
                //cpbLabel.Content = 0 + "/" + deserializedRoot.main_arr[langCombo.SelectedIndex].arr.Length;
                cpbEditLabel(0 + "/" + deserializedRoot.main_arr[selected_item].arr.Length, 1);
                //outdated = new file_url[deserializedRoot.main_arr[sele].arr.Length];
            }

            if (root_dir == "")
            {
                //MessageBox.Show("Please, enter folder", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Dispatcher.Invoke((Action)async delegate {
                    DockColors("Warning");

                    await ShowDialogHost("Please enter the folder");
                });
                showWarn = true;
                showErr  = false;
                showUpd  = false;

                return(false);
            }
            if (File.Exists(root_dir + "RainbowSix.exe") && deserializedRoot.gameExeHash != null)
            {
                string loc_hash;// = SHA256CheckSum(filename);
                using (var stream = System.IO.File.OpenRead(root_dir + "RainbowSix.exe"))
                {
                    loc_hash = await GetHashAsync <SHA256CryptoServiceProvider>(stream, ct);
                }
                if (loc_hash != deserializedRoot.gameExeHash)
                {
                    waitHandle.Reset();
                    waitingForHandle = true;
                    showErr          = true;
                    Application.Current.Dispatcher.Invoke((Action)async delegate {
                        DockColors("Error");

                        await ShowDialogHost2Buttons("Game executable doesn't match with the current version. Check if your game has been updated. Continue?");
                    });
                    waitHandle.WaitOne();
                    waitingForHandle = false;
                    if (!dialogClose_atom)
                    {
                        return(false);
                    }
                }
            }
            else if (!File.Exists(root_dir + "RainbowSix.exe"))
            {
                waitHandle.Reset();
                waitingForHandle = true;
                showWarn         = true;
                Application.Current.Dispatcher.Invoke((Action)async delegate {
                    DockColors("Warning");

                    await ShowDialogHost2Buttons_WrongFolder("");
                });
                waitHandle.WaitOne();
                waitingForHandle = false;
                if (!dialogClose_atom)
                {
                    return(false);
                }
            }
            if (showErr || showWarn || showUpd)
            {
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    DockColors("Normal");
                });
                showErr  = false;
                showWarn = false;
                showUpd  = false;
            }

            outdated = new file_url[deserializedRoot.main_arr[selected_item].arr.Length];
            int index   = 0;
            int fine    = 0;
            int arr_len = deserializedRoot.main_arr[selected_item].arr.Length;

            //currWnd.checkLabel.Content = fine + "/" + arr_len.ToString();
            cpbEditLabel(fine + "/" + arr_len.ToString(), 1);
            if (!Directory.Exists(root_dir))
            {
                //currWnd.textBox1.Text = "Need to download All Shit! Current dir does not exists. Num of files to download:  " + arr_len;
                AppendTextBox1("Need to download all the shit! Current /dir/ does not exists. Number of files to download:  " + deserializedRoot.main_arr[selected_item].arr.Length, 1);
                outdated = deserializedRoot.main_arr[selected_item].arr;
                index    = arr_len;
            }
            else
            {
                //currWnd.textBox1.Text = "";
                AppendTextBox1("", 1);

                int last_index = 0;
                foreach (file_url a in deserializedRoot.main_arr[selected_item].arr)
                {
                    last_index = (a.name).LastIndexOf("\\");
                    if (last_index < 0)
                    {
                        last_index = -1;
                    }
                    string dir_check = root_dir + (a.name).Substring(0, last_index + 1);
                    string filename  = root_dir + a.name;
                    if (!Directory.Exists(dir_check))
                    {
                        //currWnd.textBox1.Text += "File: " + filename + " was not found!\n";
                        AppendTextBox1("File: " + a.name + " was not found!\n");
                        outdated[index] = a;
                        index++;
                        continue;
                    }
                    else if (!File.Exists(filename))
                    {
                        //currWnd.textBox1.Text +="File: " + filename + " was not found!\n";
                        AppendTextBox1("File: " + a.name + " was not found!\n");
                        outdated[index] = a;
                        index++;
                        continue;
                    }
                    else if (new FileInfo(filename).Length != a.bytes)
                    {
                        //currWnd.textBox1.Text += "File: " + filename + " is outdated!\nHis size: " + new FileInfo(filename).Length + " needs to be: " + a.bytes;
                        AppendTextBox1("File: " + a.name + " is outdated!\nIts size: " + new FileInfo(filename).Length + " Expected size: " + a.bytes + "\n");
                        outdated[index] = a;
                        index++;
                        continue;
                    }
                    string loc_hash;// = SHA256CheckSum(filename);
                    using (var stream = System.IO.File.OpenRead(filename))
                    {
                        loc_hash = await GetHashAsync <SHA256CryptoServiceProvider>(stream, ct);
                    }
                    if (loc_hash == "")
                    {
                        return(false);
                    }
                    if (loc_hash != a.hash)
                    {
                        //currWnd.textBox1.Text += "File: " + filename + " is outdated!\n";
                        //currWnd.textBox1.Text += "File Hash:\t" + loc_hash + "\t!=\t" + a.hash;
                        //AppendTextBox1("File: " + filename + " is outdated!\nFile Hash:\t" + loc_hash + "\t!=\t" + a.hash);
                        AppendTextBox1("File: " + a.name + " is outdated!\nChecksum doesn't match!\n");
                        outdated[index] = a;
                        index++;
                        continue;
                    }
                    else
                    {
                        //currWnd.checkLabel.Content = (++fine) + "/" + arr_len;
                        //cpb.Value += 100 / arr_len;
                        AppendTextBox1("File: " + a.name + " is OK!\n");
                        cpbEditLabel((++fine) + "/" + arr_len, 1);
                        cpbEditValue((100 * fine) / arr_len, 1);
                    }
                }
            }
            if (outdated[0] == null)
            {
                //currWnd.textBox1.Text = "All files up-to-dated!";
                AppendTextBox1("All files are up-to-date!\n\n", 1);
                showUpd = true;
            }
            else
            {
                AppendTextBox1("-----------------\n\nTOTAL FILES TO UPDATE: " + index.ToString());
                //currWnd.textBox1.Text += "\n\nTOTAL FILES TO UPDATE: " + index.ToString();
            }
            return(true);
        }