Save() public method

Saves this NuGet.config file to disk.
public Save ( string filepath ) : void
filepath string The filepath to where this NuGet.config will be saved.
return void
        /// <summary>
        /// Creates a NuGet.config file with the default settings at the given full filepath.
        /// </summary>
        /// <param name="filePath">The full filepath where to create the NuGet.config file.</param>
        /// <returns>The loaded <see cref="NugetConfigFile"/> loaded off of the newly created default file.</returns>
        public static NugetConfigFile CreateDefaultFile(string filePath)
        {
            NugetConfigFile configFile = new NugetConfigFile();

            configFile.InstallFromCache     = true;
            configFile.ReadOnlyPackageFiles = true;

            // Add the default values
            PopulateDefaultValues(ref configFile);

            configFile.Save(filePath);

            AssetDatabase.Refresh();

            NugetHelper.DisableWSAPExportSetting(filePath, false);

            return(configFile);
        }
Ejemplo n.º 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;
            }
        }