Commit b2996052 authored by DailyShana's avatar DailyShana

fix and unify

parent f74786b3
...@@ -57,84 +57,83 @@ int main(int argc, char* argv[]) { ...@@ -57,84 +57,83 @@ int main(int argc, char* argv[]) {
return 0; return 0;
#ifdef _WIN32 #ifdef _WIN32
wchar_t** wargv;
int wargc; int wargc;
LPWSTR commandLine = GetCommandLineW(); wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
wargv = CommandLineToArgvW(commandLine, &wargc);
#else #else
wchar_t wargv[argc][256]; int wargc = argc;
for(int i = 1; i < argc; ++i) { wchar_t (*wargv)[256] = new wchar_t[wargc][256];
for(int i = 0; i < argc; ++i) {
BufferIO::DecodeUTF8(argv[i], wargv[i]); BufferIO::DecodeUTF8(argv[i], wargv[i]);
} }
#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 < wargc; ++i) {
if(argv[i][0] == '-' && argv[i][1] == 'e' && argv[i][2] != '\0') { if(wargv[i][0] == L'-' && wargv[i][1] == L'e' && wargv[i][2] != L'\0') {
char param[128]; char param[128];
BufferIO::EncodeUTF8(&wargv[i][2], param); BufferIO::EncodeUTF8(&wargv[i][2], param);
ygo::dataManager.LoadDB(param); ygo::dataManager.LoadDB(param);
continue; continue;
} }
if(!strcmp(argv[i], "-e")) { // extra database if(!wcscmp(wargv[i], L"-e")) { // extra database
++i; ++i;
if(i < argc) { if(i < wargc) {
char param[128]; char param[128];
BufferIO::EncodeUTF8(wargv[i], param); BufferIO::EncodeUTF8(wargv[i], param);
ygo::dataManager.LoadDB(param); ygo::dataManager.LoadDB(param);
} }
continue; continue;
} else if(!strcmp(argv[i], "-n")) { // nickName } else if(!wcscmp(wargv[i], L"-n")) { // nickName
++i; ++i;
if(i < argc) if(i < wargc)
ygo::mainGame->ebNickName->setText(wargv[i]); ygo::mainGame->ebNickName->setText(wargv[i]);
continue; continue;
} else if(!strcmp(argv[i], "-h")) { // Host address } else if(!wcscmp(wargv[i], L"-h")) { // Host address
++i; ++i;
if(i < argc) if(i < wargc)
ygo::mainGame->ebJoinHost->setText(wargv[i]); ygo::mainGame->ebJoinHost->setText(wargv[i]);
continue; continue;
} else if(!strcmp(argv[i], "-p")) { // host Port } else if(!wcscmp(wargv[i], L"-p")) { // host Port
++i; ++i;
if(i < argc) if(i < wargc)
ygo::mainGame->ebJoinPort->setText(wargv[i]); ygo::mainGame->ebJoinPort->setText(wargv[i]);
continue; continue;
} else if(!strcmp(argv[i], "-w")) { // host passWord } else if(!wcscmp(wargv[i], L"-w")) { // host passWord
++i; ++i;
if(i < argc) if(i < wargc)
ygo::mainGame->ebJoinPass->setText(wargv[i]); ygo::mainGame->ebJoinPass->setText(wargv[i]);
continue; continue;
} else if(!strcmp(argv[i], "-k")) { // Keep on return } else if(!wcscmp(wargv[i], L"-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(!wcscmp(wargv[i], L"-d")) { // Deck
++i; ++i;
if(i + 1 < argc) { // select deck if(i + 1 < wargc) { // select deck
wcscpy(ygo::mainGame->gameConf.lastdeck, wargv[i]); 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 < argc) { if(i < wargc) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcscpy(open_file_name, wargv[i]);
} }
ClickButton(ygo::mainGame->btnDeckEdit); ClickButton(ygo::mainGame->btnDeckEdit);
break; break;
} }
} else if(!strcmp(argv[i], "-c")) { // Create host } else if(!wcscmp(wargv[i], L"-c")) { // Create host
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu); ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnHostConfirm); ClickButton(ygo::mainGame->btnHostConfirm);
break; break;
} else if(!strcmp(argv[i], "-j")) { // Join host } else if(!wcscmp(wargv[i], L"-j")) { // Join host
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu); ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnJoinHost); ClickButton(ygo::mainGame->btnJoinHost);
break; break;
} else if(!strcmp(argv[i], "-r")) { // Replay } else if(!wcscmp(wargv[i], L"-r")) { // Replay
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
++i; ++i;
if(i < argc) { if(i < wargc) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcscpy(open_file_name, wargv[i]);
} }
...@@ -142,10 +141,10 @@ int main(int argc, char* argv[]) { ...@@ -142,10 +141,10 @@ int main(int argc, char* argv[]) {
if(open_file) if(open_file)
ClickButton(ygo::mainGame->btnLoadReplay); ClickButton(ygo::mainGame->btnLoadReplay);
break; break;
} else if(!strcmp(argv[i], "-s")) { // Single } else if(!wcscmp(wargv[i], L"-s")) { // Single
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
++i; ++i;
if(i < argc) { if(i < wargc) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcscpy(open_file_name, wargv[i]);
} }
...@@ -153,16 +152,16 @@ int main(int argc, char* argv[]) { ...@@ -153,16 +152,16 @@ int main(int argc, char* argv[]) {
if(open_file) if(open_file)
ClickButton(ygo::mainGame->btnLoadSinglePlay); ClickButton(ygo::mainGame->btnLoadSinglePlay);
break; break;
} else if(argc == 2 && strlen(argv[1]) >= 4) { } else if(wargc == 2 && wcslen(wargv[1]) >= 4) {
char* pstrext = argv[1] + strlen(argv[1]) - 4; wchar_t* pstrext = wargv[1] + wcslen(wargv[1]) - 4;
if(!mystrncasecmp(pstrext, ".ydk", 4)) { if(!mywcsncasecmp(pstrext, L".ydk", 4)) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); 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(!mywcsncasecmp(pstrext, L".yrp", 4)) {
open_file = true; open_file = true;
wcscpy(open_file_name, wargv[i]); wcscpy(open_file_name, wargv[i]);
exit_on_return = !keep_on_return; exit_on_return = !keep_on_return;
...@@ -174,6 +173,8 @@ int main(int argc, char* argv[]) { ...@@ -174,6 +173,8 @@ int main(int argc, char* argv[]) {
} }
#ifdef _WIN32 #ifdef _WIN32
LocalFree(wargv); LocalFree(wargv);
#else
delete[] wargv;
#endif #endif
ygo::mainGame->MainLoop(); ygo::mainGame->MainLoop();
#ifdef _WIN32 #ifdef _WIN32
......
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