Skip to content

Commit

Permalink
Convert filename to UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
bet4it committed Aug 25, 2018
1 parent f7e590d commit 6eef025
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.8)
project(fatcat)

set(CMAKE_CXX_STANDARD 11)
set(SOURCES
core/FatEntry.cpp
core/FatFilename.cpp
Expand Down
39 changes: 16 additions & 23 deletions src/core/FatFilename.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#include <string>
#include <iostream>
#include <locale>
#include <codecvt>
#include "FatFilename.h"
#include "FatEntry.h"

using namespace std;

#define FAT_LONG_NAME_LAST 0x40

// Offset of letters position in a special "long file name" entry
static unsigned char longFilePos[] = {
30, 28, 24, 22, 20, 18, 16, 14, 9, 7, 5, 3, 1
};

string FatFilename::getFilename()
{
string rfilename;
vector<string>::iterator it;
string filename;
vector<string>::reverse_iterator it;
wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;

for (it=letters.begin(); it!=letters.end(); it++) {
rfilename += *it;
for (it=letters.rbegin(); it!=letters.rend(); it++) {
filename += *it;
}
letters.clear();

return string(rfilename.rbegin(), rfilename.rend());
if (!filename.length()) {
return {};
}
return convert.to_bytes((char16_t *)filename.c_str());
}

void FatFilename::append(char *buffer)
Expand All @@ -35,18 +36,10 @@ void FatFilename::append(char *buffer)
letters.clear();
}

int i;
for (i=0; i<sizeof(longFilePos); i++) {
unsigned char c = buffer[longFilePos[i]];
unsigned char d = buffer[longFilePos[i]+1];
if (c != 0 && c != 0xff) {
string letter;
if (d != 0x00) {
letter += d;
}
letter += c;
letters.push_back(letter);
}
}
string letter;
letter.append(buffer + 1, 5 * 2);
letter.append(buffer + 14, 6 * 2);
letter.append(buffer + 28, 2 * 2);
letters.push_back(letter);
}

0 comments on commit 6eef025

Please sign in to comment.