Пример #1
0
 public IActionResult RenameFile(string filePath, [FromQuery] string newName)
 {
     if (!IsRestrictedPath(filePath))
     {
         var file = new PEngineFileModel(filePath);
         if (file.Valid)
         {
             var fullFolderPath = file.FullPath.Substring(0, file.FullPath.Length - file.Name.Length).TrimEnd(Path.DirectorySeparatorChar);
             var folderPath     = filePath.Substring(0, filePath.Length - file.Name.Length).TrimEnd(Path.DirectorySeparatorChar);
             var newFilePath    = $"{fullFolderPath}{Path.DirectorySeparatorChar}{newName}";
             if (!System.IO.File.Exists(newFilePath))
             {
                 System.IO.File.Move(file.FullPath, newFilePath);
                 return(this.Get(folderPath));
             }
             return(this.BadRequest());
         }
         return(this.NotFound());
     }
     return(this.BadRequest());
 }
Пример #2
0
        public IActionResult ProcessSelections(SelectionOperation operation, string targetFolderPath, [FromBody] PEngineResourceSelectionModel selections)
        {
            if (!IsRestrictedPath(targetFolderPath))
            {
                var targetFolder = new PEngineFolderModel(targetFolderPath);
                if (targetFolder.Valid && selections != null)
                {
                    bool valid = false;
                    if (selections.FilePaths != null && selections.FilePaths.Any())
                    {
                        foreach (var filePath in selections.FilePaths)
                        {
                            if (!IsRestrictedPath(filePath))
                            {
                                var file           = new PEngineFileModel(filePath);
                                var targetFullPath = $"{targetFolder.FullPath}{System.IO.Path.DirectorySeparatorChar}{file.Name}";
                                if (file.Valid)
                                {
                                    switch (operation)
                                    {
                                    case SelectionOperation.Copy:
                                        System.IO.File.Copy(file.FullPath, targetFullPath);
                                        break;

                                    case SelectionOperation.Move:
                                        System.IO.File.Move(file.FullPath, targetFullPath);
                                        break;

                                    case SelectionOperation.Delete:
                                        System.IO.File.Delete(file.FullPath);
                                        break;
                                    }
                                    valid = true;
                                }
                            }
                        }
                    }
                    if (selections.FolderPaths != null && selections.FolderPaths.Any())
                    {
                        foreach (var folderPath in selections.FolderPaths)
                        {
                            if (!IsRestrictedPath(folderPath))
                            {
                                var folder         = new PEngineFolderModel(folderPath);
                                var targetFullPath = $"{targetFolder.FullPath}{System.IO.Path.DirectorySeparatorChar}{folder.Name}";
                                if (folder.Valid)
                                {
                                    switch (operation)
                                    {
                                    case SelectionOperation.Copy:
                                        CopyFolder(folder.FullPath, targetFullPath);
                                        break;

                                    case SelectionOperation.Move:
                                        System.IO.Directory.Move(folder.FullPath, targetFullPath);
                                        break;

                                    case SelectionOperation.Delete:
                                        System.IO.Directory.Delete(folder.FullPath, true);
                                        break;
                                    }
                                    valid = true;
                                }
                            }
                        }
                    }
                    if (valid)
                    {
                        return(Get(targetFolderPath));
                    }
                }
            }
            return(this.BadRequest());
        }