Represents a NuGet Package Source (a "server").
Ejemplo n.º 1
0
        /// <summary>
        /// Loads the NuGet.config file.
        /// </summary>
        public static void LoadNugetConfigFile()
        {
            if (File.Exists(NugetConfigFilePath))
            {
                NugetConfigFile = NugetConfigFile.Load(NugetConfigFilePath);
            }
            else
            {
                Debug.LogFormat("No NuGet.config file found. Creating default at {0}", NugetConfigFilePath);

                NugetConfigFile = NugetConfigFile.CreateDefaultFile(NugetConfigFilePath);
                AssetDatabase.Refresh();
            }

            // parse any command line arguments
            //LogVerbose("Command line: {0}", Environment.CommandLine);
            packageSources.Clear();
            bool readingSources = false;
            bool useCommandLineSources = false;
            foreach (var arg in Environment.GetCommandLineArgs())
            {
                if (readingSources)
                {
                    if (arg.StartsWith("-"))
                    {
                        readingSources = false;
                    }
                    else
                    {
                        NugetPackageSource source = new NugetPackageSource("CMD_LINE_SRC_" + packageSources.Count, arg);
                        LogVerbose("Adding command line package source {0} at {1}", "CMD_LINE_SRC_" + packageSources.Count, arg);
                        packageSources.Add(source);
                    }
                }

                if (arg == "-Source")
                {
                    // if the source is being forced, don't install packages from the cache
                    NugetConfigFile.InstallFromCache = false;
                    readingSources = true;
                    useCommandLineSources = true;
                }
            }

            // if there are not command line overrides, use the NuGet.config package sources
            if (!useCommandLineSources)
            {
                if (NugetConfigFile.ActivePackageSource.Path == "(Aggregate source)")
                {
                    packageSources.AddRange(NugetConfigFile.PackageSources);
                }
                else
                {
                    packageSources.Add(NugetConfigFile.ActivePackageSource);
                }
            }
        }
Ejemplo n.º 2
0
        public static void PreferencesGUI()
        {
            EditorGUILayout.LabelField(string.Format("Version: {0}", NuGetForUnityVersion));

            if (NugetHelper.NugetConfigFile == null)
            {
                NugetHelper.LoadNugetConfigFile();
            }

            NugetHelper.NugetConfigFile.InstallFromCache = EditorGUILayout.Toggle("Install From the Cache", NugetHelper.NugetConfigFile.InstallFromCache);

            NugetHelper.NugetConfigFile.ReadOnlyPackageFiles = EditorGUILayout.Toggle("Read-Only Package Files", NugetHelper.NugetConfigFile.ReadOnlyPackageFiles);

            NugetHelper.NugetConfigFile.Verbose = EditorGUILayout.Toggle("Use Verbose Logging", NugetHelper.NugetConfigFile.Verbose);

            EditorGUILayout.LabelField("Package Sources:");

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            NugetPackageSource sourceToMoveUp   = null;
            NugetPackageSource sourceToMoveDown = null;
            NugetPackageSource sourceToRemove   = null;

            foreach (var source in NugetHelper.NugetConfigFile.PackageSources)
            {
                EditorGUILayout.BeginVertical();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.BeginVertical(GUILayout.Width(20));
                        {
                            GUILayout.Space(10);
                            source.IsEnabled = EditorGUILayout.Toggle(source.IsEnabled, GUILayout.Width(20));
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUILayout.BeginVertical();
                        {
                            source.Name      = EditorGUILayout.TextField(source.Name);
                            source.SavedPath = EditorGUILayout.TextField(source.SavedPath);
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(29);
                        EditorGUIUtility.labelWidth = 75;
                        EditorGUILayout.BeginVertical();
                        source.HasPassword = EditorGUILayout.Toggle("Credentials", source.HasPassword);
                        if (source.HasPassword)
                        {
                            source.UserName      = EditorGUILayout.TextField("User Name", source.UserName);
                            source.SavedPassword = EditorGUILayout.PasswordField("Password", source.SavedPassword);
                        }
                        else
                        {
                            source.UserName = null;
                        }
                        EditorGUIUtility.labelWidth = 0;
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button(string.Format("Move Up")))
                        {
                            sourceToMoveUp = source;
                        }

                        if (GUILayout.Button(string.Format("Move Down")))
                        {
                            sourceToMoveDown = source;
                        }

                        if (GUILayout.Button(string.Format("Remove")))
                        {
                            sourceToRemove = source;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
            }

            if (sourceToMoveUp != null)
            {
                int index = NugetHelper.NugetConfigFile.PackageSources.IndexOf(sourceToMoveUp);
                if (index > 0)
                {
                    NugetHelper.NugetConfigFile.PackageSources[index]     = NugetHelper.NugetConfigFile.PackageSources[index - 1];
                    NugetHelper.NugetConfigFile.PackageSources[index - 1] = sourceToMoveUp;
                }
            }

            if (sourceToMoveDown != null)
            {
                int index = NugetHelper.NugetConfigFile.PackageSources.IndexOf(sourceToMoveDown);
                if (index < NugetHelper.NugetConfigFile.PackageSources.Count - 1)
                {
                    NugetHelper.NugetConfigFile.PackageSources[index]     = NugetHelper.NugetConfigFile.PackageSources[index + 1];
                    NugetHelper.NugetConfigFile.PackageSources[index + 1] = sourceToMoveDown;
                }
            }

            if (sourceToRemove != null)
            {
                NugetHelper.NugetConfigFile.PackageSources.Remove(sourceToRemove);
            }

            if (GUILayout.Button(string.Format("Add New Source")))
            {
                NugetHelper.NugetConfigFile.PackageSources.Add(new NugetPackageSource("New Source", "source_path"));
            }

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button(string.Format("Save")))
            {
                NugetHelper.NugetConfigFile.Save(NugetHelper.NugetConfigFilePath);
                NugetHelper.LoadNugetConfigFile();
            }
        }
Ejemplo n.º 3
0
        public static void PreferencesGUI()
        {
            bool preferencesChangedThisFrame = false;

            EditorGUILayout.LabelField(string.Format("Version: {0}", NuGetForUnityVersion));

            if (NugetHelper.NugetConfigFile == null)
            {
                NugetHelper.LoadNugetConfigFile();
            }

            bool installFromCache = EditorGUILayout.Toggle("Install From the Cache", NugetHelper.NugetConfigFile.InstallFromCache);

            if (installFromCache != NugetHelper.NugetConfigFile.InstallFromCache)
            {
                preferencesChangedThisFrame = true;
                NugetHelper.NugetConfigFile.InstallFromCache = installFromCache;
            }

            bool readOnlyPackageFiles = EditorGUILayout.Toggle("Read-Only Package Files", NugetHelper.NugetConfigFile.ReadOnlyPackageFiles);

            if (readOnlyPackageFiles != NugetHelper.NugetConfigFile.ReadOnlyPackageFiles)
            {
                preferencesChangedThisFrame = true;
                NugetHelper.NugetConfigFile.ReadOnlyPackageFiles = readOnlyPackageFiles;
            }

            bool verbose = EditorGUILayout.Toggle("Use Verbose Logging", NugetHelper.NugetConfigFile.Verbose);

            if (verbose != NugetHelper.NugetConfigFile.Verbose)
            {
                preferencesChangedThisFrame         = true;
                NugetHelper.NugetConfigFile.Verbose = verbose;
            }

            EditorGUILayout.LabelField("Package Sources:");

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            NugetPackageSource sourceToMoveUp   = null;
            NugetPackageSource sourceToMoveDown = null;
            NugetPackageSource sourceToRemove   = null;

            foreach (var source in NugetHelper.NugetConfigFile.PackageSources)
            {
                EditorGUILayout.BeginVertical();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.BeginVertical(GUILayout.Width(20));
                        {
                            GUILayout.Space(10);
                            bool isEnabled = EditorGUILayout.Toggle(source.IsEnabled, GUILayout.Width(20));
                            if (isEnabled != source.IsEnabled)
                            {
                                preferencesChangedThisFrame = true;
                                source.IsEnabled            = isEnabled;
                            }
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUILayout.BeginVertical();
                        {
                            string name = EditorGUILayout.TextField(source.Name);
                            if (name != source.Name)
                            {
                                preferencesChangedThisFrame = true;
                                source.Name = name;
                            }

                            string savedPath = EditorGUILayout.TextField(source.SavedPath).Trim();
                            if (savedPath != source.SavedPath)
                            {
                                preferencesChangedThisFrame = true;
                                source.SavedPath            = savedPath;
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(29);
                        EditorGUIUtility.labelWidth = 75;
                        EditorGUILayout.BeginVertical();

                        bool hasPassword = EditorGUILayout.Toggle("Credentials", source.HasPassword);
                        if (hasPassword != source.HasPassword)
                        {
                            preferencesChangedThisFrame = true;
                            source.HasPassword          = hasPassword;
                        }

                        if (source.HasPassword)
                        {
                            string userName = EditorGUILayout.TextField("User Name", source.UserName);
                            if (userName != source.UserName)
                            {
                                preferencesChangedThisFrame = true;
                                source.UserName             = userName;
                            }

                            string savedPassword = EditorGUILayout.PasswordField("Password", source.SavedPassword);
                            if (savedPassword != source.SavedPassword)
                            {
                                preferencesChangedThisFrame = true;
                                source.SavedPassword        = savedPassword;
                            }
                        }
                        else
                        {
                            source.UserName = null;
                        }
                        EditorGUIUtility.labelWidth = 0;
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button(string.Format("Move Up")))
                        {
                            sourceToMoveUp = source;
                        }

                        if (GUILayout.Button(string.Format("Move Down")))
                        {
                            sourceToMoveDown = source;
                        }

                        if (GUILayout.Button(string.Format("Remove")))
                        {
                            sourceToRemove = source;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
            }

            if (sourceToMoveUp != null)
            {
                int index = NugetHelper.NugetConfigFile.PackageSources.IndexOf(sourceToMoveUp);
                if (index > 0)
                {
                    NugetHelper.NugetConfigFile.PackageSources[index]     = NugetHelper.NugetConfigFile.PackageSources[index - 1];
                    NugetHelper.NugetConfigFile.PackageSources[index - 1] = sourceToMoveUp;
                }
                preferencesChangedThisFrame = true;
            }

            if (sourceToMoveDown != null)
            {
                int index = NugetHelper.NugetConfigFile.PackageSources.IndexOf(sourceToMoveDown);
                if (index < NugetHelper.NugetConfigFile.PackageSources.Count - 1)
                {
                    NugetHelper.NugetConfigFile.PackageSources[index]     = NugetHelper.NugetConfigFile.PackageSources[index + 1];
                    NugetHelper.NugetConfigFile.PackageSources[index + 1] = sourceToMoveDown;
                }
                preferencesChangedThisFrame = true;
            }

            if (sourceToRemove != null)
            {
                NugetHelper.NugetConfigFile.PackageSources.Remove(sourceToRemove);
                preferencesChangedThisFrame = true;
            }

            if (GUILayout.Button(string.Format("Add New Source")))
            {
                NugetHelper.NugetConfigFile.PackageSources.Add(new NugetPackageSource("New Source", "source_path"));
                preferencesChangedThisFrame = true;
            }

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button(string.Format("Reset To Default")))
            {
                NugetConfigFile.CreateDefaultFile(NugetHelper.NugetConfigFilePath);
                NugetHelper.LoadNugetConfigFile();
                preferencesChangedThisFrame = true;
            }

            if (preferencesChangedThisFrame)
            {
                NugetHelper.NugetConfigFile.Save(NugetHelper.NugetConfigFilePath);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws the preferences GUI inside the Unity preferences window in the Editor.
        /// </summary>
        public static void PreferencesGUI()
        {
            EditorGUILayout.LabelField($"Version: {NuGetForUnityVersion}");

            var conf = NugetHelper.NugetConfigFile;

            EditorGUI.BeginChangeCheck();

            conf.InstallFromCache = EditorGUILayout.Toggle("Install From the Cache", conf.InstallFromCache);

            conf.ReadOnlyPackageFiles = EditorGUILayout.Toggle("Read-Only Package Files", conf.ReadOnlyPackageFiles);

            conf.Verbose = EditorGUILayout.Toggle("Use Verbose Logging", conf.Verbose);

            conf.SavedRepositoryPath = EditorGUILayout.TextField("Packages Directory", conf.SavedRepositoryPath);

            conf.AllowUninstallAll = EditorGUILayout.Toggle("Allow Uninstall All", conf.AllowUninstallAll);

            EditorGUILayout.LabelField("Package Sources:");

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            NugetPackageSource sourceToMoveUp   = null;
            NugetPackageSource sourceToMoveDown = null;
            NugetPackageSource sourceToRemove   = null;

            foreach (var source in conf.PackageSources)
            {
                EditorGUILayout.BeginVertical();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.BeginVertical(GUILayout.Width(20));
                        {
                            GUILayout.Space(10);
                            source.IsEnabled = EditorGUILayout.Toggle(source.IsEnabled, GUILayout.Width(20));
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUILayout.BeginVertical();
                        {
                            source.Name = EditorGUILayout.TextField(source.Name);

                            EditorGUI.BeginChangeCheck();
                            source.SavedPath = EditorGUILayout.TextField(source.SavedPath);
                            if (EditorGUI.EndChangeCheck())
                            {
                                source.SavedPath = source.SavedPath.Trim();
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(29);
                        EditorGUIUtility.labelWidth = 75;
                        EditorGUILayout.BeginVertical();
                        source.HasPassword = EditorGUILayout.Toggle("Credentials", source.HasPassword);
                        if (source.HasPassword)
                        {
                            source.UserName      = EditorGUILayout.TextField("User Name", source.UserName);
                            source.SavedPassword = EditorGUILayout.PasswordField("Password", source.SavedPassword);
                        }
                        else
                        {
                            source.UserName = null;
                        }
                        EditorGUIUtility.labelWidth = 0;
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button("Move Up"))
                        {
                            sourceToMoveUp = source;
                        }

                        if (GUILayout.Button("Move Down"))
                        {
                            sourceToMoveDown = source;
                        }

                        if (GUILayout.Button("Remove"))
                        {
                            sourceToRemove = source;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
            }

            if (sourceToMoveUp != null)
            {
                var index = conf.PackageSources.IndexOf(sourceToMoveUp);
                if (index > 0)
                {
                    conf.PackageSources[index]     = conf.PackageSources[index - 1];
                    conf.PackageSources[index - 1] = sourceToMoveUp;
                    GUI.changed = true;
                }
            }

            if (sourceToMoveDown != null)
            {
                var index = conf.PackageSources.IndexOf(sourceToMoveDown);
                if (index < conf.PackageSources.Count - 1)
                {
                    conf.PackageSources[index]     = conf.PackageSources[index + 1];
                    conf.PackageSources[index + 1] = sourceToMoveDown;
                    GUI.changed = true;
                }
            }

            if (sourceToRemove != null)
            {
                conf.PackageSources.Remove(sourceToRemove);
                GUI.changed = true;
            }

            if (GUILayout.Button("Add New Source"))
            {
                conf.PackageSources.Add(new NugetPackageSource("New Source", "source_path"));
                GUI.changed = true;
            }

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Reset To Default"))
            {
                NugetConfigFile.CreateDefaultFile(NugetHelper.NugetConfigFilePath);
                NugetHelper.ForceReloadNugetConfig();
                GUI.changed = true;
            }

            if (EditorGUI.EndChangeCheck())
            {
                conf.Save(NugetHelper.NugetConfigFilePath);
            }
        }