Beispiel #1
0
    private void SuccesLogin(WWW www)
    {
        ServerController.onSuccessHandler -= SuccesLogin;
        ServerController.onSuccessHandler  = null;
        Models.user = JsonUtility.FromJson <Garage>(www.text);
        Debug.Log(www.text);
        Debug.Log(Models.user.user);
        LoginPage.SetActive(false);
        GlobalParameters.isLogined = true;
        if (isSaveble)
        {
            SaveModelController.SaweUserData();
        }
        if (!PlayerPrefs.HasKey("google"))
        {
            PlayerPrefs.SetInt("google", 0);
            var auth = new UnityGoogleDrive.Data.File()
            {
                Name = "authointification"
            };
            GoogleDriveFiles.Create(auth).Send();
        }
        CallMessage cmsg = new CallMessage();

        cmsg.from   = Models.user.user;
        cmsg.to     = SystemInfo.deviceUniqueIdentifier;
        cmsg.comand = "login";

        WEbSocketController.GetInstance.SendMessage(JsonUtility.ToJson(cmsg));
    }
    private void Upload(bool toAppData)
    {
        var content = File.ReadAllBytes(UploadFilePath);

        if (content == null)
        {
            return;
        }

        var file = new UnityGoogleDrive.Data.File()
        {
            Name = Path.GetFileName(UploadFilePath), Content = content
        };

        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 void putInFolderInThread(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);


        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;
        }
        instance.folderNameGlobal = "";
    }
    public static void Export()
    {
        var file = new UnityGoogleDrive.Data.File()
        {
            Name    = string.Format("{0}_log.txt", DateTime.Now.ToLongTimeString()),
            Content = Encoding.Default.GetBytes(_log.ToString())
        };

        GoogleDriveFiles.Create(file).Send();
    }
    private void Upload()
    {
        var content = ImageToUpload.EncodeToPNG();
        var file    = new UnityGoogleDrive.Data.File()
        {
            Name = "TestUnityGoogleDriveFilesUpload.png", Content = content, MimeType = "image/png"
        };

        request        = GoogleDriveFiles.Create(file);
        request.Fields = new List <string> {
            "id", "name", "size", "createdTime"
        };
        request.Send().OnDone += PrintResult;
    }
    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();
    }
Beispiel #7
0
    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);
    }
    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++;
    }
Beispiel #9
0
    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;
    }
    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;
    }
Beispiel #11
0
    //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();
    }
Beispiel #12
0
    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");
    }
Beispiel #13
0
    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");
    }
    //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;
    }
    /// <summary>
    /// Creates a new (or update existsing) <see cref="Data.File"/> at the provided path.
    /// Will also create any missing folders at the provided path.
    /// </summary>
    /// <param name="file">Metadata for the created (updated) file.</param>
    /// <param name="path">Created file's path (including file name).</param>
    /// <param name="appData">Whether to use the AppData space instead of the drive root.</param>
    /// <param name="forceUploadContent">Whether to always upload <see cref="Data.File.Content"/>, even when checksum of the content is equal to the one kept on drive.</param>
    /// <param name="uploadMimeType">When the uploaded content differs from the target type (Eg when uploading plain text to create a google document), specify the uploaded content MIME type here.</param>
    /// <returns>ID of the created (updated) file. Null if failed.</returns>
    public static async System.Threading.Tasks.Task <string> CreateOrUpdateFileAtPathAsync(UnityGoogleDrive.Data.File file, string path, bool appData = false, bool forceUploadContent = false, string uploadMimeType = null)
    {
        var fileName = Path.GetFileName(path);

        if (string.IsNullOrWhiteSpace(fileName))
        {
            return(null);
        }
        if (string.IsNullOrWhiteSpace(file.Name))
        {
            file.Name = fileName;
        }

        // Just modify the file if already exists.
        var files = await FindFilesByPathAsync(path, appData, new List <string> {
            "files(md5Checksum)"
        }, file.MimeType);

        if (files.Count > 0)
        {
            if (files.Count > 1)
            {
                Debug.LogWarning($"UnityGoogleDrive: Multiple '{path}' files found while attempting to modify the file. Operation will modify only the first found file.");
            }
            if (!forceUploadContent && file.Content != null && CalculateMD5Checksum(file.Content) == files[0].Md5Checksum)
            {
                file.Content = null;
            }
            using (var updateRequest = GoogleDriveFiles.Update(files[0].Id, file, uploadMimeType)) {
                updateRequest.Fields = new List <string> {
                    "id"
                };
                var updatedFile = await updateRequest.Send();

                return(updatedFile.Id);
            }
        }

        // Check if all the folders in the path exist.
        var parentIds = await ValidatePath(path, appData);

        if (parentIds == null)
        {
            parentIds = new HashSet <string>();
        }
        if (parentIds.Count > 1)
        {
            Debug.LogWarning($"UnityGoogleDrive: Multiple '{Path.GetDirectoryName(path)}' pathes found while attempting to create a file. Operation will create a file at the first found path.");
        }

        // Some of the folders are missing; create them.
        if (parentIds.Count == 0)
        {
            var parentId = appData ? AppDataAlias : RootAlias;
            path = Path.GetDirectoryName(path).Replace('\\', '/');
            var parentNames = path.Split('/').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

            for (int i = 0; i < parentNames.Length; i++)
            {
                using (var listRequest = new GoogleDriveFiles.ListRequest()) {
                    listRequest.Fields = new List <string> {
                        "files(id)"
                    };
                    listRequest.Spaces = appData ? AppDataAlias : DriveSpace;
                    listRequest.Q      = $"'{parentId}' in parents and name = '{parentNames[i]}' and mimeType = '{FolderMimeType}' and trashed = false";

                    await listRequest.Send();

                    if (listRequest == null || listRequest.IsError)
                    {
                        return(null);
                    }

                    // Next folder at the current level is missing; create it.
                    if (listRequest.ResponseData.Files == null || listRequest.ResponseData.Files.Count == 0)
                    {
                        var folder = new UnityGoogleDrive.Data.File {
                            Name = parentNames[i], MimeType = FolderMimeType, Parents = new List <string> {
                                parentId
                            }
                        };
                        using (var createRequest = GoogleDriveFiles.Create(folder)) {
                            createRequest.Fields = new List <string> {
                                "id"
                            };
                            var createdFolder = await createRequest.Send();

                            parentId = createdFolder.Id;
                            continue;
                        }
                    } // Next folder exists; use it's ID and travers higher.
                    else
                    {
                        parentId = listRequest.ResponseData.Files[0].Id;
                    }
                }
            }

            parentIds.Add(parentId);
        }

        // Create the file.
        file.Parents = new List <string> {
            parentIds.First()
        };
        using (var createRequest = GoogleDriveFiles.Create(file, uploadMimeType)) {
            createRequest.Fields = new List <string> {
                "id"
            };
            var createdFile = await createRequest.Send();

            return(createdFile?.Id);
        }
    }