Esempio n. 1
0
        void LoadFiles(object filePaths)
        {
            List <string> files = (List <string>)filePaths;

            InvokeIfRequired(() =>
            {
                this.Cursor = Cursors.WaitCursor;
                statusProgressBar.Maximum = files.Count;
                ToggleProgressBar(true);
            });

            // Load HTML files

            // Step 0
            ResetProgress(LOAD_STEPS, Program.IniReader["loading"] + " Html's...");

            if (File.Exists(Path.Combine(root, @".\dialogs\quests.dat")))
            {
                try {
                    using (FileStream fs = new FileStream(Path.Combine(root, @".\dialogs\quests.dat"), FileMode.Open)) {
                        BinaryFormatter bf = new BinaryFormatter();
                        questFiles = (QuestDictionary)bf.Deserialize(fs);
                    }
                } catch { }
            }
            if (questFiles == null)
            {
                questFiles = new QuestDictionary();
            }

            bool addedNew = false;

            ResetProgress(questFiles.Count, String.Empty);

            for (int i = 0; i < files.Count; i++)
            {
                string name = Path.GetFileName(files[i]);
                if (!name.StartsWith("quest_"))
                {
                    continue;
                }
                string qId = Path.GetFileNameWithoutExtension(Path.GetFileName(files[i]))
                             .Remove(0, 7).Trim();
                int id;
                if (!Int32.TryParse(qId, out id))
                {
                    continue;
                }
                if (_raceToView == "elyo" && id >= 2000 && id < 3000)
                {
                    continue;
                }
                if (_raceToView == "asmodian" && id < 2000)
                {
                    continue;
                }
                string msg = String.Format(Program.IniReader["loading"] + " {0}...", Path.GetFileName(files[i]));
                InvokeIfRequired(() => { statusLabel.Text = msg; });
                if (!questFiles.ContainsKey(id))
                {
                    addedNew = true;
                    QuestFile questFile;
                    if (Utility.TryLoadQuestHtml(files[i], out questFile))
                    {
                        questFiles.Add(id, questFile);
                    }
                }
                InvokeIfRequired(() => { statusProgressBar.Value = i + 1; });
                Thread.Sleep(1);
            }

            try {
                using (var fs = new FileStream(Path.Combine(root, @".\dialogs\HtmlPages.xml"),
                                               FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(fs)) {
                        XmlSerializer ser = new XmlSerializer(typeof(HtmlPageIndex));
                        HtmlPage.Index = (HtmlPageIndex)ser.Deserialize(reader);
                        HtmlPage.Index.CreateIndex();
                    }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 1
            ResetProgress(LOAD_STEPS, Program.IniReader["loading"] + " HyperLinks.xml...");

            try {
                using (var fs = new FileStream(Path.Combine(root, @".\dialogs\HyperLinks.xml"),
                                               FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(fs)) {
                        XmlSerializer ser = new XmlSerializer(typeof(HyperLinkIndex));
                        SelectsAct.Index = (HyperLinkIndex)ser.Deserialize(reader);
                        SelectsAct.Index.CreateIndex();
                    }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 2
            ShowProgress(Program.IniReader["loadingStrings"] + "...");
            Utility.LoadStrings(root);

            // Step 3
            ShowProgress(Program.IniReader["loadingNpc"] + "...");
            Utility.LoadNpcs(root);

            // Step 4
            ShowProgress(Program.IniReader["loadingQuestData"] + "...");
            try {
                using (var fs = new FileStream(Path.Combine(root, @".\quest\quest.xml"),
                                               FileMode.Open, FileAccess.Read))
                    using (var reader = XmlReader.Create(fs)) {
                        XmlSerializer ser = new XmlSerializer(typeof(QuestsFile));
                        questData = (QuestsFile)ser.Deserialize(reader);
                        questData.CreateIndex();
                    }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 5
            ShowProgress(Program.IniReader["loadingItemData"] + "...");
            Utility.LoadItems(root);

            /*
             * InvBonuses bonuses = new InvBonuses();
             * bonuses.BonusItems = new List<BonusItem>();
             * foreach (var q in questData.QuestList) {
             *  WrapItem wi = null;
             *  if (q.reward_item_ext_1 != null && q.reward_item_ext_1.StartsWith("wrap_")) {
             *      wi = new WrapItem();
             *      string[] itemData = q.reward_item_ext_1.Split(' ');
             *      Item item = Utility.ItemIndex.GetItem(itemData[0]);
             *      if (item == null)
             *          wi.itemId = 0;
             *      else
             *          wi.itemId = item.id;
             *      if (itemData[0].Contains("_enchant_"))
             *          wi.type = BonusType.ENCHANT;
             *      else
             *          wi.type = BonusType.MANASTONE;
             *      string lvl = itemData[0].Substring(itemData[0].Length - 3, 2);
             *      wi.level = Int32.Parse(lvl);
             *  }
             *  if (q.HasRandomRaward()) {
             *      BonusItem bi = new BonusItem();
             *      bi.questId = q.id;
             *      bi.BonusInfos = new List<BonusInfo>();
             *      if (q.reward_item1_1 != null && q.reward_item1_1.StartsWith("%Quest_")) {
             *          BonusInfo bii = new BonusInfo();
             *          if (q.check_item1_1 != null) {
             *              string[] itemData = q.check_item1_1.Split(' ');
             *              bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
             *              bii.checkItemSpecified = true;
             *              bii.count = Int32.Parse(itemData[1]);
             *              bii.countSpecified = true;
             *          }
             *          bii.Value = q.reward_item1_1;
             *          bi.BonusInfos.Add(bii);
             *      }
             *      if (q.reward_item1_2 != null && q.reward_item1_2.StartsWith("%Quest_")) {
             *          BonusInfo bii = new BonusInfo();
             *          if (q.check_item1_2 != null) {
             *              string[] itemData = q.check_item1_2.Split(' ');
             *              bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
             *              bii.checkItemSpecified = true;
             *              bii.count = Int32.Parse(itemData[1]);
             *              bii.countSpecified = true;
             *          }
             *          bii.Value = q.reward_item1_2;
             *          bi.BonusInfos.Add(bii);
             *      }
             *      if (q.reward_item1_3 != null && q.reward_item1_3.StartsWith("%Quest_")) {
             *          BonusInfo bii = new BonusInfo();
             *          if (q.check_item1_3 != null) {
             *              string[] itemData = q.check_item1_3.Split(' ');
             *              bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
             *              bii.checkItemSpecified = true;
             *              bii.count = Int32.Parse(itemData[1]);
             *              bii.countSpecified = true;
             *          }
             *          bii.Value = q.reward_item1_3;
             *          bi.BonusInfos.Add(bii);
             *      }
             *      if (wi != null) {
             *          bi.wrap = wi;
             *          bi.wrapSpecified = true;
             *      }
             *      bonuses.BonusItems.Add(bi);
             *  } else if (wi != null) {
             *      BonusItem bi = new BonusItem();
             *      bi.questId = q.id;
             *      bi.wrap = wi;
             *      bi.wrapSpecified = true;
             *      bonuses.BonusItems.Add(bi);
             *  }
             * }
             *
             * XmlWriterSettings set = new XmlWriterSettings()
             * {
             *  CloseOutput = false,
             *  Encoding = Encoding.UTF8,
             *  Indent = true,
             *  IndentChars = "\t",
             * };
             * using (FileStream stream = new FileStream("bonuses.xml", FileMode.Create, FileAccess.Write)) {
             *  using (XmlWriter wr = XmlWriter.Create(stream, set)) {
             *      XmlSerializer ser = new XmlSerializer(typeof(InvBonuses));
             *      ser.Serialize(wr, bonuses);
             *  }
             * }
             */

            // Step 6
            ResetProgress(questFiles.Count, String.Empty);

            InvokeIfRequired(() =>
            {
                try {
                    this.Cursor = Cursors.Default;

                    foreach (int level in questData.Levels)
                    {
                        var lvlNode = rootNode.Nodes.Add(level.ToString(),
                                                         String.Format(Program.IniReader["level"] + " {0}", level));
                        TreeNode raceNode = null;
                        if (String.IsNullOrEmpty(_raceToView) || _raceToView == "elyo")
                        {
                            raceNode = lvlNode.Nodes.Add("pc_light", Program.IniReader["elyo"]);
                        }
                        if (String.IsNullOrEmpty(_raceToView) || _raceToView == "asmodian")
                        {
                            raceNode = lvlNode.Nodes.Add("pc_dark", Program.IniReader["asmodian"]);
                        }
                        Application.DoEvents();
                    }

                    rootNode.Nodes.Add("0", Program.IniReader["misc"]);
                    rootNode.Expand();
                } catch { }
            });

            var writer = new StreamWriter("quests.txt");

            foreach (KeyValuePair <int, QuestFile> quest in questFiles)
            {
                HtmlPage summary = quest.Value.HtmlPages.Where(p => p.name == "quest_summary")
                                   .FirstOrDefault();
                Quest  questInfo = null;
                string qName     = "Q" + quest.Key.ToString();

                ShowProgress(String.Format(Program.IniReader["parsing"] + " {0}", quest.Value.fileName));

                var title = Utility.StringIndex.GetStringDescription("STR_QUEST_NAME_" + qName);

                questInfo = questData["Q" + quest.Key];
                if (questInfo == null)
                {
                    Debug.Print("Missing data for: {0}", quest.Value.fileName);
                    questInfo = new Quest();
                }

                //if (!questInfo.HasRandomRaward())
                //    continue;

                questInfo.HtmlPages = quest.Value.HtmlPages;
                bool reconstructed = false;

                if (summary == null)
                {
                    Debug.Print("Quest: {0} doesn't contain summary", quest.Value.fileName);
                    if (title == null)
                    {
                        continue;
                    }
                    Debug.Print("Quest Title: {0}", title.body);
                    summary = new HtmlPage()
                    {
                        name = "quest_summary"
                    };
                    summary.Content = new Contents()
                    {
                        html = new ContentsHtml()
                        {
                            body = new Body()
                            {
                                steps = new Step[] { new Step() },
                                p     = new Paragraph[] { new Paragraph() }
                            }
                        }
                    };
                    Paragraph para = summary.Content.html.body.p[0];
                    para.font = new pFont()
                    {
                        font_xml = "quest_summary",
                        Value    = String.Empty
                    };

                    if (String.IsNullOrEmpty(questInfo.extra_category))
                    {
                        questInfo.extra_category = "devanion_quest";
                        Debug.Print("Quest: {0} extra_category is null", quest.Value.fileName);
                    }

                    CultureInfo ci  = new CultureInfo(String.Empty);
                    string      tit = ci.TextInfo.ToTitleCase(questInfo.extra_category.Replace('_', ' '));
                    para.font.Value = tit;

                    Step singleStep = summary.Content.html.body.steps[0];
                    singleStep.p = new Paragraph()
                    {
                        font = new pFont()
                        {
                            Value = Program.IniReader["step"] + " 1"
                        }
                    };

                    // Include Quest Complete page too
                    var qc = quest.Value.HtmlPages.Where(p => p.name == "quest_complete").FirstOrDefault();
                    if (qc != null)
                    {
                        qc.ForceInclude = true;
                    }

                    quest.Value.HtmlPages.Add(summary);
                    reconstructed = true;
                }
                if (!reconstructed)
                {
                    if (summary.Content == null)
                    {
                        Debug.Print("Quest: {0} summary doesn't contain content", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html == null)
                    {
                        Debug.Print("Quest: {0} summary doesn't contain html", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html.body == null)
                    {
                        Debug.Print("Quest: {0} summary doesn't contain body", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html.body.steps == null)
                    {
                        Debug.Print("Quest: {0} summary doesn't contain steps", quest.Value.fileName);
                        continue;
                    }
                }

                if (title == null)
                {
                    Debug.Print("Quest: {0} has no title", quest.Value.fileName);
                    summary.QuestTitle = qName;
                }
                else
                {
                    summary.QuestTitle = title.body;
                }

                TreeNode questNode = new TreeNode(summary.QuestTitle);
                questNode.Name = qName;
                questNode.Tag  = questInfo;

                writer.WriteLine(String.Format("{0}\t{1}", qName.Remove(0, 1), summary.QuestTitle));
                writer.Flush();

                int i = 0;
                foreach (Step step in summary.Content.html.body.steps)
                {
                    // [%collectitem]
                    // step.Value
                    i++;
                    if (String.IsNullOrEmpty(step.Value))
                    {
                        // ok
                    }
                    else if (step.Value == "[%collectitem]")
                    {
                    }

                    if (String.IsNullOrEmpty(step.p.font.Value))
                    {
                        Debug.Print("Empty step {0}", i);
                        continue;
                    }

                    step.Number = i;
                    var stepNode = questNode.Nodes.Add("S" + i.ToString(),
                                                       String.Format(Program.IniReader["step"] + " {0}", i));
                    stepNode.Tag = step;
                    Thread.Sleep(1);
                }

                TreeNode nodeToAdd = null;

                InvokeIfRequired(() =>
                {
                    if (questInfo.minlevel_permitted == 0)
                    {
                        nodeToAdd = rootNode.Nodes["0"];
                        nodeToAdd.Nodes.Add(questNode);
                        Application.DoEvents();
                    }
                    else
                    {
                        nodeToAdd = rootNode.Nodes[questInfo.minlevel_permitted.ToString()];
                        if (questInfo.race_permitted == "pc_light" &&
                            (_raceToView == null || _raceToView == "elyo"))
                        {
                            nodeToAdd = nodeToAdd.Nodes["pc_light"];
                            AddQuestToRace(nodeToAdd, questNode);
                        }
                        else if (questInfo.race_permitted == "pc_dark" &&
                                 (_raceToView == null || _raceToView == "asmodian"))
                        {
                            nodeToAdd = nodeToAdd.Nodes["pc_dark"];
                            AddQuestToRace(nodeToAdd, questNode);
                        }
                        else
                        {
                            TreeNode node = null;
                            if (_raceToView == null || _raceToView == "elyo")
                            {
                                node = nodeToAdd.Nodes["pc_light"];
                                AddQuestToRace(node, questNode);
                            }
                            if (_raceToView == null || _raceToView == "asmodian")
                            {
                                node = nodeToAdd.Nodes["pc_dark"];
                                AddQuestToRace(node, questNode);
                            }
                        }
                    }
                });
                Thread.Sleep(1);
            }

            writer.Close();

            if (addedNew)
            {
                try {
                    using (FileStream fs = new FileStream(Path.Combine(root, @".\dialogs\quests.dat"), FileMode.Create)) {
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(fs, questFiles);
                    }
                } catch (Exception e) {
                }
            }

            // Done
            InvokeIfRequired(() =>
            {
                statusProgressBar.Value = statusProgressBar.Maximum;
                statusLabel.Text        = String.Empty;
                ToggleProgressBar(false);
            });
        }
Esempio n. 2
0
        void LoadFiles(object filePaths)
        {
            List<string> files = (List<string>)filePaths;

            InvokeIfRequired(() =>
            {
                this.Cursor = Cursors.WaitCursor;
                statusProgressBar.Maximum = files.Count;
                ToggleProgressBar(true);
            });

            // Load HTML files

            // Step 0
            ResetProgress(LOAD_STEPS, Program.IniReader["loading"] + " Html's...");

            if (File.Exists(Path.Combine(root, @".\dialogs\quests.dat"))) {
                try {
                    using (FileStream fs = new FileStream(Path.Combine(root, @".\dialogs\quests.dat"), FileMode.Open)) {
                        BinaryFormatter bf = new BinaryFormatter();
                        questFiles = (QuestDictionary)bf.Deserialize(fs);
                    }
                } catch { }
            }
            if (questFiles == null)
                questFiles = new QuestDictionary();

            bool addedNew = false;

            ResetProgress(questFiles.Count, String.Empty);

            for (int i = 0; i < files.Count; i++) {
                string name = Path.GetFileName(files[i]);
                if (!name.StartsWith("quest_"))
                    continue;
                string qId = Path.GetFileNameWithoutExtension(Path.GetFileName(files[i]))
                                 .Remove(0, 7).Trim();
                int id;
                if (!Int32.TryParse(qId, out id))
                    continue;
                if (_raceToView == "elyo" && id >= 2000 && id < 3000)
                    continue;
                if (_raceToView == "asmodian" && id < 2000)
                    continue;
                string msg = String.Format(Program.IniReader["loading"] + " {0}...", Path.GetFileName(files[i]));
                InvokeIfRequired(() => { statusLabel.Text = msg; });
                if (!questFiles.ContainsKey(id)) {
                    addedNew = true;
                    QuestFile questFile;
                    if (Utility.TryLoadQuestHtml(files[i], out questFile))
                        questFiles.Add(id, questFile);
                }
                InvokeIfRequired(() => { statusProgressBar.Value = i + 1; });
                Thread.Sleep(1);
            }

            try {
                using (var fs = new FileStream(Path.Combine(root, @".\dialogs\HtmlPages.xml"),
                                               FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(fs)) {
                    XmlSerializer ser = new XmlSerializer(typeof(HtmlPageIndex));
                    HtmlPage.Index = (HtmlPageIndex)ser.Deserialize(reader);
                    HtmlPage.Index.CreateIndex();
                }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 1
            ResetProgress(LOAD_STEPS, Program.IniReader["loading"] + " HyperLinks.xml...");

            try {
                using (var fs = new FileStream(Path.Combine(root, @".\dialogs\HyperLinks.xml"),
                                               FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(fs)) {
                    XmlSerializer ser = new XmlSerializer(typeof(HyperLinkIndex));
                    SelectsAct.Index = (HyperLinkIndex)ser.Deserialize(reader);
                    SelectsAct.Index.CreateIndex();
                }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 2
            ShowProgress(Program.IniReader["loadingStrings"] + "...");
            Utility.LoadStrings(root);

            // Step 3
            ShowProgress(Program.IniReader["loadingNpc"] + "...");
            Utility.LoadNpcs(root);

            // Step 4
            ShowProgress(Program.IniReader["loadingQuestData"] + "...");
            try {
                using (var fs = new FileStream(Path.Combine(root, @".\quest\quest.xml"),
                                               FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(fs)) {
                    XmlSerializer ser = new XmlSerializer(typeof(QuestsFile));
                    questData = (QuestsFile)ser.Deserialize(reader);
                    questData.CreateIndex();
                }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 5
            ShowProgress(Program.IniReader["loadingItemData"] + "...");
            Utility.LoadItems(root);

            /*
            InvBonuses bonuses = new InvBonuses();
            bonuses.BonusItems = new List<BonusItem>();
            foreach (var q in questData.QuestList) {
                WrapItem wi = null;
                if (q.reward_item_ext_1 != null && q.reward_item_ext_1.StartsWith("wrap_")) {
                    wi = new WrapItem();
                    string[] itemData = q.reward_item_ext_1.Split(' ');
                    Item item = Utility.ItemIndex.GetItem(itemData[0]);
                    if (item == null)
                        wi.itemId = 0;
                    else
                        wi.itemId = item.id;
                    if (itemData[0].Contains("_enchant_"))
                        wi.type = BonusType.ENCHANT;
                    else
                        wi.type = BonusType.MANASTONE;
                    string lvl = itemData[0].Substring(itemData[0].Length - 3, 2);
                    wi.level = Int32.Parse(lvl);
                }
                if (q.HasRandomRaward()) {
                    BonusItem bi = new BonusItem();
                    bi.questId = q.id;
                    bi.BonusInfos = new List<BonusInfo>();
                    if (q.reward_item1_1 != null && q.reward_item1_1.StartsWith("%Quest_")) {
                        BonusInfo bii = new BonusInfo();
                        if (q.check_item1_1 != null) {
                            string[] itemData = q.check_item1_1.Split(' ');
                            bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
                            bii.checkItemSpecified = true;
                            bii.count = Int32.Parse(itemData[1]);
                            bii.countSpecified = true;
                        }
                        bii.Value = q.reward_item1_1;
                        bi.BonusInfos.Add(bii);
                    }
                    if (q.reward_item1_2 != null && q.reward_item1_2.StartsWith("%Quest_")) {
                        BonusInfo bii = new BonusInfo();
                        if (q.check_item1_2 != null) {
                            string[] itemData = q.check_item1_2.Split(' ');
                            bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
                            bii.checkItemSpecified = true;
                            bii.count = Int32.Parse(itemData[1]);
                            bii.countSpecified = true;
                        }
                        bii.Value = q.reward_item1_2;
                        bi.BonusInfos.Add(bii);
                    }
                    if (q.reward_item1_3 != null && q.reward_item1_3.StartsWith("%Quest_")) {
                        BonusInfo bii = new BonusInfo();
                        if (q.check_item1_3 != null) {
                            string[] itemData = q.check_item1_3.Split(' ');
                            bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
                            bii.checkItemSpecified = true;
                            bii.count = Int32.Parse(itemData[1]);
                            bii.countSpecified = true;
                        }
                        bii.Value = q.reward_item1_3;
                        bi.BonusInfos.Add(bii);
                    }
                    if (wi != null) {
                        bi.wrap = wi;
                        bi.wrapSpecified = true;
                    }
                    bonuses.BonusItems.Add(bi);
                } else if (wi != null) {
                    BonusItem bi = new BonusItem();
                    bi.questId = q.id;
                    bi.wrap = wi;
                    bi.wrapSpecified = true;
                    bonuses.BonusItems.Add(bi);
                }
            }

            XmlWriterSettings set = new XmlWriterSettings()
            {
                CloseOutput = false,
                Encoding = Encoding.UTF8,
                Indent = true,
                IndentChars = "\t",
            };
            using (FileStream stream = new FileStream("bonuses.xml", FileMode.Create, FileAccess.Write)) {
                using (XmlWriter wr = XmlWriter.Create(stream, set)) {
                    XmlSerializer ser = new XmlSerializer(typeof(InvBonuses));
                    ser.Serialize(wr, bonuses);
                }
            }
            */

            // Step 6
            ResetProgress(questFiles.Count, String.Empty);

            InvokeIfRequired(() =>
            {
                try {
                    this.Cursor = Cursors.Default;

                    foreach (int level in questData.Levels) {
                        var lvlNode = rootNode.Nodes.Add(level.ToString(),
                                        String.Format(Program.IniReader["level"] + " {0}", level));
                        TreeNode raceNode = null;
                        if (String.IsNullOrEmpty(_raceToView) || _raceToView == "elyo")
                            raceNode = lvlNode.Nodes.Add("pc_light", Program.IniReader["elyo"]);
                        if (String.IsNullOrEmpty(_raceToView) || _raceToView == "asmodian")
                            raceNode = lvlNode.Nodes.Add("pc_dark", Program.IniReader["asmodian"]);
                        Application.DoEvents();
                    }

                    rootNode.Nodes.Add("0", Program.IniReader["misc"]);
                    rootNode.Expand();
                } catch { }
            });

            var writer = new StreamWriter("quests.txt");

            foreach (KeyValuePair<int, QuestFile> quest in questFiles) {
                HtmlPage summary = quest.Value.HtmlPages.Where(p => p.name == "quest_summary")
                                                        .FirstOrDefault();
                Quest questInfo = null;
                string qName = "Q" + quest.Key.ToString();

                ShowProgress(String.Format(Program.IniReader["parsing"] + " {0}", quest.Value.fileName));

                var title = Utility.StringIndex.GetStringDescription("STR_QUEST_NAME_" + qName);

                questInfo = questData["Q" + quest.Key];
                if (questInfo == null) {
                    Debug.Print("Missing data for: {0}", quest.Value.fileName);
                    questInfo = new Quest();
                }

                //if (!questInfo.HasRandomRaward())
                //    continue;

                questInfo.HtmlPages = quest.Value.HtmlPages;
                bool reconstructed = false;

                if (summary == null) {
                    Debug.Print("Quest: {0} doesn't contain summary", quest.Value.fileName);
                    if (title == null) {
                        continue;
                    }
                    Debug.Print("Quest Title: {0}", title.body);
                    summary = new HtmlPage() { name = "quest_summary" };
                    summary.Content = new Contents()
                    {
                        html = new ContentsHtml()
                        {
                            body = new Body()
                            {
                                steps = new Step[] { new Step() },
                                p = new Paragraph[] { new Paragraph() }
                            }
                        }
                    };
                    Paragraph para = summary.Content.html.body.p[0];
                    para.font = new pFont()
                    {
                        font_xml = "quest_summary",
                        Value = String.Empty
                    };

                    if (String.IsNullOrEmpty(questInfo.extra_category)) {
                        questInfo.extra_category = "devanion_quest";
                        Debug.Print("Quest: {0} extra_category is null", quest.Value.fileName);
                    }

                    CultureInfo ci = new CultureInfo(String.Empty);
                    string tit = ci.TextInfo.ToTitleCase(questInfo.extra_category.Replace('_', ' '));
                    para.font.Value = tit;

                    Step singleStep = summary.Content.html.body.steps[0];
                    singleStep.p = new Paragraph()
                    {
                        font = new pFont() { Value = Program.IniReader["step"] + " 1" }
                    };

                    // Include Quest Complete page too
                    var qc = quest.Value.HtmlPages.Where(p => p.name == "quest_complete").FirstOrDefault();
                    if (qc != null)
                        qc.ForceInclude = true;

                    quest.Value.HtmlPages.Add(summary);
                    reconstructed = true;
                }
                if (!reconstructed) {
                    if (summary.Content == null) {
                        Debug.Print("Quest: {0} summary doesn't contain content", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html == null) {
                        Debug.Print("Quest: {0} summary doesn't contain html", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html.body == null) {
                        Debug.Print("Quest: {0} summary doesn't contain body", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html.body.steps == null) {
                        Debug.Print("Quest: {0} summary doesn't contain steps", quest.Value.fileName);
                        continue;
                    }
                }

                if (title == null) {
                    Debug.Print("Quest: {0} has no title", quest.Value.fileName);
                    summary.QuestTitle = qName;
                } else {
                    summary.QuestTitle = title.body;
                }

                TreeNode questNode = new TreeNode(summary.QuestTitle);
                questNode.Name = qName;
                questNode.Tag = questInfo;

                writer.WriteLine(String.Format("{0}\t{1}", qName.Remove(0, 1), summary.QuestTitle));
                writer.Flush();

                int i = 0;
                foreach (Step step in summary.Content.html.body.steps) {
                    // [%collectitem]
                    // step.Value
                    i++;
                    if (String.IsNullOrEmpty(step.Value)) {
                        // ok
                    } else if (step.Value == "[%collectitem]") {
                    }

                    if (String.IsNullOrEmpty(step.p.font.Value)) {
                        Debug.Print("Empty step {0}", i);
                        continue;
                    }

                    step.Number = i;
                    var stepNode = questNode.Nodes.Add("S" + i.ToString(),
                                          String.Format(Program.IniReader["step"] + " {0}", i));
                    stepNode.Tag = step;
                    Thread.Sleep(1);
                }

                TreeNode nodeToAdd = null;

                InvokeIfRequired(() =>
                {
                    if (questInfo.minlevel_permitted == 0) {
                        nodeToAdd = rootNode.Nodes["0"];
                        nodeToAdd.Nodes.Add(questNode);
                        Application.DoEvents();
                    } else {
                        nodeToAdd = rootNode.Nodes[questInfo.minlevel_permitted.ToString()];
                        if (questInfo.race_permitted == "pc_light" &&
                            (_raceToView == null || _raceToView == "elyo")) {
                            nodeToAdd = nodeToAdd.Nodes["pc_light"];
                            AddQuestToRace(nodeToAdd, questNode);
                        } else if (questInfo.race_permitted == "pc_dark" &&
                                   (_raceToView == null || _raceToView == "asmodian")) {
                            nodeToAdd = nodeToAdd.Nodes["pc_dark"];
                            AddQuestToRace(nodeToAdd, questNode);
                        } else {
                            TreeNode node = null;
                            if (_raceToView == null || _raceToView == "elyo") {
                                node = nodeToAdd.Nodes["pc_light"];
                                AddQuestToRace(node, questNode);
                            }
                            if (_raceToView == null || _raceToView == "asmodian") {
                                node = nodeToAdd.Nodes["pc_dark"];
                                AddQuestToRace(node, questNode);
                            }
                        }
                    }
                });
                Thread.Sleep(1);
            }

            writer.Close();

            if (addedNew) {
                try {
                    using (FileStream fs = new FileStream(Path.Combine(root, @".\dialogs\quests.dat"), FileMode.Create)) {
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(fs, questFiles);
                    }
                } catch (Exception e) {
                }
            }

            // Done
            InvokeIfRequired(() =>
            {
                statusProgressBar.Value = statusProgressBar.Maximum;
                statusLabel.Text = String.Empty;
                ToggleProgressBar(false);
            });
        }