2014-09-12 00:46:42 +02:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/file_util.h"
|
|
|
|
|
|
|
|
#include "core/file_sys/directory_sdmc.h"
|
|
|
|
#include "core/file_sys/archive_sdmc.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FileSys namespace
|
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
|
|
|
Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const std::string& path) {
|
|
|
|
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
|
|
|
// the root directory we set while opening the archive.
|
|
|
|
// For example, opening /../../usr/bin can give the emulated program your installed programs.
|
|
|
|
std::string absolute_path = archive->GetMountPoint() + path;
|
2014-09-29 10:34:37 +02:00
|
|
|
FileUtil::ScanDirectoryTree(absolute_path, directory);
|
|
|
|
children_iterator = directory.children.begin();
|
2014-09-12 00:46:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Directory_SDMC::~Directory_SDMC() {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List files contained in the directory
|
|
|
|
* @param count Number of entries to return at once in entries
|
|
|
|
* @param entries Buffer to read data into
|
|
|
|
* @return Number of entries listed
|
|
|
|
*/
|
|
|
|
u32 Directory_SDMC::Read(const u32 count, Entry* entries) {
|
2014-09-29 10:34:37 +02:00
|
|
|
u32 entries_read = 0;
|
|
|
|
|
|
|
|
while (entries_read < count && children_iterator != directory.children.cend()) {
|
|
|
|
const FileUtil::FSTEntry& file = *children_iterator;
|
|
|
|
const std::string& filename = file.virtualName;
|
|
|
|
Entry& entry = entries[entries_read];
|
2014-09-12 00:46:42 +02:00
|
|
|
|
2014-09-29 10:34:37 +02:00
|
|
|
WARN_LOG(FILESYS, "File %s: size=%d dir=%d", filename.c_str(), file.size, file.isDirectory);
|
2014-09-12 00:46:42 +02:00
|
|
|
|
|
|
|
// TODO(Link Mauve): use a proper conversion to UTF-16.
|
|
|
|
for (int j = 0; j < FILENAME_LENGTH; ++j) {
|
2014-09-29 10:34:37 +02:00
|
|
|
entry.filename[j] = filename[j];
|
2014-09-12 00:46:42 +02:00
|
|
|
if (!filename[j])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-29 10:34:37 +02:00
|
|
|
FileUtil::SplitFilename83(filename, entry.short_name, entry.extension);
|
2014-09-12 00:46:42 +02:00
|
|
|
|
2014-09-29 10:34:37 +02:00
|
|
|
entry.is_directory = file.isDirectory;
|
|
|
|
entry.is_hidden = (filename[0] == '.');
|
|
|
|
entry.is_read_only = 0;
|
|
|
|
entry.file_size = file.size;
|
2014-09-12 00:46:42 +02:00
|
|
|
|
|
|
|
// We emulate a SD card where the archive bit has never been cleared, as it would be on
|
|
|
|
// most user SD cards.
|
|
|
|
// Some homebrews (blargSNES for instance) are known to mistakenly use the archive bit as a
|
|
|
|
// file bit.
|
2014-09-29 10:34:37 +02:00
|
|
|
entry.is_archive = !file.isDirectory;
|
2014-09-12 00:46:42 +02:00
|
|
|
|
2014-09-29 10:34:37 +02:00
|
|
|
++entries_read;
|
|
|
|
++children_iterator;
|
2014-09-12 00:46:42 +02:00
|
|
|
}
|
2014-09-29 10:34:37 +02:00
|
|
|
return entries_read;
|
2014-09-12 00:46:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the directory
|
|
|
|
* @return true if the directory closed correctly
|
|
|
|
*/
|
|
|
|
bool Directory_SDMC::Close() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace FileSys
|