RunUO-FR
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
RunUO-FR

Forum de support pour RunUO en français.
 
AccueilAccueil  Dernières imagesDernières images  RechercherRechercher  S'enregistrerS'enregistrer  Connexion  
-50%
Le deal à ne pas rater :
-50% Baskets Nike Air Huarache Runner
69.99 € 139.99 €
Voir le deal

 

 Lanceur UO

Aller en bas 
AuteurMessage
Scriptiz

Scriptiz


Messages : 102
Date d'inscription : 02/09/2008
Localisation : Belgium

Lanceur UO Empty
MessageSujet: Lanceur UO   Lanceur UO Icon_minipostedVen 18 Sep - 17:02

Voici le projet :

- Un lanceur qui permettra de télécharger tous les fichiers nécessaires à l'utilisation de UO, de directement avoir les bons fichier (dernières versions) ainsi que les fichiers du serveurs (gumps, muls, maps, login.cfg, ...).
- Le joueur évite ainsi de faire des mauvaises mises à jours en lancant le patcher d'UO (due au version pas encore décrypter).
- Le joueur lance toujours le jeux via le lanceur, du coup si mise à jour il y a des gumps/muls/maps ou autre, elle sera automatiquement téléchargée.
- Gestion d'un pannel de news dans le lanceur pour avoir les dernières MAJ du serveur.

Concrètement la fonction de gestion des versions de fichiers est faite, il reste à gérer les différentes clés registres créées lors de l'installation d'UO, ainsi que le panel de news et je vous mettrais le code source.

Si vous avez des questions n'hésitez pas.

Plus d'infos et screenshots : http://uoclassic.free.fr/forum/viewtopic.php?f=9&t=837

Aperçu :
Lanceur UO Launcher2
Revenir en haut Aller en bas
http://uoclassic.free.fr/
Scriptiz

Scriptiz


Messages : 102
Date d'inscription : 02/09/2008
Localisation : Belgium

Lanceur UO Empty
MessageSujet: Re: Lanceur UO   Lanceur UO Icon_minipostedLun 21 Sep - 23:27

Voici déjà la première mouture, elle n'est pas propre, il me faut encore organiser le code, le commenter, mais j'ai fait tout ça rapidement l'autre soir puis j'ai juste rajouter les fonctions d'extractions d'archives 7zip (avec la librairie sevenZip que l'on peut trouver sur le net), ainsi que la méthode pour calculer la somme MD5 d'un fichier.

Je nettoierais tout ça plus tard et continuerais le développement car il reste beaucoup à faire.


PS : Je ne joint pas les fichiers d'interface ni de ressources pour l'instant, je ferais une grosse archive avec tout ça à la sortie de la version 1 qui sera opérationnelle.
PPS : Si vous voulez quand même déjà l'interface GUI, faites moi signe et je la posterai ici avant la monture finale.
PPPS : N'hésitez pas à apporter vos suggestions/corrections/commentaires/idée/... ça fait toujours plaisir Smile

Code:
/**
 * UoClassic Launcher
 * By Scriptiz for uoclassic.free.fr
 * First released on 17 september 2009
 * This code is released under GPL license.
 * License details : http://www.gnu.org/copyleft/gpl.html
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;                  // to use WebClient to download files
using System.IO;                    // to use StreamReader, FileStream, ...
using System.Threading;            // to use threads
using System.Reflection;            // to change properities of a thread while running another
using System.Diagnostics;          // to use processe's management
using System.Security.Cryptography; // to use MD5 crypto
using SevenZip;                    // to extract

namespace UOC_Launcher
{
    public partial class UOCLauncher : Form
    {
        // TODO verify version on a MD5 sum
        // TODO create an MD5 generator for the server
        // TODO implement try/catch block
        // TODO get administration rights under Vista/Seven
        // TODO automatically launch update
        // TODO clean the code (seperate functions, ...)
        // TODO first run : choose install dir and get base file (.7z archive)

        /*
        * Main steps :
        * 1) Get the base files (.7z)
        * 2) Add registry keys
        * 3) All files versions 1
        * 4) Verify other updates (md5 or versions?)
        * 5) Play
        */
        struct UOCFile
        {
            public string name;
            public int version;
        }

        private string uocVersion = "0.21";
        private string uocDate = "21 september 2009";
        private static string webServer = "http://scriptiz.no-ip.info/uoc_launcher/";
        private static string fileVersions = "versions.txt";
        private static WebClient client = new WebClient();
        private static bool isUpToDate = false;
        Thread t = null;
        string logs = "";

        public UOCLauncher()
        {
            InitializeComponent();
            uocTabs.SelectTab(1);
            uocPlay.Text = "&Update";
        }

        void UpdateUOC()
        {
            if (getVersions())
            {
                // Theses lists contains all the files
                List<UOCFile> serverFiles = new List<UOCFile>();
                List<UOCFile> localFiles = new List<UOCFile>();

                UOCFile addedFile = new UOCFile();

                using (StreamReader sr = new StreamReader("server_"+fileVersions))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        // Verify if this line isn't a comment
                        string first = line.Substring(0, 1);
                        if (first == "#")
                            continue;

                        // Get the delimiter position ( name + delimiter + version )
                        int delimiter = line.IndexOf('$');

                        // Verifiy if the line is correctly formatted, then parse the name and the version
                        if (delimiter != 0 && delimiter != line.Length)
                        {
                            addedFile.name = line.Substring(0, delimiter);
                            addedFile.version = Int32.Parse(line.Substring(delimiter + 1, (line.Length - delimiter - 1)));
                            serverFiles.Add(addedFile);
                        }
                    }
                }

                if (File.Exists("local_" + fileVersions))
                {
                    using (StreamReader sr = new StreamReader("local_" + fileVersions))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            int delimiter = line.IndexOf('$');

                            if (delimiter != 0)
                            {
                                addedFile.name = line.Substring(0, delimiter);
                                addedFile.version = Int32.Parse(line.Substring(delimiter + 1, (line.Length - delimiter - 1)));
                                localFiles.Add(addedFile);
                            }
                        }
                    }
                }

                bool downloadFile = false;

                int progress = (int)(100.0 / serverFiles.Count);
                if (progress * serverFiles.Count > 100)
                    progress--;
                int count = 1;

                string downloadLog;
                foreach(UOCFile file in serverFiles)
                {
                    downloadLog = "";
                    downloadFile = false;
                    if(File.Exists(file.name))
                    {
                        int pos = findPos(localFiles, file.name);

                        if (pos < 0)
                        {
                            File.Delete(file.name);
                            downloadLog = (file.name + " deleted.");
                        }
                        else if (file.version > localFiles[pos].version)
                        {
                            downloadFile = true;
                            downloadLog = (file.name + " updated.");
                        }
                        else
                        {
                            downloadLog = (file.name + " already up to date.");
                        }
                    }
                    else
                    {
                        downloadFile = true;
                        downloadLog = (file.name + " downloaded.");
                    }
                   

                    if(downloadFile && client != null)
                        client.DownloadFile(webServer + file.name, file.name);

                    printLog(downloadLog);
                    setProgress(progress * count++);
                    Thread.Sleep(50);
                }
                setProgress(100);
                File.Delete("local_versions.txt");
                File.Copy("server_versions.txt", "local_versions.txt");
            }
            printLog("Fin de la mise à jour.");
            File.Delete("server_" + fileVersions);
            activePlayButton();
            t = null;
        }

        bool getVersions()
        {
            try
            {
                client.DownloadFile(webServer + fileVersions, "server_" + fileVersions);
            }
            catch (WebException e)
            {
                printLog(e.Message);
                printLog("Une erreur est survenue lors de l'accès au serveur !");
                return false;
            }

            return true;
        }

        int findPos(List<UOCFile> list, string name)
        {
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].name == name) return i;
            }

            return -1;
        }

        void printLog(string message)
        {
            logs += message + "\n";
            if (t == null)
                richTextLogs.Text = logs;
            else
            {
                SetControlPropertyValue(richTextLogs, "Text", logs + "\n");
            }
        }

        void setProgress(int value)
        {
            if (t == null)
                uocProgress.Value = value;
            else
            {
                SetControlPropertyValue(uocProgress, "Value", value);
            }
        }

        void activePlayButton()
        {
            if (t == null)
                uocPlay.Text = "&Play";
            else
            {
                SetControlPropertyValue(uocPlay, "Text", "&Play");
            }
            isUpToDate = true;
        }

        private void uocPlay_Click(object sender, EventArgs e)
        {
            if (!isUpToDate)
            {
                t = new Thread(new ThreadStart(this.UpdateUOC));
                t.Start();
                //extractArchive("Mines.7z", "here");

            }
            else
            {
                /* Launch Client.exe */
                //Process UOClient = new Process();
                http://UOClient.StartInfo.FileName = "net";
                http://UOClient.Start();
            }
        }

        void extractArchive(string archive, string where)
        {
            printLog("Exctracting " + archive + " to " + where + ".");
            try
            {
                SevenZipExtractor se = new SevenZipExtractor(archive);
                se.ExtractArchive(where);
            }
            catch (SevenZipLibraryException e)
            {
                printLog(e.Message);
            }
            printLog("Archive extracted.");
        }

        string GetMD5HashFromFile(string fileName)
        {
            FileStream file = new FileStream(fileName, FileMode.Open);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(file);
            file.Close();
            ASCIIEncoding enc = new ASCIIEncoding();
            return enc.GetString(retVal);
        }

        delegate void SetControlValueCallback(Control oControl, string propName, object propValue);
        private void SetControlPropertyValue(Control oControl, string propName, object propValue)
        {
            if (oControl.InvokeRequired)
            {
                SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
                oControl.Invoke(d, new object[] { oControl, propName, propValue });
            }
            else
            {
                Type t = oControl.GetType();
                PropertyInfo[] props = t.GetProperties();
                foreach (PropertyInfo p in props)
                {
                    if (p.Name.ToUpper() == propName.ToUpper())
                    {
                        p.SetValue(oControl, propValue, null);
                    }
                }
            }
        }

        private void uocExit_Click(object sender, EventArgs e)
        {
            if (t == null)
                Application.Exit();
            else
            {
                DialogResult dr = MessageBox.Show("We are updating your files, exit now may cause broken files.\n\nAre you sure ?", "UOC Launcher " + uocVersion, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.OK)
                {
                    client = null;
                    t = null;
                    Application.Exit();
                }
            }
        }

        private void uocAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show("UOC Launcher " + uocVersion + "\nCreated by Scriptiz on " + uocDate + "\n\nOnly to play on http://uoclassic.free.fr/\n\nThank you for playing on UOClassic !", "UOC Launcher " + uocVersion, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
Revenir en haut Aller en bas
http://uoclassic.free.fr/
Scriptiz

Scriptiz


Messages : 102
Date d'inscription : 02/09/2008
Localisation : Belgium

Lanceur UO Empty
MessageSujet: Re: Lanceur UO   Lanceur UO Icon_minipostedMer 21 Oct - 10:33

Je n'ai pas beaucoup eu le temps d'avancer, j'ai cependant nettoyer une bonne partie du code mal propre, j'utilise désormais le téléchargement asynchrone plutôt que d'utiliser un thread pour ça, et j'ai séparer quelques méthodes dans la classe statique Tools. Bref il reste du boulot et j'essayerais de finir ça pour Nowel si j'en ai le temps :

Program.cs
Code:
/**
 * UoClassic Launcher
 * By Scriptiz for uoclassic.free.fr
 * First released on 17 september 2009
 * This code is released under GPL license.
 * License details : http://www.gnu.org/copyleft/gpl.html
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;                  // to use WebClient to download files
using System.IO;                    // to use StreamReader, FileStream, ...
using System.Threading;            // to use threads
using System.Reflection;            // to change properities of a thread while running another
using System.Diagnostics;          // to use processe's management
using System.Security.Cryptography; // to use MD5 crypto
using SevenZip;                    // to extract

namespace UOC_Launcher
{
    public partial class UOCLauncher : Form
    {
        // TODO verify version on a MD5 sum
        // TODO create an MD5 generator for the server
        // TODO implement try/catch block
        // TODO get administration rights under Vista/Seven
        // TODO automatically launch update
        // TODO clean the code (seperate functions, ...)
        // TODO first run : choose install dir and get base file (.7z archive)

        /*
        * Main steps :
        * 1) Get the base files (.7z)
        * 2) Add registry keys
        * 3) All files versions 1
        * 4) Verify other updates (md5 or versions?)
        * 5) Play
        */
        struct UOCFile
        {
            public string name;
            public int version;
        }

        private string uocVersion = "0.21";
        private string uocDate = "21 september 2009";
        private static string webServer = "http://localhost/uoc_launcher/";
        private static string fileVersions = "updates.txt";
        private static WebClient client = new WebClient();
        private static bool isUpToDate = false;
        string logs = "";
        string downloading;
        double lastBytesIn = 0;

        public UOCLauncher()
        {
            InitializeComponent();
            uocTabs.SelectTab(1);
            uocPlay.Text = "&Update";
        }

        private void UOCUpdate()
        {
            WebClient client = new WebClient();
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

            // Starts the download
            try
            {
                downloading = "uoml_6.0.14.1.7z";
                client.DownloadFileAsync(new Uri(webServer + downloading), "here/uoml_6.0.14.1.7z");
                http://client.DownloadFile("http://localhost/uoc_launcher/updates.txt", "here/updates.txt");
                http://client.DownloadFile(new Uri("http://localhost/uoc_launcher/uoml_6.0.14.1.7z"), "here");
            }
            catch (WebException e)
            {
                richTextLogs.Text += e.Message;
            }

            uocPlay.Enabled = false;
        }

        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            double bytesIn = ((int)((double.Parse(e.BytesReceived.ToString()) / 1048576) * 100)) / 100.0;
            double totalBytes = ((int)((double.Parse(e.TotalBytesToReceive.ToString()) / 1048576) * 100) / 100.0);

            uocProgress.Value = e.ProgressPercentage;
            richTextLogs.Text = logs + "Downloading file \"" + downloading + "\" ("+totalBytes+" Mo) : " + bytesIn + " Mo";
        }

        private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            logs = richTextLogs.Text + "\nDownload complete.";
            richTextLogs.Text = logs;

            uocPlay.Text = "Play";
            uocPlay.Enabled = true;
        }

        private void uocPlay_Click(object sender, EventArgs e)
        {
            if (!isUpToDate)
            {
                UOCUpdate();
            }
            else
            {
                /* Launch Client.exe */
                //Process UOClient = new Process();
                http://UOClient.StartInfo.FileName = "client.exe";
                http://UOClient.Start();
            }
        }

        private void uocAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show("UOC Launcher " + uocVersion + "\nCreated by Scriptiz on " + uocDate + "\n\nOnly to play on http://uoclassic.free.fr/\n\nThank you for playing on UOClassic !", "UOC Launcher " + uocVersion, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void uocExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Tools.cs
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using SevenZip;

namespace UOC_Launcher
{
    class Tools
    {
        public bool extractArchive(string archive, string where)
        {
            //printLog("Exctracting " + archive + " to " + where + ".");
            try
            {
                SevenZipExtractor se = new SevenZipExtractor(archive);
                se.ExtractArchive(where);
            }
            catch (SevenZipLibraryException e)
            {
                //printLog(e.Message);
                return false;
            }
            //printLog("Archive extracted.");
            return true;
        }

        string GetMD5HashFromFile(string fileName)
        {
            FileStream file = new FileStream(fileName, FileMode.Open);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(file);
            file.Close();
            ASCIIEncoding enc = new ASCIIEncoding();
            return enc.GetString(retVal);
        }
    }
}
Revenir en haut Aller en bas
http://uoclassic.free.fr/
Contenu sponsorisé





Lanceur UO Empty
MessageSujet: Re: Lanceur UO   Lanceur UO Icon_miniposted

Revenir en haut Aller en bas
 
Lanceur UO
Revenir en haut 
Page 1 sur 1

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
RunUO-FR :: Domaine public :: Vos créations-
Sauter vers: