add log migration to startup, CHANGELOG

This commit is contained in:
2026-06-03 01:35:05 +02:00
parent 995344b153
commit dffd8d2856
3 changed files with 41 additions and 0 deletions
+2
View File
@@ -39,6 +39,8 @@ All notable changes to NotAlterra are documented in this file.
- **Migration notification** — old backups in `NotAlterra_Backups/` are
migrated silently on first launch with a log entry. The user is informed
their original data remains untouched.
- **Log migration** — existing `transaction.log` is moved into `logs/`
on first launch, appended to the new location.
### Removed
- **`config.ini` eliminated entirely** — no save path, disclaimer flag, or
+34
View File
@@ -66,6 +66,40 @@ fn _game_running_linux() -> bool {
// ── transaction logging ────────────────────────────────────────────────────
/// Migrate the old `transaction.log` (next to the binary) into the new
/// `logs/` directory. Appends old entries to the new file, then renames
/// the old file to `.migrated` so it won't be migrated again.
/// Returns `true` if an old log was found and handled.
pub fn migrate_old_log() -> bool {
let old = exe_dir().join("transaction.log");
if !old.exists() {
return false;
}
let new = log_path();
// Read old content
if let Ok(content) = std::fs::read_to_string(&old) {
if !content.trim().is_empty() {
// Append to new log with a migration header
let header = format!(
"───── migrated from old location [{ts}] ─────\n",
ts = chrono::Local::now().format("%Y-%m-%d %H:%M:%S")
);
if let Ok(mut f) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(&new)
{
use std::io::Write;
let _ = write!(f, "{header}{content}");
}
}
}
// Rename old file so it won't be processed again
let migrated = old.with_extension("log.migrated");
let _ = std::fs::rename(&old, &migrated);
true
}
/// Path to `transaction.log` inside the `logs/` directory. All timestamped
/// actions are appended here for audit trail purposes.
pub fn log_path() -> PathBuf {
+5
View File
@@ -156,6 +156,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> Result<()> {
result in incomplete, corrupt, or overwritten save files.",
)?;
// Migrate old transaction.log into logs/ directory
if guard::migrate_old_log() {
guard::log_action("MIGRATE", "old transaction.log moved to logs/", "OK", &app.log_path)?;
}
// Clean up stale config.ini from v0.3.0 and earlier
if crate::config::cleanup_stale_config() {
guard::log_action("MIGRATE", "old config.ini removed", "SAFE", &app.log_path)?;