public static IEnumerable <LoadedContentItem <T> > LoadAllForMod(ModContentPack mod) { string contentDirPath = Path.Combine(mod.RootDir, GenFilePaths.ContentPath <T>()); DirectoryInfo contentDir = new DirectoryInfo(contentDirPath); if (contentDir.Exists) { DeepProfiler.Start("Loading assets of type " + typeof(T) + " for mod " + mod); FileInfo[] files = contentDir.GetFiles("*.*", SearchOption.AllDirectories); foreach (FileInfo file in files) { if (ModContentLoader <T> .IsAcceptableExtension(file.Extension)) { LoadedContentItem <T> loadedItem = ModContentLoader <T> .LoadItem(file.FullName, contentDirPath); if (loadedItem != null) { yield return(loadedItem); /*Error: Unable to find new state assignment for yield return*/; } } } DeepProfiler.End(); } }
public void ReloadAll() { foreach (Pair <string, LoadedContentItem <T> > item in ModContentLoader <T> .LoadAllForMod(mod)) { string first = item.First; first = first.Replace('\\', '/'); string text = GenFilePaths.ContentPath <T>(); if (first.StartsWith(text)) { first = first.Substring(text.Length); } if (first.EndsWith(Path.GetExtension(first))) { first = first.Substring(0, first.Length - Path.GetExtension(first).Length); } if (contentList.ContainsKey(first)) { Log.Warning("Tried to load duplicate " + typeof(T) + " with path: " + item.Second.internalFile + " and internal path: " + first); } else { contentList.Add(first, item.Second.contentItem); if (item.Second.extraDisposable != null) { extraDisposables.Add(item.Second.extraDisposable); } } } }
public static IEnumerable <LoadedContentItem <T> > LoadAllForMod(ModContentPack mod) { string contentDirPath = Path.Combine(mod.RootDir, GenFilePaths.ContentPath <T>()); DirectoryInfo contentDir = new DirectoryInfo(contentDirPath); if (contentDir.Exists) { DeepProfiler.Start(string.Concat(new object[] { "Loading assets of type ", typeof(T), " for mod ", mod })); FileInfo[] files = contentDir.GetFiles("*.*", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { FileInfo file = files[i]; if (ModContentLoader <T> .IsAcceptableExtension(file.Extension)) { LoadedContentItem <T> loadedItem = ModContentLoader <T> .LoadItem(file.FullName, contentDirPath); if (loadedItem != null) { yield return(loadedItem); } } } DeepProfiler.End(); } }
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); }
public void ReloadAll() { foreach (LoadedContentItem <T> item in ModContentLoader <T> .LoadAllForMod(this.mod)) { if (this.contentList.ContainsKey(item.internalPath)) { Log.Warning("Tried to load duplicate " + typeof(T) + " with path: " + item.internalPath); } else { this.contentList.Add(item.internalPath, item.contentItem); } } }
public void ReloadAll() { foreach (LoadedContentItem <T> current in ModContentLoader <T> .LoadAllForMod(this.mod)) { if (this.contentList.ContainsKey(current.internalPath)) { Log.Warning(string.Concat(new object[] { "Tried to load duplicate ", typeof(T), " with path: ", current.internalPath }), false); } else { this.contentList.Add(current.internalPath, current.contentItem); } } }
public void LoadData() { if (this.dataIsLoaded) { return; } this.dataIsLoaded = true; DeepProfiler.Start("Loading language data: " + this.folderName); try { foreach (string current in this.FolderPaths) { string localFolderPath = current; LongEventHandler.ExecuteWhenFinished(delegate { if (this.icon == BaseContent.BadTex) { FileInfo fileInfo = new FileInfo(Path.Combine(localFolderPath.ToString(), "LangIcon.png")); if (fileInfo.Exists) { this.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName, null).contentItem; } } }); DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(current.ToString(), "CodeLinked")); if (directoryInfo.Exists) { this.loadErrors.Add("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directoryInfo); } else { directoryInfo = new DirectoryInfo(Path.Combine(current.ToString(), "Keyed")); } if (directoryInfo.Exists) { FileInfo[] files = directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { FileInfo file = files[i]; this.LoadFromFile_Keyed(file); } } DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(current.ToString(), "DefLinked")); if (directoryInfo2.Exists) { this.loadErrors.Add("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directoryInfo2); } else { directoryInfo2 = new DirectoryInfo(Path.Combine(current.ToString(), "DefInjected")); } if (directoryInfo2.Exists) { DirectoryInfo[] directories = directoryInfo2.GetDirectories("*", SearchOption.TopDirectoryOnly); for (int j = 0; j < directories.Length; j++) { DirectoryInfo directoryInfo3 = directories[j]; string name = directoryInfo3.Name; Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name); if (typeInAnyAssembly == null && name.Length > 3) { typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1)); } if (typeInAnyAssembly == null) { this.loadErrors.Add(string.Concat(new string[] { "Error loading language from ", current, ": dir ", directoryInfo3.Name, " doesn't correspond to any def type. Skipping..." })); } else { FileInfo[] files2 = directoryInfo3.GetFiles("*.xml", SearchOption.AllDirectories); for (int k = 0; k < files2.Length; k++) { FileInfo file2 = files2[k]; this.LoadFromFile_DefInject(file2, typeInAnyAssembly); } } } } this.EnsureAllDefTypesHaveDefInjectionPackage(); DirectoryInfo directoryInfo4 = new DirectoryInfo(Path.Combine(current.ToString(), "Strings")); if (directoryInfo4.Exists) { DirectoryInfo[] directories2 = directoryInfo4.GetDirectories("*", SearchOption.TopDirectoryOnly); for (int l = 0; l < directories2.Length; l++) { DirectoryInfo directoryInfo5 = directories2[l]; FileInfo[] files3 = directoryInfo5.GetFiles("*.txt", SearchOption.AllDirectories); for (int m = 0; m < files3.Length; m++) { FileInfo file3 = files3[m]; this.LoadFromFile_Strings(file3, directoryInfo4); } } } this.wordInfo.LoadFrom(current); } } catch (Exception arg) { Log.Error("Exception loading language data. Rethrowing. Exception: " + arg, false); throw; } finally { DeepProfiler.End(); } }
public void LoadData() { if (!this.dataIsLoaded) { this.dataIsLoaded = true; DeepProfiler.Start("Loading language data: " + this.folderName); foreach (string folderPath in this.FolderPaths) { string localFolderPath = folderPath; LongEventHandler.ExecuteWhenFinished(delegate { if ((UnityEngine.Object) this.icon == (UnityEngine.Object)BaseContent.BadTex) { FileInfo fileInfo = new FileInfo(Path.Combine(localFolderPath.ToString(), "LangIcon.png")); if (fileInfo.Exists) { this.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName, null).contentItem; } } }); DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(folderPath.ToString(), "CodeLinked")); if (directoryInfo.Exists) { Log.Warning("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directoryInfo); } else { directoryInfo = new DirectoryInfo(Path.Combine(folderPath.ToString(), "Keyed")); } if (directoryInfo.Exists) { FileInfo[] files = directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories); foreach (FileInfo file in files) { this.LoadFromFile_Keyed(file); } } DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(folderPath.ToString(), "DefLinked")); if (directoryInfo2.Exists) { Log.Warning("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directoryInfo2); } else { directoryInfo2 = new DirectoryInfo(Path.Combine(folderPath.ToString(), "DefInjected")); } if (directoryInfo2.Exists) { DirectoryInfo[] directories = directoryInfo2.GetDirectories("*", SearchOption.TopDirectoryOnly); foreach (DirectoryInfo directoryInfo3 in directories) { string name = directoryInfo3.Name; Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name); if (typeInAnyAssembly == null && name.Length > 3) { typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1)); } if (typeInAnyAssembly == null) { Log.Warning("Error loading language from " + folderPath + ": dir " + directoryInfo3.Name + " doesn't correspond to any def type. Skipping..."); } else { FileInfo[] files2 = directoryInfo3.GetFiles("*.xml", SearchOption.AllDirectories); foreach (FileInfo file2 in files2) { this.LoadFromFile_DefInject(file2, typeInAnyAssembly); } } } } DirectoryInfo directoryInfo4 = new DirectoryInfo(Path.Combine(folderPath.ToString(), "Strings")); if (directoryInfo4.Exists) { DirectoryInfo[] directories2 = directoryInfo4.GetDirectories("*", SearchOption.TopDirectoryOnly); foreach (DirectoryInfo directoryInfo5 in directories2) { FileInfo[] files3 = directoryInfo5.GetFiles("*.txt", SearchOption.AllDirectories); foreach (FileInfo file3 in files3) { this.LoadFromFile_Strings(file3, directoryInfo4); } } } } DeepProfiler.End(); } }
public void LoadData() { if (dataIsLoaded) { return; } dataIsLoaded = true; DeepProfiler.Start("Loading language data: " + folderName); try { tmpAlreadyLoadedFiles.Clear(); foreach (Tuple <VirtualDirectory, ModContentPack, string> allDirectory in AllDirectories) { Tuple <VirtualDirectory, ModContentPack, string> localDirectory = allDirectory; if (!tmpAlreadyLoadedFiles.ContainsKey(localDirectory.Item2)) { tmpAlreadyLoadedFiles[localDirectory.Item2] = new HashSet <string>(); } LongEventHandler.ExecuteWhenFinished(delegate { if (icon == BaseContent.BadTex) { VirtualFile file = localDirectory.Item1.GetFile("LangIcon.png"); if (file.Exists) { icon = ModContentLoader <Texture2D> .LoadItem(file).contentItem; } } }); VirtualDirectory directory = localDirectory.Item1.GetDirectory("CodeLinked"); if (directory.Exists) { loadErrors.Add("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directory); } else { directory = localDirectory.Item1.GetDirectory("Keyed"); } if (directory.Exists) { foreach (VirtualFile file2 in directory.GetFiles("*.xml", SearchOption.AllDirectories)) { if (TryRegisterFileIfNew(localDirectory, file2.FullPath)) { LoadFromFile_Keyed(file2); } } } VirtualDirectory directory2 = localDirectory.Item1.GetDirectory("DefLinked"); if (directory2.Exists) { loadErrors.Add("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directory2); } else { directory2 = localDirectory.Item1.GetDirectory("DefInjected"); } if (directory2.Exists) { foreach (VirtualDirectory directory4 in directory2.GetDirectories("*", SearchOption.TopDirectoryOnly)) { string name = directory4.Name; Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name); if (typeInAnyAssembly == null && name.Length > 3) { typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1)); } if (typeInAnyAssembly == null) { loadErrors.Add(string.Concat("Error loading language from ", allDirectory, ": dir ", directory4.Name, " doesn't correspond to any def type. Skipping...")); continue; } foreach (VirtualFile file3 in directory4.GetFiles("*.xml", SearchOption.AllDirectories)) { if (TryRegisterFileIfNew(localDirectory, file3.FullPath)) { LoadFromFile_DefInject(file3, typeInAnyAssembly); } } } } EnsureAllDefTypesHaveDefInjectionPackage(); VirtualDirectory directory3 = localDirectory.Item1.GetDirectory("Strings"); if (directory3.Exists) { foreach (VirtualDirectory directory5 in directory3.GetDirectories("*", SearchOption.TopDirectoryOnly)) { foreach (VirtualFile file4 in directory5.GetFiles("*.txt", SearchOption.AllDirectories)) { if (TryRegisterFileIfNew(localDirectory, file4.FullPath)) { LoadFromFile_Strings(file4, directory3); } } } } wordInfo.LoadFrom(localDirectory, this); } } catch (Exception arg) { Log.Error("Exception loading language data. Rethrowing. Exception: " + arg); throw; } finally { DeepProfiler.End(); } }
public void LoadData() { if (this.dataIsLoaded) { return; } this.dataIsLoaded = true; DeepProfiler.Start("Loading language data: " + this.folderName); foreach (string text in this.FolderPaths) { string localFolderPath = text; LongEventHandler.ExecuteWhenFinished(delegate { if (this.icon == BaseContent.BadTex) { FileInfo fileInfo = new FileInfo(Path.Combine(localFolderPath.ToString(), "LangIcon.png")); if (fileInfo.Exists) { this.icon = ModContentLoader <Texture2D> .LoadItem(fileInfo.FullName, null).contentItem; } } }); DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(text.ToString(), "CodeLinked")); if (directoryInfo.Exists) { this.loadErrors.Add("Translations aren't called CodeLinked any more. Please rename to Keyed: " + directoryInfo); } else { directoryInfo = new DirectoryInfo(Path.Combine(text.ToString(), "Keyed")); } if (directoryInfo.Exists) { foreach (FileInfo file in directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories)) { this.LoadFromFile_Keyed(file); } } DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(text.ToString(), "DefLinked")); if (directoryInfo2.Exists) { this.loadErrors.Add("Translations aren't called DefLinked any more. Please rename to DefInjected: " + directoryInfo2); } else { directoryInfo2 = new DirectoryInfo(Path.Combine(text.ToString(), "DefInjected")); } if (directoryInfo2.Exists) { foreach (DirectoryInfo directoryInfo3 in directoryInfo2.GetDirectories("*", SearchOption.TopDirectoryOnly)) { string name = directoryInfo3.Name; Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name); if (typeInAnyAssembly == null && name.Length > 3) { typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(name.Substring(0, name.Length - 1)); } if (typeInAnyAssembly == null) { this.loadErrors.Add(string.Concat(new string[] { "Error loading language from ", text, ": dir ", directoryInfo3.Name, " doesn't correspond to any def type. Skipping..." })); } else { foreach (FileInfo file2 in directoryInfo3.GetFiles("*.xml", SearchOption.AllDirectories)) { this.LoadFromFile_DefInject(file2, typeInAnyAssembly); } } } } this.EnsureAllDefTypesHaveDefInjectionPackage(); DirectoryInfo directoryInfo4 = new DirectoryInfo(Path.Combine(text.ToString(), "Strings")); if (directoryInfo4.Exists) { foreach (DirectoryInfo directoryInfo5 in directoryInfo4.GetDirectories("*", SearchOption.TopDirectoryOnly)) { foreach (FileInfo file3 in directoryInfo5.GetFiles("*.txt", SearchOption.AllDirectories)) { this.LoadFromFile_Strings(file3, directoryInfo4); } } } } DeepProfiler.End(); }