csharp/adrenak/airpeer/Assets/ParrelSync/Editor/Project.cs

Project.cs
using System.Collections.Generic;
using System.Linq;

namespace ParrelSync
{
    public clast Project : System.ICloneable
    {
        public string name;
        public string projectPath;
        string rootPath;
        public string astetPath;
        public string projectSettingsPath;
        public string libraryPath;
        public string packagesPath;
        public string autoBuildPath;
        public string localPackages;

        char[] separator = new char[1] { '/' };


        /// 
        /// Default constructor
        /// 
        public Project()
        {

        }


        /// 
        /// Initialize the project object by parsing its full path returned by Unity into a bunch of individual folder names and paths.
        /// 
        /// 
        public Project(string path)
        {
            ParsePath(path);
        }


        /// 
        /// Create a new object with the same settings
        /// 
        /// 
        public object Clone()
        {
            Project newProject = new Project();
            newProject.rootPath = rootPath;
            newProject.projectPath = projectPath;
            newProject.astetPath = astetPath;
            newProject.projectSettingsPath = projectSettingsPath;
            newProject.libraryPath = libraryPath;
            newProject.name = name;
            newProject.separator = separator;
            newProject.packagesPath = packagesPath;
            newProject.autoBuildPath = autoBuildPath;
            newProject.localPackages = localPackages;


            return newProject;
        }


        /// 
        /// Update the project object by renaming and reparsing it. Past in the new name of a project, and it'll update the other member variables to match.
        /// 
        /// 
        public void updateNewName(string newName)
        {
            name = newName;
            ParsePath(rootPath + "/" + name + "/astets");
        }


        /// 
        /// Debug override so we can quickly print out the project info.
        /// 
        /// 
        public override string ToString()
        {
            string printString = name + "\n" +
                                 rootPath + "\n" +
                                 projectPath + "\n" +
                                 astetPath + "\n" +
                                 projectSettingsPath + "\n" +
                                 packagesPath + "\n" +
                                 autoBuildPath + "\n" +
                                 localPackages + "\n" +
                                 libraryPath;
            return (printString);
        }

        private void ParsePath(string path)
        {
            //Unity's Application functions return the astets path in the Editor. 
            projectPath = path;

            //pop off the last part of the path for the project name, keep the rest for the root path
            List pathArray = projectPath.Split(separator).ToList();
            name = pathArray.Last();

            pathArray.RemoveAt(pathArray.Count() - 1);
            rootPath = string.Join(separator[0].ToString(), pathArray.ToArray());

            astetPath = projectPath + "/astets";
            projectSettingsPath = projectPath + "/ProjectSettings";
            libraryPath = projectPath + "/Library";
            packagesPath = projectPath + "/Packages";
            autoBuildPath = projectPath + "/AutoBuild";
            localPackages = projectPath + "/LocalPackages";
        }
    }
}