Ejemplo n.º 1
0
 /// <summary>
 /// Ajoute le jeu passé en paramètres au fichier Jeux.xml
 /// </summary>
 /// <param name="g">Le jeu à ajouter</param>
 private void WriteGame(Game g)
 {
     try
     {
         using (FileStream fs = new FileStream(Path.Combine(executableDirectory.Substring(6), "Jeux.xml"), FileMode.Open))
         {
             MoveAfter(fs, "</Jeux>");
             fs.Seek(-7, SeekOrigin.Current);
             AddText(fs, "\t<Jeu>\n");
             AddText(fs, "\t\t<Nom>" + g.Name + "</Nom>\n");
             AddText(fs, "\t\t<Icone>" + g.RealIcon + "</Icone>\n");
             AddText(fs, "\t\t<Executable>" + g.Executable + "</Executable>\n");
             AddText(fs, "\t\t<Description>" + g.Description + "</Description>\n");
             AddText(fs, "\t\t<Version>" + g.Version.ToString() + "</Version>\n");
             AddText(fs, "\t</Jeu>\n");
             AddText(fs, "</Jeux>");
             fs.Close();
         }
     }
     catch (Exception sarlon)
     {
         MessageBox.Show("Le fichier de configuration Jeux.xml est inaccessible.\nVos changements ne seront pas pris en compte au prochain démarrage.\n" + sarlon.Message, "Fichier manquant", MessageBoxButtons.OK);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Teste si deux jeux sont identiques (même version, description, nom et executable)
 /// </summary>
 /// <param name="g">Le jeu à tester</param>
 /// <returns>true ou false selon les membres des jeux</returns>
 public bool Equals(Game g)
 {
     return g.Version == Version &&
         g.Description == Description &&
         g.Name == Name &&
         g.Executable == Executable;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Lancement du jeu
        /// </summary>
        /// <param name="g">Jeux à lancer</param>
        private void LaunchGame(Game g)
        {
            if (Game.IsPlayable(g))
            {
                if (g.Install == InstallState.UpdateAvailable)
                {
                    DialogResult update = MessageBox.Show("Une mise à jour est disponible pour ce jeu.\nVoulez-vous l'installer ?", "Mise à jour disponible", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    if (update == DialogResult.Yes)
                    {
                        foreach (ListViewItem lvi in listView1.Items)
                        {
                            if (((Game)lvi.Tag).Executable == g.Executable)
                            {
                                foreach (Game rg in remoteGames)
                                {
                                    if (rg.Executable == g.Executable)
                                    {
                                        g = rg;
                                        Console.WriteLine(rg.Description);
                                        lvi.Tag = g;
                                    }
                                }
                            }
                        }
                        try
                        {
                            WebClient client = new WebClient();
                            client.DownloadFile(new Uri("http://g2iut.alwaysdata.net/games/" + g.Executable + ".gzip"), Path.Combine(temporaryPath, g.Executable));
                            g.Install = InstallState.Installing;
                            ZipHandler.DecompressToDirectory(Path.Combine(temporaryPath, g.Executable), Path.Combine(executableDirectory.Substring(6), "games", g.Executable));
                            if (File.Exists(Path.Combine(executableDirectory.Substring(6), g.Icon)))
                                File.Delete(Path.Combine(executableDirectory.Substring(6), g.Icon));
                            File.Copy(temporaryPath + g.Icon.Substring(g.Icon.IndexOf("\\")), Path.Combine(executableDirectory.Substring(6), g.Icon));
                            g.Install = InstallState.UpToDate;

                            try
                            {
                                using (FileStream fs = new FileStream(Path.Combine(executableDirectory.Substring(6), "Jeux.xml"), FileMode.Open))
                                {
                                    fs.Seek(0, SeekOrigin.Begin);
                                    MoveAfter(fs, g.Executable);
                                    if (fs.Position > 100)
                                    {
                                        fs.Seek(-100, SeekOrigin.Current);
                                        MoveAfter(fs, "</Jeu>");
                                    }
                                    else
                                    {
                                        fs.Seek(0, SeekOrigin.Begin);
                                        MoveAfter(fs, "<Jeux>");
                                    }
                                    long position = fs.Position;
                                    MoveAfter(fs, "</Jeu>");
                                    byte[] array = new byte[fs.Length - fs.Position];
                                    fs.Read(array, 0, (int)(fs.Length - fs.Position));
                                    fs.Seek(position, SeekOrigin.Begin);
                                    fs.Write(array, 0, array.Length);
                                    while (fs.Position < fs.Length)
                                        fs.WriteByte((byte)' ');
                                    fs.Close();
                                }
                                WriteGame(g);
                            }
                            catch(Exception sarlon)
                            {
                                MessageBox.Show("Le fichier de configuration Jeux.xml est inaccessible.\nVos changements ne seront pas pris en compte au prochain démarrage.", "Fichier manquant", MessageBoxButtons.OK);
                            }
                        }
                        catch (Exception sarlon)
                        {
                            string msg = "";
            #if DEBUG
                            msg = sarlon.Message;
            #endif
                            MessageBox.Show("Impossible de contacter le serveur " + msg, "Erreur lors de la récupération", MessageBoxButtons.OK);
                        }
                    }
                    else if (update == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                System.Diagnostics.ProcessStartInfo myInfo = new System.Diagnostics.ProcessStartInfo();
                myInfo.FileName = g.BaseName;
                myInfo.WorkingDirectory = Path.Combine("games", g.PathName);
                System.Diagnostics.Process.Start(myInfo);
            }
            else if (g.Install == InstallState.Installing)
            {
                MessageBox.Show("Veuillez patienter, l'installation est en cours...", "Installation en cours...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                /*
                DialogResult reload = MessageBox.Show("Veuillez patienter, le téléchargement est en cours...\nVoulez-vous annuler le téléchargement en cours et le relancer ?", "Téléchargement en cours...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (reload == DialogResult.Yes)
                {
                    // TODO : Annuler le téléchargement et le recommencer
                }*/
            }
            else
            {
                DialogResult install = MessageBox.Show("Ce jeu n'est pas installé. Voulez-vous le télecharger et l'installer ?", "Jeu non-installé", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (install == DialogResult.Yes)
                {
                    // TODO : Téléchargement Asynchrone, avec barre de progression
                    // pour ne pas bloquer la plateforme
                    try
                    {
                        WebClient client = new WebClient();
                        client.DownloadFile(new Uri("http://g2iut.alwaysdata.net/games/" + g.Executable + ".gzip"), Path.Combine(temporaryPath, g.Executable));
                        g.Install = InstallState.Installing;
                        ZipHandler.DecompressToDirectory(Path.Combine(temporaryPath, g.Executable), Path.Combine(executableDirectory.Substring(6), "games", g.Executable));
                        g.Install = InstallState.Installed;
                        if (File.Exists(Path.Combine(executableDirectory.Substring(6), g.Icon)))
                            File.Delete(Path.Combine(executableDirectory.Substring(6), g.Icon));
                        File.Copy(temporaryPath + g.Icon.Substring(g.Icon.LastIndexOf("\\")), Path.Combine(executableDirectory.Substring(6), g.Icon));
                        WriteGame(g);
                    }
                    catch (Exception sarlon)
                    {
                        string msg = "";
            #if DEBUG
                        msg = sarlon.Message;
            #endif
                        MessageBox.Show("Impossible de contacter le serveur " + msg, "Erreur lors de la récupération", MessageBoxButtons.OK);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Indique si le jeu peut être lancé
 /// </summary>
 /// <param name="g">Le jeu à tester</param>
 /// <returns>true ou false selon l'état d'installation du jeu</returns>
 public static bool IsPlayable(Game g)
 {
     return g.Install == InstallState.Installed || g.Install == InstallState.UpdateAvailable || g.Install == InstallState.UpToDate;
 }