Commit 2c080e02 authored by mercury233's avatar mercury233

fix & remove redoundant code

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