Example #1
0
        void DrawGoogleSheetDownload()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding);
            GUIContent content = new GUIContent(GDEConstants.DownloadGoogleSheetLbl);
            Vector2    size    = headerStyle.CalcSize(content);

            GUILayout.Label(content, headerStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
            EditorGUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding);
            content.text = GDEConstants.SelectSheetLbl;
            size         = labelStyle.CalcSize(content);
            GUILayout.Label(content, labelStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding);
            downloadSelectionIndex = EditorGUILayout.Popup(downloadSelectionIndex, GDEDriveHelper.Instance.SpreadSheetNames, comboBoxStyle);
            GUILayout.Space(windowPadding);
            EditorGUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding * 2f);
            if (GUILayout.Button(GDEConstants.BackBtn, buttonStyle))
            {
                nextView = GDEImportView.Default;
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(GDEConstants.DownloadBtn, buttonStyle))
            {
                googleSheetImportName = GDEDriveHelper.Instance.SpreadSheetNames[downloadSelectionIndex];

                // Save import settings
                GDESettings settings = GDESettings.Instance;
                settings.ImportedGoogleSpreadsheetName = googleSheetImportName;
                settings.ImportType = ImportExportType.Google;
                settings.Save();

                /*
                 * GoogleDriveHelper driveHelper = GoogleDriveHelper.Instance;
                 * spreadsheetPath = driveHelper.DownloadSpreadSheet(driveHelper.SpreadSheetNames[downloadSelectionIndex],
                 *                                                "import_" + googleSheetImportName + ".xlsx");
                 */

                GDEExcelManager.DoImport();
                nextView = GDEImportView.ImportComplete;
            }
            GUILayout.Space(windowPadding * 2f);
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(windowPadding);
        }
Example #2
0
        public void Init()
        {
            if (HasAuthenticated())
            {
                GDESettings settings     = GDESettings.Instance;
                string      accessToken  = settings.AccessTokenKey;
                string      refreshToken = settings.RefreshTokenKey;

                oauth2Params.AccessToken  = accessToken;
                oauth2Params.RefreshToken = refreshToken;

                string   timeString    = settings.AccessTokenTimeout;
                DateTime lastRefreshed = DateTime.MinValue;

                if (!timeString.Equals(string.Empty))
                {
                    DateTime.Parse(timeString);
                }

                TimeSpan timeSinceRefresh = DateTime.Now.Subtract(lastRefreshed);

                if (timeSinceRefresh.TotalSeconds >= ACCESS_TOKEN_TIMEOUT)
                {
                    RefreshAccessToken();
                }
            }
        }
Example #3
0
        void SaveTokens()
        {
            GDESettings settings = GDESettings.Instance;

            settings.AccessTokenTimeout = DateTime.Now.ToString();
            settings.AccessTokenKey     = oauth2Params.AccessToken;
            settings.RefreshTokenKey    = oauth2Params.RefreshToken;

            settings.Save();
        }
Example #4
0
        static void Load(string path)
        {
            byte[] bytes = File.ReadAllBytes(path);

            using (var stream = new MemoryStream(bytes))
            {
                BinaryFormatter bin = new BinaryFormatter();
                _instance = bin.Deserialize(stream) as GDESettings;
            }
        }
Example #5
0
        public static void ClearAuth()
        {
            GDESettings settings = GDESettings.Instance;

            settings.AccessTokenTimeout = string.Empty;
            settings.AccessTokenKey     = string.Empty;
            settings.RefreshTokenKey    = string.Empty;

            settings.Save();

            Debug.Log(GDEConstants.ClearedAuthMsg);
        }
        void DrawExportLocalFile()
        {
            content.text = GDEConstants.ExportExcelWorkbookLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeExportExcelWorkbookLblKey, content, headerStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CenteredOnLine(size.x), drawHelper.TopOfLine(), size.x, size.y), content, headerStyle);

            drawHelper.NewLine(2);

            content.text = GDEConstants.ExcelFileExportLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeExcelFileExportLblKey, content, labelStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
            drawHelper.CurrentLinePosition += size.x + 2f;
            drawHelper.NewLine();

            spreadsheetPath = EditorGUI.TextField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), drawHelper.FullSeparatorWidth(),
                                                           textFieldStyle.fixedHeight), spreadsheetPath, textFieldStyle);
            drawHelper.CurrentLinePosition += size.x + 2f;
            drawHelper.NewLine(1.1f);

            content.text = GDEConstants.BrowseBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeBrowseBtnKey, content, buttonStyle, out size);
            if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, buttonStyle))
            {
                string newSpreadSheetPath = EditorUtility.OpenFilePanel(GDEConstants.OpenWBLbl, spreadsheetPath, string.Empty);
                if (!string.IsNullOrEmpty(newSpreadSheetPath) && !newSpreadSheetPath.Equals(spreadsheetPath))
                {
                    spreadsheetPath = newSpreadSheetPath;
                }
                GUI.FocusControl(string.Empty);
            }

            // Draw Back & Export Buttons
            content.text = GDEConstants.BackBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeBackBtnKey, content, buttonStyle, out size);
            if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, position.height - size.y - drawHelper.BottomBuffer, size.x, size.y), content, buttonStyle))
            {
                nextView = View.Default;
            }

            content.text = GDEConstants.ExportBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeExportBtnKey, content, buttonStyle, out size);
            if (GUI.Button(new Rect(position.width - size.x - drawHelper.LeftBuffer, position.height - size.y - drawHelper.BottomBuffer, size.x, size.y), content, buttonStyle))
            {
                GDESettings settings = GDESettings.Instance;
                settings.ExportedLocalSpreadsheetName = spreadsheetPath;
                settings.ExportType = ImportExportType.Local;
                settings.Save();

                GDEExcelManager.DoExport();
                nextView = View.ImportComplete;
            }
        }
        public static void DoExport(bool newSheet = false)
        {
            GDESettings settings = GDESettings.Instance;

            if (!GDEItemManager.FileChangedOnDisk(GDEItemManager.DataFilePath, settings.ExportFileMD5))
            {
                Debug.Log("GDE Data hasn't changed, skipping export.");
                return;
            }

            if (settings.ExportType.Equals(ImportExportType.Local) &&
                !string.IsNullOrEmpty(settings.ExportedLocalSpreadsheetName))
            {
                // take the local languages dictionary
                // write it out to an excel file
                GDEExcelDataHelper excelHelper = new GDEExcelDataHelper(settings.ExportedLocalSpreadsheetName, true);
                excelHelper.ExportToSheet(GDEItemManager.ItemListBySchema);
                settings.ExportFileMD5 = File.ReadAllText(GDEItemManager.DataFilePath).Md5Sum();
            }
            else if (settings.ExportType.Equals(ImportExportType.Google) &&
                     !string.IsNullOrEmpty(settings.ExportedGoogleSpreadsheetPath) &&
                     GDEDriveHelper.Instance.HasAuthenticated())
            {
                GDEDriveHelper.Instance.GetSpreadsheetList();

                string tempSheetPath = FileUtil.GetUniqueTempPathInProject() + "exportnewgoog_" + settings.ExportedGoogleSpreadsheetPath + ".xlsx";

                GDEExcelDataHelper excelHelper = new GDEExcelDataHelper(tempSheetPath, true);
                excelHelper.ExportToSheet(GDEItemManager.ItemListBySchema);

                if (newSheet)
                {
                    GDEDriveHelper.Instance.UploadNewSheet(tempSheetPath, settings.ExportedGoogleSpreadsheetPath);
                    settings.ExportFileMD5 = File.ReadAllText(GDEItemManager.DataFilePath).Md5Sum();
                }
                else
                {
                    GDEDriveHelper.Instance.UploadToExistingSheet(settings.ExportedGoogleSpreadsheetPath, tempSheetPath);
                    settings.ExportFileMD5 = File.ReadAllText(GDEItemManager.DataFilePath).Md5Sum();
                }
            }
            else
            {
                var window = EditorWindow.GetWindow <GameDataEditor.GDEExportExcel>(true, GDEConstants.ExportSpreadsheetLbl);
                window.LoadSettings();
                window.Show();
            }
        }
        public static void ClearExcelSettings()
        {
            GDESettings settings = GDESettings.Instance;

            settings.ImportedGoogleSpreadsheetName = string.Empty;
            settings.ImportedLocalSpreadsheetName  = string.Empty;

            settings.ExportedGoogleSpreadsheetPath = string.Empty;
            settings.ExportedLocalSpreadsheetName  = string.Empty;

            settings.ImportType    = ImportExportType.None;
            settings.ExportType    = ImportExportType.None;
            settings.ExportFileMD5 = string.Empty;

            settings.Save();
        }
        static void Load()
        {
            if (File.Exists(settingsPath))
            {
                byte[] bytes = File.ReadAllBytes(settingsPath);

                using (var stream = new MemoryStream(bytes))
                {
                    BinaryFormatter bin = new BinaryFormatter();
                    _instance = bin.Deserialize(stream) as GDESettings;
                }
            }
            else
            {
                _instance = new GDESettings();
            }
        }
Example #10
0
 static void Load()
 {
     if (File.Exists(oldSettingsPath))
     {
         Load(oldSettingsPath);
         File.Delete(oldSettingsPath);
         Instance.Save();
         AssetDatabase.Refresh();
     }
     else if (File.Exists(settingsPath))
     {
         Load(settingsPath);
     }
     else
     {
         _instance = new GDESettings();
     }
 }
        void DrawUploadNewView()
        {
            content.text = GDEConstants.ExportNewGoogleSheetLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeExportToNewSheetBtnKey, content, headerStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CenteredOnLine(size.x), drawHelper.TopOfLine(), size.x, size.y), content, headerStyle);

            drawHelper.NewLine(2);

            content.text = GDEConstants.NewSheetFileNameLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeNewSheetFileNameLblKey, content, labelStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);

            drawHelper.NewLine(1.1f);

            spreadsheetName = EditorGUI.TextField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), drawHelper.FullSeparatorWidth(), size.y),
                                                  spreadsheetName, textFieldStyle);

            // Draw Back & Upload Buttons
            content.text = GDEConstants.BackBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeBackBtnKey, content, buttonStyle, out size);
            if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, position.height - size.y - drawHelper.BottomBuffer, size.x, size.y), content, buttonStyle))
            {
                nextView = View.Default;
            }

            content.text = GDEConstants.UploadBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeUploadBtnKey, content, buttonStyle, out size);
            if (!string.IsNullOrEmpty(spreadsheetName) &&
                GUI.Button(new Rect(position.width - size.x - drawHelper.LeftBuffer, position.height - size.y - drawHelper.BottomBuffer, size.x, size.y), content, buttonStyle))
            {
                GDESettings settings = GDESettings.Instance;
                settings.ExportedGoogleSpreadsheetPath = spreadsheetName;
                settings.ExportType = ImportExportType.Google;
                settings.Save();

                GDEExcelManager.DoExport(true);
                nextView = View.ImportComplete;
            }
        }
        void DrawUploadExistingView()
        {
            content.text = GDEConstants.ExportGoogleSheetLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeExportGoogleSheetLblKey, content, headerStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CenteredOnLine(size.x), drawHelper.TopOfLine(), size.x, size.y), content, headerStyle);

            drawHelper.NewLine(2);

            content.text = GDEConstants.SelectExportSpreadSheetLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeSelectExportSpreadSheetLblKey, content, labelStyle, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);

            drawHelper.NewLine(1.1f);

            downloadSelectionIndex = EditorGUI.Popup(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), drawHelper.FullSeparatorWidth(), size.y),
                                                     downloadSelectionIndex, GDEDriveHelper.Instance.SpreadSheetNames, comboBoxStyle);

            // Draw Back & Upload Buttons
            content.text = GDEConstants.BackBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeBackBtnKey, content, buttonStyle, out size);
            if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, position.height - size.y - drawHelper.BottomBuffer, size.x, size.y), content, buttonStyle))
            {
                nextView = View.Default;
            }

            content.text = GDEConstants.UploadBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeUploadBtnKey, content, buttonStyle, out size);
            if (GUI.Button(new Rect(position.width - size.x - drawHelper.LeftBuffer, position.height - size.y - drawHelper.BottomBuffer, size.x, size.y), content, buttonStyle))
            {
                GDESettings settings = GDESettings.Instance;
                settings.ExportedGoogleSpreadsheetPath = GDEDriveHelper.Instance.SpreadSheetNames[downloadSelectionIndex];
                settings.ExportType = ImportExportType.Google;
                settings.Save();

                GDEExcelManager.DoExport();
                nextView = View.ImportComplete;
            }
        }
        public static void DoImport()
        {
            GDESettings settings = GDESettings.Instance;

            if (settings.ImportType.Equals(ImportExportType.Local) &&
                !string.IsNullOrEmpty(settings.ImportedLocalSpreadsheetName))
            {
                ProcessSheet(settings.ImportedLocalSpreadsheetName);
            }
            else if (settings.ImportType.Equals(ImportExportType.Google) &&
                     !string.IsNullOrEmpty(settings.ImportedGoogleSpreadsheetName) &&
                     GDEDriveHelper.Instance.HasAuthenticated())
            {
                string path = GDEDriveHelper.Instance.DownloadSpreadSheet(settings.ImportedGoogleSpreadsheetName,
                                                                          "import_" + settings.ImportedGoogleSpreadsheetName + ".xlsx");
                ProcessSheet(path);
            }
            else
            {
                var window = EditorWindow.GetWindow <GDEImportExcel>(true, GDEConstants.ImportSpreadsheetMenu);
                window.LoadSettings();
                window.Show();
            }
        }
Example #14
0
        void DrawImportLocalFile()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding);
            GUIContent content = new GUIContent(GDEConstants.ImportWBLbl);
            Vector2    size    = headerStyle.CalcSize(content);

            GUILayout.Label(content, headerStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
            EditorGUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding);
            content.text = GDEConstants.ExcelFileLbl;
            size         = labelStyle.CalcSize(content);
            GUILayout.Label(content, labelStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding);
            spreadsheetPath = EditorGUILayout.TextField(spreadsheetPath, textFieldStyle);
            GUILayout.Space(windowPadding);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding);
            if (GUILayout.Button(GDEConstants.BrowseBtn, buttonStyle))
            {
                string newSpreadSheetPath = EditorUtility.OpenFilePanel(GDEConstants.OpenWBLbl, spreadsheetPath, string.Empty);
                if (!string.IsNullOrEmpty(newSpreadSheetPath) && !newSpreadSheetPath.Equals(spreadsheetPath))
                {
                    spreadsheetPath = newSpreadSheetPath;
                }
                GUI.FocusControl(string.Empty);
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(windowPadding * 2f);
            if (GUILayout.Button(GDEConstants.BackBtn, buttonStyle))
            {
                nextView = GDEImportView.Default;
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(GDEConstants.ImportBtn, buttonStyle))
            {
                // Save the import settings
                GDESettings settings = GDESettings.Instance;
                settings.ImportedLocalSpreadsheetName = spreadsheetPath;
                settings.ImportType = ImportExportType.Local;
                settings.Save();

                // Do the import
                GDEExcelManager.DoImport();
                nextView = GDEImportView.ImportComplete;
            }
            GUILayout.Space(windowPadding * 2f);
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(windowPadding);
        }
Example #15
0
        static void Load()
        {
            if (File.Exists(settingsPath))
            {
                byte[] bytes = File.ReadAllBytes(settingsPath);

                using (var stream = new MemoryStream(bytes))
                {
                    BinaryFormatter bin = new BinaryFormatter();
                    _instance = bin.Deserialize(stream) as GDESettings;
                }
            }
            else
            {
                _instance = new GDESettings();
            }
        }