private static bool CheckOrFixPragmas(string fileName, bool onlyCheck) { string oldText = File.ReadAllText(fileName); StringBuilder sb = new StringBuilder(oldText); PragmaFixing30.LooseComments(sb); Match match = PragmaFixing30.PragmaMatch(sb, "strict"); if (!match.Success) { return(false); } bool success1 = PragmaFixing30.PragmaMatch(sb, "downcast").Success; bool success2 = PragmaFixing30.PragmaMatch(sb, "implicit").Success; if (success1 && success2) { return(false); } if (!onlyCheck) { PragmaFixing30.DoFixPragmasInFile(fileName, oldText, match.Index + match.Length, success1, success2); } return(true); }
private static bool CheckOrFixPragmas(string fileName, bool onlyCheck) { string text = File.ReadAllText(fileName); StringBuilder sb = new StringBuilder(text); PragmaFixing30.LooseComments(sb); Match match = PragmaFixing30.PragmaMatch(sb, "strict"); bool result; if (!match.Success) { result = false; } else { bool success = PragmaFixing30.PragmaMatch(sb, "downcast").Success; bool success2 = PragmaFixing30.PragmaMatch(sb, "implicit").Success; if (success && success2) { result = false; } else { if (!onlyCheck) { PragmaFixing30.DoFixPragmasInFile(fileName, text, match.Index + match.Length, success, success2); } result = true; } } return(result); }
public static void FixFiles(string[] filesToFix) { foreach (string fileName in filesToFix) { try { PragmaFixing30.FixPragmasInFile(fileName); } catch (Exception ex) { UnityEngine.Debug.LogError((object)("Failed to fix pragmas in file '" + fileName + "'.\n" + ex.Message)); } } }
private static void DoFixPragmasInFile(string fileName, string oldText, int fixPos, bool hasDowncast, bool hasImplicit) { string str1 = string.Empty; string str2 = !PragmaFixing30.HasWinLineEndings(oldText) ? "\n" : "\r\n"; if (!hasImplicit) { str1 = str1 + str2 + "#pragma implicit"; } if (!hasDowncast) { str1 = str1 + str2 + "#pragma downcast"; } File.WriteAllText(fileName, oldText.Insert(fixPos, str1)); }
public static void FixFiles(string[] filesToFix) { for (int i = 0; i < filesToFix.Length; i++) { string text = filesToFix[i]; try { PragmaFixing30.FixPragmasInFile(text); } catch (Exception ex) { UnityEngine.Debug.LogError("Failed to fix pragmas in file '" + text + "'.\n" + ex.Message); } } }
private static void FixJavaScriptPragmas() { string[] array = PragmaFixing30.CollectBadFiles(); if (array.Length != 0) { if (!InternalEditorUtility.inBatchMode) { PragmaFixingWindow.ShowWindow(array); } else { PragmaFixing30.FixFiles(array); } } }
private static string[] CollectBadFiles() { List <string> stringList = new List <string>(); foreach (string fileName in PragmaFixing30.SearchRecursive(Path.Combine(Directory.GetCurrentDirectory(), "Assets"), "*.js")) { try { if (PragmaFixing30.FileNeedsPragmaFixing(fileName)) { stringList.Add(fileName); } } catch (Exception ex) { UnityEngine.Debug.LogError((object)("Failed to fix pragmas in file '" + fileName + "'.\n" + ex.Message)); } } return(stringList.ToArray()); }
private static void FixPragmasInFile(string fileName) { PragmaFixing30.CheckOrFixPragmas(fileName, false); }
private static bool FileNeedsPragmaFixing(string fileName) { return(PragmaFixing30.CheckOrFixPragmas(fileName, true)); }