Add method to get unique report GUID

This commit is contained in:
2026-04-03 18:16:28 +09:00
parent a2452e2585
commit 2092f15580
+36 -1
View File
@@ -6,6 +6,7 @@ using System.IO;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using MayShow.Models;
using Tmds.DBus.Protocol; using Tmds.DBus.Protocol;
namespace MayShows.Helpers; namespace MayShows.Helpers;
@@ -66,11 +67,45 @@ class Utilities
public static string GetTempConvertedImagesFolderPath() public static string GetTempConvertedImagesFolderPath()
{ {
// get converted files directory path and create it if necessary // get converted files directory path and create it if necessary
var convertedDir = Path.Combine(Utilities.GetInternalDataPath(), "converted"); var convertedDir = Path.Combine(GetInternalDataPath(), "converted");
if (!Directory.Exists(convertedDir)) if (!Directory.Exists(convertedDir))
{ {
Directory.CreateDirectory(convertedDir); Directory.CreateDirectory(convertedDir);
} }
return convertedDir; return convertedDir;
} }
public static Guid GetUniqueReportGuid(Settings settings)
{
// Guid should be, well, unique already, BUT we are not going to take ANY chances.
var internalPath = GetInternalDataPath();
Guid guid = Guid.NewGuid();
var isUnique = false;
while (!isUnique)
{
var strUUID = guid.ToString();
var didFind = false;
foreach (var existingReport in settings.AllReportInfo)
{
if (existingReport.UUID == strUUID)
{
didFind = true;
break;
}
}
if (Directory.Exists(Path.Combine(internalPath, strUUID)))
{
didFind = true;
}
if (!didFind)
{
isUnique = true;
}
else
{
guid = Guid.NewGuid();
}
}
return guid;
}
} }