From 2092f1558091ed0af8fac089e9a64848ec8a1fe4 Mon Sep 17 00:00:00 2001 From: Michael Babienco Date: Fri, 3 Apr 2026 18:16:28 +0900 Subject: [PATCH] Add method to get unique report GUID --- src/MayShow.Shared/Helpers/Utilities.cs | 37 ++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/MayShow.Shared/Helpers/Utilities.cs b/src/MayShow.Shared/Helpers/Utilities.cs index 66b40c0..8add352 100644 --- a/src/MayShow.Shared/Helpers/Utilities.cs +++ b/src/MayShow.Shared/Helpers/Utilities.cs @@ -6,6 +6,7 @@ using System.IO; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions; +using MayShow.Models; using Tmds.DBus.Protocol; namespace MayShows.Helpers; @@ -66,11 +67,45 @@ class Utilities public static string GetTempConvertedImagesFolderPath() { // 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)) { Directory.CreateDirectory(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; + } } \ No newline at end of file