diff --git a/src/DP/DPDatabase.Abstraction.cs b/src/DP/DPDatabase.Abstraction.cs index 2f5cb88..bc499b8 100644 --- a/src/DP/DPDatabase.Abstraction.cs +++ b/src/DP/DPDatabase.Abstraction.cs @@ -7,11 +7,6 @@ using System.Threading; using System.Data.SQLite; using System.IO; -using DAZ_Installer.External; -using System.Data.Entity.Core.Objects; -using System.Linq; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; -using System.Security.Cryptography; namespace DAZ_Installer.DP { @@ -917,10 +912,15 @@ private static void InsertRecords(DPProductRecord pRecord, DPExtractionRecord eR connection = CreateAndOpenConnection(c); if (connection == null) return; - object[] pObjs = new object[] { productName, JoinString(", ", tags), author, sku, time.ToFileTimeUtc(), thumbnailPath }; - object[] eObjs = new object[] { archiveFileName, JoinString(", ", files), - JoinString(", ", folders), destPath, JoinString(", ", erroredFiles), - JoinString(", ", erroredMessages) }; + // Shorten strings if applicable. + productName = productName?.Length > 70 ? productName.Substring(0, 70) : productName; + author = author?.Length > 30 ? author.Substring(0, 30) : author; + sku = sku?.Length > 10 ? sku.Substring(0, 10) : sku; + + object[] pObjs = new object[] { productName, JoinString(", ", 70, tags), author, sku, time.ToFileTimeUtc(), thumbnailPath }; + object[] eObjs = new object[] { archiveFileName, JoinString(", ", 384, files), + JoinString(", ", 384, folders), destPath, JoinString(", ", 384, erroredFiles), + JoinString(", ", 65536, erroredMessages) }; // If both operations are successful, emit signal. if (InsertValuesToTable("ProductRecords", pColumns, pObjs, connection, t)) @@ -1026,7 +1026,13 @@ private static bool UpdateProductRecord(uint pid, DPProductRecord newRecord, SQL return false; newRecord.Deconstruct(out var productName, out var tags, out var author, out var sku, out var time, out var thumbnailPath, out var eid, out var _); - object[] pObjs = new object[] { productName, JoinString(", ", tags), author, sku, time.ToFileTimeUtc(), thumbnailPath, eid }; + + // Shorten strings if applicable. + productName = productName?.Length > 70 ? productName.Substring(0, 70) : productName; + author = author?.Length > 30 ? author.Substring(0, 30) : author; + sku = sku?.Length > 10 ? sku.Substring(0, 10) : sku; + + object[] pObjs = new object[] { productName, JoinString(", ", 70, tags), author, sku, time.ToFileTimeUtc(), thumbnailPath, eid }; SQLiteConnection connection = null; SQLiteTransaction transaction = null; SQLiteCommand sqlCommand = null; @@ -1099,9 +1105,9 @@ private static bool UpdateExtractionRecord(uint eid, DPExtractionRecord newRecor return false; newRecord.Deconstruct(out var archiveFileName, out var destPath, out var files, out var erroredFiles, out var erroredMessages, out var folders, out var newPID); - object[] eObjs = new object[] { archiveFileName, JoinString(", ", files), - JoinString(", ", folders), destPath, JoinString(", ", erroredFiles), - JoinString(", ", erroredMessages), newPID }; + object[] eObjs = new object[] { archiveFileName, JoinString(", ", 384, files), + JoinString(", ", 384, folders), destPath, JoinString(", ", 384, erroredFiles), + JoinString(", ", 65536, erroredMessages), newPID }; SQLiteConnection connection = null; SQLiteTransaction transaction = null; SQLiteCommand sqlCommand = null; @@ -1192,24 +1198,28 @@ private static void TruncateJournal() } /// /// Similar to string.Join() but will skip values that are null or empty (after trim). + /// /// can be null and will return null. Otherwise, seperator must not /// be null, otherwise an exception will be thrown. + /// + /// Additionally, you can set the max size of each string value. The default is 256. Meaning, for each + /// tag, the value will be trimmed to 256 characters if the value exceeds that size. /// /// The seperator to add in between values in string. Cannot be null. + /// The maximum string size of each value. Default is 256. /// The values to join. /// The values combined into a string seperated by the sepertor or null if values is null. - private static string? JoinString(string seperator, params string[] values) + private static string? JoinString(string seperator, int maxSize = 256, params string[] values) { if (values == null || values.Length == 0) return null; StringBuilder builder = new StringBuilder(512); for (int i = 0; i < values.Length; i++) { - if (values[i] == null) continue; - if (values[i].Trim() != string.Empty) - { - builder.Append(values[i] + seperator); - } + var s = values[i]; + if (string.IsNullOrWhiteSpace(s)) continue; + builder.Append(s.Length > maxSize ? s[..maxSize] : s); + builder.Append(seperator); } builder.Remove(builder.Length - seperator.Length, seperator.Length); return builder.ToString(); diff --git a/src/DP/DPDatabase.Public.cs b/src/DP/DPDatabase.Public.cs index e48ae63..e1a143f 100644 --- a/src/DP/DPDatabase.Public.cs +++ b/src/DP/DPDatabase.Public.cs @@ -2,7 +2,6 @@ using System.Data; using System.Collections.Generic; using System.Data.SQLite; -using System.Threading.Tasks; namespace DAZ_Installer.DP { diff --git a/src/DP/DPDatabase.QueryProcessing.cs b/src/DP/DPDatabase.QueryProcessing.cs index 4d29973..0559786 100644 --- a/src/DP/DPDatabase.QueryProcessing.cs +++ b/src/DP/DPDatabase.QueryProcessing.cs @@ -2,12 +2,9 @@ // You may find a full copy of this license at root project directory\LICENSE using System; using System.Data; -using System.Collections.Generic; using System.Text; -using System.Linq; using System.Threading; using System.Data.SQLite; -using System.IO; using DAZ_Installer.External; namespace DAZ_Installer.DP diff --git a/src/DP/DPDatabase.cs b/src/DP/DPDatabase.cs index fa2b942..e57f38a 100644 --- a/src/DP/DPDatabase.cs +++ b/src/DP/DPDatabase.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using System.Data.SQLite; using System.IO; -using DAZ_Installer.External; namespace DAZ_Installer.DP {