示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScFile"/> class.
        /// </summary>
        /// <exception cref="ArgumentException"/>
        public ScFile(ScFormatVersion version)
        {
            if (version < ScFormatVersion.Version7 || version > ScFormatVersion.Version8)
            {
                throw new ArgumentException();
            }

            _version = version;
        }
示例#2
0
        public static ScLoader GetLoader(ScFormatVersion version)
        {
            var type = (Type)null;

            if (!s_version2loader.TryGetValue(version, out type))
            {
                throw new Exception("Unable to find ScLoader for the specified version.");
            }

            return((ScLoader)Activator.CreateInstance(type));
        }
示例#3
0
        /// <summary>
        /// Loads the .sc(<see cref="ScFile"/>) file at the specified path.
        /// </summary>
        /// <param name="path">Path pointing to the .sc file.</param>
        /// <returns>An instance of the <see cref="ScFile"/> representing the specified .sc file.</returns>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="FileNotFoundException"/>
        public static ScFile Load(string path, ScFormatVersion version)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }

            var scFile = new ScFile(version);
            var loader = ScLoader.GetLoader(version);

            using (var fileStream = File.OpenRead(path))
                loader.Load(ref scFile, fileStream);

            return(scFile);
        }