Implement Trash option, update fslib for bug fix.

This commit is contained in:
J-D-K 2025-08-22 09:07:33 -04:00
parent 3b52b82e38
commit bb26eb98ec
5 changed files with 37 additions and 9 deletions

@ -1 +1 @@
Subproject commit bae65f98fa5c7a34555d85d92eaf6ba78c4fa3cb
Subproject commit f948cecb43c4f1e089442a8c0fd58df7deefb955

View File

@ -69,6 +69,9 @@ class SettingsState final : public BaseState
/// @brief Toggles JKSM mode and calls the main menu to reinitialize the views.
void toggle_jksm_mode();
/// @brief Toggles the trash folder and creates or deletes it if needed.
void toggle_trash_folder();
/// @brief Cycles and wraps the animation scaling (1.0 to 4.0);
void cycle_anim_scaling();

View File

@ -172,11 +172,11 @@ bool JKSV::create_directories()
const bool workDirCreated = needsWorkDir && fslib::create_directories_recursively(workDir);
if (needsWorkDir && !workDirCreated) { return false; }
// SVI folder.
const fslib::Path sviDir = workDir / "svi";
const bool needsSviDir = !fslib::directory_exists(sviDir);
const bool sviDirCreated = needsSviDir && fslib::create_directory(sviDir);
if (needsSviDir && !sviDirCreated) { return false; }
// Trash folder. This can fail without being fatal.
const fslib::Path trashDir{workDir / "_TRASH_"};
const bool trashEnabled = config::get_by_key(config::keys::ENABLE_TRASH_BIN);
const bool needsTash = trashEnabled && !fslib::directory_exists(trashDir);
if (needsTash) { error::fslib(fslib::create_directory(trashDir)); }
return true;
}

View File

@ -30,6 +30,7 @@ namespace
CYCLE_ZIP = 14,
CYCLE_SORT_TYPE = 15,
TOGGLE_JKSM = 16,
TOGGLE_TRASH = 22,
CYCLE_SCALING = 23
};
@ -206,6 +207,7 @@ void SettingsState::toggle_options()
case CYCLE_ZIP: SettingsState::cycle_zip_level(); break;
case CYCLE_SORT_TYPE: SettingsState::cycle_sort_type(); break;
case TOGGLE_JKSM: SettingsState::toggle_jksm_mode(); break;
case TOGGLE_TRASH: SettingsState::toggle_trash_folder(); break;
case CYCLE_SCALING: SettingsState::cycle_anim_scaling(); break;
default: config::toggle_by_key(CONFIG_KEY_ARRAY[selected]); break;
}
@ -246,6 +248,17 @@ void SettingsState::toggle_jksm_mode()
MainMenuState::initialize_view_states();
}
void SettingsState::toggle_trash_folder()
{
const bool trashEnabled = config::get_by_key(config::keys::ENABLE_TRASH_BIN);
const fslib::Path trashPath{config::get_working_directory() / "_TRASH_"};
logger::log("%s", trashPath.full_path());
config::toggle_by_key(config::keys::ENABLE_TRASH_BIN);
if (trashEnabled) { error::fslib(fslib::delete_directory_recursively(trashPath)); }
else { error::fslib(fslib::create_directory(trashPath)); }
}
void SettingsState::cycle_anim_scaling()
{
double scaling = config::get_animation_scaling();

View File

@ -328,9 +328,21 @@ void tasks::backup::delete_backup_local(sys::Task *task, BackupMenuState::TaskDa
task->set_status(status);
}
const bool isDir = fslib::directory_exists(path);
const bool dirError = isDir && error::fslib(fslib::delete_directory_recursively(path));
const bool fileError = !isDir && error::fslib(fslib::delete_file(path));
const bool trashEnabled = config::get_by_key(config::keys::ENABLE_TRASH_BIN);
const bool isDir = fslib::directory_exists(path);
bool dirError{}, fileError{};
if (trashEnabled)
{
const fslib::Path newPath{config::get_working_directory() / "_TRASH_" / path.get_filename()};
dirError = isDir && error::fslib(fslib::rename_directory(path, newPath));
fileError = !isDir && error::fslib(fslib::rename_file(path, newPath));
}
else
{
dirError = isDir && error::fslib(fslib::delete_directory_recursively(path));
fileError = !isDir && error::fslib(fslib::delete_file(path));
}
if (dirError || fileError)
{
const char *popFailed = strings::get_by_name(strings::names::BACKUPMENU_POPS, 4);