/// <summary>
    /// Auth and get all files in AppData.
    /// </summary>
    IEnumerator InitGoogleDrive()
    {
        initInProgress = true;

        drive              = new GoogleDrive();
        drive.ClientID     = "897584417662-rnkgkl5tlpnsau7c4oc0g2jp08cpluom.apps.googleusercontent.com";
        drive.ClientSecret = "tGNLbYnrdRO2hdFmwJAo5Fbt";

        drive.Scopes = new string[] {
            "https://www.googleapis.com/auth/drive.file",
            "https://www.googleapis.com/auth/userinfo.email",
            "https://www.googleapis.com/auth/drive.appdata",
        };

        var authorization = drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
            Debug.LogWarning(authorization.Current as Exception);
            goto finish;
        }
        else
        {
            Debug.Log("User Account: " + drive.UserAccount);
        }

        // Get all files in AppData folder and view text file.
        {
            var listFiles = drive.ListFiles(drive.AppData);
            yield return(StartCoroutine(listFiles));

            var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(listFiles);

            if (files != null)
            {
                foreach (var file in files)
                {
                    Debug.Log(file);

                    if (file.Title.EndsWith(".txt"))
                    {
                        var download = drive.DownloadFile(file);
                        yield return(StartCoroutine(download));

                        var data = GoogleDrive.GetResult <byte[]>(download);
                        Debug.Log(System.Text.Encoding.UTF8.GetString(data));
                    }
                }
            }
            else
            {
                Debug.LogError(listFiles.Current);
            }
        }

finish:
        initInProgress = false;
    }
Exemple #2
0
    /// <summary>
    /// Auth and get all files in AppData.
    /// </summary>
    IEnumerator InitGoogleDrive()
    {
        initInProgress = true;

        drive              = new GoogleDrive();
        drive.ClientID     = "251952116687-bl6cbb0n9veq5ovirpk5n99pjlgtf16g.apps.googleusercontent.com";
        drive.ClientSecret = "z65O11Za6aB74a7r21_TbtFL";

        var authorization = drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
            Debug.LogWarning(authorization.Current as Exception);
            goto finish;
        }
        else
        {
            Debug.Log("User Account: " + drive.UserAccount);
        }

        // Get all files in AppData folder and view text file.
        {
            //var listFiles = drive.ListFiles(drive.AppData);
            //var listFiles = drive.ListAllFiles();
            var listFiles = drive.ListFolders("");


            yield return(StartCoroutine(listFiles));

            var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(listFiles);

            if (files != null)
            {
                foreach (var file in files)
                {
                    Debug.Log(file);

                    if (file.Title.EndsWith(".txt"))
                    {
                        var download = drive.DownloadFile(file);
                        yield return(StartCoroutine(download));

                        var data = GoogleDrive.GetResult <byte[]>(download);
                        Debug.Log(System.Text.Encoding.UTF8.GetString(data));
                    }
                }
            }
            else
            {
                Debug.LogError(listFiles.Current);
            }
        }

finish:
        initInProgress = false;
    }
    /// <summary>
    /// Auth and get all files in AppData.
    /// </summary>
    IEnumerator InitGoogleDrive()
    {
        initInProgress = true;

        drive              = new GoogleDrive();
        drive.ClientID     = "327028157545-te6a8nm4josmi80t08i3mvkn3snmnt9m.apps.googleusercontent.com";
        drive.ClientSecret = "XJWfBPzJinRvj1JLytI-eyWK";

        var authorization = drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
            Debug.LogWarning(authorization.Current as Exception);
            goto finish;
        }
        else
        {
            Debug.Log("User Account: " + drive.UserAccount);
        }

        // Get all files in AppData folder and view text file.
        {
            var listFiles = drive.ListFiles(drive.AppData);
            yield return(StartCoroutine(listFiles));

            var files = GoogleDrive.GetResult <List <GoogleDrive.File> > (listFiles);

            if (files != null)
            {
                foreach (var file in files)
                {
                    Debug.Log(file);

                    if (file.Title.EndsWith(".txt"))
                    {
                        var download = drive.DownloadFile(file);
                        yield return(StartCoroutine(download));

                        var data = GoogleDrive.GetResult <byte[]> (download);
                        Debug.Log(System.Text.Encoding.UTF8.GetString(data));
                    }
                }
            }
            else
            {
                Debug.LogError(listFiles.Current);
            }
        }

finish:
        initInProgress = false;
    }
Exemple #4
0
    IEnumerator ListPresentationsCoroutine()
    {
        Drive.ClientID     = "327028157545-te6a8nm4josmi80t08i3mvkn3snmnt9m.apps.googleusercontent.com";
        Drive.ClientSecret = "XJWfBPzJinRvj1JLytI-eyWK";

        // Request authorization.
        var authorization = Drive.Authorize();

        yield return(StartCoroutine(authorization));

        if (authorization.Current is Exception)
        {
            Debug.LogWarning(authorization.Current as Exception);
            yield break;
        }

        // Authorization succeeded.
        Debug.Log("User Account: " + Drive.UserAccount);

        var listFiles = Drive.ListFilesByQueary("mimeType = 'application/vnd.google-apps.presentation'");

        //var listFiles = Drive.ListAllFiles ();
        yield return(StartCoroutine(listFiles));

        var files = GoogleDrive.GetResult <List <GoogleDrive.File> > (listFiles);

        if (files != null && files.Count > 0)
        {
            foreach (GoogleDrive.File file in files)
            {
                //Debug.Log (file.Title);
            }
            GoogleDrive.File file0 = files [0];
            var pdfExportLink      = file0.ExportLinks ["application/pdf"];

            var download = Drive.DownloadFile((string)pdfExportLink);
            yield return(StartCoroutine(download));

            var data = GoogleDrive.GetResult <byte[]> (download);
            if (data != null)
            {
                Debug.Log("Happy");
                Stream pdfStream = new MemoryStream(data);
                //PdfSharp.Pdf.PdfDocument pdfDoc = PdfSharp.Pdf.IO.PdfReader.Open (pdfStream, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import);

                //	Debug.Log (pdfDoc.Info.Title);
            }
        }
        else
        {
            Debug.Log("files: " + files.Count);
        }
    }
Exemple #5
0
    IEnumerator GetFileLists_internal(string Id, funcResult callback)
    {
        var listFiles = _drive.ListFolders(Id);

        yield return(StartCoroutine(listFiles));

        var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(listFiles);

        recentFolderID = Id;
        //parentFolderID = _filesDictionary [removedLastWhiteSpace].Parents [0];

        if (files != null)
        {
            _filesDictionary.Clear();
            foreach (GoogleDrive.File file in files)
            {
                                #if UNITY_EDITOR
                Debug.Log(file);
                                #endif
                if (_filesDictionary.ContainsKey(file.Title))
                {
                    //Ignores Duplicated files
                                        #if UNITY_EDITOR
                    Debug.Log(file.Title);
                                        #endif
                }
                else
                {
                    _filesDictionary.Add(file.Title, file);

                    if (file.IsFolder == true)
                    {
                        parentFolderID = file.Parents [0];
                    }
                }
            }
            callback();
        }
                #if UNITY_EDITOR
        Debug.Log(files);
                #endif
    }
Exemple #6
0
    /// <summary>
    /// Upload a screenshot to the root folder.
    /// </summary>
    IEnumerator UploadScreenshot()
    {
        if (drive == null || !drive.IsAuthorized || uploadScreenshotInProgress)
        {
            yield break;
        }

        uploadScreenshotInProgress = true;

        yield return(new WaitForEndOfFrame());

        var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        tex.Apply();

        var png = tex.EncodeToPNG();

        GameObject.Destroy(tex);
        tex = null;

        if (file == null)
        {
            var upload = drive.UploadFile("my_screen.png", "image/png", png);
            yield return(StartCoroutine(upload));

            file = GoogleDrive.GetResult <GoogleDrive.File>(upload);
        }
        else
        {
            var upload = drive.UploadFile(file, png);
            yield return(StartCoroutine(upload));

            file = GoogleDrive.GetResult <GoogleDrive.File>(upload);
        }

        uploadScreenshotInProgress = false;
    }
Exemple #7
0
    /// <summary>
    /// <para>Update 'my_text.txt' in the root folder.</para>
    /// <para>The file has json data.</para>
    /// </summary>
    IEnumerator UploadText()
    {
        if (drive == null || !drive.IsAuthorized || uploadTextInProgress)
        {
            yield break;
        }

        uploadTextInProgress = true;

        // Get 'my_text.txt'.
        var list = drive.ListFilesByQueary("title = 'my_text.txt'");

        yield return(StartCoroutine(list));

        GoogleDrive.File            file;
        Dictionary <string, object> data;

        var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(list);

        if (files == null || files.Count > 0)
        {
            // Found!
            file = files[0];

            // Download file data.
            var download = drive.DownloadFile(file);
            yield return(StartCoroutine(download));

            var bytes = GoogleDrive.GetResult <byte[]>(download);
            try
            {
                // Data is json format.
                var reader = new JsonFx.Json.JsonReader(Encoding.UTF8.GetString(bytes));
                data = reader.Deserialize <Dictionary <string, object> >();
            }
            catch (Exception e)
            {
                Debug.LogWarning(e);

                data = new Dictionary <string, object>();
            }
        }
        else
        {
            // Make a new file.
            file = new GoogleDrive.File(new Dictionary <string, object>
            {
                { "title", "my_text.txt" },
                { "mimeType", "text/plain" },
                { "description", "test" }
            });
            data = new Dictionary <string, object>();
        }

        // Update file data.
        data["date"] = DateTime.Now.ToString();
        if (data.ContainsKey("count"))
        {
            data["count"] = (int)data["count"] + 1;
        }
        else
        {
            data["count"] = 0;
        }

        // And uploading...
        {
            var bytes = Encoding.UTF8.GetBytes(JsonFx.Json.JsonWriter.Serialize(data));

            var upload = drive.UploadFile(file, bytes);
            yield return(StartCoroutine(upload));

            if (!(upload.Current is Exception))
            {
                Debug.Log("Upload complete!");
            }
        }

        uploadTextInProgress = false;
    }
Exemple #8
0
    IEnumerator DonwloadAllFilesInFolder_internal(string loadFolderName, string saveFolderPath)
    {
        _isFileDownloadProcessing = true;

        _isFileDownloadDone       = false;
        _isSingleFileDownloadDone = false;



        string targetId = "";

        if (loadFolderName != "")
        {
            if (_filesDictionary != null && _filesDictionary.ContainsKey(loadFolderName))
            {
                targetId = _filesDictionary [loadFolderName].ID;
            }
        }

        var listFiles = _drive.ListFolders(recentFolderID);

        yield return(StartCoroutine(listFiles));

        var files = GoogleDrive.GetResult <List <GoogleDrive.File> >(listFiles);


        if (files != null)
        {
            //Processing Number Initialize !!
            if (!Directory.Exists(saveFolderPath))
            {
                Directory.CreateDirectory(saveFolderPath);
            }


            //Processed file count
            _NumberOfTotalDownloadFile = 0;
            foreach (var file in files)
            {
                if (file.Title.EndsWith(".jpg") || file.Title.EndsWith(".png") || file.Title.EndsWith(".JPG") || file.Title.EndsWith(".PNG"))
                {
                    _NumberOfTotalDownloadFile += 1;
                }
            }
            _NumberOfProcessedFile    = 0;
            _isSingleFileDownloadDone = true;


            //Download Start;

            //fileName Duplicator Check
            List <string> fileNameList = new List <string>();

            foreach (var file in files)
            {
                                #if UNITY_EDITOR
                Debug.Log(file);
                                #endif

                if (_isFileDownloadCancel)
                {
                    break;
                }


                if (file.Title.EndsWith(".jpg") || file.Title.EndsWith(".png") || file.Title.EndsWith(".JPG") || file.Title.EndsWith(".PNG"))
                {
                    var download = _drive.DownloadFile(file);
                    yield return(StartCoroutine(download));

                    var data = GoogleDrive.GetResult <byte[]>(download);

                    //Name Duplicator checker
                    string finalFileTitle = file.Title;

                    bool bIsDuplicatedFileName = false;
                    int  duplicatedNumber      = 0;
                    foreach (string title in fileNameList)
                    {
                        if (title == file.Title)
                        {
                            bIsDuplicatedFileName = true;
                            duplicatedNumber++;
                        }
                    }

                    if (bIsDuplicatedFileName)
                    {
                        finalFileTitle += duplicatedNumber.ToString();
                    }

                    try{
                        FileStream fs = new FileStream(saveFolderPath + "/" + finalFileTitle, FileMode.Create);
                        fs.Write(data, 0, data.Length);
                        fs.Dispose();

                        fileNameList.Add(file.Title);

                        //-----
                        ++_NumberOfProcessedFile;
                        _isSingleFileDownloadDone = true;
                    }catch {
                        _isFileDownloadCancel = true;
                    }
                }
            }
        }
        else
        {
                        #if UNITY_EDITOR
            Debug.Log(listFiles.Current);
                        #endif
        }

        _isFileDownloadDone = true;
    }