示例#1
0
        public static Archive LoadArchive(string filePath)
        {
            FileInfo fileInfo = new FileInfo(filePath);
            Archive  arc      = null;

            // Checks if the file even exist.
            if (!File.Exists(fileInfo.FullName))
            {
                throw new FileNotFoundException("The given archive does not exist.");
            }

            // Checks if the file is not empty.
            if (fileInfo.Length == 0)
            {
                throw new Exception("The given file is empty.");
            }

            // Addons
            foreach (var addon in Addon.Addons)
            {
                foreach (var archive in addon.Archives)
                {
                    if (archive.FileExtensions.Contains(fileInfo.Extension))
                    {
                        arc = Activator.CreateInstance(archive.ArchiveType) as Archive;
                        arc.Load(filePath);
                        return(arc);
                    }
                }
            }

            // TODO: Add support for other types of archive.
            if (fileInfo.Extension == GensArchive.Extension ||
                fileInfo.Extension == GensArchive.SplitExtension ||
                fileInfo.Extension == GensArchive.PFDExtension ||
                fileInfo.Extension == GensArchive.ListExtension)
            {
                arc = new GensArchive();
            }
            else if (fileInfo.Extension == LWArchive.Extension)
            {
                arc = new LWArchive();
            }
            else if (fileInfo.Extension == ONEArchive.Extension)
            {
                // I know This is a horrible way of checking between archives.
                if (File.ReadAllBytes(fileInfo.FullName)[3] == 0x00)
                {
                    arc = new ONEArchive();
                }
                else
                {
                    arc = new SBArchive();
                }
            }
            else
            {
                throw new Exception("The given archive has an unknown extension.");
            }

            arc.Load(filePath);
            return(arc);
        }