Exemple #1
0
        List <ThemeData> LoadThemes(string[] data)
        {
            var themes = new List <ThemeData>();

            foreach (var theme in data)
            {
                var split = theme.Split('|');

                if (split.Length != 3)
                {
                    // except
                    continue;
                }

                var name = split[0];
                var path = split[1];
                var guid = split[2];

                try
                {
                    using (var http = new ExWebClient())
                    {
                        http.Encoding = Encoding.UTF8;
                        var files = new List <FilesData>();
                        var bytes = http.DownloadData("https://dnf.kxnrl.com/themes/" + path + ".list");
                        foreach (var result in Encoding.UTF8.GetString(bytes).Split('\n'))
                        {
                            var info = result.Split('|');
                            if (info.Length != 4)
                            {
                                // except
                                continue;
                            }
                            files.Add(new FilesData(info[0], info[2], info[3], info[1]));
                        }
                        if (files.Count == 0)
                        {
                            // wtf?
                            throw new Exception("NullDataSet");
                        }
                        themes.Add(new ThemeData(name, guid, path, files));
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError("LoadTheme [{0}] Exception: {1}{2}", name, e.Message, e.StackTrace);
                }
            }

            return(themes);
        }
Exemple #2
0
        private void PatchForm_Load(object sender, EventArgs e)
        {
            Icon = Properties.Resources.icon;

            Utils.NPKScanner.Scan();

            switch (Variables.PatchMode)
            {
            case Variables.PatchType.Character:
                Text          = "角色补丁";
                PatchTypeName = "Character";
                break;

            case Variables.PatchType.Optimization:
                Text          = "优化补丁";
                PatchTypeName = "Optimization";
                break;

            case Variables.PatchType.Miscellaneous:
                Text          = "其他补丁";
                PatchTypeName = "Miscellaneous";
                break;

            //case Variables.PatchType.Theme:
            //    Text = "自定义主题";
            //    PatchTypeName = "Theme";
            //    break;
            default:
                MessageBox.Show("发生未知错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ((MainForm)Owner).Activate();
                Close();
                Dispose();
                return;
            }

            new Thread(() =>
            {
                Invoke(new Action(() =>
                {
                    ActionLabel.Text = "正在连接服务器...";
                    Application.DoEvents();
                }));

                Thread.Sleep(100);

                Invoke(new Action(() =>
                {
                    try
                    {
                        using (var http = new ExWebClient())
                        {
                            http.Encoding = Encoding.UTF8;
                            var data      = Encoding.UTF8.GetString(http.DownloadData("https://dnf.kxnrl.com/" + PatchTypeName + ".list")).Split('\n');

                            if (data.Length == 0)
                            {
                                // null
                                ActionLabel.Text = "补丁列表为空";
                                throw new Exception("补丁列表为空");
                            }

                            patches.Clear();

                            foreach (var patch in data)
                            {
                                var split = patch.Split('|');
                                if (split.Length != 4)
                                {
                                    // ???
                                    continue;
                                }

                                patches.Add(new Patches(split[0], split[1], split[2].ToLowerInvariant(), split[3]));
                            }

                            Progressbar.Value = Progressbar.Maximum;
                            ActionLabel.Text  = "初始化完成...";

                            foreach (var p in patches)
                            {
                                PatchList.Rows.Add(p.pGUID, p.pName, p.pDesc, p.pDone ? "卸载" : "安装");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("初始化补丁列表失败:" + Environment.NewLine + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Logger.LogError("DownloadData [{0}] Exception: {1}", "ThreadInvoker", ex.Message);
                        Invoke(new Action(() =>
                        {
                            ((MainForm)Owner).Activate();
                            Close();
                            Dispose();
                        }));
                    }
                }));
            }).Start();
        }
Exemple #3
0
        private void ThemeForm_Load(object sender, EventArgs e)
        {
            Icon = Properties.Resources.icon;

            Utils.NPKScanner.Scan();

            new Thread(() =>
            {
                Invoke(new Action(() =>
                {
                    ActionLabel.Text = "正在连接服务器...";
                    Application.DoEvents();
                }));

                Thread.Sleep(100);

                Invoke(new Action(() =>
                {
                    try
                    {
                        using (var http = new ExWebClient())
                        {
                            http.Encoding = Encoding.UTF8;
                            var text      = Encoding.UTF8.GetString(http.DownloadData("https://dnf.kxnrl.com/" + "Theme.list")).Split('\n');

                            if (text.Length == 0)
                            {
                                // null
                                ActionLabel.Text = "补丁列表为空";
                                throw new Exception("补丁列表为空");
                            }

                            defaultIndex = ThemeSelector.Items.Add(new ThemeData("国服DNF原版界面"));
                            ThemeSelector.SelectedIndex = defaultIndex;
                            currentInstalled            = defaultIndex;
                            foreach (var theme in LoadThemes(text))
                            {
                                var index = ThemeSelector.Items.Add(theme);
                                CheckValidation(theme.tFile, out int installed);
                                if (installed > 0)
                                {
                                    // installed
                                    currentInstalled            = index;
                                    ThemeSelector.SelectedIndex = index;
                                }
                            }
                            ThemeSelector.DropDownStyle = ComboBoxStyle.DropDownList;
                            ThemeSelector.Enabled       = true;

                            Progressbar.Value = Progressbar.Maximum;
                            ActionLabel.Text  = "初始化完成...";
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("初始化补丁列表失败:" + Environment.NewLine + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Logger.LogError("DownloadData [{0}] Exception: {1} {2} {3}", "ThreadInvoker", ex.Message, Environment.NewLine, ex.StackTrace);
                        Invoke(new Action(() =>
                        {
                            ((MainForm)Owner).Activate();
                            Close();
                            Dispose();
                        }));
                    }
                }));
            }).Start();
        }