Commit f42ed605 authored by DailyShana's avatar DailyShana

Revert "fix & remove redoundant code"

This reverts commit 2c080e02.
parent 2c080e02
......@@ -12,6 +12,9 @@ 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;
......@@ -57,66 +60,120 @@ int main(int argc, char* argv[]) {
return 0;
#ifdef _WIN32
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]);
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;
}
#endif //_WIN32
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
bool keep_on_return = false;
for(int i = 1; i < argc; ++i) {
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);
if(argv[i][0] == '-' && argv[i][1] == 'e' && argv[i][2]) {
ygo::dataManager.LoadDB(&argv[i][2]);
continue;
}
if(!strcmp(argv[i], "-e")) { // extra database
++i;
if(i < argc) {
char param[128];
BufferIO::EncodeUTF8(wargv[i], param);
ygo::dataManager.LoadDB(param);
}
if(i < argc)
ygo::dataManager.LoadDB(&argv[i][0]);
continue;
} else if(!strcmp(argv[i], "-n")) { // nickName
++i;
if(i < argc)
ygo::mainGame->ebNickName->setText(wargv[i]);
if(i < argc) {
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebNickName->setText(param);
}
continue;
} else if(!strcmp(argv[i], "-h")) { // Host address
++i;
if(i < argc)
ygo::mainGame->ebJoinHost->setText(wargv[i]);
if(i < argc) {
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinHost->setText(param);
}
continue;
} else if(!strcmp(argv[i], "-p")) { // host Port
++i;
if(i < argc)
ygo::mainGame->ebJoinPort->setText(wargv[i]);
if(i < argc) {
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPort->setText(param);
}
continue;
} else if(!strcmp(argv[i], "-w")) { // host passWord
++i;
if(i < argc)
ygo::mainGame->ebJoinPass->setText(wargv[i]);
if(i < argc) {
wchar_t param[128];
GetParameterW(param, &argv[i][0]);
ygo::mainGame->ebJoinPass->setText(param);
}
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;
if(i + 1 < argc) { // select deck
wcscpy(ygo::mainGame->gameConf.lastdeck, wargv[i]);
GetParameterW(ygo::mainGame->gameConf.lastdeck, &argv[i][0]);
continue;
} else { // open deck
exit_on_return = !keep_on_return;
if(i < argc) {
if(i + 1 < argc) {
open_file = true;
wcscpy(open_file_name, wargv[i]);
GetParameterW(open_file_name, &argv[i + 1][0]);
}
ClickButton(ygo::mainGame->btnDeckEdit);
break;
......@@ -133,10 +190,9 @@ int main(int argc, char* argv[]) {
break;
} else if(!strcmp(argv[i], "-r")) { // Replay
exit_on_return = !keep_on_return;
++i;
if(i < argc) {
if(i + 1 < argc) {
open_file = true;
wcscpy(open_file_name, wargv[i]);
GetParameterW(open_file_name, &argv[i + 1][0]);
}
ClickButton(ygo::mainGame->btnReplayMode);
if(open_file)
......@@ -144,10 +200,9 @@ int main(int argc, char* argv[]) {
break;
} else if(!strcmp(argv[i], "-s")) { // Single
exit_on_return = !keep_on_return;
++i;
if(i < argc) {
if(i + 1 < argc) {
open_file = true;
wcscpy(open_file_name, wargv[i]);
GetParameterW(open_file_name, &argv[i + 1][0]);
}
ClickButton(ygo::mainGame->btnSingleMode);
if(open_file)
......@@ -157,14 +212,14 @@ int main(int argc, char* argv[]) {
char* pstrext = argv[1] + strlen(argv[1]) - 4;
if(!mystrncasecmp(pstrext, ".ydk", 4)) {
open_file = true;
wcscpy(open_file_name, wargv[i]);
GetParameterW(open_file_name, &argv[1][0]);
exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnDeckEdit);
break;
}
if(!mystrncasecmp(pstrext, ".yrp", 4)) {
open_file = true;
wcscpy(open_file_name, wargv[i]);
GetParameterW(open_file_name, &argv[1][0]);
exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay);
......@@ -172,9 +227,6 @@ 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