aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>2014-09-29 08:34:37 +0000
committerGravatar Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>2014-10-06 19:58:43 +0200
commitfbd72fd6bf0f02a13be207c9d61f630c594e3156 (patch)
tree766620c93a936e767cc073382573660041c2e193 /src/core/file_sys
parent19c2a96ab07649f901fea9e14fcb6d762c307cbc (diff)
Common: Add a helper function to generate a 8.3 filename from a long one.
Core: Fix the SDMC Directory implementation to make blargSnes work.
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/directory.h4
-rw-r--r--src/core/file_sys/directory_sdmc.cpp43
-rw-r--r--src/core/file_sys/directory_sdmc.h9
3 files changed, 27 insertions, 29 deletions
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h
index 9f3546b0..e1043133 100644
--- a/src/core/file_sys/directory.h
+++ b/src/core/file_sys/directory.h
@@ -19,9 +19,9 @@ namespace FileSys {
const size_t FILENAME_LENGTH = 0x20C / 2;
struct Entry {
char16_t filename[FILENAME_LENGTH]; // Entry name (UTF-16, null-terminated)
- char short_name[9]; // 8.3 file name ('longfilename' -> 'LONGFI~1', null-terminated)
+ std::array<char, 9> short_name; // 8.3 file name ('longfilename' -> 'LONGFI~1', null-terminated)
char unknown1; // unknown (observed values: 0x0A, 0x70, 0xFD)
- char extension[4]; // 8.3 file extension (set to spaces for directories, null-terminated)
+ std::array<char, 4> extension; // 8.3 file extension (set to spaces for directories, null-terminated)
char unknown2; // unknown (always 0x01)
char unknown3; // unknown (0x00 or 0x08)
char is_directory; // directory flag
diff --git a/src/core/file_sys/directory_sdmc.cpp b/src/core/file_sys/directory_sdmc.cpp
index 11e86785..36951564 100644
--- a/src/core/file_sys/directory_sdmc.cpp
+++ b/src/core/file_sys/directory_sdmc.cpp
@@ -20,8 +20,8 @@ Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const std::string& p
// 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;
- entry_count = FileUtil::ScanDirectoryTree(absolute_path, entry);
- current_entry = 0;
+ FileUtil::ScanDirectoryTree(absolute_path, directory);
+ children_iterator = directory.children.begin();
}
Directory_SDMC::~Directory_SDMC() {
@@ -35,44 +35,39 @@ Directory_SDMC::~Directory_SDMC() {
* @return Number of entries listed
*/
u32 Directory_SDMC::Read(const u32 count, Entry* entries) {
- u32 i;
- for (i = 0; i < count && current_entry < entry_count; ++i) {
- FileUtil::FSTEntry file = entry.children[current_entry];
- std::string filename = file.virtualName;
- WARN_LOG(FILESYS, "File %s: size=%d dir=%d", filename.c_str(), file.size, file.isDirectory);
+ 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];
- Entry* entry = &entries[i];
+ WARN_LOG(FILESYS, "File %s: size=%d dir=%d", filename.c_str(), file.size, file.isDirectory);
// TODO(Link Mauve): use a proper conversion to UTF-16.
for (int j = 0; j < FILENAME_LENGTH; ++j) {
- entry->filename[j] = filename[j];
+ entry.filename[j] = filename[j];
if (!filename[j])
break;
}
- // Split the filename into 8.3 format.
- // TODO(Link Mauve): move that to common, I guess, and make it more robust to long filenames.
- std::string::size_type n = filename.rfind('.');
- if (n == std::string::npos) {
- strncpy(entry->short_name, filename.c_str(), 8);
- memset(entry->extension, '\0', 3);
- } else {
- strncpy(entry->short_name, filename.substr(0, n).c_str(), 8);
- strncpy(entry->extension, filename.substr(n + 1).c_str(), 8);
- }
+ FileUtil::SplitFilename83(filename, entry.short_name, entry.extension);
- entry->is_directory = file.isDirectory;
- entry->file_size = file.size;
+ entry.is_directory = file.isDirectory;
+ entry.is_hidden = (filename[0] == '.');
+ entry.is_read_only = 0;
+ entry.file_size = file.size;
// 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.
- entry->is_archive = !file.isDirectory;
+ entry.is_archive = !file.isDirectory;
- ++current_entry;
+ ++entries_read;
+ ++children_iterator;
}
- return i;
+ return entries_read;
}
/**
diff --git a/src/core/file_sys/directory_sdmc.h b/src/core/file_sys/directory_sdmc.h
index 0bc6c9ef..cb8d32fd 100644
--- a/src/core/file_sys/directory_sdmc.h
+++ b/src/core/file_sys/directory_sdmc.h
@@ -37,9 +37,12 @@ public:
bool Close() const override;
private:
- u32 entry_count;
- u32 current_entry;
- FileUtil::FSTEntry entry;
+ u32 total_entries_in_directory;
+ FileUtil::FSTEntry directory;
+
+ // We need to remember the last entry we returned, so a subsequent call to Read will continue
+ // from the next one. This iterator will always point to the next unread entry.
+ std::vector<FileUtil::FSTEntry>::iterator children_iterator;
};
} // namespace FileSys