void deities(View* view, int lastInd = 0) { vector<View::ListElem> options; for (Deity* deity : Deity::getDeities()) options.push_back(deity->getName()); auto index = view->chooseFromList("Deities", options, lastInd); if (!index) return; deity(view, Deity::getDeities()[*index]); deities(view, *index); }
void Encyclopedia::present(View* view, int lastInd) { auto index = view->chooseFromList("Choose topic:", {"Advances", /*"Workshop",*/ "Deities", "Skills"}, lastInd); if (!index) return; switch (*index) { case 0: advances(view); break; // case 1: workshop(view); break; case 1: deities(view); break; case 2: skills(view); break; default: FAIL << "wfepok"; } present(view, *index); }
static T_Status Crawl_Data(bool use_cache, T_Glyph_Ptr email, T_Glyph_Ptr password, T_Filename output_folder, bool is_clear) { T_Status status; T_WWW internet = NULL; bool is_exists; T_Glyph_Ptr path_ptr; T_Filename folder; T_XML_Document doc_languages = NULL; T_XML_Document doc_wepprops = NULL; T_XML_Document doc_sources = NULL; C_Pool pool(10000000,10000000); C_DDI_Deities deities(&pool); C_DDI_Skills skills(&pool); C_DDI_Rituals rituals(&pool); C_DDI_Items items(&pool); C_DDI_Classes classes(&pool); C_DDI_Races races(&pool); C_DDI_Paragons paragons(&pool); C_DDI_Epics epics(&pool); C_DDI_Feats feats(&pool); C_DDI_Powers powers(&pool); C_DDI_Monsters monsters(&pool); C_DDI_Backgrounds backgrounds(&pool); vector<C_DDI_Common *> list; vector<C_DDI_Single_Common *> singles; /* Add all of our downloader classes to the list */ list.push_back(&deities); list.push_back(&skills); list.push_back(&rituals); list.push_back(&items); list.push_back(&classes); list.push_back(&races); list.push_back(¶gons); list.push_back(&epics); list.push_back(&feats); list.push_back(&powers); //Monsters aren't supported yet... #ifdef NOTYET list.push_back(&monsters); #endif list.push_back(&backgrounds); /* Find a temporary folder to use */ Get_Temporary_Folder(folder); path_ptr = folder + strlen(folder); /* Search for the folder and create it if it doesn't exist */ is_exists = FileSys_Does_Folder_Exist(folder); if (!is_exists) { status = FileSys_Create_Directory(folder); if (x_Trap_Opt(!x_Is_Success(status))) { Log_Message("Couldn't create temporary folder."); x_Status_Return(LWD_ERROR); } } /* If we're not using cached copies, log in to D&D insider (if we don't have a username and password, this just establishes the connection) */ if (!use_cache) { Log_Message("Connecting to server...\n", true); /* Open a connection to the server first */ status = WWW_HTTP_Open(&internet,LOGIN_URL,NULL,NULL,NULL); if (x_Trap_Opt(!x_Is_Success(status))) { Log_Message("Couldn't open connection to login server!\n", true); goto cleanup_exit; } status = Login(internet, email, password, true); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* If we're not using the cache, we want to make sure we have fresh copies of everything, so delete the files in our temporary folder */ if (!use_cache) { strcpy(path_ptr,"*.*"); FileSys_Delete_Files(folder); *path_ptr = '\0'; } /* Create XML documents for deities languages - the crawlers can add their own entries for these during processing */ status = Create_Document(&doc_languages, &l_language_root, "language", DTD_Get_Data()); if (!x_Is_Success(status)) goto cleanup_exit; status = Create_Document(&doc_wepprops, &l_wepprop_root, "weapon property", DTD_Get_Augmentation()); if (!x_Is_Success(status)) goto cleanup_exit; status = Create_Document(&doc_sources, &l_source_root, "source", DTD_Get_Augmentation()); if (!x_Is_Success(status)) goto cleanup_exit; /* First, download all the index pages if we need to */ if (!use_cache) { for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Download_Index(folder, internet); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Download(folder, internet); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } } /* Read them in */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Read_Index(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Read(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Now download the rest of the content all at once NOTE: As of March 2011, there's no further content for download unless you have a password. */ if (!use_cache && l_is_password) { for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Download_Content(folder, internet); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* It's possible that some downloads were screwed up due to the servers acting weirdly. If so, they were added to a failed list, so try them again */ Retry_Failed_Downloads(internet); } /* Read it in and process it */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Read_Content(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Process all our stuff */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Process(); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Process(); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Post-process all our stuff - this requires it to have been output first, and puts finishing touches on everything */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Post_Process(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Post_Process(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Output our languages to the temporary folder, so we can append extensions to them later */ status = Finish_Document(doc_languages, folder, LANGUAGE_FILENAME); if (!x_Is_Success(status)) goto cleanup_exit; /* Now append any fixup extensions that are needed to compensate for the data being terrible */ Append_Extensions(folder, output_folder); /* Load the old "powers" XML document and try and copy any wizard powers out of it */ //We don't need to do this any more, but keep the code around just in case... // Fixup_Wizard_Powers(output_folder); /* Sources and weapon properties don't need any extensions, so they can go directly into the output folder - plus they're augmentation files, which aren't messed with anyway */ status = Finish_Document(doc_sources, output_folder, SOURCE_FILENAME); if (!x_Is_Success(status)) goto cleanup_exit; status = Finish_Document(doc_wepprops, output_folder, WEPPROP_FILENAME); if (!x_Is_Success(status)) goto cleanup_exit; /* wrapup everything */ cleanup_exit: l_language_root = NULL; if (doc_languages != NULL) XML_Destroy_Document(doc_languages); l_wepprop_root = NULL; if (doc_wepprops != NULL) XML_Destroy_Document(doc_wepprops); l_source_root = NULL; if (doc_sources != NULL) XML_Destroy_Document(doc_sources); if (internet != NULL) WWW_Close_Server(internet); /* Delete everything in our folder if required */ if (is_clear) { strcpy(path_ptr,"*.*"); FileSys_Delete_Files(folder); *path_ptr = '\0'; } x_Status_Return(status); }