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