Skip to content

Commit

Permalink
[fix] No Init when non-DR | [chore] Remove most logging & upgrade SDK…
Browse files Browse the repository at this point in the history
… version
  • Loading branch information
DueDine committed Dec 30, 2024
1 parent 1c6cc8d commit bbc06de
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 130 deletions.
8 changes: 4 additions & 4 deletions ContactsTracker/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ 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;

public bool ArchiveOldEntries { get; set; } = false;

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.

Expand Down
4 changes: 2 additions & 2 deletions ContactsTracker/ContactsTracker.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Dalamud.NET.SDK/11.0.0">
<Project Sdk="Dalamud.NET.SDK/11.2.0">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Version>0.1.0.0</Version>
<Version>0.1.0.1</Version>
<Description>Help you remember previous contacts.</Description>
<PackageProjectUrl>https://github.com/DueDine/ContactsTracker</PackageProjectUrl>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
Expand Down
1 change: 0 additions & 1 deletion ContactsTracker/DataEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 3 additions & 17 deletions ContactsTracker/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}

Expand All @@ -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<DataEntry>(content);
}
else
{
Plugin.Logger.Debug("Failed to load temp.json!");
return null;
}
}
Expand All @@ -83,12 +80,10 @@ public static void Export()
var records = JsonConvert.DeserializeObject<List<DataEntry>>(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
Expand All @@ -106,7 +101,6 @@ public static bool Import(string filePath)
{
if (!File.Exists(filePath))
{
Plugin.Logger.Debug("File not found.");
return false;
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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.");
}

}
Expand Down
53 changes: 2 additions & 51 deletions ContactsTracker/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TerritoryType>()?.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);
}
}
Expand All @@ -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;
}
}
Expand All @@ -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();
}
}
Expand All @@ -224,7 +181,6 @@ private void OnDutyStarted(object? sender, ushort territoryID)
return;
}

Logger.Debug("Duty Started: " + territoryID);

if (DataEntry.Instance != null)
{
Expand All @@ -244,7 +200,6 @@ private void OnDutyCompleted(object? sender, ushort territoryID)
return;
}

Logger.Debug("Duty Completed: " + territoryID);

if (DataEntry.Instance == null)
{
Expand Down Expand Up @@ -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<ContentRoulette>()?.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);
}
}

Expand Down
58 changes: 3 additions & 55 deletions ContactsTracker/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=="
}
}
}
Expand Down

0 comments on commit bbc06de

Please sign in to comment.