CreateReadStream() public method

public CreateReadStream ( ) : Stream
return Stream
Example #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;
                }
            }
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
0
        private static bool TryFileEMA(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                reader.ReadBytes(8);
                string imgExt = Encoding.ASCII.GetString(reader.ReadBytes(4)).ToLower();
                if ((imgExt == ".bmp") || (imgExt == ".tga"))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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;
        }
Example #10
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;
        }
Example #11
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;
        }
Example #12
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;
        }
Example #13
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;
        }
Example #14
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;
        }
Example #15
0
        private static bool TryFileEMA(ppSubfile subfile)
        {
            using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream()))
            {
                reader.ReadBytes(8);
                string imgExt = Encoding.ASCII.GetString(reader.ReadBytes(4)).ToLower();
                if ((imgExt == ".bmp") || (imgExt == ".tga"))
                {
                    return true;
                }
            }

            return false;
        }
Example #16
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;
        }
Example #17
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);
        }