Пример #1
0
        public Task <IEnumerable <string> > GetNameListingAsync(string path)
        {
            path = GetLocalVfsPath(path);
            List <string> result = PinvokeFilesystem.GetNames(path);

            return(Task.FromResult(result.AsEnumerable()));
        }
Пример #2
0
        public async Task RenameAsync(string fromPath, string toPath)
        {
            //get full path from parameter "fromPath"
            fromPath = GetLocalVfsPath(fromPath);
            toPath   = GetLocalVfsPath(toPath);

            PinvokeFilesystem.GetFileAttributesExFromApp((@"\\?\" + fromPath), PinvokeFilesystem.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo);
            if (lpFileInfo.dwFileAttributes == 0)
            {
                throw new FileNoAccessException("Can't find the item to rename");
            }
            else
            {
                if (lpFileInfo.dwFileAttributes.HasFlag(System.IO.FileAttributes.Directory))
                {
                    PinvokeFilesystem.CreateDirectoryFromApp(@"\\?\" + toPath, IntPtr.Zero);
                    if (!(await MoveFolderAsync(fromPath, toPath)))
                    {
                        throw new FileBusyException("Some items can't be moved");
                    }
                }
                else
                {
                    await Task.Run(() =>
                    {
                        PinvokeFilesystem.CopyFileFromApp(fromPath, toPath, false);
                        PinvokeFilesystem.DeleteFileFromApp(fromPath);
                    });
                }
            }
        }
Пример #3
0
        public async Task RecursivelyCreateDirectoryAsync(string path)
        {
            string parentPath = System.IO.Directory.GetParent(path).ToString();
            var    itemexists = ItemExists(parentPath);

            if (!itemexists)
            {
                await RecursivelyCreateDirectoryAsync(parentPath);
            }
            await Task.Run(() => { PinvokeFilesystem.CreateDirectoryFromApp((@"\\?\" + path), IntPtr.Zero); });
        }
Пример #4
0
 public bool ItemExists(string path)
 {
     PinvokeFilesystem.GetFileAttributesExFromApp((@"\\?\" + path), PinvokeFilesystem.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo);
     if (lpFileInfo.dwFileAttributes != 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #5
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());
            }
        }
Пример #6
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));
        }
Пример #7
0
        public async Task <DateTime> GetFileModificationTimeAsync(string path)
        {
            path = GetLocalVfsPath(path);
            var pathexists = ItemExists(path);

            if (pathexists)
            {
                return(await Task.Run(() => { return PinvokeFilesystem.GetFileModificationTime(path); }));
            }
            else
            {
                throw new FileNotFoundException();
            }
        }
Пример #8
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());
            }
        }
Пример #9
0
        public async Task <bool> SetFileModificationTimeAsync(string path, DateTime newTime)
        {
            path = GetLocalVfsPath(path);
            var pathexists = ItemExists(path);

            if (pathexists)
            {
                await Task.Run(() => { PinvokeFilesystem.SetFileModificationTime(path, newTime); });

                return(true);
            }
            else
            {
                throw new FileNotFoundException();
            }
        }
Пример #10
0
        public async Task RecursivelyDeleteDirectoryAsync(string path)
        {
            List <MonitoredFolderItem> mininfo = PinvokeFilesystem.GetMinInfo(path);

            foreach (MonitoredFolderItem item in mininfo)
            {
                string itempath = System.IO.Path.Combine(item.ParentFolderPath, item.Name);
                if (item.attributes.HasFlag(System.IO.FileAttributes.Directory))
                {
                    await RecursivelyDeleteDirectoryAsync(itempath);
                }
                else
                {
                    await Task.Run(() => { PinvokeFilesystem.DeleteFileFromApp(@"\\?\" + itempath); });
                }
            }
            await Task.Run(() => { PinvokeFilesystem.RemoveDirectoryFromApp(@"\\?\" + path); });
        }
Пример #11
0
 public async Task DeleteAsync(string path)
 {
     path = GetLocalVfsPath(path);
     PinvokeFilesystem.GetFileAttributesExFromApp((@"\\?\" + path), PinvokeFilesystem.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out var lpFileInfo);
     //this handling is only neccessary as winscp for some reason sends directory delete commands as file delete commands
     if (lpFileInfo.dwFileAttributes.HasFlag(System.IO.FileAttributes.Directory))
     {
         await RecursivelyDeleteDirectoryAsync(path);
     }
     else if (lpFileInfo.dwFileAttributes != 0)
     {
         await Task.Run(() => { PinvokeFilesystem.DeleteFileFromApp(@"\\?\" + path); });
     }
     else
     {
         throw new FileBusyException("Items of unknown type can't be deleted");
     }
     MainPage.Current.RefreshStorage();
 }
Пример #12
0
        private async Task <bool> MoveFolderAsync(string folder, string destination, bool firstcall = true)
        {
            List <MonitoredFolderItem> mininfo = PinvokeFilesystem.GetMinInfo(folder);

            foreach (MonitoredFolderItem item in mininfo)
            {
                string itempath   = System.IO.Path.Combine(item.ParentFolderPath, item.Name);
                string targetpath = System.IO.Path.Combine(destination, item.Name);
                if (item.attributes.HasFlag(System.IO.FileAttributes.Directory))
                {
                    await Task.Run(() =>
                    {
                        PinvokeFilesystem.CreateDirectoryFromApp(@"\\?\" + targetpath, IntPtr.Zero);
                    });
                    await MoveFolderAsync(itempath, targetpath, false);
                }
                else
                {
                    //move file
                    await Task.Run(() =>
                    {
                        PinvokeFilesystem.CopyFileFromApp(@"\\?\" + itempath, @"\\?\" + targetpath, false);
                        PinvokeFilesystem.DeleteFileFromApp(@"\\?\" + itempath);
                    });
                }
            }
            mininfo = PinvokeFilesystem.GetMinInfo(folder);
            if (mininfo.Count() == 0)
            {
                await Task.Run(() => { PinvokeFilesystem.RemoveDirectoryFromApp(@"\\?\" + folder); });

                if (firstcall)
                {
                    MainPage.Current.RefreshStorage();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #13
0
        public Task <IEnumerable <FileSystemEntry> > GetListingAsync(string path)
        {
            if (path == "-a" || path == "-al")
            {
                path = "";
            }
            string fullPath = GetLocalPath(path);

            //SetWorkingDirectory(fullPath);
            string[] splitpath = fullPath.Split("VFSROOT");

            //create empty list of filesystem entries
            List <FileSystemEntry> result = new List <FileSystemEntry>();

            //check if the current path is the root of the virtual filesystem
            // the \\- check is to make sure that it is not a sub command being entered
            if (splitpath[1] == "" || splitpath[1].StartsWith("\\-"))
            {
                //if in this if statement then the check returned true
                //get all drives
                List <string> drives = PinvokeFilesystem.GetDrives();
                //loop through all the drives
                foreach (string drive in drives)
                {
                    //create an entry for the current drive
                    FileSystemEntry entry = new FileSystemEntry()
                    {
                        IsDirectory   = true,
                        IsReadOnly    = true,
                        LastWriteTime = DateTime.Now,
                        Length        = 0,
                        Name          = drive
                    };
                    //add the entry
                    result.Add(entry);
                }

                //add entry for the so called Local folder - used to access apps local data
                FileSystemEntry localentry = new FileSystemEntry()
                {
                    IsDirectory   = true,
                    IsReadOnly    = true,
                    LastWriteTime = DateTime.Now,
                    Length        = 0,
                    Name          = "LOCALFOLDER"
                };
                //add the entry that was just created

                result.Add(localentry);
            }
            else
            {
                string reformatedpath = GetLocalVfsPath(path);
                List <MonitoredFolderItem> monfiles = PinvokeFilesystem.GetItems(reformatedpath);
                foreach (var item in monfiles)
                {
                    switch (item.Name)
                    {
                    case ".":
                        break;

                    case "..":
                        break;

                    case "":
                        break;

                    default:
                        FileSystemEntry entry = new FileSystemEntry()
                        {
                            IsDirectory   = item.IsDir,
                            IsReadOnly    = item.attributes.HasFlag(System.IO.FileAttributes.ReadOnly),
                            LastWriteTime = item.DateModified.ToUniversalTime().DateTime,
                            Length        = (long)item.Size,
                            Name          = item.Name
                        };
                        result.Add(entry);
                        break;
                    }
                }
            }

            //return list of entrys
            MainPage.Current.RefreshStorage();
            return(Task.FromResult(result.AsEnumerable()));
        }