Example #1
0
        private static void HandleCommands()
        {
            string command;

            while ((command = m_inputBox.ReadLine()) != "exit")
            {
                if (string.IsNullOrEmpty(command))
                {
                    continue;
                }

                WriteLog(command, LogType.CONSOLE);

                string[] parsed = command.Split(' ');
                switch (parsed[0].ToLower())
                {
                case "add":
                    if (parsed.Length < 2)
                    {
                        break;
                    }

                    if (parsed.Length == 2)
                    {
                        if (int.TryParse(parsed[1], out int version))
                        {
                            UpdatesManager.AddPatch(new PatchStructure
                            {
                                To = version
                            }, false);
                        }
                    }
                    else if (parsed.Length == 4)
                    {
                        int    from = 0, to = 0;
                        string fileName = parsed[3];

                        if (!int.TryParse(parsed[1], out from) || !int.TryParse(parsed[2], out to))
                        {
                            break;
                        }

                        UpdatesManager.AddPatch(new PatchStructure
                        {
                            From = from, To = to, FileName = fileName
                        }, false);
                    }
                    break;

                case "remove":
                    if (parsed.Length < 2)
                    {
                        break;
                    }

                    if (int.TryParse(parsed[1], out int remVersion))
                    {
                        UpdatesManager.RemovePatch(remVersion, false);
                    }
                    break;

                case "test":
                    if (parsed.Length < 2)
                    {
                        break;
                    }

                    if (parsed[1] == "download_list")
                    {
                        if (parsed.Length < 3 || !int.TryParse(parsed[2], out int idPatch))
                        {
                            break;
                        }

                        foreach (var patch in UpdatesManager.GetDownloadList(idPatch))
                        {
                            if (patch.From > 0)
                            {
                                WriteLog($"Patch[From:{patch.From}][To:{patch.To}][File:{patch.FileName}]");
                            }
                            else
                            {
                                WriteLog($"Patch[To:{patch.To}][File:{patch.FileName}]");
                            }
                        }
                    }

                    break;
                }
            }
        }
Example #2
0
        private static void ReadConfigFile()
        {
            const string configFile = "AutoUpdater.xml";
            string       path       = Environment.CurrentDirectory + "\\" + configFile;

            if (!File.Exists(path))
            {
                MyXml create = new MyXml(path);
                create.AddNewNode("https://ftwmasters.com.br/patches", null, "DownloadUrl", "Config");
                create.AddNewNode("9528", null, "ListenPort", "Config");
                create.AddNewNode("10000", null, "LatestUpdaterVersion", "Config");
                create.AddNewNode("4000", null, "LatestGameVersion", "Config");
                create.AddNewNode("2019-10-22 00:00:00", null, "PrivacyTermsUpdate", "Config");
                create.AddNewNode("", null, "AllowedPatches", "Config");
                create.AddNewNode("", null, "BundlePatches", "Config");
            }

            Kernel.MyXml = new MyXml(path);
            if (int.TryParse(Kernel.MyXml.GetValue("Config", "ListenPort"), out int port))
            {
                Kernel.ListenPort = port;
            }
            WriteLog($"Server will listen to port: {Kernel.ListenPort}", LogType.CONSOLE);
            WriteLog("If you want to change the server port, write `exit` and edit AutoUpdater.xml file.", LogType.CONSOLE);

            if (int.TryParse(Kernel.MyXml.GetValue("Config", "LatestUpdaterVersion"), out int updater))
            {
                Kernel.LatestUpdaterPatch = updater;
            }
            WriteLog($"Latest updater client version: {Kernel.LatestUpdaterPatch}", LogType.CONSOLE);

            if (int.TryParse(Kernel.MyXml.GetValue("Config", "LatestGameVersion"), out int game))
            {
                Kernel.LatestGamePatch = game;
            }
            WriteLog($"Latest game client version: {Kernel.LatestGamePatch}", LogType.CONSOLE);

            if (!string.IsNullOrEmpty(Kernel.MyXml.GetValue("Config", "DownloadUrl")))
            {
                Kernel.DownloadUrl = Kernel.MyXml.GetValue("Config", "DownloadUrl");
            }
            WriteLog($"Client will download files from: {Kernel.DownloadUrl}", LogType.CONSOLE);
            if (!string.IsNullOrEmpty(Kernel.MyXml.GetValue("Config", "PrivacyTermsUpdate")))
            {
                Kernel.PrivacyTermsUpdate = DateTime.Parse(Kernel.MyXml.GetValue("Config", "PrivacyTermsUpdate"));
            }
            WriteLog($"Privacy Terms last updated: {Kernel.PrivacyTermsUpdate}", LogType.CONSOLE);

            foreach (XmlNode node in Kernel.MyXml.GetAllNodes("Config", "AllowedPatches"))
            {
                UpdatesManager.AddPatch(new PatchStructure
                {
                    To       = int.Parse(Kernel.MyXml.GetValue("Config", "AllowedPatches", $"Patch[@id='{node.Attributes["id"].Value}']")),
                    FileName = Kernel.MyXml.GetValue("Config", "AllowedPatches", $"Patch[@id='{node.Attributes["id"].Value}']")
                }, true);
            }

            foreach (XmlNode node in Kernel.MyXml.GetAllNodes("Config", "BundlePatches"))
            {
                UpdatesManager.AddPatch(new PatchStructure
                {
                    From     = int.Parse(Kernel.MyXml.GetValue("Config", "BundlePatches", $"Patch[@id='{node.Attributes["id"].Value}']", "From")),
                    To       = int.Parse(Kernel.MyXml.GetValue("Config", "BundlePatches", $"Patch[@id='{node.Attributes["id"].Value}']", "To")),
                    FileName = Kernel.MyXml.GetValue("Config", "BundlePatches", $"Patch[@id='{node.Attributes["id"].Value}']", "FileName")
                }, true);
            }
        }