Misc fixes

This commit is contained in:
Natsumi
2025-01-20 21:56:33 +13:00
parent 95d5486cdb
commit 555d4adf60
8 changed files with 60 additions and 49 deletions
+5 -8
View File
@@ -116,14 +116,11 @@ public partial class AppApi
var path = GetVRChatPhotosLocation();
if (!Directory.Exists(path))
return null;
var lastDirectory = Directory.GetDirectories(path).OrderByDescending(Directory.GetCreationTime).FirstOrDefault();
if (lastDirectory == null)
return null;
var lastScreenshot = Directory.GetFiles(lastDirectory, "*.png").OrderByDescending(File.GetCreationTime).FirstOrDefault();
if (lastScreenshot == null)
return null;
// exclude folder names that contain "Prints" or "Stickers"
var imageFiles = Directory.GetFiles(path, "*.png", SearchOption.AllDirectories)
.Where(x => !Regex.IsMatch(x, @"\\Prints\\|\\Stickers\\", RegexOptions.IgnoreCase));
var lastScreenshot = imageFiles.OrderByDescending(Directory.GetCreationTime).FirstOrDefault();
return lastScreenshot;
}
+6 -10
View File
@@ -76,16 +76,17 @@ namespace VRCX
if (metadata == null || metadata.Error != null)
{
addToCache.Add(dbEntry);
metadataCache.Add(file, null);
metadataCache.TryAdd(file, null);
continue;
}
dbEntry.Metadata = JsonConvert.SerializeObject(metadata);
addToCache.Add(dbEntry);
metadataCache.Add(file, metadata);
metadataCache.TryAdd(file, metadata);
}
if (metadata == null) continue;
if (metadata == null)
continue;
switch (searchType)
{
@@ -121,18 +122,13 @@ namespace VRCX
return result;
}
/// <summary>
/// Retrieves metadata from a PNG screenshot file and attempts to parse it.
/// </summary>
/// <param name="path">The path to the PNG screenshot file.</param>
/// <returns>A JObject containing the metadata or null if no metadata was found.</returns>
public static ScreenshotMetadata GetScreenshotMetadata(string path, bool includeJSON = false)
public static ScreenshotMetadata? GetScreenshotMetadata(string path, bool includeJSON = false)
{
// Early return if file doesn't exist, or isn't a PNG(Check both extension and file header)
if (!File.Exists(path) || !path.EndsWith(".png") || !IsPNGFile(path))
return null;
///if (metadataCache.TryGetValue(path, out var cachedMetadata))
// if (metadataCache.TryGetValue(path, out var cachedMetadata))
// return cachedMetadata;
string metadataString;
@@ -57,7 +57,7 @@ namespace VRCX
/// Any error that occurred while parsing the file. This being true implies nothing else is set.
/// </summary>
[JsonIgnore]
internal string Error;
internal string? Error;
[JsonIgnore]
internal string JSON;