Skip to content

Commit

Permalink
Allow Hidden Files
Browse files Browse the repository at this point in the history
Initial commit for allowing hidden files
  • Loading branch information
wolf-sigma committed Feb 14, 2016
1 parent 6ac76cb commit 196d917
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -30,3 +30,6 @@ CMakeFiles
cmake_install.cmake
Makefile
*.cmake

# .idea
.idea/*
18 changes: 14 additions & 4 deletions es-app/src/FileData.cpp
@@ -1,5 +1,6 @@
#include "FileData.h"
#include "SystemData.h"
#include "Settings.h"

namespace fs = boost::filesystem;

Expand Down Expand Up @@ -78,18 +79,27 @@ const std::string& FileData::getThumbnailPath() const
}


std::vector<FileData*> FileData::getFilesRecursive(unsigned int typeMask) const
std::vector<FileData*> FileData::getFilesRecursive(unsigned int typeMask, bool forceHidden) const
{
std::vector<FileData*> out;

for(auto it = mChildren.begin(); it != mChildren.end(); it++)
{
if((*it)->getType() & typeMask)
out.push_back(*it);
if((*it)->getType() & typeMask & (!(*it)->metadata.getBool("hidden") || Settings::getInstance()->getBool("ShowHiddenFiles") || forceHidden))
if ((*it)->getParent() != NULL)
{
if (!(*it)->getParent()->metadata.getBool("hidden") || Settings::getInstance()->getBool("ShowHiddenFiles") || forceHidden)
{
out.push_back(*it);
}
}
else {
out.push_back(*it);
}

if((*it)->getChildren().size() > 0)
{
std::vector<FileData*> subchildren = (*it)->getFilesRecursive(typeMask);
std::vector<FileData*> subchildren = (*it)->getFilesRecursive(typeMask, forceHidden);
out.insert(out.end(), subchildren.cbegin(), subchildren.cend());
}
}
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/FileData.h
Expand Up @@ -44,7 +44,7 @@ class FileData

virtual const std::string& getThumbnailPath() const;

std::vector<FileData*> getFilesRecursive(unsigned int typeMask) const;
std::vector<FileData*> getFilesRecursive(unsigned int typeMask, bool forceHidden) const;

void addChild(FileData* file); // Error if mType != FOLDER
void removeChild(FileData* file); //Error if mType != FOLDER
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/Gamelist.cpp
Expand Up @@ -209,7 +209,7 @@ void updateGamelist(SystemData* system)
if (rootFolder != nullptr)
{
//get only files, no folders
std::vector<FileData*> files = rootFolder->getFilesRecursive(GAME | FOLDER);
std::vector<FileData*> files = rootFolder->getFilesRecursive(GAME | FOLDER, true);
//iterate through all files, checking if they're already in the XML
std::vector<FileData*>::const_iterator fit = files.cbegin();
while(fit != files.cend())
Expand Down
29 changes: 23 additions & 6 deletions es-app/src/MetaData.cpp
Expand Up @@ -5,9 +5,9 @@

namespace fs = boost::filesystem;

MetaDataDecl gameDecls[] = {
MetaDataDecl gameDecls[] = {
// key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd
{"name", MD_STRING, "", false, "name", "enter game name"},
{"name", MD_STRING, "", false, "name", "enter game name"},
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description"},
{"image", MD_IMAGE_PATH, "", false, "image", "enter path to image"},
{"thumbnail", MD_IMAGE_PATH, "", false, "thumbnail", "enter path to thumbnail"},
Expand All @@ -17,16 +17,19 @@ MetaDataDecl gameDecls[] = {
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"},
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre"},
{"players", MD_INT, "1", false, "players", "enter number of players"},
{"hidden", MD_BOOL, "false", false, "hidden" ""}, // TODO: shows up funny in the UI, so made prompt blank.
// note: all non-statistic MDs must go above the statistic ones. probably should check the logic in GuiMetaDataEd
{"playcount", MD_INT, "0", true, "play count", "enter number of times played"},
{"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"}
{"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"},
};
const std::vector<MetaDataDecl> gameMDD(gameDecls, gameDecls + sizeof(gameDecls) / sizeof(gameDecls[0]));

MetaDataDecl folderDecls[] = {
{"name", MD_STRING, "", false},
MetaDataDecl folderDecls[] = {
{"name", MD_STRING, "", false},
{"desc", MD_MULTILINE_STRING, "", false},
{"image", MD_IMAGE_PATH, "", false},
{"thumbnail", MD_IMAGE_PATH, "", false},
{"hidden", MD_BOOL, "", false}
};
const std::vector<MetaDataDecl> folderMDD(folderDecls, folderDecls + sizeof(folderDecls) / sizeof(folderDecls[0]));

Expand Down Expand Up @@ -93,7 +96,7 @@ void MetaDataList::appendToXML(pugi::xml_node parent, bool ignoreDefaults, const
// if it's just the default (and we ignore defaults), don't write it
if(ignoreDefaults && mapIter->second == mddIter->defaultValue)
continue;

// try and make paths relative if we can
std::string value = mapIter->second;
if(mddIter->type == MD_IMAGE_PATH)
Expand Down Expand Up @@ -129,6 +132,20 @@ float MetaDataList::getFloat(const std::string& key) const
return (float)atof(get(key).c_str());
}

bool MetaDataList::getBool(const std::string& key) const
{
if(get(key) == "true"){
return true;
}
else if(get(key) == "false"){
return false;
}
else{
LOG(LogWarning) << "Hidden must be \"true\" or \"false\". Defaulting to \"false\"";
return false;
}
}

boost::posix_time::ptime MetaDataList::getTime(const std::string& key) const
{
return string_to_ptime(get(key), "%Y%m%dT%H%M%S%F%q");
Expand Down
4 changes: 3 additions & 1 deletion es-app/src/MetaData.h
Expand Up @@ -13,6 +13,7 @@ enum MetaDataType
MD_STRING,
MD_INT,
MD_FLOAT,
MD_BOOL,

//specialized types
MD_MULTILINE_STRING,
Expand Down Expand Up @@ -47,13 +48,14 @@ class MetaDataList
void appendToXML(pugi::xml_node parent, bool ignoreDefaults, const boost::filesystem::path& relativeTo) const;

MetaDataList(MetaDataListType type);

void set(const std::string& key, const std::string& value);
void setTime(const std::string& key, const boost::posix_time::ptime& time); //times are internally stored as ISO strings (e.g. boost::posix_time::to_iso_string(ptime))

const std::string& get(const std::string& key) const;
int getInt(const std::string& key) const;
float getFloat(const std::string& key) const;
bool getBool(const std::string& key) const;
boost::posix_time::ptime getTime(const std::string& key) const;

inline MetaDataListType getType() const { return mType; }
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/SystemData.cpp
Expand Up @@ -439,7 +439,7 @@ bool SystemData::hasGamelist() const

unsigned int SystemData::getGameCount() const
{
return mRootFolder->getFilesRecursive(GAME).size();
return mRootFolder->getFilesRecursive(GAME, false).size();
}

void SystemData::loadTheme()
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/guis/GuiGamelistOptions.cpp
Expand Up @@ -141,4 +141,4 @@ std::vector<HelpPrompt> GuiGamelistOptions::getHelpPrompts()
IGameListView* GuiGamelistOptions::getGamelist()
{
return ViewController::get()->getGameListView(mSystem).get();
}
}
37 changes: 26 additions & 11 deletions es-app/src/guis/GuiMetaDataEd.cpp
Expand Up @@ -11,28 +11,30 @@
#include "components/TextEditComponent.h"
#include "components/DateTimeComponent.h"
#include "components/RatingComponent.h"
#include "components/SwitchComponent.h"

#include "guis/GuiTextEditPopup.h"

using namespace Eigen;

GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd, ScraperSearchParams scraperParams,
const std::string& header, std::function<void()> saveCallback, std::function<void()> deleteFunc) : GuiComponent(window),
mScraperParams(scraperParams),
GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd, ScraperSearchParams scraperParams,
const std::string& header, std::function<void()> saveCallback, std::function<void()> deleteFunc) : GuiComponent(window),
mScraperParams(scraperParams),

mBackground(window, ":/frame.png"),
mBackground(window, ":/frame.png"),
mGrid(window, Vector2i(1, 3)),

mMetaDataDecl(mdd),
mMetaData(md),
mMetaDataDecl(mdd),
mMetaData(md),
mSavedCallback(saveCallback), mDeleteFunc(deleteFunc)
{
addChild(&mBackground);
addChild(&mGrid);

mHeaderGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(1, 5));

mTitle = std::make_shared<TextComponent>(mWindow, "EDIT METADATA", Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER);
mSubtitle = std::make_shared<TextComponent>(mWindow, strToUpper(scraperParams.game->getPath().filename().generic_string()),
mSubtitle = std::make_shared<TextComponent>(mWindow, strToUpper(scraperParams.game->getPath().filename().generic_string()),
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER);
mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true);
mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true);
Expand Down Expand Up @@ -73,6 +75,20 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
// pass input to the actual RatingComponent instead of the spacer
row.input_handler = std::bind(&GuiComponent::input, ed.get(), std::placeholders::_1, std::placeholders::_2);

break;
}
case MD_BOOL:
{
ed = std::make_shared<SwitchComponent>(window);
//ed->setState(false);
row.addElement(ed, false, true);

auto spacer = std::make_shared<GuiComponent>(mWindow);
spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0);
row.addElement(spacer, false);

// pass input to the actual SwitchComponent instead of the spacer
row.input_handler = std::bind(&GuiComponent::input, ed.get(), std::placeholders::_1, std::placeholders::_2);
break;
}
case MD_DATE:
Expand All @@ -86,7 +102,6 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector

// pass input to the actual DateTimeComponent instead of the spacer
row.input_handler = std::bind(&GuiComponent::input, ed.get(), std::placeholders::_1, std::placeholders::_2);

break;
}
case MD_TIME:
Expand All @@ -101,7 +116,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
// MD_STRING
ed = std::make_shared<TextComponent>(window, "", Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT), 0x777777FF, ALIGN_RIGHT);
row.addElement(ed, true);

auto spacer = std::make_shared<GuiComponent>(mWindow);
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0);
row.addElement(spacer, false);
Expand Down Expand Up @@ -230,7 +245,7 @@ void GuiMetaDataEd::close(bool closeAllWindows)
if(dirty)
{
// changes were made, ask if the user wants to save them
mWindow->pushGui(new GuiMsgBox(mWindow,
mWindow->pushGui(new GuiMsgBox(mWindow,
"SAVE CHANGES?",
"YES", [this, closeFunc] { save(); closeFunc(); },
"NO", closeFunc
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/guis/GuiScraperStart.cpp
Expand Up @@ -77,7 +77,7 @@ std::queue<ScraperSearchParams> GuiScraperStart::getSearches(std::vector<SystemD
std::queue<ScraperSearchParams> queue;
for(auto sys = systems.begin(); sys != systems.end(); sys++)
{
std::vector<FileData*> games = (*sys)->getRootFolder()->getFilesRecursive(GAME);
std::vector<FileData*> games = (*sys)->getRootFolder()->getFilesRecursive(GAME, false);
for(auto game = games.begin(); game != games.end(); game++)
{
if(selector((*sys), (*game)))
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/views/ViewController.cpp
Expand Up @@ -210,7 +210,7 @@ std::shared_ptr<IGameListView> ViewController::getGameListView(SystemData* syste

//decide type
bool detailed = false;
std::vector<FileData*> files = system->getRootFolder()->getFilesRecursive(GAME | FOLDER);
std::vector<FileData*> files = system->getRootFolder()->getFilesRecursive(GAME | FOLDER, false);
for(auto it = files.begin(); it != files.end(); it++)
{
if(!(*it)->getThumbnailPath().empty())
Expand Down
10 changes: 9 additions & 1 deletion es-app/src/views/gamelist/BasicGameListView.cpp
Expand Up @@ -41,9 +41,17 @@ void BasicGameListView::populateList(const std::vector<FileData*>& files)

mHeaderText.setText(files.at(0)->getSystem()->getFullName());

bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles");

for(auto it = files.begin(); it != files.end(); it++)
{
mList.add((*it)->getName(), *it, ((*it)->getType() == FOLDER));
if ((*it)->metadata.get("hidden") != "true" || showHiddenFiles)
{
mList.add((*it)->getName(), *it, ((*it)->getType() == FOLDER));
}
else{
LOG(LogInfo) << (*it)->getPath() << " is hidden. Skipping displaying it.";
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion es-app/src/views/gamelist/GridGameListView.cpp
Expand Up @@ -40,7 +40,13 @@ void GridGameListView::populateList(const std::vector<FileData*>& files)
mGrid.clear();
for(auto it = files.begin(); it != files.end(); it++)
{
mGrid.add((*it)->getName(), (*it)->getThumbnailPath(), *it);
if ((*it)->metadata.get("hidden") != "true")
{
mGrid.add((*it)->getName(), (*it)->getThumbnailPath(), *it);
}
else{
LOG(LogInfo) << (*it)->getPath() << " is hidden. Skipping displaying it.";
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion es-core/src/Settings.cpp
Expand Up @@ -18,7 +18,8 @@ std::vector<const char*> settings_dont_save = boost::assign::list_of
("Windowed")
("VSync")
("HideConsole")
("IgnoreGamelist");
("IgnoreGamelist")
("ShowHiddenFiles");

Settings::Settings()
{
Expand All @@ -44,6 +45,7 @@ void Settings::setDefaults()
mBoolMap["DrawFramerate"] = false;
mBoolMap["ShowExit"] = true;
mBoolMap["Windowed"] = false;
mBoolMap["ShowHiddenFiles"] = false;

#ifdef _RPI_
// don't enable VSync by default on the Pi, since it already
Expand Down
23 changes: 22 additions & 1 deletion es-core/src/components/SwitchComponent.cpp
Expand Up @@ -3,6 +3,8 @@
#include "resources/Font.h"
#include "Window.h"

#include "Log.h"

SwitchComponent::SwitchComponent(Window* window, bool state) : GuiComponent(window), mImage(window), mState(state)
{
mImage.setImage(":/off.svg");
Expand All @@ -15,6 +17,25 @@ void SwitchComponent::onSizeChanged()
mImage.setSize(mSize);
}

std::string SwitchComponent::getValue() const
{
return mState ? "true" : "false";
}

void SwitchComponent::setValue(const std::string& value)
{
if(value == "true")
{
setState(true);
}else if(value == "false")
{
setState(false);
}else{
LOG(LogWarning) << "SwitchComponent setValue must be \"true\" or \"false\". Defaulting to false.";
setState(false);
}
}

bool SwitchComponent::input(InputConfig* config, Input input)
{
if(config->isMappedTo("a", input) && input.value)
Expand All @@ -30,7 +51,7 @@ bool SwitchComponent::input(InputConfig* config, Input input)
void SwitchComponent::render(const Eigen::Affine3f& parentTrans)
{
Eigen::Affine3f trans = parentTrans * getTransform();

mImage.render(trans);

renderChildren(trans);
Expand Down
4 changes: 4 additions & 0 deletions es-core/src/components/SwitchComponent.h
Expand Up @@ -10,6 +10,10 @@ class SwitchComponent : public GuiComponent
public:
SwitchComponent(Window* window, bool state = false);

// apis for GuiMetaDataEd
std::string getValue() const override;
void setValue(const std::string& value) override;

bool input(InputConfig* config, Input input) override;
void render(const Eigen::Affine3f& parentTrans) override;
void onSizeChanged() override;
Expand Down

0 comments on commit 196d917

Please sign in to comment.