Commit f74786b3 authored by DailyShana's avatar DailyShana

Revert "Revert "fix & remove redoundant code""

This reverts commit f42ed605.
parent f42ed605
...@@ -12,9 +12,6 @@ bool open_file = false; ...@@ -12,9 +12,6 @@ bool open_file = false;
wchar_t open_file_name[256] = L""; wchar_t open_file_name[256] = L"";
bool bot_mode = false; bool bot_mode = false;
void GetParameterW(wchar_t* param, const char* arg) {
BufferIO::DecodeUTF8(arg, param);
}
void ClickButton(irr::gui::IGUIElement* btn) { void ClickButton(irr::gui::IGUIElement* btn) {
irr::SEvent event; irr::SEvent event;
event.EventType = irr::EET_GUI_EVENT; event.EventType = irr::EET_GUI_EVENT;
...@@ -60,120 +57,66 @@ int main(int argc, char* argv[]) { ...@@ -60,120 +57,66 @@ int main(int argc, char* argv[]) {
return 0; return 0;
#ifdef _WIN32 #ifdef _WIN32
wchar_t* command = GetCommandLineW(); wchar_t** wargv;
char buffer[2048]; int wargc;
BufferIO::EncodeUTF8(command, buffer); LPWSTR commandLine = GetCommandLineW();
char* ptr = buffer; wargv = CommandLineToArgvW(commandLine, &wargc);
argc = 0; #else
int j = 0; wchar_t wargv[argc][256];
bool in_QM = false, in_TEXT = false, in_SPACE = true; for(int i = 1; i < argc; ++i) {
while(*ptr) { BufferIO::DecodeUTF8(argv[i], wargv[i]);
if(in_QM) {
if(*ptr == '\"')
in_QM = false;
else
++j;
} else {
switch(*ptr) {
case '\"': {
in_QM = true;
in_TEXT = true;
if(in_SPACE) {
argv[argc] = ptr + 1;
j = 0;
}
in_SPACE = false;
break;
}
case ' ':
case '\t':
case '\n':
case '\r': {
if(in_TEXT) {
argv[argc][j] = '\0';
++argc;
}
in_TEXT = false;
in_SPACE = true;
break;
}
default: {
in_TEXT = true;
if(in_SPACE) {
argv[argc] = ptr;
j = 1;
} else
++j;
in_SPACE = false;
break;
}
}
}
++ptr;
}
if(in_TEXT) {
argv[argc][j] = '\0';
++argc;
} }
argv[argc] = NULL; #endif //_WIN32
#endif // _WIN32
bool keep_on_return = false; bool keep_on_return = false;
for(int i = 1; i < argc; ++i) { for(int i = 1; i < argc; ++i) {
if(argv[i][0] == '-' && argv[i][1] == 'e' && argv[i][2]) { if(argv[i][0] == '-' && argv[i][1] == 'e' && argv[i][2] != '\0') {
ygo::dataManager.LoadDB(&argv[i][2]); char param[128];
BufferIO::EncodeUTF8(&wargv[i][2], param);
ygo::dataManager.LoadDB(param);
continue; continue;
} }
if(!strcmp(argv[i], "-e")) { // extra database if(!strcmp(argv[i], "-e")) { // extra database
++i; ++i;
if(i < argc) if(i < argc) {
ygo::dataManager.LoadDB(&argv[i][0]); char param[128];
BufferIO::EncodeUTF8(wargv[i], param);
ygo::dataManager.LoadDB(param);
}
continue; continue;
} else if(!strcmp(argv[i], "-n")) { // nickName } else if(!strcmp(argv[i], "-n")) { // nickName
++i; ++i;
if(i < argc) { if(i < argc)
wchar_t param[128]; ygo::mainGame->ebNickName->setText(wargv[i]);
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebNickName->setText(param);
}
continue; continue;
} else if(!strcmp(argv[i], "-h")) { // Host address } else if(!strcmp(argv[i], "-h")) { // Host address
++i; ++i;
if(i < argc) { if(i < argc)
wchar_t param[128]; ygo::mainGame->ebJoinHost->setText(wargv[i]);
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinHost->setText(param);
}
continue; continue;
} else if(!strcmp(argv[i], "-p")) { // host Port } else if(!strcmp(argv[i], "-p")) { // host Port
++i; ++i;
if(i < argc) { if(i < argc)
wchar_t param[128]; ygo::mainGame->ebJoinPort->setText(wargv[i]);
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPort->setText(param);
}
continue; continue;
} else if(!strcmp(argv[i], "-w")) { // host passWord } else if(!strcmp(argv[i], "-w")) { // host passWord
++i; ++i;
if(i < argc) { if(i < argc)
wchar_t param[128]; ygo::mainGame->ebJoinPass->setText(wargv[i]);
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPass->setText(param);
}
continue; continue;
} else if(!strcmp(argv[i], "-k")) { // Keep on return } else if(!strcmp(argv[i], "-k")) { // Keep on return
exit_on_return = false; exit_on_return = false;
keep_on_return = true; keep_on_return = true;
} else if(!strcmp(argv[i], "-d")) { // Deck } else if(!strcmp(argv[i], "-d")) { // Deck
if(i + 2 < argc) { // select deck ++i;
++i; if(i + 1 < argc) { // select deck
GetParameterW(ygo::mainGame->gameConf.lastdeck, &argv[i][0]); wcscpy(ygo::mainGame->gameConf.lastdeck, wargv[i]);
continue; continue;
} else { // open deck } else { // open deck
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
if(i + 1 < argc) { if(i < argc) {
open_file = true; open_file = true;
GetParameterW(open_file_name, &argv[i + 1][0]); wcscpy(open_file_name, wargv[i]);
} }
ClickButton(ygo::mainGame->btnDeckEdit); ClickButton(ygo::mainGame->btnDeckEdit);
break; break;
...@@ -190,9 +133,10 @@ int main(int argc, char* argv[]) { ...@@ -190,9 +133,10 @@ int main(int argc, char* argv[]) {
break; break;
} else if(!strcmp(argv[i], "-r")) { // Replay } else if(!strcmp(argv[i], "-r")) { // Replay
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
if(i + 1 < argc) { ++i;
if(i < argc) {
open_file = true; open_file = true;
GetParameterW(open_file_name, &argv[i + 1][0]); wcscpy(open_file_name, wargv[i]);
} }
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
if(open_file) if(open_file)
...@@ -200,9 +144,10 @@ int main(int argc, char* argv[]) { ...@@ -200,9 +144,10 @@ int main(int argc, char* argv[]) {
break; break;
} else if(!strcmp(argv[i], "-s")) { // Single } else if(!strcmp(argv[i], "-s")) { // Single
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
if(i + 1 < argc) { ++i;
if(i < argc) {
open_file = true; open_file = true;
GetParameterW(open_file_name, &argv[i + 1][0]); wcscpy(open_file_name, wargv[i]);
} }
ClickButton(ygo::mainGame->btnSingleMode); ClickButton(ygo::mainGame->btnSingleMode);
if(open_file) if(open_file)
...@@ -212,14 +157,14 @@ int main(int argc, char* argv[]) { ...@@ -212,14 +157,14 @@ int main(int argc, char* argv[]) {
char* pstrext = argv[1] + strlen(argv[1]) - 4; char* pstrext = argv[1] + strlen(argv[1]) - 4;
if(!mystrncasecmp(pstrext, ".ydk", 4)) { if(!mystrncasecmp(pstrext, ".ydk", 4)) {
open_file = true; open_file = true;
GetParameterW(open_file_name, &argv[1][0]); wcscpy(open_file_name, wargv[i]);
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnDeckEdit); ClickButton(ygo::mainGame->btnDeckEdit);
break; break;
} }
if(!mystrncasecmp(pstrext, ".yrp", 4)) { if(!mystrncasecmp(pstrext, ".yrp", 4)) {
open_file = true; open_file = true;
GetParameterW(open_file_name, &argv[1][0]); wcscpy(open_file_name, wargv[i]);
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnReplayMode); ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay); ClickButton(ygo::mainGame->btnLoadReplay);
...@@ -227,6 +172,9 @@ int main(int argc, char* argv[]) { ...@@ -227,6 +172,9 @@ int main(int argc, char* argv[]) {
} }
} }
} }
#ifdef _WIN32
LocalFree(wargv);
#endif
ygo::mainGame->MainLoop(); ygo::mainGame->MainLoop();
#ifdef _WIN32 #ifdef _WIN32
WSACleanup(); WSACleanup();
......
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