예제 #1
0
        public static LoadedContentItem <T> LoadItem(string absFilePath, string contentDirPath = null)
        {
            string text = absFilePath;

            if (contentDirPath != null)
            {
                text = text.Substring(contentDirPath.ToString().Length);
            }
            text = text.Substring(0, text.Length - Path.GetExtension(text).Length);
            text = text.Replace('\\', '/');
            try
            {
                if (typeof(T) == typeof(string))
                {
                    return(new LoadedContentItem <T>(text, (T)(object)GenFile.TextFromRawFile(absFilePath)));
                }
                if (typeof(T) == typeof(Texture2D))
                {
                    return(new LoadedContentItem <T>(text, (T)(object)ModContentLoader <T> .LoadPNG(absFilePath)));
                }
                if (typeof(T) == typeof(AudioClip))
                {
                    if (Prefs.LogVerbose)
                    {
                        DeepProfiler.Start("Loading file " + text);
                    }
                    T val = default(T);
                    try
                    {
                        bool doStream = ModContentLoader <T> .ShouldStreamAudioClipFromPath(absFilePath);

                        val = (T)(object)Manager.Load(absFilePath, doStream, true, true);
                    }
                    finally
                    {
                        if (Prefs.LogVerbose)
                        {
                            DeepProfiler.End();
                        }
                    }
                    UnityEngine.Object @object = ((object)val) as UnityEngine.Object;
                    if (@object != (UnityEngine.Object)null)
                    {
                        @object.name = Path.GetFileNameWithoutExtension(new FileInfo(absFilePath).Name);
                    }
                    return(new LoadedContentItem <T>(text, val));
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception loading " + typeof(T) + " from file.\nabsFilePath: " + absFilePath + "\ncontentDirPath: " + contentDirPath + "\nException: " + ex.ToString());
            }
            if (typeof(T) == typeof(Texture2D))
            {
                return((LoadedContentItem <T>) new LoadedContentItem <Texture2D>(absFilePath, BaseContent.BadTex));
            }
            return(null);
        }
예제 #2
0
        private void LoadFromFile_Strings(FileInfo file, DirectoryInfo stringsTopDir)
        {
            string text;

            try
            {
                text = GenFile.TextFromRawFile(file.FullName);
            }
            catch (Exception ex)
            {
                this.loadErrors.Add(string.Concat(new object[]
                {
                    "Exception loading from strings file ",
                    file,
                    ": ",
                    ex
                }));
                return;
            }
            string text2 = file.FullName;

            if (stringsTopDir != null)
            {
                text2 = text2.Substring(stringsTopDir.FullName.Length + 1);
            }
            text2 = text2.Substring(0, text2.Length - Path.GetExtension(text2).Length);
            text2 = text2.Replace('\\', '/');
            List <string> list = new List <string>();

            foreach (string current in GenText.LinesFromString(text))
            {
                list.Add(current);
            }
            List <string> list2;

            if (this.stringFiles.TryGetValue(text2, out list2))
            {
                foreach (string current2 in list)
                {
                    list2.Add(current2);
                }
            }
            else
            {
                this.stringFiles.Add(text2, list);
            }
        }
        private void LoadFromFile_Strings(FileInfo file, DirectoryInfo stringsTopDir)
        {
            string text;

            try
            {
                text = GenFile.TextFromRawFile(file.FullName);
            }
            catch (Exception ex)
            {
                Log.Warning("Exception loading from strings file " + file + ": " + ex);
                return;
            }
            string text2 = file.FullName;

            if (stringsTopDir != null)
            {
                text2 = text2.Substring(stringsTopDir.FullName.Length + 1);
            }
            text2 = text2.Substring(0, text2.Length - Path.GetExtension(text2).Length);
            text2 = text2.Replace('\\', '/');
            List <string> list = new List <string>();

            foreach (string item in GenText.LinesFromString(text))
            {
                list.Add(item);
            }
            List <string> list2 = default(List <string>);

            if (this.stringFiles.TryGetValue(text2, out list2))
            {
                foreach (string item2 in list)
                {
                    list2.Add(item2);
                }
            }
            else
            {
                this.stringFiles.Add(text2, list);
            }
        }
예제 #4
0
 public void TryLoadMetadataFrom(string folderPath)
 {
     if (this.info == null)
     {
         string filePath = Path.Combine(folderPath.ToString(), "LanguageInfo.xml");
         this.info = DirectXmlLoader.ItemFromXmlFile <LanguageInfo>(filePath, false);
         if (this.info.friendlyNameNative.NullOrEmpty())
         {
             FileInfo fileInfo = new FileInfo(Path.Combine(folderPath.ToString(), "FriendlyName.txt"));
             if (fileInfo.Exists)
             {
                 this.info.friendlyNameNative = GenFile.TextFromRawFile(fileInfo.ToString());
             }
         }
         if (this.info.friendlyNameNative.NullOrEmpty())
         {
             this.info.friendlyNameNative = this.folderName;
         }
         if (this.info.friendlyNameEnglish.NullOrEmpty())
         {
             this.info.friendlyNameEnglish = this.folderName;
         }
     }
 }