示例#1
0
        public static string GeneratePermadeathSaveName()
        {
            string text = NameGenerator.GenerateName(Faction.OfPlayer.def.factionNameMaker, null, false, null, null);

            text = GenFile.SanitizedFileName(text);
            return(PermadeathModeUtility.NewPermadeathSaveNameWithAppendedNumberIfNecessary(text, null));
        }
示例#2
0
        public static string GeneratePermadeathSaveName()
        {
            string fileName = NameGenerator.GenerateName(Faction.OfPlayer.def.factionNameMaker);

            fileName = GenFile.SanitizedFileName(fileName);
            return(NewPermadeathSaveNameWithAppendedNumberIfNecessary(fileName));
        }
示例#3
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);
        }
示例#4
0
        public static IEnumerable <string> LinesFromFile(string filePath)
        {
            string rawText = GenFile.TextFromResourceFile(filePath);

            foreach (string line in GenText.LinesFromString(rawText))
            {
                yield return(line);
            }
        }
示例#5
0
        public static string TextFromResourceFile(string filePath)
        {
            TextAsset textAsset = Resources.Load("Text/" + filePath) as TextAsset;

            if (textAsset == null)
            {
                Log.Message("Found no text asset in resources at " + filePath);
                return(null);
            }
            return(GenFile.GetTextWithoutBOM(textAsset));
        }
示例#6
0
        public static string TextFromResourceFile(string filePath)
        {
            TextAsset textAsset = Resources.Load("Text/" + filePath) as TextAsset;
            string    result;

            if (textAsset == null)
            {
                Log.Message("Found no text asset in resources at " + filePath, false);
                result = null;
            }
            else
            {
                result = GenFile.GetTextWithoutBOM(textAsset);
            }
            return(result);
        }
示例#7
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);
            }
        }
示例#8
0
        public static IEnumerable <string> LinesFromFile(string filePath)
        {
            string rawText = GenFile.TextFromResourceFile(filePath);

            using (IEnumerator <string> enumerator = GenText.LinesFromString(rawText).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    string line = enumerator.Current;
                    yield return(line);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_00ca:
            /*Error near IL_00cb: Unexpected return in MoveNext()*/;
        }
示例#9
0
        public static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs, bool useLinuxLineEndings = false)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirName);

            DirectoryInfo[] directories = directoryInfo.GetDirectories();
            if (!directoryInfo.Exists)
            {
                throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName);
            }
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }
            FileInfo[] files = directoryInfo.GetFiles();
            FileInfo[] array = files;
            for (int i = 0; i < array.Length; i++)
            {
                FileInfo fileInfo = array[i];
                string   text     = Path.Combine(destDirName, fileInfo.Name);
                if (useLinuxLineEndings && (fileInfo.Extension == ".sh" || fileInfo.Extension == ".txt"))
                {
                    if (!File.Exists(text))
                    {
                        File.WriteAllText(text, File.ReadAllText(fileInfo.FullName).Replace("\r\n", "\n").Replace("\r", "\n"));
                    }
                }
                else
                {
                    fileInfo.CopyTo(text, false);
                }
            }
            if (copySubDirs)
            {
                DirectoryInfo[] array2 = directories;
                for (int j = 0; j < array2.Length; j++)
                {
                    DirectoryInfo directoryInfo2 = array2[j];
                    string        destDirName2   = Path.Combine(destDirName, directoryInfo2.Name);
                    GenFile.DirectoryCopy(directoryInfo2.FullName, destDirName2, copySubDirs, useLinuxLineEndings);
                }
            }
        }
        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);
            }
        }
示例#11
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;
         }
     }
 }
示例#12
0
        public static string GeneratePermadeathSaveNameBasedOnPlayerInput(string factionName, string acceptedNameEvenIfTaken = null)
        {
            string name = GenFile.SanitizedFileName(factionName);

            return(PermadeathModeUtility.NewPermadeathSaveNameWithAppendedNumberIfNecessary(name, acceptedNameEvenIfTaken));
        }