Exemplo n.º 1
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            if (exeORmods == "exe")
            {
                DownloadHelper.DownloadUpdate();
            }
            else if (exeORmods == "mods")
            {
                DownloadHelper.DownloadModlist();
            }

            Close();
        }
        private void ReadModsFromFile(string parameter)
        {
            if (File.Exists(MODLIST_FILE))
            {
                DownloadHelper.CheckForNewModlist(silently: true);
            }
            else
            {
                DownloadHelper.DownloadModlist();
            }

            // Wait 2 seconds for Modlist to download
            int counter = 0;

            while (!IsFileReady(MODLIST_FILE) && counter < 200)
            {
                Thread.Sleep(10);
                counter++;
            }

            using (StreamReader file = new StreamReader(MODLIST_FILE))
            {
                string line;

                while ((line = file.ReadLine()) != null)
                {
                    if (line.StartsWith(parameter))
                    {
                        // Skipping an empty line
                        file.ReadLine();

                        // Read lines untill we will found mods for the different version
                        while (!(Convert.ToChar(file.Peek()) == '['))
                        {
                            // Reading 5 lines and creating a Mod instance
                            string[] modProperties = new string[5];

                            for (int i = 0; i < 5; i++)
                            {
                                if ((line = file.ReadLine()) != null)
                                {
                                    if (line.StartsWith("-"))
                                    {
                                        line = "";
                                    }

                                    modProperties[i] = line;
                                }
                                else
                                {
                                    modProperties[i] = "";      // There is no line to read - we have to add something to a Mod instance!
                                }
                            }

                            modlist.Add(new Mod(modProperties[0], modProperties[1], modProperties[2], modProperties[3], modProperties[4]));

                            // Skipping an empty line
                            file.ReadLine();
                        }

                        // We found all mods for current DoW version
                        break;
                    }
                }
            }
        }