示例#1
0
        private void RunNextUpdate()
        {
            // Vider le dossier update (même si ça aurait déjà dû être fait, permet d'éviter les problèmes en cas de récupération après crash)
            try
            {
                DirectoryInfo di = new DirectoryInfo(_installPath + "\\Update");
                FormInstall.SetAttributesNormal(di);
                di.Delete(true);
                Directory.CreateDirectory(_installPath + "\\Update");
            }
            catch (Exception)
            {
                _etat = Etat.EnErreur;
                MessageBox.Show("Problème d'accès au dossier de mise à jour :-(",
                                "Serious error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                return;
            }

            // Terminer si nécessaire
            if (_updateListeUtile.Count() <= 0)
            {
                Terminate();
                return;
            }

            // Prendre le prochain
            labelSubtitle.Visible = false;
            labelPoint1.Visible   = false;
            labelPoint2.Visible   = false;
            labelPoint3.Visible   = false;
            labelPoint4.Visible   = false;
            labelPoint5.Visible   = false;
            _currentUpdate        = _updateListeUtile.First();
            _updateListeUtile.Remove(_currentUpdate);
            labelSubtitle.Text    = string.Format("Mise à jour version {0}.{1} => {2}.{3}", _localVersion.Major, _localVersion.Minor, _currentUpdate.Version.Major, _currentUpdate.Version.Minor);
            labelSubtitle.Visible = true;
            _updateiterator++;

            // Télécharger la mise à jour
            labelPoint1.Visible = true;
            using (WebClient wc = new WebClient())
            {
                wc.DownloadProgressChanged += wc_DownloadProgressChanged;
                wc.DownloadFileCompleted   += Wc_DownloadFileCompleted;
                wc.DownloadFileAsync(new System.Uri(UPDATE_SERVICE_URL + "/Updates/" + _currentUpdate.Filename), _installPath + "\\Update\\" + _currentUpdate.Filename);
            }
        }
示例#2
0
        private void Wc_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            // Erreur
            if (e.Error != null)
            {
                Terminate(true);
                return;
            }

            // Suppression des fichiers obsolètes
            labelPoint2.Visible = true;
            foreach (string folderPath in _currentUpdate.Delete.Folders)
            {
                string fullPath = _installPath + "\\" + folderPath;
                if (Directory.Exists(fullPath))
                {
                    try
                    {
                        DirectoryInfo di = new DirectoryInfo(fullPath);
                        FormInstall.SetAttributesNormal(di);
                        di.Delete(true);
                    }
                    catch (Exception)
                    {
                        _etat = Etat.EnErreur;
                        MessageBox.Show("Impossible de supprimer le dossier. L'installation est corrompue, veuillez réinstaller :-(", "Serious error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                        return;
                    }
                }
            }
            foreach (string filePath in _currentUpdate.Delete.Files)
            {
                string fullPath = _installPath + "\\" + filePath;
                if (File.Exists(fullPath))
                {
                    try
                    {
                        File.Delete(fullPath);
                    }
                    catch (Exception)
                    {
                        _etat = Etat.EnErreur;
                        MessageBox.Show("Impossible de supprimer le fichier. L'installation est corrompue, veuillez réinstaller :-(", "Serious error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                        return;
                    }
                }
            }

            // Mettre à jour la progress bar
            // Créer un thread pour éviter les problèmes UI
            DirectoryInfo di2 = new DirectoryInfo(_installPath);

            _sizeBefore = FormInstall.DirSize(di2);
            Task.Factory.StartNew(() =>
            {
                // On attend la fin de la décompression
                while (_etat != Etat.Suivant && _etat != Etat.EnErreur)
                {
                    long actualSize = FormInstall.DirSize(di2) - _sizeBefore;
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            int partAcquise   = (1000 / _nbUpdates) * (_updateiterator - 1);
                            partAcquise      += 1000 / _nbUpdates / 2;
                            progressBar.Value = partAcquise + (Convert.ToInt32(Decimal.Divide(actualSize, _currentUpdate.Size) * 1000) / 2 / _nbUpdates);
                        }
                        catch (Exception)
                        {
                            // Semble imporbable mais en cas de problème ne pas planter le programme pour une question de progressBar
                        }
                    }, CancellationToken.None, TaskCreationOptions.None, _uiScheduler);
                    Thread.Sleep(200);
                }
            }).ContinueWith(antecedent =>
            {
                // Gestion des erreurs
                if (_etat == Etat.EnErreur)
                {
                    MessageBox.Show("Erreur lors de la décompression des fichiers. L'installation est corrompue, veuillez réinstaller :-(", "Serious error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                }
                else
                {
                    // On passe à la suite
                    _etat = Etat.EnCours;

                    // Mise à jour du registre
                    labelPoint4.Visible = true;
                    RegistryKey keyUge  = Registry.LocalMachine.OpenSubKey("Software\\GeneralsUltimateExperience", true);
                    keyUge.SetValue("MajorVersion", _currentUpdate.Version.Major);
                    keyUge.SetValue("MinorVersion", _currentUpdate.Version.Minor);

                    // Vider le dossier update
                    try
                    {
                        DirectoryInfo di = new DirectoryInfo(_installPath + "\\Update");
                        FormInstall.SetAttributesNormal(di);
                        di.Delete(true);
                        Directory.CreateDirectory(_installPath + "\\Update");
                    }
                    catch (Exception)
                    {
                        _etat = Etat.EnErreur;
                        MessageBox.Show("Problème d'accès au dossier de mise à jour. L'installation est corrompue, veuillez réinstaller :-(",
                                        "Serious error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                    }

                    if (_etat != Etat.EnErreur)
                    {
                        // Revenir au répertoire courant de l'exécutable (pour pouvoir permettre suppression si nécessaire)
                        Directory.SetCurrentDirectory(_executingPath);

                        // Lancer la prochaine update
                        RunNextUpdate();
                    }
                }
            }, _uiScheduler);

            // Décompression des nouveaux fichiers
            labelPoint3.Visible         = true;
            _process                    = new Process();
            _process.StartInfo.FileName = _installPath + "\\Update\\" + _currentUpdate.Filename;
            _process.StartInfo.Verb     = "runas";
            Directory.SetCurrentDirectory(_installPath);
            _process.EnableRaisingEvents = true;
            _process.Exited += Process_Exited;
            _process.Start();
        }
示例#3
0
        private void buttonUninstall_Click(object sender, EventArgs e)
        {
            // Initialisation
            _running = true;
            string installPath = null;

            labelPoint1.Visible     = true;
            buttonCancel.Enabled    = false;
            buttonUninstall.Enabled = false;
            checkBoxDeleteDocumentFolder.Enabled = false;
            string zeroHourDataLeaf = null;

            // Suppression des entrées du registre
            RegistryKey keySoftware = Registry.LocalMachine.OpenSubKey("Software", true);

            RegistryKey keyEaGames = keySoftware.OpenSubKey("EA Games", true);

            if (keyEaGames != null && keyEaGames.OpenSubKey("Command and Conquer Generals Zero Hour") != null)
            {
                keyEaGames.DeleteSubKeyTree("Command and Conquer Generals Zero Hour");
            }
            if (keyEaGames.ValueCount == 0 && keyEaGames.SubKeyCount == 0)
            {
                keySoftware.DeleteSubKeyTree("EA Games");
            }

            RegistryKey keyElectronicArts = keySoftware.OpenSubKey("Electronic Arts", true);

            if (keyElectronicArts != null)
            {
                RegistryKey keyElectronicArtsEaGames = keyElectronicArts.OpenSubKey("EA GAMES", true);
                if (keyElectronicArtsEaGames != null)
                {
                    if (keyElectronicArtsEaGames.GetValue("UserDataLeafName") != null)
                    {
                        zeroHourDataLeaf = keyElectronicArtsEaGames.GetValue("UserDataLeafName").ToString();
                    }
                    if (keyElectronicArtsEaGames.OpenSubKey("Command and Conquer Generals Zero Hour") != null)
                    {
                        keyElectronicArtsEaGames.DeleteSubKeyTree("Command and Conquer Generals Zero Hour");
                    }
                    if (keyElectronicArtsEaGames.OpenSubKey("Generals") != null)
                    {
                        keyElectronicArtsEaGames.DeleteSubKeyTree("Generals");
                    }
                    if (keyElectronicArtsEaGames.ValueCount == 0 && keyElectronicArtsEaGames.SubKeyCount == 0)
                    {
                        keyElectronicArts.DeleteSubKeyTree("EA GAMES");
                    }
                }
                if (keyElectronicArts.ValueCount == 0 && keyElectronicArts.SubKeyCount == 0)
                {
                    keySoftware.DeleteSubKeyTree("Electronic Arts");
                }
            }

            RegistryKey keyUge = keySoftware.OpenSubKey("GeneralsUltimateExperience");

            if (keyUge != null)
            {
                installPath = keyUge.GetValue("InstallPath").ToString();
                keySoftware.DeleteSubKeyTree("GeneralsUltimateExperience");
            }

            RegistryKey keyUninstall = Registry.LocalMachine.OpenSubKey(FormInstall.UNINSTALL_REG_KEY_PATH, true);

            if (keyUninstall != null)
            {
                keyUninstall.DeleteSubKeyTree(new Guid("f416dd93-d270-4bff-aa66-c1ce6bbf95a8").ToString("B"));
            }

            // Suppression des fichiers
            labelPoint2.Visible = true;
            if (installPath == null)
            {
                MessageBox.Show("Impossible de trouver le dossier d'installation, l'entrée dans le registre ayant été supprimée. Merci d'effacer les fichiers manuellement.", "Suppression des fichiers impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (!Directory.Exists(installPath))
                {
                    MessageBox.Show("Impossible de trouver le dossier d'installation. S'il a été déplacé veuillez effacer les fichiers manuellement.", "Suppression des fichiers impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    DirectoryInfo di = new DirectoryInfo(installPath);
                    FormInstall.SetAttributesNormal(di);
                    di.Delete(true);
                }
            }

            // Suppression du raccourci bureau
            string link = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + Path.DirectorySeparatorChar + "Generals Ultimate Experience.lnk";

            if (File.Exists(link))
            {
                File.Delete(link);
            }

            // Suppression du contenu document
            if (checkBoxDeleteDocumentFolder.Checked)
            {
                labelPoint3.Visible = true;
                string documentGeneralsPath = Environment.SpecialFolder.MyDocuments + "\\Command and Conquer Generals Data";
                string documentHeureHPath   = Environment.SpecialFolder.MyDocuments + "\\" + zeroHourDataLeaf;
                if (Directory.Exists(documentGeneralsPath))
                {
                    DirectoryInfo di = new DirectoryInfo(documentGeneralsPath);
                    FormInstall.SetAttributesNormal(di);
                    di.Delete(true);
                }
                if (Directory.Exists(documentHeureHPath))
                {
                    DirectoryInfo di = new DirectoryInfo(documentHeureHPath);
                    FormInstall.SetAttributesNormal(di);
                    di.Delete(true);
                }
            }

            // Fin
            _running            = false;
            labelPoint4.Visible = true;
            MessageBox.Show("Désinstallation terminée avec succès ! Au revoir.", "Fin", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Close();
        }