Skip to content

Commit

Permalink
upgrading toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
nadrino committed Dec 27, 2023
1 parent dd7d4ec commit cd66b0e
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tsl::elm::Element *GameBrowserGui::createUI() {
// _gameBrowser_ = std::make_unique<GameBrowser>();
// _c_ = std::make_unique<ConfigHandler>();

GenericToolbox::doesPathIsFile("/config/SimpleModManager/parameters.ini");
GenericToolbox::isFile("/config/SimpleModManager/parameters.ini");

// A list that can contain sub elements and handles scrolling
_list_ = new tsl::elm::List();
Expand Down
2 changes: 1 addition & 1 deletion src/ModManagerCore/include/ConfigHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ConfigHolder{
ss << GET_VAR_NAME_VALUE(selectedPresetIndex) << std::endl;
ss << GET_VAR_NAME_VALUE(lastSmmVersion) << std::endl;
ss << GET_VAR_NAME_VALUE(configFilePath) << std::endl;
ss << GenericToolbox::iterableToString(presetList, [](const PresetConfig& p){ return p.name + " -> " + p.installBaseFolder; });
ss << GenericToolbox::toString(presetList, [](const PresetConfig& p){ return p.name + " -> " + p.installBaseFolder; });
return ss.str();
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/ModManagerCore/include/ConsoleHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace ConsoleHandler{

void upgradeFrom150(){
std::string oldPath = GenericToolbox::getCurrentWorkingDirectory() + "/parameters.ini"; // before 1.5.0
if(GenericToolbox::doesPathIsFile(oldPath)){
if(GenericToolbox::isFile(oldPath)){
ConfigHandler p;

// get the new default path
Expand All @@ -50,7 +50,7 @@ namespace ConsoleHandler{
p.dumpConfigToFile();

// delete the old config file
GenericToolbox::deleteFile( oldPath );
GenericToolbox::rm( oldPath );

GenericToolbox::Switch::Terminal::printLeft("");
GenericToolbox::Switch::Terminal::printLeft("Welcome in SimpleModManager v" + Toolbox::getAppVersion(), GenericToolbox::ColorCodes::greenBackground);
Expand Down
6 changes: 3 additions & 3 deletions src/ModManagerCore/src/ConfigHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void ConfigHandler::loadConfig(const std::string &configFilePath_) {

std::string lastUsedPresetName{"default"};

if( not GenericToolbox::doesPathIsFile(config.configFilePath) ){
if( not GenericToolbox::isFile(config.configFilePath) ){
// immediately dump the default config to the file
this->dumpConfigToFile();
return;
Expand All @@ -59,7 +59,7 @@ void ConfigHandler::loadConfig(const std::string &configFilePath_) {
GenericToolbox::trimInputString(line, " ");

// check if it is a comment
if( GenericToolbox::doesStringStartsWithSubstring(line, "#") ) continue;
if( GenericToolbox::startsWith(line, "#") ) continue;

// check if it is a valid piece of data
auto elements = GenericToolbox::splitString(line, "=");
Expand Down Expand Up @@ -106,7 +106,7 @@ void ConfigHandler::loadConfig(const std::string &configFilePath_) {
}
void ConfigHandler::dumpConfigToFile() const {

GenericToolbox::mkdirPath( GenericToolbox::getFolderPathFromFilePath( _config_.configFilePath ) );
GenericToolbox::mkdir( GenericToolbox::getFolderPath( _config_.configFilePath ) );

std::stringstream ssConfig;
ssConfig << "# This is a config file" << std::endl;
Expand Down
12 changes: 6 additions & 6 deletions src/ModManagerCore/src/GameBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ void GameBrowser::rebuildSelectorMenu(){
_selector_.getHeader() >> "SimpleModManager v" >> Toolbox::getAppVersion() << std::endl;
_selector_.getHeader() << GenericToolbox::ColorCodes::redBackground << "Current Folder : ";
_selector_.getHeader() << _configHandler_.getConfig().baseFolder << std::endl;
_selector_.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;

_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
_selector_.getFooter() << " Page (" << _selector_.getCursorPage() + 1 << "/" << _selector_.getNbPages() << ")" << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
_selector_.getFooter() << "Configuration preset : " << GenericToolbox::ColorCodes::greenBackground;
_selector_.getFooter() << _configHandler_.getConfig().getCurrentPresetName() << GenericToolbox::ColorCodes::resetColor << std::endl;
_selector_.getFooter() << "install-mods-base-folder = " + _configHandler_.getConfig().getCurrentPreset().installBaseFolder << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
_selector_.getFooter() << " A : Select folder" >> "Y : Change config preset " << std::endl;
_selector_.getFooter() << " B : Quit" >> "ZL/ZR : Switch back to the GUI " << std::endl;
_selector_.getFooter() << std::endl;
Expand All @@ -153,13 +153,13 @@ uint8_t* GameBrowser::getFolderIcon(const std::string& gameFolder_){

// protected
void GameBrowser::init(){
auto gameList = GenericToolbox::getListOfSubFoldersInFolder( _configHandler_.getConfig().baseFolder );
auto gameList = GenericToolbox::lsDirs( _configHandler_.getConfig().baseFolder );

std::vector<size_t> nGameMod;
nGameMod.reserve( gameList.size() );
for( auto& game : gameList ){
nGameMod.emplace_back(
GenericToolbox::getListOfSubFoldersInFolder(
GenericToolbox::lsDirs(
_configHandler_.getConfig().baseFolder + "/" + game
).size()
);
Expand Down
74 changes: 37 additions & 37 deletions src/ModManagerCore/src/ModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ConfigHolder& ModManager::getConfig(){

void ModManager::updateModList() {
// list folders
auto folderList = GenericToolbox::getListOfSubFoldersInFolder(_gameFolderPath_);
auto folderList = GenericToolbox::lsDirs(_gameFolderPath_);
GenericToolbox::removeEntryIf(folderList, [](const std::string& entry_){ return entry_ == ".plugins"; });

_modList_.clear(); _modList_.reserve( folderList.size() );
Expand Down Expand Up @@ -100,13 +100,13 @@ void ModManager::dumpModStatusCache() {
}
void ModManager::reloadModStatusCache(){
std::string cacheFilePath = _gameFolderPath_ + "/mods_status_cache.txt";
if( not GenericToolbox::doesPathIsFile(cacheFilePath) ) return;
if( not GenericToolbox::isFile(cacheFilePath) ) return;

auto lines = GenericToolbox::dumpFileAsVectorString( cacheFilePath );
for( auto & line : lines ){
GenericToolbox::trimInputString(line, " ");

if( GenericToolbox::doesStringStartsWithSubstring(line, "#") ) continue;
if( GenericToolbox::startsWith(line, "#") ) continue;

auto elements = GenericToolbox::splitString(line, "=");
if( elements.size() < 2 ) continue;
Expand All @@ -131,7 +131,7 @@ void ModManager::reloadModStatusCache(){
}
}
void ModManager::resetAllModsCacheAndFile(){
GenericToolbox::deleteFile(_gameFolderPath_ + "/mods_status_cache.txt");
GenericToolbox::rm(_gameFolderPath_ + "/mods_status_cache.txt");
this->updateModList();
}

Expand All @@ -157,7 +157,7 @@ ResultModAction ModManager::updateModStatus(int modIndex_){
consoleUpdate(nullptr);

std::string modFolderPath = _gameFolderPath_ + "/" + modPtr->modName;
auto filesList = GenericToolbox::getListOfFilesInSubFolders( modFolderPath );
auto filesList = GenericToolbox::lsFilesRecursive( modFolderPath );


PadState pad;
Expand All @@ -174,7 +174,7 @@ ResultModAction ModManager::updateModStatus(int modIndex_){
if( kDown & HidNpadButton_B ) return Abort;
}

if( _ignoreCacheFiles_ and GenericToolbox::doesStringStartsWithSubstring(GenericToolbox::getFileNameFromFilePath(file), ".") ) {
if( _ignoreCacheFiles_ and GenericToolbox::startsWith(GenericToolbox::getFileName(file), ".") ) {
nIgnoredFiles++; continue;
}

Expand All @@ -185,7 +185,7 @@ ResultModAction ModManager::updateModStatus(int modIndex_){
modFilePath += "/" + file;

std::stringstream ssPbar;
ssPbar << "Checking : (" << iFile+1 << "/" << filesList.size() << ") " << GenericToolbox::getFileNameFromFilePath(file);
ssPbar << "Checking : (" << iFile+1 << "/" << filesList.size() << ") " << GenericToolbox::getFileName(file);
GenericToolbox::Switch::Terminal::displayProgressBar( iFile++, filesList.size(), ssPbar.str() );

if( GenericToolbox::Switch::IO::doFilesAreIdentical( installedPathCandidate, modFilePath ) ){
Expand Down Expand Up @@ -256,14 +256,14 @@ ResultModAction ModManager::applyMod(int modIndex_, bool overrideConflicts_){

GenericToolbox::Switch::Terminal::printLeft(" Getting files list...", GenericToolbox::ColorCodes::greenBackground, true);
consoleUpdate(nullptr);
auto filesList = GenericToolbox::getListOfFilesInSubFolders( modFolderPath );
auto filesList = GenericToolbox::lsFilesRecursive( modFolderPath );

// filtering files
GenericToolbox::removeEntryIf(filesList, [&](const std::string &file_) {
return (
(_ignoreCacheFiles_ and
GenericToolbox::doesStringStartsWithSubstring(
GenericToolbox::getFileNameFromFilePath(file_), "."
GenericToolbox::startsWith(
GenericToolbox::getFileName(file_), "."
))
or
(GenericToolbox::doesElementIsInVector(file_, _ignoredFileList_))
Expand Down Expand Up @@ -293,7 +293,7 @@ ResultModAction ModManager::applyMod(int modIndex_, bool overrideConflicts_){
GenericToolbox::Switch::Terminal::displayProgressBar(
iFile, filesList.size(),
"(" + std::to_string(iFile+1) + "/" + std::to_string(filesList.size()) + ") " +
GenericToolbox::getFileNameFromFilePath(file) + " (" + fileSize + ")"
GenericToolbox::getFileName(file) + " (" + fileSize + ")"
);
iFile++;

Expand All @@ -305,7 +305,7 @@ ResultModAction ModManager::applyMod(int modIndex_, bool overrideConflicts_){
// on conflict:
if ( onConflictAction == "Yes to all" ){ installFile = true; } // no IO first
else if( onConflictAction == "No to all" ){ installFile = false; }
else if( not GenericToolbox::doesPathIsFile( dstFilePath ) ){ installFile = true; }
else if( not GenericToolbox::isFile( dstFilePath ) ){ installFile = true; }
else if( GenericToolbox::Switch::IO::doFilesAreIdentical( dstFilePath, srcFilePath ) ){ installFile = false; }
else{
onConflictAction = Selector::askQuestion(
Expand Down Expand Up @@ -336,7 +336,7 @@ ResultModAction ModManager::applyModList(const std::vector<std::string> &modName

for( int iMod = int( modNamesList_.size() ) - 1 ; iMod >= 0 ; iMod-- ){
std::string modFolder = _gameFolderPath_ + "/" + modNamesList_[iMod];
auto fileList = GenericToolbox::getListOfFilesInSubFolders(modFolder );
auto fileList = GenericToolbox::lsFilesRecursive(modFolder );
for(auto& file : fileList){
if( GenericToolbox::doesElementIsInVector(file, appliedFileList) ){
ignoredFileListPerMod[iMod].emplace_back(file);
Expand Down Expand Up @@ -367,7 +367,7 @@ void ModManager::removeMod(int modIndex_) {
GenericToolbox::Switch::Terminal::printLeft("Disabling : " + modPtr->modName, GenericToolbox::ColorCodes::redBackground);

std::string srcFolder = _gameFolderPath_ + "/" + modPtr->modName;
auto fileList{GenericToolbox::getListOfFilesInSubFolders(srcFolder)};
auto fileList{GenericToolbox::lsFilesRecursive(srcFolder)};

size_t iFile{0};
for( auto& file : fileList ){
Expand All @@ -383,21 +383,21 @@ void ModManager::removeMod(int modIndex_) {

GenericToolbox::Switch::Terminal::displayProgressBar(
iFile++, fileList.size(),
GenericToolbox::getFileNameFromFilePath(file) + " (" + fileSize + ")"
GenericToolbox::getFileName(file) + " (" + fileSize + ")"
);

// Check if the installed mod belongs to the selected mod
if( GenericToolbox::Switch::IO::doFilesAreIdentical( dstFilePath, srcFilePath ) ){

// Remove the mod file
GenericToolbox::deleteFile( dstFilePath );
GenericToolbox::rm( dstFilePath );

// Delete the folder if no other files is present
std::string emptyFolderCandidate = GenericToolbox::getFolderPathFromFilePath(dstFilePath );
while( GenericToolbox::isFolderEmpty( emptyFolderCandidate ) ) {
std::string emptyFolderCandidate = GenericToolbox::getFolderPath(dstFilePath );
while( GenericToolbox::isDirEmpty( emptyFolderCandidate ) ) {
if( emptyFolderCandidate.empty() ) break;
GenericToolbox::deleteEmptyDirectory( emptyFolderCandidate );
emptyFolderCandidate = GenericToolbox::getFolderPathFromFilePath( emptyFolderCandidate );
GenericToolbox::rmDir( emptyFolderCandidate );
emptyFolderCandidate = GenericToolbox::getFolderPath( emptyFolderCandidate );
}
}
}
Expand Down Expand Up @@ -530,16 +530,16 @@ void ModManager::rebuildSelectorMenu(){
_selector_.clearMenu();
_selector_.getHeader() >> "SimpleModManager v" >> Toolbox::getAppVersion() << std::endl;
_selector_.getHeader() << GenericToolbox::ColorCodes::redBackground << "Current Folder : " << _owner_->getConfigHandler().getConfig().baseFolder << std::endl;
_selector_.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;

_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
_selector_.getFooter() << " Page (" << _selector_.getCursorPage() + 1 << "/" << _selector_.getNbPages() << ")" << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
_selector_.getFooter() << "Mod preset : " << _owner_->getModPresetHandler().getSelectedModPresetName() << std::endl;
_selector_.getFooter() << "Configuration preset : " << GenericToolbox::ColorCodes::greenBackground;
_selector_.getFooter() << fetchCurrentPreset().name << GenericToolbox::ColorCodes::resetColor << std::endl;
_selector_.getFooter() << "install-mods-base-folder = " + this->fetchCurrentPreset().installBaseFolder << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
_selector_.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
_selector_.getFooter() << " ZL : Rescan all mods" >> "ZR : Disable all mods " << std::endl;
_selector_.getFooter() << " A/X : Apply/Disable mod" >> "L/R : Previous/Next preset " << std::endl;
_selector_.getFooter() << " -/+ : Select/Apply mod preset" >> "Y : Mod options " << std::endl;
Expand All @@ -557,7 +557,7 @@ void ModManager::displayModFilesStatus(const std::string &modName_){

std::stringstream ssSrcFolder;
ssSrcFolder << _gameFolderPath_ << "/" << modName_;
auto fileList = GenericToolbox::getListOfFilesInSubFolders( ssSrcFolder.str() );
auto fileList = GenericToolbox::lsFilesRecursive( ssSrcFolder.str() );

GenericToolbox::Switch::Terminal::printLeft("Checking Files...", GenericToolbox::ColorCodes::redBackground);
consoleUpdate(nullptr);
Expand All @@ -569,7 +569,7 @@ void ModManager::displayModFilesStatus(const std::string &modName_){
GenericToolbox::Switch::Terminal::displayProgressBar(
iFile, fileList.size(),
"(" + std::to_string(iFile + 1) + "/" + std::to_string(fileList.size()) + ") " +
GenericToolbox::getFileNameFromFilePath(file)
GenericToolbox::getFileName(file)
);

std::stringstream ssSrc;
Expand All @@ -580,7 +580,7 @@ void ModManager::displayModFilesStatus(const std::string &modName_){
if( GenericToolbox::Switch::IO::doFilesAreIdentical( ssDst.str(), ssSrc.str() ) ){
selector.setTag(iFile, "-> Installed");
}
else if( GenericToolbox::doesPathIsFile( ssDst.str() ) ){
else if( GenericToolbox::isFile( ssDst.str() ) ){
selector.setTag(iFile, "-> Not same");
}
else{
Expand All @@ -591,11 +591,11 @@ void ModManager::displayModFilesStatus(const std::string &modName_){
}

selector.getHeader() << GenericToolbox::ColorCodes::redBackground << modName_ << std::endl;
selector.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth());
selector.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth());

selector.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
selector.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
selector.getFooter() << "Page (" << selector.getCursorPage() << "/" << selector.getNbPages() << ")" << std::endl;
selector.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
selector.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
selector.getFooter() << " B : Go back" << std::endl;
if(selector.getNbPages() > 1) selector.getFooter() << " <- : Previous Page" >> "-> : Next Page " << std::endl;

Expand Down Expand Up @@ -638,7 +638,7 @@ void ModManager::displayConflictsWithOtherMods(size_t modIndex_){
};


auto fileList = GenericToolbox::getListOfFilesInSubFolders(
auto fileList = GenericToolbox::lsFilesRecursive(
_gameFolderPath_ + "/" + _modList_[modIndex_].modName
);
std::vector<ModFileConflict> modFileConflictList;
Expand All @@ -654,7 +654,7 @@ void ModManager::displayConflictsWithOtherMods(size_t modIndex_){
for( auto& mod : _modList_ ){
if( mod.modName == _modList_[modIndex_].modName ){ continue; }

auto fList = GenericToolbox::getListOfFilesInSubFolders( _gameFolderPath_+"/"+mod.modName );
auto fList = GenericToolbox::lsFilesRecursive( _gameFolderPath_+"/"+mod.modName );
for( auto& conflictCandidate : modFileConflictList ){
if( GenericToolbox::doesElementIsInVector(conflictCandidate.file, fList) ){
conflictCandidate.conflictingModList.emplace_back( mod.modName );
Expand Down Expand Up @@ -682,12 +682,12 @@ void ModManager::displayConflictsWithOtherMods(size_t modIndex_){

// header
sel.getHeader() << GenericToolbox::ColorCodes::redBackground << "Conflicts with " + _modList_[modIndex_].modName << std::endl;
sel.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
sel.getHeader() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;

// footer
sel.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
sel.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
sel.getFooter() << "Page (" << sel.getCursorPage() << "/" << sel.getNbPages() << ")" << std::endl;
sel.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::Switch::Hardware::getTerminalWidth()) << std::endl;
sel.getFooter() << GenericToolbox::repeatString("*", GenericToolbox::getTerminalWidth()) << std::endl;
sel.getFooter() << " B : Go back" >> "" << std::endl;
sel.getFooter() << " <- : Previous Page" >> "-> : Next Page " << std::endl;

Expand Down Expand Up @@ -738,7 +738,7 @@ int ModManager::getModIndex(const std::string& modName_){

void ModManager::reloadCustomPreset(){
std::string configFilePath = _gameFolderPath_ + "/this_folder_config.txt";
if( GenericToolbox::doesPathIsFile(configFilePath) ){
if( GenericToolbox::isFile(configFilePath) ){
_currentPresetName_ = GenericToolbox::dumpFileAsString(configFilePath);
}
else{
Expand All @@ -747,7 +747,7 @@ void ModManager::reloadCustomPreset(){
}
void ModManager::setCustomPreset(const std::string &presetName_) {
std::string configFilePath = _gameFolderPath_ + "/this_folder_config.txt";
GenericToolbox::deleteFile( configFilePath );
GenericToolbox::rm( configFilePath );
if( not presetName_.empty() ){
GenericToolbox::dumpStringInFile( configFilePath, presetName_ );
}
Expand Down
Loading

0 comments on commit cd66b0e

Please sign in to comment.