CreateDefaultFile() публичный статический Метод

Creates a NuGet.config file with the default settings at the given full filepath.
public static CreateDefaultFile ( string filePath ) : NugetConfigFile
filePath string The full filepath where to create the NuGet.config file.
Результат NugetConfigFile
        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);
            }
        }
Пример #2
0
        private static void DisplayPackageSource(NugetConfigFile configFile)
        {
            if (configFile == null)
            {
                return;
            }

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            bool preferencesChangedThisFrame    = false;
            NugetPackageSource sourceToMoveUp   = null;
            NugetPackageSource sourceToMoveDown = null;
            NugetPackageSource sourceToRemove   = null;

            foreach (var source in configFile.PackageSources)
            {
                preferencesChangedThisFrame = DisplaySourceUI(source, out sourceToMoveUp, out sourceToMoveDown, out sourceToRemove);

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

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

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

                if (preferencesChangedThisFrame)
                {
                    configFile.Save(configFile.FilePath);
                }
            }

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

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button(string.Format("Reset To Default")))
            {
                NugetConfigFile.CreateDefaultFile(NugetHelper.NugetConfigFilePath);
                NugetHelper.LoadNugetConfigFile();
                preferencesChangedThisFrame = true;
            }
        }
Пример #3
0
        #pragma warning restore CS0618

        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.LabelField("Supported Libs:");

                foreach (var platform in NugetHelper.NugetConfigFile.SupportedPlatforms)
                {
                    EditorGUILayout.BeginVertical();
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.BeginVertical();
                            {
                                BuildTargetGroup buildTarget = BuildTargetGroup.Standalone;

                                EditorGUILayout.BeginHorizontal();
                                {
                                    buildTarget = (BuildTargetGroup)EditorGUILayout.EnumPopup(platform.Platform);
                                    if (buildTarget != platform.Platform)
                                    {
                                        preferencesChangedThisFrame = true;
                                        platform.Platform           = buildTarget;
                                    }

                                    if (GUILayout.Button("Remove"))
                                    {
                                        NugetHelper.NugetConfigFile.SupportedPlatforms.Remove(platform);
                                        preferencesChangedThisFrame = true;
                                        break;
                                    }
                                }
                                EditorGUILayout.EndHorizontal();

                                EditorGUI.indentLevel++;

                                for (int i = 0; i < platform.LibraryNames.Count; i++)
                                {
                                    string libName = platform.LibraryNames[i];

                                    EditorGUILayout.BeginHorizontal();
                                    {
                                        string name = EditorGUILayout.TextField(libName);
                                        if (name != libName)
                                        {
                                            preferencesChangedThisFrame = true;
                                            platform.LibraryNames[i]    = name;
                                        }

                                        if (GUILayout.Button("Up") && i > 0)
                                        {
                                            // Swap values
                                            platform.LibraryNames[i]     = platform.LibraryNames[i - 1];
                                            platform.LibraryNames[i - 1] = libName;
                                        }

                                        if (GUILayout.Button("Down") && i < (platform.LibraryNames.Count - 1))
                                        {
                                            platform.LibraryNames[i]     = platform.LibraryNames[i + 1];
                                            platform.LibraryNames[i + 1] = libName;
                                        }

                                        if (GUILayout.Button("Remove"))
                                        {
                                            platform.LibraryNames.RemoveAt(i);
                                        }
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }

                                EditorGUI.indentLevel--;
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    if (GUILayout.Button(string.Format("Add New Library")))
                    {
                        platform.LibraryNames.Add("New Library");
                        preferencesChangedThisFrame = true;
                    }
                    EditorGUILayout.EndVertical();
                }

                if (GUILayout.Button(string.Format("Add New Platform")))
                {
                    NugetHelper.NugetConfigFile.SupportedPlatforms.Add(new NugetPackageSupportedPlatform(BuildTargetGroup.Standalone));
                    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);
            }
        }
Пример #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);
            }
        }