コード例 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (File.Exists("version.txt"))
            {
                string[]       lines = System.IO.File.ReadAllLines("version.txt");
                ConnectServeur s     = new ConnectServeur();
                try {
                    reponse = s.connect(ipAddresseServeur, 6000, "L " + lines[0]);
                    //envoie ligne 0 launcher, ligne 1 jeu
                    if (reponse != "ok")
                    {
                        backgroundWorker1                       = new BackgroundWorker();
                        backgroundWorker1.DoWork               += new DoWorkEventHandler(backgroundWorker1_workUpdate);
                        backgroundWorker1.RunWorkerCompleted   += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompletedUpdate);
                        backgroundWorker1.ProgressChanged      += new ProgressChangedEventHandler(backgroundWorker1_change);
                        backgroundWorker1.WorkerReportsProgress = true;

                        backgroundWorker1.RunWorkerAsync();
                    }
                    else
                    {
                        this.start();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("une erreur c'est produite erreur 422" + ex.Message);
                }
            }
            else
            {
                ConnectServeur s = new ConnectServeur();
                reponse = s.connect(ipAddresseServeur, 6000, "L 0.0.0.0.0.0");
                if (reponse != "-1")
                {
                    // recuperer l'emplacement
                    backgroundWorker1.DoWork               += new DoWorkEventHandler(backgroundWorker1_work);
                    backgroundWorker1.RunWorkerCompleted   += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
                    backgroundWorker1.ProgressChanged      += new ProgressChangedEventHandler(backgroundWorker1_change);
                    backgroundWorker1.WorkerReportsProgress = true;

                    backgroundWorker1.RunWorkerAsync();
                }
                else
                {
                    MessageBox.Show("Serveur Non dipsognible");
                }
            }
        }
コード例 #2
0
        private void backgroundWorker1_RunWorkerCompletedUpdate(object sender, RunWorkerCompletedEventArgs e)
        {
            // First, handle the case where an exception was thrown.
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }

            else
            {
                if (reponse != "ok" && reponse != "-1")
                {
                    string version = reponse.Split(' ')[1];
                    ZipFile.ExtractToDirectory(@"update.zip", @".\patch");

                    miseAJour("patch\\updateLauncherJeu.json", version, reponse.Split(' ')[0]);

                    //
                    //ecrire la nouvelle version

                    File.Delete("updateJeu.json");
                    FileStream ver = new FileStream("version.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    ver.Write(System.Text.Encoding.UTF8.GetBytes(version), 0, System.Text.Encoding.UTF8.GetBytes(version).Length);
                    ver.Close();


                    while (backgroundWorker1.IsBusy)
                    {
                        Thread.Sleep(1000);
                    }
                    ConnectServeur s = new ConnectServeur();
                    try
                    {
                        string[] lines = System.IO.File.ReadAllLines("version.txt");
                        reponse = s.connect(ipAddresseServeur, 6000, "L " + version);
                        //envoie ligne 0 launcher, ligne 1 jeu
                        if (reponse != "ok")
                        {
                            backgroundWorker1.DoWork               += new DoWorkEventHandler(backgroundWorker1_workUpdate);
                            backgroundWorker1.RunWorkerCompleted   += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompletedUpdate);
                            backgroundWorker1.ProgressChanged      += new ProgressChangedEventHandler(backgroundWorker1_change);
                            backgroundWorker1.WorkerReportsProgress = true;

                            backgroundWorker1.RunWorkerAsync();
                        }

                        else
                        {
                            this.start();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("une erreur c'est produite erreur 42" + ex.Message);
                    }
                }
                else if (reponse == "-1")
                {
                    MessageBox.Show("problème de connexion!");
                }
            }

            // Enable the UpDown control.
        }