private void SubmitNewMod_OnReadLogo(string path, bool success, byte[] data)
        {
            if (!success)
            {
                this.SubmissionError_Local("Mod Profile logo file could not be read for uploading."
                                           + "\nLogo Path: " + path);
            }
            else
            {
                this.addModParams.logo = BinaryUpload.Create(Path.GetFileName(path), data);

                if (this.eModProfile == null)
                {
                    APIClient.AddMod(this.addModParams,
                                     this.onSuccess,
                                     this.onError);
                }
                else
                {
                    APIClient.AddMod(this.addModParams,
                                     this.SubmitModChanges_Internal,
                                     this.onError);
                }
            }
        }
Пример #2
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);
        }
Пример #3
0
        public static void UploadModBinary_Zipped(int modId,
                                                  EditableModfile modfileValues,
                                                  string binaryZipLocation,
                                                  bool setPrimary,
                                                  Action <Modfile> onSuccess,
                                                  Action <WebRequestError> onError)
        {
            string buildFilename = Path.GetFileName(binaryZipLocation);

            byte[] buildZipData = File.ReadAllBytes(binaryZipLocation);

            var parameters = new AddModfileParameters();

            parameters.zippedBinaryData = BinaryUpload.Create(buildFilename, buildZipData);
            if (modfileValues.version.isDirty)
            {
                parameters.version = modfileValues.version.value;
            }
            if (modfileValues.changelog.isDirty)
            {
                parameters.changelog = modfileValues.changelog.value;
            }
            if (modfileValues.metadataBlob.isDirty)
            {
                parameters.metadataBlob = modfileValues.metadataBlob.value;
            }

            // - Generate Hash -
            using (var md5 = System.Security.Cryptography.MD5.Create())
            {
                using (var stream = System.IO.File.OpenRead(binaryZipLocation))
                {
                    var hash = md5.ComputeHash(stream);
                    parameters.fileHash = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                }
            }

            APIClient.AddModfile(modId, parameters, onSuccess, onError);
        }
Пример #4
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());
        }
        private void SubmitNextParameter(object o)
        {
            // - Media -
            if ((this.removedImageFileNames != null && this.removedImageFileNames.Count > 0) ||
                (this.removedSketchfabURLs != null && this.removedSketchfabURLs.Count > 0) ||
                (this.removedYouTubeURLs != null && this.removedYouTubeURLs.Count > 0))
            {
                var parameters = new DeleteModMediaParameters();

                if (this.removedImageFileNames != null)
                {
                    parameters.images = this.removedImageFileNames.ToArray();
                }
                if (this.removedSketchfabURLs != null)
                {
                    parameters.sketchfab = this.removedSketchfabURLs.ToArray();
                }
                if (this.removedYouTubeURLs != null)
                {
                    parameters.youtube = this.removedYouTubeURLs.ToArray();
                }

                APIClient.DeleteModMedia(this.modId, parameters,
                                         this.SubmitNextParameter,
                                         this.onError);

                this.removedImageFileNames = null;
                this.removedSketchfabURLs  = null;
                this.removedYouTubeURLs    = null;
            }
            else if ((this.logoData != null) ||
                     (this.imageArchiveData != null) ||
                     (this.addedSketchfabURLs != null && this.addedSketchfabURLs.Count > 0) ||
                     (this.addedYouTubeURLs != null && this.addedYouTubeURLs.Count > 0))
            {
                var parameters = new AddModMediaParameters();

                if (this.logoData != null)
                {
                    parameters.logo = BinaryUpload.Create(Path.GetFileName(this.logoPath), this.logoData);
                }
                if (this.imageArchiveData != null)
                {
                    parameters.galleryImages = BinaryUpload.Create("images.zip", this.imageArchiveData);
                }
                if (this.addedSketchfabURLs != null && this.addedSketchfabURLs.Count > 0)
                {
                    parameters.sketchfab = this.addedSketchfabURLs.ToArray();
                }
                if (this.addedYouTubeURLs != null && this.addedYouTubeURLs.Count > 0)
                {
                    parameters.youtube = this.addedYouTubeURLs.ToArray();
                }

                APIClient.AddModMedia(this.modId, parameters,
                                      this.SubmitNextParameter,
                                      this.onError);

                this.logoData           = null;
                this.imageArchiveData   = null;
                this.addedSketchfabURLs = null;
                this.addedYouTubeURLs   = null;
            }
            // - Tags -
            else if (this.removedTags != null && this.removedTags.Count > 0)
            {
                var parameters = new DeleteModTagsParameters();
                parameters.tagNames = this.removedTags.ToArray();

                APIClient.DeleteModTags(this.modId, parameters,
                                        this.SubmitNextParameter,
                                        this.onError);

                this.removedTags = null;
            }
            else if (this.addedTags != null && this.addedTags.Count > 0)
            {
                var parameters = new AddModTagsParameters();
                parameters.tagNames = this.addedTags.ToArray();

                APIClient.AddModTags(this.modId, parameters,
                                     this.SubmitNextParameter,
                                     this.onError);

                this.addedTags = null;
            }
            // - KVPs -
            else if (this.removedKVPs != null && this.removedKVPs.Count > 0)
            {
                var parameters = new DeleteModKVPMetadataParameters();
                parameters.metadataKeys = this.removedKVPs.Keys.ToArray();

                APIClient.DeleteModKVPMetadata(this.modId, parameters,
                                               this.SubmitNextParameter,
                                               this.onError);
                this.removedKVPs = null;
            }
            else if (this.addedKVPs != null && this.addedKVPs.Count > 0)
            {
                string[] addedKVPStrings = AddModKVPMetadataParameters.ConvertMetadataKVPsToAPIStrings(MetadataKVP.DictionaryToArray(this.addedKVPs));

                var parameters = new AddModKVPMetadataParameters();
                parameters.metadata = addedKVPStrings;

                APIClient.AddModKVPMetadata(this.modId, parameters,
                                            this.SubmitNextParameter,
                                            this.onError);

                this.addedKVPs = null;
            }
            // - FINALIZE -
            else if (o != null && o is ModProfile && ((ModProfile)o).id == this.modId)
            {
                if (this.onSuccess != null)
                {
                    this.onSuccess.Invoke((ModProfile)o);
                }
            }
            else
            {
                APIClient.GetMod(this.modId, this.onSuccess, this.onError);
            }
        }