Пример #1
0
        // ---------[ VALUE DUPLICATION ]---------
        public static EditableModProfile CreateFromProfile(ModProfile profile)
        {
            EditableModProfile retVal = new EditableModProfile();

            retVal.ApplyBaseProfileChanges(profile);
            return(retVal);
        }
        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);
            }
        }
Пример #3
0
        // ---------[ UPLOADING ]---------
        public static void SubmitNewMod(EditableModProfile modEdits,
                                        Action <ModProfile> modSubmissionSucceeded,
                                        Action <WebRequestError> modSubmissionFailed)
        {
            Debug.Assert(modEdits.name.isDirty && modEdits.summary.isDirty);
            Debug.Assert(File.Exists(modEdits.logoLocator.value.url));

            // - Initial Mod Submission -
            var parameters = new AddModParameters();

            parameters.name    = modEdits.name.value;
            parameters.summary = modEdits.summary.value;
            parameters.logo    = BinaryUpload.Create(Path.GetFileName(modEdits.logoLocator.value.url),
                                                     File.ReadAllBytes(modEdits.logoLocator.value.url));
            if (modEdits.visibility.isDirty)
            {
                parameters.visibility = modEdits.visibility.value;
            }
            if (modEdits.nameId.isDirty)
            {
                parameters.nameId = modEdits.nameId.value;
            }
            if (modEdits.description.isDirty)
            {
                parameters.description = modEdits.description.value;
            }
            if (modEdits.homepageURL.isDirty)
            {
                parameters.nameId = modEdits.homepageURL.value;
            }
            if (modEdits.metadataBlob.isDirty)
            {
                parameters.metadataBlob = modEdits.metadataBlob.value;
            }
            if (modEdits.nameId.isDirty)
            {
                parameters.nameId = modEdits.nameId.value;
            }
            if (modEdits.tags.isDirty)
            {
                parameters.tags = modEdits.tags.value;
            }

            // NOTE(@jackson): As add Mod takes more parameters than edit,
            //  we can ignore some of the elements in the EditModParameters
            //  when passing to SubmitModProfileComponents
            var remainingModEdits = new EditableModProfile();

            remainingModEdits.youtubeURLs          = modEdits.youtubeURLs;
            remainingModEdits.sketchfabURLs        = modEdits.sketchfabURLs;
            remainingModEdits.galleryImageLocators = modEdits.galleryImageLocators;

            APIClient.AddMod(parameters,
                             result => SubmitModProfileComponents(result,
                                                                  remainingModEdits,
                                                                  modSubmissionSucceeded,
                                                                  modSubmissionFailed),
                             modSubmissionFailed);
        }
        /// <summary>Submits changes to a mod to the server.</summary>
        public void SubmitModChanges(int modId, EditableModProfile modEdits)
        {
            Debug.Assert(modId != ModProfile.NULL_ID);

            this.eModProfile = modEdits;

            if (this.eModProfile.status.isDirty ||
                this.eModProfile.visibility.isDirty ||
                this.eModProfile.name.isDirty ||
                this.eModProfile.nameId.isDirty ||
                this.eModProfile.summary.isDirty ||
                this.eModProfile.descriptionAsHTML.isDirty ||
                this.eModProfile.homepageURL.isDirty ||
                this.eModProfile.metadataBlob.isDirty)
            {
                var parameters = new EditModParameters();
                if (this.eModProfile.status.isDirty)
                {
                    parameters.status = this.eModProfile.status.value;
                }
                if (this.eModProfile.visibility.isDirty)
                {
                    parameters.visibility = this.eModProfile.visibility.value;
                }
                if (this.eModProfile.name.isDirty)
                {
                    parameters.name = this.eModProfile.name.value;
                }
                if (this.eModProfile.nameId.isDirty)
                {
                    parameters.nameId = this.eModProfile.nameId.value;
                }
                if (this.eModProfile.summary.isDirty)
                {
                    parameters.summary = this.eModProfile.summary.value;
                }
                if (this.eModProfile.descriptionAsHTML.isDirty)
                {
                    parameters.descriptionAsHTML = this.eModProfile.descriptionAsHTML.value;
                }
                if (this.eModProfile.homepageURL.isDirty)
                {
                    parameters.homepageURL = this.eModProfile.homepageURL.value;
                }
                if (this.eModProfile.metadataBlob.isDirty)
                {
                    parameters.metadataBlob = this.eModProfile.metadataBlob.value;
                }

                APIClient.EditMod(modId, parameters, this.SubmitModChanges_Internal, this.onError);
            }
            // - Get updated ModProfile -
            else
            {
                ModManager.GetModProfile(modId, this.SubmitModChanges_Internal, this.onError);
            }
        }
Пример #5
0
        private static void SubmitModProfileComponents(ModProfile profile,
                                                       EditableModProfile modEdits,
                                                       Action <ModProfile> modSubmissionSucceeded,
                                                       Action <WebRequestError> modSubmissionFailed)
        {
            List <Action>       submissionActions      = new List <Action>();
            int                 nextActionIndex        = 0;
            Action <APIMessage> doNextSubmissionAction = (m) =>
            {
                if (nextActionIndex < submissionActions.Count)
                {
                    submissionActions[nextActionIndex++]();
                }
            };

            // - Media -
            if (modEdits.logoLocator.isDirty ||
                modEdits.youtubeURLs.isDirty ||
                modEdits.sketchfabURLs.isDirty ||
                modEdits.galleryImageLocators.isDirty)
            {
                var addMediaParameters    = new AddModMediaParameters();
                var deleteMediaParameters = new DeleteModMediaParameters();

                if (modEdits.logoLocator.isDirty &&
                    File.Exists(modEdits.logoLocator.value.url))
                {
                    addMediaParameters.logo = BinaryUpload.Create(Path.GetFileName(modEdits.logoLocator.value.url),
                                                                  File.ReadAllBytes(modEdits.logoLocator.value.url));
                }

                if (modEdits.youtubeURLs.isDirty)
                {
                    var addedYouTubeLinks = new List <string>(modEdits.youtubeURLs.value);
                    foreach (string youtubeLink in profile.media.youtubeURLs)
                    {
                        addedYouTubeLinks.Remove(youtubeLink);
                    }
                    addMediaParameters.youtube = addedYouTubeLinks.ToArray();

                    var removedTags = new List <string>(profile.media.youtubeURLs);
                    foreach (string youtubeLink in modEdits.youtubeURLs.value)
                    {
                        removedTags.Remove(youtubeLink);
                    }
                    deleteMediaParameters.youtube = addedYouTubeLinks.ToArray();
                }

                if (modEdits.sketchfabURLs.isDirty)
                {
                    var addedSketchfabLinks = new List <string>(modEdits.sketchfabURLs.value);
                    foreach (string sketchfabLink in profile.media.sketchfabURLs)
                    {
                        addedSketchfabLinks.Remove(sketchfabLink);
                    }
                    addMediaParameters.sketchfab = addedSketchfabLinks.ToArray();

                    var removedTags = new List <string>(profile.media.sketchfabURLs);
                    foreach (string sketchfabLink in modEdits.sketchfabURLs.value)
                    {
                        removedTags.Remove(sketchfabLink);
                    }
                    deleteMediaParameters.sketchfab = addedSketchfabLinks.ToArray();
                }

                if (modEdits.galleryImageLocators.isDirty)
                {
                    var addedImageFilePaths = new List <string>();
                    foreach (var locator in modEdits.galleryImageLocators.value)
                    {
                        if (File.Exists(locator.url))
                        {
                            addedImageFilePaths.Add(locator.url);
                        }
                    }
                    // - Create Images.Zip -
                    if (addedImageFilePaths.Count > 0)
                    {
                        string galleryZipLocation
                            = Application.temporaryCachePath + "/modio/imageGallery_" + DateTime.Now.ToFileTime() + ".zip";

                        try
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(galleryZipLocation));

                            using (var zip = new Ionic.Zip.ZipFile())
                            {
                                foreach (string imageFilePath in addedImageFilePaths)
                                {
                                    zip.AddFile(imageFilePath);
                                }
                                zip.Save(galleryZipLocation);
                            }

                            var imageGalleryUpload = BinaryUpload.Create("images.zip",
                                                                         File.ReadAllBytes(galleryZipLocation));

                            addMediaParameters.galleryImages = imageGalleryUpload;
                        }
                        catch (Exception e)
                        {
                            Debug.LogError("[mod.io] Unable to zip image gallery prior to uploading.\n\n"
                                           + Utility.GenerateExceptionDebugString(e));
                        }
                    }

                    var removedImageFileNames = new List <string>();
                    foreach (var locator in profile.media.galleryImageLocators)
                    {
                        removedImageFileNames.Add(locator.fileName);
                    }
                    foreach (var locator in modEdits.galleryImageLocators.value)
                    {
                        removedImageFileNames.Remove(locator.fileName);
                    }

                    if (removedImageFileNames.Count > 0)
                    {
                        deleteMediaParameters.images = removedImageFileNames.ToArray();
                    }
                }

                if (addMediaParameters.stringValues.Count > 0 ||
                    addMediaParameters.binaryData.Count > 0)
                {
                    submissionActions.Add(() =>
                    {
                        APIClient.AddModMedia(profile.id,
                                              addMediaParameters,
                                              doNextSubmissionAction, modSubmissionFailed);
                    });
                }
                if (deleteMediaParameters.stringValues.Count > 0)
                {
                    submissionActions.Add(() =>
                    {
                        APIClient.DeleteModMedia(profile.id,
                                                 deleteMediaParameters,
                                                 () => doNextSubmissionAction(null),
                                                 modSubmissionFailed);
                    });
                }
            }

            // - Tags -
            if (modEdits.tags.isDirty)
            {
                var removedTags = new List <string>(profile.tagNames);
                foreach (string tag in modEdits.tags.value)
                {
                    removedTags.Remove(tag);
                }
                var addedTags = new List <string>(modEdits.tags.value);
                foreach (string tag in profile.tagNames)
                {
                    addedTags.Remove(tag);
                }

                if (removedTags.Count > 0)
                {
                    submissionActions.Add(() =>
                    {
                        var parameters      = new DeleteModTagsParameters();
                        parameters.tagNames = removedTags.ToArray();
                        APIClient.DeleteModTags(profile.id, parameters,
                                                doNextSubmissionAction, modSubmissionFailed);
                    });
                }
                if (addedTags.Count > 0)
                {
                    submissionActions.Add(() =>
                    {
                        var parameters      = new AddModTagsParameters();
                        parameters.tagNames = addedTags.ToArray();
                        APIClient.AddModTags(profile.id, parameters,
                                             doNextSubmissionAction, modSubmissionFailed);
                    });
                }
            }

            // - Metadata KVP -
            if (modEdits.metadataKVPs.isDirty)
            {
                var removedKVPs = MetadataKVP.ArrayToDictionary(profile.metadataKVPs);
                var addedKVPs   = MetadataKVP.ArrayToDictionary(modEdits.metadataKVPs.value);

                foreach (MetadataKVP kvp in modEdits.metadataKVPs.value)
                {
                    string profileValue;

                    // if edited kvp is exact match it's not removed
                    if (removedKVPs.TryGetValue(kvp.key, out profileValue) &&
                        profileValue == kvp.value)
                    {
                        removedKVPs.Remove(kvp.key);
                    }
                }

                foreach (MetadataKVP kvp in profile.metadataKVPs)
                {
                    string editValue;

                    // if profile kvp is exact match it's not new
                    if (addedKVPs.TryGetValue(kvp.key, out editValue) &&
                        editValue == kvp.value)
                    {
                        addedKVPs.Remove(kvp.key);
                    }
                }

                if (removedKVPs.Count > 0)
                {
                    submissionActions.Add(() =>
                    {
                        var parameters          = new DeleteModKVPMetadataParameters();
                        parameters.metadataKeys = removedKVPs.Keys.ToArray();
                        APIClient.DeleteModKVPMetadata(profile.id, parameters,
                                                       doNextSubmissionAction,
                                                       modSubmissionFailed);
                    });
                }

                if (addedKVPs.Count > 0)
                {
                    string[] addedKVPStrings = AddModKVPMetadataParameters.ConvertMetadataKVPsToAPIStrings(MetadataKVP.DictionaryToArray(addedKVPs));

                    submissionActions.Add(() =>
                    {
                        var parameters      = new AddModKVPMetadataParameters();
                        parameters.metadata = addedKVPStrings;
                        APIClient.AddModKVPMetadata(profile.id, parameters,
                                                    doNextSubmissionAction,
                                                    modSubmissionFailed);
                    });
                }
            }

            // - Get Updated Profile -
            submissionActions.Add(() => APIClient.GetMod(profile.id,
                                                         modSubmissionSucceeded,
                                                         modSubmissionFailed));

            // - Start submission chain -
            doNextSubmissionAction(new APIMessage());
        }
Пример #6
0
        public static void SubmitModChanges(int modId,
                                            EditableModProfile modEdits,
                                            Action <ModProfile> modSubmissionSucceeded,
                                            Action <WebRequestError> modSubmissionFailed)
        {
            Debug.Assert(modId > 0);

            Action <ModProfile> submitChanges = (profile) =>
            {
                if (modEdits.status.isDirty ||
                    modEdits.visibility.isDirty ||
                    modEdits.name.isDirty ||
                    modEdits.nameId.isDirty ||
                    modEdits.summary.isDirty ||
                    modEdits.description.isDirty ||
                    modEdits.homepageURL.isDirty ||
                    modEdits.metadataBlob.isDirty)
                {
                    var parameters = new EditModParameters();
                    if (modEdits.status.isDirty)
                    {
                        parameters.status = modEdits.status.value;
                    }
                    if (modEdits.visibility.isDirty)
                    {
                        parameters.visibility = modEdits.visibility.value;
                    }
                    if (modEdits.name.isDirty)
                    {
                        parameters.name = modEdits.name.value;
                    }
                    if (modEdits.nameId.isDirty)
                    {
                        parameters.nameId = modEdits.nameId.value;
                    }
                    if (modEdits.summary.isDirty)
                    {
                        parameters.summary = modEdits.summary.value;
                    }
                    if (modEdits.description.isDirty)
                    {
                        parameters.description = modEdits.description.value;
                    }
                    if (modEdits.homepageURL.isDirty)
                    {
                        parameters.homepageURL = modEdits.homepageURL.value;
                    }
                    if (modEdits.metadataBlob.isDirty)
                    {
                        parameters.metadataBlob = modEdits.metadataBlob.value;
                    }

                    APIClient.EditMod(modId, parameters,
                                      (p) => SubmitModProfileComponents(profile, modEdits,
                                                                        modSubmissionSucceeded,
                                                                        modSubmissionFailed),
                                      modSubmissionFailed);
                }
                // - Get updated ModProfile -
                else
                {
                    SubmitModProfileComponents(profile,
                                               modEdits,
                                               modSubmissionSucceeded,
                                               modSubmissionFailed);
                }
            };

            ModManager.GetModProfile(modId,
                                     submitChanges,
                                     modSubmissionFailed);
        }
        // ---------[ Submission Functions ]---------
        /// <summary>Submits a new mod to the server.</summary>
        public void SubmitNewMod(EditableModProfile newModProfile)
        {
            Debug.Assert(newModProfile != null);

            // - Client-Side error-checking -
            string errorMessage = null;

            if (String.IsNullOrEmpty(newModProfile.name.value))
            {
                errorMessage = "Mod Profile needs to be named before it can be uploaded";
            }
            else if (String.IsNullOrEmpty(newModProfile.summary.value))
            {
                errorMessage = "Mod Profile needs to be given a summary before it can be uploaded";
            }

            // Send data
            if (errorMessage == null)
            {
                // - string params -
                this.addModParams         = new AddModParameters();
                this.addModParams.name    = newModProfile.name.value;
                this.addModParams.summary = newModProfile.summary.value;

                if (newModProfile.visibility.isDirty)
                {
                    this.addModParams.visibility = newModProfile.visibility.value;
                }
                if (newModProfile.nameId.isDirty)
                {
                    this.addModParams.nameId = newModProfile.nameId.value;
                }
                if (newModProfile.descriptionAsHTML.isDirty)
                {
                    this.addModParams.descriptionAsHTML = newModProfile.descriptionAsHTML.value;
                }
                if (newModProfile.homepageURL.isDirty)
                {
                    this.addModParams.nameId = newModProfile.homepageURL.value;
                }
                if (newModProfile.metadataBlob.isDirty)
                {
                    this.addModParams.metadataBlob = newModProfile.metadataBlob.value;
                }
                if (newModProfile.nameId.isDirty)
                {
                    this.addModParams.nameId = newModProfile.nameId.value;
                }
                if (newModProfile.tags.isDirty)
                {
                    this.addModParams.tags = newModProfile.tags.value;
                }

                // - editable params -
                if (newModProfile.youTubeURLs.isDirty ||
                    newModProfile.sketchfabURLs.isDirty ||
                    newModProfile.galleryImageLocators.isDirty)
                {
                    // NOTE(@jackson): As add Mod takes more parameters than edit,
                    //  we can ignore some of the elements in the EditModParameters
                    //  when passing to SubmitModChanges_Internal
                    this.eModProfile                      = new EditableModProfile();
                    this.eModProfile.youTubeURLs          = newModProfile.youTubeURLs;
                    this.eModProfile.sketchfabURLs        = newModProfile.sketchfabURLs;
                    this.eModProfile.galleryImageLocators = newModProfile.galleryImageLocators;
                }

                // - data params -
                DataStorage.ReadFile(newModProfile.logoLocator.value.url, this.SubmitNewMod_OnReadLogo);
            }
            else
            {
                this.SubmissionError_Local(errorMessage);
            }
        }
Пример #8
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);
            }
        }