/// <summary> /// Renames the item. /// </summary> public void RenameItem() { var dialog = new InputWindow("Insert name here", this.Name); dialog.ShowDialog(); if (dialog.Answer != "") { GoogleDriveAPI.Rename(dialog.Answer, this.Id);; Parent.Expand(); } }
/// <summary> /// Creates a new directory inside the item (if it's a drive or a directory) /// </summary> public void CreateDirectory() { var dialog = new InputWindow("Insert name here", "New folder"); dialog.ShowDialog(); if (dialog.Answer != "") { GoogleDriveAPI.CreateDirectory(dialog.Answer, this.Id); Expand(); DirectoryStructureViewModel.ActionType[0] = DirectoryItemActionType.Create; } }
/// <summary> /// Uploads a file to the item (if it's a drive or a directory) /// </summary> public void UploadFile() { var dialog = new OpenFileDialog(); dialog.ShowDialog(); if (dialog.FileName != "") { GoogleDriveAPI.UploadFile(dialog.FileName, this.Id); Expand(); DirectoryStructureViewModel.ActionType[0] = DirectoryItemActionType.Upload; } }
/// <summary> /// Gets all logical drive on the computer /// </summary> /// <returns></returns> public static List <DirectoryItem> GetDrives() { var root = GoogleDriveAPI.GetRootId(); List <DirectoryItem> drives = new List <DirectoryItem>(); drives.Add(new DirectoryItem { Name = root.Name, Id = root.Id, Type = DirectoryItemType.Drive }); return(drives); }
/// <summary> /// Get files of the directory. /// </summary> /// <param name="parentId">The id of the parent directory.</param> /// <returns></returns> public static List <DirectoryItem> GetFiles(string parentId) { var items = new List <DirectoryItem>(); var fs = GoogleDriveAPI.GetFiles(parentId); foreach (var file in fs.Files) { var newItem = new DirectoryItem() { Name = file.Name, Id = file.Id, Type = DirectoryItemType.File, }; items.Add(newItem); } return(items); }
/// <summary> /// Get directories of the directory. /// </summary> /// <param name="parentId">The id of the parent directory.</param> /// <returns></returns> public static List <DirectoryItem> GetDirectories(string parentId) { var items = new List <DirectoryItem>(); var dirs = GoogleDriveAPI.GetDirectories(parentId); foreach (var folder in dirs.Files) { var newItem = new DirectoryItem() { Name = folder.Name, Id = folder.Id, Type = DirectoryItemType.Folder, }; items.Add(newItem); } return(items); }
/// <summary> /// Downloads the item and saves it to the chosen path. /// </summary> public void DownloadItem() { var dialog = new FolderBrowserDialog(); dialog.Description = "Choose a location to save the file:"; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { if (this.Type == DirectoryItemType.File) { GoogleDriveAPI.DownloadFile(this.Id, this.Name, dialog.SelectedPath); } if (this.Type == DirectoryItemType.Folder) { GoogleDriveAPI.DownloadDirectory(this.Id, this.Name, dialog.SelectedPath); } DirectoryStructureViewModel.ActionType[0] = DirectoryItemActionType.Download; } }
/// <summary> /// Deletes the item /// </summary> public void DeleteItem() { GoogleDriveAPI.Delete(this.Id); Parent.Expand(); DirectoryStructureViewModel.ActionType[0] = DirectoryItemActionType.Delete; }