-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix nullabiliy in .xaml.cs * Fix nullability in navigation * Fix ChooseModLoaderData * Fix NewsData
- Loading branch information
Showing
31 changed files
with
224 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Natsurainko.FluentLauncher.Classes.Data.UI; | ||
|
||
internal class NewsData | ||
{ | ||
public string ImageUrl { get; set; } | ||
public string? ImageUrl { get; set; } = null!; | ||
|
||
[JsonPropertyName("title")] | ||
public string Title { get; set; } | ||
public string? Title { get; set; } | ||
|
||
[JsonPropertyName("tag")] | ||
public string Tag { get; set; } | ||
public string? Tag { get; set; } | ||
|
||
[JsonPropertyName("date")] | ||
public string Date { get; set; } | ||
public string? Date { get; set; } | ||
|
||
[JsonPropertyName("text")] | ||
public string Text { get; set; } | ||
public string? Text { get; set; } | ||
|
||
[JsonPropertyName("readMoreLink")] | ||
public string ReadMoreUrl { get; set; } | ||
public string? ReadMoreUrl { get; set; } | ||
|
||
|
||
public static NewsData Deserialize(JsonNode node) | ||
{ | ||
NewsData? data = node.Deserialize<NewsData>(); | ||
if (data is null) | ||
throw new JsonException("Failed to deserialize news data"); | ||
|
||
string urlPath = node["newsPageImage"]?["url"]?.GetValue<string>() | ||
?? throw new JsonException("Failed to get news image URL"); | ||
data.ImageUrl = $"https://launchercontent.mojang.com{urlPath}"; | ||
|
||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace Natsurainko.FluentLauncher.Utils; | ||
|
||
internal static class JsonNodeUtils | ||
{ | ||
public static JsonNode ParseFile(string filePath) | ||
{ | ||
JsonNode? jsonNode = null; | ||
try | ||
{ | ||
jsonNode = JsonNode.Parse(File.ReadAllText(filePath)); | ||
} | ||
catch (JsonException) { } | ||
|
||
// jsonNode is null if either | ||
// - the file is not a valid json file, or | ||
// - the file contains the string "null" and JsonNode.Parse(string) returns null. | ||
if (jsonNode is null) | ||
throw new InvalidDataException($"Error in parsing the json file {filePath}."); | ||
|
||
return jsonNode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Natsurainko.FluentLauncher.Utils; | ||
|
||
internal static class LinqExtensions | ||
{ | ||
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source) where T : class | ||
{ | ||
return source.Where(x => x is not null)!; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Natsurainko.FluentLauncher/Utils/NavigationViewItemExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.UI.Xaml.Controls; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Natsurainko.FluentLauncher.Utils; | ||
|
||
internal static class NavigationViewItemExtensions | ||
{ | ||
public static string GetTag(this NavigationViewItem item) | ||
{ | ||
return item.Tag?.ToString() | ||
?? throw new ArgumentNullException("The item's tag is null."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.