Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public bool SaveMeta(XmlDocument doc)
        {
            //if explorer is in edit mode, and the current RpfFileEntry is valid, convert XML to the
            //current meta format and then save the file into the RPF.
            //otherwise, save the generated file to disk?
            //(currently just return false and revert to XML file save)

            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.RSC:
                    var meta = XmlMeta.GetMeta(doc);
                    if ((meta.DataBlocks?.Data == null) || (meta.DataBlocks.Count == 0))
                    {
                        MessageBox.Show("Schema not supported.", "Cannot import Meta XML");
                        return(false);
                    }
                    data = ResourceBuilder.Build(meta, 2);     //meta is RSC "Version":2    (it's actually a type identifier, not a version!)
                    break;

                case MetaFormat.PSO:
                    var pso = XmlPso.GetPso(doc);
                    if ((pso.DataSection == null) || (pso.DataMapSection == null) || (pso.SchemaSection == null))
                    {
                        MessageBox.Show("Schema not supported.", "Cannot import PSO XML");
                        return(false);
                    }
                    data = pso.Save();
                    break;

                case MetaFormat.RBF:
                    var rbf = XmlRbf.GetRbf(doc);
                    if (rbf.current == null)
                    {
                        MessageBox.Show("Schema not supported.", "Cannot import RBF XML");
                        return(false);
                    }
                    data = rbf.Save();
                    break;

                case MetaFormat.Ynd:
                    var ynd = XmlYnd.GetYnd(doc);
                    if (ynd.NodeDictionary == null)
                    {
                        MessageBox.Show("Schema not supported.", "Cannot import YND XML");
                        return(false);
                    }
                    data = ynd.Save();
                    break;

                case MetaFormat.CacheFile:
                    MessageBox.Show("Sorry, CacheFile import is not supported.", "Cannot import CacheFile XML");
                    return(false);
                }
            }
#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);
        }
Ejemplo n.º 3
0
        public bool SaveMeta(XmlDocument doc)
        {
            //if explorer is in edit mode, and the current RpfFileEntry is valid, convert XML to the
            //current meta format and then save the file into the RPF.
            //otherwise, save the generated file to disk?
            //(currently just return false and revert to XML file save)

            if (!(exploreForm?.EditMode ?? false))
            {
                return(false);
            }

            if (metaFormat == MetaFormat.XML)
            {
                return(false);                            //what are we even doing here?
            }
            byte[] data = null;

#if !DEBUG
            try
#endif
            {
                data = XmlMeta.GetData(doc, metaFormat, string.Empty);

                if (data == null)
                {
                    MessageBox.Show("Schema not supported.", "Cannot import " + XmlMeta.GetXMLFormatName(metaFormat));
                    return(false);
                }
            }
#if !DEBUG
            catch (Exception ex)
            {
                MessageBox.Show("Exception encountered!\r\n" + ex.ToString(), "Cannot convert XML");
                return(false);
            }
#endif

            if (rpfFileEntry?.Parent != null)
            {
                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");
                }
            }
            else if (!string.IsNullOrEmpty(rpfFileEntry?.Path))
            {
                try
                {
                    File.WriteAllBytes(rpfFileEntry.Path, data);

                    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 filesystem!\r\n" + ex.ToString(), "File I/O Error");
                }
            }

            return(false);
        }