예제 #1
0
        public static void DoUpload(PackageVersion packageVersion, Action succeed)
        {
            EditorUtility.DisplayProgressBar("插件上传", "打包中...", 0.1f);

            var fileName = packageVersion.Name + "_" + packageVersion.Version + ".unitypackage";
            var fullpath = FrameworkPMView.ExportPaths(fileName, packageVersion.InstallPath);
            var file     = File.ReadAllBytes(fullpath);

            var form = new WWWForm();

            form.AddField("name", packageVersion.Name);
            form.AddField("version", packageVersion.Version);
            form.AddField("file_name", fileName);
            form.AddBinaryData("file", file);
            form.AddField("version", packageVersion.Version);
            form.AddField("release_note", packageVersion.Readme.content);
            form.AddField("install_path", packageVersion.InstallPath);
            form.AddField("access_right", packageVersion.AccessRight.ToString().ToLower());

            if (packageVersion.Type == PackageType.FrameworkModule)
            {
                form.AddField("type", "fm");
            }
            else if (packageVersion.Type == PackageType.Shader)
            {
                form.AddField("type", "s");
            }
            else if (packageVersion.Type == PackageType.AppOrGameDemoOrTemplate)
            {
                form.AddField("type", "agt");
            }
            else if (packageVersion.Type == PackageType.Plugin)
            {
                form.AddField("type", "p");
            }

            Debug.Log(fullpath);

            EditorUtility.DisplayProgressBar("插件上传", "上传中...", 0.2f);


            ObservableWWW.Post(UPLOAD_URL, form, new Dictionary <string, string> {
                { "Authorization", "Token " + User.Token.Value }
            })
            .Subscribe(responseContent =>
            {
                EditorUtility.ClearProgressBar();
                Debug.Log(responseContent);
                succeed.InvokeGracefully();
                File.Delete(fullpath);
            }, e =>
            {
                EditorUtility.ClearProgressBar();
                EditorUtility.DisplayDialog("插件上传", "上传失败!{0}".FillFormat(e.Message), "确定");
                File.Delete(fullpath);
            });
        }
예제 #2
0
        public static IEnumerator DoUpload(string username, string password, PackageVersion packageVersion, Action succeed)
        {
            var loginPage = UnityWebRequest.Get(LOGIN_URL);

            yield return(loginPage.Send());

            #if UNITY_2018_2_OR_NEWER
            if (loginPage.isNetworkError)
            #else
            if (loginPage.isError)
            #endif
            {
                Debug.Log(loginPage.error);
                yield break;
            }

            // get the csrf cookie
            var SetCookie     = loginPage.GetResponseHeader("set-cookie");
            var rxCookie      = new Regex("csrftoken=(?<csrf_token>.{64});");
            var cookieMatches = rxCookie.Matches(SetCookie);
            var csrfCookie    = cookieMatches[0].Groups["csrf_token"].Value;

            // get the middleware value
//            var loginPageHtml = loginPage.downloadHandler.text;
//            var rxMiddleware = new Regex("name='csrfmiddlewaretoken' value='(?<csrf_token>.{64})'");
//            var middlewareMatches = rxMiddleware.Matches(loginPageHtml);
//            string csrfMiddlewareToken = middlewareMatches[0].Groups["csrf_token"].Value;

            /*
             * Make a login request.
             */

            var form     = new WWWForm();
            var fileName = packageVersion.Name + "_" + packageVersion.Version + ".unitypackage";
            var fullpath = FrameworkPMView.ExportPaths(fileName, packageVersion.InstallPath);
            var file     = File.ReadAllBytes(fullpath);

            form.AddField("username", username);
            form.AddField("password", password);

            form.AddField("name", packageVersion.Name);
            form.AddField("file_name", fileName);
            form.AddBinaryData("file", file);
            form.AddField("version", packageVersion.Version);
            form.AddField("release_note", packageVersion.Readme.content);

            if (packageVersion.Type == PackageType.FrameworkModule)
            {
                form.AddField("type", "fm");
            }
            else if (packageVersion.Type == PackageType.Shader)
            {
                form.AddField("type", "s");
            }
            else if (packageVersion.Type == PackageType.AppOrGameDemoOrTemplate)
            {
                form.AddField("type", "agt");
            }

            UnityWebRequest doLogin3 =
                UnityWebRequest.Post(UPLOAD_URL, form);
            doLogin3.SetRequestHeader("cookie", "csrftoken=" + csrfCookie);
            doLogin3.SetRequestHeader("X-CSRFToken", csrfCookie);

            File.Delete(fullpath);

            yield return(doLogin3.Send());

            #if UNITY_2018_2_OR_NEWER
            if (doLogin3.isNetworkError)
            #else
            if (doLogin3.isError)
            #endif
            {
                Log.E(doLogin3.error);
            }
            else
            {
                Log.I(doLogin3.downloadHandler.text);
                succeed.InvokeGracefully();
            }
        }
예제 #3
0
 private void Init()
 {
     mPMView = new FrameworkPMView();
     mPMView.Init();
 }
예제 #4
0
        public static IEnumerator DoUpload(string username, string password, PackageVersion packageVersion, Action succeed)
        {
            var loginPage = UnityWebRequest.Get(LOGIN_URL);

            EditorUtility.DisplayProgressBar("插件上传", "获取验证信息", 0.1f);
            yield return(loginPage.Send());

            #if UNITY_2017_1_OR_NEWER
            if (loginPage.isNetworkError)
            #else
            if (loginPage.isError)
            #endif
            {
                Debug.Log(loginPage.error);
                yield break;
            }

            EditorUtility.DisplayProgressBar("插件上传", "生成 token", 0.1f);

            var SetCookie     = loginPage.GetResponseHeader("set-cookie");
            var rxCookie      = new Regex("csrftoken=(?<csrf_token>.{64});");
            var cookieMatches = rxCookie.Matches(SetCookie);
            var csrfCookie    = cookieMatches[0].Groups["csrf_token"].Value;

            var form     = new WWWForm();
            var fileName = packageVersion.Name + "_" + packageVersion.Version + ".unitypackage";
            var fullpath = FrameworkPMView.ExportPaths(fileName, packageVersion.InstallPath);
            var file     = File.ReadAllBytes(fullpath);

            form.AddField("username", username);
            form.AddField("password", password);

            form.AddField("name", packageVersion.Name);
            form.AddField("file_name", fileName);
            form.AddBinaryData("file", file);
            form.AddField("version", packageVersion.Version);
            form.AddField("release_note", packageVersion.Readme.content);

            if (packageVersion.Type == PackageType.FrameworkModule)
            {
                form.AddField("type", "fm");
            }
            else if (packageVersion.Type == PackageType.Shader)
            {
                form.AddField("type", "s");
            }
            else if (packageVersion.Type == PackageType.AppOrGameDemoOrTemplate)
            {
                form.AddField("type", "agt");
            }


            var doLogin3 =
                UnityWebRequest.Post(UPLOAD_URL, form);
            doLogin3.SetRequestHeader("cookie", "csrftoken=" + csrfCookie);
            doLogin3.SetRequestHeader("X-CSRFToken", csrfCookie);

            File.Delete(fullpath);

            yield return(doLogin3.Send());

            EditorUtility.ClearProgressBar();

            #if UNITY_2017_1_OR_NEWER
            if (doLogin3.isNetworkError)
            #else
            if (doLogin3.isError)
            #endif
            {
                EditorUtility.DisplayDialog("插件上传", "上传失败!{0}".FillFormat(doLogin3.error), "确定");
            }
            else
            {
                Log.I(doLogin3.downloadHandler.text);
                succeed.InvokeGracefully();
            }
        }