예제 #1
0
        public int DeleteDirectory(string filename, DokanFileInfo info)
        {
            PFSDirectory dir = GetDirectory(filename);

            if (dir == null)
            {
                return(-1);
            }
            Queue <string> todel = new Queue <string>();

            foreach (KeyValuePair <ulong, ChunkMetadata> cmd in chunkMetadata)
            {
                foreach (KeyValuePair <string, FileMetadata> file in cmd.Value.files)
                {
                    if (GetPath(file.Key) != filename)
                    {
                        continue;
                    }
                    todel.Enqueue(file.Key);
                }
                while (todel.Count > 0)
                {
                    string curItem = todel.Dequeue();
                    DeleteFile(curItem, info);
                }
            }
            directories.Remove(filename);
            // Check if we should save
            EditSave();
            return(0);
        }
예제 #2
0
        private PFSDirectory GetDirectory(string fulldir)
        {
            // Hard fix : Root dir
            if (fulldir == "\\")
            {
                return(directories["\\"]);
            }
            // Split fulldir into parts
            List <string> dirs    = new List <string>(fulldir.Split("\\".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
            string        basedir = "\\" + dirs[0];

            // Remove basedir from array (Splicing)
            dirs.RemoveAt(0);
            if (!directories.ContainsKey(basedir))
            {
                return(null);
            }
            PFSDirectory current = directories[basedir];

            foreach (string dir in dirs)
            {
                if (!current.innerdirs.ContainsKey(dir))
                {
                    return(null);
                }
                current = current.innerdirs[dir];
            }
            return(current);
        }
예제 #3
0
        private void LoadMetadata(string[] metadataFiles)
        {
            chunkMetadata = new Dictionary <ulong, ChunkMetadata>();
            files         = new Dictionary <string, ulong>();
            Console.WriteLine("Loading " + metadataFiles.LongLength + " metadata files...");
            Regex _regex = new Regex(@"(.*)chunk-([0-9]+)\.meta$");

            // Load every file
            foreach (string mdpath in metadataFiles)
            {
                Match match = _regex.Match(mdpath);
                if (!match.Success)
                {
                    continue;
                }
                ulong chunkId;
                if (!ulong.TryParse(match.Groups[2].Value, out chunkId))
                {
                    continue;
                }
                Console.WriteLine(" - Loading chunk #" + chunkId + " metadata...");
                chunkMetadata[chunkId] = metadata.LoadChunkMetadata(chunkId);
                foreach (KeyValuePair <string, FileMetadata> file in chunkMetadata[chunkId].files)
                {
                    files[file.Key] = chunkId;
                }
            }
            // Load directories
            directories = metadata.LoadDirectoryMetadata();
            // Hard fix : Root dir
            // Root data
            rootData = new FileInformation
            {
                Attributes     = FileAttributes.Directory | FileAttributes.Hidden | FileAttributes.System,
                CreationTime   = DateTime.Now,
                LastAccessTime = DateTime.Now,
                LastWriteTime  = DateTime.Now,
                FileName       = settings.mountPoint,
                Length         = 0
            };
            // Root Dir Entry
            directories["\\"] = new PFSDirectory {
                name = "\\", info = rootData, innerdirs = null
            };

            Console.WriteLine(" - Loading directories metadata...");
            Console.WriteLine("Metadata loaded...");
        }
예제 #4
0
 public int CreateDirectory(string filename, DokanFileInfo info)
 {
     if (GetDirectory(filename) == null)
     {
         // Split fulldir into parts
         List <string> dirs    = new List <string>(filename.Split("\\".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
         string        basedir = "\\" + dirs[0];
         // Remove basedir from array (Splicing)
         dirs.RemoveAt(0);
         if (!directories.ContainsKey(basedir))
         {
             PFSDirectory basedirval = new PFSDirectory
             {
                 name = GetFilename(basedir),
                 info = new FileInformation
                 {
                     Attributes   = FileAttributes.Directory, FileName = GetFilename(basedir), Length = 0,
                     CreationTime = DateTime.Now, LastAccessTime = DateTime.Now, LastWriteTime = DateTime.Now
                 },
                 innerdirs = new Dictionary <string, PFSDirectory>()
             };
             directories.Add(basedir, basedirval);
         }
         PFSDirectory current = directories[basedir];
         foreach (string dir in dirs)
         {
             if (!current.innerdirs.ContainsKey(dir))
             {
                 PFSDirectory dirval = new PFSDirectory
                 {
                     name = GetFilename(dir),
                     info = new FileInformation
                     {
                         Attributes   = FileAttributes.Directory, FileName = GetFilename(dir), Length = 0,
                         CreationTime = DateTime.Now, LastAccessTime = DateTime.Now, LastWriteTime = DateTime.Now
                     },
                     innerdirs = new Dictionary <string, PFSDirectory>()
                 };
                 current.innerdirs.Add(dir, dirval);
             }
             current = current.innerdirs[dir];
         }
     }
     // Check if we should save
     EditSave();
     return(0);
 }
예제 #5
0
        public int GetFileInformation(string filename, ref FileInformation fileinfo, DokanFileInfo info)
        {
            // Is it a directory?
            PFSDirectory dir = GetDirectory(filename);

            if (dir != null)
            {
                fileinfo = dir.info;
                return(0);
            }
            // Or is it a file?
            else if (files.ContainsKey(filename))
            {
                fileinfo = chunkMetadata[files[filename]].files[filename].fileinfo;
                return(0);
            }
            return(-DokanNet.ERROR_FILE_NOT_FOUND);
        }
예제 #6
0
        public int FindFiles(string filename, System.Collections.ArrayList ofiles, DokanFileInfo info)
        {
            // THIS SHOULD ALWAYS EXISTS -- IF IT DOESN'T.. SCREW YOU WINDOWS!
            PFSDirectory dir = GetDirectory(filename);

            // Still, a little check should be done anyway.
            if (dir == null)
            {
                return(-1);
            }

            // Get file list
            foreach (KeyValuePair <string, ulong> file in files)
            {
                if (GetPath(file.Key) != filename)
                {
                    continue;
                }
                FileInformation fi = chunkMetadata[file.Value].files[file.Key].fileinfo;
                ofiles.Add(fi);
            }

            // Hard Fix : Root dir
            if (filename == "\\")
            {
                foreach (PFSDirectory innerdir in directories.Values)
                {
                    if (innerdir.name == "\\")
                    {
                        continue;
                    }
                    ofiles.Add(innerdir.info);
                }
                return(0);
            }

            // Get directory list
            foreach (PFSDirectory innerdir in dir.innerdirs.Values)
            {
                ofiles.Add(innerdir.info);
            }
            return(0);
        }
예제 #7
0
        public int MoveFile(string filename, string newname, bool replace, DokanFileInfo info)
        {
            PFSDirectory dir = GetDirectory(filename);

            // Is it a file?
            if (files.ContainsKey(filename))
            {
                ulong id = files[filename];
                // Change File record and metadata
                files.Add(newname, id);
                chunkMetadata[id].files.Add(newname, chunkMetadata[id].files[filename]);
                chunkMetadata[id].files[newname].fileinfo.FileName = GetFilename(newname);
                // Load and change inner Chunk record (if loaded)
                if (loadedChunks.ContainsKey(id))
                {
                    loadedChunks[id].files.Add(newname, loadedChunks[id].files[filename]);
                    // Remove old file from chunk
                    loadedChunks[id].files.Remove(filename);
                }
                // Remove old record from metadata and filelist
                chunkMetadata[id].files.Remove(filename);
                files.Remove(filename);
                // Check if we should save
                EditSave();
                return(0);
            }
            // Or is it a directory
            else if (dir != null)
            {
                // Check if it's a root dir
                if (directories.ContainsKey(filename))
                {
                    directories.Add(newname, directories[filename]);
                    directories[newname].name = directories[newname].info.FileName = GetFilename(newname);
                    directories.Remove(filename);
                }
                else
                {
                    // Find parent dir
                    // Split fulldir into parts
                    List <string> dirs    = new List <string>(filename.Split("\\".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                    string        basedir = "\\" + dirs[0];
                    // Remove basedir from array (Splicing)
                    dirs.RemoveAt(0);
                    PFSDirectory current = directories[basedir];
                    string       targetName = GetFilename(filename), newfname = GetFilename(newname);
                    foreach (string dirp in dirs)
                    {
                        if (dirp == targetName)
                        {
                            current.innerdirs.Add(newfname, current.innerdirs[targetName]);
                            current.innerdirs.Remove(targetName);
                            current      = current.innerdirs[newfname];
                            current.name = current.info.FileName = newfname;
                            break;
                        }
                        current = current.innerdirs[dirp];
                    }
                }
                Queue <Tuple <string, string> > renames = new Queue <Tuple <string, string> >();
                foreach (KeyValuePair <ulong, ChunkMetadata> cmd in chunkMetadata)
                {
                    bool isChunkLoaded = loadedChunks.ContainsKey(cmd.Key);
                    foreach (KeyValuePair <string, FileMetadata> file in cmd.Value.files)
                    {
                        if (file.Key.IndexOf(filename + "\\") < 0)
                        {
                            continue;
                        }
                        string newpath = file.Key.Replace(filename, newname);
                        renames.Enqueue(new Tuple <string, string>(file.Key, newpath));
                    }
                    while (renames.Count > 0)
                    {
                        Tuple <string, string> curItem = renames.Dequeue();
                        files.Add(curItem.Item2, files[curItem.Item1]);
                        files.Remove(curItem.Item1);
                        chunkMetadata[cmd.Key].files.Add(curItem.Item2, chunkMetadata[cmd.Key].files[curItem.Item1]);
                        chunkMetadata[cmd.Key].files.Remove(curItem.Item1);
                        if (isChunkLoaded)
                        {
                            loadedChunks[cmd.Key].files.Add(curItem.Item2, loadedChunks[cmd.Key].files[curItem.Item1]);
                            loadedChunks[cmd.Key].files.Remove(curItem.Item1);
                        }
                    }
                }
                // Check if we should save
                EditSave();
                return(0);
            }

            return(-1);
        }