Exemple #1
0
        public override bool TryConvertVirtualizationRoot(string directory, out string error)
        {
            Result result = VirtualizationInstance.ConvertDirectoryToVirtualizationRoot(directory);

            error = result.ToString();
            return(result == Result.Success);
        }
 public MacFileSystemVirtualizer(
     GVFSContext context,
     GVFSGitObjects gitObjects,
     VirtualizationInstance virtualizationInstance)
     : base(context, gitObjects)
 {
     this.virtualizationInstance = virtualizationInstance ?? new VirtualizationInstance();
 }
Exemple #3
0
        public override bool TryConvertVirtualizationRoot(string directory, out string error)
        {
            error = string.Empty;
            HResult result = VirtualizationInstance.ConvertDirectoryToVirtualizationRoot(Guid.NewGuid(), directory);

            if (result != HResult.Ok)
            {
                error = result.ToString("F");
                return(false);
            }

            return(true);
        }
Exemple #4
0
        public bool TryPrepareFolderForCallbacks(string folderPath, out string error)
        {
            error = string.Empty;
            Result result = VirtualizationInstance.ConvertDirectoryToVirtualizationRoot(folderPath);

            if (result != Result.Success)
            {
                error = "Failed to prepare \"" + folderPath + "\" for callbacks, error: " + result.ToString("F");
                return(false);
            }

            return(true);
        }
Exemple #5
0
        // Using an Impl method allows TryPrepareFolderForCallbacks to catch any ProjFS dependency related exceptions
        // thrown in the process of calling this method.
        private bool TryPrepareFolderForCallbacksImpl(string folderPath, out string error)
        {
            error = string.Empty;
            Guid    virtualizationInstanceGuid = Guid.NewGuid();
            HResult result = VirtualizationInstance.ConvertDirectoryToVirtualizationRoot(virtualizationInstanceGuid, folderPath);

            if (result != HResult.Ok)
            {
                error = "Failed to prepare \"" + folderPath + "\" for callbacks, error: " + result.ToString("F");
                return(false);
            }

            return(true);
        }
        public override bool TryStartVirtualizationInstance(Enlistment enlistment, out string error)
        {
            this.virtualizationInstance.OnQueryFileName        = this.QueryFileName;
            this.virtualizationInstance.OnNotifyPreDelete      = this.OnPreDelete;
            this.virtualizationInstance.OnNotifyNewFileCreated = this.OnNewFileCreated;
            this.virtualizationInstance.OnNotifyFileHandleClosedFileModifiedOrDeleted = this.OnFileModifiedOrDeleted;
            this.virtualizationInstance.OnNotifyFileRenamed          = this.OnFileRenamed;
            this.virtualizationInstance.OnNotifyHardlinkCreated      = this.OnHardlinkCreated;
            this.virtualizationInstance.OnNotifyFilePreConvertToFull = this.OnFilePreConvertToFull;

            uint threadCount = (uint)Environment.ProcessorCount * 2;

            NotificationMapping[] notificationMappings = new NotificationMapping[]
            {
                new NotificationMapping(
                    NotificationType.NewFileCreated |
                    NotificationType.PreDelete |
                    NotificationType.FileRenamed |
                    NotificationType.HardlinkCreated |
                    NotificationType.FileHandleClosedFileModified,
                    string.Empty),
            };

            this.virtualizationInstance = new VirtualizationInstance(
                enlistment.SrcRoot,
                poolThreadCount: threadCount,
                concurrentThreadCount: threadCount,
                enableNegativePathCache: false,
                notificationMappings: notificationMappings);

            HResult result = this.virtualizationInstance.StartVirtualizing(this);

            if (result == HResult.Ok)
            {
                return(base.TryStartVirtualizationInstance(enlistment, out error));
            }

            error = result.ToString("F");
            return(false);
        }
Exemple #7
0
        public bool InitProjection()
        {
            Stop();

            try {
                _sftpClient.Connect();
            } catch (Exception e) {
                MessageBox.Show($"{e.Message}\n{e.StackTrace}", "Failed to connect to sftp server");
                return(false);
            }

            SftpRootPath = _sftpClient.WorkingDirectory;

            try {
                _virtInstance = new VirtualizationInstance(VirtualizationDirectory.FullName, 0, 0, false, new NotificationMapping[0]);
                VirtualizationDirectory.Refresh();
            } catch (Exception e) {
                MessageBox.Show($"{e.Message}\n{e.StackTrace}", "Failed to create virtualization instance");
                return(false);
            }
            return(true);
        }
Exemple #8
0
        public PakProvider(string filePath, string targetRoot)
        {
            this.filePath   = filePath;
            this.targetRoot = targetRoot;

            // Read pak file
            fileStream   = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            binaryReader = new BinaryReader(fileStream);

            var reader   = new PakReader();
            var metadata = reader.ReadIndex(binaryReader);

            this.metadata = Encoding.UTF8.GetBytes(metadata.ToString(Newtonsoft.Json.Formatting.Indented));
            var files = reader.FindItems(binaryReader);

            fileTree = new Dictionary <string, List <PakItem> >();

            // Map assets
            foreach (var file in files)
            {
                var dir = file.Path.Substring(0, file.Path.LastIndexOf("/") + 1);
                if (!fileTree.ContainsKey(dir))
                {
                    fileTree[dir] = new List <PakItem>();
                }
                fileTree[dir].Add(file);
            }

            // Set up virtualization
            var notificationMappings = new List <NotificationMapping> {
                new NotificationMapping(NotificationType.FileOpened | NotificationType.PreDelete | NotificationType.PreRename, string.Empty)
            };

            virtualizationInstance = new VirtualizationInstance(targetRoot, 0, 0, false, notificationMappings);
            // Disallow delete/rename.
            virtualizationInstance.OnNotifyPreDelete = new NotifyPreDeleteCallback((a, b, c, d) => false);
            virtualizationInstance.OnNotifyPreRename = new NotifyPreRenameCallback((a, b, c, d) => false);
            enumerations = new ConcurrentDictionary <Guid, FileEnumeration>();
        }
Exemple #9
0
 public RequiredCallbacks(FileProvider provider, VirtualizationInstance virtualization, SftpClient client)
 {
     fileProvider        = provider;
     this.virtualization = virtualization;
     sftpClient          = client;
 }
        public SimpleProvider(ProviderOptions options)
        {
            this.scratchRoot = options.VirtRoot;
            this.layerRoot   = options.SourceRoot;

            this.Options = options;

            // If in test mode, enable notification callbacks.
            if (this.Options.TestMode)
            {
                this.Options.EnableNotifications = true;
            }

            // Enable notifications if the user requested them.
            List <NotificationMapping> notificationMappings;

            if (this.Options.EnableNotifications)
            {
                string rootName = string.Empty;
                notificationMappings = new List <NotificationMapping>()
                {
                    new NotificationMapping(
                        NotificationType.FileOpened
                        | NotificationType.NewFileCreated
                        | NotificationType.FileOverwritten
                        | NotificationType.PreDelete
                        | NotificationType.PreRename
                        | NotificationType.PreCreateHardlink
                        | NotificationType.FileRenamed
                        | NotificationType.HardlinkCreated
                        | NotificationType.FileHandleClosedNoModification
                        | NotificationType.FileHandleClosedFileModified
                        | NotificationType.FileHandleClosedFileDeleted
                        | NotificationType.FilePreConvertToFull,
                        rootName)
                };
            }
            else
            {
                notificationMappings = new List <NotificationMapping>();
            }

            try
            {
                // This will create the virtualization root directory if it doesn't already exist.
                this.virtualizationInstance = new VirtualizationInstance(
                    this.scratchRoot,
                    poolThreadCount: 0,
                    concurrentThreadCount: 0,
                    enableNegativePathCache: false,
                    notificationMappings: notificationMappings);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Failed to create VirtualizationInstance.");
                throw;
            }

            // Set up notifications.
            notificationCallbacks = new NotificationCallbacks(
                this,
                this.virtualizationInstance,
                notificationMappings);

            Log.Information("Created instance. Layer [{Layer}], Scratch [{Scratch}]", this.layerRoot, this.scratchRoot);

            if (this.Options.TestMode)
            {
                Log.Information("Provider started in TEST MODE.");
            }

            this.activeEnumerations = new ConcurrentDictionary <Guid, ActiveEnumeration>();
        }
Exemple #11
0
        public NotificationCallbacks(
            SimpleProvider provider,
            VirtualizationInstance virtInstance,
            IReadOnlyCollection <NotificationMapping> notificationMappings)
        {
            this.provider = provider;

            // Look through notificationMappings for all the set notification bits.  Supply a callback
            // for each set bit.
            NotificationType notification = NotificationType.None;

            foreach (NotificationMapping mapping in notificationMappings)
            {
                notification |= mapping.NotificationMask;
            }

            if ((notification & NotificationType.FileOpened) == NotificationType.FileOpened)
            {
                virtInstance.OnNotifyFileOpened = NotifyFileOpenedCallback;
            }

            if ((notification & NotificationType.NewFileCreated) == NotificationType.NewFileCreated)
            {
                virtInstance.OnNotifyNewFileCreated = NotifyNewFileCreatedCallback;
            }

            if ((notification & NotificationType.FileOverwritten) == NotificationType.FileOverwritten)
            {
                virtInstance.OnNotifyFileOverwritten = NotifyFileOverwrittenCallback;
            }

            if ((notification & NotificationType.PreDelete) == NotificationType.PreDelete)
            {
                virtInstance.OnNotifyPreDelete = NotifyPreDeleteCallback;
            }

            if ((notification & NotificationType.PreRename) == NotificationType.PreRename)
            {
                virtInstance.OnNotifyPreRename = NotifyPreRenameCallback;
            }

            if ((notification & NotificationType.PreCreateHardlink) == NotificationType.PreCreateHardlink)
            {
                virtInstance.OnNotifyPreCreateHardlink = NotifyPreCreateHardlinkCallback;
            }

            if ((notification & NotificationType.FileRenamed) == NotificationType.FileRenamed)
            {
                virtInstance.OnNotifyFileRenamed = NotifyFileRenamedCallback;
            }

            if ((notification & NotificationType.HardlinkCreated) == NotificationType.HardlinkCreated)
            {
                virtInstance.OnNotifyHardlinkCreated = NotifyHardlinkCreatedCallback;
            }

            if ((notification & NotificationType.FileHandleClosedNoModification) == NotificationType.FileHandleClosedNoModification)
            {
                virtInstance.OnNotifyFileHandleClosedNoModification = NotifyFileHandleClosedNoModificationCallback;
            }

            if (((notification & NotificationType.FileHandleClosedFileModified) == NotificationType.FileHandleClosedFileModified) ||
                ((notification & NotificationType.FileHandleClosedFileDeleted) == NotificationType.FileHandleClosedFileDeleted))
            {
                virtInstance.OnNotifyFileHandleClosedFileModifiedOrDeleted = NotifyFileHandleClosedFileModifiedOrDeletedCallback;
            }

            if ((notification & NotificationType.FilePreConvertToFull) == NotificationType.FilePreConvertToFull)
            {
                virtInstance.OnNotifyFilePreConvertToFull = NotifyFilePreConvertToFullCallback;
            }
        }
 public RequiredCallbacks(VirtualizationInstance virtualization, SftpClient client)
 {
     _virtInstance = virtualization;
     _sftpClient   = client;
 }