void DownloadModel() { var path = Application.persistentDataPath + "/" + fileName.Replace(" ", ""); //EditorUtility.RevealInFinder(path); //first try to get the file by name try { using (var assetLoader = new AssetLoader()) { var ops = AssetLoaderOptions.CreateInstance(); //Creates the AssetLoaderOptions instance. //AssetLoaderOptions let you specify options to load your model. //(Optional) You can skip this object creation and it's parameter or pass null. //You can modify assetLoaderOptions before passing it to LoadFromFile method. You can check the AssetLoaderOptions API reference at: //https://ricardoreis.net/trilib/manual/html/class_tri_lib_1_1_asset_loader_options.html ops.UseOriginalPositionRotationAndScale = true; ops.Scale = 1 / 1000f; var wrapperGameObject = gameObject; //Sets the game object where your model will be loaded into. //(Optional) You can skip this object creation and it's parameter or pass null. var myGameObject = assetLoader.LoadFromFile(path, ops, wrapperGameObject); //Loads the model synchronously and stores the reference in myGameObject. //successful retreival of file if (myGameObject != null) { var ObjectToPlace = Instantiate(myGameObject); //After instantiating object kill UI GameObject.Find("Canvas").SetActive(false); //Assign variable to TapToPlace GameObject.Find("AR Session Origin").GetComponent <TapToPlace>().objectToPlace = ObjectToPlace; } } } catch { //if we don't get the file locally, we'll have to download it from the server request = GoogleDriveFiles.Download(fileId); //request = GoogleDriveFiles.Download(fileId, range.start >= 0 ? (RangeInt?)range : null); request.Send().OnDone += SetResult; } }
public void SendDataFile() { string filePath = Application.persistentDataPath + "/datacollection.txt"; string testContent = File.ReadAllText(filePath); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(testContent); var file = new UnityGoogleDrive.Data.File() { Name = "BiodegradabilityCollectedData.txt", Content = bytes }; GoogleDriveFiles.Create(file).Send().OnDone += file1 => _response = Encoding.UTF8.GetString(file.Content); }
public void UploadSnap() { imageToUpload = snapShot.virtualPhoto; var content = imageToUpload.EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = filename, Content = content, MimeType = "image/png" }; request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send(); }
/// <summary> /// Looks for the files located at the provided path. /// </summary> /// <param name="path">File's path in Google Drive. Add front slash to find all files in a folder.</param> /// <param name="appData">Whether to use the AppData space instead of the drive root.</param> /// <param name="fields">Required fields for the list request. To request file's fields, use 'files(id, name, mimeType, ...)'.</param> /// <param name="mime">File's MIME type.</param> /// <param name="trashed">Whether to include trashed files.</param> public static async System.Threading.Tasks.Task <List <UnityGoogleDrive.Data.File> > FindFilesByPathAsync(string path, bool appData = false, List <string> fields = null, string mime = null, bool trashed = false) { var result = new List <UnityGoogleDrive.Data.File>(); var fileName = Path.GetFileName(path); var parentIds = await ValidatePath(path, appData); if (parentIds == null) { return(result); } var parentQueries = parentIds.Select(parentId => $"'{parentId}' in parents"); var query = $"({string.Join(" or ", parentQueries)}) and trashed = {trashed}"; if (!string.IsNullOrWhiteSpace(fileName)) { query += $" and name = '{fileName}'"; } if (!string.IsNullOrWhiteSpace(mime)) { query += $" and mimeType = '{mime}'"; } if (fields == null) { fields = new List <string>(); } fields.Add("nextPageToken, files(id)"); string pageToken = null; do { var listRequest = GoogleDriveFiles.List(query, fields, appData ? AppDataSpace : DriveSpace, pageToken); var fileList = await listRequest.Send(); if (fileList?.Files?.Count > 0) { result.AddRange(fileList.Files); } pageToken = fileList?.NextPageToken; listRequest.Dispose(); } while (pageToken != null); return(result); }
void DownloadFiles() { GoogleDriveFiles.List().Send().OnDone += list => { foreach (File listedFile in list.Files) { if (listedFile.Name.StartsWith("virtualshackrecording")) { GoogleDriveFiles.DownloadAudio(listedFile.Id, AudioType.WAV).Send().OnDone += file => { SavWav.Save("downloaded_" + listedFile.Name, file.AudioClip); }; } } }; }
private void ListFiles(string nextPageToken = null) { request = GoogleDriveFiles.List(); request.Fields = new List <string> { "nextPageToken, files(id, name, size, createdTime)" }; request.PageSize = ResultsPerPage; //if (!string.IsNullOrEmpty(query)) // request.Q = string.Format("name contains '{0}'", query); request.Q = string.Format("name contains '{0}' or name contains '{1}' or name contains '{2}'", ".png", ".jpg", ".jpeg"); if (!string.IsNullOrEmpty(nextPageToken)) { request.PageToken = nextPageToken; } request.Send().OnDone += BuildResults; }
private void Upload() { var content = File.ReadAllBytes(UploadFilePath); if (content == null) { return; } var file = new UnityGoogleDrive.Data.File() { Name = Path.GetFileName(UploadFilePath), Content = content }; request = GoogleDriveFiles.CreateResumable(file, resumableSessionUri); request.Send().OnDone += SaveSessionUri; }
void Submit() { AudioClip myClip = SavWav.TrimSilence(audioSource.clip, 0.1f); string fileName = "virtualshackrecording_" + myNum; string outputLocation = SavWav.Save(fileName, myClip); Byte[] content = System.IO.File.ReadAllBytes(outputLocation); File file = new File { Name = Path.GetFileName(outputLocation), Content = content }; GoogleDriveFiles.Create(file).Send().OnDone += result => { Debug.Log("Uploaded: " + result.Name); }; myNum++; }
public IEnumerator Test006_FilesCopy() { var file = new UnityGoogleDrive.Data.File() { Id = createdFileId }; var request = GoogleDriveFiles.Copy(file); request.Fields = new List <string> { "id" }; yield return(request.Send()); Assert.IsFalse(request.IsError); Assert.NotNull(request.ResponseData.Id); copiedFileId = request.ResponseData.Id; }
void Update() { if (fileStatus == EDownloadStatus.kDownloadRequested) { fileStatus = EDownloadStatus.kInProgress; GoogleDriveFiles.List().Send().OnDone += RefreshFileList; } if (fileStatus == EDownloadStatus.kFilesListRefreshed) { fileStatus = EDownloadStatus.kInProgress; keyfile = files[0]; GoogleDriveFiles.Download(keyfile.Id).Send().OnDone += DownloadFile; } if (hasChanges && !(textForWalls is null) && fileStatus == EDownloadStatus.kDownloaded) { UpdateFile(); } }
public ActionResult TaiLenPhim(GoogleDriveFiles BoPhimId, HttpPostedFileBase[] files, string TP, string TLg, int Tap, DateTime NamXB, HttpPostedFileBase LkA, int PV, int maBP) { string videoID = null; //Lưu và o Drive GoogleDriveFileRepository.FileUploadInFolder(BoPhimId.Id, files, ref videoID); //Lưu và o csdl string _LkAName = null; if (LkA.ContentLength > 0) { _LkAName = Path.GetFileName(LkA.FileName); string _pathLkA = Path.Combine(Server.MapPath("~/LkA_File"), _LkAName); LkA.SaveAs(_pathLkA); } new PhanPhimDAO().ThemPhanPhim(videoID, TP, TLg, Tap, NamXB, _LkAName, PV, maBP); return(View("TaoPhanPhim")); }
public IEnumerator Test003_FilesCreate() { var content = Resources.Load <Texture2D>(TEST_RESOURCE_PATH).EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = "AutoTestUpload", Content = content }; var request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id" }; yield return(request.Send()); Assert.IsFalse(request.IsError); Assert.NotNull(request.ResponseData.Id); createdFileId = request.ResponseData.Id; }
private IEnumerator RestoreFromGoogleDriveSaveFileWithName(GameObject loadObject) { var request = GoogleDriveFiles.List(); yield return(request.Send()); string saveFileId = ""; for (int i = 0; i < request.ResponseData.Files.Count; i++) { if (request.ResponseData.Files[i].Name == "PS_SaveData") { saveFileId = request.ResponseData.Files[i].Id; break; } } if (saveFileId == "") { loadObject.SetActive(false); StopCoroutine(RestoreFromGoogleDriveSaveFileWithName(loadObject)); } var request2 = GoogleDriveFiles.Download(saveFileId); yield return(request2.Send()); string destination = Application.persistentDataPath + "/SaveData.xml"; File.Delete(destination); File.WriteAllBytes(destination, request2.ResponseData.Content); saveData = Load(); for (int i = 0; i < dataCreationManager.folderHolder.childCount; i++) { Destroy(dataCreationManager.folderHolder.GetChild(i).gameObject); } SetLoadedSaveData(); loadObject.SetActive(false); StructureManager.instance.NewNotification("Restore Completed"); }
public static List <GoogleDriveFiles> GetContainsInFolderCustom(String folderId) { List <string> ChildList = new List <string>(); Google.Apis.Drive.v2.DriveService ServiceV2 = GetService_v2(); ChildrenResource.ListRequest ChildrenIDsRequest = ServiceV2.Children.List(folderId); // for getting only folders ChildrenIDsRequest.Q = "mimeType!='application/vnd.google-apps.folder'"; //file catched by usiing ! sign ChildrenIDsRequest.Fields = "files(id,name)"; do { var children = ChildrenIDsRequest.Execute(); if (children.Items != null && children.Items.Count > 0) { foreach (var file in children.Items) { ChildList.Add(file.Id); } } ChildrenIDsRequest.PageToken = children.NextPageToken; } while (!String.IsNullOrEmpty(ChildrenIDsRequest.PageToken)); //Get All File List // List<GoogleDriveFiles> AllFileList = GetDriveFiles(); List <GoogleDriveFiles> Filter_FileList = new List <GoogleDriveFiles>(); foreach (string Id in ChildList) { GoogleDriveFiles File = new GoogleDriveFiles { Id = Id, Name = "", Size = 0, Version = 0, CreatedTime = null }; Filter_FileList.Add(File); } return(Filter_FileList); }
void Upload() { Texture2D texCopy = new Texture2D(image.width, image.height, image.format, image.mipmapCount > 1); texCopy.LoadRawTextureData(image.GetRawTextureData()); texCopy.Apply(); var content = texCopy.EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = "proof.png", Content = content, MimeType = "image/png" }; request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send().OnDone += PrintResult; }
//do the upload to google drive public void upload() { if (data.Length == 0) { return; } var file = new UnityGoogleDrive.Data.File() { Name = "log_" + uploadID.ToString() + ".txt", Parents = new List <string> { "1UANcfS3aWNjJwmsb1dA--FUDX_Guj2rF" }, //<<<<<------hacked in for now Content = Encoding.ASCII.GetBytes(data) }; var result = GoogleDriveFiles.Create(file).Send(); //TODO: add some flag to the OnDone event to manage conflicts (or call infrequently). uploadID += 1; clearData(); }
private void Upload(bool toAppData) { var content = ImageToUpload.EncodeToPNG(); var file = new UnityGoogleDrive.Data.File() { Name = "TestUnityGoogleDriveFilesUpload.png", Content = content, MimeType = "image/png" }; if (toAppData) { file.Parents = new List <string> { "appDataFolder" } } ; request = GoogleDriveFiles.Create(file); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send().OnDone += PrintResult; }
private async UniTask <byte[]> DownloadFileAsync(UnityGoogleDrive.Data.File fileMeta) { if (useNativeRequests) { if (typeof(TResource) == typeof(AudioClip)) { downloadRequest = GoogleDriveFiles.DownloadAudio(fileMeta.Id, WebUtils.EvaluateAudioTypeFromMime(fileMeta.MimeType)); } else if (typeof(TResource) == typeof(Texture2D)) { downloadRequest = GoogleDriveFiles.DownloadTexture(fileMeta.Id, true); } } else { downloadRequest = new GoogleDriveFiles.DownloadRequest(fileMeta); } await downloadRequest.SendNonGeneric(); if (downloadRequest.IsError || downloadRequest.GetResponseData <UnityGoogleDrive.Data.File>().Content == null) { Debug.LogError($"Failed to download {Path}{usedRepresentation.Extension} resource from Google Drive."); return(null); } if (useNativeRequests) { if (typeof(TResource) == typeof(AudioClip)) { loadedObject = downloadRequest.GetResponseData <UnityGoogleDrive.Data.AudioFile>().AudioClip as TResource; } else if (typeof(TResource) == typeof(Texture2D)) { loadedObject = downloadRequest.GetResponseData <UnityGoogleDrive.Data.TextureFile>().Texture as TResource; } } return(downloadRequest.GetResponseData <UnityGoogleDrive.Data.File>().Content); }
public static List <GoogleDriveFiles> GetDriveFilesCustom(string id) { Google.Apis.Drive.v3.DriveService service = GetService(); // Define parameters of request. Google.Apis.Drive.v3.FilesResource.ListRequest FileListRequest = service.Files.List(); // for getting folders only. FileListRequest.Q = "'" + id + "' in parents and " + "mimeType!='application/vnd.google-apps.folder'"; //get the files under folder id FileListRequest.Fields = "nextPageToken, files(*)"; // List files. IList <Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files; List <GoogleDriveFiles> FileList = new List <GoogleDriveFiles>(); // For getting only folders // files = files.Where(x => x.MimeType != "application/vnd.google-apps.folder").ToList(); if (files != null && files.Count > 0) { foreach (var file in files) { GoogleDriveFiles File = new GoogleDriveFiles { Id = file.Id, Name = file.Name, Size = file.Size, Version = file.Version, CreatedTime = file.CreatedTime, }; FileList.Add(File); } } return(FileList); }
private IEnumerator SaveToGoogleDrive(GameObject loadObject, bool hasGoogleDriveSaveFile) { var file = new UnityGoogleDrive.Data.File() { Name = "PS_SaveData", Content = File.ReadAllBytes(Application.persistentDataPath + "/SaveData.xml") }; if (!hasGoogleDriveSaveFile) { var request = GoogleDriveFiles.Create(file); yield return(request.Send()); saveData.googleDriveSaveFileId = request.ResponseData.Id; } else { var request = GoogleDriveFiles.Update(saveData.googleDriveSaveFileId, file); yield return(request.Send()); } loadObject.SetActive(false); StructureManager.instance.NewNotification("Save Completed"); }
void MountPhase(GameObject go) { loading.SetActive(true); string id = ""; Fileids.TryGetValue(go, out id); if (string.IsNullOrEmpty(id)) { Debug.LogError("Houve um erro ao carregar o arquivo!"); return; } Assets.Scripts.DAL.BetaTesterContext.FileId = id; var phase = Assets.Scripts.DAL.BetaTesterContext.Phase.GetData().Single(x => x.FileId == Assets.Scripts.DAL.BetaTesterContext.FileId); phase.Played++; Assets.Scripts.DAL.BetaTesterContext.Phase.Update(phase); GoogleDriveFiles.Download(id).Send().OnDone += SetResult; }
public static int GetRecordingNum() { int maxNum = 0; GoogleDriveFiles.List().Send().OnDone += list => { foreach (File file in list.Files) { if (!file.Name.Contains("virtualshackrecording")) { continue; } string[] fileName = file.Name.Split('_'); int currentNum = FindIntInString(fileName[fileName.Length - 1]); if (currentNum >= myNum) { myNum = currentNum + 1; } } //Debug.Log(myNum); }; return(maxNum); }
private IEnumerator putInFolder(UnityGoogleDrive.Data.File file) { GoogleDriveFiles.CreateRequest request; PhotoSession.PhotoFolder folder = instance.getFolder(instance.folderNameGlobal, instance.folderDateGlobal); string p = Path.Combine(datapath, folder.folderName + "_" + folder.data + "_" + folder.modelid + "_" + folder.userid); Debug.Log(instance.folderNameGlobal); while (folder.files.Count == 0) { Load(); folder = instance.getFolder(instance.folderNameGlobal, instance.folderDateGlobal); Debug.Log(folder.files.Count); yield return(null); } foreach (var link in folder.files) { string path = Path.Combine(p, link.name); Sprite sprite = SpriteLoader.GetSpriteFromFileWithCompression(path); var filen = new UnityGoogleDrive.Data.File() { Name = GenerateName() + GetId(link.id + 1), Content = sprite.texture.EncodeToPNG(), Parents = new List <string> { file.Id } }; request = GoogleDriveFiles.Create(filen); request.Fields = new List <string> { "id", "name", "size", "createdTime" }; request.Send().OnDone += instance.PrintResult; } yield return(null); instance.folderNameGlobal = ""; }
//private GoogleDriveFiles.CreateRequest request; #endregion #region Google Drive public static void onGoogleDriveLoad() { if (string.IsNullOrEmpty(VideoCallPhotoManager.FolderName)) { return; } if (VideoCallPhotoManager.GetPhotosCount() == 0) { return; } instance.folderNameGlobal = VideoCallPhotoManager.FolderName; instance.folderDateGlobal = VideoCallPhotoManager.FolderDate; GoogleDriveFiles.CreateRequest request; var folderr = new UnityGoogleDrive.Data.File() { Name = instance.GenerateName(), MimeType = "application/vnd.google-apps.folder" }; request = GoogleDriveFiles.Create(folderr); request.Send().OnDone += instance.putInFolderCorut; VideoCallPhotoManager.FolderName = ""; VideoCallPhotoManager.FolderDate = null; GlobalParameters.isSameSession = false; }
private IEnumerator RestoreFromGoogleDriveSaveFileWithID(GameObject loadObject) { var request = GoogleDriveFiles.Download(saveData.googleDriveSaveFileId); yield return(request.Send()); string destination = Application.persistentDataPath + "/SaveData.xml"; File.Delete(destination); File.WriteAllBytes(destination, request.ResponseData.Content); saveData = Load(); for (int i = 0; i < dataCreationManager.folderHolder.childCount; i++) { Destroy(dataCreationManager.folderHolder.GetChild(i).gameObject); } SetLoadedSaveData(); loadObject.SetActive(false); StructureManager.instance.dataSavePanel.SetActive(false); StructureManager.instance.NewNotification("Restore Completed"); }
void GetResults(UnityGoogleDrive.Data.FileList fileList) { byte[] content = File.ReadAllBytes(getPath()); UnityGoogleDrive.Data.File file = new UnityGoogleDrive.Data.File() { Name = Path.GetFileName(getPath()), Content = content }; if (fileList.Files.Count >= 1) { for (int i = 0; i < fileList.Files.Count; i++) { if (fileList.Files[i].Name == fileName) { GoogleDriveFiles.Update(fileList.Files[i].Id, file).Send(); } } } else { GoogleDriveFiles.Create(file).Send(); } // Debug.Log("done"); }
public ActionResult DeleteFile(GoogleDriveFiles file) { GoogleDriveFilesRepository.DeleteFile(file); return(RedirectToAction("GetGoogleDriveFiles")); }
public ActionResult FileUploadInFolder(GoogleDriveFiles FolderId, HttpPostedFileBase file) { GoogleDriveFilesRepository.FileUploadInFolder(FolderId.Id, file); return(RedirectToAction("GetGoogleDriveFiles")); }
private void DownloadAudio(UnityGoogleDrive.Data.File file) { downloadRequest = GoogleDriveFiles.DownloadAudio(file.Id, AudioType.UNKNOWN); downloadRequest.Send().OnDone += PlayAudio; }
private void DeleteFile() { request = GoogleDriveFiles.Delete(fileId); request.Send().OnDone += _ => result = request.IsError ? request.Error : "file deleted"; }