Commit e35f4fa0 authored by fallenstardust's avatar fallenstardust

safe file name

parent d1bb196a
...@@ -310,42 +310,42 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -310,42 +310,42 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_EXPORT_DECK: { case BUTTON_EXPORT_DECK: {
if(mainGame->lstReplayList->getSelected() == -1) if(mainGame->lstReplayList->getSelected() == -1)
break; break;
Replay replay; Replay replay;
wchar_t ex_filename[256]; wchar_t ex_filename[256];
wchar_t namebuf[4][20]; wchar_t namebuf[4][20];
wchar_t filename[256]; wchar_t filename[256];
myswprintf(ex_filename, L"%ls", mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected())); myswprintf(ex_filename, L"%ls", mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected()));
if(!replay.OpenReplay(ex_filename)) if(!replay.OpenReplay(ex_filename))
break; break;
const ReplayHeader& rh = replay.pheader; const ReplayHeader& rh = replay.pheader;
if(rh.flag & REPLAY_SINGLE_MODE) if(rh.flag & REPLAY_SINGLE_MODE)
break; break;
int max = (rh.flag & REPLAY_TAG) ? 4 : 2; int max = (rh.flag & REPLAY_TAG) ? 4 : 2;
//player name //player name
for(int i = 0; i < max; ++i) for(int i = 0; i < max; ++i)
replay.ReadName(namebuf[i]); replay.ReadName(namebuf[i]);
//skip pre infos //skip pre infos
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
replay.ReadInt32(); replay.ReadInt32();
//deck //deck
for(int i = 0; i < max; ++i) { for(int i = 0; i < max; ++i) {
int main = replay.ReadInt32(); int main = replay.ReadInt32();
Deck tmp_deck; Deck tmp_deck;
for(int j = 0; j < main; ++j) for(int j = 0; j < main; ++j)
tmp_deck.main.push_back(dataManager.GetCodePointer(replay.ReadInt32())); tmp_deck.main.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
int extra = replay.ReadInt32(); int extra = replay.ReadInt32();
for(int j = 0; j < extra; ++j) for(int j = 0; j < extra; ++j)
tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32())); tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]); FileSystem::SafeFileName(namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename); myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]);
} deckManager.SaveDeck(tmp_deck, filename);
mainGame->stACMessage->setText(dataManager.GetSysString(1335)); }
mainGame->PopupElement(mainGame->wACMessage, 20); mainGame->stACMessage->setText(dataManager.GetSysString(1335));
break; mainGame->PopupElement(mainGame->wACMessage, 20);
} break;
//TEST BOT MODE }
case BUTTON_BOT_START: { case BUTTON_BOT_START: {
int sel = mainGame->lstBotList->getSelected(); int sel = mainGame->lstBotList->getSelected();
if(sel == -1) if(sel == -1)
......
...@@ -19,6 +19,11 @@ ...@@ -19,6 +19,11 @@
class FileSystem { class FileSystem {
public: public:
static void SafeFileName(wchar_t* wfile) {
while((wfile = wcspbrk(wfile, L"<>:\"/\\|?*")) != NULL)
*wfile++ = '_';
}
static bool IsFileExists(const wchar_t* wfile) { static bool IsFileExists(const wchar_t* wfile) {
DWORD attr = GetFileAttributesW(wfile); DWORD attr = GetFileAttributesW(wfile);
return attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY); return attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY);
...@@ -112,6 +117,11 @@ public: ...@@ -112,6 +117,11 @@ public:
class FileSystem { class FileSystem {
public: public:
static void SafeFileName(wchar_t* wfile) {
while((wfile = wcspbrk(wfile, L"/")) != NULL)
*wfile++ = '_';
}
static bool IsFileExists(const char* file) { static bool IsFileExists(const char* file) {
struct stat fileStat; struct stat fileStat;
return (stat(file, &fileStat) == 0) && !S_ISDIR(fileStat.st_mode); 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