Example #1
0
        public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false)
        {
            var ret = new BinaryStateLoader();

            using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                byte[] data = new byte[4];
                fs.Read(data, 0, 4);
                if (!data.SequenceEqual(zipheader))
                    return null;
            }

            try
            {
                ret._zip = new ZipFile(filename);
                ret.PopulateEntries();
                if (!isMovieLoad && !ret.GetLump(BinaryStateLump.Versiontag, false, ret.ReadVersion))
                {
                    ret._zip.Close();
                    return null;
                }

                return ret;
            }
            catch (ZipException)
            {
                return null;
            }
        }
Example #2
0
        public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false)
        {
            var ret = new BinaryStateLoader();

            // PORTABLE TODO - SKIP THIS.. FOR NOW
            // check whether its an archive before we try opening it
            bool isArchive;
            using (var archiveChecker = new SevenZipSharpArchiveHandler())
            {
                int offset;
                bool isExecutable;
                isArchive = archiveChecker.CheckSignature(filename, out offset, out isExecutable);
            }

            if (!isArchive)
            {
                return null;
            }

            try
            {
                ret._zip = new ZipFile(filename);
                ret.PopulateEntries();
                if (!isMovieLoad && !ret.GetLump(BinaryStateLump.Versiontag, false, ret.ReadVersion))
                {
                    ret._zip.Close();
                    return null;
                }

                return ret;
            }
            catch (ZipException)
            {
                return null;
            }
        }