コード例 #1
0
 // retrieves the packed file at the given path name
 public PackEntry this[string filepath] {
     get {
         string[]         paths  = filepath.Split(Path.DirectorySeparatorChar);
         VirtualDirectory dir    = Root;
         PackEntry        result = dir;
         foreach (string subDir in paths)
         {
             result = dir.GetEntry(subDir);
             dir    = result as VirtualDirectory;
         }
         return(result);
     }
 }
コード例 #2
0
        /*
         * Adds the given file to the given path, relative to this directory.
         */
        public void Add(string relativePath, PackedFile file, bool overwrite = false)
        {
            VirtualDirectory current = this;

            char[] splitAt = { Path.DirectorySeparatorChar };
            var    parts   = relativePath.Split(splitAt);

            for (int i = 0; i < parts.Count() - 1; i++)
            {
                current = current.GetSubdirectory(parts[i]);
            }

            file.Parent = current;
            current.Add(file, overwrite);
        }
コード例 #3
0
        /*
         * Adds the given file to the given path, relative to this directory.
         */
        public void Add(string relativePath, PackedFile file, bool overwrite = false)
        {
            char[] splitAt = { Path.DirectorySeparatorChar };
            string baseDir = Path.GetDirectoryName(relativePath);

            string[] dirs = baseDir != null?baseDir.Split(splitAt, StringSplitOptions.RemoveEmptyEntries) : new string[0];

            VirtualDirectory current = this;

            if (dirs.Length > 0)
            {
                foreach (string dir in dirs)
                {
                    current = current.GetSubdirectory(dir);
                }
            }
            file.Parent = current;
            current.Add(file, overwrite);
        }
コード例 #4
0
        /*
         * Retrieve the directory with the given name.
         * Will create and add an empty one if it doesn't already exists.
         */
        public VirtualDirectory GetSubdirectory(string subDir)
        {
            VirtualDirectory result = null;

            foreach (VirtualDirectory dir in subdirectories)
            {
                if (dir.Name.Equals(subDir))
                {
                    result = dir;
                    break;
                }
            }
            if (result == null)
            {
                result = new VirtualDirectory {
                    Parent = this, Name = subDir
                };
                Add(result);
            }
            return(result);
        }