Beispiel #1
0
        private void CreateMD5_DoWork(object sender, DoWorkEventArgs e)
        {
            if (File.Exists(appdata + "ListMod.xml"))
            {
                File.Delete(appdata + "ListMod.xml");
            }
            if (File.Exists(appdata + "ListMaj.xml"))
            {
                File.Delete(appdata + "ListMaj.xml");
            }
            if (File.Exists(appdata + "ListServer.xml"))
            {
                File.Delete(appdata + "ListServer.xml");
            }
            metroProgressSpinner1.Invoke(new Action(() => { metroProgressSpinner1.Style = MetroFramework.MetroColorStyle.Blue; }));
            Label_HASH.Invoke(new Action(() => { Label_HASH.ForeColor = Color.Blue; }));
            Label_HASH.Invoke(new Action(() => { Label_HASH.Text = "création du hash en cours !"; }));
            metroProgressSpinner1.Invoke(new Action(() => { metroProgressSpinner1.Visible = true; }));
            System.IO.FileStream filed = System.IO.File.Create(appdata + "ListMod.xml");

            XmlTextWriter xmltextwriter = new XmlTextWriter(filed, System.Text.Encoding.UTF8);

            xmltextwriter.Formatting = Formatting.Indented;

            xmltextwriter.WriteStartDocument(false);

            xmltextwriter.WriteStartElement("HASH");

            using (var md5 = MD5.Create())
            {
                var files = from filee in Directory.EnumerateFiles(Mod_MAJ, "*", SearchOption.TopDirectoryOnly)
                            select new
                {
                    File  = filee,
                    Files = filee,
                };

                foreach (var f in files)
                {
                    using (var stream = File.OpenRead(f.File))
                    {
                        string Files = f.Files.Replace(@"C:\Users\root\Desktop\Mod_MaishaRP_MAJ\", "");
                        string lines = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", string.Empty);
                        xmltextwriter.WriteStartElement("addons");
                        xmltextwriter.WriteAttributeString("Nom", Files);
                        xmltextwriter.WriteAttributeString("Hash", lines);
                        Label_HASH.Invoke(new Action(() => { Label_HASH.Text = lines; }));
                        xmltextwriter.WriteEndElement();
                    }
                }
                xmltextwriter.WriteEndElement();

                xmltextwriter.Flush();

                xmltextwriter.Close();
            }
        }
Beispiel #2
0
 private void CheckMD5_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (counter_check == 0)
     {
         Server_start();
     }
     else
     {
         CopyStart();
     }
     Label_HASH.Invoke(new Action(() => { Label_HASH.ForeColor = Color.Black; }));
     Label_HASH.Text = "Haschage terminé";
     metroProgressSpinner1.Invoke(new Action(() => { metroProgressSpinner1.Visible = false; }));
     //CheckMD5.Dispose();
 }
Beispiel #3
0
        private void CheckMD5_DoWork(object sender, DoWorkEventArgs e)
        {
            metroProgressSpinner1.Invoke(new Action(() => { metroProgressSpinner1.Style = MetroFramework.MetroColorStyle.Green; }));
            Label_HASH.Invoke(new Action(() => { Label_HASH.ForeColor = Color.Green; }));
            System.IO.FileStream filed = System.IO.File.Create(appdata + "ListServer.xml");

            XmlTextWriter xmltextwriter = new XmlTextWriter(filed, System.Text.Encoding.UTF8);

            xmltextwriter.Formatting = Formatting.Indented;

            xmltextwriter.WriteStartDocument(false);
            xmltextwriter.WriteStartElement("HASH");
            using (var md5 = MD5.Create())
            {
                var files = from filee in Directory.EnumerateFiles(Server_Directory, "*", SearchOption.TopDirectoryOnly)
                            select new
                {
                    File  = filee,
                    Files = filee,
                };

                foreach (var f in files)
                {
                    using (var stream = File.OpenRead(f.File))
                    {
                        string Files = f.Files.Replace(Server_Directory, "");
                        string lines = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", string.Empty);
                        xmltextwriter.WriteStartElement("addons");
                        xmltextwriter.WriteAttributeString("Nom", Files);
                        xmltextwriter.WriteAttributeString("Hash", lines);
                        xmltextwriter.WriteEndElement();;
                        Label_HASH.Invoke(new Action(() => { Label_HASH.Text = lines; }));
                    }
                }
                xmltextwriter.WriteEndElement();

                xmltextwriter.Flush();

                xmltextwriter.Close();
            }

            System.IO.FileStream file = System.IO.File.Create(appdata + "ListMaj.xml");

            XmlTextWriter myXmlTextWriter = new XmlTextWriter(file, System.Text.Encoding.UTF8);

            myXmlTextWriter.Formatting = Formatting.Indented;

            myXmlTextWriter.WriteStartDocument(false);

            myXmlTextWriter.WriteStartElement("downloader");

            XmlDocument hashclient = new XmlDocument();

            hashclient.Load(appdata + "ListServer.xml");

            XmlNodeList lstclient = hashclient.GetElementsByTagName("addons");

            XmlDocument hashserver = new XmlDocument();

            var nodees = new List <XmlNode>(lstclient.Cast <XmlNode>());

            hashserver.Load(appdata + "ListMod.xml");

            XmlNodeList lst = hashserver.GetElementsByTagName("addons");

            if (hashclient.SelectSingleNode("//addons") == null)
            {
                foreach (XmlNode p in lst)
                {
                    myXmlTextWriter.WriteStartElement("addons");

                    myXmlTextWriter.WriteAttributeString("addons", p.Attributes[0].Value);

                    myXmlTextWriter.WriteAttributeString("download", "true");

                    myXmlTextWriter.WriteEndElement();
                }
            }
            foreach (XmlNode n in lst)
            {
                foreach (XmlNode b in lstclient)
                {
                    if (n.Attributes[0].Value == b.Attributes[0].Value)
                    {
                        if (n.Attributes[1].Value == b.Attributes[1].Value)
                        {
                            myXmlTextWriter.WriteStartElement("addons");

                            myXmlTextWriter.WriteAttributeString("addons", n.Attributes[0].Value);

                            myXmlTextWriter.WriteAttributeString("download", "false");

                            myXmlTextWriter.WriteEndElement();
                        }
                        else
                        {
                            myXmlTextWriter.WriteStartElement("addons");

                            myXmlTextWriter.WriteAttributeString("addons", n.Attributes[0].Value);

                            myXmlTextWriter.WriteAttributeString("download", "true");

                            myXmlTextWriter.WriteEndElement();
                        }

                        break;
                    }
                }
            }

            foreach (XmlNode h in lst)
            {
                foreach (XmlNode g in lstclient)
                {
                    if (g.Attributes[0] == null)
                    {
                        myXmlTextWriter.WriteStartElement("addons");

                        myXmlTextWriter.WriteAttributeString("addons", h.Attributes[0].Value);

                        myXmlTextWriter.WriteAttributeString("download", "true");

                        myXmlTextWriter.WriteEndElement();
                    }
                }
            }
            bool del = false;

            foreach (XmlNode v in lstclient)
            {
                foreach (XmlNode d in lst)
                {
                    del = false;

                    if (v.Attributes[0].Value == d.Attributes[0].Value)
                    {
                        break;
                    }

                    else
                    {
                        del = true;
                    }
                }
                if (del)
                {
                    myXmlTextWriter.WriteStartElement("addons");

                    myXmlTextWriter.WriteAttributeString("addons", v.Attributes[0].Value);

                    myXmlTextWriter.WriteAttributeString("download", "del");

                    myXmlTextWriter.WriteEndElement();
                }
            }
            foreach (XmlNode v in lst)
            {
                foreach (XmlNode d in lstclient)
                {
                    del = false;

                    if (v.Attributes[0].Value == d.Attributes[0].Value)
                    {
                        break;
                    }

                    else
                    {
                        del = true;
                    }
                }
                if (del)
                {
                    myXmlTextWriter.WriteStartElement("addons");

                    myXmlTextWriter.WriteAttributeString("addons", v.Attributes[0].Value);

                    myXmlTextWriter.WriteAttributeString("download", "true");

                    myXmlTextWriter.WriteEndElement();
                }
            }

            myXmlTextWriter.WriteEndElement();

            myXmlTextWriter.Flush();

            myXmlTextWriter.Close();

            XmlDocument List_download2 = new XmlDocument();

            List_download2.Load(appdata + "ListMaj.xml");

            XmlNodeList listdownload = List_download2.GetElementsByTagName("addons");

            foreach (XmlNode down in listdownload)
            {
                if (down.Attributes[1].Value == "true" || down.Attributes[1].Value == "del")
                {
                    counter_check++;
                }
            }
        }