Search Unity

Feedback Update all

Discussion in 'Package Manager' started by georgeq, May 24, 2019.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Currently, if you have several updates/installs to do, you have to install one by one, wait for the whole thing to compile after every update/install. It would be better if you could select all the installs/removals/updates you want and then click on "update all"... that way you could save a lot of time.
     
    RKeown3D, tonialatalo, Siethu and 2 others like this.
  2. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    I would also like to have an option to select a number of packages, and remove them.
    Every time I start a new project, I'm opening the Package Manager UI and remove some packages one by one, or opening the manifest.json and removing them from there...
     
    tonialatalo likes this.
  3. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
    I wrote this, but should warn you, it may cause packages or even all project reimport. It's not resolving dependencies, package version is chosen automaticly by Unity's "Client.Add(PackageName)". After execution may need to restart unity

    Available with btn in Package info and MenuItem "Help / Update All Packages"

    github: https://github.com/mitay-walle/Unity-PackageManager-Update-All

    Code (CSharp):
    1. using PackageInfo = UnityEditor.PackageManager.PackageInfo;
    2. using UnityEditor.PackageManager.Requests;
    3. using UnityEditor.PackageManager.UI;
    4. using System.Collections.Generic;
    5. using UnityEditor.PackageManager;
    6. using UnityEngine.UIElements;
    7. using UnityEngine;
    8. using UnityEditor;
    9.  
    10. namespace Plugins.Editor
    11. {
    12.     internal class PMUpdateAllBtnExtension : IPackageManagerExtension
    13.     {
    14.         public VisualElement CreateExtensionUI()
    15.         {
    16.             var btn = new Button(PackageManagerUpdateAllUtility.StartUpdateAll);
    17.             btn.text = btn.name = "Update All Packages";
    18.             return btn;
    19.         }
    20.  
    21.         public void OnPackageSelectionChange(PackageInfo packageInfo)
    22.         {
    23.  
    24.         }
    25.  
    26.         public void OnPackageAddedOrUpdated(PackageInfo packageInfo)
    27.         {
    28.  
    29.         }
    30.  
    31.         public void OnPackageRemoved(PackageInfo packageInfo)
    32.         {
    33.  
    34.         }
    35.     }
    36.  
    37.     [InitializeOnLoad]
    38.     public static class PackageManagerUpdateAllUtility
    39.     {
    40.         private const bool ADD_BTN = true;
    41.         private const bool FULL_LOGS = false;
    42.  
    43.         const int MAX_ITERATIONS = 50;
    44.         static int UpdatePackagesCurrentCount = 0;
    45.         static bool UpdatingSomePackage;
    46.         static bool UpdatePackagesInProgress;
    47.         static ListRequest lRequest;
    48.         static AddRequest aRequest;
    49.         static readonly List<string> needToUpate = new List<string>();
    50.  
    51.         private static readonly PMUpdateAllBtnExtension extension = new PMUpdateAllBtnExtension();
    52.  
    53.  
    54.  
    55.         static PackageManagerUpdateAllUtility()
    56.         {
    57.             if (ADD_BTN)
    58.             {
    59.                 PackageManagerExtensions.RegisterExtension(extension);
    60.             }
    61.  
    62. //            if (FULL_LOGS) Debug.Log("check EditorPrefs");
    63. //            UpdatePackagesInProgress = EditorPrefs.GetBool("UpdatePackagesInProgress");
    64. //            UpdatePackagesCurrentCount  = EditorPrefs.GetInt("UpdatePackagesCurrentCount");
    65. //
    66. //            if (UpdatePackagesCurrentCount > MAX_ITERATIONS)
    67. //            {
    68. //                ForceStop();
    69. //                Debug.LogError($"{MAX_ITERATIONS} packages updated, prevent infinite update");
    70. //                return;
    71. //            }
    72. //
    73. //            EditorPrefs.SetInt("UpdatePackagesCurrentCount",UpdatePackagesCurrentCount+1);
    74. //
    75. //            if (UpdatePackagesInProgress && !UpdatingSomePackage)
    76. //            {
    77. //                ContinueUpdateAllpackages();
    78. //            }
    79.         }
    80.  
    81.         [MenuItem("Help/Update All Packages")]
    82.         public static void StartUpdateAll()
    83.         {
    84.             EditorPrefs.SetBool("UpdatePackagesInProgress", true);
    85.             UpdatePackagesInProgress = true;
    86.             ContinueUpdateAllpackages();
    87.         }
    88.  
    89.         public static void ContinueUpdateAllpackages()
    90.         {
    91.             lRequest = Client.List(); // List packages installed for the Project
    92.  
    93.             EditorApplication.update += ProgressRequestPackageList;
    94.         }
    95.  
    96.         static void ForceStop()
    97.         {
    98.             Debug.LogError("somethnig go wrong!");
    99.             EditorApplication.update -= ProgressRequestPackageList;
    100.             EditorPrefs.SetBool("UpdatePackagesInProgress", true);
    101.  
    102.             UpdatePackagesCurrentCount = 0;
    103.  
    104.             EditorPrefs.SetInt("UpdatePackagesCurrentCount",0);
    105.  
    106.             UpdatePackagesInProgress = true;
    107.         }
    108.  
    109.         static void ProgressRequestPackageList()
    110.         {
    111.             if (lRequest == null)
    112.             {
    113.                 ForceStop();
    114.                 return;
    115.             }
    116.  
    117.             if (lRequest.IsCompleted)
    118.             {
    119.                 if (lRequest.Status == StatusCode.Success)
    120.                 {
    121.                     UpdateAll();
    122.                 }
    123.                 else if (lRequest.Status >= StatusCode.Failure)
    124.                     Debug.LogError(lRequest.Error.message);
    125.  
    126.                 EditorApplication.update -= ProgressRequestPackageList;
    127.             }
    128.         }
    129.  
    130.         private static void UpdateAll()
    131.         {
    132.             var check = false;
    133.  
    134.             needToUpate.Clear();
    135.             foreach (var package in lRequest.Result)
    136.             {
    137.                 if (package.status == PackageStatus.Available)
    138.                 {
    139.                    if (FULL_LOGS) Debug.Log($"'{package.name}' current:{package.version } last compatible:{package.versions.latestCompatible} verified:{package.versions.verified}");
    140.      
    141.                     if (package.version == package.versions.latestCompatible || package.version == package.versions.verified)
    142.                     {
    143.                         //Debug.Log($"{package.name} up to date");
    144.                     }
    145.                     else
    146.                     {
    147.                        if (FULL_LOGS) Debug.Log($"'{package.name}' need update from: {package.version} to: {package.versions.latestCompatible}");
    148.                         needToUpate.Add(package.name);
    149.                         check = true;
    150.                     }
    151.                 }
    152.             }
    153.  
    154.             if (check)
    155.             {
    156.                 Debug.Log($"need to Update {needToUpate.Count} packages");
    157.                 CheckUpdateRequests();
    158.                 EditorApplication.update += CheckUpdateRequests;
    159.             }
    160.             else
    161.             {
    162.                 Debug.Log($"all packages are up to date!");
    163.             }
    164.         }
    165.  
    166.         private static void CheckUpdateRequests()
    167.         {
    168.             UpdatingSomePackage = false;
    169.  
    170.             if (aRequest == null)
    171.             {
    172.                 // update first
    173.                 if (FULL_LOGS) Debug.Log($"update first: {needToUpate[0]}");
    174.                 aRequest = Client.Add(needToUpate[0]);
    175.                 return;
    176.             }
    177.  
    178.             if (!aRequest.IsCompleted)
    179.             {
    180.                 UpdatingSomePackage = true;
    181.                 return;
    182.             }
    183.  
    184.             //process update result
    185.             if (FULL_LOGS) Debug.Log($"process update result: {aRequest.Result.name}");
    186.             if (aRequest.Status == StatusCode.Success)
    187.             {
    188.                 Debug.Log($"{aRequest.Result.name} updated to {aRequest.Result.version}");
    189.             }
    190.  
    191.             if (aRequest.Status >= StatusCode.Failure)
    192.             {
    193.                 Debug.LogError(aRequest.Error.message);
    194.             }
    195.  
    196.             needToUpate.Remove(aRequest.Result.name);
    197.  
    198.             if (needToUpate.Count > 0)
    199.             {
    200.                 //update next
    201.                 if (FULL_LOGS) Debug.Log($"update next: {needToUpate[0]}");
    202.                 aRequest = Client.Add(needToUpate[0]);
    203.             }
    204.             else
    205.             {
    206.                 // finish
    207.                 Debug.Log($"finish updating all packages");
    208.                 EditorApplication.update -= CheckUpdateRequests;
    209.                 EditorPrefs.SetBool("UpdatePackagesInProgress", false);
    210.                 UpdatePackagesInProgress = false;
    211.             }
    212.         }
    213.     }
    214. }


     

    Attached Files:

    Last edited: Apr 25, 2020
    ROBYER1 and tonialatalo like this.
  4. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    Was there ever any notion to officially implement this by Unity?
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    I do not think so.
     
  6. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454