private void ModProfileSubmissionSucceeded(ModProfile updatedProfile,
                                                   string profileFilePath)
        {
            // Update ScriptableModProfile
            profile.modId = updatedProfile.id;
            profile.editableModProfile = EditableModProfile.CreateFromProfile(updatedProfile);
            EditorUtility.SetDirty(profile);
            AssetDatabase.SaveAssets();

            // Upload Build
            if (System.IO.File.Exists(buildFilePath))
            {
                Action <WebRequestError> onSubmissionFailed = (e) =>
                {
                    EditorUtility.DisplayDialog("Upload Failed",
                                                "Failed to upload the mod build to the server.\n"
                                                + e.message,
                                                "Close");
                    isAwaitingServerResponse = false;
                };

                ModManager.UploadModBinary_Unzipped(profile.modId,
                                                    buildProfile,
                                                    buildFilePath,
                                                    true,
                                                    mf => NotifySubmissionSucceeded(updatedProfile.name,
                                                                                    updatedProfile.profileURL),
                                                    onSubmissionFailed);
            }
            else
            {
                NotifySubmissionSucceeded(updatedProfile.name, updatedProfile.profileURL);
            }
        }
Exemple #2
0
        protected virtual void LayoutProfileInitialization()
        {
            EditorGUILayout.LabelField("Initialize Mod Profile");

            // ---[ DISPLAY ]---
            EditorGUILayout.Space();

            if (GUILayout.Button("Create New"))
            {
                EditorApplication.delayCall += () =>
                {
                    ScriptableModProfile smp = this.target as ScriptableModProfile;
                    Undo.RecordObject(smp, "Initialize Mod Profile");

                    smp.modId = 0;
                    smp.editableModProfile = new EditableModProfile();

                    OnDisable();
                    OnEnable();
                    isRepaintRequired = true;
                };
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("---- OR ----");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Load Existing Profile");

            if (user == null)
            {
                EditorGUILayout.HelpBox("Log in required to load existing mods",
                                        MessageType.Info);
                if (GUILayout.Button("Log In to mod.io"))
                {
                    LoginWindow.GetWindow <LoginWindow>("Login to mod.io");
                }
            }
            else if (modOptions.Length > 0)
            {
                using (new EditorGUI.DisabledScope(isModListLoading))
                {
                    modInitializationOptionIndex = EditorGUILayout.Popup("Select Mod", modInitializationOptionIndex, modOptions, null);
                    if (GUILayout.Button("Load"))
                    {
                        ModProfile profile = modList[modInitializationOptionIndex];
                        EditorApplication.delayCall += () =>
                        {
                            ScriptableModProfile smp = this.target as ScriptableModProfile;
                            Undo.RecordObject(smp, "Initialize Mod Profile");

                            smp.modId = profile.id;
                            smp.editableModProfile = EditableModProfile.CreateFromProfile(profile);

                            string smpFilePath = AssetDatabase.GetAssetPath(smp);
                            string smpDir      = System.IO.Path.GetDirectoryName(smpFilePath);

                            int profileCount
                                = System.IO.Directory.GetFiles(smpDir, profile.name + "*.asset").Length;

                            string fileNameAddition = (profileCount > 0
                                                       ? " (" + profileCount.ToString() + ")"
                                                       : "");

                            AssetDatabase.RenameAsset(smpFilePath, profile.name + fileNameAddition + ".asset");

                            OnDisable();
                            OnEnable();
                            isRepaintRequired = true;
                        };
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("No loadable mod profiles detected.",
                                        MessageType.Info);
            }
        }