void bmt::XML::SaveXML (void) { std::wstring documents_dir = BMT_GetDocumentsDir (); wchar_t wszXML [1024]; wsprintf (wszXML, L"%s\\WB Games\\Batman Arkham Knight\\GFXSettings.BatmanArkhamKnight.xml", documents_dir.c_str ()); wchar_t* wszOut = new wchar_t [8192]; wchar_t* wszEnd = print (wszOut, bmak_xml, 0); int last_brace = 0; // XML parser doesn't like the TM symbol, so get it the hell out of there! for (int i = 0; i < 8192; i++) { if (wszOut [i] == L'™') wszOut [i] = L' '; if (wszOut [i] == L'>') last_brace = i; } wszOut [last_brace + 1] = L'\0'; FILE* fXML; errno_t ret = _wfopen_s (&fXML, wszXML, L"w,ccs=UTF-16LE"); if (ret != 0 || fXML == 0) { delete [] wszOut; BMT_MessageBox (L"Could not open GFXSettings.BatmanArkhamKnight.xml for writing!\n", L"Unable to save XML settings", MB_OK | MB_ICONSTOP); return; } fputws (L"<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\n", fXML); fputws (wszOut, fXML); delete [] wszOut; fflush (fXML); fclose (fXML); // // Windows 10 File Permission Fixes // // Normalize file ownership and attributes (Win10 fix) BMT_SetNormalFileAttribs (wszXML); // Now normalize the directory as a whole wsprintf (wszXML, L"%s\\WB Games\\Batman Arkham Knight", documents_dir.c_str ()); BMT_SetNormalFileAttribs (wszXML); }
bmt::INI::File::File (wchar_t* filename) { // We skip a few bytes (Unicode BOM) in crertain cirumstances, so this is the // actual pointer we need to free... wchar_t* alloc; wszName = _wcsdup (filename); errno_t ret; TRY_FILE_IO (_wfopen_s (&fINI, filename, L"rb"), filename, ret); if (ret == 0 && fINI != 0) { fseek (fINI, 0, SEEK_END); long size = ftell (fINI); rewind (fINI); wszData = new wchar_t [size]; alloc = wszData; fread (wszData, size, 1, fINI); // This is essentially our Unicode BOM, if the first character is '[', then it's ANSI. if (((char *)wszData) [0] == '[') { char* string = new char [size + 1]; memcpy (string, wszData, size); string [size] = '\0'; delete [] wszData; wszData = new wchar_t [size + 1]; MultiByteToWideChar (CP_OEMCP, 0, string, -1, wszData, size + 1); alloc = wszData; } // Otherwise it's Unicode, let's fix up a couple of things else { if (*wszData != L'[') ++wszData; wszData [size / 2 - 1] = '\0'; } parse (); delete [] alloc; wszData = nullptr; fflush (fINI); fclose (fINI); } else { BMT_MessageBox (L"Unable to Locate INI File", filename, MB_OK); } }
bool bmt::XML::LoadXML (void) { wchar_t wszXML [1024]; std::wstring documents_dir = BMT_GetDocumentsDir (); // // Windows 10 File Permission Fixes // // Normalize the directory as a whole wsprintf (wszXML, L"%s\\WB Games\\Batman Arkham Knight", documents_dir.c_str ()); BMT_SetNormalFileAttribs (wszXML); wsprintf (wszXML, L"%s\\WB Games\\Batman Arkham Knight\\GFXSettings.BatmanArkhamKnight.xml", documents_dir.c_str ()); // Normalize file ownership and attributes (Win10 fix) BMT_SetNormalFileAttribs (wszXML); FILE* fXML; errno_t ret = _wfopen_s (&fXML, wszXML, L"r,ccs=UTF-16LE"); if (ret != 0) { BMT_MessageBox (L"Unable to locate GFXSettings.BatmanArkhamKnight.XML.\n\n " L"This file is created when the game starts, try running the " L"game once.\n", L"Missing XML File", MB_OK | MB_ICONERROR); return false; } fseek (fXML, 0, SEEK_END); DWORD dwLen = ftell (fXML); rewind (fXML); wchar_t* xml = new wchar_t [dwLen + 1]; fread (xml, 1, dwLen, fXML); int last_brace = 0; // XML parser doesn't like the TM symbol, so get it the hell out of there! for (unsigned int i = 0; i < dwLen; i++) { if (xml [i] == L'™') xml [i] = L' '; if (xml [i] == L'>') last_brace = i; } xml [last_brace + 1] = 0; bmak_xml.parse <0> (xml); fclose (fXML); bmak_root = bmak_xml.first_node (); if (bmak_root == NULL) { BMT_MessageBox (L"GFXSettings.BatmanArkhamKnight.xml appears to be corrupt, please delete it and re-load the game\n", L"Corrupt XML File", MB_OK | MB_ICONHAND); return false; } bmak_application = bmak_root->first_node (); bmak_gamesettings = FindNode (bmak_root, L"GAMESETTINGS"); xml_attribute <wchar_t>* install_path_attrib = FindAttrib (FindNode (bmak_application, L"INSTALLPATH"), L"Value"); if (install_path_attrib != NULL) { install_path = install_path_attrib->value (); } xml_attribute <wchar_t>* exec_cmd_attrib = FindAttrib (FindNode (bmak_application, L"EXECCMD"), L"Value"); if (exec_cmd_attrib != NULL && install_path_attrib != NULL) { executable = install_path_attrib->value () + std::wstring (exec_cmd_attrib->value ()) + std::wstring (L".exe"); } return true; }