Пример #1
0
        private bool SaveToRPF(string txt)
        {
            if (!(exploreForm?.EditMode ?? false))
            {
                return(false);
            }
            if (rpfFileEntry?.Parent == null)
            {
                return(false);
            }

            byte[] data = null;

            data = Encoding.UTF8.GetBytes(txt);

            if (data == null)
            {
                MessageBox.Show("Unspecified error - data was null!", "Cannot save file");
                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 = "Text 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);
        }
Пример #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);
        }
Пример #3
0
        private void SaveYTD(bool saveas = false)
        {
            if (Ytd == null)
            {
                return;
            }
            if (!(ExploreForm?.EditMode ?? false))
            {
                saveas = true;
            }

            var isinrpf      = false;
            var rpfFileEntry = Ytd.RpfFileEntry;

            if (rpfFileEntry == null)
            {
                saveas = true;
            }
            else
            {
                if (rpfFileEntry?.Parent != null)
                {
                    if (!saveas)
                    {
                        isinrpf = true;
                        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)
                            {
                                saveas  = true;//that was a close one
                                isinrpf = false;
                            }
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(rpfFileEntry?.Path))
                {
                    isinrpf = false; //saving direct to filesystem in RPF explorer...
                }
                else
                {
                    saveas = true;//this probably shouldn't happen
                }
            }

            var data = Ytd.Save();

            if (saveas) //save direct to filesystem in external location
            {
                SaveYTDFileDialog.FileName = FileName;
                if (SaveYTDFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                string fpath = SaveYTDFileDialog.FileName;
                File.WriteAllBytes(fpath, data);
            }
            else if (!isinrpf) //save direct to filesystem in RPF explorer
            {
                File.WriteAllBytes(rpfFileEntry.Path, data);
                ExploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
            }
            else //save to RPF...
            {
                if (!(ExploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false))
                {
                    MessageBox.Show("Unable to save file, RPF encryption needs to be OPEN for this operation!");
                    return;
                }

                Ytd.RpfFileEntry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data);
                ExploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
            }

            Modified = false;
            UpdateStatus("YTD file saved successfully at " + DateTime.Now.ToString());
            UpdateFormTitle();
        }
Пример #4
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);
        }
Пример #5
0
        private bool SaveToRPF(string txt)
        {
            if (!(exploreForm?.EditMode ?? false))
            {
                return(false);
            }
            if (rpfFileEntry?.Parent == null)
            {
                return(false);
            }

            byte[] data = null;

            if (fileType == TextFileType.Text)
            {
                data = Encoding.UTF8.GetBytes(txt);
            }
            else if (fileType == TextFileType.GXT2)
            {
                var gxt = Gxt2File.FromText(txt);
                data = gxt.Save();
            }
            else if (fileType == TextFileType.Nametable)
            {
                if (!txt.EndsWith("\n"))
                {
                    txt = txt + "\n";
                }
                txt = txt.Replace("\r", "");
                var lines = txt.Split('\n');
                foreach (var line in lines)
                {
                    var str = line.Trim();
                    if (string.IsNullOrEmpty(str))
                    {
                        continue;
                    }
                    var strl = str.ToLowerInvariant();
                    JenkIndex.Ensure(strl);
                }
                data = Encoding.UTF8.GetBytes(txt.Replace('\n', '\0'));
            }

            if (data == null)
            {
                MessageBox.Show("Unspecified error - data was null!", "Cannot save file");
                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 = fileType.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);
        }
Пример #6
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);
        }