Пример #1
0
        /// <summary>
        /// Guess the file type and format based on its path.
        /// </summary>
        /// <param name="file">The relative asset path.</param>
        /// <param name="type">The file type.</param>
        /// <param name="format">The file format (file ending).</param>
        /// <returns>The passed asset path, trimmed if required.</returns>
        public static string GuessType(string file, out Type type, out string format)
        {
            type   = typeof(object);
            format = file.Length < 4 ? null : file.Substring(file.Length - 3);

            if (file.EndsWith(".dll"))
            {
                type = typeof(AssetTypeAssembly);
            }
            else if (OnGuessType != null)
            {
                // Allow mods to parse custom types.
                Delegate[] ds = OnGuessType.GetInvocationList();
                for (int i = 0; i < ds.Length; i++)
                {
                    Type   typeMod;
                    string formatMod;
                    string fileMod = ((TypeGuesser)ds[i])(file, out typeMod, out formatMod);
                    if (fileMod == null || typeMod == null || formatMod == null)
                    {
                        continue;
                    }
                    file   = fileMod;
                    type   = typeMod;
                    format = formatMod;
                    break;
                }
            }

            return(file);
        }
Пример #2
0
        /// <summary>
        /// Guess the file type and format based on its path.
        /// </summary>
        /// <param name="file">The relative asset path.</param>
        /// <param name="type">The file type.</param>
        /// <param name="format">The file format (file ending).</param>
        /// <returns>The passed asset path, trimmed if required.</returns>
        public static string GuessType(string file, out Type type, out string format)
        {
            type   = typeof(object);
            format = Path.GetExtension(file) ?? "";
            if (format.Length >= 1)
            {
                format = format.Substring(1);
            }

            if (file.EndsWith(".dll"))
            {
                type = typeof(AssetTypeAssembly);
            }
            else if (file.EndsWith(".yaml"))
            {
                type   = typeof(AssetTypeYaml);
                file   = file.Substring(0, file.Length - 5);
                format = ".yml";
            }
            else if (file.EndsWith(".yml"))
            {
                type = typeof(AssetTypeYaml);
                file = file.Substring(0, file.Length - 4);
            }
            else if (OnGuessType != null)
            {
                // Allow mods to parse custom types.
                Delegate[] ds = OnGuessType.GetInvocationList();
                for (int i = 0; i < ds.Length; i++)
                {
                    Type   typeMod;
                    string formatMod;
                    string fileMod = ((TypeGuesser)ds[i])(file, out typeMod, out formatMod);
                    if (fileMod == null || typeMod == null || formatMod == null)
                    {
                        continue;
                    }
                    file   = fileMod;
                    type   = typeMod;
                    format = formatMod;
                    break;
                }
            }

            return(file);
        }
Пример #3
0
            /// <summary>
            /// Guess the file type and format based on its path.
            /// </summary>
            /// <param name="file">The relative asset path.</param>
            /// <param name="type">The file type.</param>
            /// <param name="format">The file format (file ending).</param>
            /// <returns>The passed asset path, trimmed if required.</returns>
            public static string GuessType(string file, out Type type, out string format)
            {
                type   = typeof(object);
                format = Path.GetExtension(file) ?? "";
                if (format.Length >= 1)
                {
                    format = format.Substring(1);
                }

                if (file.EndsWith(".dll"))
                {
                    type = typeof(AssetTypeAssembly);
                }
                else if (file.EndsWith(".png"))
                {
                    type = typeof(Texture2D);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.EndsWith(".obj"))
                {
                    type = typeof(ObjModel);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.EndsWith(".yaml"))
                {
                    type   = typeof(AssetTypeYaml);
                    file   = file.Substring(0, file.Length - 5);
                    format = ".yml";
                }
                else if (file.EndsWith(".yml"))
                {
                    type = typeof(AssetTypeYaml);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.EndsWith(".xml"))
                {
                    type = typeof(AssetTypeXml);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.StartsWith("Dialog/") && file.EndsWith(".txt"))
                {
                    type = typeof(AssetTypeDialog);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.StartsWith("Maps/") && file.EndsWith(".bin"))
                {
                    type = typeof(AssetTypeMap);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.EndsWith(".bank"))
                {
                    type = typeof(AssetTypeBank);
                    file = file.Substring(0, file.Length - 5);
                }
                else if (file.EndsWith(".guids.txt"))
                {
                    type = typeof(AssetTypeGUIDs);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.EndsWith(".GUIDs.txt"))     // Default FMOD casing
                {
                    type  = typeof(AssetTypeGUIDs);
                    file  = file.Substring(0, file.Length - 4 - 6);
                    file += ".guids";
                }
                else if (OnGuessType != null)
                {
                    // Allow mods to parse custom types.
                    Delegate[] ds = OnGuessType.GetInvocationList();
                    for (int i = 0; i < ds.Length; i++)
                    {
                        Type   typeMod;
                        string formatMod;
                        string fileMod = ((TypeGuesser)ds[i])(file, out typeMod, out formatMod);
                        if (fileMod == null || typeMod == null || formatMod == null)
                        {
                            continue;
                        }
                        file   = fileMod;
                        type   = typeMod;
                        format = formatMod;
                        break;
                    }
                }

                return(file);
            }
Пример #4
0
            public static string GuessType(string file, out Type type, out string format)
            {
                type   = typeof(object);
                format = file.Length < 4 ? null : file.Substring(file.Length - 3);

                if (file.EndsWith(".dll"))
                {
                    type = typeof(AssetTypeAssembly);
                }
                else if (file.EndsWith(".png"))
                {
                    type = typeof(Texture2D);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.EndsWith(".obj"))
                {
                    type = typeof(ObjModel);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.EndsWith(".yaml"))
                {
                    type   = typeof(AssetTypeYaml);
                    file   = file.Substring(0, file.Length - 5);
                    format = ".yml";
                }
                else if (file.EndsWith(".yml"))
                {
                    type = typeof(AssetTypeYaml);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.StartsWith("Dialog/") && file.EndsWith(".txt"))
                {
                    type = typeof(AssetTypeDialog);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (file.StartsWith("Maps/") && file.EndsWith(".bin"))
                {
                    type = typeof(AssetTypeMap);
                    file = file.Substring(0, file.Length - 4);
                }
                else if (OnGuessType != null)
                {
                    // Allow mods to parse custom types.
                    Delegate[] ds = OnGuessType.GetInvocationList();
                    for (int i = 0; i < ds.Length; i++)
                    {
                        Type   typeMod;
                        string formatMod;
                        string fileMod = ((TypeGuesser)ds[i])(file, out typeMod, out formatMod);
                        if (fileMod == null || typeMod == null || formatMod == null)
                        {
                            continue;
                        }
                        file   = fileMod;
                        type   = typeMod;
                        format = formatMod;
                        break;
                    }
                }

                return(file);
            }