private async Task UploadDirectoryRecursive(string directoryPath, string path) { labelAction.Text = "Uploading..."; labelContent.Text = path; System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(path); string brickPath = $"{directoryPath}{directoryInfo.Name}/"; await BrickExplorer.CreateDirectory(brickPath); foreach (System.IO.FileInfo file in directoryInfo.GetFiles()) { if (BrickExplorer.IsRobotFile(file.FullName)) { labelContent.Text = file.FullName; await BrickExplorer.UploadFile(file.FullName, brickPath, file.Name); } } if (UserSettings.Mode != Mode.BASIC) { foreach (System.IO.DirectoryInfo subDir in directoryInfo.GetDirectories()) { await UploadDirectoryRecursive(brickPath, subDir.FullName); } } }
/// <summary> /// Uploads a file to this directory. Any existing file will not be overriden. /// </summary> /// <param name="localFilePath">The absolute local filePath to a lego file on the local machine</param> /// <param name="fileName">The renamed fileName as stored on brick incl. extension</param> /// <returns></returns> public async Task <File> UploadFile(string localFilePath, string fileName) { bool success = await BrickExplorer.UploadFile(localFilePath, Path, fileName); if (success) { return(await GetFile(fileName)); } return(null); }
/// <summary> /// Uploads a file to this directory /// </summary> /// <param name="stream">The stream to a lego file on the local machine or resource file</param> /// <param name="type">The type of the filedata</param> /// <param name="fileName">The renamed fileName as stored on brick excl. extension</param> /// <returns></returns> public async Task <File> UploadFile(System.IO.Stream stream, FileType type, string fileName) { fileName = System.IO.Path.ChangeExtension(fileName, File.GetExtension(type)); bool success = await BrickExplorer.UploadFile(stream, Path, fileName); if (success) { return(await GetFile(fileName)); } return(null); }
/// <summary> /// Uploads a file to this directory. Any existing file will not be overriden. /// </summary> /// <param name="file">The byte[] filedata of a lego file on the local machine or resource file</param> /// <param name="type">The type of the filedata</param> /// <param name="fileName">The renamed fileName as stored on brick excl. extension</param> /// <returns></returns> public async Task <File> UploadFile(byte[] file, FileType type, string fileName) { fileName = $"{System.IO.Path.GetFileNameWithoutExtension(fileName)}{File.GetExtension(type)}"; bool success = await BrickExplorer.UploadFile(file, Path, fileName); if (success) { return(await GetFile(fileName)); } return(null); }
public async Task <bool> Save() { errorProvider.Clear(); if (string.IsNullOrWhiteSpace(textBoxFileName.Text)) { errorProvider.SetError(textBoxFileName, "Filename is required"); return(false); } string fileName = System.IO.Path.GetFileNameWithoutExtension(textBoxFileName.Text.Trim()); bool isNewName = !fileName.Equals(originalFileName, StringComparison.InvariantCultureIgnoreCase); if (!TextHasChanged && !isNewName) { return(true); } //textbox returns lines as /n .. weird should ne /r/n //so hack work around string[] lines = richTextBox.Lines; string text = "-"; if (lines?.Length > 0) { StringBuilder sb = new StringBuilder(); int lineCount = lines.Length; for (int i = 0; i < lineCount; i++) { if (i + 1 < lineCount) { sb.AppendLine(lines[i]); } else { sb.Append(lines[i]); } } text = sb.ToString(); } byte[] data = FileConverter.TexttoRTF(text); if (TextFile != null) { await BrickExplorer.UploadFile(data, Directory.Path, $"{fileName}.rtf"); if (isNewName) { await TextFile.Delete(); } } else { await BrickExplorer.UploadFile(data, Directory.Path, $"{fileName}.rtf"); } TextHasChanged = false; RefreshDirectory = true; return(true); }