Esempio n. 1
0
 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);
     });
 }
Esempio n. 2
0
    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);
    }
Esempio n. 3
0
    internal static void LoginWithRememberedSession(AssetStoreClient.DoneLoginCallback callback)
    {
        if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
        {
            DebugUtils.LogWarning("Tried to login with remembered session while already in progress of logging in");
            return;
        }
        AssetStoreClient.sLoginState        = AssetStoreClient.LoginState.IN_PROGRESS;
        AssetStoreClient.sLoginErrorMessage = null;
        if (!AssetStoreClient.RememberSession)
        {
            AssetStoreClient.SavedSessionID = string.Empty;
        }
        Uri uri = new Uri(string.Format("{0}/login?reuse_session={1}&unityversion={2}&toolversion={3}&xunitysession={4}", new object[] { AssetStoreClient.AssetStoreUrl, AssetStoreClient.SavedSessionID, Uri.EscapeDataString(Application.unityVersion), Uri.EscapeDataString("V5.0.0"), "26c4202eb475d02864b40827dfff11a14657aa41" }));
        AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient();

        AssetStoreClient.Pending pending = new AssetStoreClient.Pending()
        {
            conn     = assetStoreWebClient,
            id       = "login",
            callback = AssetStoreClient.WrapLoginCallback(callback)
        };
        AssetStoreClient.pending.Add(pending);
        assetStoreWebClient.Headers.Add("Accept", "application/json");
        assetStoreWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AssetStoreClient.DownloadStringCallback);
        try
        {
            assetStoreWebClient.DownloadStringAsync(uri, pending);
        }
        catch (WebException webException)
        {
            pending.ex = webException;
            AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR;
        }
    }
Esempio n. 4
0
 public static AssetStoreClient.Pending CreatePendingUpload(string name, string path, string filepath, AssetStoreClient.DoneCallback callback)
 {
     DebugUtils.Log("CreatePendingUpload");
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = () =>
     {
         bool flag;
         pending.conn = AssetStoreClient.AcquireClient();
         if (pending.conn == null)
         {
             return(false);
         }
         try
         {
             pending.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             pending.conn.UploadProgressChanged += new UploadProgressChangedEventHandler(AssetStoreClient.UploadProgressCallback);
             pending.conn.UploadFileCompleted   += new UploadFileCompletedEventHandler(AssetStoreClient.UploadFileCallback);
             pending.conn.UploadFileAsync(AssetStoreClient.APIUri(path), "PUT", filepath, pending);
             return(true);
         }
         catch (WebException webException)
         {
             pending.ex = webException;
             flag       = false;
         }
         return(flag);
     };
     if (!pendingQueueDelegate())
     {
         pending.queueDelegate = pendingQueueDelegate;
     }
     return(pending);
 }
Esempio n. 5
0
    private static Uri APIUri(string path, IDictionary <string, string> extraQuery)
    {
        Dictionary <string, string> strs;

        strs = (extraQuery == null ? new Dictionary <string, string>() : new Dictionary <string, string>(extraQuery));
        strs.Add("unityversion", Application.unityVersion);
        strs.Add("toolversion", "V5.0.0");
        strs.Add("xunitysession", AssetStoreClient.ActiveOrUnauthSessionID);
        UriBuilder    uriBuilder    = new UriBuilder(AssetStoreClient.GetProperPath(path));
        StringBuilder stringBuilder = new StringBuilder();

        foreach (KeyValuePair <string, string> keyValuePair in strs)
        {
            string key = keyValuePair.Key;
            string str = Uri.EscapeDataString(keyValuePair.Value);
            stringBuilder.AppendFormat("&{0}={1}", key, str);
        }
        if (string.IsNullOrEmpty(uriBuilder.Query))
        {
            uriBuilder.Query = stringBuilder.Remove(0, 1).ToString();
        }
        else
        {
            uriBuilder.Query = string.Concat(uriBuilder.Query.Substring(1), stringBuilder);
        }
        DebugUtils.Log(string.Concat("preparing: ", uriBuilder.Uri));
        return(uriBuilder.Uri);
    }
Esempio n. 6
0
    private void RenderToolbar()
    {
        GUILayout.FlexibleSpace();
        bool flag = GUI.enabled;

        GUI.enabled = !this.m_PackageController.IsUploading;
        if (GUILayout.Button("Refresh Packages", EditorStyles.toolbarButton, new GUILayoutOption[0]))
        {
            this.RefreshPackages();
        }
        if (AssetStoreManager.sDbgButtons)
        {
            GUILayout.Label("Debug: ", AssetStoreManager.Styles.ToolbarLabel, new GUILayoutOption[0]);
            if (GUILayout.Button("FileSelector", EditorStyles.toolbarButton, new GUILayoutOption[0]))
            {
                FileSelector.Show("/", new List <string>(), (List <string> newList) => {
                    foreach (string str in newList)
                    {
                        DebugUtils.Log(str);
                    }
                });
            }
            if (GUILayout.Button("Logout", EditorStyles.toolbarButton, new GUILayoutOption[0]))
            {
                AssetStoreClient.Logout();
            }
        }
        GUI.enabled = flag;
    }
    public static void Login(string loginReason, LoginWindow.LoginCallback callback, Rect windowRect)
    {
        if (AssetStoreClient.HasActiveSessionID)
        {
            AssetStoreClient.Logout();
        }

        if (AssetStoreClient.RememberSession && AssetStoreClient.HasSavedSessionID)
        {
            AssetStoreClient.LoginWithRememberedSession((string errorMessage) =>
            {
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    LoginWindow.ShowLoginWindow(loginReason, callback, windowRect);
                }
                else
                {
                    callback(errorMessage);
                }
            });
            return;
        }

        LoginWindow.ShowLoginWindow(loginReason, callback, windowRect);
    }
Esempio n. 8
0
    public static void UploadAssets(Package package, string localRootGuid, string localRootPath, string projectPath, string draftAssetsPath, DoneCallback callback, AssetStoreClient.ProgressCallback progressCallback)
    {
        Type doneCallbackType, clientProgressCallbackType;
        var  doneCallback           = CreateCallbackDelegate("DoneCallback", callback, out doneCallbackType);
        var  clientProgressCallback = AssetStoreClient.CreateCallbackDelegate("ProgressCallback", progressCallback, out clientProgressCallbackType);

        s_Instance.GetRuntimeType().Invoke("UploadAssets", package.GetRuntimeObject().Param(), localRootGuid.Param(), localRootPath.Param(), projectPath.Param(), draftAssetsPath.Param(), new Parameter(doneCallback, doneCallbackType), new Parameter(clientProgressCallback, clientProgressCallbackType));
    }
Esempio n. 9
0
    private static void AssetStoreLogout()
    {
        DebugUtils.Log("Logged out of Asset Store");
        AssetStoreManager assetStoreManager = (AssetStoreManager)EditorWindow.GetWindow(typeof(AssetStoreManager), false, "Package Upload");

        assetStoreManager.Close();
        AssetStoreClient.Logout();
    }
Esempio n. 10
0
    // -----------------------------------------------
    // Helper functions
    // -----------------------------------------------

    static void Finish()
    {
        AssetStoreClient.Logout();
        s_LoginDone          = false;
        s_GetMetadataDone    = false;
        s_AssetsUploadedDone = false;
        AssetStoreClient.Update();
    }
Esempio n. 11
0
 private static void AssetStoreLogout()
 {
     if (EditorUtility.DisplayDialog("Logout Confirmation", "Are you sure you want to log out of Asset Store Tools?", "Confirm", "Cancel"))
     {
         DebugUtils.Log("Logged out of Asset Store");
         ((AssetStoreManager)EditorWindow.GetWindow(typeof(AssetStoreManager), false, "Package Upload")).Close();
         AssetStoreClient.Logout();
     }
 }
Esempio n. 12
0
    public static ImageCache DownloadImage(Image img, ImageCache.DownloadCallback callback)
    {
        if (img == null || img.mUrl == null)
        {
            return(null);
        }
        ImageCache ic;

        if (ImageCache.EntriesByUrl.TryGetValue(img.mUrl, out ic))
        {
            if (ic.Texture != null || ic.Progress >= 0f || ic.Failed)
            {
                img.mImgCache = ic;
                return(ic);
            }
        }
        else
        {
            ImageCache.EnsureCacheSpace();
            ic                = new ImageCache();
            ic.Failed         = false;
            ic.Texture        = null;
            ic.m_DownloadedAt = -1.0;
            ic.LastUsed       = EditorApplication.timeSinceStartup;
            ImageCache.EntriesByUrl[img.mUrl] = ic;
        }
        img.mImgCache = ic;
        ic.Progress   = 0f;
        AssetStoreClient.ProgressCallback progress = delegate(double pctUp, double pctDown)
        {
            ic.Progress = (float)pctDown;
        };
        AssetStoreClient.DoneCallback callback2 = delegate(AssetStoreResponse resp)
        {
            ic.Progress       = -1f;
            ic.LastUsed       = EditorApplication.timeSinceStartup;
            ic.m_DownloadedAt = ic.LastUsed;
            ic.Failed         = resp.failed;
            if (resp.ok && resp.binData != null && resp.binData.Length > 0)
            {
                Texture2D texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texture2D.LoadImage(resp.binData);
                ic.Texture = texture2D;
            }
            if (callback != null)
            {
                string text = string.Format("Error fetching {0}", img.Name);
                if (resp.failed)
                {
                    DebugUtils.LogWarning(text + string.Format(" : ({0}) {1} from {2}", resp.HttpStatusCode, resp.HttpErrorMessage ?? "n/a", img.mUrl));
                }
                callback(img, ic, (!resp.ok) ? text : null);
            }
        };
        AssetStoreClient.LoadFromUrl(img.mUrl, callback2, progress);
        return(ic);
    }
Esempio n. 13
0
    public static ImageCache DownloadImage(Image img, ImageCache.DownloadCallback callback)
    {
        ImageCache imageCache;

        if (img == null || img.mUrl == null)
        {
            return(null);
        }

        if (!ImageCache.EntriesByUrl.TryGetValue(img.mUrl, out imageCache))
        {
            ImageCache.EnsureCacheSpace();
            imageCache = new ImageCache()
            {
                Failed         = false,
                Texture        = null,
                m_DownloadedAt = -1,
                LastUsed       = EditorApplication.timeSinceStartup
            };
            ImageCache.EntriesByUrl[img.mUrl] = imageCache;
        }
        else if (imageCache.Texture != null || imageCache.Progress >= 0f || imageCache.Failed)
        {
            img.mImgCache = imageCache;
            return(imageCache);
        }

        img.mImgCache       = imageCache;
        imageCache.Progress = 0f;
        AssetStoreClient.ProgressCallback progress     = (double pctUp, double pctDown) => imageCache.Progress = (float)pctDown;
        AssetStoreClient.DoneCallback     doneCallback = (AssetStoreResponse resp) =>
        {
            imageCache.Progress       = -1f;
            imageCache.LastUsed       = EditorApplication.timeSinceStartup;
            imageCache.m_DownloadedAt = imageCache.LastUsed;
            imageCache.Failed         = resp.failed;
            if (resp.ok && resp.binData != null && (int)resp.binData.Length > 0)
            {
                Texture2D texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texture2D.LoadImage(resp.binData);
                imageCache.Texture = texture2D;
            }

            if (callback != null)
            {
                string str = string.Format("Error fetching {0}", img.Name);
                if (resp.failed)
                {
                    DebugUtils.LogWarning(string.Concat(str, string.Format(" : ({0}) {1} from {2}", resp.HttpStatusCode, resp.HttpErrorMessage ?? "n/a", img.mUrl)));
                }

                callback(img, imageCache, (!resp.ok ? str : null));
            }
        };
        AssetStoreClient.LoadFromUrl(img.mUrl, doneCallback, progress);
        return(imageCache);
    }
Esempio n. 14
0
 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);
 }
Esempio n. 15
0
 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);
 }
Esempio n. 16
0
 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;
 }
Esempio n. 17
0
 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;
 }
 public void OnClickUpload()
 {
     if (this.m_AssetsState != AssetStorePackageController.AssetsState.UploadingPackage)
     {
         this.Upload();
         GUIUtility.ExitGUI();
     }
     else
     {
         AssetStoreClient.AbortLargeFilesUpload();
         this.m_AssetsState = AssetStorePackageController.AssetsState.None;
     }
 }
    private void Login()
    {
        this.m_LoginRemoteMessage = null;
        if (AssetStoreClient.HasActiveSessionID)
        {
            AssetStoreClient.Logout();
        }

        if (string.IsNullOrEmpty(this.m_Email))
        {
            this.m_LoginRemoteMessage = "Please enter your email address.";
            this.Repaint();
            return;
        }

        if (!this.IsValidEmail(this.m_Email))
        {
            this.m_LoginRemoteMessage = "Invalid email address.";
            this.Repaint();
            return;
        }

        if (string.IsNullOrEmpty(this.m_Password))
        {
            this.m_LoginRemoteMessage = "Please enter your password.";
            this.Repaint();
            return;
        }

        AssetStoreClient.LoginWithCredentials(this.m_Email, this.m_Password, AssetStoreClient.RememberSession, (string errorMessage) =>
        {
            this.m_LoginRemoteMessage = errorMessage;
            if (errorMessage != null)
            {
                this.Repaint();
            }
            else
            {
                if (this.m_LoginCallback != null)
                {
                    this.m_LoginCallback(this.m_LoginRemoteMessage);
                }

                base.Close();
            }
        });
    }
 private void RenderAssetsFolderStatus()
 {
     if (this.m_AssetsState == AssetStorePackageController.AssetsState.UploadingPackage)
     {
         int    num = (int)Mathf.Ceil(this.m_DraftAssetsUploadProgress * 100f);
         string str = num.ToString();
         if (AssetStorePackageController.CancelableProgressBar(this.m_DraftAssetsUploadProgress, string.Concat("Uploading ", str, " %"), "Cancel"))
         {
             this.m_DraftAssetsUploadProgress = 0f;
             this.m_AssetsState     = AssetStorePackageController.AssetsState.None;
             this.m_DraftAssetsPath = string.Empty;
             this.m_DraftAssetsSize = (long)0;
             AssetStoreClient.AbortLargeFilesUpload();
         }
     }
     else if (this.m_AssetsState != AssetStorePackageController.AssetsState.BuildingPackage)
     {
         Color  color = GUI.color;
         string str1  = "No assets selected";
         if (this.m_LocalRootPath != null)
         {
             if (!this.IsValidRelativeProjectFolder(this.m_LocalRootPath))
             {
                 GUI.color = GUIUtil.ErrorColor;
                 str1      = string.Format("The path \"{0}\" is not valid within this Project", this.m_LocalRootPath);
             }
             else if (!this.m_LocalRootPath.StartsWith("/AssetStoreTools"))
             {
                 str1 = string.Concat(" ", this.m_LocalRootPath);
             }
             else
             {
                 GUI.color = GUIUtil.ErrorColor;
                 str1      = string.Format("The selected path cannot be part of \"/AssetStoreTools\" folder", this.m_LocalRootPath);
             }
         }
         GUILayout.Label(str1, new GUILayoutOption[0]);
         GUI.color = color;
         GUILayout.FlexibleSpace();
     }
     else
     {
         GUILayout.Label(GUIUtil.StatusWheel, new GUILayoutOption[0]);
         GUILayout.Label("Please wait - building package", new GUILayoutOption[0]);
         GUILayout.FlexibleSpace();
     }
 }
Esempio n. 21
0
    static bool WaitForUpdate(ref bool isDone, int timeout)
    {
        s_Stopwatch.Reset();
        s_Stopwatch.Start();

        do
        {
            AssetStoreClient.Update();
            Thread.Sleep(10);
            if (!isDone && s_Stopwatch.Elapsed.TotalSeconds > timeout)
            {
                throw new TimeoutException("Asset Store batch mode operation timed out.");
            }
        } while (!isDone);

        return(isDone);
    }
Esempio n. 22
0
 private void Login()
 {
     this.m_LoginRemoteMessage = null;
     if (AssetStoreClient.HasActiveSessionID)
     {
         AssetStoreClient.Logout();
     }
     AssetStoreClient.LoginWithCredentials(this.m_Username, this.m_Password, AssetStoreClient.RememberSession, delegate(string errorMessage)
     {
         this.m_LoginRemoteMessage = errorMessage;
         if (errorMessage == null)
         {
             base.Close();
         }
         else
         {
             base.Repaint();
         }
     });
 }