Exemple #1
0
 public static void SetCurrentPath(Pathfinder pathfinder)
 {
     currentPath = pathfinder;
 }
Exemple #2
0
 public static void ClearCurrentPath()
 {
     currentPath = null;
 }
Exemple #3
0
        // Example: Pathfinder.Find("Lichen:common/ball", "sprites", Pathfinder.image).Path
        //public static Pathfinder Find(string locator, string collection, FileType type, Pathfinder current = null, string ext = null)
        public static Pathfinder Find(string locator, string collection, FileType type, string ext = null)
        {
            Pathfinder pathfinder = new Pathfinder();

            pathfinder.collection = collection;
            pathfinder.type       = type;
            pathfinder.ext        = ext;
            //string currentNamespace;
            //List<string> currentPath;
            if (currentPath == null)
            {
                pathfinder._namespace = "core";
                pathfinder.sub        = new List <string>();
            }
            else
            {
                pathfinder._namespace = currentPath._namespace;
                pathfinder.sub        = new List <string>(currentPath.sub); // make a duplicate instead of copying the reference
            }

            /*
             * if (!ValidateLocator(locator))
             * {
             *  // error
             * }
             */

            string[] parts = locator.Split(':');
            if (parts.Length == 2)
            {
                pathfinder._namespace = parts[0];
            }
            else if (parts.Length != 1)
            {
                throw new Exception("Duplicate namespace marker ':' in '" + locator + "'.");
            }
            string[] parts2 = parts[parts.Length - 1].Split('/');
            pathfinder.file = parts2[parts2.Length - 1];
            if (parts2.Length > 1)
            {
                if (parts2[0].Equals(""))
                {
                    pathfinder.sub = new List <string>();
                }
                for (int i = 0; i < parts2.Length - 1; i++)
                {
                    if (parts2[i].Equals(".."))
                    {
                        if (pathfinder.sub.Count < 1)
                        {
                            throw new Exception("Path out of resource folder with excessive ':' in '" + locator + "'.");
                        }
                        pathfinder.sub.RemoveAt(pathfinder.sub.Count - 1);
                    }
                    else if (!parts2[i].Equals(""))
                    {
                        pathfinder.sub.Add(parts2[i]);
                    }
                }
            }

            /*
             * for (int i = 0; i < ext.Length; i++)
             * {
             *  if (File.Exists(Path.Combine(GlobalServices.ContentDirectory, )))
             * }
             */
            if (!Validate(pathfinder._namespace))
            {
                throw new Exception("Invalid namespace character in '" + pathfinder._namespace + "' via '" + locator + "'.");
            }
            foreach (string str in pathfinder.sub)
            {
                if (!Validate(str))
                {
                    throw new Exception("Invalid path character in '" + str + "' via '" + locator + "'.");
                }
            }
            if (!Validate(pathfinder.file))
            {
                throw new Exception("Invalid filename character in '" + pathfinder.file + "' via '" + locator + "'.");
            }
            pathfinder.FindPath();
            return(pathfinder);
        }