Exemplo n.º 1
0
        private async Task RecursiveRemoveForOffline(String sfoPath, String nodeName)
        {
            String newSfoPath = Path.Combine(sfoPath, nodeName);

            // Search if the folder has a pending transfer for offline and cancel it on this case
            TransfersService.CancelPendingNodeOfflineTransfers(String.Concat(newSfoPath, "\\"), this.IsFolder);

            IEnumerable <string> childFolders = Directory.GetDirectories(newSfoPath);

            if (childFolders != null)
            {
                foreach (var folder in childFolders)
                {
                    if (folder != null)
                    {
                        await RecursiveRemoveForOffline(newSfoPath, folder);

                        SavedForOffline.DeleteNodeByLocalPath(Path.Combine(newSfoPath, folder));
                    }
                }
            }

            IEnumerable <string> childFiles = Directory.GetFiles(newSfoPath);

            if (childFiles != null)
            {
                foreach (var file in childFiles)
                {
                    if (file != null)
                    {
                        SavedForOffline.DeleteNodeByLocalPath(Path.Combine(newSfoPath, file));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task RemoveForOffline(AutoResetEvent waitEventRequest = null)
        {
            String parentNodePath = ((new DirectoryInfo(this.NodePath)).Parent).FullName;

            String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""));

            if (this.IsFolder)
            {
                await RecursiveRemoveForOffline(parentNodePath, this.Name);

                FolderService.DeleteFolder(this.NodePath, true);
            }
            else
            {
                // Search if the file has a pending transfer for offline and cancel it on this case
                TransfersService.CancelPendingNodeOfflineTransfers(this.NodePath, this.IsFolder);

                FileService.DeleteFile(this.NodePath);
            }

            SavedForOffline.DeleteNodeByLocalPath(this.NodePath);

            if (this.ParentCollection != null)
            {
                this.ParentCollection.Remove((IOfflineNode)this);
            }

            if (waitEventRequest != null)
            {
                waitEventRequest.Set();
            }
        }
Exemplo n.º 3
0
        public async Task <bool> RemoveForOffline()
        {
            bool result;

            MNode parentNode = SdkService.MegaSdk.getParentNode(this.OriginalMNode);

            String parentNodePath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                                 AppResources.DownloadsDirectory.Replace("\\", ""),
                                                 (SdkService.MegaSdk.getNodePath(parentNode)).Remove(0, 1).Replace("/", "\\"));

            String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                              AppResources.DownloadsDirectory.Replace("\\", ""));

            var nodePath = Path.Combine(parentNodePath, this.Name);

            if (this.IsFolder)
            {
                await RecursiveRemoveForOffline(parentNodePath, this.Name);

                result = FolderService.DeleteFolder(nodePath, true);
            }
            else
            {
                // Search if the file has a pending transfer for offline and cancel it on this case
                TransfersService.CancelPendingNodeOfflineTransfers(nodePath, this.IsFolder);

                result = FileService.DeleteFile(nodePath);
            }

            SavedForOffline.DeleteNodeByLocalPath(nodePath);
            this.IsAvailableOffline = this.IsSelectedForOffline = false;

            // Check if the previous folders of the path are empty and
            // remove from the offline and the DB on this case
            while (String.Compare(parentNodePath, sfoRootPath) != 0)
            {
                var folderPathToRemove = parentNodePath;
                parentNodePath = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                if (FolderService.IsEmptyFolder(folderPathToRemove))
                {
                    result = result & FolderService.DeleteFolder(folderPathToRemove);
                    SavedForOffline.DeleteNodeByLocalPath(folderPathToRemove);
                }
            }

            return(result);
        }