Checkpoint/3ds/source/directory.cpp

81 lines
2.3 KiB
C++
Raw Normal View History

2018-05-14 06:52:41 +00:00
/*
2019-05-06 20:51:09 +00:00
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
2017-09-29 07:45:56 +00:00
2018-05-14 06:52:41 +00:00
#include "directory.hpp"
2017-09-29 07:45:56 +00:00
2018-05-14 06:52:41 +00:00
Directory::Directory(FS_Archive archive, const std::u16string& root)
2017-09-29 07:45:56 +00:00
{
2018-05-14 06:52:41 +00:00
mGood = false;
mList.clear();
Handle handle;
2019-05-06 20:51:09 +00:00
2018-05-14 06:52:41 +00:00
mError = FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, root.data()));
2019-05-06 20:51:09 +00:00
if (R_FAILED(mError)) {
2018-05-14 06:52:41 +00:00
return;
}
2019-05-06 20:51:09 +00:00
2018-05-14 06:52:41 +00:00
u32 result;
do {
FS_DirectoryEntry item;
mError = FSDIR_Read(handle, &result, 1, &item);
2019-05-06 20:51:09 +00:00
if (result == 1) {
2018-05-14 06:52:41 +00:00
mList.push_back(item);
}
2019-05-06 20:51:09 +00:00
} while (result);
2018-05-14 06:52:41 +00:00
mError = FSDIR_Close(handle);
2019-05-06 20:51:09 +00:00
if (R_FAILED(mError)) {
2018-05-14 06:52:41 +00:00
mList.clear();
return;
}
2019-05-06 20:51:09 +00:00
2018-05-14 06:52:41 +00:00
mGood = true;
2017-09-29 07:45:56 +00:00
}
2018-05-14 06:52:41 +00:00
Result Directory::error(void)
2017-09-29 07:45:56 +00:00
{
2018-05-14 06:52:41 +00:00
return mError;
2017-09-29 07:45:56 +00:00
}
2018-05-14 06:52:41 +00:00
bool Directory::good(void)
2017-09-29 07:45:56 +00:00
{
2018-05-14 06:52:41 +00:00
return mGood;
2017-09-29 07:45:56 +00:00
}
2018-05-14 06:52:41 +00:00
std::u16string Directory::entry(size_t index)
2017-09-29 07:45:56 +00:00
{
2018-05-14 06:52:41 +00:00
return index < mList.size() ? (char16_t*)mList.at(index).name : StringUtils::UTF8toUTF16("");
2017-09-29 07:45:56 +00:00
}
2018-05-14 06:52:41 +00:00
bool Directory::folder(size_t index)
2017-09-29 07:45:56 +00:00
{
2019-05-06 20:51:09 +00:00
return index < mList.size() ? mList.at(index).attributes == FS_ATTRIBUTE_DIRECTORY : false;
2017-09-29 07:45:56 +00:00
}
2018-05-14 06:52:41 +00:00
size_t Directory::size(void)
2017-09-29 07:45:56 +00:00
{
2018-05-14 06:52:41 +00:00
return mList.size();
2017-09-29 07:45:56 +00:00
}