Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: |
release_kind=(--latest)
if grep -q "^Prerelease\b" "$RUNNER_TEMP/lifetimestats-release/release-notes.md"; then
release_kind=(--prerelease)
fi
gh release create "$GITHUB_REF_NAME" \
"$RUNNER_TEMP/lifetimestats-release/LifeTimeStats-${GITHUB_REF_NAME#v}.zip" \
"$RUNNER_TEMP/lifetimestats-release/LifeTimeStats-${GITHUB_REF_NAME#v}.zip.sha256" \
--repo "$GITHUB_REPOSITORY" \
--title "LifeTimeStats $GITHUB_REF_NAME" \
--notes-file "$RUNNER_TEMP/lifetimestats-release/release-notes.md" \
--verify-tag \
--latest
"${release_kind[@]}"
145 changes: 113 additions & 32 deletions Backup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ local function SortedKeys(t)
return keys
end

local function CaptureLegacyBody(rec)
local function CaptureLegacyBody(rec, progress)
local parts = {}
local function Emit(part)
parts[#parts + 1] = part
if progress and #parts % 512 == 0 then progress("Encoding statistics", #parts) end
end
for _, sec in ipairs(FLAT) do
local t = rec[sec] or {}
for _, k in ipairs(SortedKeys(t)) do
if type(t[k]) ~= "table" then parts[#parts + 1] = sec .. "." .. Esc(k) .. "=" .. Val(t[k]) end
if type(t[k]) ~= "table" then Emit(sec .. "." .. Esc(k) .. "=" .. Val(t[k])) end
end
end
for _, sec in ipairs(NESTED) do
Expand All @@ -59,7 +63,7 @@ local function CaptureLegacyBody(rec)
if type(inner) == "table" then
for _, k in ipairs(SortedKeys(inner)) do
if type(inner[k]) ~= "table" then
parts[#parts + 1] = sec .. "." .. Esc(g) .. "." .. Esc(k) .. "=" .. Val(inner[k])
Emit(sec .. "." .. Esc(g) .. "." .. Esc(k) .. "=" .. Val(inner[k]))
end
end
end
Expand Down Expand Up @@ -176,10 +180,27 @@ function ns.ReadLegacyBackup(text, finished, status)
end

function ns.WriteLegacyBackup(rec, finished, status)
-- Capture without yielding so counters cannot change during collection.
local ok, body = pcall(CaptureLegacyBody, rec)
if not ok then finished(nil, body); return end
return RunBackupJob(body, EncodeLegacyBody, EncodeLegacyBody, finished, status)
local function CopyScalars(source)
local out = {}
for k, v in pairs(type(source) == "table" and source or {}) do
local kind = type(v)
if kind == "number" or kind == "string" or kind == "boolean" then out[k] = v end
end
return out
end
local captured = {}
for _, field in ipairs(FLAT) do captured[field] = CopyScalars(rec[field]) end
for _, field in ipairs(NESTED) do
local out = {}
for group, bucket in pairs(rec[field] or {}) do
if type(bucket) == "table" then out[group] = CopyScalars(bucket) end
end
captured[field] = out
end
local function Encode(input, progress)
return EncodeLegacyBody(CaptureLegacyBody(input, progress), progress)
end
return RunBackupJob(captured, Encode, Encode, finished, status)
end

local function MergeHistory(dst, src)
Expand Down Expand Up @@ -791,7 +812,7 @@ function ns.IsFullBackup(text)
return type(text) == "string" and not IsSecret(text) and text:match("^%s*LTS3|") ~= nil
end

local function CaptureFullSnapshot()
local function FullSnapshotSource()
Require(ns.ValidRecord(ns.char) and Key(ns.charKey), "The active character is unavailable.")
local record = { meta = {} }
for _, field in ipairs(FULL_FIELDS) do
Expand All @@ -801,7 +822,11 @@ local function CaptureFullSnapshot()
end
end
for field in pairs(FULL_META) do record.meta[field] = ns.char.meta[field] end
local snapshot = StageFullSnapshot({ character = ns.charKey, savedAt = time(), record = record }, true)
return { character = ns.charKey, savedAt = time(), record = record }
end

local function ValidateExport(source, progress)
local snapshot = StageFullSnapshot(source, true, progress)
snapshot.noteCount = nil -- Derived during preview, never trusted from a pasted backup.
return snapshot
end
Expand All @@ -812,15 +837,37 @@ local function EncodeFullSnapshot(snapshot, progress)
end

function ns.SerializeFullBackup()
return Attempt(function() return EncodeFullSnapshot(CaptureFullSnapshot()) end)
return Attempt(function() return EncodeFullSnapshot(ValidateExport(FullSnapshotSource())) end)
end

function ns.WriteFullBackup(finished, status)
-- Validation makes a detached snapshot. Only encoding that copy may yield.
local snapshot, why = Attempt(CaptureFullSnapshot)
if not snapshot then finished(nil, why); return end
return RunBackupJob(snapshot, EncodeFullSnapshot, function(input)
return Attempt(function() return EncodeFullSnapshot(input) end)
-- Only copy mutable tables in the click handler. Validate and format the
-- detached values later, so events cannot change an export mid-job.
local captured, why = Attempt(function()
local count, active = 0, {}
local function Copy(value, depth)
Require(not IsSecret(value), "The full backup contains unreadable data.")
if type(value) ~= "table" then return value end
Require(PlainTable(value) and not active[value] and depth <= MAX_FULL_DEPTH,
"The full backup contains invalid data.")
active[value] = true
local out = {}
for key, item in pairs(value) do
count = count + 1
Require(count <= MAX_FULL_NODES, "The full backup contains too many entries.")
out[key] = Copy(item, depth + 1)
end
active[value] = nil
return out
end
return Copy(FullSnapshotSource(), 1)
end)
if not captured then finished(nil, why); return end
local function Encode(input, progress)
return EncodeFullSnapshot(ValidateExport(input, progress), progress)
end
return RunBackupJob(captured, Encode, function(input)
return Attempt(function() return Encode(input) end)
end, finished, status)
end

Expand All @@ -843,26 +890,24 @@ function ns.DeserializeFullBackup(text)
return Attempt(function() return ReadFullSnapshot(text) end)
end

function ns.ReadFullBackup(text, finished, status)
return RunBackupJob(text, ReadFullSnapshot, ns.DeserializeFullBackup, finished, status)
end

function ns.RestoreFullBackup(snapshot)
local destination, character = ns.char, ns.charKey
local staged, reason = Attempt(function()
Require(ns.ValidRecord(destination) and Key(character) and type(ns.db) == "table"
and type(ns.db.chars) == "table" and type(LifeTimeStatsCharDB) == "table", "The active character is unavailable.")
Require(PlainTable(snapshot) and snapshot.character == character, "This full backup belongs to a different character.")
return StageFullSnapshot(snapshot).record
end)
if not staged then return false, reason end

local uniqueCounts = {}
for set, values in pairs(staged.u) do
local function CountFullUniques(record, progress)
local uniqueCounts, total = {}, 0
for set, values in pairs(record.u) do
local count = 0
for _ in pairs(values) do count = count + 1 end
for _ in pairs(values) do
count, total = count + 1, total + 1
if progress and total % 512 == 0 then progress("Counting discoveries", total) end
end
uniqueCounts[set] = count
end
return uniqueCounts
end

local function CommitFullBackup(destination, character, staged, uniqueCounts)
if not ns.ValidRecord(destination) or ns.char ~= destination or ns.charKey ~= character
or type(ns.db) ~= "table" or type(ns.db.chars) ~= "table" or type(LifeTimeStatsCharDB) ~= "table" then
return false, "The active character changed or is unavailable."
end
local session = ns.session
local liveID = session and ID(session.id) and session.id
local serial = ID(destination.meta.sessionSerial) and destination.meta.sessionSerial or 0
Expand Down Expand Up @@ -896,6 +941,42 @@ function ns.RestoreFullBackup(snapshot)
return true
end

-- The preview holds a summary and a one-shot closure, not a mutable record.
-- The closure privately owns the validated record; confirmation therefore
-- need not copy or revalidate it. Session collision checks still use live data.
function ns.ReadFullBackup(text, finished, status)
local destination, character = ns.char, ns.charKey
local function Prepare(input, progress)
local snapshot = ReadFullSnapshot(input, progress)
local record = snapshot.record
local counts = CountFullUniques(record, progress)
return {
character = snapshot.character, savedAt = snapshot.savedAt,
noteCount = snapshot.noteCount, journalCount = #record.journal, sessionCount = #record.sessionlog,
apply = function()
if not record then return false, "This preview has already been used." end
local staged = record
record = nil
return CommitFullBackup(destination, character, staged, counts)
end,
}
end
return RunBackupJob(text, Prepare, function(input)
return Attempt(function() return Prepare(input) end)
end, finished, status)
end

function ns.RestoreFullBackup(snapshot)
local destination, character = ns.char, ns.charKey
local staged, reason = Attempt(function()
Require(Key(character) and PlainTable(snapshot) and snapshot.character == character,
"This full backup belongs to a different character.")
return StageFullSnapshot(snapshot).record
end)
if not staged then return false, reason end
return CommitFullBackup(destination, character, staged, CountFullUniques(staged))
end

-- Portable account preferences, deliberately separate from character backups.
-- Do not include geometry, identity, notes, diagnostic flags or screenshot settings.
local PREFS = {
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to LifeTimeStats. Format: [Keep a Changelog](https://keepachangelog.com/), versions follow [SemVer](https://semver.org/).

## [1.27.0-forever] - 2026-11-19

Prerelease for WoW: Forever 1.60.1 (Interface 16001). Offline regression suites pass; live client testing is pending.

### Added
- Portable account preference backups with a confirmation preview, separate from character history and window placement.
- Progress and cancellation for large backup reads and exports, and a preview before applying stats-only restores.
- Date-filtered history CSV exports, `/lts resetwindow`, and German translations for selected controls and backup progress messages.

### Changed
- Window scale adapts to a smaller UI canvas without replacing the saved preference.
- Search, section tabs, Top Lists, and pooled table rows avoid repeated work when their data or presentation is unchanged.
- Full-character restore validates and counts discoveries before confirmation rather than repeating that work on apply.

### Fixed
- More resilient save recovery, session continuity, malformed history handling, and legacy backup validation.
- Safer chat sharing and spreadsheet exports, and stricter release checks for TOC and media references.

## [1.26.1-forever] - 2026-11-17

Prerelease. Offline regression suites pass; not yet checked in the live client. From in-game screenshots of 1.26.0.
Expand Down
29 changes: 25 additions & 4 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,24 @@ end
local TALLY_CAP, DAY_KEEP = 400, 40
local tallySizes = setmetatable({}, { __mode = "k" })

local tallyVersions = setmetatable({}, { __mode = "k" })
local tallyMembership = setmetatable({}, { __mode = "k" })
function ns.TallyVersion(bucket)
return bucket and tallyVersions[bucket] or 0
end

function ns.TallyMembershipVersion(bucket)
return bucket and tallyMembership[bucket] or 0
end

function ns.MarkTallyChanged(bucket, membershipChanged)
tallyVersions[bucket] = (tallyVersions[bucket] or 0) + 1
if membershipChanged then tallyMembership[bucket] = (tallyMembership[bucket] or 0) + 1 end
end

local function AddTally(bucket, name, n)
if bucket[name] == nil then
local isNew = bucket[name] == nil
if isNew then
local size = tallySizes[bucket]
if not size then
size = 0
Expand All @@ -641,7 +657,10 @@ local function AddTally(bucket, name, n)
tallySizes[bucket] = size + 1
end
local value = CounterValue(bucket[name]) + n
if not Bad(value) then bucket[name] = value end
if not Bad(value) and bucket[name] ~= value then
bucket[name] = value
ns.MarkTallyChanged(bucket, isNew)
end
end

function ns.Tally(tbl, name, n)
Expand Down Expand Up @@ -777,11 +796,12 @@ end
function ns.TrimTallyBuckets(rec)
for _, bucket in pairs(rec.t) do
if type(bucket) == "table" then
local count = 0
local count, changed = 0, false
for key, value in pairs(bucket) do
if Bad(value) then bucket[key] = nil else count = count + 1 end
if Bad(value) then bucket[key], changed = nil, true else count = count + 1 end
end
if count > TALLY_CAP then
changed = true
local list = {}
for key, value in pairs(bucket) do list[#list + 1] = { key, value } end
table.sort(list, function(a, b)
Expand All @@ -791,6 +811,7 @@ function ns.TrimTallyBuckets(rec)
for i = TALLY_CAP + 1, count do bucket[list[i][1]] = nil end
end
tallySizes[bucket] = math.min(count, TALLY_CAP)
if changed then ns.MarkTallyChanged(bucket, true) end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion LifeTimeStats.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: |cffffb238LifeTime|r|cffefe6d2Stats|r
## Notes: Lifetime cumulative statistics for your character: steps, jumps, kills, deaths, gold, quests, dungeons and lots more.
## Author: Malikor
## Version: 1.26.1
## Version: 1.27.0
## IconTexture: Interface\AddOns\LifeTimeStats\Media\icon
## OptionalDeps: ElvUI, Tukui, EllesmereUI
## SavedVariables: LifeTimeStatsDB
Expand Down
Loading
Loading