If removed from a ppParser, CreateReadStream() is no longer guaranteed to work. The .pp file may have changed, so you have to transfer the ppSubfile's data when removing.
Inheritance: IReadFile, IWriteFile
Beispiel #1
0
        public static void ExportSubfile([DefaultVar] ppParser parser, string name, string path)
        {
            for (int i = 0; i < parser.Subfiles.Count; i++)
            {
                if (parser.Subfiles[i].Name == name)
                {
                    FileInfo      file = new FileInfo(path);
                    DirectoryInfo dir  = file.Directory;
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }

                    using (FileStream fs = file.Create())
                    {
                        IWriteFile subfile   = parser.Subfiles[i];
                        ppSubfile  ppSubfile = subfile as ppSubfile;
                        if (ppSubfile != null)
                        {
                            ppSubfile.SourceStream = ppSubfile.CreateReadStream();
                        }
                        subfile.WriteTo(fs);
                        if (ppSubfile != null)
                        {
                            ppSubfile.SourceStream = null;
                        }
                    }
                    break;
                }
            }
        }
Beispiel #2
0
        public static List<IWriteFile> ReadHeader(string path)
        {
            List<IWriteFile> subfiles = null;
            using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
            {
                if (!VerifyHeader(path))
                    throw new InvalidDataException("The supplied file is not a PP archive.");

                byte[] versionHeader = reader.ReadBytes(8);
                int version = BitConverter.ToInt32(DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                DecryptHeaderBytes(reader.ReadBytes(1));  // first byte
                int numFiles = BitConverter.ToInt32(DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                byte[] buf = DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

                subfiles = new List<IWriteFile>(numFiles);
                for (int i = 0; i < numFiles; i++)
                {
                    int offset = i * 288;
                    ppSubfile subfile = new ppSubfile(path);
                    subfile.Name = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                    subfile.size = BitConverter.ToUInt32(buf, offset + 260);
                    subfile.offset = BitConverter.ToUInt32(buf, offset + 264);

                    Metadata metadata = new Metadata();
                    metadata.LastBytes = new byte[20];
                    System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                    subfile.Metadata = metadata;

                    subfiles.Add(subfile);
                }
            }
            return subfiles;
        }
Beispiel #3
0
        public static void ExportPP([DefaultVar] ppParser parser, string path)
        {
            if (path == String.Empty)
            {
                path = @".\";
            }
            DirectoryInfo dir = new DirectoryInfo(path);

            if (!dir.Exists)
            {
                dir.Create();
            }

            using (Stream src = File.OpenRead(parser.FilePath))
            {
                for (int i = 0; i < parser.Subfiles.Count; i++)
                {
                    var subfile = parser.Subfiles[i];
                    using (FileStream fs = File.Create(dir.FullName + @"\" + subfile.Name))
                    {
                        ppSubfile ppSubfile = subfile as ppSubfile;
                        if (ppSubfile != null)
                        {
                            src.Position           = ppSubfile.offset;
                            ppSubfile.SourceStream = ppSubfile.ppFormat.ReadStream(new PartialStream(src, ppSubfile.size));
                        }
                        subfile.WriteTo(fs);
                        if (ppSubfile != null)
                        {
                            ppSubfile.SourceStream = null;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public static bool TryFileSVIEX(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            if (subfile.size < 32)
            {
                return(false);
            }
            int version = reader.ReadInt32();

            if (version != 100)
            {
                return(false);
            }
            int numSections = reader.ReadInt32();

            if (numSections < 1 || numSections > 1000)
            {
                return(false);
            }
            version = reader.ReadInt32();
            if (version != 100)
            {
                return(false);
            }
            int lenFirstMesh = reader.ReadInt32();

            if (lenFirstMesh < 1 || lenFirstMesh > 50)
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        void RestoreBackup(string destPath, string backup)
        {
            if (File.Exists(destPath) && File.Exists(backup))
            {
                File.Delete(destPath);

                if (backup != null)
                {
                    File.Move(backup, destPath);

                    if (destPath.Equals(this.FilePath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        for (int i = 0; i < Subfiles.Count; i++)
                        {
                            ppSubfile subfile = Subfiles[i] as ppSubfile;

                            /*if ((subfile != null) && subfile.ppPath.Equals(backup, StringComparison.InvariantCultureIgnoreCase))
                             * {
                             *      subfile.ppPath = this.FilePath;
                             * }*/
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public override List <IWriteFile> ReadHeader(string path, ppFormat format)
        {
            List <IWriteFile> subfiles = null;

            using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
            {
                byte[] versionHeader = reader.ReadBytes(8);
                int    version       = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));                  // first byte
                int    numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);
                byte[] buf      = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

                subfiles = new List <IWriteFile>(numFiles);
                for (int i = 0; i < numFiles; i++)
                {
                    int       offset  = i * 288;
                    ppSubfile subfile = new ppSubfile(path);
                    subfile.ppFormat = format;
                    subfile.Name     = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                    subfile.size     = BitConverter.ToUInt32(buf, offset + 260);
                    subfile.offset   = BitConverter.ToUInt32(buf, offset + 264);

                    Metadata metadata = new Metadata();
                    metadata.LastBytes = new byte[20];
                    System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                    subfile.Metadata = metadata;

                    subfiles.Add(subfile);
                }
            }
            return(subfiles);
        }
Beispiel #7
0
        public List <IWriteFile> ReadHeader(FileStream stream, ppFormat format, byte[] SMFigTable)
        {
            List <IWriteFile> subfiles = null;

            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            DecryptHeaderBytes(binaryReader.ReadBytes(1), SMFigTable);              // first byte
            int numFiles = BitConverter.ToInt32(DecryptHeaderBytes(binaryReader.ReadBytes(4), SMFigTable), 0);

            byte[] buf = DecryptHeaderBytes(binaryReader.ReadBytes(numFiles * 268), SMFigTable);

            subfiles = new List <IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int       offset  = i * 268;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name     = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                subfile.size     = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset   = BitConverter.ToUInt32(buf, offset + 264);
                subfiles.Add(subfile);
            }

            return(subfiles);
        }
Beispiel #8
0
        private static bool TryFileBMP(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf = reader.ReadBytes(2);
            if ((buf[0] == 'B') && (buf[1] == 'M'))
            {
                return(true);
            }

            return(false);
        }
Beispiel #9
0
        private static ppFormat TryFile(ppSubfile subfile, ppFormat[] formats)
        {
            Func <ppSubfile, bool> tryFunc = null;

            string ext = Path.GetExtension(subfile.Name).ToLower();

            if (ext == ".xx")
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileXX);
            }
            else if (ext == ".xa")
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileXA);
            }
            else if (ext == ".bmp")
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileBMP);
            }
            else if (ext == ".tga")
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileTGA);
            }
            else if (ext == ".ema")
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileEMA);
            }
            else if (Utility.ImageSupported(ext))
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileImage);
            }
            else if (ext == ".lst")
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileLst);
            }
            else if (ext == ".wav" || ext == ".ogg")
            {
                tryFunc = new Func <ppSubfile, bool>(TryFileSound);
            }

            if (tryFunc != null)
            {
                for (int i = 0; i < formats.Length; i++)
                {
                    subfile.ppFormat = formats[i];
                    if (tryFunc(subfile))
                    {
                        return(subfile.ppFormat);
                    }
                }
            }

            return(null);
        }
Beispiel #10
0
        private static bool TryFileXX(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf = reader.ReadBytes(5);
            if ((buf[0] >= 0x01) && (BitConverter.ToInt32(buf, 1) == 0))
            {
                return(true);
            }

            return(false);
        }
Beispiel #11
0
        private static bool TryFileXX(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte[] buf = reader.ReadBytes(5);
                if ((buf[0] >= 0x01) && (BitConverter.ToInt32(buf, 1) == 0))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #12
0
        private static bool TryFileXA(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte type = reader.ReadByte();

            if ((type == 0x00) || (type == 0x01) || (type == 0x02) || (type == 0x03))
            {
                return(true);
            }

            return(false);
        }
Beispiel #13
0
        public static bool TryFileSound(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf = reader.ReadBytes(4);
            if (buf[0] == 'O' && buf[1] == 'g' && buf[2] == 'g' && buf[3] == 'S' ||
                buf[0] == 'R' && buf[1] == 'I' && buf[2] == 'F' && buf[3] == 'F')
            {
                return(true);
            }

            return(false);
        }
Beispiel #14
0
        private static bool TryFileBMP(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte[] buf = reader.ReadBytes(2);
                if ((buf[0] == 'B') && (buf[1] == 'M'))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #15
0
        private static bool TryFileXA(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte type = reader.ReadByte();
                if ((type == 0x00) || (type == 0x01) || (type == 0x02) || (type == 0x03))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #16
0
        public static bool TryFileSound(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte[] buf = reader.ReadBytes(4);
                if (buf[0] == 'O' && buf[1] == 'g' && buf[2] == 'g' && buf[3] == 'S' ||
                    buf[0] == 'R' && buf[1] == 'I' && buf[2] == 'F' && buf[3] == 'F')
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #17
0
        private static bool TryFileEMA(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            reader.ReadBytes(8);
            string imgExt = Encoding.ASCII.GetString(reader.ReadBytes(4)).ToLower();

            if ((imgExt == ".bmp") || (imgExt == ".tga"))
            {
                return(true);
            }

            return(false);
        }
Beispiel #18
0
        private static bool TryFileImage(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            try
            {
                byte[] data    = reader.ReadToEnd();
                var    imgInfo = ImageInformation.FromMemory(data);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Beispiel #19
0
        private static bool TryFileImage(ppSubfile subfile)
        {
            try
            {
                using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
                {
                    byte[] data    = reader.ReadToEnd();
                    var    imgInfo = ImageInformation.FromMemory(data);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Beispiel #20
0
        public override List <IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List <IWriteFile> subfiles = null;

            stream.Position = 0;
            BinaryReader reader = new BinaryReader(stream);

            byte[] versionHeader = reader.ReadBytes(8);
            Version = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

            ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));              // first byte
            int numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

            byte[] buf = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

            subfiles = new List <IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int       offset  = i * 288;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                int length = 260;
                for (int j = 0; j < length; j++)
                {
                    if (buf[offset + j] == 0x00)
                    {
                        length = j;
                        break;
                    }
                }
                subfile.Name   = Utility.EncodingShiftJIS.GetString(buf, offset, length);
                subfile.size   = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset = BitConverter.ToUInt32(buf, offset + 264);

                Metadata metadata = new Metadata();
                metadata.LastBytes = new byte[20];
                System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                subfile.Metadata = metadata;

                subfiles.Add(subfile);
            }

            return(subfiles);
        }
Beispiel #21
0
        private static bool TryFileTGA(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf    = reader.ReadBytes(8);
            int    bufSum = 0;

            for (int i = 0; i < buf.Length; i++)
            {
                bufSum += buf[i];
            }

            if ((buf[2] == 0x02) && (bufSum == 0x02))
            {
                return(true);
            }

            return(false);
        }
Beispiel #22
0
        public override List <IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List <IWriteFile> subfiles = null;

            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            int numFiles = binaryReader.ReadInt32();

            subfiles = new List <IWriteFile>(numFiles);
            binaryReader.ReadInt32();              // total size

            // get filenames
            for (int i = 0; i < numFiles; i++)
            {
                byte[] nameBuf = binaryReader.ReadBytes(0x20);
                for (int j = 0; j < nameBuf.Length; j++)
                {
                    nameBuf[j] = (byte)(~nameBuf[j] + 1);
                }

                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name     = Utility.EncodingShiftJIS.GetString(nameBuf).TrimEnd(new char[] { '\0' });
                subfiles.Add(subfile);
            }

            // get filesizes
            uint offset = HeaderSize(numFiles);              // start of first file data

            for (int i = 0; i < numFiles; i++)
            {
                ppSubfile subfile = (ppSubfile)subfiles[i];
                subfile.offset = offset;
                subfile.size   = binaryReader.ReadUInt32();
                offset        += subfile.size;
            }

            return(subfiles);
        }
Beispiel #23
0
        public static List <IWriteFile> ReadHeader(string path)
        {
            List <IWriteFile> subfiles = null;

            using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
            {
                if (!VerifyHeader(path))
                {
                    throw new InvalidDataException("The supplied file is not a PP archive.");
                }

                byte[] versionHeader = reader.ReadBytes(8);
                int    version       = BitConverter.ToInt32(DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                DecryptHeaderBytes(reader.ReadBytes(1));                  // first byte
                int numFiles = BitConverter.ToInt32(DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                byte[] buf = DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

                subfiles = new List <IWriteFile>(numFiles);
                for (int i = 0; i < numFiles; i++)
                {
                    int       offset  = i * 288;
                    ppSubfile subfile = new ppSubfile(path);
                    subfile.Name   = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                    subfile.size   = BitConverter.ToUInt32(buf, offset + 260);
                    subfile.offset = BitConverter.ToUInt32(buf, offset + 264);

                    Metadata metadata = new Metadata();
                    metadata.LastBytes = new byte[20];
                    System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                    subfile.Metadata = metadata;

                    subfiles.Add(subfile);
                }
            }
            return(subfiles);
        }
Beispiel #24
0
        public override List<IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List<IWriteFile> subfiles = null;
            stream.Position = 0;
            BinaryReader reader = new BinaryReader(stream);

            byte[] versionHeader = reader.ReadBytes(8);
            Version = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

            ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));  // first byte
            int numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);
            byte[] buf = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

            subfiles = new List<IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int offset = i * 288;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                int length = 260;
                for (int j = 0; j < length; j++)
                {
                    if (buf[offset + j] == 0x00)
                    {
                        length = j;
                        break;
                    }
                }
                subfile.Name = Utility.EncodingShiftJIS.GetString(buf, offset, length);
                subfile.size = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset = BitConverter.ToUInt32(buf, offset + 264);

                Metadata metadata = new Metadata();
                metadata.LastBytes = new byte[20];
                System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                subfile.Metadata = metadata;

                subfiles.Add(subfile);
            }

            return subfiles;
        }
Beispiel #25
0
        public List<IWriteFile> ReadHeader(FileStream stream, ppFormat format, byte[] SMFigTable)
        {
            List<IWriteFile> subfiles = null;
            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            DecryptHeaderBytes(binaryReader.ReadBytes(1), SMFigTable);  // first byte
            int numFiles = BitConverter.ToInt32(DecryptHeaderBytes(binaryReader.ReadBytes(4), SMFigTable), 0);
            byte[] buf = DecryptHeaderBytes(binaryReader.ReadBytes(numFiles * 268), SMFigTable);

            subfiles = new List<IWriteFile>(numFiles);
            for (int i = 0; i < numFiles; i++)
            {
                int offset = i * 268;
                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                subfile.size = BitConverter.ToUInt32(buf, offset + 260);
                subfile.offset = BitConverter.ToUInt32(buf, offset + 264);
                subfiles.Add(subfile);
            }

            return subfiles;
        }
Beispiel #26
0
        public override List<IWriteFile> ReadHeader(FileStream stream, ppFormat format)
        {
            List<IWriteFile> subfiles = null;
            stream.Position = 0;
            BinaryReader binaryReader = new BinaryReader(stream);

            int numFiles = binaryReader.ReadInt32();

            subfiles = new List<IWriteFile>(numFiles);
            binaryReader.ReadInt32();  // total size

            // get filenames
            for (int i = 0; i < numFiles; i++)
            {
                byte[] nameBuf = binaryReader.ReadBytes(0x20);
                for (int j = 0; j < nameBuf.Length; j++)
                {
                    nameBuf[j] = (byte)(~nameBuf[j] + 1);
                }

                ppSubfile subfile = new ppSubfile(stream.Name);
                subfile.ppFormat = format;
                subfile.Name = Utility.EncodingShiftJIS.GetString(nameBuf).TrimEnd(new char[] { '\0' });
                subfiles.Add(subfile);
            }

            // get filesizes
            uint offset = HeaderSize(numFiles);  // start of first file data
            for (int i = 0; i < numFiles; i++)
            {
                ppSubfile subfile = (ppSubfile)subfiles[i];
                subfile.offset = offset;
                subfile.size = binaryReader.ReadUInt32();
                offset += subfile.size;
            }

            return subfiles;
        }
Beispiel #27
0
        public override List<IWriteFile> ReadHeader(string path, ppFormat format)
        {
            List<IWriteFile> subfiles = null;
            using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
            {
                byte[] versionHeader = reader.ReadBytes(8);
                int version = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);

                ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(1));  // first byte
                int numFiles = BitConverter.ToInt32(ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(4)), 0);
                byte[] buf = ppHeader_SMRetail.DecryptHeaderBytes(reader.ReadBytes(numFiles * 288));

                subfiles = new List<IWriteFile>(numFiles);
                for (int i = 0; i < numFiles; i++)
                {
                    int offset = i * 288;
                    ppSubfile subfile = new ppSubfile(path);
                    subfile.ppFormat = format;
                    subfile.Name = Utility.EncodingShiftJIS.GetString(buf, offset, 260).TrimEnd(new char[] { '\0' });
                    subfile.size = BitConverter.ToInt32(buf, offset + 260);
                    subfile.offset = BitConverter.ToInt32(buf, offset + 264);

                    Metadata metadata = new Metadata();
                    metadata.LastBytes = new byte[20];
                    System.Array.Copy(buf, offset + 268, metadata.LastBytes, 0, 20);
                    subfile.Metadata = metadata;

                    subfiles.Add(subfile);
                }
            }
            return subfiles;
        }
Beispiel #28
0
        private static ppFormat TryFile(ppSubfile subfile, ppFormat[] formats)
        {
            Func<ppSubfile, bool> tryFunc = null;

            string ext = Path.GetExtension(subfile.Name).ToLower();
            if (ext == ".xx")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileXX);
            }
            else if (ext == ".xa")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileXA);
            }
            else if (ext == ".bmp")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileBMP);
            }
            else if (ext == ".tga")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileTGA);
            }
            else if (ext == ".ema")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileEMA);
            }
            else if (Utility.ImageSupported(ext))
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileImage);
            }
            else if (ext == ".lst")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileLst);
            }
            else if (ext == ".wav" || ext == ".ogg")
            {
                tryFunc = new Func<ppSubfile, bool>(TryFileSound);
            }

            if (tryFunc != null)
            {
                for (int i = 0; i < formats.Length; i++)
                {
                    subfile.ppFormat = formats[i];
                    if (tryFunc(subfile))
                    {
                        return subfile.ppFormat;
                    }
                }
            }

            return null;
        }
Beispiel #29
0
        private static ppFormat TryFile(Stream stream, ppSubfile subfile, ppFormat[] formats)
        {
            Func<Stream, ppSubfile, bool> tryFunc = null;

            string ext = Path.GetExtension(subfile.Name).ToLower();
            if (ext == ".xx")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileXX);
            }
            else if (ext == ".xa")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileXA);
            }
            else if (ext == ".svi")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileSVI);
            }
            else if (ext == ".sviex")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileSVIEX);
            }
            else if (ext == ".bmp")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileBMP);
            }
            else if (ext == ".tga")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileTGA);
            }
            else if (ext == ".ema")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileEMA);
            }
            else if (Utility.ImageSupported(ext))
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileImage);
            }
            else if (ext == ".lst")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileLst);
            }
            else if (ext == ".wav" || ext == ".ogg")
            {
                tryFunc = new Func<Stream, ppSubfile, bool>(TryFileSound);
            }

            if (tryFunc != null)
            {
                for (int i = 0; i < formats.Length; i++)
                {
                    subfile.ppFormat = formats[i];
                    stream.Position = subfile.offset;
                    if (tryFunc(subfile.ppFormat.ReadStream(new PartialStream(stream, subfile.size)), subfile))
                    {
                        return subfile.ppFormat;
                    }
                }
            }

            return null;
        }
Beispiel #30
0
        public static bool TryFileSound(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf = reader.ReadBytes(4);
            if (buf[0] == 'O' && buf[1] == 'g' && buf[2] == 'g' && buf[3] == 'S' ||
                buf[0] == 'R' && buf[1] == 'I' && buf[2] == 'F' && buf[3] == 'F')
            {
                return true;
            }

            return false;
        }
Beispiel #31
0
        private static bool TryFileXA(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte type = reader.ReadByte();
                if ((type == 0x00) || (type == 0x01) || (type == 0x02) || (type == 0x03))
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #32
0
        private static bool TryFileImage(ppSubfile subfile)
        {
            try
            {
                using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
                {
                    byte[] data = reader.ReadToEnd();
                    var imgInfo = ImageInformation.FromMemory(data);
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
Beispiel #33
0
        private static bool TryFileXA(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte type = reader.ReadByte();
            if ((type == 0x00) || (type == 0x01) || (type == 0x02) || (type == 0x03))
            {
                return true;
            }

            return false;
        }
Beispiel #34
0
        private static bool TryFileLst(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            try
            {
                byte[] buf = reader.ReadBytes(128);
                int i = 0, numbersInLine = 0, stringsInLine = 0;
                while (i < buf.Length)
                {
                    if (buf[i] == '-')
                    {
                        i++;
                    }
                    int startPos = i;
                    while (i < buf.Length && buf[i] >= '0' && buf[i] <= '9')
                    {
                        i++;
                    }
                    if (i > startPos)
                    {
                        numbersInLine++;
                    }
                    if (buf[i] == '\t')
                    {
                        i++;
                        continue;
                    }
                    else if (buf[i] == '\r')
                    {
                        return (numbersInLine > 0 || stringsInLine > 0) && buf[++i] == '\n';
                    }
                    else
                    {
                        startPos = i;
                        while (i < buf.Length)
                        {
                            if (buf[i] == '\t')
                            {
                                i++;
                                break;
                            }
                            if (buf[i] == '\r')
                            {
                                i++;
                                if (buf[i] == '\n')
                                {
                                    i++;
                                    break;
                                }
                                return false;
                            }
                            if (buf[i] < 0x20 || buf[i] == '\x80' || buf[i] == '\xA0' || buf[i] >= '\xF0')
                            {
                                return false;
                            }
                            if ((buf[i] >= '\x81' && buf[i] <= '\x84' || buf[i] >= '\x87' && buf[i] <= '\x9F' || buf[i] >= '\xE0' && buf[i] <= '\xEF') && i + 1 < buf.Length)
                            {
                                if (buf[i + 1] < '\x40' || buf[i + 1] == '\x7F' || buf[i + 1] > '\xFC')
                                {
                                    return false;
                                }
                                i++;
                            }
                            i++;
                        }
                        if (i > startPos)
                        {
                            stringsInLine++;
                        }
                    }
                }
                if (numbersInLine == 0 && stringsInLine == 0)
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
Beispiel #35
0
        private static bool TryFileLst(ppSubfile subfile)
        {
            try
            {
                using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
                {
                    byte[] buf   = reader.ReadBytes(128);
                    string ascii = Utility.EncodingShiftJIS.GetString(buf);

                    int i = 0, numbersInLine = 0, stringsInLine = 0;
                    while (i < buf.Length)
                    {
                        int startPos = i;
                        while (i < ascii.Length && char.IsDigit(ascii[i]))
                        {
                            i++;
                        }
                        if (i > startPos)
                        {
                            numbersInLine++;
                        }
                        if (ascii[i] == '\t')
                        {
                            i++;
                            continue;
                        }
                        else if (ascii[i] == '\r')
                        {
                            return((numbersInLine > 0 || stringsInLine > 0) && ascii[++i] == '\n');
                        }
                        else
                        {
                            startPos = i;
                            while (i < ascii.Length)
                            {
                                if (ascii[i] == 't')
                                {
                                    i++;
                                    break;
                                }
                                if (ascii[i] == '\r')
                                {
                                    if (ascii[++i] == '\n')
                                    {
                                        break;
                                    }
                                    return(false);
                                }
                                if (char.IsControl(ascii[i]) || (byte)ascii[i] >= (byte)'\xe0')
                                {
                                    return(false);
                                }
                                i++;
                            }
                            if (i > startPos)
                            {
                                stringsInLine++;
                            }
                        }
                    }
                    if (numbersInLine == 0 && stringsInLine == 0)
                    {
                        return(false);
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Beispiel #36
0
        private static bool TryFileXX(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte[] buf = reader.ReadBytes(5);
                if ((buf[0] >= 0x01) && (BitConverter.ToInt32(buf, 1) == 0))
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #37
0
        void writeArchiveWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;
            string           backup = null;

            string dirName = Path.GetDirectoryName(destPath);

            if (dirName == String.Empty)
            {
                dirName = @".\";
            }
            DirectoryInfo dir = new DirectoryInfo(dirName);

            if (!dir.Exists)
            {
                dir.Create();
            }

            if (File.Exists(destPath))
            {
                backup = Utility.GetDestFile(dir, Path.GetFileNameWithoutExtension(destPath) + ".bak", Path.GetExtension(destPath));
                File.Move(destPath, backup);

                if (destPath.Equals(this.FilePath, StringComparison.InvariantCultureIgnoreCase))
                {
                    for (int i = 0; i < Subfiles.Count; i++)
                    {
                        ppSubfile subfile = Subfiles[i] as ppSubfile;
                        if ((subfile != null) && subfile.ppPath.Equals(this.FilePath, StringComparison.InvariantCultureIgnoreCase))
                        {
                            subfile.ppPath = backup;
                        }
                    }
                }
            }

            try
            {
                using (BinaryWriter writer = new BinaryWriter(File.Create(destPath)))
                {
                    writer.BaseStream.Seek(Format.ppHeader.HeaderSize(Subfiles.Count), SeekOrigin.Begin);
                    int      offset   = (int)writer.BaseStream.Position;
                    int[]    sizes    = new int[Subfiles.Count];
                    object[] metadata = new object[Subfiles.Count];

                    for (int i = 0; i < Subfiles.Count; i++)
                    {
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }

                        worker.ReportProgress(i * 100 / Subfiles.Count);

                        ppSubfile subfile = Subfiles[i] as ppSubfile;
                        if ((subfile != null) && (subfile.ppFormat == this.Format))
                        {
                            using (BinaryReader reader = new BinaryReader(File.OpenRead(subfile.ppPath)))
                            {
                                reader.BaseStream.Seek(subfile.offset, SeekOrigin.Begin);

                                int readSteps = subfile.size / Utility.BufSize;
                                for (int j = 0; j < readSteps; j++)
                                {
                                    writer.Write(reader.ReadBytes(Utility.BufSize));
                                }
                                writer.Write(reader.ReadBytes(subfile.size % Utility.BufSize));
                            }
                            metadata[i] = subfile.Metadata;
                        }
                        else
                        {
                            Stream stream = Format.WriteStream(writer.BaseStream);
                            Subfiles[i].WriteTo(stream);
                            metadata[i] = Format.FinishWriteTo(stream);
                        }

                        int pos = (int)writer.BaseStream.Position;
                        sizes[i] = pos - offset;
                        offset   = pos;
                    }

                    if (!e.Cancel)
                    {
                        writer.BaseStream.Seek(0, SeekOrigin.Begin);
                        Format.ppHeader.WriteHeader(writer.BaseStream, Subfiles, sizes, metadata);
                        offset = (int)writer.BaseStream.Position;
                        for (int i = 0; i < Subfiles.Count; i++)
                        {
                            ppSubfile subfile = Subfiles[i] as ppSubfile;
                            if (subfile != null)
                            {
                                subfile.offset = offset;
                                subfile.size   = sizes[i];
                            }
                            offset += sizes[i];
                        }
                    }
                }

                if (e.Cancel)
                {
                    RestoreBackup(destPath, backup);
                }
                else
                {
                    if (destPath.Equals(this.FilePath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        for (int i = 0; i < Subfiles.Count; i++)
                        {
                            ppSubfile subfile = Subfiles[i] as ppSubfile;
                            if ((subfile != null) && subfile.ppPath.Equals(backup, StringComparison.InvariantCultureIgnoreCase))
                            {
                                subfile.ppPath = this.FilePath;
                            }
                        }
                    }
                    else
                    {
                        this.FilePath = destPath;
                    }

                    if ((backup != null) && !keepBackup)
                    {
                        File.Delete(backup);
                    }
                }
            }
            catch (Exception ex)
            {
                RestoreBackup(destPath, backup);
                Utility.ReportException(ex);
            }
        }
Beispiel #38
0
        private static bool TryFileEMA(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            reader.ReadBytes(8);
            string imgExt = Encoding.ASCII.GetString(reader.ReadBytes(4)).ToLower();
            if ((imgExt == ".bmp") || (imgExt == ".tga"))
            {
                return true;
            }

            return false;
        }
Beispiel #39
0
        void writeArchiveWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;
            string           backup = null;

            string dirName = Path.GetDirectoryName(destPath);

            if (dirName == String.Empty)
            {
                dirName = @".\";
            }
            DirectoryInfo dir = new DirectoryInfo(dirName);

            if (!dir.Exists)
            {
                dir.Create();
            }

            if (File.Exists(destPath))
            {
                backup = Utility.GetDestFile(dir, Path.GetFileNameWithoutExtension(destPath), ".bak");
                File.Move(destPath, backup);

                if (destPath.Equals(this.FilePath, StringComparison.InvariantCultureIgnoreCase))
                {
                    foreach (IWriteFile iw in Subfiles)
                    {
                        if (iw is ppSubfile)
                        {
                            ppSubfile subfile = iw as ppSubfile;
                            if (subfile.ppPath.Equals(this.FilePath, StringComparison.InvariantCultureIgnoreCase))
                            {
                                subfile.ppPath = backup;
                            }
                        }
                    }
                }
            }

            try
            {
                using (BinaryWriter writer = new BinaryWriter(File.Create(destPath)))
                {
                    writer.BaseStream.Seek(ppHeader.HeaderSize(Subfiles.Count), SeekOrigin.Begin);
                    long offset = writer.BaseStream.Position;
                    var  Hashes = new MetaIWriteList();

                    for (int i = 0; i < Subfiles.Count; i++)
                    {
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }

                        worker.ReportProgress(i * 100 / Subfiles.Count);

                        System.Diagnostics.Trace.WriteLine(Subfiles[i].Name);

                        if (Subfiles[i] is ppSubfile)
                        {
                            ppSubfile subfile = Subfiles[i] as ppSubfile;
                            using (MD5 md5 = MD5.Create())
                                using (MemoryStream mem = new MemoryStream())
                                    using (BinaryReader reader = new BinaryReader(File.OpenRead(subfile.ppPath)))
                                    {
                                        reader.BaseStream.Seek(subfile.offset, SeekOrigin.Begin);
                                        int bufsize = Utility.EstBufSize(subfile.size);

                                        uint hash = 0;

                                        if (bufsize == 0)
                                        {
                                            Hashes.AddNew(Subfiles[i], hash, 0, subfile.Metadata);
                                            continue;
                                        }

                                        int readSteps = (int)subfile.size / bufsize;

                                        byte[] buf;

                                        for (int j = 0; j < readSteps; j++)
                                        {
                                            buf = reader.ReadBytes(bufsize);

                                            md5.TransformBlock(buf, 0, bufsize, buf, 0);

                                            mem.WriteBytes(buf);
                                        }
                                        int remaining = (int)(subfile.size % bufsize);

                                        buf = reader.ReadBytes(remaining);
                                        md5.TransformFinalBlock(buf, 0, remaining);
                                        mem.WriteBytes(buf);

                                        hash = BitConverter.ToUInt32(md5.Hash, 0);

                                        if (!Hashes.Any(x => x.Hash == hash))
                                        {
                                            writer.Write(mem.ToArray());

                                            Hashes.AddNew(Subfiles[i], hash, (uint)(writer.BaseStream.Position - offset), subfile.Metadata);
                                        }
                                        else
                                        {
                                            var first = Hashes.First(x => x.Hash == hash);

                                            Hashes.AddNew(Subfiles[i], hash, first.Size, first.Metadata);
                                        }
                                    }
                        }
                        else
                        {
                            Stream stream = ppFormat.WriteStream(writer.BaseStream);

                            using (MD5 md5 = MD5.Create())
                                using (MemoryStream mem = new MemoryStream())
                                {
                                    Subfiles[i].WriteTo(mem);

                                    uint hash = BitConverter.ToUInt32(md5.ComputeHash(mem.ToArray()), 0);

                                    if (Hashes.Any(x => x.Hash == hash))
                                    {
                                        var first = Hashes.First(x => x.Hash == hash);
                                        Hashes.AddNew(Subfiles[i], hash, first.Size, first.Metadata);
                                    }
                                    else
                                    {
                                        mem.WriteTo(stream);
                                        object meta = ppFormat.FinishWriteTo(stream);
                                        long   ppos = writer.BaseStream.Position;

                                        Hashes.AddNew(Subfiles[i], hash, (uint)(ppos - offset), meta);
                                    }
                                }
                        }
                        offset = writer.BaseStream.Position;
                    }

                    if (!e.Cancel)
                    {
                        writer.BaseStream.Seek(0, SeekOrigin.Begin);

                        ppHeader.WriteRLEHeader(writer.BaseStream, Hashes);
                    }
                }

                if (e.Cancel)
                {
                    RestoreBackup(destPath, backup);
                }
                else if ((backup != null) && !keepBackup)
                {
                    File.Delete(backup);
                }

                foreach (IWriteFile iw in Subfiles)
                {
                    if (iw is IDisposable)
                    {
                        ((IDisposable)iw).Dispose();
                    }
                }

                //ReloadSubfiles();
            }
            catch (Exception ex)
            {
                RestoreBackup(destPath, backup);
                throw new Exception("PP Parser has encountered an error.", ex);
            }
        }
Beispiel #40
0
        public static bool TryFileSound(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte[] buf = reader.ReadBytes(4);
                if (buf[0] == 'O' && buf[1] == 'g' && buf[2] == 'g' && buf[3] == 'S' ||
                    buf[0] == 'R' && buf[1] == 'I' && buf[2] == 'F' && buf[3] == 'F')
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #41
0
        public static bool TryFileSVIEX(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            if (subfile.size < 32)
            {
                return false;
            }
            int version = reader.ReadInt32();
            if (version != 100)
            {
                return false;
            }
            int numSections = reader.ReadInt32();
            if (numSections < 1 || numSections > 1000)
            {
                return false;
            }
            version = reader.ReadInt32();
            if (version != 100)
            {
                return false;
            }
            int lenFirstMesh = reader.ReadInt32();
            if (lenFirstMesh < 1 || lenFirstMesh > 50)
            {
                return false;
            }

            return true;
        }
Beispiel #42
0
        private static bool TryFileLst(ppSubfile subfile)
        {
            try
            {
                using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
                {
                    byte[] buf = reader.ReadBytes(128);
                    string ascii = Utility.EncodingShiftJIS.GetString(buf);

                    int i = 0, numbersInLine = 0, stringsInLine = 0;
                    while (i < buf.Length)
                    {
                        int startPos = i;
                        while (i < ascii.Length && char.IsDigit(ascii[i]))
                            i++;
                        if (i > startPos)
                            numbersInLine++;
                        if (ascii[i] == '\t')
                        {
                            i++;
                            continue;
                        }
                        else if (ascii[i] == '\r')
                        {
                            return (numbersInLine > 0 || stringsInLine > 0) && ascii[++i] == '\n';
                        }
                        else
                        {
                            startPos = i;
                            while (i < ascii.Length)
                            {
                                if (ascii[i] == 't')
                                {
                                    i++;
                                    break;
                                }
                                if (ascii[i] == '\r')
                                {
                                    if (ascii[++i] == '\n')
                                        break;
                                    return false;
                                }
                                if (char.IsControl(ascii[i]) || (byte)ascii[i] >= (byte)'\xe0')
                                    return false;
                                i++;
                            }
                            if (i > startPos)
                                stringsInLine++;
                        }
                    }
                    if (numbersInLine == 0 && stringsInLine == 0)
                        return false;
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
Beispiel #43
0
        private static bool TryFileBMP(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf = reader.ReadBytes(2);
            if ((buf[0] == 'B') && (buf[1] == 'M'))
            {
                return true;
            }

            return false;
        }
Beispiel #44
0
        private static ppFormat TryFile(Stream stream, ppSubfile subfile, ppFormat[] formats)
        {
            Func <Stream, ppSubfile, bool> tryFunc = null;

            string ext = Path.GetExtension(subfile.Name).ToLower();

            if (ext == ".xx")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileXX);
            }
            else if (ext == ".xa")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileXA);
            }
            else if (ext == ".svi")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileSVI);
            }
            else if (ext == ".sviex")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileSVIEX);
            }
            else if (ext == ".bmp")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileBMP);
            }
            else if (ext == ".tga")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileTGA);
            }
            else if (ext == ".ema")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileEMA);
            }
            else if (Utility.ImageSupported(ext))
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileImage);
            }
            else if (ext == ".lst")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileLst);
            }
            else if (ext == ".wav" || ext == ".ogg")
            {
                tryFunc = new Func <Stream, ppSubfile, bool>(TryFileSound);
            }

            if (tryFunc != null)
            {
                for (int i = 0; i < formats.Length; i++)
                {
                    subfile.ppFormat = formats[i];
                    stream.Position  = subfile.offset;
                    if (tryFunc(subfile.ppFormat.ReadStream(new PartialStream(stream, subfile.size)), subfile))
                    {
                        return(subfile.ppFormat);
                    }
                }
            }

            return(null);
        }
Beispiel #45
0
        private static bool TryFileImage(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            try
            {
                byte[] data = reader.ReadToEnd();
                var imgInfo = ImageInformation.FromMemory(data);
            }
            catch
            {
                return false;
            }

            return true;
        }
Beispiel #46
0
        private static bool TryFileTGA(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte[] buf = reader.ReadBytes(8);
                int bufSum = 0;
                for (int i = 0; i < buf.Length; i++)
                {
                    bufSum += buf[i];
                }

                if ((buf[2] == 0x02) && (bufSum == 0x02))
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #47
0
        private static bool TryFileTGA(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf = reader.ReadBytes(8);
            int bufSum = 0;
            for (int i = 0; i < buf.Length; i++)
            {
                bufSum += buf[i];
            }

            if ((buf[2] == 0x02) && (bufSum == 0x02))
            {
                return true;
            }

            return false;
        }
Beispiel #48
0
        private static bool TryFileLst(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            try
            {
                byte[] buf = reader.ReadBytes(128);
                int    i = 0, numbersInLine = 0, stringsInLine = 0;
                while (i < buf.Length)
                {
                    if (buf[i] == '-')
                    {
                        i++;
                    }
                    int startPos = i;
                    while (i < buf.Length && buf[i] >= '0' && buf[i] <= '9')
                    {
                        i++;
                    }
                    if (i > startPos)
                    {
                        numbersInLine++;
                    }
                    if (buf[i] == '\t')
                    {
                        i++;
                        continue;
                    }
                    else if (buf[i] == '\r')
                    {
                        return((numbersInLine > 0 || stringsInLine > 0) && buf[++i] == '\n');
                    }
                    else
                    {
                        startPos = i;
                        while (i < buf.Length)
                        {
                            if (buf[i] == '\t')
                            {
                                i++;
                                break;
                            }
                            if (buf[i] == '\r')
                            {
                                i++;
                                if (buf[i] == '\n')
                                {
                                    i++;
                                    break;
                                }
                                return(false);
                            }
                            if (buf[i] < 0x20 || buf[i] == '\x80' || buf[i] == '\xA0' || buf[i] >= '\xF0')
                            {
                                return(false);
                            }
                            if ((buf[i] >= '\x81' && buf[i] <= '\x84' || buf[i] >= '\x87' && buf[i] <= '\x9F' || buf[i] >= '\xE0' && buf[i] <= '\xEF') && i + 1 < buf.Length)
                            {
                                if (buf[i + 1] < '\x40' || buf[i + 1] == '\x7F' || buf[i + 1] > '\xFC')
                                {
                                    return(false);
                                }
                                i++;
                            }
                            i++;
                        }
                        if (i > startPos)
                        {
                            stringsInLine++;
                        }
                    }
                }
                if (numbersInLine == 0 && stringsInLine == 0)
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Beispiel #49
0
        private static bool TryFileXX(Stream stream, ppSubfile subfile)
        {
            BinaryReader reader = new BinaryReader(stream);

            byte[] buf = reader.ReadBytes(5);
            if ((buf[0] >= 0x01) && (BitConverter.ToInt32(buf, 1) == 0))
            {
                return true;
            }

            return false;
        }
Beispiel #50
0
        private static bool TryFileBMP(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                byte[] buf = reader.ReadBytes(2);
                if ((buf[0] == 'B') && (buf[1] == 'M'))
                {
                    return true;
                }
            }

            return false;
        }