Ejemplo n.º 1
0
        public async Task <Stream> OpenFileForWriteAsync(string path)
        {
            path = GetLocalVfsPath(path);
            try
            {
                IntPtr hStream = PinvokeFilesystem.CreateFileFromApp((@"\\?\" + path), PinvokeFilesystem.GENERIC_WRITE | PinvokeFilesystem.GENERIC_READ, 0, IntPtr.Zero, PinvokeFilesystem.OPEN_ALWAYS, (uint)PinvokeFilesystem.File_Attributes.BackupSemantics, IntPtr.Zero);
                return(new FileStream(hStream, FileAccess.ReadWrite));
            } catch {
                var file = await StorageFile.GetFileFromPathAsync(path);

                return(await file.OpenStreamForWriteAsync());
            }
        }
Ejemplo n.º 2
0
        public async Task <Stream> CreateFileForWriteAsync(string path)
        {
            path = GetLocalVfsPath(path);
            string parentPath   = Path.GetDirectoryName(path);
            var    parentexists = ItemExists(parentPath);

            if (!parentexists)
            {
                await RecursivelyCreateDirectoryAsync(parentPath);
            }
            IntPtr hStream = PinvokeFilesystem.CreateFileFromApp(path, PinvokeFilesystem.GENERIC_WRITE, 0, IntPtr.Zero, PinvokeFilesystem.CREATE_ALWAYS, (uint)PinvokeFilesystem.File_Attributes.BackupSemantics, IntPtr.Zero);

            return(new FileStream(hStream, FileAccess.Write));
        }
Ejemplo n.º 3
0
        public async Task <Stream> OpenFileForReadAsync(string path)
        {
            path = GetLocalVfsPath(path);
            try
            {
                IntPtr hStream = PinvokeFilesystem.CreateFileFromApp((@"\\?\" + path), PinvokeFilesystem.GENERIC_READ, 0, IntPtr.Zero, PinvokeFilesystem.OPEN_ALWAYS, 4, IntPtr.Zero);
                return(new FileStream(hStream, FileAccess.Read));
            }
            catch
            {
                var file = await StorageFile.GetFileFromPathAsync(path);

                return(await file.OpenStreamForReadAsync());
            }
        }