Exemple #1
0
        // public static void UpdateRepository(Action<string> OnComplete)
        // {
        //     Debug.Log("Updating repository...");
        //     EditorCoroutine.start(GetData(OpenPackageManagerConfig.RepositoryLink, null, null,
        //      (string data) =>
        //      {
        //          // On Success
        //          if (!string.IsNullOrEmpty(data))
        //          {
        //              Debug.Log("Repository Updated: " + data);
        //              if (OnComplete != null) OnComplete(data);
        //          }
        //          else
        //          {
        //              Debug.LogError("Faild to update repository. received data is null.");
        //          }
        //      }, (error) =>
        //      {
        //          Debug.LogError("Faild to update repository: " + error);
        //      }));
        // }

        public static void DownloadPackage(GithubPackage package, Action <float> OnProgress, Action <byte[]> OnComplete, Action <string> OnError)
        {
            // https://api.github.com/repos/omid3098/OpenUi/zipball
            if (!Directory.Exists(saveDirectory))
            {
                Debug.Log("Download directory does not exist. Creating: " + saveDirectory);
                Directory.CreateDirectory(saveDirectory);
                AssetDatabase.Refresh();
            }

            var url = "https://api.github.com/repos/" + package.owner.login + "/" + package.name + "/zipball";

            Debug.Log(url);
            EditorCoroutine.start(GetData(url, "", OnProgress, (byteArrays) =>
            {
                if (OnComplete != null)
                {
                    OnComplete(byteArrays);
                }
                string fullPath = saveDirectory + "/" + package.name + ".zip";
                Debug.Log(fullPath);
                File.WriteAllBytes(fullPath, byteArrays);
                ZipUtil.Unzip(fullPath, saveDirectory);
                AssetDatabase.Refresh();
            }, OnError));
        }
Exemple #2
0
 private void DrawPackage(GithubPackage package)
 {
     { // Draw package name, version, author and description
         EditorGUILayout.BeginHorizontal();
         {
             EditorGUILayout.BeginVertical();
             {
                 EditorGUILayout.BeginHorizontal();
                 {
                     EditorGUILayout.LabelField(package.name, EditorStyles.boldLabel);
                     if (GUILayout.Button("Author: " + package.owner.login, linkButtonStyle))
                     {
                         Application.OpenURL(controller.repository.server + package.owner.login);
                     }
                     if (GUILayout.Button("Source", linkButtonStyle))
                     {
                         Application.OpenURL(controller.repository.server + package.full_name);
                     }
                     EditorGUILayout.LabelField("Size: " + StringTools.GetBytesReadable(package.size * 1000));
                 }
                 EditorGUILayout.EndHorizontal();
                 EditorGUILayout.LabelField("Description: " + package.description);
             }
             EditorGUILayout.EndVertical();
         }
         // Draw Download Button
         string downloadLable = "download";
         if (downloadingPackages.Contains(package.name))
         {
             downloadLable = downloadProgress + "%";
         }
         if (GUILayout.Button(downloadLable, buttonWidth, buttonHeight))
         {
             downloadingPackages.Add(package.name);
             ConnectionTools.DownloadPackage(package, DownloadingProgress, (byteArray) =>
             {
                 downloadingPackages.Remove(package.name);
             }, (error) =>
             {
                 downloadingPackages.Remove(package.name);
             });
         }
         EditorGUILayout.EndHorizontal();
     }
     DrawLine();
 }