Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to include the new JSON Structure with Explicit and TrustLevel #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/WGet.NET/Data/WinGetSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using WGetNET.Models;
using WGetNET.Helper;
using System.Collections.Generic;

namespace WGetNET
{
Expand Down Expand Up @@ -82,6 +83,29 @@ public string Identifier
}
}

/// <summary>
/// Gets whether the source was explicitly added.
/// </summary>
public bool Explicit
{
get
{
return _explicit;
}
}

/// <summary>
/// Gets the trust level of the source.
/// </summary>
public List<string> TrustLevel
{
get
{
return _trustLevel;
}
}


/// <inheritdoc/>
public bool IsEmpty
{
Expand All @@ -105,6 +129,8 @@ public bool IsEmpty
private readonly string _type;
private readonly string _data;
private readonly string _identifier;
private readonly bool _explicit;
private readonly List<string> _trustLevel;

/// <summary>
/// Initializes a new instance of the <see cref="WGetNET.WinGetSource"/> class.
Expand All @@ -115,13 +141,17 @@ public bool IsEmpty
/// <param name="type">Type identifier of the source.</param>
/// <param name="data">Data of the source source. This field is only used by some sources.</param>
/// <param name="identifier">The identifier of the package</param>
internal WinGetSource(string name, string arg, Uri? uri, string type, string identifier, string? data = null)
/// <param name="explicitSource">Indicates if the source was explicitly added.</param>
/// <param name="trustLevel">Trust level of the source.</param>
internal WinGetSource(string name, string arg, Uri? uri, string type, string identifier, bool explicitSource = false, List<string>? trustLevel = default, string? data = null)
{
_name = name;
_arg = arg;
_uri = uri;
_type = type;
_identifier = identifier;
_explicit = explicitSource;
_trustLevel = trustLevel;

if (data != null)
{
Expand Down Expand Up @@ -188,7 +218,7 @@ public static WinGetSource Create(string name, string identifier, string arg, st

Uri.TryCreate(arg, UriKind.Absolute, out Uri? uri);

return new WinGetSource(name, arg, uri, type, identifier, data);
return new WinGetSource(name, arg, uri, type, identifier,data: data);
}

/// <summary>
Expand All @@ -202,7 +232,7 @@ internal static WinGetSource FromSourceModel(SourceModel model)
{
Uri.TryCreate(model.Arg, UriKind.Absolute, out Uri? uri);

return new WinGetSource(model.Name, model.Arg, uri, model.Type, model.Identifier, model.Data);
return new WinGetSource(model.Name, model.Arg, uri, model.Type, model.Identifier,model.Explicit, model.TrustLevel, model.Data);
}

/// <inheritdoc/>
Expand All @@ -214,6 +244,8 @@ public object Clone()
_uri,
_type,
_identifier,
_explicit,
_trustLevel,
_data
);
}
Expand Down
51 changes: 47 additions & 4 deletions src/WGet.NET/Models/SourceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// Created by basicx-StrgV //
// https://github.com/basicx-StrgV/ //
//--------------------------------------------------//
using System.Collections.Generic;

namespace WGetNET.Models
{
/// <summary>
/// Represents a winget source for json parsing.
/// Represents a winget source for JSON parsing.
/// </summary>
internal class SourceModel
{
Expand Down Expand Up @@ -54,7 +56,7 @@ public string Arg
}

/// <summary>
/// Gets sets the type of the source.
/// Gets or sets the type of the source.
/// </summary>
public string Type
{
Expand Down Expand Up @@ -119,18 +121,57 @@ public string Identifier
}
}

/// <summary>
/// Gets or sets whether the source was explicitly added.
/// </summary>
public bool Explicit
{
get
{
return _explicit;
}
set
{
_explicit = value;
}
}

/// <summary>
/// Gets or sets the trust level of the source.
/// </summary>
public List<string> TrustLevel
{
get
{
return _trustLevel;
}
set
{
if (value != null)
{
_trustLevel = value;
}
else
{
_trustLevel = new List<string>();
}
}
}

private string _name = string.Empty;
private string _arg = string.Empty;
private string _type = string.Empty;
private string _data = string.Empty;
private string _identifier = string.Empty;
private bool _explicit;
private List<string> _trustLevel = new List<string>();

/// <summary>
/// Initializes a new instance of the <see cref="WGetNET.Models.SourceModel"/> class.
/// </summary>
internal SourceModel()
{
// Empty constructor for json parsing.
// Empty constructor for JSON parsing.
}

/// <summary>
Expand All @@ -148,7 +189,9 @@ public static SourceModel FromWinGetSource(WinGetSource source)
Arg = source.Arg,
Type = source.Type,
Data = source.Data,
Identifier = source.Identifier
Identifier = source.Identifier,
Explicit = source.Explicit,
TrustLevel = source.TrustLevel
};
}
}
Expand Down
Loading