Exemple #1
0
 private static void CheckCurrentDownloadQueue()
 {
     if (forceStopCurrentDownloads)
     {
         forceStopCurrentDownloads = false;
         Debug.Log($"[GoogleDataDownloader] Forced stop download queue");
         return;
     }
     if (googleFileDownloadQueue.Count <= 0)
     {
         if (googleFolderDownloadQueue.Count <= 0)
         {
             Debug.Log($"[GoogleDataDownloader] Finished download queue");
             downloadingRecursively = false;
             currentlyDownloading   = false;
             EditorUtility.ClearProgressBar();
             //refresh view to where recursive started.
             googleFolderIdHierarcyTree.RemoveAt(googleFolderIdHierarcyTree.Count - 1);
             RequestGoogleDriveFolderItems(defaultGoogleSharedDriveId, googleFolderIdHierarcyTree[googleFolderIdHierarcyTree.Count - 1].itemId);
             return;
         }
         else
         {
             if (!firstRecursiveDownload)
             {
                 googleFolderIdHierarcyTree.RemoveAt(googleFolderIdHierarcyTree.Count - 1);
             }
             GoogleDriveItem folderToSearch = googleFolderDownloadQueue.Dequeue();
             RequestGoogleDriveFolderItems(defaultGoogleSharedDriveId, folderToSearch.itemId, folderToSearch.itemName);
             return;
         }
     }
     currentMetaItem = googleFileDownloadQueue.Dequeue();
     RequestDownloadGoogleDriveFile(currentMetaItem);
 }
Exemple #2
0
        private static void RequestDownloadGoogleDriveFile(GoogleDriveItem itemToDownload)
        {
            string fetchUrl = $@"{googleApiGetItemUrl}/{itemToDownload.itemId}?{googleAllowTeamDrive}&alt=media";

            Debug.Log($"[GoogleDataUpload] Attempting to download: {itemToDownload.itemName}");

            webRequestObj = new UnityWebRequest();
            webRequestObj = UnityWebRequest.Get(fetchUrl);
            webRequestObj.SetRequestHeader("Authorization", $"Bearer {googleDriveAccessToken}");

            webRequestObj.SendWebRequest();

            EditorApplication.update += RetrieveCurrentFileDownloadRequest;
        }
Exemple #3
0
        private static void ProcessReceivedBinaryData(byte[] dataToWrite, GoogleDriveItem metaDataToReference, string pathToExport)
        {
            //Over here I can add a switch later if I want to support more types.
            if (metaDataToReference.itemType == GoogleFileType.NotSet)
            {
                Debug.LogError($"[GoogleDataDownloader] Unable to process received data due to passed meta file not having a type set.");
                return;
            }

            if (metaDataToReference.itemType == GoogleFileType.Octet)
            {
                FileStream fs = new FileStream(Path.Combine(pathToExport, GetSafeFilename(metaDataToReference.itemName)), FileMode.OpenOrCreate, FileAccess.Write);
                if (fs == null)
                {
                    Debug.LogError($"[GoogleDataDownloader] Unable create/open file {GetSafeFilename(metaDataToReference.itemName)}.");
                    return;
                }
                fs.Write(dataToWrite, 0, dataToWrite.Length);
                fs.Close();
                Debug.Log($"[GoogleDataUpload] Created new octet-stream file {metaDataToReference.itemName} at {pathToExport}");
            }
        }
Exemple #4
0
        private static void GoUpGoogleFolderHierarchy()
        {
            if (googleFolderIdHierarcyTree.Count <= 1)
            {
                Debug.LogError($"[GoogleDataDownloader] Cannot go back further in folder hierarchy, researched starting point.");
                return;
            }
            int             currentFolderIndex = (googleFolderIdHierarcyTree.Count - 1);             //Get current item index
            GoogleDriveItem newFolder          = googleFolderIdHierarcyTree[currentFolderIndex - 1]; // get previous item to go towards.

            if (string.IsNullOrEmpty(newFolder.itemId) || string.IsNullOrEmpty(newFolder.itemName))
            {
                Debug.LogError($"[GoogleDataDownloader] GoogleDriveItem invalid, cannot be used to search folders.");
            }
            //Remove current item from list and fetch previous item;
            googleFolderIdHierarcyTree.RemoveAt(currentFolderIndex);
            if (googleFolderIdHierarcyTree.Count <= 1 && canGoBackInGoogleDriveHierarchy)
            {
                canGoBackInGoogleDriveHierarchy = false;
            }
            RequestGoogleDriveFolderItems(defaultGoogleSharedDriveId, newFolder.itemId); //Leave out name to just fetch the folder but don't add to hierarchy.
        }