ParseRating -> TryParseRating

This commit is contained in:
Colin McMillen 2023-07-25 09:54:41 -04:00
parent a33304ae7d
commit cb01d1dbea

View File

@ -166,7 +166,7 @@ public class Photo {
public async void Load() { public async void Load() {
image = await Image.LoadAsync<Rgba32>(File); image = await Image.LoadAsync<Rgba32>(File);
ParseRating(image); TryParseRating(image.Metadata.XmpProfile, out Rating);
ExifProfile? exifs = image.Metadata.ExifProfile; ExifProfile? exifs = image.Metadata.ExifProfile;
if (exifs != null) { if (exifs != null) {
// FIXME: handle Orientation // FIXME: handle Orientation
@ -240,27 +240,27 @@ public class Photo {
} }
} }
private void ParseRating(Image image) { private bool TryParseRating(XmpProfile? xmp, out int rating) {
XmpProfile? xmp = image.Metadata.XmpProfile; rating = 0;
if (xmp == null) { if (xmp == null) {
return; return false;
} }
XDocument? doc = xmp.GetDocument(); XDocument? doc = xmp.GetDocument();
if (doc == null) { if (doc == null) {
return; return false;
} }
XElement? root = doc.Root; XElement? root = doc.Root;
if (root == null) { if (root == null) {
return; return false;
} }
foreach (XElement elt in root.Descendants()) { foreach (XElement elt in root.Descendants()) {
if (elt.Name == "{http://ns.adobe.com/xap/1.0/}Rating") { if (elt.Name == "{http://ns.adobe.com/xap/1.0/}Rating") {
int rating;
if (int.TryParse(elt.Value, out rating)) { if (int.TryParse(elt.Value, out rating)) {
Rating = rating; return true;
} }
} }
} }
return false;
} }
public Texture Texture() { public Texture Texture() {