Commit 7c71bf63 authored by mercury233's avatar mercury233 Committed by GitHub

check the filename generated from the playername (#2372)

parent 732662cc
......@@ -309,6 +309,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int extra = replay.ReadInt32();
for(int j = 0; j < extra; ++j)
tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
FileSystem::SafeFileName(namebuf[i]);
myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename);
}
......
......@@ -19,6 +19,11 @@
class FileSystem {
public:
static void SafeFileName(wchar_t* wfile) {
while((wfile = wcspbrk(wfile, L"<>:\"/\\|?*")) != NULL)
*wfile++ = '_';
}
static bool IsFileExists(const wchar_t* wfile) {
DWORD attr = GetFileAttributesW(wfile);
return attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY);
......@@ -112,6 +117,11 @@ public:
class FileSystem {
public:
static void SafeFileName(wchar_t* wfile) {
while((wfile = wcspbrk(wfile, L"/")) != NULL)
*wfile++ = '_';
}
static bool IsFileExists(const char* file) {
struct stat fileStat;
return (stat(file, &fileStat) == 0) && !S_ISDIR(fileStat.st_mode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment