Manages ROM and project persistence state. More...
#include <rom_lifecycle_manager.h>
Classes | |
| struct | Dependencies |
Public Types | |
| enum class | PotItemSaveDecision { kSaveWithPotItems , kSaveWithoutPotItems , kCancel } |
Public Member Functions | |
| RomLifecycleManager ()=default | |
| RomLifecycleManager (Dependencies deps) | |
| ~RomLifecycleManager ()=default | |
| void | Initialize (Dependencies deps) |
| void | SetProjectContext (const project::YazeProject *project) |
| void | ActivateRomIdentity (const RomSession *session) |
| const std::string & | current_rom_hash () const |
| Get the cached ROM hash string. | |
| bool | IsRomHashMismatch () const |
| Check whether the ROM hash mismatches the project's expected hash. | |
| absl::Status | CheckRomOpenPolicy (Rom *rom) |
| Validate that the loaded ROM is a safe project target to open/edit. | |
| absl::Status | CheckRomRebindPolicy (Rom *rom) |
| absl::Status | CheckRomWritePolicy (Rom *rom, const std::optional< std::string > &target_filename=std::nullopt) |
| Enforce project write policy; may set pending_rom_write_confirm. | |
| absl::Status | CheckOracleRomSafetyPreSave (Rom *rom) |
| Run Oracle-specific ROM safety preflight before saving. | |
| bool | IsRomWriteConfirmPending () const |
| void | ConfirmRomWrite () |
| void | CancelRomWriteConfirm () |
| void | AllowBuildOutputOpenOnce () |
| const std::vector< core::WriteConflict > & | pending_write_conflicts () const |
| bool | ShouldBypassWriteConflict () const |
| void | BypassWriteConflictOnce () |
| void | ClearPendingWriteConflicts () |
| void | SetPendingWriteConflicts (std::vector< core::WriteConflict > conflicts) |
| void | ConsumeWriteConflictBypass () |
| bool | HasPendingPotItemSaveConfirmation () const |
| int | pending_pot_item_unloaded_rooms () const |
| int | pending_pot_item_total_rooms () const |
| void | SetPotItemConfirmPending (int unloaded_rooms, int total_rooms) |
| Set pot-item confirmation pending (called by SaveRom when needed). | |
| PotItemSaveDecision | ResolvePotItemSaveConfirmation (PotItemSaveDecision decision) |
| bool | ShouldBypassPotItemConfirm () const |
| bool | ShouldSuppressPotItemSave () const |
| void | CancelPotItemSaveConfirmation () |
| void | ClearPotItemBypass () |
| void | ResetPendingSaveState () |
| std::vector< RomFileManager::BackupEntry > | GetRomBackups (Rom *rom) const |
| absl::Status | PruneRomBackups (Rom *rom) |
| void | ApplyDefaultBackupPolicy (bool enabled, const std::string &folder, int retention_count, bool keep_daily, int keep_daily_days) |
| Apply default backup policy from user settings. | |
Private Member Functions | |
| bool | HasEditableSource (const std::string &source_path) const |
Private Attributes | |
| RomFileManager * | rom_file_manager_ = nullptr |
| SessionCoordinator * | session_coordinator_ = nullptr |
| ToastManager * | toast_manager_ = nullptr |
| PopupManager * | popup_manager_ = nullptr |
| const project::YazeProject * | project_ = nullptr |
| util::RomIdentityHashes | current_rom_identity_ |
| std::string | current_rom_path_ |
| std::string | current_rom_editing_source_path_ |
| bool | pending_rom_write_confirm_ = false |
| bool | bypass_rom_write_confirm_once_ = false |
| bool | bypass_build_output_open_once_ = false |
| bool | pending_pot_item_save_confirm_ = false |
| int | pending_pot_item_unloaded_rooms_ = 0 |
| int | pending_pot_item_total_rooms_ = 0 |
| bool | bypass_pot_item_confirm_once_ = false |
| bool | suppress_pot_item_save_once_ = false |
| std::vector< core::WriteConflict > | pending_write_conflicts_ |
| bool | bypass_write_conflict_once_ = false |
Manages ROM and project persistence state.
Extracted from EditorManager to consolidate all ROM/project save/load state management, write-policy enforcement, backup management, and confirmation dialogs into a single component.
EditorManager delegates ROM operations to this class and receives results/errors back. The manager does NOT own the ROM or project objects - those live in the session hierarchy.
Definition at line 34 of file rom_lifecycle_manager.h.
|
strong |
| Enumerator | |
|---|---|
| kSaveWithPotItems | |
| kSaveWithoutPotItems | |
| kCancel | |
Definition at line 36 of file rom_lifecycle_manager.h.
|
default |
|
explicit |
Definition at line 126 of file rom_lifecycle_manager.cc.
|
default |
| void yaze::editor::RomLifecycleManager::Initialize | ( | Dependencies | deps | ) |
Late-initialize dependencies (for when deps aren't available at construction time, e.g. EditorManager's member initialization).
Definition at line 133 of file rom_lifecycle_manager.cc.
References yaze::editor::RomLifecycleManager::Dependencies::popup_manager, popup_manager_, yaze::editor::RomLifecycleManager::Dependencies::project, project_, yaze::editor::RomLifecycleManager::Dependencies::rom_file_manager, rom_file_manager_, yaze::editor::RomLifecycleManager::Dependencies::session_coordinator, session_coordinator_, yaze::editor::RomLifecycleManager::Dependencies::toast_manager, and toast_manager_.
Referenced by yaze::editor::EditorManager::InitializeSubsystems().
|
inline |
Select the project policy used by subsequent hash/write/safety checks. The caller retains ownership and must keep the project alive.
Definition at line 60 of file rom_lifecycle_manager.h.
References project_.
Referenced by yaze::editor::EditorManager::ApplyCurrentProjectRuntimeContext(), yaze::editor::EditorManager::RestoreProjectContextForSession(), and yaze::editor::EditorManager::SaveRomInternal().
| void yaze::editor::RomLifecycleManager::ActivateRomIdentity | ( | const RomSession * | session | ) |
Restore a session's captured baseline, or clear identity for no/empty ROM. Never hashes mutable ROM bytes during activation.
Definition at line 145 of file rom_lifecycle_manager.cc.
References current_rom_editing_source_path_, current_rom_identity_, current_rom_path_, yaze::Rom::is_loaded(), yaze::editor::RomSession::rom, and yaze::editor::RomSession::rom_baseline.
Referenced by yaze::editor::EditorManager::RestoreCurrentRomIdentity().

|
inline |
Get the cached ROM hash string.
Definition at line 73 of file rom_lifecycle_manager.h.
References yaze::util::RomIdentityHashes::crc32, and current_rom_identity_.
Referenced by yaze::editor::EditorManager::GetCurrentRomHash().
| bool yaze::editor::RomLifecycleManager::IsRomHashMismatch | ( | ) | const |
Check whether the ROM hash mismatches the project's expected hash.
Definition at line 170 of file rom_lifecycle_manager.cc.
References yaze::util::RomIdentityHashes::crc32, current_rom_identity_, current_rom_path_, yaze::project::RomMetadata::expected_hash, HasEditableSource(), yaze::util::kMismatch, yaze::util::RomIdentityHashes::Match(), project_, yaze::project::YazeProject::project_opened(), and yaze::project::YazeProject::rom_metadata.
Referenced by yaze::editor::EditorManager::IsRomHashMismatch().

| absl::Status yaze::editor::RomLifecycleManager::CheckRomOpenPolicy | ( | Rom * | rom | ) |
Validate that the loaded ROM is a safe project target to open/edit.
Definition at line 188 of file rom_lifecycle_manager.cc.
References bypass_build_output_open_once_, yaze::Rom::filename(), yaze::Rom::is_loaded(), yaze::project::kAllow, yaze::editor::kError, project_, yaze::project::YazeProject::project_opened(), yaze::project::YazeProject::rom_metadata, yaze::editor::ToastManager::Show(), toast_manager_, and yaze::project::RomMetadata::write_policy.
Referenced by CheckRomRebindPolicy(), yaze::editor::EditorManager::LoadProjectWithRom(), yaze::editor::EditorManager::OpenRomOrProjectInternal(), yaze::editor::EditorManager::ReloadProjectRom(), yaze::editor::EditorManager::RestoreRomBackup(), and yaze::editor::EditorManager::ValidateProjectRomSelection().

| absl::Status yaze::editor::RomLifecycleManager::CheckRomRebindPolicy | ( | Rom * | rom | ) |
Validate a project ROM rebind before changing its descriptor or models. Guarded projects with a fixed manifest development ROM retain that exact backing file; changing rom_filename cannot change the manifest contract.
Definition at line 221 of file rom_lifecycle_manager.cc.
References yaze::core::HackManifest::build_pipeline(), CheckRomOpenPolicy(), yaze::core::BuildPipeline::dev_rom, yaze::Rom::filename(), yaze::project::YazeProject::GetAbsolutePath(), yaze::project::YazeProject::hack_manifest, yaze::Rom::is_loaded(), yaze::project::kAllow, yaze::core::HackManifest::loaded(), yaze::editor::SessionCoordinator::PathsReferToSameBackingFile(), project_, yaze::project::YazeProject::project_opened(), yaze::project::YazeProject::rom_metadata, and yaze::project::RomMetadata::write_policy.
Referenced by yaze::editor::EditorManager::SwapProjectRom().
| absl::Status yaze::editor::RomLifecycleManager::CheckRomWritePolicy | ( | Rom * | rom, |
| const std::optional< std::string > & | target_filename = std::nullopt ) |
Enforce project write policy; may set pending_rom_write_confirm.
Definition at line 247 of file rom_lifecycle_manager.cc.
References bypass_rom_write_confirm_once_, yaze::util::RomIdentityHashes::crc32, current_rom_identity_, current_rom_path_, yaze::project::RomMetadata::expected_hash, yaze::Rom::filename(), HasEditableSource(), yaze::project::kAllow, yaze::project::kBlock, yaze::editor::kError, yaze::util::kMismatch, yaze::editor::PopupID::kRomWriteConfirm, yaze::editor::kWarning, yaze::util::RomIdentityHashes::Match(), pending_rom_write_confirm_, popup_manager_, project_, yaze::project::YazeProject::project_opened(), yaze::project::YazeProject::rom_metadata, yaze::editor::PopupManager::Show(), yaze::editor::ToastManager::Show(), toast_manager_, and yaze::project::RomMetadata::write_policy.
Referenced by yaze::editor::EditorManager::CheckRomWritePolicy().
| absl::Status yaze::editor::RomLifecycleManager::CheckOracleRomSafetyPreSave | ( | Rom * | rom | ) |
Run Oracle-specific ROM safety preflight before saving.
Definition at line 324 of file rom_lifecycle_manager.cc.
References yaze::project::YazeProject::GetAbsolutePath(), yaze::project::YazeProject::hack_manifest, yaze::project::YazeProject::hack_manifest_file, yaze::core::HackManifest::HasProjectRegistry(), yaze::Rom::is_loaded(), yaze::editor::kError, yaze::core::HackManifest::loaded(), yaze::zelda3::OracleRomSafetyPreflightOptions::max_collision_errors, project_, yaze::project::YazeProject::project_opened(), yaze::zelda3::OracleRomSafetyPreflightOptions::require_custom_collision_write_support, yaze::zelda3::OracleRomSafetyPreflightOptions::require_water_fill_reserved_region, yaze::zelda3::RunOracleRomSafetyPreflight(), yaze::editor::ToastManager::Show(), toast_manager_, yaze::zelda3::OracleRomSafetyPreflightOptions::validate_custom_collision_maps, and yaze::zelda3::OracleRomSafetyPreflightOptions::validate_water_fill_table.
Referenced by yaze::editor::EditorManager::CheckOracleRomSafetyPreSave().
|
inline |
Definition at line 100 of file rom_lifecycle_manager.h.
References pending_rom_write_confirm_.
Referenced by yaze::editor::EditorManager::ConfirmRomWrite(), yaze::editor::EditorManager::HasPendingRomSaveConfirmation(), yaze::editor::EditorManager::IsRomWriteConfirmPending(), yaze::editor::EditorManager::SaveRom(), and yaze::editor::EditorManager::SaveRomInternal().
| void yaze::editor::RomLifecycleManager::ConfirmRomWrite | ( | ) |
Definition at line 381 of file rom_lifecycle_manager.cc.
References bypass_rom_write_confirm_once_, and pending_rom_write_confirm_.
Referenced by yaze::editor::EditorManager::ConfirmRomWrite().
| void yaze::editor::RomLifecycleManager::CancelRomWriteConfirm | ( | ) |
Definition at line 386 of file rom_lifecycle_manager.cc.
References bypass_rom_write_confirm_once_, and pending_rom_write_confirm_.
Referenced by ResetPendingSaveState(), and yaze::editor::EditorManager::SaveRomInternal().
|
inline |
Definition at line 103 of file rom_lifecycle_manager.h.
References bypass_build_output_open_once_.
|
inline |
Definition at line 109 of file rom_lifecycle_manager.h.
References pending_write_conflicts_.
Referenced by yaze::editor::EditorManager::HasPendingRomSaveConfirmation(), yaze::editor::EditorManager::pending_write_conflicts(), yaze::editor::EditorManager::SaveRom(), and yaze::editor::EditorManager::SaveRomInternal().
|
inline |
Definition at line 112 of file rom_lifecycle_manager.h.
References bypass_write_conflict_once_.
Referenced by yaze::editor::EditorManager::SaveRom(), and yaze::editor::EditorManager::SaveRomInternal().
|
inline |
Definition at line 113 of file rom_lifecycle_manager.h.
References bypass_write_conflict_once_.
Referenced by yaze::editor::EditorManager::BypassWriteConflictOnce().
|
inline |
Definition at line 114 of file rom_lifecycle_manager.h.
References pending_write_conflicts_.
|
inline |
Definition at line 115 of file rom_lifecycle_manager.h.
References pending_write_conflicts_.
Referenced by yaze::editor::EditorManager::SaveRomInternal().
|
inline |
Definition at line 118 of file rom_lifecycle_manager.h.
References bypass_write_conflict_once_, and pending_write_conflicts_.
Referenced by yaze::editor::EditorManager::SaveRomInternal().
|
inline |
Definition at line 127 of file rom_lifecycle_manager.h.
References pending_pot_item_save_confirm_.
Referenced by yaze::editor::EditorManager::HasPendingPotItemSaveConfirmation(), yaze::editor::EditorManager::HasPendingRomSaveConfirmation(), and yaze::editor::EditorManager::SaveRom().
|
inline |
Definition at line 130 of file rom_lifecycle_manager.h.
References pending_pot_item_unloaded_rooms_.
Referenced by yaze::editor::EditorManager::pending_pot_item_unloaded_rooms().
|
inline |
Definition at line 133 of file rom_lifecycle_manager.h.
References pending_pot_item_total_rooms_.
Referenced by yaze::editor::EditorManager::pending_pot_item_total_rooms().
| void yaze::editor::RomLifecycleManager::SetPotItemConfirmPending | ( | int | unloaded_rooms, |
| int | total_rooms ) |
Set pot-item confirmation pending (called by SaveRom when needed).
Definition at line 395 of file rom_lifecycle_manager.cc.
References pending_pot_item_save_confirm_, pending_pot_item_total_rooms_, and pending_pot_item_unloaded_rooms_.
| RomLifecycleManager::PotItemSaveDecision yaze::editor::RomLifecycleManager::ResolvePotItemSaveConfirmation | ( | PotItemSaveDecision | decision | ) |
Resolve the pot item confirmation dialog. If decision is kSaveWithPotItems or kSaveWithoutPotItems, the caller should invoke SaveRom() again (with the appropriate bypass).
Definition at line 403 of file rom_lifecycle_manager.cc.
References bypass_pot_item_confirm_once_, kCancel, kSaveWithoutPotItems, pending_pot_item_save_confirm_, pending_pot_item_total_rooms_, pending_pot_item_unloaded_rooms_, and suppress_pot_item_save_once_.
Referenced by yaze::editor::EditorManager::ResolvePotItemSaveConfirmation().
|
inline |
Definition at line 146 of file rom_lifecycle_manager.h.
References bypass_pot_item_confirm_once_.
|
inline |
Definition at line 149 of file rom_lifecycle_manager.h.
References suppress_pot_item_save_once_.
|
inline |
Definition at line 152 of file rom_lifecycle_manager.h.
References ClearPotItemBypass(), pending_pot_item_save_confirm_, pending_pot_item_total_rooms_, and pending_pot_item_unloaded_rooms_.
Referenced by ResetPendingSaveState().

|
inline |
Definition at line 158 of file rom_lifecycle_manager.h.
References bypass_pot_item_confirm_once_, and suppress_pot_item_save_once_.
Referenced by CancelPotItemSaveConfirmation().
|
inline |
Clear every confirmation and one-shot bypass associated with a logical save request. This must be called when that request succeeds, fails, is cancelled, or loses its originating ROM session.
Definition at line 166 of file rom_lifecycle_manager.h.
References bypass_write_conflict_once_, CancelPotItemSaveConfirmation(), CancelRomWriteConfirm(), and pending_write_conflicts_.
Referenced by yaze::editor::EditorManager::CancelPendingRomSave(), and yaze::editor::EditorManager::ResumePendingRomSave().

| std::vector< RomFileManager::BackupEntry > yaze::editor::RomLifecycleManager::GetRomBackups | ( | Rom * | rom | ) | const |
Definition at line 424 of file rom_lifecycle_manager.cc.
References yaze::Rom::filename(), yaze::editor::RomFileManager::ListBackups(), and rom_file_manager_.
Referenced by yaze::editor::EditorManager::GetRomBackups().

| absl::Status yaze::editor::RomLifecycleManager::PruneRomBackups | ( | Rom * | rom | ) |
Definition at line 432 of file rom_lifecycle_manager.cc.
References yaze::Rom::filename(), yaze::editor::RomFileManager::PruneBackups(), and rom_file_manager_.
Referenced by yaze::editor::EditorManager::PruneRomBackups().

| void yaze::editor::RomLifecycleManager::ApplyDefaultBackupPolicy | ( | bool | enabled, |
| const std::string & | folder, | ||
| int | retention_count, | ||
| bool | keep_daily, | ||
| int | keep_daily_days ) |
Apply default backup policy from user settings.
Definition at line 442 of file rom_lifecycle_manager.cc.
References rom_file_manager_, yaze::editor::RomFileManager::SetBackupBeforeSave(), yaze::editor::RomFileManager::SetBackupFolder(), yaze::editor::RomFileManager::SetBackupKeepDaily(), yaze::editor::RomFileManager::SetBackupKeepDailyDays(), and yaze::editor::RomFileManager::SetBackupRetentionCount().
Referenced by yaze::editor::EditorManager::ApplyCurrentProjectRuntimeContext(), yaze::editor::EditorManager::ApplyDefaultBackupPolicy(), and yaze::editor::EditorManager::SaveRomInternal().
|
private |
Definition at line 157 of file rom_lifecycle_manager.cc.
References current_rom_editing_source_path_, current_rom_path_, and project_.
Referenced by CheckRomWritePolicy(), and IsRomHashMismatch().
|
private |
Definition at line 189 of file rom_lifecycle_manager.h.
Referenced by ApplyDefaultBackupPolicy(), GetRomBackups(), Initialize(), and PruneRomBackups().
|
private |
Definition at line 190 of file rom_lifecycle_manager.h.
Referenced by Initialize().
|
private |
Definition at line 191 of file rom_lifecycle_manager.h.
Referenced by CheckOracleRomSafetyPreSave(), CheckRomOpenPolicy(), CheckRomWritePolicy(), and Initialize().
|
private |
Definition at line 192 of file rom_lifecycle_manager.h.
Referenced by CheckRomWritePolicy(), and Initialize().
|
private |
Definition at line 193 of file rom_lifecycle_manager.h.
Referenced by CheckOracleRomSafetyPreSave(), CheckRomOpenPolicy(), CheckRomRebindPolicy(), CheckRomWritePolicy(), HasEditableSource(), Initialize(), IsRomHashMismatch(), and SetProjectContext().
|
private |
Definition at line 196 of file rom_lifecycle_manager.h.
Referenced by ActivateRomIdentity(), CheckRomWritePolicy(), current_rom_hash(), and IsRomHashMismatch().
|
private |
Definition at line 197 of file rom_lifecycle_manager.h.
Referenced by ActivateRomIdentity(), CheckRomWritePolicy(), HasEditableSource(), and IsRomHashMismatch().
|
private |
Definition at line 198 of file rom_lifecycle_manager.h.
Referenced by ActivateRomIdentity(), and HasEditableSource().
|
private |
Definition at line 201 of file rom_lifecycle_manager.h.
Referenced by CancelRomWriteConfirm(), CheckRomWritePolicy(), ConfirmRomWrite(), and IsRomWriteConfirmPending().
|
private |
Definition at line 202 of file rom_lifecycle_manager.h.
Referenced by CancelRomWriteConfirm(), CheckRomWritePolicy(), and ConfirmRomWrite().
|
private |
Definition at line 203 of file rom_lifecycle_manager.h.
Referenced by AllowBuildOutputOpenOnce(), and CheckRomOpenPolicy().
|
private |
Definition at line 206 of file rom_lifecycle_manager.h.
Referenced by CancelPotItemSaveConfirmation(), HasPendingPotItemSaveConfirmation(), ResolvePotItemSaveConfirmation(), and SetPotItemConfirmPending().
|
private |
Definition at line 207 of file rom_lifecycle_manager.h.
Referenced by CancelPotItemSaveConfirmation(), pending_pot_item_unloaded_rooms(), ResolvePotItemSaveConfirmation(), and SetPotItemConfirmPending().
|
private |
Definition at line 208 of file rom_lifecycle_manager.h.
Referenced by CancelPotItemSaveConfirmation(), pending_pot_item_total_rooms(), ResolvePotItemSaveConfirmation(), and SetPotItemConfirmPending().
|
private |
Definition at line 209 of file rom_lifecycle_manager.h.
Referenced by ClearPotItemBypass(), ResolvePotItemSaveConfirmation(), and ShouldBypassPotItemConfirm().
|
private |
Definition at line 210 of file rom_lifecycle_manager.h.
Referenced by ClearPotItemBypass(), ResolvePotItemSaveConfirmation(), and ShouldSuppressPotItemSave().
|
private |
Definition at line 213 of file rom_lifecycle_manager.h.
Referenced by ClearPendingWriteConflicts(), ConsumeWriteConflictBypass(), pending_write_conflicts(), ResetPendingSaveState(), and SetPendingWriteConflicts().
|
private |
Definition at line 214 of file rom_lifecycle_manager.h.
Referenced by BypassWriteConflictOnce(), ConsumeWriteConflictBypass(), ResetPendingSaveState(), and ShouldBypassWriteConflict().