Exemple #1
0
        public static void UploadModBinary_Unzipped(int modId,
                                                    EditableModfile modfileValues,
                                                    string unzippedBinaryLocation,
                                                    bool setPrimary,
                                                    Action <Modfile> onSuccess,
                                                    Action <WebRequestError> onError)
        {
            string binaryZipLocation = Application.temporaryCachePath + "/modio/" + System.IO.Path.GetFileNameWithoutExtension(unzippedBinaryLocation) + DateTime.Now.ToFileTime() + ".zip";
            bool   zipSucceeded      = false;

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

                using (var zip = new Ionic.Zip.ZipFile())
                {
                    zip.AddFile(unzippedBinaryLocation);
                    zip.Save(binaryZipLocation);
                }

                zipSucceeded = true;
            }
            catch (Exception e)
            {
                Debug.LogError("[mod.io] Unable to zip mod binary prior to uploading.\n\n"
                               + Utility.GenerateExceptionDebugString(e));

                WebRequestError error = new WebRequestError()
                {
                    message      = "Unable to zip mod binary prior to uploading",
                    url          = binaryZipLocation,
                    timeStamp    = ServerTimeStamp.Now,
                    responseCode = 0,
                };

                onError(error);
            }

            if (zipSucceeded)
            {
                UploadModBinary_Zipped(modId, modfileValues, binaryZipLocation, setPrimary, onSuccess, onError);
            }
        }
Exemple #2
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);
        }
        // ------[ INITIALIZATION ]------
        protected virtual void OnEnable()
        {
            buildProfile = new EditableModfile();
            buildProfile.version.value = "0.0.0";
            uploadSucceededMessage     = null;
            uploadFailedMessage        = null;

            string authToken = CacheClient.LoadAuthenticatedUserToken();

            if (!String.IsNullOrEmpty(authToken))
            {
                APIClient.userAuthorizationToken = authToken;

                ModManager.GetAuthenticatedUserProfile((userProfile) =>
                {
                    this.user = userProfile;
                    Repaint();
                },
                                                       null);
            }

            LoginWindow.userLoggedIn += OnUserLogin;
        }