コード例 #1
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);
                    });
                }
            }
        }
コード例 #2
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); });
        }
コード例 #3
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();
 }
コード例 #4
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);
            }
        }