/// <summary> /// Deletes the clone of the currently open project, if such exists. /// </summary> public static void DeleteClone() { /// Clone won't be able to delete itself. if (ProjectCloner.IsClone()) { return; } string cloneProjectPath = ProjectCloner.GetCloneProjectPath(); ///Extra precautions. if (cloneProjectPath == string.Empty) { return; } if (cloneProjectPath == ProjectCloner.GetOriginalProjectPath()) { return; } if (!cloneProjectPath.EndsWith(ProjectCloner.CloneNameSuffix)) { return; } //Check what OS is switch (Application.platform) { case (RuntimePlatform.WindowsEditor): string args = "/c " + @"rmdir /s/q " + string.Format("\"{0}\"", cloneProjectPath); StartHiddenConsoleProcess("cmd.exe", args); Debug.Log("Clone deleted"); break; case (RuntimePlatform.OSXEditor): throw new System.NotImplementedException("No Mac function implement yet :("); break; case (RuntimePlatform.LinuxEditor): throw new System.NotImplementedException("No linux support yet :("); break; default: Debug.LogWarning("Not in a known editor. Where are you!?"); break; } }
/// <summary> /// Deletes the clone of the currently open project, if such exists. /// </summary> public static void DeleteClone() { /// Clone won't be able to delete itself. if (ProjectCloner.IsClone()) { return; } string cloneProjectPath = ProjectCloner.GetCloneProjectPath(); ///Extra precautions. if (cloneProjectPath == string.Empty) { return; } if (cloneProjectPath == ProjectCloner.GetOriginalProjectPath()) { return; } if (cloneProjectPath.EndsWith(ProjectCloner.CloneNameSuffix)) { return; } /// Delete the clone project folder. throw new System.NotImplementedException(); // TODO: implement proper project deletion; // appears that using FileUtil.DeleteFileOrDirectory(...) on symlinks affects the contents of linked folders // (because this script self-deleted itself and half of the Assets folder when I tested it :D) // there must be another, safe method to delete the clone folder and symlinks without touching the original { /* * EditorUtility.DisplayProgressBar("Deleting clone...", "Deleting '" + ProjectCloner.GetCloneProjectPath() + "'", 0f); * try * { * FileUtil.DeleteFileOrDirectory(cloneProjectPath); * } * catch (IOException) * { * EditorUtility.DisplayDialog("Could not delete clone", "'" + ProjectCloner.GetCurrentProject().name + "_clone' may be currently open in another unity Editor. Please close it and try again.", "OK"); * } * EditorUtility.ClearProgressBar(); */ } }
private void OnGUI() { GUILayout.Label("Clone settings", EditorStyles.boldLabel); if (isClone) { /// If it is a clone project... string originalProjectPath = ProjectCloner.GetOriginalProjectPath(); if (originalProjectPath == string.Empty) { /// If original project cannot be found, display warning message. string thisProjectName = ProjectCloner.GetCurrentProject().name; string supposedOriginalProjectName = ProjectCloner.GetCurrentProject().name.Replace("_clone", ""); EditorGUILayout.HelpBox( "This project is a clone, but the link to the original seems lost.\nYou have to manually open the original and create a new clone instead of this one.\nThe original project should have a name '" + supposedOriginalProjectName + "', if it was not changed.", MessageType.Warning); } else { /// If original project is present, display some usage info. EditorGUILayout.HelpBox( "This project is a clone of the project '" + Path.GetFileName(originalProjectPath) + "'.\nIf you want to make changes the project files or manage clones, please open the original project through Unity Hub.", MessageType.Info); } } else { /// If it is an original project... if (isCloneCreated) { /// If clone is created, we can either open it or delete it. string cloneProjectPath = ProjectCloner.GetCloneProjectPath(); EditorGUILayout.TextField("Clone project path", cloneProjectPath, EditorStyles.textField); if (GUILayout.Button("Open clone project")) { ProjectCloner.OpenProject(cloneProjectPath); } if (GUILayout.Button("Delete clone")) { bool delete = EditorUtility.DisplayDialog( "Delete the clone?", "Are you sure you want to delete the clone project '" + ProjectCloner.GetCurrentProject().name + "_clone'? If so, you can always create a new clone from ProjectCloner window.", "Delete", "Cancel"); if (delete) { ProjectCloner.DeleteClone(); this.Repaint(); } } } else { /// If no clone created yet, we must create it. EditorGUILayout.HelpBox("No project clones found. Create a new one!", MessageType.Info); if (GUILayout.Button("Create new clone")) { ProjectCloner.CreateCloneFromCurrent(); } } } }