Esempio n. 1
0
        static void Main(string[] args)
        {
            bool mutexWasCreated;
            mut = new Mutex(true, "T Starter 3", out mutexWasCreated);
            if (!mutexWasCreated) return;

            if (args.Length > 0) {
                try {
                    var pack = new DirectoryPack(new DirectoryInfo("Bonus\\" + args[0]));
                    var process = pack.Load();
                    process.WaitForExit();
                }
                catch (Exception) { }
                CleanUp();
                return;
            }

            try {
                XmlDocument doc = new XmlDocument();
                doc.Load("T2002Levels.xml");
                OnlineLevels.levels.Clear();
                var nodes = doc.GetElementsByTagName("Level");
                foreach (XmlNode node in nodes) {
                    string levelname = node.Attributes.GetNamedItem("name").Value;

                    OnlineLevel level = new OnlineLevel();
                    level.name = levelname;
                    level.author = node.Attributes.GetNamedItem("author").Value;
                    level.date = node.Attributes.GetNamedItem("date").Value;
                    OnlineLevels.levels.Add(level);
                }
            }
            catch (Exception) {

            }

            Application.EnableVisualStyles();
            Application.Run(Instance = new Form1());
        }
Esempio n. 2
0
        private void Reload()
        {
            checkedListBox1.Items.Clear();
            DirectoryInfo dir = new DirectoryInfo("Bonus");
            List<string> levels = new List<string>();

            List<T2002Level> localLevels = new List<T2002Level>();

            foreach (FileInfo file in dir.GetFiles()) {
                if (!file.Name.EndsWith(".zip")) continue;
                ZipFile z = new ZipFile(file.Open(FileMode.Open));
                List<Entry> entries = new List<Entry>();
                for (int i = 0; i < z.Count; ++i) {
                    entries.Add(new Entry(z[i].Name, z[i].Crc));
                }
                localLevels.Add(new T2002Level(file.Name, entries));
                z.Close();
            }

            foreach (FileInfo file in dir.GetFiles()) levels.Add(file.Name.Substring(0, file.Name.Length - 4));
            foreach (DirectoryInfo nextdir in dir.GetDirectories()) levels.Add(nextdir.Name);

            WebRequest myRequest = WebRequest.Create("http://turricanforever.de/T2002Levels.xml");//("http://turricanforever.de/levelbase");
            WebResponse myResponse = myRequest.GetResponse();
            System.IO.Stream streamReceive = myResponse.GetResponseStream();
            System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
            System.IO.StreamReader streamRead = new System.IO.StreamReader(streamReceive, encoding);

            List<T2002Level> remoteLevels = new List<T2002Level>();
            XmlDocument doc = new XmlDocument();
            doc.Load(streamRead);
            OnlineLevels.levels.Clear();
            var nodes = doc.GetElementsByTagName("Level");
            foreach (XmlNode node in nodes) {
                string levelname = node.Attributes.GetNamedItem("name").Value;

                OnlineLevel level = new OnlineLevel();
                level.name = levelname;
                level.author = node.Attributes.GetNamedItem("author").Value;
                level.date = node.Attributes.GetNamedItem("date").Value;
                OnlineLevels.levels.Add(level);

                List<Entry> entries = new List<Entry>();
                foreach (XmlNode entrynode in node.ChildNodes) {
                    var entry = new Entry(entrynode.Attributes.GetNamedItem("name").Value, long.Parse(entrynode.Attributes.GetNamedItem("crc").Value));
                    entries.Add(entry);
                }
                remoteLevels.Add(new T2002Level(levelname, entries));
            }

            doc.Save("T2002Levels.xml");

            /*
            string page = streamRead.ReadToEnd();
            int start = 0;
            for (string found = FindInbetween(page, "href=\"", "\">", ref start); found != null; found = FindInbetween(page, "href=\"", "\">", ref start))
            {
                if (found.EndsWith(".zip") && found.Contains("t2002"))
                {
                    string[] parts = found.Split('/');
                    string name = parts[parts.Length - 1]; //found.Substring(7, found.Length - 7 - 4);
                    if (name.StartsWith("TStarter") || name.StartsWith("T Starter") || name.StartsWith("T-Starter")) continue;
                    if (!levels.Contains(name.Substring(0, name.Length - 4))) checkedListBox1.Items.Add(name, true);
                }
            }*/
            foreach (var level in remoteLevels) {
                bool gotit = false;
                foreach (var locallevel in localLevels) {
                    if (locallevel.getName() == level.getName()) {
                        if (locallevel.Equals(level)) gotit = true;
                        else break;
                    }
                }
                if (!gotit) checkedListBox1.Items.Add(level.getName(), true);
            }

            if (checkedListBox1.Items.Count == 0) button1.Enabled = false;
        }