Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
FileManagement Class Reference

Owns the on-disk side of a save: the current path, the recent-files list, and the live SaveFile. More...

#include <filemanagement.h>

Inheritance diagram for FileManagement:
Collaboration diagram for FileManagement:

Public Member Functions

 FileManagement (QObject *parent=nullptr)
 Current file path. Setting it triggers a load via setPath().
virtual ~FileManagement ()
QString getLastErrorMessage ()
QString getLastErrorDetail ()
QString getPath ()
 Current file path.
QString getRecentFile (int index=0)
 Recent path at index (0 = most recent).
QList< QString > getRecentFiles ()
 The whole recent-files list.
int recentFilesCount ()
 How many recent files are currently remembered.
int recentFilesMax ()
 The cap (MAX_RECENT_FILES).
void recentFilesSwap (int from, int to)
 Reorder the recent list (e.g. drag to reorder).
void recentFilesRemove (int ind)
 Drop one entry from the recent list.
protected::void pathChanged (QString newPath, QString oldPath)
 The active path changed.
void recentFilesChanged (QList< QString > files)
 The recent-files list changed.
void dataChanged ()
 The live SaveFile was replaced.
void loadError ()
 A load failed on a file that exists (unreadable / truncated).
void reset ()
 Clear path + data back to a blank starting state.
void newFile ()
 Start a fresh blank save.
bool openFile ()
 Prompt for and open a save.
bool openFileRecent (int index)
 Open an entry from the recent-files list.
void reopenFile ()
 Reload the current path from disk, discarding edits.
void addRecentFile (QString path)
 Push a path onto the recent list (de-duped, capped).
void setPath (QString path)
 Set the active path (backs the path property).
bool saveFile ()
 Save to the current path.
bool saveFileAs ()
 Prompt for a new path and save there.
bool saveFileCopy ()
 Save a copy elsewhere without changing the active path.
void wipeUnusedSpace ()
 Zero out save regions that aren't meaningfully used.
void clearRecentFiles ()
 Forget the entire recent-files list.

Public Attributes

SaveFiledata = nullptr
 The live save file these operations load into / save from.

Detailed Description

Owns the on-disk side of a save: the current path, the recent-files list, and the live SaveFile.

This is the top of the savefile layer that the UI talks to – QML reaches it as brg.file. It handles the file verbs (new/open/save/reopen, plus "save as" and "save copy"), maintains a persisted recent-files list via QSettings, and reads raw bytes off disk into a SaveFile (and writes them back). The actual byte parsing lives in SaveFile / SaveFileToolset; this class is the I/O and file-lifecycle controller around it.

See also
SaveFile (data), and the data lifecycle.

Definition at line 45 of file filemanagement.h.

Constructor & Destructor Documentation

◆ FileManagement()

FileManagement::FileManagement ( QObject * parent = nullptr)

Current file path. Setting it triggers a load via setPath().

The live save. QML reads through this as brg.file.data. Plain-English description of the most recent failed load (the primary message). The real, one-line technical detail behind the failure (the OS/Qt file error string, or the actual size mismatch). Shown small/secondary – never as the primary message, and not a made-up code.

Definition at line 30 of file filemanagement.cpp.

References data, and reset().

◆ ~FileManagement()

FileManagement::~FileManagement ( )
virtual

Definition at line 36 of file filemanagement.cpp.

References data.

Member Function Documentation

◆ addRecentFile()

void FileManagement::addRecentFile ( QString path)

Push a path onto the recent list (de-duped, capped).

Definition at line 188 of file filemanagement.cpp.

Referenced by loadError(), and setPath().

◆ clearRecentFiles()

void FileManagement::clearRecentFiles ( )

Forget the entire recent-files list.

Definition at line 255 of file filemanagement.cpp.

Referenced by loadError(), and pse::shortcutActions().

◆ dataChanged()

void FileManagement::dataChanged ( )

The live SaveFile was replaced.

◆ getLastErrorDetail()

QString FileManagement::getLastErrorDetail ( )
See also
lastErrorDetail property.

Definition at line 183 of file filemanagement.cpp.

◆ getLastErrorMessage()

QString FileManagement::getLastErrorMessage ( )
See also
lastErrorMessage property.

Definition at line 178 of file filemanagement.cpp.

◆ getPath()

QString FileManagement::getPath ( )

Current file path.

Definition at line 41 of file filemanagement.cpp.

◆ getRecentFile()

QString FileManagement::getRecentFile ( int index = 0)

Recent path at index (0 = most recent).

Definition at line 46 of file filemanagement.cpp.

Referenced by openFileRecent().

◆ getRecentFiles()

QList< QString > FileManagement::getRecentFiles ( )

The whole recent-files list.

Definition at line 51 of file filemanagement.cpp.

◆ loadError()

void FileManagement::loadError ( )

A load failed on a file that exists (unreadable / truncated).

The app layer reacts by showing the file-error screen; read lastErrorMessage (plain) and lastErrorDetail (the real technical one-liner).

References addRecentFile(), clearRecentFiles(), data, newFile(), openFile(), openFileRecent(), reopenFile(), reset(), saveFile(), saveFileAs(), saveFileCopy(), setPath(), and wipeUnusedSpace().

◆ newFile()

void FileManagement::newFile ( )

Start a fresh blank save.

Definition at line 91 of file filemanagement.cpp.

References data, and setPath().

Referenced by loadError(), reset(), and pse::shortcutActions().

◆ openFile()

bool FileManagement::openFile ( )

Prompt for and open a save.

Returns
true on success.

Definition at line 97 of file filemanagement.cpp.

References setPath().

Referenced by loadError(), and pse::shortcutActions().

◆ openFileRecent()

bool FileManagement::openFileRecent ( int index)

Open an entry from the recent-files list.

Returns
true on success.

Definition at line 112 of file filemanagement.cpp.

References getRecentFile(), and setPath().

Referenced by loadError().

◆ pathChanged()

protected::void FileManagement::pathChanged ( QString newPath,
QString oldPath )

The active path changed.

Referenced by setPath().

◆ recentFilesChanged()

void FileManagement::recentFilesChanged ( QList< QString > files)

The recent-files list changed.

Referenced by RecentFilesModel::RecentFilesModel().

◆ recentFilesCount()

int FileManagement::recentFilesCount ( )

How many recent files are currently remembered.

Definition at line 56 of file filemanagement.cpp.

◆ recentFilesMax()

int FileManagement::recentFilesMax ( )

The cap (MAX_RECENT_FILES).

Definition at line 61 of file filemanagement.cpp.

References MAX_RECENT_FILES.

◆ recentFilesRemove()

void FileManagement::recentFilesRemove ( int ind)

Drop one entry from the recent list.

Definition at line 77 of file filemanagement.cpp.

◆ recentFilesSwap()

void FileManagement::recentFilesSwap ( int from,
int to )

Reorder the recent list (e.g. drag to reorder).

Definition at line 66 of file filemanagement.cpp.

◆ reopenFile()

void FileManagement::reopenFile ( )

Reload the current path from disk, discarding edits.

Definition at line 125 of file filemanagement.cpp.

References data.

Referenced by loadError(), and pse::shortcutActions().

◆ reset()

void FileManagement::reset ( )

Clear path + data back to a blank starting state.

Definition at line 83 of file filemanagement.cpp.

References KEY_RECENT_FILES, newFile(), and setPath().

Referenced by FileManagement(), and loadError().

◆ saveFile()

bool FileManagement::saveFile ( )

Save to the current path.

Returns
true on success.

Definition at line 216 of file filemanagement.cpp.

References data, and saveFileAs().

Referenced by loadError(), and pse::shortcutActions().

◆ saveFileAs()

bool FileManagement::saveFileAs ( )

Prompt for a new path and save there.

Returns
true on success.

Definition at line 227 of file filemanagement.cpp.

References data, and setPath().

Referenced by loadError(), saveFile(), and pse::shortcutActions().

◆ saveFileCopy()

bool FileManagement::saveFileCopy ( )

Save a copy elsewhere without changing the active path.

Definition at line 239 of file filemanagement.cpp.

References data.

Referenced by loadError(), and pse::shortcutActions().

◆ setPath()

void FileManagement::setPath ( QString path)

Set the active path (backs the path property).

Definition at line 197 of file filemanagement.cpp.

References addRecentFile(), KEY_LAST_FILE, and pathChanged().

Referenced by loadError(), newFile(), openFile(), openFileRecent(), reset(), and saveFileAs().

◆ wipeUnusedSpace()

void FileManagement::wipeUnusedSpace ( )

Zero out save regions that aren't meaningfully used.

Definition at line 250 of file filemanagement.cpp.

References data.

Referenced by loadError(), and pse::shortcutActions().

Member Data Documentation

◆ data

SaveFile* FileManagement::data = nullptr

The live save file these operations load into / save from.

Definition at line 72 of file filemanagement.h.

Referenced by FileManagement(), loadError(), newFile(), reopenFile(), saveFile(), saveFileAs(), saveFileCopy(), pse::shortcutActions(), wipeUnusedSpace(), and ~FileManagement().


The documentation for this class was generated from the following files: