refactor(export): read text from chunks, write the file atomically
Two changes to MessageExporter before it gets a caller. It read SenderSource and ContentSource, the raw SeStrings. TextValue on one holding an auto-translate phrase reaches SeStringEvaluator, which asserts it is on the main thread and throws unconditionally when a macro resolves a global number. An export belongs on a worker, so that would abort it partway and leave half a file. The plan called for resolving text in batches on the framework thread. Not needed: Message.Sender and Message.Content are already-resolved chunk lists -- ChunkUtil turns auto-translate into text at ingest, and the full-text index reads them exactly this way. Same strings, no evaluator, no thread affinity, and no batching machinery. Second, the file handling. The format was validated after the StreamWriter was opened, so an unknown format left a zero-byte file where a previous export had been. It is checked first now, and the write goes to a .part file that is moved into place at the end. A crash halfway used to leave a file that opens cleanly and is quietly incomplete -- which on the path a GDPR access request goes out on is worse than an obvious failure. Almost none of this is reachable from the build suite: ExportToFile takes IEnumerable<Message>, Message needs SeString, and xUnit cannot load Dalamud.dll -- even an empty list fails, because the runtime resolves the parameter type before the body runs. So the format mapping is pinned there and the rest by a new self-test, which builds probe messages with deliberately empty SeStrings: if the exporter ever reads them again, the text comes out blank and it fails.
This commit is contained in:
@@ -422,6 +422,7 @@ public sealed class Plugin : IAsyncDalamudPlugin
|
||||
await _lifecycle.LoadAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
SelfTestRegistry.RegisterTestSteps([
|
||||
new SelfTests.ExportRoundTripStep(),
|
||||
new SelfTests.ThemeSwitchSelfTestStep(this),
|
||||
new SelfTests.ThemeCrossfadeSelfTestStep(this),
|
||||
new SelfTests.FontManagerCtorSmokeStep(this),
|
||||
|
||||
Reference in New Issue
Block a user