void CopyFolders(XUPEMod mods) { //ext.copyFolder Debug.Log("Adding copyied folders..."); PBXGroup modGroup = this.GetGroup(mods.xcmod.group); foreach (string copiedFolderPath in mods.copiedFolder) { string sourceFloderPath = mods.path + "/" + copiedFolderPath; DirectoryInfo souceDirector = new DirectoryInfo(sourceFloderPath); DirectoryInfo targetDirector; //crate director in xcode project folder if (modGroup != null) { targetDirector = this.CreateDirectorInRootDir(modGroup.path); } else { targetDirector = new DirectoryInfo(this.projectRootPath); } //copy "coyied folder" into target folder Debug.Log("copy '" + souceDirector.FullName + "' to '" + targetDirector.FullName + "'."); PShellUtil.CopyInto(souceDirector, targetDirector); //add target folder reference to project this.AddFolder(targetDirector.FullName + "/" + souceDirector.Name, modGroup, (string[])mods.xcmod.excludes.ToArray(typeof(string))); } }
// Copy xCodeProject, and Modify copy public static void ExportFromXCodeProject(string sourceXCodeProjectPath, string xupeModPath, string targetXCodeProjectPath) { DirectoryInfo sourceDi = new DirectoryInfo(sourceXCodeProjectPath); if (!sourceDi.Exists) { throw new IOException("'" + sourceXCodeProjectPath + "' not exists!"); } DirectoryInfo modDi = new DirectoryInfo(xupeModPath); if (!modDi.Exists) { throw new IOException("'" + xupeModPath + "' not exists!"); } DirectoryInfo targetDi = new DirectoryInfo(targetXCodeProjectPath); if (targetDi.Exists) { Debug.Log("target exits, delete"); targetDi.Delete(true); } Debug.Log("copying '" + sourceXCodeProjectPath + "' to '" + targetXCodeProjectPath + "'..."); PShellUtil.CopyAll(sourceDi, targetDi); ModXCodeProject(targetXCodeProjectPath, xupeModPath); }
public static void Restore() { UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel); // to path list List <string> pathList = new List <string>(); foreach (var asset in arr) { var path = AssetDatabase.GetAssetPath(asset); pathList.Add(path); } OnlyKeepSystemDir(pathList); if (pathList.Count == 0) { return; } // remove systems which hasn't dll for (int i = pathList.Count - 1; i >= 0; i--) { var dir = pathList[i]; var systemName = Path.GetFileName(dir); var dllName = systemName + ".dll"; var dlls = Directory.GetFiles(dir, dllName, SearchOption.TopDirectoryOnly); if (dlls.Length == 0) { pathList.RemoveAt(i); } } if (pathList.Count == 0) { return; } foreach (var path in pathList) { Debug.Log("[PreCompile] restore: " + path); var name = Path.GetFileName(path); PShellUtil.MoveTo("PreCompile/Compiled/" + name, path); var dll = path + "/" + name + ".dll"; File.Delete(dll); PShellUtil.DeleteEmptyDirectory("PreCompile/Compiled/" + name); } AssetDatabase.Refresh(); }
public static void Compile() { if (Application.platform != RuntimePlatform.OSXEditor) { EditorUtility.DisplayDialog("PreCompile", "Only Supported on Mac", "quit"); return; } UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel); // to path list List <string> pathList = new List <string>(); foreach (var asset in arr) { var path = AssetDatabase.GetAssetPath(asset); pathList.Add(path); } OnlyKeepSystemDir(pathList); if (pathList.Count == 0) { return; } var gmcs = GetGmcs(); if (gmcs == null) { return; } var managed = GetManaged(); if (managed == null) { return; } foreach (var path in pathList) { var systemRoot = path; var systemName = Path.GetFileName(systemRoot); var unityEngine = managed + "/UnityEngine.dll"; var unityEditor = managed + "/UnityEditor.dll"; var recurse = systemRoot + "/*.cs"; var o = systemRoot + "/" + systemName + ".dll"; var define = "UNITY_EDITOR"; var r = unityEngine + "," + unityEditor; var target = "library"; var arg = @"-r:" + r + " -target:" + target + " -recurse:" + recurse + " -define:" + define + " -out:" + o; var ret = Exec.Run(gmcs, arg, true); if (ret == 0) { PShellUtil.MoveTo(path, "PreCompile/Compiled/" + systemName, PShellUtil.FileExsitsOption.Override, PShellUtil.DirectoryExsitsOption.Merge, null, new string[] { ".cs", ".cs.meta" }); // delete out dll in codebase PShellUtil.DeleteEmptyDirectory(systemRoot); } else { Debug.LogError("[PreCompile] Error: " + ret); } } AssetDatabase.Refresh(); }
void CopyPlainFile(XUPEMod mods) { //copy file Debug.Log("Copy files..."); PShellUtil.CopyAll(new DirectoryInfo(Path.Combine(mods.path, "file")), new DirectoryInfo(this.projectRootPath)); }
public void ApplyCommands(Mod mod, XmlNode commandNode) { //XmlNode commandNode = mod.Xml.DocumentElement.SelectSingleNode ("command"); //ReplaceVar (commandNode); int index = 0; XmlNodeList commandList = commandNode.ChildNodes; foreach (XmlNode command in commandList) { if (command.Name == "delete") { string deleteDir = command.Attributes["target"].Value; //deleteDir = filtPath(deleteDir, mod); if (Directory.Exists(deleteDir)) { DirectoryInfo dir = new DirectoryInfo(deleteDir); dir.Delete(true); } else if (File.Exists(deleteDir)) { FileInfo file = new FileInfo(deleteDir); file.Delete(); } else { throw new Exception("'" + deleteDir + "' not exits!"); } } if (command.Name == "copy") { string from = command.Attributes ["from"].Value; string to = command.Attributes ["to"].Value; //from = filtPath(from, mod); //to = filtPath(to, mod); Debug.Log("from: " + from); Debug.Log("to: " + to); if (Directory.Exists(from)) { PShellUtil.CopyTo(new DirectoryInfo(from), new DirectoryInfo(to)); } else if (File.Exists(from)) { FileInfo fi = new FileInfo(from); //FileInfo t = new FileInfo(to + "/" + fi.Name); //t.Directory.Create(); fi.CopyTo(to, true); } else { throw new Exception("copy error: '" + from + "' not exsists!"); } //--------------translate variables in these files-------------------- if (command.Attributes["translate-variables"] != null) { string reg = command.Attributes["translate-variables"].Value; List <string> targetFiles = FindFile(to, reg); TranslateVariables(mod, targetFiles); } } if (command.Name == "copyInto") { string from = command.Attributes ["from"].Value; string into = command.Attributes ["into"].Value; //from = filtPath(from, mod); //into = filtPath(into, mod); Debug.Log("from: " + from); Debug.Log("into: " + into); if (Directory.Exists(from)) { PShellUtil.CopyInto(new DirectoryInfo(from), new DirectoryInfo(into)); } else if (File.Exists(from)) { FileInfo fi = new FileInfo(from); FileInfo to = new FileInfo(into + "/" + fi.Name); to.Directory.Create(); fi.CopyTo(to.FullName, true); } else { throw new Exception("copy error: '" + from + "' not exsists!"); } //--------------translate variables in these files-------------------- if (command.Attributes["translate-variables"] != null) { FileInfo fi = new FileInfo(from); FileInfo to = new FileInfo(into + "/" + fi.Name); string reg = command.Attributes["translate-variables"].Value; List <string> targetFiles = FindFile(to.FullName, reg); TranslateVariables(mod, targetFiles); } } if (command.Name == "add-lib-project") { string modFilePath = Path.Combine(this.rootPath, "project.properties"); string libProjectPath = command.Attributes["target"].Value; FileInfo file = new FileInfo(modFilePath); StreamWriter sw = file.AppendText(); List <string> lines = new List <string>(); index++; lines.Add("android.library.reference." + index + "=./" + libProjectPath); foreach (var line in lines) { sw.WriteLine(line); } sw.Close(); } if (command.Name == "modify-code") { string filePath = command.Attributes ["file"].Value; //filePath = filtPath(filePath, mod); if (!File.Exists(filePath)) { throw new Exception("'" + filePath + "' not exits!"); } string source = command.Attributes ["source"].Value; string target = command.Attributes ["target"].Value; XClass xc = new XClass(filePath); xc.Replace(source, target); } if (command.Name == "rename") { string from = command.Attributes ["from"].Value; string to = command.Attributes ["to"].Value; //from = filtPath(from, mod); //to = filtPath(to, mod); if (Directory.Exists(from)) { Directory.Move(from, to); } if (File.Exists(from)) { File.Move(from, to); } } } }