IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Système de récupération de zip ( MàJ Automatique )


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Juillet 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3
    Par défaut Système de récupération de zip ( MàJ Automatique )
    J'ai crée un updater avec un système de Mise à jour donc avec lecture de plusieurs fichiers txt ( ftp - client ) pour récupérer les archives des Mises à jours. L'updater se lance bien, les fonctions marchent parfaitement, si l'updater est à jour, il renvoie vers un jeu. Seul problème lorsque je change la version pour indiquer qu'une mise à jour est à effectuer, l'updater s'ouvre puis se ferme sans me laisser le temps de voir la "possible" erreur pourtant je ne crois pas avoir fais de fautes dans le code source.

    Voilà le code source pour récupérer les fichiers txt :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
     private List<Version> GetVersions()
            {
                var dico = new List<Version>();
     
                myWebClient.DownloadFile(Settings.Configuration.LinkDownload + "versions.txt", "./UpLauncher/versions.txt");
     
                var LauncherReader = new System.IO.StreamReader("./UpLauncher/versions.txt", Encoding.Default);
     
                while (!LauncherReader.EndOfStream)
                {
                    var line = LauncherReader.ReadLine();
     
                    if (line.Contains(">"))
                        dico.Add(new Version()
                        {
                            ID = int.Parse(line.Split('>')[0].Trim()),
                            ActualVersion = line.Split('>')[1].Trim(),
                            Description = line.Split('>')[2].Trim(),
                        });
                }
     
                LauncherReader.Close();
     
                System.IO.File.Delete("./UpLauncher/versions.txt");
     
                return dico;
            }
            private void Initialize()
            {
                if (System.IO.File.Exists("./UpLauncher/configuration.conf"))
                {
                    var reader = new StreamReader("./UpLauncher/configuration.conf", Encoding.Default);
     
                    Settings.Configuration.LinkDofus = reader.ReadLine().Split('=')[1];
                    myVersion.ActualVersion = reader.ReadLine().Split('=')[1];
     
                    reader.Close();
                }
                else
                {
                    AddToLog("Fichier de configuration inexistant ou corrompu, remise à zéro.", true, true);
     
                    var writer = new StreamWriter("./UpLauncher/configuration.conf", false, Encoding.Default);
                    writer.AutoFlush = true;
     
                    writer.WriteLine(@"LinkDofus=.\Dofus.exe");
                    writer.WriteLine(@"VersionDofus=1.0.0");
                    writer.WriteLine(@"LinkDownload=http://127.0.0.1/download/");
     
                    writer.Close();
     
                    Settings.Configuration.LinkDofus = @".\Dofus.exe";
                    Settings.Configuration.LinkDownload = @"http://127.0.0.1/download/";
     
                    myVersion.ActualVersion = "1.0.0";
                }
     
                AddToLog("Version de l'UpLauncher : " + Settings.Configuration.LauncherVersion + " !", true);
                AddToLog("Version de l'application DOFUS : " + myVersion.ActualVersion + " !", true);
            }
            private bool VerifVersion(ref string game)
            {
                if (!System.IO.Directory.Exists("./UpLauncher"))
                    System.IO.Directory.CreateDirectory("./UpLauncher");
     
                var LauncherVersion = myWebClient.DownloadString(Settings.Configuration.LinkDownload + "launcher.txt");
     
                if (LauncherVersion != Settings.Configuration.LauncherVersion)
                {
                    var result = MessageBox.Show("Une nouvelle version de l'UpLauncher est disponible, nous allons vous rediriger sur le site pour que vous puissez vous mettre à jour vers la version '" + LauncherVersion + "' !", "Nouvelle version disponible !", MessageBoxButton.OK);
     
                    if (result == MessageBoxResult.OK)
                        System.Diagnostics.Process.Start(Settings.Configuration.LinkSite);
     
                    Environment.Exit(0);
                }
     
                game = myWebClient.DownloadString(Settings.Configuration.LinkDownload + "client.txt");
     
                AddToLog("Dernière version détectée : " + game + " !", true);
     
                return new Version() { ActualVersion = game }.IsBigger(myVersion);
            }
            private void StartUpdate(Version VersionToDownload)
            {
                this.progress.Dispatcher.Invoke(
                System.Windows.Threading.DispatcherPriority.Normal,
                new Action(
                delegate()
                {
                    progress.IsIndeterminate = false;
                    progress.Value = 0;
                }));
     
                AddToLog("Téléchargement de la version [" + VersionToDownload.ActualVersion + "] (" + VersionToDownload.Description + ") ...", false);
     
                myWebClient.DownloadFileAsync(new Uri(Settings.Configuration.LinkDownload + "updates/" + VersionToDownload.ActualVersion + ".zip"), "./UpLauncher/" + VersionToDownload.ActualVersion + ".zip");
     
                myWebClient.DownloadProgressChanged += (s, e) =>
                {
                    this.progress.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                    delegate()
                    {
                        progress.Value = e.ProgressPercentage;
                    }));
                };
     
                myWebClient.DownloadFileCompleted += (s, e) =>
                {
                    StartUnpressUpdate(VersionToDownload);
                };
            }
            private void ChangeProgressEnabled(bool ena)
            {
                this.progress.Dispatcher.Invoke(
                System.Windows.Threading.DispatcherPriority.Normal,
                new Action(
                delegate()
                {
                    if (ena == true)
                        progress.Visibility = System.Windows.Visibility.Visible;
                    else
                        progress.Visibility = System.Windows.Visibility.Hidden;
                }));
            }
            private void StartUnpressUpdate(Version VersionToDownload)
            {
                this.progress.Dispatcher.Invoke(
                System.Windows.Threading.DispatcherPriority.Normal,
                new Action(
                delegate()
                {
                    progress.IsIndeterminate = true;
                    progress.Value = 0;
                }));
     
                AddToLog("Décompression de la version [" + VersionToDownload.ActualVersion + "] (" + VersionToDownload.Description + ") ...", false);
     
                try
                {
                    ZipInputStream zis = null;
                    FileStream fos = null;
     
                    zis = new ZipInputStream(new FileStream("./UpLauncher/" + VersionToDownload.ActualVersion + ".zip", FileMode.Open, FileAccess.Read));
                    ZipEntry ze;
     
                    while ((ze = zis.GetNextEntry()) != null)
                    {
                        if (ze.IsDirectory)
                            Directory.CreateDirectory(@".\Game\\" + ze.Name);
                        else
                        {
                            if (!Directory.Exists(@".\Game\\" + System.IO.Path.GetDirectoryName(ze.Name)))
                                Directory.CreateDirectory(@".\Game\\" + System.IO.Path.GetDirectoryName(ze.Name));
     
                            fos = new FileStream(@".\Game\\" + ze.Name, FileMode.Create, FileAccess.Write);
     
                            int count;
                            byte[] buffer = new byte[4096];
     
                            while ((count = zis.Read(buffer, 0, 4096)) > 0)
                                fos.Write(buffer, 0, count);
                        }
                    }
     
                    if (zis != null)
                        zis.Close();
     
                    if (fos != null)
                        fos.Close();
     
                    if (File.Exists("./UpLauncher/" + VersionToDownload.ActualVersion + ".zip"))
                        System.IO.File.Delete("./UpLauncher/" + VersionToDownload.ActualVersion + ".zip");
                }
                catch
                {
                    AddToLog("Erreur lors de la décompression  !", true, true);
                    return;
                }
     
                AddToLog("Mise à jour [" + VersionToDownload.ActualVersion + "] (" + VersionToDownload.Description + ") installée !", true);
                myVersion.ActualVersion = VersionToDownload.ActualVersion;
     
                Settings.Configuration.SaveConf(myVersion.ActualVersion);
     
                if (VerifVersion(ref gameVersion))
                {
                    AddToLog("Version à jour !", true, true);
     
                    ChangePlayEnabled(true);
                    ChangeProgressEnabled(false);
     
                    myWebClient.Dispose();
     
                    foreach (var file in Directory.GetFiles("./UpLauncher/"))
                    {
                        if (file.Split('/')[file.Split('/').Length - 1] == "configuration.conf")
                            continue;
     
                        File.Delete(file);
                    }
                }
                else
                {
                    Versions.Remove(VersionToDownload);
     
                    myWebClient = new WebClient();
                    myWebClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);
                    myWebClient.Headers.Add("Cache-Control", "no-cache");
     
                    StartUpdate(Versions.Where(x => !x.IsBigger(myVersion)).OrderBy(x => x.ID).ToArray()[0]);
                }
            }
    Merci de m'aider

  2. #2
    Membre à l'essai
    Homme Profil pro
    Lycéen
    Inscrit en
    Juillet 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3
    Par défaut
    Résolu, erreur de version dans l'updater.

Discussions similaires

  1. Réponses: 1
    Dernier message: 22/06/2007, 16h48
  2. récupération des clés générées automatiquement
    Par giannichedda dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 07/05/2007, 14h52
  3. [Excel] Récupération d'un filtre automatique dans une cellule
    Par billy123 dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 01/03/2007, 16h32
  4. Réponses: 10
    Dernier message: 02/08/2006, 16h32
  5. Réponses: 9
    Dernier message: 21/06/2006, 17h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo