public static void UploadAssets(Package package, string newGUID, string newRootPath, string newProjectpath, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress) { string path = string.Format("/package/{0}/unitypackage", package.versionId); AssetStoreClient.UploadLargeFile(path, filepath, new Dictionary <string, string> { { "root_guid", newGUID }, { "root_path", newRootPath }, { "project_path", newProjectpath } }, delegate(AssetStoreResponse resp) { if (resp.HttpStatusCode == -2) { callback("aborted"); return; } string errorMessage = null; JSONValue jSONValue; AssetStoreAPI.Parse(resp, out errorMessage, out jSONValue); callback(errorMessage); }, progress); }
public static void GetMetaData(AssetStorePublisher account, PackageDataSource packageDataSource, AssetStoreAPI.DoneCallback callback) { AssetStoreClient.CreatePendingGet("metadata", "/metadata/0", delegate(AssetStoreResponse res) { DebugUtils.Log(res.data); string errorMessage; JSONValue jval; bool flag = AssetStoreAPI.Parse(res, out errorMessage, out jval); if (flag && !jval.ContainsKey("error_fields")) { callback(errorMessage); return; } string str = "none"; try { str = "account"; string text = AssetStoreAPI.OnAssetStorePublisher(jval, account, packageDataSource); if (text != null) { callback(text); return; } } catch (JSONTypeException ex) { callback("Malformed metadata response from server: " + str + " - " + ex.Message); } catch (KeyNotFoundException ex2) { callback("Malformed metadata response from server. " + str + " - " + ex2.Message); } callback(null); }); }
public static void UploadBundle(string path, string filepath, AssetStoreAPI.UploadBundleCallback callback, AssetStoreClient.ProgressCallback progress) { AssetStoreClient.UploadLargeFile(path, filepath, null, delegate(AssetStoreResponse resp) { string errorMessage = null; JSONValue jSONValue; AssetStoreAPI.Parse(resp, out errorMessage, out jSONValue); callback(filepath, errorMessage); }, progress); }
public static void UploadBundle(string path, string filepath, AssetStoreAPI.UploadBundleCallback callback, AssetStoreClient.ProgressCallback progress) { AssetStoreClient.UploadLargeFile(path, filepath, null, (AssetStoreResponse resp) => { JSONValue jSONValue; string str = null; AssetStoreAPI.Parse(resp, out str, out jSONValue); callback(filepath, str); }, progress); }
private static void Upload(string path, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress = null) { AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingUpload(path, path, filepath, (AssetStoreResponse resp) => { JSONValue jSONValue; string str = null; AssetStoreAPI.Parse(resp, out str, out jSONValue); callback(str); }); pending.progressCallback = progress; }
private static void Upload(string path, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress = null) { AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingUpload(path, path, filepath, delegate(AssetStoreResponse resp) { string errorMessage = null; JSONValue jSONValue; AssetStoreAPI.Parse(resp, out errorMessage, out jSONValue); callback(errorMessage); }); pending.progressCallback = progress; }
private void UploadPackage() { DebugUtils.Log("UploadPackage"); this.m_AssetsState = AssetStorePackageController.AssetsState.UploadingPackage; if (string.IsNullOrEmpty(this.m_DraftAssetsPath)) { DebugUtils.LogError("No assets to upload has been selected"); this.m_AssetsState = AssetStorePackageController.AssetsState.None; return; } AssetStoreAPI.UploadAssets(this.m_Package, this.m_LocalRootGUID, this.m_LocalRootPath, this.m_LocalProjectPath, this.m_DraftAssetsPath, new AssetStoreAPI.DoneCallback(this.OnAssetsUploaded), new AssetStoreClient.ProgressCallback(this.OnAssetsUploading)); }
private static string OnAssetStorePublisher(JSONValue jval, AssetStorePublisher account, PackageDataSource packageDataSource) { string str; string str1 = "unknown field"; try { str1 = "publisher"; Dictionary <string, JSONValue> strs = jval["publisher"].AsDict(false); account.mStatus = AssetStorePublisher.Status.New; if (strs.ContainsKey("name")) { account.mStatus = AssetStorePublisher.Status.Existing; str1 = "publisher -> id"; JSONValue item = strs["id"]; account.publisherId = int.Parse(item.AsString(false)); str1 = "publisher -> name"; account.publisherName = strs["name"].AsString(false); } str1 = "publisher"; if (AssetStoreManager.sDbg) { JSONValue jSONValue = jval["publisher"]; DebugUtils.Log(string.Concat("publisher ", jSONValue.ToString(string.Empty, " "))); JSONValue item1 = jval["packages"]; DebugUtils.Log(string.Concat("packs ", item1.ToString(string.Empty, " "))); } str1 = "packages"; if (!jval.Get("packages").IsNull()) { AssetStoreAPI.OnPackages(jval["packages"], packageDataSource); } return(null); } catch (JSONTypeException jSONTypeException1) { JSONTypeException jSONTypeException = jSONTypeException1; str = string.Concat("Malformed response from server: ", str1, " - ", jSONTypeException.Message); } catch (KeyNotFoundException keyNotFoundException1) { KeyNotFoundException keyNotFoundException = keyNotFoundException1; str = string.Concat("Malformed response from server. ", str1, " - ", keyNotFoundException.Message); } return(str); }
public void UploadAllAssetBundles() { this.m_PendingUploadsAssetPath = this.m_AssetBundleFiles.Keys.ToList <string>(); this.m_MainAssetsProgress = new List <double>(this.m_MainAssets.Count); this.m_ErrorMessages = null; this.m_ProgressDirty = false; this.m_CachedProgressValue = 0; foreach (string mPendingUploadsAssetPath in this.m_PendingUploadsAssetPath) { string item = this.m_AssetBundleFiles[mPendingUploadsAssetPath]; string uploadBundlePath = AssetStoreAPI.GetUploadBundlePath(this.m_AssetStorePackageController.SelectedPackage, mPendingUploadsAssetPath); AssetStoreAPI.UploadBundle(uploadBundlePath, item, new AssetStoreAPI.UploadBundleCallback(this.OnFinishUploadBundle), this.OnBundleProgress(mPendingUploadsAssetPath)); this.m_MainAssetsProgress.Add(0); } }
private void RefreshPackages() { this.Account.mStatus = AssetStorePublisher.Status.Loading; AssetStoreAPI.GetMetaData(this.Account, this.m_PackageDataSource, (string errMessage) => { if (errMessage == null) { this.m_PackageController.AutoSetSelected(this); this.Repaint(); return; } Debug.LogError(string.Concat("Error fetching metadata: ", errMessage)); LoginWindow.Logout(); AssetStoreManager.Login("To upload packages, please log in to your Asset Store Publisher account."); this.Repaint(); }); }
private static void OnPackages(JSONValue jv, PackageDataSource packageDataSource) { IList <Package> allPackages = packageDataSource.GetAllPackages(); Dictionary <string, JSONValue> strs = jv.AsDict(false); string empty = string.Empty; allPackages.Clear(); foreach (KeyValuePair <string, JSONValue> keyValuePair in strs) { int num = int.Parse(keyValuePair.Key); JSONValue value = keyValuePair.Value; Package package = packageDataSource.FindByID(num) ?? new Package(num); empty = string.Concat(empty, AssetStoreAPI.OnPackageReceived(value, package)); empty = string.Concat(empty, AssetStoreAPI.RefreshMainAssets(value, package)); allPackages.Add(package); } packageDataSource.OnDataReceived(empty); }
private static string OnAssetStorePublisher(JSONValue jval, AssetStorePublisher account, PackageDataSource packageDataSource) { string str = "unknown field"; try { str = "publisher"; Dictionary <string, JSONValue> dictionary = jval["publisher"].AsDict(false); account.mStatus = AssetStorePublisher.Status.New; if (dictionary.ContainsKey("name")) { account.mStatus = AssetStorePublisher.Status.Existing; str = "publisher -> id"; account.publisherId = int.Parse(dictionary["id"].AsString(false)); str = "publisher -> name"; account.publisherName = dictionary["name"].AsString(false); } str = "publisher"; if (AssetStoreManager.sDbg) { DebugUtils.Log("publisher " + jval["publisher"].ToString(string.Empty, " ")); DebugUtils.Log("packs " + jval["packages"].ToString(string.Empty, " ")); } str = "packages"; if (!jval.Get("packages").IsNull()) { AssetStoreAPI.OnPackages(jval["packages"], packageDataSource); } } catch (JSONTypeException ex) { string result = "Malformed response from server: " + str + " - " + ex.Message; return(result); } catch (KeyNotFoundException ex2) { string result = "Malformed response from server. " + str + " - " + ex2.Message; return(result); } return(null); }
private static void OnPackages(JSONValue jv, PackageDataSource packageDataSource) { IList <Package> allPackages = packageDataSource.GetAllPackages(); Dictionary <string, JSONValue> dictionary = jv.AsDict(false); string text = string.Empty; foreach (KeyValuePair <string, JSONValue> current in dictionary) { int num = int.Parse(current.Key); JSONValue value = current.Value; Package package = packageDataSource.FindByID(num); if (package == null) { package = new Package(num); } text += AssetStoreAPI.OnPackageReceived(value, package); text += AssetStoreAPI.RefreshMainAssets(value, package); allPackages.Add(package); } packageDataSource.OnDataReceived(text); }
private void RenderDebug() { if (AssetStoreManager.sDbgButtons) { GUILayout.FlexibleSpace(); GUILayout.Label("Debug: ", AssetStoreManager.Styles.ToolbarLabel, new GUILayoutOption[0]); if (GUILayout.Button("FileSelector", EditorStyles.toolbarButton, new GUILayoutOption[0])) { FileSelector.Show("/", new List <string>(), delegate(List <string> newList) { foreach (string current in newList) { DebugUtils.Log(current); } }); } if (GUILayout.Button("Reload", EditorStyles.toolbarButton, new GUILayoutOption[0])) { AssetStoreAPI.GetMetaData(this.Account, this.m_PackageDataSource, delegate(string errMessage) { if (errMessage != null) { Debug.LogError("Error fetching metadata: " + errMessage); LoginWindow.Logout(); AssetStoreManager.Login("Login to fetch current list of published packages"); base.Repaint(); return; } this.m_PackageController.AutoSetSelected(this); base.Repaint(); }); } if (GUILayout.Button("Logout", EditorStyles.toolbarButton, new GUILayoutOption[0])) { AssetStoreClient.Logout(); } } }
public static void UploadAssets(Package package, string newGUID, string newRootPath, string newProjectpath, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress) { string str1 = string.Format("/package/{0}/unitypackage", package.versionId); Dictionary <string, string> strs = new Dictionary <string, string>() { { "root_guid", newGUID }, { "root_path", newRootPath }, { "project_path", newProjectpath } }; AssetStoreClient.UploadLargeFile(str1, filepath, strs, (AssetStoreResponse resp) => { JSONValue jSONValue; if (resp.HttpStatusCode == -2) { callback("aborted"); return; } string str = null; AssetStoreAPI.Parse(resp, out str, out jSONValue); callback(str); }, progress); }
public static void GetMetaData(AssetStorePublisher account, PackageDataSource packageDataSource, AssetStoreAPI.DoneCallback callback) { AssetStoreClient.CreatePendingGet("metadata", "/metadata/0", (AssetStoreResponse res) => { string str; JSONValue jSONValue; DebugUtils.Log(res.data); if (AssetStoreAPI.Parse(res, out str, out jSONValue) && !jSONValue.ContainsKey("error_fields")) { callback(str); return; } string str1 = "none"; try { str1 = "account"; string str2 = AssetStoreAPI.OnAssetStorePublisher(jSONValue, account, packageDataSource); if (str2 != null) { callback(str2); return; } } catch (JSONTypeException jSONTypeException) { callback(string.Concat("Malformed metadata response from server: ", str1, " - ", jSONTypeException.Message)); } catch (KeyNotFoundException keyNotFoundException) { callback(string.Concat("Malformed metadata response from server. ", str1, " - ", keyNotFoundException.Message)); } callback(null); }); }
static AssetStoreAPI() { s_Instance = new AssetStoreAPI(); }
private void RenderMenu() { GUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]); GUILayout.FlexibleSpace(); this.RenderToolbar(); GUILayout.EndHorizontal(); bool flag = false; if (LoginWindow.IsLoggedIn) { if (this.Account.mStatus == AssetStorePublisher.Status.NotLoaded) { this.Account.mStatus = AssetStorePublisher.Status.Loading; AssetStoreAPI.GetMetaData(this.Account, this.m_PackageDataSource, (string errMessage) => { if (errMessage == null) { this.m_PackageController.AutoSetSelected(this); this.Repaint(); return; } Debug.LogError(string.Concat("Error fetching metadata: ", errMessage)); LoginWindow.Logout(); AssetStoreManager.Login("To upload packages, please log in to your Asset Store Publisher account.", "Account is not registered as a Publisher. \nPlease create a Publisher ID."); this.Repaint(); }); } if (this.Account.mStatus == AssetStorePublisher.Status.NotLoaded || this.Account.mStatus == AssetStorePublisher.Status.Loading) { GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.Space(10f); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.Label(GUIUtil.StatusWheel, new GUILayoutOption[0]); GUILayout.Label("Fetching account information", new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); this.Repaint(); } else { bool flag1 = GUI.enabled; if (this.Account.mStatus != AssetStorePublisher.Status.Existing) { GUI.enabled = false; } GUI.enabled = flag1; flag = true; } } else { if (!LoginWindow.IsVisible) { LoginWindow.Login("To upload packages, please log in to your Asset Store Publisher account.", new LoginWindow.LoginCallback(AssetStoreManager.OnLoggedIn), GUIUtil.RectOnRect(360f, 180f, base.position)); } GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.Space(10f); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.Label(GUIUtil.StatusWheel, new GUILayoutOption[0]); GUILayout.Label("Please login", new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } if (!flag && this.m_PackageController.SelectedPackage != null) { this.m_PackageController.SelectedPackage = null; } }
private void RenderMenu() { GUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]); GUILayout.FlexibleSpace(); this.RenderDebug(); GUILayout.EndHorizontal(); bool flag = false; if (!LoginWindow.IsLoggedIn) { if (!LoginWindow.IsVisible) { LoginWindow.Login("Please re-login to asset store in order to fetch publisher details", new LoginWindow.LoginCallback(AssetStoreManager.OnLoggedIn), GUIUtil.RectOnRect(360f, 140f, base.position)); } GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.Space(10f); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.Label(GUIUtil.StatusWheel, new GUILayoutOption[0]); GUILayout.Label("Please login", new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } else { if (this.Account.mStatus == AssetStorePublisher.Status.NotLoaded) { this.Account.mStatus = AssetStorePublisher.Status.Loading; AssetStoreAPI.GetMetaData(this.Account, this.m_PackageDataSource, delegate(string errMessage) { if (errMessage != null) { Debug.LogError("Error fetching metadata: " + errMessage); LoginWindow.Logout(); AssetStoreManager.Login("Login to fetch current list of published packages"); base.Repaint(); return; } this.m_PackageController.AutoSetSelected(this); base.Repaint(); }); } if (this.Account.mStatus == AssetStorePublisher.Status.NotLoaded || this.Account.mStatus == AssetStorePublisher.Status.Loading) { GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.Space(10f); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.Label(GUIUtil.StatusWheel, new GUILayoutOption[0]); GUILayout.Label("Fetching account information", new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); base.Repaint(); } else { bool enabled = GUI.enabled; if (this.Account.mStatus != AssetStorePublisher.Status.Existing) { GUI.enabled = false; } GUI.enabled = enabled; flag = true; } } if (!flag && this.m_PackageController.SelectedPackage != null) { this.m_PackageController.SelectedPackage = null; } }
/// <inheritdoc /> protected override void OnPostExecute() { _assetStoreApi.Logout(); _assetStoreApi = null; }
/// <inheritdoc /> protected override void OnInterrupt() { _assetStoreApi.Logout(); _assetStoreApi = null; }
/// <summary> /// Upload a package, using the specified options. /// </summary> /// <param name="username">The username credentials to use for package uploading.</param> /// <param name="password">The password credentials to use for package uploading.</param> /// <param name="packageName">The package name. The package must be set to draft status in the Publisher Administration.</param> /// <param name="rootPath">The root path of the package (relative to Application.dataPath). If null, use the project Assets folder.</param> /// <param name="mainAssets">An array of the main assets for the package (relative to Application.dataPath). If null, do not upload or change any main assets.</param> /// <param name="loginTimeout">The maximum amount of time to wait (in seconds) when logging in. Defaults to 90 seconds. Must be within 2 and 36000 seconds. Login is attempted twice.</param> /// <param name="metadataTimeout">The maximum amount of time to wait (in seconds) when getting metadata. Defaults to 600 seconds. Must be within 2 and 36000 seconds.</param> /// <param name="uploadTimeout">The maximum amount of time to wait (in seconds) when uploading. Defaults to 36000 seconds. Must be within 2 and 36000 seconds.</param> public static void UploadAssetStorePackage(string username, string password, string packageName, string rootPath = null, string[] mainAssets = null, int loginTimeout = 90, int metadataTimeout = 600, int uploadTimeout = 36000, bool skipProjectSettings = false, bool actuallyUpload = false, string outputPath = "") { if (string.IsNullOrEmpty(username)) { throw new ArgumentNullException("username"); } if (string.IsNullOrEmpty(password)) { throw new ArgumentNullException("password"); } if (string.IsNullOrEmpty(packageName)) { throw new ArgumentNullException("packageName"); } s_Username = username; s_Password = password; s_PackageName = packageName; s_RootPath = rootPath; s_MainAssets = mainAssets; s_LoginTimeout = Mathf.Clamp(loginTimeout, 2, 36000); s_MetadataTimeout = Mathf.Clamp(metadataTimeout, 2, 36000); s_UploadTimeout = Mathf.Clamp(uploadTimeout, 2, 36000); s_SkipProjectSettings = skipProjectSettings; Finish(); #if !UNITY_5_5_OR_NEWER if (Application.webSecurityEnabled) { Debug.Log("[Asset Store Batch Mode] Switching from Web Player platform..."); EditorUserBuildSettings.SwitchActiveBuildTarget(EditorUserBuildSettings.selectedStandaloneTarget); } #endif Debug.Log("[Asset Store Batch Mode] Logging into the Asset Store..."); AssetStoreClient.LoginWithCredentials(s_Username, s_Password, false, OnLogin); if (!WaitForUpdate(ref s_LoginDone, s_LoginTimeout)) { Finish(); // Try again s_LoginDone = false; AssetStoreClient.LoginWithCredentials(s_Username, s_Password, false, OnLogin); if (!WaitForUpdate(ref s_LoginDone, s_LoginTimeout)) { Finish(); return; } } AssetStoreAPI.GetMetaData(s_PublisherAccount, s_PackageDataSource, OnGetMetadata); Debug.Log("[Asset Store Batch Mode] Getting package metadata..."); if (!WaitForUpdate(ref s_GetMetadataDone, s_MetadataTimeout)) { Finish(); return; } var packages = s_PackageDataSource.GetAllPackages(); var package = packages.FirstOrDefault(p => p.Name == s_PackageName && p.Status == Package.PublishedStatus.Draft); if (package == null) { Debug.LogError("[Asset Store Batch Mode] Draft package: " + s_PackageName + " not found!"); Finish(); return; } // Validate root project folder var projectFolder = Path.Combine(Application.dataPath, s_RootPath ?? string.Empty); // Convert to unix path style projectFolder = projectFolder.Replace("\\", "/"); if (!IsValidProjectFolder(projectFolder)) { Debug.LogError("[Asset Store Batch Mode] Project folder is invalid"); Finish(); return; } // Set root asset path var localRootPath = SetRootPath(package, projectFolder); // Set main assets if (MainAssetsUtil.CanGenerateBundles) { // TODO: Set main assets } // Verify content var checkContent = CheckContent(package, localRootPath); if (!string.IsNullOrEmpty(checkContent)) { Debug.LogError("[Asset Store Batch Mode] " + checkContent); Finish(); return; } var draftAssetsPath = GetDraftAssetsPath(localRootPath); Export(package, localRootPath, draftAssetsPath, outputPath); if (actuallyUpload) { // Upload assets AssetStoreAPI.UploadAssets( package, AssetStorePackageController.GetLocalRootGUID(package), localRootPath, Application.dataPath, draftAssetsPath, OnAssetsUploaded, null); Debug.Log("[Asset Store Batch Mode] Uploading asset..."); if (!WaitForUpdate(ref s_AssetsUploadedDone, s_UploadTimeout)) { Finish(); return; } if (MainAssetsUtil.CanGenerateBundles) { // TODO: Upload main assets } Debug.Log("[Asset Store Batch Mode] Asset successfully uploaded"); } Finish(); }
/// <inheritdoc /> protected override IEnumerator OnExecute(JobContext context) { AssetDirectoryPath = PathHelpers.FixSlashes(AssetDirectoryPath); _assetStoreApi = new AssetStoreAPI(); yield return(null); _assetStoreApi.Login(Username, Password); while (_assetStoreApi.IsLogging()) { yield return(null); } IsSuccess = _assetStoreApi.IsConnected; if (!IsSuccess) { RockLog.WriteLine(this, LogTier.Error, _assetStoreApi.LastError); yield break; } _assetStoreApi.FetchPackages(); while (_assetStoreApi.IsFetchingPackages()) { yield return(null); } IsSuccess = _assetStoreApi.HasPackages; if (!IsSuccess) { RockLog.WriteLine(this, LogTier.Error, _assetStoreApi.LastError); yield break; } // fetch required package var package = _assetStoreApi.EachPackage.FirstOrDefault(x => x.packageId == PackageId); if (package == null) { RockLog.WriteLine(this, LogTier.Error, string.Format("Package of id \"{0}\" not found.", PackageId)); IsSuccess = false; yield break; } yield return(null); var packageFilePath = GeneratePackage(); yield return(null); HttpWebResponse uploadWebResponse = null; var rootPath = AssetDirectoryPath; if (!rootPath.StartsWith("/")) { rootPath = '/' + AssetDirectoryPath; } // upload package to the asset store dashboard _assetStoreApi.Upload( package.id, packageFilePath, rootPath, Application.dataPath, Application.unityVersion, (response, s) => { uploadWebResponse = response; } ); while (uploadWebResponse == null) { yield return(null); } IsSuccess = uploadWebResponse.StatusCode == HttpStatusCode.OK; }