private static void GetArchiveChildren(string filePath, XmlNode node, ref OIVArchive root)
        {
            foreach (XmlNode subNode in node.ChildNodes)
            {
                if (subNode.Name == "add")
                {
                    root?.Add(filePath + "content\\" + subNode.Attributes.GetNamedItem("source").Value,
                              subNode.InnerText);
                }

                else if (subNode.Name == "archive")
                {
                    var archive = new OIVArchive();

                    archive.Path = subNode.Attributes.GetNamedItem("path").Value;

                    archive.CreateIfNotExist = Convert.ToBoolean(subNode.Attributes.GetNamedItem("createIfNotExist").Value);

                    archive.Version = (RageArchiveType)Enum.Parse(typeof(RageArchiveType), subNode.Attributes.GetNamedItem("type").Value);

                    root.NestedArchives.Add(archive);

                    GetArchiveChildren(filePath, subNode, ref archive);
                }
            }
        }
        private void FinishButtonClick(object sender, CancelEventArgs e)
        {
            string fullPath = textBox1.Text.Trim();

            SaveCommonPath(fullPath);

            fullPath = fullPath.Replace('/', '\\');

            if (fullPath.Length <= 0 || !fullPath.Contains(".rpf"))
            {
                MessageBox.Show("Invalid archive path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (files.Count <= 0)
            {
                MessageBox.Show("No files were selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int startIndex = 0;
            int endIndex   = 0;

            startIndex = fullPath.IndexOf(".rpf") + 4;

            var initialPath = fullPath.Substring(0, startIndex);

            archive.Path = initialPath;

            string subStr = fullPath;

            OIVArchive currentNode = archive;

            for (int i = 1; i < Regex.Matches(fullPath, ".rpf").Count; i++)
            {
                subStr   = subStr.Substring(startIndex, subStr.Length - startIndex);
                endIndex = subStr.IndexOf(".rpf") + 4;
                var subArchivePath = subStr.Substring(0, endIndex).TrimStart('\\');
                startIndex = endIndex;
                var subArchive = new OIVArchive(archive.Version, new List <OIVArchiveFile>(), subArchivePath, false);
                currentNode.NestedArchives.Add(subArchive);
                currentNode = subArchive;
            }

            foreach (var file in files)
            {
                var innerPath = fullPath.Substring(fullPath.LastIndexOf(".rpf") + 4);
                if (innerPath.Length > 0 && !innerPath.EndsWith("\\"))
                {
                    innerPath += "\\";
                }
                currentNode.Add(file, innerPath + file.Substring(file.LastIndexOf("\\") + 1));
            }

            Finished?.Invoke(this, archive);
            Close();
        }