// Warning: paths returned by FileBrowser dialogs do not contain a trailing '\' character // Warning: FileBrowser can only show 1 dialog at a time public void OpenDialog() { // Set filters (optional) // It is sufficient to set the filters just once (instead of each time before showing the file browser dialog), // if all the dialogs will be using the same filters FileBrowser.SetFilters(true, new FileBrowser.Filter("RFP File", ".rfp")); // Set default filter that is selected when the dialog is shown (optional) // Returns true if the default filter is set successfully // In this case, set Images filter as the default filter FileBrowser.SetDefaultFilter(".rfp"); // Set excluded file extensions (optional) (by default, .lnk and .tmp extensions are excluded) // Note that when you use this function, .lnk and .tmp extensions will no longer be // excluded unless you explicitly add them as parameters to the function FileBrowser.SetExcludedExtensions(".lnk", ".tmp", ".zip", ".rar", ".exe"); // Add a new quick link to the browser (optional) (returns true if quick link is added successfully) // It is sufficient to add a quick link just once // Name: Users // Path: C:\Users // Icon: default (folder icon) FileBrowser.AddQuickLink("Users", "C:\\Users", null); // Show a save file dialog // onSuccess event: not registered (which means this dialog is pretty useless) // onCancel event: not registered // Save file/folder: file, Allow multiple selection: false // Initial path: "C:\", Initial filename: "Screenshot.png" // Title: "Save As", Submit button text: "Save" // FileBrowser.ShowSaveDialog( null, null, FileBrowser.PickMode.Files, false, "C:\\", "Screenshot.png", "Save As", "Save" ); // Show a select folder dialog // onSuccess event: print the selected folder's path // onCancel event: print "Canceled" // Load file/folder: folder, Allow multiple selection: false // Initial path: default (Documents), Initial filename: empty // Title: "Select Folder", Submit button text: "Select" string initialPath = null; string initialFile = null; if (FileBrowserHelpers.FileExists(fileInput.text)) { initialPath = FileBrowserHelpers.GetDirectoryName(fileInput.text); initialFile = FileBrowserHelpers.GetFilename(fileInput.text); } if (FileBrowserHelpers.DirectoryExists(fileInput.text)) { initialPath = fileInput.text; } FileBrowser.ShowLoadDialog((paths) => { Debug.Log("Selected: " + paths[0]); fileInput.text = paths[0]; }, () => { Debug.Log("Canceled file open"); }, FileBrowser.PickMode.Files, false, initialPath, initialFile); // Coroutine example //StartCoroutine(ShowLoadDialogCoroutine()); }
private void UpdateFilesListUI() { var appManager = AppManager.Instance; int fileIndex = _currentFileIndex; for (int i = 0; i < _filesSlots.Length; i++) { if (appManager.FilesData == null || fileIndex >= appManager.FilesData.Files.Count || appManager.FilesData.Files[fileIndex] == null || appManager.FilesData.Files[fileIndex].Path == string.Empty) { _filesSlots[i].gameObject.SetActive(false); continue; } var file = appManager.FilesData.Files[fileIndex]; var slot = _filesSlots[i]; if (!FileBrowserHelpers.FileExists(file.Path)) { appManager.FilesData.Files.Remove(file); appManager.SaveFilesData(); _filesSlots[i].gameObject.SetActive(false); continue; } Sprite cover = null; if (file.CoverImagePath != string.Empty) { if (!FileBrowserHelpers.FileExists(file.CoverImagePath)) { file.CoverImagePath = string.Empty; appManager.SaveFilesData(); } else { cover = appManager.LoadSprite(file.CoverImagePath); } } UnityAction openFile = new UnityAction(() => { OpenFile(file); }); slot.Init(cover, file.Name, openFile); fileIndex++; } }
/// <summary> /// Uploads a single file to the server. Not used in case of upload to AmazonS3 /// Note - As the backend server supports only upload to AmazonS3 this is never called /// </summary> /// <param name="uploadFilePath">Path of file to be uploaded</param> /// <param name="deleteTempFile">Path of temporary Zip file</param> /// <returns></returns> private IEnumerator UploadFileToServer(string uploadFilePath, bool deleteTempFile) { List <IMultipartFormSection> formData = new List <IMultipartFormSection>(); string fileName = FileBrowserHelpers.GetFilename(uploadFilePath); byte[] fileData = FileBrowserHelpers.ReadBytesFromFile(uploadFilePath); formData.Add(new MultipartFormFileSection("Object", fileData, fileName, "application/octet-stream")); using (UnityWebRequest uwr = UnityWebRequest.Post(amazonS3ServerBackend + "/fileupload", formData)) { uwr.SendWebRequest(); MessageFields uploadMsgFields = DisplayUploadProgressMessage(); StartCoroutine(CheckUploadConnection(uwr)); while (!uwr.isDone) { string progress = "Progress : " + Mathf.Round(uwr.uploadProgress * 100).ToString() + "%"; uploadMsgFields.MessageDetails("Upload Progress ...", progress); if (uwr.isNetworkError || uwr.isHttpError) { yield break; } yield return(null); } if (uwr.result != UnityWebRequest.Result.Success) { DestroyUploadProgressMessage(uploadMsgFields); if (deleteTempFile && FileBrowserHelpers.FileExists(uploadFilePath)) { FileBrowserHelpers.DeleteFile(uploadFilePath); Debug.Log("Temp File deleted after Error"); } DisplayUploadErrorMessage(uwr.error); } else { DestroyUploadProgressMessage(uploadMsgFields); if (deleteTempFile && FileBrowserHelpers.FileExists(uploadFilePath)) { FileBrowserHelpers.DeleteFile(uploadFilePath); Debug.Log("Temp File deleted"); } } } }
public Sprite GetPage(PdfiumViewer.PdfDocument doc, int pageNum) { if (pageNum >= doc.PageCount) { return(null); } var tempPath = Application.persistentDataPath + _targetFolder + "_tempImage_.png"; if (FileBrowserHelpers.FileExists(tempPath)) { FileBrowserHelpers.DeleteFile(tempPath); } var image = doc.Render(pageNum, 72, 72, false); image.Save(tempPath, System.Drawing.Imaging.ImageFormat.Png); var sprite = LoadSprite(tempPath); return(sprite); }
IEnumerator ShowLoadDialogCoroutine() { // Show a load file dialog and wait for a response from user // Load file/folder: both, Allow multiple selection: true // Initial path: default (Documents), Initial filename: empty // Title: "Load File", Submit button text: "Load" yield return(FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.FilesAndFolders, false, null, null, "Load Files and Folders", "Load")); // Dialog is closed // Print whether the user has selected some files/folders or cancelled the operation (FileBrowser.Success) Debug.Log(FileBrowser.Success); if (FileBrowser.Success) { // Print paths of the selected files (FileBrowser.Result) (null, if FileBrowser.Success is false) // for( int i = 0; i < FileBrowser.Result.Length; i++ ) // Debug.Log( FileBrowser.Result[i] ); // Read the bytes of the first file via FileBrowserHelpers // Contrary to File.ReadAllBytes, this function works on Android 10+, as well byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(FileBrowser.Result[0]); Debug.Log(bytes); // Or, copy the first file to persistentDataPath // string destinationPath = Path.Combine( Application.persistentDataPath, FileBrowserHelpers.GetFilename( FileBrowser.Result[0] ) ); string destinationPath = Path.Combine(Application.persistentDataPath, "Data.csv"); Debug.Log(destinationPath); if (FileBrowserHelpers.FileExists(destinationPath)) { FileBrowserHelpers.DeleteFile(destinationPath); } FileBrowserHelpers.CopyFile(FileBrowser.Result[0], destinationPath); name = FileBrowserHelpers.GetFilename(FileBrowser.Result[0]); Debug.Log(name); FileSelectText(name); } }