Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String[] listDirectory(String filePath) throws java.io.IOException, java.io.FileNotFoundException
        public virtual string[] listDirectory(string filePath)
        {
            Iso9660Directory dir = null;

            if (filePath.Length == 0)
            {
                dir = new Iso9660Handler(this);
            }
            else
            {
                Iso9660File info = getFileEntry(filePath);
                if (info != null && isDirectory(info))
                {
                    dir = new Iso9660Directory(this, info.LBA, info.Size);
                }
            }

            if (dir == null)
            {
                throw new FileNotFoundException("File '" + filePath + "' not found or not a directory.");
            }

            return(dir.FileList);
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private pspsharp.filesystems.umdiso.iso9660.Iso9660File getFileEntry(String filePath) throws java.io.IOException, java.io.FileNotFoundException
        private Iso9660File getFileEntry(string filePath)
        {
            Iso9660File info;

            info = fileCache[filePath];
            if (info != null)
            {
                return(info);
            }

            int parentDirectoryIndex = filePath.LastIndexOf('/');

            if (parentDirectoryIndex >= 0)
            {
                string           parentDirectory = filePath.Substring(0, parentDirectoryIndex);
                Iso9660Directory dir             = dirCache[parentDirectory];
                if (dir != null)
                {
                    int index = dir.getFileIndex(filePath.Substring(parentDirectoryIndex + 1));
                    info = dir.getEntryByIndex(index);
                    if (info != null)
                    {
                        fileCache[filePath] = info;
                        return(info);
                    }
                }
            }

            Iso9660Directory dir = new Iso9660Handler(this);

            string[] path = filePath.Split("[\\/]", true);

            // First convert the path to a canonical path by removing all the
            // occurrences of "." and "..".
            int pathLength = path.Length;

            for (int i = 0; i < pathLength;)
            {
                if (path[i].Equals("."))
                {
                    // Remove "."
                    pathLength = removePath(path, i, pathLength);
                }
                else if (path[i].Equals(".."))
                {
                    // Remove ".." and its parent
                    pathLength = removePath(path, i, pathLength);
                    pathLength = removePath(path, i - 1, pathLength);
                }
                else
                {
                    i++;
                }
            }

            // walk through the canonical path
            for (int i = 0; i < pathLength;)
            {
                int index = dir.getFileIndex(path[i]);

                info = dir.getEntryByIndex(index);

                if (isDirectory(info))
                {
                    dir = new Iso9660Directory(this, info.LBA, info.Size);
                    StringBuilder dirPath = new StringBuilder(path[0]);
                    for (int j = 1; j <= i; j++)
                    {
                        dirPath.Append("/").Append(path[j]);
                    }
                    dirCache[dirPath.ToString()] = dir;
                }
                i++;
            }

            if (info != null)
            {
                fileCache[filePath] = info;
            }

            return(info);
        }