Пример #1
0
        /// <summary>
        /// Parses string metadata, checking for invalid content.
        /// </summary>
        /// <param name="reader">A binary reader to use to get the data.</param>
        /// <param name="payloadLength">Payload length of the metadata to parse, in bytes.</param>
        /// <param name="allowLineBreaks">If <c>true</c>, line breaks are allowed in the string and preserved; otherwise, line breaks are considered invalid and a string containing one is rejected.</param>
        /// <returns>The string as parsed. If invalid characters are found, an empty string is returned.</returns>
        public static string ParseStringFromMetadata(this INTV.Core.Utility.BinaryReader reader, uint payloadLength, bool allowLineBreaks)
        {
            // PCLs only support UTF-8...
            // LUIGI documentation indicates this could be ASCII or UTF-8 (LUIGI)...
            // ROM metadata spec supports UTF-8 as of jzintv version 1843 and later. Let's hope we don't run into anything *too* weird.
            var bytes        = reader.ReadBytes((int)payloadLength);
            var stringResult = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length).Trim('\0');

            return(stringResult);
        }
Пример #2
0
            /// <inheritdoc />
            protected override LuigiFileHeader GetMemo(string filePath, object data)
            {
                LuigiFileHeader luigiHeader = null;

                try
                {
                    using (var file = StreamUtilities.OpenFileStream(filePath))
                    {
                        var    reader = new INTV.Core.Utility.BinaryReader(file);
                        byte[] header = reader.ReadBytes(MagicKey.Length);
                        if (header.SequenceEqual(MagicKey))
                        {
                            file.Seek(0, System.IO.SeekOrigin.Begin);
                            luigiHeader = LuigiFileHeader.Inflate(file);
                        }
                    }
                }
                catch (Exception)
                {
                    // Just in case the header looks OK, but turns out to be bad.
                }
                return(luigiHeader);
            }