public static void CheckModsAndMakeLink() { if (System.IO.Directory.Exists("Assets/Mods")) { var dirs = System.IO.Directory.GetDirectories("Assets/Mods"); if (dirs != null) { foreach (var dir in dirs) { var mod = System.IO.Path.GetFileName(dir); var linkdir = dir + "/Link"; if (System.IO.Directory.Exists(linkdir)) { CapsEditorUtils.HideFile(linkdir); if (System.IO.File.Exists(linkdir + ".meta")) { System.IO.File.Delete(linkdir + ".meta"); } foreach (var usdir in UniqueSpecialFolders) { var srcdir = linkdir + "/" + usdir; if (System.IO.Directory.Exists(srcdir)) { var phdir = "Assets/" + usdir + "/Mods/" + mod + "/Content"; if (!CapsEditorUtils.IsDirLink(phdir)) { if (System.IO.Directory.Exists(phdir)) { System.IO.Directory.Delete(phdir, true); } else if (System.IO.File.Exists(phdir)) { System.IO.File.Delete(phdir); } System.IO.Directory.CreateDirectory("Assets/" + usdir + "/Mods/" + mod); CapsEditorUtils.MakeDirLink(phdir, "../../../../" + srcdir); } } } } } } } AssetDatabase.Refresh(); CheckModsVisibility(); }
public static void CheckModsVisibility() { HashSet <string> compilerOpLines = new HashSet <string>(); System.Xml.Linq.XDocument linkxml = new System.Xml.Linq.XDocument(); var flags = new HashSet <string>(ResManager.PreRuntimeDFlags); var mods = GetAllModsOrPackages(); for (int i = 0; i < mods.Length; ++i) { var mod = mods[i]; if (!IsModOptional(mod) || flags.Contains(mod)) { // enable string defpath; bool defPathExists = false; var pdir = GetModRootInPackage(mod); if (!string.IsNullOrEmpty(pdir)) { defpath = pdir + "/mcs.rsp"; if (defPathExists = System.IO.File.Exists(defpath)) { var pname = GetPackageName(mod); compilerOpLines.Add("-define:MOD_" + pname.ToUpper().Replace(".", "_")); } else { defpath = "Assets/Mods/" + mod + "/Link/mcs.rsp"; } } else { defpath = "Assets/Mods/" + mod + "/Link/mcs.rsp"; } if (defPathExists || System.IO.File.Exists(defpath)) { compilerOpLines.Add("-define:MOD_" + mod.ToUpper().Replace(".", "_")); try { compilerOpLines.UnionWith(System.IO.File.ReadAllLines(defpath)); } catch (Exception e) { Debug.LogException(e); } } string linkxmlpath; bool linkxmlPathExists = false; if (!string.IsNullOrEmpty(pdir)) { linkxmlpath = pdir + "/link.xml"; if (linkxmlPathExists = System.IO.File.Exists(linkxmlpath)) { } else { linkxmlpath = "Assets/Mods/" + mod + "/Link/link.xml"; } } else { linkxmlpath = "Assets/Mods/" + mod + "/Link/link.xml"; } if (linkxmlPathExists || System.IO.File.Exists(linkxmlpath)) { CapsEditorUtils.MergeXml(linkxml, linkxmlpath); } CapsEditorUtils.UnhideFile("Assets/Mods/" + mod); if (System.IO.File.Exists("Assets/Mods/" + mod + ".meta")) { CapsEditorUtils.UnhideFile("Assets/Mods/" + mod + ".meta"); } foreach (var sdir in UniqueSpecialFolders) { var moddir = "Assets/" + sdir + "/Mods/" + mod; if (System.IO.Directory.Exists(moddir)) { CapsEditorUtils.UnhideFile(moddir); if (System.IO.File.Exists(moddir + ".meta")) { CapsEditorUtils.UnhideFile(moddir + ".meta"); } } } } else { // disable CapsEditorUtils.HideFile("Assets/Mods/" + mod); if (System.IO.File.Exists("Assets/Mods/" + mod + ".meta")) { System.IO.File.Delete("Assets/Mods/" + mod + ".meta"); } foreach (var sdir in UniqueSpecialFolders) { var moddir = "Assets/" + sdir + "/Mods/" + mod; if (System.IO.Directory.Exists(moddir)) { CapsEditorUtils.HideFile(moddir); if (System.IO.File.Exists(moddir + ".meta")) { System.IO.File.Delete(moddir + ".meta"); } } } } } if (linkxml.Root != null) { linkxml.Save("Assets/link.xml"); } else { System.IO.File.Delete("Assets/link.xml"); } compilerOpLines.Remove(""); HashSet <string> existCompilerOpLines = new HashSet <string>(); if (System.IO.File.Exists("Assets/mcs.rsp")) { try { existCompilerOpLines.UnionWith(System.IO.File.ReadAllLines("Assets/mcs.rsp")); existCompilerOpLines.Remove(""); } catch (Exception e) { Debug.LogException(e); } } bool hasdiff = true; if (existCompilerOpLines.Count == compilerOpLines.Count) { var diff = new HashSet <string>(compilerOpLines); diff.ExceptWith(existCompilerOpLines); hasdiff = diff.Count > 0; } if (hasdiff) { if (System.IO.File.Exists("Assets/mcs.rsp")) { System.IO.File.Delete("Assets/mcs.rsp"); } if (System.IO.File.Exists("Assets/csc.rsp")) { System.IO.File.Delete("Assets/csc.rsp"); } var lines = compilerOpLines.ToArray(); Array.Sort(lines); System.IO.File.WriteAllLines("Assets/mcs.rsp", lines); System.IO.File.WriteAllLines("Assets/csc.rsp", lines); AssetDatabase.ImportAsset("Assets/mcs.rsp"); AssetDatabase.ImportAsset("Assets/csc.rsp"); EditorApplication.LockReloadAssemblies(); try { AssetDatabase.ImportAsset(CapsEditorUtils.__ASSET__, ImportAssetOptions.ForceUpdate); } catch { } AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(ScriptableObject.CreateInstance <CapsModDesc>())), ImportAssetOptions.ForceUpdate); // Update all package... //foreach (var kvp in _PackageName2ModName) //{ // var pname = kvp.Key; // AssetDatabase.ImportAsset("Packages/" + pname, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive); //} ReimportAllAssemblyDefinitions(); EditorApplication.UnlockReloadAssemblies(); } AssetDatabase.Refresh(); }