Commit 9ca19022 authored by mercury233's avatar mercury233

update command line parameters

parent ae29e5f2
......@@ -73,5 +73,7 @@ using namespace gui;
extern const unsigned short PRO_VERSION;
extern int enable_log;
extern bool exit_on_return;
extern bool open_file;
extern wchar_t open_file_name[256];
#endif
......@@ -88,7 +88,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_SAVE_DECK: {
if(deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()))) {
int sel = mainGame->cbDBDecks->getSelected();
if(sel>-1 && deckManager.SaveDeck(deckManager.current_deck, mainGame->cbDBDecks->getItem(sel))) {
mainGame->stACMessage->setText(dataManager.GetSysString(1335));
mainGame->PopupElement(mainGame->wACMessage, 20);
}
......
......@@ -168,21 +168,28 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
deck = ndeck;
return true;
}
bool DeckManager::LoadDeck(const wchar_t* file) {
int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
wchar_t deck[64];
myswprintf(deck, L"./deck/%ls.ydk", file);
int cardlist[128];
bool is_side = false;
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
#ifdef WIN32
FILE* fp = _wfopen(deck, L"r");
FILE* fp = _wfopen(file, (wchar_t*)mode);
#else
char deckfn[256];
BufferIO::EncodeUTF8(deck, deckfn);
FILE* fp = fopen(deckfn, "r");
char file2[256];
BufferIO::EncodeUTF8(file, file2);
FILE* fp = fopen(file2, mode);
#endif
return fp;
}
bool DeckManager::LoadDeck(const wchar_t* file) {
int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
wchar_t localfile[64];
myswprintf(localfile, L"./deck/%ls.ydk", file);
FILE* fp = OpenDeckFile(localfile, "r");
if(!fp) {
fp = OpenDeckFile(file, "r");
}
if(!fp)
return false;
int cardlist[128];
bool is_side = false;
char linebuf[256];
fseek(fp, 0, SEEK_END);
int fsize = ftell(fp);
......@@ -211,13 +218,7 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
#ifdef WIN32
FILE* fp = _wfopen(file, L"w");
#else
char filefn[256];
BufferIO::EncodeUTF8(file, filefn);
FILE* fp = fopen(filefn, "w");
#endif
FILE* fp = OpenDeckFile(file, "w");
if(!fp)
return false;
fprintf(fp, "#created by ...\n#main\n");
......
......@@ -40,6 +40,7 @@ public:
int CheckLFList(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
void LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
FILE* OpenDeckFile(const wchar_t * file, const char * mode);
bool LoadDeck(const wchar_t* file);
bool SaveDeck(Deck& deck, const wchar_t* name);
bool DeleteDeck(Deck& deck, const wchar_t* name);
......
......@@ -5,6 +5,40 @@
int enable_log = 0;
bool exit_on_return = false;
bool open_file = false;
wchar_t open_file_name[256] = L"";
const char* GetParameter(const char* arg) {
#ifdef _WIN32
wchar_t arg1[260];
MultiByteToWideChar(CP_ACP, 0, arg, -1, arg1, 260);
char arg2[260];
BufferIO::EncodeUTF8(arg1, arg2);
return arg2;
#else
return arg;
#endif
}
const wchar_t* GetParameterW(const char* arg) {
#ifdef _WIN32
wchar_t arg1[260];
MultiByteToWideChar(CP_ACP, 0, arg, -1, arg1, 260);
return arg1;
#else
wchar_t arg2[260];
BufferIO::DecodeUTF8(arg, arg2);
return arg2;
#endif
}
void ClickButton(irr::gui::IGUIElement* btn) {
irr::SEvent event;
event.EventType = irr::EET_GUI_EVENT;
event.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED;
event.GUIEvent.Caller = btn;
ygo::mainGame->device->postEventFromUser(event);
}
int main(int argc, char* argv[]) {
#ifdef _WIN32
......@@ -22,46 +56,42 @@ int main(int argc, char* argv[]) {
return 0;
for(int i = 1; i < argc; ++i) {
/*command line args:
* -j: join host (host info from system.conf)
* -d: deck edit
* -r: replay */
if(argv[i][0] == '-' && argv[i][1] == 'e') {
#ifdef _WIN32
wchar_t fname[260];
MultiByteToWideChar(CP_ACP, 0, &argv[i][2], -1, fname, 260);
char fname2[260];
BufferIO::EncodeUTF8(fname, fname2);
ygo::dataManager.LoadDB(fname2);
#else
ygo::dataManager.LoadDB(&argv[i][2]);
#endif
} else if(!strcmp(argv[i], "-j") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-r") || !strcmp(argv[i], "-s")) {
if(!strcmp(argv[i], "-e")) { // extra database
++i;
ygo::dataManager.LoadDB(GetParameter(&argv[i][0]));
} else if(!strcmp(argv[i], "-n")) { // nickName
++i;
ygo::mainGame->ebNickName->setText(GetParameterW(&argv[i][0]));
} else if(!strcmp(argv[i], "-h")) { // Host address
++i;
ygo::mainGame->ebJoinIP->setText(GetParameterW(&argv[i][0]));
} else if(!strcmp(argv[i], "-p")) { // host Port
++i;
ygo::mainGame->ebJoinPort->setText(GetParameterW(&argv[i][0]));
} else if(!strcmp(argv[i], "-w")) { // host passWord
++i;
ygo::mainGame->ebJoinPass->setText(GetParameterW(&argv[i][0]));
} else if(!strcmp(argv[i], "-x")) { // eXit on return
exit_on_return = true;
irr::SEvent event;
event.EventType = irr::EET_GUI_EVENT;
event.GUIEvent.EventType = irr::gui::EGET_BUTTON_CLICKED;
if(!strcmp(argv[i], "-j")) {
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
event.GUIEvent.Caller = ygo::mainGame->btnJoinHost;
ygo::mainGame->device->postEventFromUser(event);
} else if(!strcmp(argv[i], "-d")) {
event.GUIEvent.Caller = ygo::mainGame->btnDeckEdit;
ygo::mainGame->device->postEventFromUser(event);
} else if(!strcmp(argv[i], "-r")) {
event.GUIEvent.Caller = ygo::mainGame->btnReplayMode;
ygo::mainGame->device->postEventFromUser(event);
ygo::mainGame->lstReplayList->setSelected(0);
event.GUIEvent.Caller = ygo::mainGame->btnLoadReplay;
ygo::mainGame->device->postEventFromUser(event);
} else if(!strcmp(argv[i], "-s")) {
event.GUIEvent.Caller = ygo::mainGame->btnServerMode;
ygo::mainGame->device->postEventFromUser(event);
ygo::mainGame->lstSinglePlayList->setSelected(0);
event.GUIEvent.Caller = ygo::mainGame->btnLoadSinglePlay;
ygo::mainGame->device->postEventFromUser(event);
}
} else if(!strcmp(argv[i], "-j")) { // Join host
ClickButton(ygo::mainGame->btnLanMode);
ClickButton(ygo::mainGame->btnJoinHost);
break;
} else if(!strcmp(argv[i], "-o")) { // Open file
open_file = true;
++i;
wcscpy(open_file_name, GetParameterW(&argv[i][0]));
} else if(!strcmp(argv[i], "-d")) { // Deck
ClickButton(ygo::mainGame->btnDeckEdit);
break;
} else if(!strcmp(argv[i], "-r")) { // Replay
ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay);
break;
} else if(!strcmp(argv[i], "-s")) { // Single
ClickButton(ygo::mainGame->btnServerMode);
ClickButton(ygo::mainGame->btnLoadSinglePlay);
break;
}
}
ygo::mainGame->MainLoop();
......
......@@ -74,6 +74,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
case BUTTON_JOIN_CANCEL: {
mainGame->HideElement(mainGame->wLanWindow);
mainGame->ShowElement(mainGame->wMainMenu);
if(exit_on_return)
mainGame->device->closeDevice();
break;
}
case BUTTON_LAN_REFRESH: {
......@@ -160,10 +162,15 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_LOAD_REPLAY: {
if(open_file) {
ReplayMode::cur_replay.OpenReplay(open_file_name);
open_file = false;
} else {
if(mainGame->lstReplayList->getSelected() == -1)
break;
if(!ReplayMode::cur_replay.OpenReplay(mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected())))
break;
}
mainGame->imgCard->setImage(imageManager.tCover[0]);
mainGame->wCardImg->setVisible(true);
mainGame->wInfos->setVisible(true);
......@@ -198,7 +205,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_LOAD_SINGLEPLAY: {
if(mainGame->lstSinglePlayList->getSelected() == -1)
if(!open_file && mainGame->lstSinglePlayList->getSelected() == -1)
break;
mainGame->singleSignal.SetNoWait(false);
SingleMode::StartPlay();
......@@ -211,8 +218,32 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case BUTTON_DECK_EDIT: {
mainGame->RefreshDeck(mainGame->cbDBDecks);
if(mainGame->cbDBDecks->getSelected() != -1)
if(open_file && deckManager.LoadDeck(open_file_name)) {
#ifdef WIN32
wchar_t *dash = wcsrchr(open_file_name, L'\\');
#else
wchar_t *dash = wcsrchr(open_file_name, L'/');
#endif
wchar_t *dot = wcsrchr(open_file_name, L'.');
if(dash && dot) {
wchar_t deck_name[256];
wcsncpy(deck_name, dash + 1, dot - dash - 1);
deck_name[dot - dash - 1] = L'\0';
mainGame->ebDeckname->setText(deck_name);
mainGame->cbDBDecks->setSelected(-1);
} else {
for(size_t i = 0; i < mainGame->cbDBDecks->getItemCount(); ++i) {
if(!wcscmp(mainGame->cbDBDecks->getItem(i), open_file_name)) {
mainGame->cbDBDecks->setSelected(i);
break;
}
}
}
open_file = false;
} else if(mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadDeck(mainGame->cbDBDecks->getItem(mainGame->cbDBDecks->getSelected()));
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu);
mainGame->is_building = true;
mainGame->is_siding = false;
......
......@@ -139,6 +139,14 @@ void Replay::SaveReplay(const wchar_t* name) {
fclose(fp);
}
bool Replay::OpenReplay(const wchar_t* name) {
#ifdef WIN32
fp = _wfopen(name, L"rb");
#else
char name2[256];
BufferIO::EncodeUTF8(name, name2);
fp = fopen(name2, "rb");
#endif
if(!fp) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
#ifdef WIN32
......@@ -148,6 +156,7 @@ bool Replay::OpenReplay(const wchar_t* name) {
BufferIO::EncodeUTF8(fname, fname2);
fp = fopen(fname2, "rb");
#endif
}
if(!fp)
return false;
fseek(fp, 0, SEEK_END);
......
......@@ -185,6 +185,8 @@ int ReplayMode::ReplayThread(void* param) {
mainGame->ShowElement(mainGame->wReplay);
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock();
if(exit_on_return)
mainGame->device->closeDevice();
}
return 0;
}
......
......@@ -29,11 +29,17 @@ void SingleMode::SetResponse(unsigned char* resp) {
set_responseb(pduel, resp);
}
int SingleMode::SinglePlayThread(void* param) {
char fname2[256];
size_t slen;
if(open_file) {
slen = BufferIO::EncodeUTF8(open_file_name, fname2);
open_file = false;
} else {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(mainGame->lstSinglePlayList->getSelected());
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
char fname2[256];
size_t slen = BufferIO::EncodeUTF8(fname, fname2);
slen = BufferIO::EncodeUTF8(fname, fname2);
}
mtrandom rnd;
time_t seed = time(0);
rnd.reset(seed);
......@@ -103,6 +109,8 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock();
if(exit_on_return)
mainGame->device->closeDevice();
}
return 0;
}
......
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