5using System.Collections.Generic;
7using System.Threading.Tasks;
41 return ProcessOutputReader.ToSourceList(result.Output);
62 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName,
"sourceName");
66 return ProcessOutputReader.ToSourceList(result.Output);
87 if (cancellationToken.IsCancellationRequested)
89 return new List<WinGetSource>();
92 return ProcessOutputReader.ToSourceList(result.Output);
117 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName,
"sourceName");
122 if (cancellationToken.IsCancellationRequested)
124 return new List<WinGetSource>();
127 return ProcessOutputReader.ToSourceList(result.Output);
158 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name,
"name");
159 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(arg,
"arg");
161 ProcessResult result =
167 .AcceptSourceAgreements(),
170 return result.Success;
200 public bool AddSource(
string name,
string arg,
string type)
202 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name,
"name");
203 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(arg,
"arg");
204 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(type,
"type");
206 ProcessResult result =
213 .AcceptSourceAgreements(),
216 return result.Success;
242 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(source,
"source");
244 if (
string.IsNullOrWhiteSpace(source.
Type))
270 public bool AddSource(IEnumerable<WinGetSource> sources)
272 ArgsHelper.ThrowIfObjectIsNull(sources,
"sources");
314 public async Task<bool>
AddSourceAsync(
string name,
string arg, CancellationToken cancellationToken =
default)
316 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name,
"name");
317 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(arg,
"arg");
319 ProcessResult result =
325 .AcceptSourceAgreements(),
326 true, cancellationToken);
328 return result.Success;
362 public async Task<bool>
AddSourceAsync(
string name,
string arg,
string type, CancellationToken cancellationToken =
default)
364 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name,
"name");
365 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(arg,
"arg");
366 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(type,
"type");
368 ProcessResult result =
375 .AcceptSourceAgreements(),
376 true, cancellationToken);
378 return result.Success;
408 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(source,
"source");
410 if (
string.IsNullOrWhiteSpace(source.
Type))
443 public async Task<bool>
AddSourceAsync(IEnumerable<WinGetSource> sources, CancellationToken cancellationToken =
default)
445 ArgsHelper.ThrowIfObjectIsNull(sources,
"sources");
450 if (cancellationToken.IsCancellationRequested)
482 return result.Success;
505 return result.Success;
548 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file,
"file");
549 ArgsHelper.ThrowIfPathIsInvalid(file);
551 FileHelper.WriteTextToFile(
596 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file,
"file");
597 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName,
"sourceName");
598 ArgsHelper.ThrowIfPathIsInvalid(file);
600 FileHelper.WriteTextToFile(
649 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(source,
"source");
650 ArgsHelper.ThrowIfPathIsInvalid(file);
699 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file,
"file");
700 ArgsHelper.ThrowIfPathIsInvalid(file);
702 await FileHelper.WriteTextToFileAsync(
753 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(file,
"file");
754 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(sourceName,
"sourceName");
755 ArgsHelper.ThrowIfPathIsInvalid(file);
757 await FileHelper.WriteTextToFileAsync(
813 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(source,
"source");
814 ArgsHelper.ThrowIfPathIsInvalid(file);
847 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(jsonString,
"jsonString");
849 List<SourceModel> sources = JsonHelper.StringToObject<List<SourceModel>>(jsonString);
852 for (
int i = 0; i < sources.Count; i++)
893 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(jsonString,
"jsonString");
895#if NETCOREAPP3_1_OR_GREATER
896 List<SourceModel> sources =
897 await JsonHelper.StringToObjectAsync<List<SourceModel>>(jsonString, cancellationToken);
899 List<SourceModel> sources =
900 JsonHelper.StringToObject<List<SourceModel>>(jsonString);
904 for (
int i = 0; i < sources.Count; i++)
906 if (cancellationToken.IsCancellationRequested)
941 return result.Success;
967 return result.Success;
995 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name,
"name");
999 return result.Success;
1025 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(source,
"source");
1057 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name,
"name");
1061 return result.Success;
1091 ArgsHelper.ThrowIfWinGetObjectIsNullOrEmpty(source,
"source");
1110#pragma warning disable S2325
1112#pragma warning restore S2325
1114 ArgsHelper.ThrowIfObjectIsNull(sources,
"sources");
1117 List<SourceModel> models =
new();
1120 models.Add(SourceModel.FromWinGetSource(source));
1123 return JsonHelper.GetJson(models);
The WGetNET.WinGet class offers informations about the installed winget version.
The WGetNET.WinGetSourceManager class offers methods to manage the sources used by winget.
async Task< bool > RemoveSourcesAsync(string name, CancellationToken cancellationToken=default)
Asynchronously removes a source from winget (Needs administrator rights).
bool AddSource(string name, string arg)
Adds a new source to winget (Needs administrator rights).
async Task< bool > AddSourceAsync(string name, string arg, CancellationToken cancellationToken=default)
Asynchronously adds a new source to winget (Needs administrator rights).
bool AddSource(string name, string arg, string type)
Adds a new source to winget (Needs administrator rights).
WinGetSourceManager()
Initializes a new instance of the WGetNET.WinGetSourceManager class.
bool AddSource(IEnumerable< WinGetSource > sources)
Adds multiple new sources to winget (Needs administrator rights).
bool ImportSourcesFromJson(string jsonString)
Imports sources into winget from a json string.
bool RemoveSources(WinGetSource source)
Removes a source from winget (Needs administrator rights).
async Task ExportSourcesToFileAsync(string file, CancellationToken cancellationToken=default)
Asynchronously exports the winget sources in json format to a file.
string SourcesToJson(IEnumerable< WinGetSource > sources)
Generates a valid json string from the provided sources.
async Task< bool > AddSourceAsync(WinGetSource source, CancellationToken cancellationToken=default)
Asynchronously adds a new source to winget (Needs administrator rights).
bool AddSource(WinGetSource source)
Adds a new source to winget (Needs administrator rights).
void ExportSourcesToFile(string file)
Exports the winget sources in json format to a file.
async Task ExportSourcesToFileAsync(string file, string sourceName, CancellationToken cancellationToken=default)
Asynchronously exports the winget sources in json format to a file.
bool RemoveSources(string name)
Removes a source from winget (Needs administrator rights).
async Task< bool > AddSourceAsync(string name, string arg, string type, CancellationToken cancellationToken=default)
Asynchronously adds a new source to winget (Needs administrator rights).
async Task< List< WinGetSource > > GetInstalledSourcesAsync(string sourceName, CancellationToken cancellationToken=default)
Asynchronously gets a list of installed sources that matches the provided name.
async Task< List< WinGetSource > > GetInstalledSourcesAsync(CancellationToken cancellationToken=default)
Asynchronously gets a list of all sources that are installed in winget.
List< WinGetSource > GetInstalledSources()
Gets a list of all sources that are installed in winget.
async Task ExportSourcesToFileAsync(string file, WinGetSource source, CancellationToken cancellationToken=default)
Asynchronously exports the winget sources in json format to a file.
async Task< bool > RemoveSourcesAsync(WinGetSource source, CancellationToken cancellationToken=default)
Asynchronously removes a source from winget (Needs administrator rights).
List< WinGetSource > GetInstalledSources(string sourceName)
Gets a list of installed sources that matches the provided name.
async Task< bool > ResetSourcesAsync(CancellationToken cancellationToken=default)
Asynchronously resets all sources that are installed in winget (Needs administrator rights).
async Task< bool > UpdateSourcesAsync(CancellationToken cancellationToken=default)
Asynchronously updates all sources that are installed in winget.
void ExportSourcesToFile(string file, WinGetSource source)
Exports the winget sources in json format to a file.
void ExportSourcesToFile(string file, string sourceName)
Exports the winget sources in json format to a file.
async Task< bool > ImportSourcesFromJsonAsync(string jsonString, CancellationToken cancellationToken=default)
Asynchronously imports sources into winget from a json string.
bool ResetSources()
Resets all sources that are installed in winget (Needs administrator rights).
async Task< bool > AddSourceAsync(IEnumerable< WinGetSource > sources, CancellationToken cancellationToken=default)
Asynchronously adds multiple new sources to winget (Needs administrator rights).
bool UpdateSources()
Updates all sources that are installed in winget.
Represents a winget arguments string for different winget actions.
static WinGetArguments SourceUpdate()
Creates a new winget arguments object with "source update" as the base cmd.
WinGetArguments Name(string name)
Adds name data to the arguments.
WinGetArguments Force()
Adds the '–force' flag to the arguments.
static WinGetArguments SourceReset()
Creates a new winget arguments object with "source reset" as the base cmd.
static WinGetArguments SourceExport()
Creates a new winget arguments object with "source export" as the base cmd.
static WinGetArguments SourceRemove()
Creates a new winget arguments object with "source remove" as the base cmd.
Represents a winget source.
string Name
Gets the name of the source.
string Type
Gets the type of the source.
string Arg
Gets the URL/UNC of the source.