private void RenderUpload()
        {
            GUILayout.Label("4. Upload package", new GUILayoutOption[0]);
            bool enabled = GUI.enabled;

            if (string.IsNullOrEmpty(this.m_Package.Name) || string.IsNullOrEmpty(this.m_Package.VersionName) || this.m_AssetsState != AssetStorePackageController.AssetsState.None || string.IsNullOrEmpty(this.m_LocalRootPath) || !this.IsValidRelativeProjectFolder(this.m_LocalRootPath) || this.m_Package.Status != Package.PublishedStatus.Draft)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button((this.m_AssetsState != AssetStorePackageController.AssetsState.UploadingPackage) ? "Upload" : "Stop", new GUILayoutOption[]
            {
                GUILayout.Width(90f)
            }))
            {
                if (this.m_AssetsState == AssetStorePackageController.AssetsState.UploadingPackage)
                {
                    AssetStoreClient.AbortLargeFilesUpload();
                    this.m_AssetsState = AssetStorePackageController.AssetsState.None;
                }
                else
                {
                    this.Upload();
                    GUIUtility.ExitGUI();
                }
            }
            GUI.enabled = enabled;
        }
 public static AssetStoreClient.Pending CreatePendingGetBinary(string name, string url, AssetStoreClient.DoneCallback callback)
 {
     AssetStoreClient.Pending p = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = delegate()
     {
         p.conn = AssetStoreClient.AcquireClient();
         if (p.conn == null)
         {
             return(false);
         }
         try
         {
             p.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             p.conn.DownloadProgressChanged += AssetStoreClient.DownloadProgressCallback;
             p.conn.DownloadDataCompleted   += AssetStoreClient.DownloadDataCallback;
             p.conn.DownloadDataAsync(new Uri(url), p);
         }
         catch (WebException ex)
         {
             p.ex = ex;
             return(false);
         }
         return(true);
     };
     if (!pendingQueueDelegate())
     {
         p.queueDelegate = pendingQueueDelegate;
     }
     return(p);
 }
 public static AssetStoreClient.Pending CreatePendingUpload(string name, string path, string filepath, AssetStoreClient.DoneCallback callback)
 {
     DebugUtils.Log("CreatePendingUpload");
     AssetStoreClient.Pending p = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = delegate()
     {
         p.conn = AssetStoreClient.AcquireClient();
         if (p.conn == null)
         {
             return(false);
         }
         try
         {
             p.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             p.conn.UploadProgressChanged += AssetStoreClient.UploadProgressCallback;
             p.conn.UploadFileCompleted   += AssetStoreClient.UploadFileCallback;
             p.conn.UploadFileAsync(AssetStoreClient.APIUri(path), "PUT", filepath, p);
         }
         catch (WebException ex)
         {
             p.ex = ex;
             return(false);
         }
         return(true);
     };
     if (!pendingQueueDelegate())
     {
         p.queueDelegate = pendingQueueDelegate;
     }
     return(p);
 }
        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 void Open()
 {
     try
     {
         this.RequestFileStream = new FileStream(this.FilePath, FileMode.Open, FileAccess.Read);
         this.Request           = (HttpWebRequest)WebRequest.Create(AssetStoreClient.APIUri(this.URI, this.m_extraParams));
         this.Request.AllowWriteStreamBuffering = false;
         this.Request.Timeout = 36000000;
         this.Request.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
         this.Request.KeepAlive     = false;
         this.Request.ContentLength = this.RequestFileStream.Length;
         this.Request.Method        = "PUT";
         this.BytesToSend           = this.RequestFileStream.Length;
         this.BytesSent             = 0L;
         this.RequestStream         = this.Request.GetRequestStream();
         if (this.Buffer == null)
         {
             this.Buffer = new byte[32768];
         }
     }
     catch (Exception ex)
     {
         AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(null, null, ex, null);
         this.RequestDoneCallback(job);
         this.Close();
         throw ex;
     }
 }
        private static Uri APIUri(string path, IDictionary <string, string> extraQuery)
        {
            Dictionary <string, string> dictionary;

            if (extraQuery != null)
            {
                dictionary = new Dictionary <string, string>(extraQuery);
            }
            else
            {
                dictionary = new Dictionary <string, string>();
            }
            dictionary.Add("unityversion", Application.unityVersion);
            dictionary.Add("toolversion", "V4.1.0");
            dictionary.Add("xunitysession", AssetStoreClient.ActiveOrUnauthSessionID);
            UriBuilder    uriBuilder    = new UriBuilder(AssetStoreClient.GetProperPath(path));
            StringBuilder stringBuilder = new StringBuilder();

            foreach (KeyValuePair <string, string> keyValuePair in dictionary)
            {
                string key = keyValuePair.Key;
                string arg = Uri.EscapeDataString(keyValuePair.Value);
                stringBuilder.AppendFormat("&{0}={1}", key, arg);
            }
            if (!string.IsNullOrEmpty(uriBuilder.Query))
            {
                uriBuilder.Query = uriBuilder.Query.Substring(1) + stringBuilder;
            }
            else
            {
                uriBuilder.Query = stringBuilder.Remove(0, 1).ToString();
            }
            DebugUtils.Log("preparing: " + uriBuilder.Uri);
            return(uriBuilder.Uri);
        }
 public static AssetStoreClient.Pending CreatePendingPost(string name, string path, NameValueCollection param, AssetStoreClient.DoneCallback callback)
 {
     AssetStoreClient.Pending p = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = delegate()
     {
         p.conn = AssetStoreClient.AcquireClient();
         if (p.conn == null)
         {
             return(false);
         }
         try
         {
             p.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             p.conn.UploadProgressChanged += AssetStoreClient.UploadProgressCallback;
             p.conn.UploadValuesCompleted += AssetStoreClient.UploadValuesCallback;
             p.conn.UploadValuesAsync(AssetStoreClient.APIUri(path), "POST", param, p);
         }
         catch (WebException ex)
         {
             p.ex = ex;
             return(false);
         }
         return(true);
     };
     if (!pendingQueueDelegate())
     {
         p.queueDelegate = pendingQueueDelegate;
     }
     return(p);
 }
 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);
     });
 }
        private void RenderToolbar()
        {
            GUILayout.FlexibleSpace();
            bool enabled = 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>(), delegate(List <string> newList)
                    {
                        foreach (string str in newList)
                        {
                            DebugUtils.Log(str);
                        }
                    });
                }
                if (GUILayout.Button("Logout", EditorStyles.toolbarButton, new GUILayoutOption[0]))
                {
                    AssetStoreClient.Logout();
                }
            }
            GUI.enabled = enabled;
        }
Beispiel #10
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();
        }
 private static AssetStoreWebClient AcquireClient()
 {
     AssetStoreClient.InitClientPool();
     if (AssetStoreClient.sClientPool.Count != 0)
     {
         return(AssetStoreClient.sClientPool.Pop());
     }
     return(null);
 }
Beispiel #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);
                    ImageConversion.LoadImage(texture2D, 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);
        }
 private static void ReleaseClient(AssetStoreWebClient client)
 {
     AssetStoreClient.InitClientPool();
     if (client != null)
     {
         client.Headers.Remove("X-HttpMethod");
         AssetStoreClient.sClientPool.Push(client);
     }
 }
 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 assetStoreManager = (AssetStoreManager)EditorWindow.GetWindow(typeof(AssetStoreManager), false, "Package Upload");
         assetStoreManager.Close();
         AssetStoreClient.Logout();
     }
 }
 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);
 }
 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;
 }
 public void OnClickUpload()
 {
     if (this.m_AssetsState == AssetStorePackageController.AssetsState.UploadingPackage)
     {
         AssetStoreClient.AbortLargeFilesUpload();
         this.m_AssetsState = AssetStorePackageController.AssetsState.None;
     }
     else
     {
         this.Upload();
         GUIUtility.ExitGUI();
     }
 }
 private void RenderAssetsFolderStatus()
 {
     if (this.m_AssetsState == AssetStorePackageController.AssetsState.UploadingPackage)
     {
         string str = ((int)Mathf.Ceil(this.m_DraftAssetsUploadProgress * 100f)).ToString();
         if (AssetStorePackageController.CancelableProgressBar(this.m_DraftAssetsUploadProgress, "Uploading " + str + " %", "Cancel"))
         {
             this.m_DraftAssetsUploadProgress = 0f;
             this.m_AssetsState     = AssetStorePackageController.AssetsState.None;
             this.m_DraftAssetsPath = string.Empty;
             this.m_DraftAssetsSize = 0L;
             AssetStoreClient.AbortLargeFilesUpload();
         }
     }
     else if (this.m_AssetsState == AssetStorePackageController.AssetsState.BuildingPackage)
     {
         GUILayout.Label(GUIUtil.StatusWheel, new GUILayoutOption[0]);
         GUILayout.Label("Please wait - building package", new GUILayoutOption[0]);
         GUILayout.FlexibleSpace();
     }
     else
     {
         Color  color = GUI.color;
         string text  = "No assets selected";
         if (this.m_LocalRootPath != null)
         {
             if (!this.IsValidRelativeProjectFolder(this.m_LocalRootPath))
             {
                 GUI.color = GUIUtil.ErrorColor;
                 text      = string.Format("The path \"{0}\" is not valid within this Project", this.m_LocalRootPath);
             }
             else if (this.m_LocalRootPath.StartsWith("/AssetStoreTools"))
             {
                 GUI.color = GUIUtil.ErrorColor;
                 text      = string.Format("The selected path cannot be part of \"/AssetStoreTools\" folder", this.m_LocalRootPath);
             }
             else
             {
                 text = " " + this.m_LocalRootPath;
             }
         }
         GUILayout.Label(text, new GUILayoutOption[0]);
         GUI.color = color;
         GUILayout.FlexibleSpace();
     }
 }
 private void RenderMainAssetsStatus()
 {
     if (this.m_AssetsState == AssetStorePackageController.AssetsState.BuildingMainAssets)
     {
         GUILayout.Label(GUIUtil.StatusWheel, new GUILayoutOption[0]);
         GUILayout.Label("Please wait - building Main Assets", new GUILayoutOption[0]);
         GUILayout.FlexibleSpace();
     }
     else if (this.m_AssetsState == AssetStorePackageController.AssetsState.UploadingMainAssets)
     {
         float  num = (float)this.m_MainAssetsUploadHelper.GetProgress();
         string str = Mathf.FloorToInt(num).ToString();
         if (AssetStorePackageController.CancelableProgressBar(num, "Uploading " + str + " %", "Cancel"))
         {
             this.m_AssetsState     = AssetStorePackageController.AssetsState.None;
             this.m_DraftAssetsPath = string.Empty;
             this.m_DraftAssetsSize = 0L;
             AssetStoreClient.AbortLargeFilesUpload();
         }
     }
     else
     {
         string text;
         if (this.m_Package != null && !string.IsNullOrEmpty(this.m_LocalRootPath) && this.IsValidRelativeProjectFolder(this.m_LocalRootPath))
         {
             if (this.m_MainAssets.Count == 0)
             {
                 text = "No Files Selected";
             }
             else if (this.m_MainAssets.Count == 1)
             {
                 text = this.m_MainAssets[0] + " selected";
             }
             else
             {
                 text = this.m_MainAssets.Count + " File(s) selected";
             }
         }
         else
         {
             text = "Please select a valid Assets folder";
         }
         GUILayout.Label(text, new GUILayoutOption[0]);
     }
 }
Beispiel #20
0
 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, delegate(string errorMessage)
     {
         this.m_LoginRemoteMessage = errorMessage;
         if (errorMessage == null)
         {
             if (this.m_LoginCallback != null)
             {
                 this.m_LoginCallback(this.m_LoginRemoteMessage);
             }
             base.Close();
         }
         else
         {
             this.Repaint();
         }
     });
 }
Beispiel #21
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();
         }
     });
 }
        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 address = 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("V4.1.0"),
                "26c4202eb475d02864b40827dfff11a14657aa41"
            }));
            AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient();

            AssetStoreClient.Pending pending = new AssetStoreClient.Pending();
            pending.conn     = assetStoreWebClient;
            pending.id       = "login";
            pending.callback = AssetStoreClient.WrapLoginCallback(callback);
            AssetStoreClient.pending.Add(pending);
            assetStoreWebClient.Headers.Add("Accept", "application/json");
            assetStoreWebClient.DownloadStringCompleted += AssetStoreClient.DownloadStringCallback;
            try
            {
                assetStoreWebClient.DownloadStringAsync(address, pending);
            }
            catch (WebException ex)
            {
                pending.ex = ex;
                AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR;
            }
        }
 public static void AbortLargeFilesUpload()
 {
     if (AssetStoreClient.s_PendingLargeFiles.Count == 0)
     {
         return;
     }
     AssetStoreClient.s_PendingLargeFiles.RemoveAll(delegate(AssetStoreClient.LargeFilePending assetUpload)
     {
         if (assetUpload == null)
         {
             return(true);
         }
         AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(null, null, null, null);
         job.HttpStatusCode     = -2;
         if (assetUpload.RequestDoneCallback != null)
         {
             assetUpload.RequestDoneCallback(job);
         }
         assetUpload.Close();
         return(true);
     });
 }
Beispiel #24
0
 public static void Login(string loginReason, LoginWindow.LoginCallback callback, Rect windowRect)
 {
     if (AssetStoreClient.HasActiveSessionID)
     {
         AssetStoreClient.Logout();
     }
     if (UnityConnectSession.instance.LoggedIn())
     {
         AssetStoreClient.LoginWithAccessToken(delegate(string errorMessage)
         {
             if (string.IsNullOrEmpty(errorMessage))
             {
                 callback(errorMessage);
             }
             else
             {
                 LoginWindow.ShowLoginWindow(loginReason, callback, windowRect);
             }
         });
         return;
     }
     if (!AssetStoreClient.RememberSession || !AssetStoreClient.HasSavedSessionID)
     {
         LoginWindow.ShowLoginWindow(loginReason, callback, windowRect);
         return;
     }
     AssetStoreClient.LoginWithRememberedSession(delegate(string errorMessage)
     {
         if (string.IsNullOrEmpty(errorMessage))
         {
             callback(errorMessage);
         }
         else
         {
             LoginWindow.ShowLoginWindow(loginReason, callback, windowRect);
         }
     });
 }
Beispiel #25
0
 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 str in newList)
                 {
                     DebugUtils.Log(str);
                 }
             });
         }
         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();
         }
     }
 }
        internal static void LoginWithCredentials(string username, string password, bool rememberMe, AssetStoreClient.DoneLoginCallback callback)
        {
            if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
            {
                DebugUtils.LogWarning("Tried to login with credentials while already in progress of logging in");
                return;
            }
            AssetStoreClient.sLoginState        = AssetStoreClient.LoginState.IN_PROGRESS;
            AssetStoreClient.RememberSession    = rememberMe;
            AssetStoreClient.sLoginErrorMessage = null;
            Uri address = new Uri(string.Format("{0}/login", AssetStoreClient.AssetStoreUrl));
            AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient();
            NameValueCollection nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("user", username);
            nameValueCollection.Add("pass", password);
            nameValueCollection.Add("unityversion", Application.unityVersion);
            nameValueCollection.Add("toolversion", "V4.1.0");
            nameValueCollection.Add("license_hash", AssetStoreClient.GetLicenseHash());
            nameValueCollection.Add("hardware_hash", AssetStoreClient.GetHardwareHash());
            AssetStoreClient.Pending pending = new AssetStoreClient.Pending();
            pending.conn     = assetStoreWebClient;
            pending.id       = "login";
            pending.callback = AssetStoreClient.WrapLoginCallback(callback);
            AssetStoreClient.pending.Add(pending);
            assetStoreWebClient.Headers.Add("Accept", "application/json");
            assetStoreWebClient.UploadValuesCompleted += AssetStoreClient.UploadValuesCallback;
            try
            {
                assetStoreWebClient.UploadValuesAsync(address, "POST", nameValueCollection, pending);
            }
            catch (WebException ex)
            {
                pending.ex = ex;
                AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR;
            }
        }
 private static Uri APIUri(string path)
 {
     return(AssetStoreClient.APIUri(path, null));
 }
        public static void Update()
        {
            List <AssetStoreClient.Pending> obj = AssetStoreClient.pending;

            lock (obj)
            {
                AssetStoreClient.pending.RemoveAll(delegate(AssetStoreClient.Pending p)
                {
                    if (p.conn == null)
                    {
                        if (p.queueDelegate == null)
                        {
                            DebugUtils.LogWarning("Invalid pending state while communicating with asset store");
                            return(true);
                        }
                        if (!p.queueDelegate() && p.conn == null)
                        {
                            return(false);
                        }
                        p.queueDelegate = null;
                    }
                    if (!p.conn.IsBusy)
                    {
                        if (p.ex == null && p.data == null)
                        {
                            if (p.binData == null)
                            {
                                goto IL_19F;
                            }
                        }
                        try
                        {
                            AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(p.data, p.binData, p.ex, (p.conn != null) ? p.conn.ResponseHeaders : null);
                            if (AssetStoreManager.sDbg)
                            {
                                DebugUtils.Log(string.Concat(new string[]
                                {
                                    "Pending done: ",
                                    Thread.CurrentThread.ManagedThreadId.ToString(),
                                    " ",
                                    p.id,
                                    " ",
                                    job.data ?? "<nodata>"
                                }));
                                if (job.HttpHeaders != null && job.HttpHeaders.Get("X-Unity-Reason") != null)
                                {
                                    DebugUtils.LogWarning("X-Unity-Reason: " + job.HttpHeaders.Get("X-Unity-Reason"));
                                }
                            }
                            p.callback(job);
                        }
                        catch (Exception ex)
                        {
                            DebugUtils.LogError("Uncaught exception in async net callback: " + ex.Message);
                            DebugUtils.LogError(ex.StackTrace);
                        }
                        AssetStoreClient.ReleaseClient(p.conn);
                        p.conn = null;
                        return(true);
                    }
                    IL_19F:
                    if (p.progressCallback != null && p.statsUpdated)
                    {
                        p.statsUpdated = false;
                        double pctUp   = (p.totalBytesToSend <= 0)
                            ? 0
                            : p.bytesSend / p.totalBytesToSend * 100.0;

                        double pctDown = (p.totalBytesToReceive <= 0)
                            ? 0
                            : p.bytesReceived / p.totalBytesToReceive * 100.0;

                        try
                        {
                            p.progressCallback(pctUp, pctDown);
                        }
                        catch (Exception ex2)
                        {
                            DebugUtils.LogError("Uncaught exception in async net progress callback: " + ex2.Message);
                        }
                    }
                    return(false);
                });
            }
            AssetStoreClient.UpdateLargeFilesUpload();
        }
        private static string UpdateLargeFilesUpload()
        {
            if (AssetStoreClient.s_UploadingLargeFile == null)
            {
                if (AssetStoreClient.s_PendingLargeFiles.Count == 0)
                {
                    return(null);
                }
                AssetStoreClient.s_UploadingLargeFile = AssetStoreClient.s_PendingLargeFiles[0];
                try
                {
                    AssetStoreClient.s_UploadingLargeFile.Open();
                }
                catch (Exception ex)
                {
                    DebugUtils.LogError("Unable to start uploading:" + AssetStoreClient.s_UploadingLargeFile.FilePath + " Reason: " + ex.Message);
                    AssetStoreClient.s_PendingLargeFiles.Remove(AssetStoreClient.s_UploadingLargeFile);
                    AssetStoreClient.s_PendingLargeFiles = null;
                    return(null);
                }
            }
            AssetStoreClient.LargeFilePending largeFilePending = AssetStoreClient.s_UploadingLargeFile;
            StreamReader streamReader = null;
            WebResponse  webResponse  = null;

            try
            {
                if (largeFilePending == null || largeFilePending.Request == null)
                {
                    return(null);
                }
                byte[] buffer = largeFilePending.Buffer;
                int    num    = 0;
                for (int i = 0; i < 2; i++)
                {
                    num = largeFilePending.RequestFileStream.Read(buffer, 0, buffer.Length);
                    if (num == 0)
                    {
                        break;
                    }
                    largeFilePending.RequestStream.Write(buffer, 0, num);
                    largeFilePending.BytesSent += (long)num;
                }
                if (num != 0)
                {
                    try
                    {
                        double num2  = (double)largeFilePending.BytesSent;
                        double num3  = (double)largeFilePending.BytesToSend;
                        double pctUp = num2 / num3 * 100.0;
                        if (largeFilePending.RequestProgressCallback != null)
                        {
                            largeFilePending.RequestProgressCallback(pctUp, 0.0);
                        }
                    }
                    catch (Exception ex2)
                    {
                        DebugUtils.LogWarning("Progress update error " + ex2.Message);
                    }
                    return(null);
                }
                AssetStoreClient.s_PendingLargeFiles.Remove(largeFilePending);
                AssetStoreClient.s_UploadingLargeFile = null;
                DebugUtils.Log("Finished Uploading: " + largeFilePending.Id);
                webResponse = largeFilePending.Request.GetResponse();
                Stream responseStream = webResponse.GetResponseStream();
                string text;
                try
                {
                    streamReader = new StreamReader(responseStream);
                    text         = streamReader.ReadToEnd();
                    streamReader.Close();
                }
                catch (Exception ex3)
                {
                    DebugUtils.LogError("StreamReader sr");
                    throw ex3;
                }
                AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(text, null, null, webResponse.Headers);
                largeFilePending.Close();
                largeFilePending.RequestDoneCallback(job);
                return(text);
            }
            catch (Exception ex4)
            {
                DebugUtils.LogError("UploadingLarge Files Exception:" + ex4.Source);
                if (streamReader != null)
                {
                    streamReader.Close();
                }
                AssetStoreResponse job2 = AssetStoreClient.parseAssetStoreResponse(null, null, ex4, (webResponse == null) ? null : webResponse.Headers);
                largeFilePending.RequestDoneCallback(job2);
                largeFilePending.Close();
                AssetStoreClient.s_PendingLargeFiles.Remove(largeFilePending);
            }
            return(null);
        }
 public static void LoadFromUrl(string url, AssetStoreClient.DoneCallback callback, AssetStoreClient.ProgressCallback progress)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingGetBinary(url, url, callback);
     pending.progressCallback = progress;
 }