Exemplo n.º 1
0
        public void LoadMeta(YtypFile ytyp)
        {
            string fn;

            Xml      = MetaXml.GetXml(ytyp, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ytyp;
            rpfFileEntry = ytyp?.RpfFileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (ytyp != null)
            {
                if (ytyp.Meta != null)
                {
                    metaFormat = MetaFormat.RSC;
                }
                if (ytyp.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
                if (ytyp.Rbf != null)
                {
                    metaFormat = MetaFormat.RBF;
                }
            }
        }
Exemplo n.º 2
0
        public void LoadMeta(YmfFile ymf)
        {
            string fn;

            Xml      = MetaXml.GetXml(ymf, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ymf;
            rpfFileEntry = ymf?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (ymf != null)
            {
                if (ymf.Meta != null)
                {
                    metaFormat = MetaFormat.RSC;
                }
                if (ymf.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
                if (ymf.Rbf != null)
                {
                    metaFormat = MetaFormat.RBF;
                }
            }
        }
Exemplo n.º 3
0
        public static string GetXMLFormatName(MetaFormat mformat)
        {
            switch (mformat)
            {
            case MetaFormat.RSC: return("Meta XML");

            case MetaFormat.PSO: return("PSO XML");

            case MetaFormat.RBF: return("RBF XML");

            case MetaFormat.AudioRel: return("REL XML");

            case MetaFormat.Ynd: return("YND XML");

            case MetaFormat.Ynv: return("YNV XML");

            case MetaFormat.Ycd: return("YCD XML");

            case MetaFormat.Ybn: return("YBN XML");

            case MetaFormat.Ytd: return("YTD XML");

            case MetaFormat.Ydr: return("YDR XML");

            case MetaFormat.Ydd: return("YDD XML");

            case MetaFormat.Yft: return("YFT XML");

            case MetaFormat.Ypt: return("YPT XML");

            case MetaFormat.Yld: return("YLD XML");

            case MetaFormat.Yed: return("YED XML");

            case MetaFormat.Ywr: return("YWR XML");

            case MetaFormat.Yvr: return("YVR XML");

            case MetaFormat.Awc: return("AWC XML");

            case MetaFormat.CacheFile: return("CacheFile XML");

            case MetaFormat.Heightmap: return("Heightmap XML");

            case MetaFormat.Ypdb: return("YPDB XML");

            default: return("XML");
            }
        }
Exemplo n.º 4
0
        public void LoadMeta(CacheDatFile cachedat)
        {
            var fn = ((cachedat?.FileEntry?.Name) ?? "") + ".xml";

            Xml      = cachedat.GetXml();
            FileName = fn;
            RawPropertyGrid.SelectedObject = cachedat;
            rpfFileEntry = cachedat?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (cachedat?.FileEntry != null)
            {
                metaFormat = MetaFormat.CacheFile;
            }
        }
Exemplo n.º 5
0
        public void LoadMeta(YndFile ynd)
        {
            var fn = ((ynd?.RpfFileEntry?.Name) ?? "") + ".xml";

            Xml      = MetaXml.GetXml(ynd, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = ynd;
            rpfFileEntry = ynd?.RpfFileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (ynd?.RpfFileEntry != null)
            {
                metaFormat = MetaFormat.Ynd;
            }
        }
Exemplo n.º 6
0
        public void LoadMeta(HeightmapFile heightmap)
        {
            var fn = ((heightmap?.RpfFileEntry?.Name) ?? "") + ".xml";

            Xml      = HmapXml.GetXml(heightmap);
            FileName = fn;
            RawPropertyGrid.SelectedObject = heightmap;
            rpfFileEntry = heightmap?.RpfFileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (heightmap?.RpfFileEntry != null)
            {
                metaFormat = MetaFormat.Heightmap;
            }
        }
Exemplo n.º 7
0
        public void LoadMeta(CutFile cut)
        {
            string fn;

            Xml      = MetaXml.GetXml(cut, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = cut;
            rpfFileEntry = cut?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (cut != null)
            {
                if (cut.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
            }
        }
Exemplo n.º 8
0
        public void LoadMeta(JPsoFile jpso)
        {
            string fn;

            Xml      = MetaXml.GetXml(jpso, out fn);
            FileName = fn;
            RawPropertyGrid.SelectedObject = jpso;
            rpfFileEntry = jpso?.FileEntry;
            modified     = false;
            metaFormat   = MetaFormat.XML;
            if (jpso != null)
            {
                if (jpso.Pso != null)
                {
                    metaFormat = MetaFormat.PSO;
                }
            }
        }
Exemplo n.º 9
0
        private void SaveDocument(bool saveAs = false)
        {
            if ((metaFormat != MetaFormat.XML) && (saveAs == false))
            {
                var doc = new XmlDocument();
                try
                {
                    doc.LoadXml(xml);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("There's something wrong with your XML document:\r\n" + ex.Message, "Unable to parse XML");
                    return;
                }
                if (SaveMeta(doc))
                {
                    return;
                }
                //if Meta saving failed for whatever reason, fallback to saving the XML in the filesystem.
                saveAs = true;
            }

            if (string.IsNullOrEmpty(FileName))
            {
                saveAs = true;
            }
            if (string.IsNullOrEmpty(FilePath))
            {
                saveAs = true;
            }
            else if ((FilePath.ToLowerInvariant().StartsWith(GTAFolder.CurrentGTAFolder.ToLowerInvariant())))
            {
                saveAs = true;
            }
            if (!File.Exists(FilePath))
            {
                saveAs = true;
            }

            var fn = FilePath;

            if (saveAs)
            {
                if (!string.IsNullOrEmpty(fn))
                {
                    var dir = new FileInfo(fn).DirectoryName;
                    if (!Directory.Exists(dir))
                    {
                        dir = "";
                    }
                    SaveFileDialog.InitialDirectory = dir;
                }
                SaveFileDialog.FileName = FileName;
                if (SaveFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                fn = SaveFileDialog.FileName;
            }

            File.WriteAllText(fn, xml);

            modified   = false;
            FilePath   = fn;
            FileName   = new FileInfo(fn).Name;
            metaFormat = MetaFormat.XML;
        }
Exemplo n.º 10
0
        public void LoadRel(RelFile rel)
        {
            fileName = rel?.Name;
            if (string.IsNullOrEmpty(fileName))
            {
                fileName = rel?.RpfFileEntry?.Name;
            }

            UpdateFormTitle();

            RelPropertyGrid.SelectedObject = rel;

            CurrentFile = rel;

            rpfFileEntry = rel?.RpfFileEntry;

            Xml = RelXml.GetXml(rel);

            metaFormat = MetaFormat.AudioRel;

            StringBuilder sb = new StringBuilder();

            if (rel != null)
            {
                if (rel.NameTable != null)
                {
                    sb.AppendLine("NameTable - " + rel.NameTable.Length.ToString() + " entries");
                    foreach (var name in rel.NameTable)
                    {
                        sb.AppendLine(name);
                    }
                    sb.AppendLine();
                }
                if (rel.IndexStrings != null)
                {
                    sb.AppendLine("IndexStrings - " + rel.IndexStrings.Length.ToString() + " entries");
                    foreach (var rstr in rel.IndexStrings)
                    {
                        sb.AppendLine(rstr.Name);
                    }
                    sb.AppendLine();
                }
                if (rel.IndexHashes != null)
                {
                    sb.AppendLine("IndexHashes - " + rel.IndexHashes.Length.ToString() + " entries");
                    foreach (var rhash in rel.IndexHashes)
                    {
                        uint h    = rhash.Name;
                        var  jstr = JenkIndex.TryGetString(h);
                        if (!string.IsNullOrEmpty(jstr))
                        {
                            sb.AppendLine(jstr);
                        }
                        else
                        {
                            sb.AppendLine("0x" + h.ToString("X").PadLeft(8, '0'));
                        }
                    }
                    sb.AppendLine();
                }
            }
            MainTextBox.Text = sb.ToString();
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns>localId=serverId pair</returns>
        private string ApplyAddOrReplaceCommand(SyncMLUpdateBase command)
        {
            if (command == null)
            {
                return(null);
            }

            bool isBase64     = false;
            bool isAddCommand = false;

            SyncMLMeta commandMeta = command.Meta;
            SyncMLItem commandItem = command.ItemCollection[0]; //assuming there is always one item.

            if (String.IsNullOrEmpty(commandMeta.Content) && (!commandMeta.Xml.HasElements))
            {
                commandMeta = commandItem.Meta;
            }

            MetaParser metaParser = new MetaParser(commandMeta.Xml);
            MetaFormat metaFormat = metaParser.GetMetaFormat();

            if (metaFormat != null)
            {
                isBase64 = metaFormat.Content == "b64";
            }

            MetaType metaType = metaParser.GetMetaType();

            if (metaType == null)
            {
                return(null); //the meta element may be empty, so no need to proceed.
            }

            //    if (contentType == ContactExchangeType.Unknown)
            //todo: add some exception        throw new LocalDataSourceException("expected data is Base64 encoded SIF-C or vCard");

            isAddCommand = command is SyncMLAdd;

            //Assuming there will be only one item.
            string serverId;
            string localId = null;

            serverId = commandItem.Source.LocURI.Content; //id of remote one

            if (!isAddCommand)
            {
                localId = commandItem.Target.LocURI.Content; // entryId of existing contact
            }
            string text = GetTextFromContent(isBase64, metaType.Content, commandItem.Data.Content);

            if (text != null)
            {
                localId = isAddCommand ? sifAgent.AddItem(text) :
                          sifAgent.ReplaceItem(text, localId);

                return(isAddCommand ? localId + "=" + serverId : null);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 12
0
        }  // using xmlWriter

        /// <summary>
        ///
        /// </summary>
        /// <param name="topElement">the 'Changes' element, to be manipulated</param>
        /// <param name="command"></param>
        private static void WriteAddOrReplaceCommandToXml(XElement topElement, SyncMLUpdateBase command)
        {
            if (command == null)
            {
                return;
            }

            bool isBase64 = false;
            ContactExchangeType contentType = ContactExchangeType.Unknown;
            bool isAddCommand = false;

            string commandTypeStr;

            SyncMLMeta commandMeta = command.Meta;
            SyncMLItem commandItem = command.ItemCollection[0]; //assuming there is always one item.

            if (String.IsNullOrEmpty(commandMeta.Content) && (!commandMeta.Xml.HasElements))
            {
                commandMeta = commandItem.Meta;
            }

            MetaParser metaParser = new MetaParser(commandMeta.Xml);
            MetaFormat metaFormat = metaParser.GetMetaFormat();

            if (metaFormat != null)
            {
                isBase64 = metaFormat.Content == "b64";
            }

            MetaType metaType = metaParser.GetMetaType();

            if (metaType == null)
            {
                return; //the meta element may be empty, so no need to proceed.
            }

            if (metaType.Content == "text/x-s4j-sifc")
            {
                contentType = ContactExchangeType.Sifc;
            }
            else if ((metaType.Content == "text/x-vcard") || (metaType.Content == "text/vcard"))
            {
                contentType = ContactExchangeType.Vcard21;
            }

            if (contentType == ContactExchangeType.Unknown)
            {
                throw new LocalDataSourceException("expected data is Base64 encoded SIF-C or vCard");
            }

            isAddCommand   = command is SyncMLAdd;
            commandTypeStr = isAddCommand ? "New" : "Update";

            //Assuming there will be only one item.
            string id;

            if (isAddCommand)
            {
                id = commandItem.Source.LocURI.Content;
            }
            else
            {
                id = commandItem.Target.LocURI.Content;
            }

            XElement cItem     = new XElement("C", new XAttribute("ID", id));
            XElement changItem = new XElement(commandTypeStr, cItem);

            topElement.Add(changItem);

            switch (contentType)
            {
            case ContactExchangeType.Sifc:     // do not need to check isBase64, because it must be
                cItem.Add(XElement.Parse(Utility.ConvertFromBase64(commandItem.Data.Content)));
                break;

            case ContactExchangeType.Vcard21:
                XElement sifcXml;
                if (isBase64)
                {
                    sifcXml = VCardSIFC.ConvertVCardToSifCXml(VCardReader.ParseText(
                                                                  Utility.ConvertFromBase64(commandItem.Data.Content)));
                }
                else
                {
                    sifcXml = VCardSIFC.ConvertVCardToSifCXml(VCardReader.ParseText(commandItem.Data.Content));
                }

                cItem.Add(sifcXml);
                break;

            default:
                throw new LocalDataSourceException("Can not create stream from command Data.");
            }
        }
Exemplo n.º 13
0
        public static byte[] GetData(XmlDocument doc, MetaFormat mformat, string fpathin)
        {
            switch (mformat)
            {
            case MetaFormat.RSC:
                return(GetRSCData(doc));

            case MetaFormat.PSO:
                return(GetPSOData(doc));

            case MetaFormat.RBF:
                return(GetRBFData(doc));

            case MetaFormat.AudioRel:
                return(GetRelData(doc));

            case MetaFormat.Ynd:
                return(GetYndData(doc));

            case MetaFormat.Ynv:
                return(GetYnvData(doc));

            case MetaFormat.Ycd:
                return(GetYcdData(doc));

            case MetaFormat.Ybn:
                return(GetYbnData(doc));

            case MetaFormat.Ytd:
                return(GetYtdData(doc, fpathin));

            case MetaFormat.Ydr:
                return(GetYdrData(doc, fpathin));

            case MetaFormat.Ydd:
                return(GetYddData(doc, fpathin));

            case MetaFormat.Yft:
                return(GetYftData(doc, fpathin));

            case MetaFormat.Ypt:
                return(GetYptData(doc, fpathin));

            case MetaFormat.Yld:
                return(GetYldData(doc, fpathin));

            case MetaFormat.Yed:
                return(GetYedData(doc, fpathin));

            case MetaFormat.Ywr:
                return(GetYwrData(doc, fpathin));

            case MetaFormat.Yvr:
                return(GetYvrData(doc, fpathin));

            case MetaFormat.Awc:
                return(GetAwcData(doc, fpathin));

            case MetaFormat.CacheFile:
                return(GetCacheFileData(doc));

            case MetaFormat.Heightmap:
                return(GetHeightmapData(doc));

            case MetaFormat.Ypdb:
                return(GetYpdbData(doc));
            }
            return(null);
        }
Exemplo n.º 14
0
        public void LoadRel(RelFile rel)
        {
            fileName = rel?.Name;
            if (string.IsNullOrEmpty(fileName))
            {
                fileName = rel?.RpfFileEntry?.Name;
            }

            UpdateFormTitle();

            RelPropertyGrid.SelectedObject = rel;

            CurrentFile = rel;

            rpfFileEntry = rel?.RpfFileEntry;

            Xml = RelXml.GetXml(rel);

            metaFormat = MetaFormat.AudioRel;

            StringBuilder sb = new StringBuilder();

            if (rel != null)
            {
                if (rel.NameTable != null)
                {
                    sb.AppendLine("NameTable - " + rel.NameTable.Length.ToString() + " entries");
                    foreach (var name in rel.NameTable)
                    {
                        sb.AppendLine(name);
                    }
                    sb.AppendLine();
                }
                if (rel.IndexStrings != null)
                {
                    sb.AppendLine("IndexStrings - " + rel.IndexStrings.Length.ToString() + " entries");
                    foreach (var rstr in rel.IndexStrings)
                    {
                        sb.AppendLine(rstr.Name);
                    }
                    sb.AppendLine();
                }
                if (rel.IndexHashes != null)
                {
                    sb.AppendLine("IndexHashes - " + rel.IndexHashes.Length.ToString() + " entries");
                    foreach (var rhash in rel.IndexHashes)
                    {
                        uint h    = rhash.Name;
                        var  jstr = JenkIndex.TryGetString(h);
                        if (!string.IsNullOrEmpty(jstr))
                        {
                            sb.AppendLine(jstr);
                        }
                        else
                        {
                            sb.AppendLine("0x" + h.ToString("X").PadLeft(8, '0'));
                        }
                    }
                    sb.AppendLine();
                }
            }
            MainTextBox.Text = sb.ToString();


            SynthsComboBox.Items.Clear();
            SynthTextBox.Language = Language.Custom;
            SynthTextBox.Text     = "";
            SynthTextBox.ClearUndo();
            if (rel.RelType == RelDatFileType.Dat10ModularSynth)
            {
                foreach (var relData in rel.RelDatasSorted)
                {
                    if ((Dat10RelType)relData.TypeID == Dat10RelType.Synth)
                    {
                        SynthsComboBox.Items.Add(relData);
                    }
                }
            }
            else
            {
                MainTabControl.TabPages.Remove(SynthsTabPage);
            }
        }