diff --git a/CHANGELOG.md b/CHANGELOG.md index dac0ec0..42b49fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/guard.rs b/src/guard.rs index 3da638f..11f3cbe 100644 --- a/src/guard.rs +++ b/src/guard.rs @@ -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 { diff --git a/src/main.rs b/src/main.rs index a4a72e2..c9418ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,6 +156,11 @@ fn run_app(terminal: &mut Terminal) -> 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)?;