Ejemplo n.º 1
0
        public static byte[] GetRelData(XmlDocument doc)
        {
            var rel = XmlRel.GetRel(doc);

            if ((rel.RelDatasSorted == null) || (rel.RelDatas == null))
            {
                return(null);
            }
            return(rel.Save());
        }
Ejemplo n.º 2
0
        private bool SaveRel(XmlDocument doc)
        {
            if (!(exploreForm?.EditMode ?? false))
            {
                return(false);
            }
            if (rpfFileEntry?.Parent == null)
            {
                return(false);
            }

            byte[] data = null;

#if !DEBUG
            try
#endif
            {
                switch (metaFormat)
                {
                default:
                case MetaFormat.XML:
                    return(false);   //what are we even doing here?

                case MetaFormat.AudioRel:
                    var rel = XmlRel.GetRel(doc);
                    if ((rel?.RelDatasSorted == null) || (rel.RelDatasSorted.Length == 0))
                    {
                        MessageBox.Show("Schema not supported.", "Cannot import REL XML");
                        return(false);
                    }
                    data = rel.Save();
                    break;
                }
            }
#if !DEBUG
            catch (Exception ex)
            {
                MessageBox.Show("Exception encountered!\r\n" + ex.ToString(), "Cannot convert XML");
                return(false);
            }
#endif
            if (data == null)
            {
                MessageBox.Show("Schema not supported. (Unspecified error - data was null!)", "Cannot convert XML");
                return(false);
            }

            if (!rpfFileEntry.Path.ToLowerInvariant().StartsWith("mods"))
            {
                if (MessageBox.Show("This file is NOT located in the mods folder - Are you SURE you want to save this file?\r\nWARNING: This could cause permanent damage to your game!!!", "WARNING: Are you sure about this?", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return(false);//that was a close one
                }
            }

            try
            {
                if (!(exploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false))
                {
                    return(false);
                }

                var newentry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data);
                if (newentry != rpfFileEntry)
                {
                }
                rpfFileEntry = newentry;

                exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...

                modified = false;

                StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString();

                return(true); //victory!
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error saving file to RPF! The RPF archive may be corrupted...\r\n" + ex.ToString(), "Really Bad Error");
            }

            return(false);
        }