示例#1
0
        public PboFsRealFolder(string name, string inputPath, PboFsFolder inputParent) : base(name, inputParent)
        {
            path = inputPath;

            var dirInfo = new DirectoryInfo(path);

            FileInformation.Attributes    = dirInfo.Attributes;
            FileInformation.CreationTime  = dirInfo.CreationTime;
            FileInformation.LastWriteTime = dirInfo.LastWriteTime;
            FileInformation.LastWriteTime = dirInfo.LastWriteTime;
        }
示例#2
0
 public PboFsFolder(string name, PboFsFolder inputParent) : base()
 {
     Children        = new Dictionary <string, IPboFsNode>();
     parent          = inputParent;
     FileInformation = new DokanNet.FileInformation()
     {
         Attributes     = System.IO.FileAttributes.Directory,
         FileName       = name,
         LastAccessTime = DateTime.Now,
         LastWriteTime  = DateTime.Now,
         CreationTime   = DateTime.Now,
     };
 }
示例#3
0
        void injectFile(FileInfo file, PboFsFolder rootDirectory, string fileFullRealPath)
        {
            if (fileTreeLookup.Contains(new PboFsLookupDummy(fileFullRealPath)))
            {
                //file from writeable directory overrides pbo file.
                Console.WriteLine("DokanPbo::LinkRealDirectory overwriting file from PBO with real file: " + fileFullRealPath);
                fileTreeLookup.Remove(new PboFsLookupDummy(fileFullRealPath));
            }

            var newFile = new PboFsRealFile(file, rootDirectory);

            rootDirectory.Children[file.Name.ToLower()] = newFile;
            this.fileTreeLookup.Add(newFile);
        }
示例#4
0
        public PboFsRealFile(System.IO.FileInfo inputFile, PboFsFolder inputParent) : base()
        {
            file   = inputFile;
            parent = inputParent;

            FileInformation = new DokanNet.FileInformation()
            {
                Attributes     = file.Attributes,
                FileName       = file.Name,
                Length         = file.Length,
                LastAccessTime = file.LastAccessTime,
                LastWriteTime  = file.LastWriteTime,
                CreationTime   = file.CreationTime,
            };
        }
示例#5
0
        private List <string> GetFolderPathElements(PboFsFolder folder)
        {
            var         output      = new List <string>();
            PboFsFolder currentNode = folder;

            output.Add(currentNode.FileInformation.FileName);
            while (currentNode.parent != null)
            {
                currentNode = currentNode.parent;
                output.Add(currentNode.FileInformation.FileName ?? "\\"); //root node has null FileName
            }

            output.Reverse();
            return(output);
        }
示例#6
0
        public PboFsFile(string name, FileEntry file, PboFsFolder inputParent) : base()
        {
            File = file;
            var fileTimestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime().AddSeconds(file.TimeStamp);

            parent          = inputParent;
            FileInformation = new DokanNet.FileInformation()
            {
                Attributes     = System.IO.FileAttributes.Normal | FileAttributes.ReadOnly,
                FileName       = name,
                Length         = (long)file.DataSize,
                LastAccessTime = DateTime.Now,
                LastWriteTime  = fileTimestamp,
                CreationTime   = fileTimestamp,
            };
        }
示例#7
0
        private PboFsFolder CreateOrFindDirectoryRecursive(string fullPath)
        {
            var node = FindNode(fullPath);

            if (node != null)
            {
                return(node as PboFsFolder);
            }

            var currentPath = "\\";
            var splitPath   = fullPath.Remove(0, 1).Split('\\');

            PboFsFolder currentFolder = FindNode("\\") as PboFsFolder;//get root node

            // Create folder for all sub paths
            foreach (var folderName in splitPath)
            {
                currentPath += folderName;

                PboFsFolder folder    = null;
                var         foundNode = FindNode(currentPath);
                if (foundNode == null)
                {
                    folder = new PboFsFolder(folderName, currentFolder);
                    fileTree.AddNode(folder);
                }
                else
                {
                    folder = (PboFsFolder)foundNode;
                }

                if (!currentFolder.Children.ContainsKey(folderName.ToLower()))
                {
                    currentFolder.Children[folderName.ToLower()] = currentFolder = folder;
                }
                else
                {
                    currentFolder = (PboFsFolder)currentFolder.Children[folderName.ToLower()];
                }

                currentPath += "\\";
            }
            return(currentFolder);
        }
示例#8
0
        public PboFsRealFolder MakeDirectoryWriteable(PboFsFolder inputFolder)
        {
            List <string> pathElements = GetFolderPathElements(inputFolder);

            pathElements.Remove("\\"); //root node is already writeable
            string currentPath = "";

            foreach (var element in pathElements)
            {
                currentPath += "\\" + element;

                var currentDirectoryNode = NodeForPath(currentPath) as PboFsFolder;

                string currentDirectoryName = currentDirectoryNode.FileInformation.FileName;

                if (currentDirectoryNode is PboFsRealFolder)
                {
                    continue;                                          //already writeable
                }
                try
                {
                    if (!Directory.Exists(writeableDirectory + currentPath))
                    {
                        Directory.CreateDirectory(writeableDirectory + currentPath);
                    }


                    var folderR = new PboFsRealFolder(currentDirectoryName, writeableDirectory + currentPath, currentDirectoryNode.parent);
                    folderR.Children = currentDirectoryNode.Children;
                    folderR.parent.Children[currentDirectoryName.ToLower()] = folderR;
                    fileTreeLookup.Remove(currentDirectoryNode);
                    fileTreeLookup.Add(folderR);
                    //Done.
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine(e.Message);
                }
            }

            return(NodeForPath(currentPath) as PboFsRealFolder);
        }
示例#9
0
 //writeableStream is from newly created file
 public PboFsRealFile(System.IO.FileInfo inputFile, PboFsFolder inputParent, System.IO.FileStream writeableStream) : this(inputFile, inputParent)
 {
     writeStream = writeableStream;
 }
示例#10
0
 public PboFsDebinarizedFile(string name, FileEntry file, PboFsFolder inputParent) : base(name, file, inputParent)
 {
 }
示例#11
0
        void LinkRealDirectory(System.IO.DirectoryInfo root, string currentPath, PboFsFolder rootDir, bool first)
        {
            System.IO.FileInfo[]      files   = null;
            System.IO.DirectoryInfo[] subDirs = null;

            if (first)
            {
                // First, process all the files directly under this inputFolder
                try
                {
                    files = root.GetFiles("*.*");
                }
                // This is thrown if even one of the files requires permissions greater
                // than the application provides.
                catch (UnauthorizedAccessException e)
                {
                    Console.WriteLine(e);
                }
                catch (System.IO.DirectoryNotFoundException e)
                {
                    Console.WriteLine(e);
                }

                if (files == null)
                {
                    return;
                }


                foreach (var fi in files)
                {
                    injectFile(fi, rootDir, currentPath + "\\" + fi.Name.ToLower());
                }

                // Now find all the subdirectories under this directory.
                subDirs = root.GetDirectories();

                foreach (var dirInfo in subDirs)
                {
                    // Resursive call for each subdirectory.
                    LinkRealDirectory(dirInfo, currentPath, rootDir, false);
                }

                return;
            }



            currentPath += "\\" + root.Name.ToLower();

            //Make sure rootDir is writeable
            if (!(rootDir is PboFsRealFolder))
            {
                rootDir = MakeDirectoryWriteable(rootDir);
            }
            PboFsRealFolder currentFolder;

            //If inputFolder already exists make it writeable
            fileTreeLookup.TryGetValue(new PboFsLookupDummy(currentPath), out var existingNode);
            if (existingNode != null)
            {
                var existingCurrentFolder = existingNode as PboFsFolder;
                if (existingCurrentFolder is PboFsRealFolder existingCurrentFolderReal)
                {
                    currentFolder = existingCurrentFolderReal;
                }
                else
                {
                    currentFolder = MakeDirectoryWriteable(existingCurrentFolder);
                }
            }
            else
            {
                currentFolder = new PboFsRealFolder(root.Name, root.FullName, rootDir);
                rootDir.Children[root.Name.ToLower()] = currentFolder;
                this.fileTreeLookup.Add(currentFolder);
            }



            // First, process all the files directly under this inputFolder
            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                Console.WriteLine(e);
            }



            if (files == null)
            {
                return;
            }

            foreach (var fi in files)
            {
                injectFile(fi, currentFolder, currentPath + "\\" + fi.Name.ToLower());
            }

            // Now find all the subdirectories under this directory.
            subDirs = root.GetDirectories();

            foreach (var dirInfo in subDirs)
            {
                // Resursive call for each subdirectory.
                LinkRealDirectory(dirInfo, currentPath, currentFolder, false);
            }
        }
示例#12
0
        private void CreateFileTree()
        {
            this.root           = new PboFsRealFolder(null, writeableDirectory, null);
            this.fileTreeLookup = new HashSet <IPboFsNode>();
            this.fileTreeLookup.Add(this.root);
            var hasCfgConvert = PboFS.HasCfgConvert();

            foreach (string filePath in this.archiveManager.FilePathToFileEntry.Keys)
            {
                if (excludePrefix != null && filePath.StartsWith(excludePrefix))
                {
                    continue;
                }
                FileEntry file = this.archiveManager.FilePathToFileEntry[filePath];

                PboFsFolder currentFolder = root;
                var         currentPath   = "\\";
                var         splitPath     = filePath.Split('\\');

                // Create inputFolder for all sub paths
                for (int i = 1; i < splitPath.Length - 1; i++)
                {
                    var folderName = splitPath[i];
                    currentPath += folderName;

                    PboFsFolder folder = null;
                    if (!this.fileTreeLookup.Contains(new PboFsLookupDummy(currentPath)))
                    {
                        folder = new PboFsFolder(folderName, currentFolder);
                        this.fileTreeLookup.Add(folder);
                    }
                    else
                    {
                        fileTreeLookup.TryGetValue(new PboFsLookupDummy(currentPath), out var node);
                        folder = node as PboFsFolder;
                    }

                    if (!currentFolder.Children.ContainsKey(folderName))
                    {
                        currentFolder.Children[folderName] = currentFolder = folder;
                    }
                    else
                    {
                        currentFolder = (PboFsFolder)currentFolder.Children[folderName];
                    }

                    currentPath += "\\";
                }

                var fileName = splitPath[splitPath.Length - 1];
                var fileNode = new PboFsFile(fileName, file, currentFolder);
                currentFolder.Children[fileName] = fileNode;
                this.fileTreeLookup.Add(fileNode);
                if (hasCfgConvert && fileName == "config.bin")
                {
                    var derapNode = new PboFsDebinarizedFile("config.cpp", file, currentFolder);
                    currentFolder.Children["config.cpp"] = derapNode;
                    this.fileTreeLookup.Add(derapNode);
                }
            }

            //Interweave writeableDirectory
            LinkRealDirectory(new System.IO.DirectoryInfo(writeableDirectory), "", this.root, true);
        }
示例#13
0
        private void CreateFileTree()
        {
            this.root           = new PboFsRealFolder(null, writeableDirectory, null);
            this.fileTreeLookup = new HashSet <IPboFsNode>();
            this.fileTreeLookup.Add(this.root);
            var hasCfgConvert = PboFS.HasCfgConvert();


            foreach (var(filePath, file) in this.archiveManager.Enumerator)
            {
                if (excludePrefix != null && filePath.StartsWith(excludePrefix))
                {
                    continue;
                }
                this.archiveManager.TotalBytes += (long)file.DataSize;

                PboFsFolder currentFolder = root;
                var         currentPath   = "\\";
                var         splitPath     = filePath.Split(PboFsLookupDummy.PathChars, StringSplitOptions.RemoveEmptyEntries);

                // Make sure the files directory path exists
                for (int i = 0; i < splitPath.Length - 1; i++)
                {
                    var folderName = splitPath[i];
                    currentPath += folderName;

                    //A part of the path might already exist, walking the tree directly via this shortcut saves alot of time
                    currentFolder.Children.TryGetValue(folderName, out var subFolderNode);
                    if (subFolderNode is PboFsFolder subFolder)
                    {
                        currentFolder = subFolder;
                        currentPath  += "\\";
                        continue;
                    }
                    var lookup = new PboFsLookupDummy(currentPath);

                    PboFsFolder folder = null;
                    if (!this.fileTreeLookup.Contains(lookup))
                    {
                        folder = new PboFsFolder(folderName, currentFolder);
                        this.fileTreeLookup.Add(folder);
                    }
                    else
                    {
                        fileTreeLookup.TryGetValue(lookup, out var node);
                        folder = node as PboFsFolder;
                    }

                    if (!currentFolder.Children.ContainsKey(folderName))
                    {
                        currentFolder.Children[folderName] = currentFolder = folder;
                    }
                    else
                    {
                        currentFolder = (PboFsFolder)currentFolder.Children[folderName];
                    }

                    currentPath += "\\";
                }

                var fileName = splitPath[splitPath.Length - 1];
                var fileNode = new PboFsFile(fileName, file, currentFolder);

                if (hasCfgConvert && fileName.EndsWith("rvmat"))
                {
                    byte[] buffer = new byte[4];
                    fileNode.ReadFile(buffer, out var length, 0);
                    if (buffer[0] == 0 && buffer[1] == 'r' && buffer[2] == 'a' && buffer[3] == 'P')
                    {
                        var derapNode = new PboFsDebinarizedFile(fileName, file, currentFolder);
                        currentFolder.Children[fileName] = derapNode;
                        this.fileTreeLookup.Add(derapNode);
                        continue;
                    }
                }

                currentFolder.Children[fileName] = fileNode;
                this.fileTreeLookup.Add(fileNode);

                if (hasCfgConvert && fileName == "config.bin")
                {
                    var derapNode = new PboFsDebinarizedFile("config.cpp", file, currentFolder);
                    currentFolder.Children["config.cpp"] = derapNode;
                    this.fileTreeLookup.Add(derapNode);
                }
            }

            //Interweave writeableDirectory
            LinkRealDirectory(new System.IO.DirectoryInfo(writeableDirectory), "", this.root, true);
        }