From bbc06de4d55debc4fb3bde8d06d286e89f0d6e08 Mon Sep 17 00:00:00 2001 From: DueDine Date: Mon, 30 Dec 2024 13:27:24 +0800 Subject: [PATCH] [fix] No Init when non-DR | [chore] Remove most logging & upgrade SDK version --- ContactsTracker/Configuration.cs | 8 ++-- ContactsTracker/ContactsTracker.csproj | 4 +- ContactsTracker/DataEntry.cs | 1 - ContactsTracker/Database.cs | 20 ++------- ContactsTracker/Plugin.cs | 53 +---------------------- ContactsTracker/packages.lock.json | 58 ++------------------------ 6 files changed, 14 insertions(+), 130 deletions(-) diff --git a/ContactsTracker/Configuration.cs b/ContactsTracker/Configuration.cs index bcf953e..11d1265 100644 --- a/ContactsTracker/Configuration.cs +++ b/ContactsTracker/Configuration.cs @@ -8,15 +8,15 @@ public class Configuration : IPluginConfiguration { public int Version { get; set; } = 0; - public bool EnableLogging { get; set; } = false; + public bool EnableLogging { get; set; } = true; public bool EnableLogParty { get; set; } = false; public bool RecordSolo { get; set; } = false; - public bool PrintToChat { get; set; } = true; + public bool PrintToChat { get; set; } = false; - public bool OnlyDutyRoulette { get; set; } = false; + public bool OnlyDutyRoulette { get; set; } = true; public bool KeepIncompleteEntry { get; set; } = true; @@ -24,7 +24,7 @@ public class Configuration : IPluginConfiguration public int ArchiveWhenEntriesExceed { get; set; } = -1; // -1 means no limit - public int ArchiveKeepEntries { get; set; } = 5; // Remove oldest ArchiveWhenEntriesExceed - ArchiveKeepEntries entries + public int ArchiveKeepEntries { get; set; } = 100; // Remove oldest ArchiveWhenEntriesExceed - ArchiveKeepEntries entries public bool EnableDeleteAll { get; set; } = false; // Dangerous. Disabled by default. diff --git a/ContactsTracker/ContactsTracker.csproj b/ContactsTracker/ContactsTracker.csproj index 04fcc2f..0f6cd2b 100644 --- a/ContactsTracker/ContactsTracker.csproj +++ b/ContactsTracker/ContactsTracker.csproj @@ -1,9 +1,9 @@ - + net8.0-windows - 0.1.0.0 + 0.1.0.1 Help you remember previous contacts. https://github.com/DueDine/ContactsTracker AGPL-3.0-or-later diff --git a/ContactsTracker/DataEntry.cs b/ContactsTracker/DataEntry.cs index 6461ee4..82a588c 100644 --- a/ContactsTracker/DataEntry.cs +++ b/ContactsTracker/DataEntry.cs @@ -57,7 +57,6 @@ public unsafe static void finalize(Configuration configuration) { if (configuration.RecordSolo == false) { - Plugin.Logger.Debug("Solo record is disabled. Ignoring the record."); Reset(); return; } diff --git a/ContactsTracker/Database.cs b/ContactsTracker/Database.cs index 8b55181..ed5e611 100644 --- a/ContactsTracker/Database.cs +++ b/ContactsTracker/Database.cs @@ -44,7 +44,7 @@ public static void Load() } else { - Plugin.Logger.Debug("Failed to load data.json!"); + Plugin.Logger.Verbose("Failed to load data.json!"); } } @@ -59,13 +59,10 @@ public static void Load() var content = File.ReadAllText(tempPath); if (content != null) { - // File.Delete(tempPath); // Remove temp file - Plugin.Logger.Debug("Recover previous entry"); return JsonConvert.DeserializeObject(content); } else { - Plugin.Logger.Debug("Failed to load temp.json!"); return null; } } @@ -83,12 +80,10 @@ public static void Export() var records = JsonConvert.DeserializeObject>(File.ReadAllText(dataPath)); if (records == null) { - Plugin.Logger.Debug("Failed to export data.json!"); return; } else if (records.Count == 0) { - Plugin.Logger.Debug("No records to export."); return; } else @@ -106,7 +101,6 @@ public static bool Import(string filePath) { if (!File.Exists(filePath)) { - Plugin.Logger.Debug("File not found."); return false; } @@ -150,13 +144,11 @@ public static bool Import(string filePath) InsertEntry(entry); } Save(); - Plugin.Logger.Debug($"Imported {importedEntries.Count} entries successfully."); return true; } catch (Exception e) { - Plugin.Logger.Debug("Failed to import."); - Plugin.Logger.Debug(e.Message); + Plugin.Logger.Verbose(e.Message); return false; } } @@ -165,13 +157,11 @@ public static void Archive(Configuration configuration) { if (configuration.ArchiveWhenEntriesExceed == -1) { - Plugin.Logger.Debug("ArchiveWhenEntriesExceed is -1, skipping archive."); return; } if (Entries.Count < configuration.ArchiveWhenEntriesExceed) { - Plugin.Logger.Debug("Entries count is less than ArchiveWhenEntriesExceed, skipping archive."); return; } @@ -181,12 +171,10 @@ public static void Archive(Configuration configuration) if (records == null) { - Plugin.Logger.Debug("Failed to archive data.json!"); return; } else if (records.Count == 0) { - Plugin.Logger.Debug("No records to archive."); return; } else @@ -196,8 +184,6 @@ public static void Archive(Configuration configuration) csv.WriteRecords(records); } - Plugin.ChatGui.Print($"Archived to {archivePath}"); - if (File.Exists(archivePath)) // Then keep newest ArchiveKeepEntries entries { var recordsToKeep = records.Skip(records.Count - configuration.ArchiveKeepEntries).ToList(); @@ -206,7 +192,7 @@ public static void Archive(Configuration configuration) } else { - Plugin.Logger.Debug("Failed to archive data.json!"); + Plugin.Logger.Verbose("Failed to archive."); } } diff --git a/ContactsTracker/Plugin.cs b/ContactsTracker/Plugin.cs index aa33699..ee76cf7 100644 --- a/ContactsTracker/Plugin.cs +++ b/ContactsTracker/Plugin.cs @@ -54,10 +54,6 @@ public Plugin() Database.Load(); - // - // Logger.Debug($"Info: {ClientState.LocalContentId}"); TODO: Character -> CID Mapping - // - ClientState.TerritoryChanged += OnTerritoryChanged; ClientState.CfPop += OnCfPop; ClientState.Logout += OnLogout; @@ -99,36 +95,10 @@ private void OnCommand(string command, string args) } } - /* - private void OnLogon() - { - if (DutyState.IsDutyStarted && ClientState.IsLoggedIn) - { - Logger.Debug("User reconnected. Prepare to recover."); - var territoryName = DataManager.GetExcelSheet()?.GetRow(ClientState.TerritoryType).ContentFinderCondition.Value.Name.ToString(); - if (!string.IsNullOrEmpty(territoryName)) - { - Logger.Debug("Try to recover previous entry"); - var entry = Database.LoadFromTempPath(); - if (entry != null && entry.TerritoryName == territoryName) - { - Logger.Debug("Recovered"); - DataEntry.Initialize(entry); - } - else - { - Logger.Debug("TerritoryName mismatch. Ignore it."); - } - } - } - } - */ - private void OnLogout(int type, int code) { if (DataEntry.Instance != null && DataEntry.Instance.IsCompleted == false && !string.IsNullOrEmpty(DataEntry.Instance.TerritoryName)) { - Logger.Debug("User disconnected. Saving the record."); Database.SaveInProgressEntry(DataEntry.Instance); } } @@ -145,43 +115,34 @@ private void OnTerritoryChanged(ushort territoryID) if (Database.isDirty) { - Logger.Debug("User reconnected. Prepare to recover."); if (!string.IsNullOrEmpty(territoryName)) { - Logger.Debug("Try to recover previous entry"); var entry = Database.LoadFromTempPath(); if (entry != null && entry.TerritoryName == territoryName) { - Logger.Debug("Recovered"); DataEntry.Initialize(entry); } else { - Logger.Debug("TerritoryName mismatch. Ignore it."); + // ignore } Database.isDirty = false; // False whatever the result } return; } - Logger.Debug("Territory Changed"); - Logger.Debug("New Territory: " + (string.IsNullOrEmpty(territoryName) ? "Non Battle Area" : territoryName)); - if (DataEntry.Instance == null) { if (!string.IsNullOrEmpty(territoryName)) { if (Configuration.OnlyDutyRoulette) // If DR, already initialized by CFPop { - Logger.Debug("Duty Roulette Only Mode. No New Entry."); return; } - Logger.Debug("New Entry"); DataEntry.Initialize(null, null, false); } else { - Logger.Debug("Non Battle Area -> No New Entry."); return; } } @@ -198,19 +159,15 @@ private void OnTerritoryChanged(ushort territoryID) } else if (DataEntry.Instance.TerritoryName == territoryName) // Intened to handle rejoin. { - Logger.Debug("Territory Unchanged: " + territoryName); } else { - Logger.Debug("Territory Changed: " + DataEntry.Instance.TerritoryName + " -> " + (string.IsNullOrEmpty(territoryName) ? "Non Battle Area" : territoryName)); - Logger.Debug("Force Finalizing Previous Entry"); if (Configuration.KeepIncompleteEntry) { DataEntry.finalize(Configuration); } else { - Logger.Debug("Do not keep Incomplete. Ignore this."); DataEntry.Reset(); } } @@ -224,7 +181,6 @@ private void OnDutyStarted(object? sender, ushort territoryID) return; } - Logger.Debug("Duty Started: " + territoryID); if (DataEntry.Instance != null) { @@ -244,7 +200,6 @@ private void OnDutyCompleted(object? sender, ushort territoryID) return; } - Logger.Debug("Duty Completed: " + territoryID); if (DataEntry.Instance == null) { @@ -272,22 +227,18 @@ private unsafe void OnCfPop(ContentFinderCondition condition) return; } - Logger.Debug("Finder Pop"); var queueInfo = ContentsFinder.Instance()->QueueInfo; if (queueInfo.PoppedContentType == ContentsFinderQueueInfo.PoppedContentTypes.Roulette) { - Logger.Debug("Roulette Mode"); var type = DataManager.GetExcelSheet()?.GetRow(queueInfo.PoppedContentId).Name.ToString(); DataEntry.Reset(); // Reset. Some may choose to abandon the roulette DataEntry.Initialize(null, type, false); - Logger.Debug("Roulette Type: " + type); } else { - Logger.Debug("Non Roulette Mode"); DataEntry.Reset(); // Handle case where user DR -> Abandon -> Non DR vice versa - DataEntry.Initialize(null, "Normal", false); + // DataEntry.Initialize(null, "Normal", false); } } diff --git a/ContactsTracker/packages.lock.json b/ContactsTracker/packages.lock.json index 8f1e7f2..e58e93c 100644 --- a/ContactsTracker/packages.lock.json +++ b/ContactsTracker/packages.lock.json @@ -16,61 +16,9 @@ }, "DotNet.ReproducibleBuilds": { "type": "Direct", - "requested": "[1.1.1, )", - "resolved": "1.1.1", - "contentHash": "+H2t/t34h6mhEoUvHi8yGXyuZ2GjSovcGYehJrS2MDm2XgmPfZL2Sdxg+uL2lKgZ4M6tTwKHIlxOob2bgh0NRQ==", - "dependencies": { - "Microsoft.SourceLink.AzureRepos.Git": "1.1.1", - "Microsoft.SourceLink.Bitbucket.Git": "1.1.1", - "Microsoft.SourceLink.GitHub": "1.1.1", - "Microsoft.SourceLink.GitLab": "1.1.1" - } - }, - "Microsoft.Build.Tasks.Git": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "AT3HlgTjsqHnWpBHSNeR0KxbLZD7bztlZVj7I8vgeYG9SYqbeFGh0TM/KVtC6fg53nrWHl3VfZFvb5BiQFcY6Q==" - }, - "Microsoft.SourceLink.AzureRepos.Git": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "qB5urvw9LO2bG3eVAkuL+2ughxz2rR7aYgm2iyrB8Rlk9cp2ndvGRCvehk3rNIhRuNtQaeKwctOl1KvWiklv5w==", - "dependencies": { - "Microsoft.Build.Tasks.Git": "1.1.1", - "Microsoft.SourceLink.Common": "1.1.1" - } - }, - "Microsoft.SourceLink.Bitbucket.Git": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "cDzxXwlyWpLWaH0em4Idj0H3AmVo3L/6xRXKssYemx+7W52iNskj/SQ4FOmfCb8YQt39otTDNMveCZzYtMoucQ==", - "dependencies": { - "Microsoft.Build.Tasks.Git": "1.1.1", - "Microsoft.SourceLink.Common": "1.1.1" - } - }, - "Microsoft.SourceLink.Common": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "WMcGpWKrmJmzrNeuaEb23bEMnbtR/vLmvZtkAP5qWu7vQsY59GqfRJd65sFpBszbd2k/bQ8cs8eWawQKAabkVg==" - }, - "Microsoft.SourceLink.GitHub": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "IaJGnOv/M7UQjRJks7B6p7pbPnOwisYGOIzqCz5ilGFTApZ3ktOR+6zJ12ZRPInulBmdAf1SrGdDG2MU8g6XTw==", - "dependencies": { - "Microsoft.Build.Tasks.Git": "1.1.1", - "Microsoft.SourceLink.Common": "1.1.1" - } - }, - "Microsoft.SourceLink.GitLab": { - "type": "Transitive", - "resolved": "1.1.1", - "contentHash": "tvsg47DDLqqedlPeYVE2lmiTpND8F0hkrealQ5hYltSmvruy/Gr5nHAKSsjyw5L3NeM/HLMI5ORv7on/M4qyZw==", - "dependencies": { - "Microsoft.Build.Tasks.Git": "1.1.1", - "Microsoft.SourceLink.Common": "1.1.1" - } + "requested": "[1.2.25, )", + "resolved": "1.2.25", + "contentHash": "xCXiw7BCxHJ8pF6wPepRUddlh2dlQlbr81gXA72hdk4FLHkKXas7EH/n+fk5UCA/YfMqG1Z6XaPiUjDbUNBUzg==" } } }