Commit 3ecfeece authored by mercury233's avatar mercury233 Committed by GitHub

fix deck arg (#2380)

parent 95daf329
...@@ -92,7 +92,6 @@ extern int enable_log; ...@@ -92,7 +92,6 @@ extern int enable_log;
extern bool exit_on_return; extern bool exit_on_return;
extern bool open_file; extern bool open_file;
extern wchar_t open_file_name[256]; extern wchar_t open_file_name[256];
extern wchar_t open_file_name_with_category[256];
extern bool bot_mode; extern bool bot_mode;
#endif #endif
...@@ -11,7 +11,6 @@ int enable_log = 0; ...@@ -11,7 +11,6 @@ int enable_log = 0;
bool exit_on_return = false; bool exit_on_return = false;
bool open_file = false; bool open_file = false;
wchar_t open_file_name[256] = L""; wchar_t open_file_name[256] = L"";
wchar_t open_file_name_with_category[256] = L"";
bool bot_mode = false; bool bot_mode = false;
void ClickButton(irr::gui::IGUIElement* btn) { void ClickButton(irr::gui::IGUIElement* btn) {
...@@ -128,11 +127,14 @@ int main(int argc, char* argv[]) { ...@@ -128,11 +127,14 @@ int main(int argc, char* argv[]) {
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
if(i < wargc) { if(i < wargc) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); if(deckCategorySpecified) {
if(deckCategorySpecified && wcslen(ygo::mainGame->gameConf.lastcategory)) { #ifdef WIN32
swprintf(open_file_name_with_category, 256, L"%ls/%ls", ygo::mainGame->gameConf.lastcategory, open_file_name); myswprintf(open_file_name, L"%ls\\%ls", ygo::mainGame->gameConf.lastcategory, wargv[i]);
#else
myswprintf(open_file_name, L"%ls/%ls", ygo::mainGame->gameConf.lastcategory, wargv[i]);
#endif
} else { } else {
wcscpy(open_file_name_with_category, open_file_name); wcscpy(open_file_name, wargv[i]);
} }
} }
ClickButton(ygo::mainGame->btnDeckEdit); ClickButton(ygo::mainGame->btnDeckEdit);
......
...@@ -399,14 +399,14 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -399,14 +399,14 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
} }
case BUTTON_DECK_EDIT: { case BUTTON_DECK_EDIT: {
mainGame->RefreshCategoryDeck(mainGame->cbDBCategory, mainGame->cbDBDecks); mainGame->RefreshCategoryDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
if(open_file && deckManager.LoadDeck(open_file_name_with_category)) { if(open_file && deckManager.LoadDeck(open_file_name)) {
#ifdef WIN32 #ifdef WIN32
wchar_t *dash = wcsrchr(open_file_name, L'\\'); wchar_t *dash = wcsrchr(open_file_name, L'\\');
#else #else
wchar_t *dash = wcsrchr(open_file_name, L'/'); wchar_t *dash = wcsrchr(open_file_name, L'/');
#endif #endif
wchar_t *dot = wcsrchr(open_file_name, L'.'); wchar_t *dot = wcsrchr(open_file_name, L'.');
if(dash && dot) { if(dash && dot && !mywcsncasecmp(dot, L".ydk", 4)) { // full path
wchar_t deck_name[256]; wchar_t deck_name[256];
wcsncpy(deck_name, dash + 1, dot - dash - 1); wcsncpy(deck_name, dash + 1, dot - dash - 1);
deck_name[dot - dash - 1] = L'\0'; deck_name[dot - dash - 1] = L'\0';
...@@ -416,7 +416,17 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -416,7 +416,17 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->btnManageDeck->setEnabled(false); mainGame->btnManageDeck->setEnabled(false);
mainGame->cbDBCategory->setEnabled(false); mainGame->cbDBCategory->setEnabled(false);
mainGame->cbDBDecks->setEnabled(false); mainGame->cbDBDecks->setEnabled(false);
} else { } else if(dash) { // has category
wchar_t deck_name[256];
wcsncpy(deck_name, dash + 1, 256);
for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
if(!wcscmp(mainGame->cbDBDecks->getItem(i), deck_name)) {
wcscpy(mainGame->gameConf.lastdeck, deck_name);
mainGame->cbDBDecks->setSelected(i);
break;
}
}
} else { // only deck name
for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) { for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
if(!wcscmp(mainGame->cbDBDecks->getItem(i), open_file_name)) { if(!wcscmp(mainGame->cbDBDecks->getItem(i), open_file_name)) {
wcscpy(mainGame->gameConf.lastdeck, open_file_name); wcscpy(mainGame->gameConf.lastdeck, open_file_name);
......
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