示例#1
0
        /// <summary>
        /// Returns the path to the original project.
        /// If currently open project is the original, returns its own path.
        /// If the original project folder cannot be found, retuns an empty string.
        /// </summary>
        /// <returns></returns>
        public static string GetOriginalProjectPath()
        {
            if (IsClone())
            {
                /// If this is a clone...
                /// Original project path can be deduced by removing the suffix from the clone's path.
                string cloneProjectPath = ProjectCloner.GetCurrentProject().projectPath;

                int index = cloneProjectPath.LastIndexOf(ProjectCloner.CloneNameSuffix);
                if (index > 0)
                {
                    string originalProjectPath = cloneProjectPath.Substring(0, index);
                    if (Directory.Exists(originalProjectPath))
                    {
                        return(originalProjectPath);
                    }
                }

                return(string.Empty);
            }
            else
            {
                /// If this is the original, we return its own path.
                return(ProjectCloner.GetCurrentProjectPath());
            }
        }
示例#2
0
        /// <summary>
        /// Returns true is the project currently open in Unity Editor is a clone.
        /// </summary>
        /// <returns></returns>
        public static bool IsClone()
        {
            /// The project is a clone if its root directory contains an empty file named ".clone".
            string cloneFilePath = Path.Combine(ProjectCloner.GetCurrentProjectPath(), ProjectCloner.CloneFileName);
            bool   isClone       = File.Exists(cloneFilePath);

            return(isClone);
        }
示例#3
0
        /// <summary>
        /// Creates clone from the project currently open in Unity Editor.
        /// </summary>
        /// <returns></returns>
        public static Project CreateCloneFromCurrent()
        {
            if (IsClone())
            {
                Debug.LogError("This project is already a clone. Cannot clone it.");
                return(null);
            }

            string currentProjectPath = ProjectCloner.GetCurrentProjectPath();

            return(ProjectCloner.CreateCloneFromPath(currentProjectPath));
        }
示例#4
0
        /// <summary>
        /// Opens a project located at the given path (if one exists).
        /// </summary>
        /// <param name="projectPath"></param>
        public static void OpenProject(string projectPath)
        {
            if (!Directory.Exists(projectPath))
            {
                Debug.LogError("Cannot open the project - provided folder (" + projectPath + ") does not exist.");
                return;
            }
            if (projectPath == ProjectCloner.GetCurrentProjectPath())
            {
                Debug.LogError("Cannot open the project - it is already open.");
                return;
            }

            string fileName = EditorApplication.applicationPath;
            string args     = "-projectPath \"" + projectPath + "\"";

            Debug.Log("Opening project \"" + fileName + " " + args + "\"");
            ProjectCloner.StartHiddenConsoleProcess(fileName, args);
        }
示例#5
0
        /// <summary>
        /// Returns the path to the clone project.
        /// If currently open project is the clone, returns its own path.
        /// If the clone does not exist yet, retuns an empty string.
        /// </summary>
        /// <returns></returns>
        public static string GetCloneProjectPath()
        {
            if (IsClone())
            {
                /// If this is the clone, we return its own path.
                return(ProjectCloner.GetCurrentProjectPath());
            }
            else
            {
                /// If this is the original...
                /// Clone project path can be deduced by add the suffix to the original's path.
                string originalProjectPath = ProjectCloner.GetCurrentProject().projectPath;
                string cloneProjectPath    = originalProjectPath + ProjectCloner.CloneNameSuffix;

                if (Directory.Exists(cloneProjectPath))
                {
                    return(cloneProjectPath);
                }
                return(string.Empty);
            }
        }
        /// <summary>
        /// Returns the path to the original project.
        /// If currently open project is the original, returns its own path.
        /// If the original project folder cannot be found, retuns an empty string.
        /// </summary>
        /// <returns></returns>
        public static string GetOriginalProjectPath()
        {
            if (IsClone())
            {
                // If this is a clone...
                // Original project path can be deduced by removing the suffix from the clone's path.
                string cloneProjectPath    = ProjectCloner.GetCurrentProject().projectPath;
                string originalProjectPath = cloneProjectPath.Remove(cloneProjectPath.Length - ProjectCloner.CloneNameSuffix.Length);

                if (Directory.Exists(originalProjectPath))
                {
                    return(originalProjectPath);
                }
                return(string.Empty);
            }
            else
            {
                // If this is the original, we return its own path.
                return(ProjectCloner.GetCurrentProjectPath());
            }
        }
示例#7
0
        /// <summary>
        /// Return a project object that describes all the paths we need to clone it.
        /// </summary>
        /// <returns></returns>
        public static Project GetCurrentProject()
        {
            string pathString = ProjectCloner.GetCurrentProjectPath();

            return(new Project(pathString));
        }