/// Loads a CTR ELF file bool Load_ELF(std::string &filename) { std::string full_path = filename; std::string path, file, extension; SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); #if EMU_PLATFORM == PLATFORM_WINDOWS path = ReplaceAll(path, "/", "\\"); #endif File::IOFile f(filename, "rb"); if (f.IsOpen()) { u64 size = f.GetSize(); u8* buffer = new u8[size]; ElfReader* elf_reader = NULL; f.ReadBytes(buffer, size); elf_reader = new ElfReader(buffer); elf_reader->LoadInto(0x00100000); Kernel::LoadExec(elf_reader->GetEntryPoint()); delete[] buffer; delete elf_reader; } else { return false; } f.Close(); return true; }
bool Load_PSP_ELF_PBP(const char *filename, std::string *error_string) { // This is really just for headless, might need tweaking later. if (!PSP_CoreParameter().mountIso.empty()) { auto bd = constructBlockDevice(PSP_CoreParameter().mountIso.c_str()); if (bd != NULL) { ISOFileSystem *umd2 = new ISOFileSystem(&pspFileSystem, bd); pspFileSystem.Mount("umd1:", umd2); pspFileSystem.Mount("disc0:", umd2); pspFileSystem.Mount("umd:", umd2); } } std::string full_path = filename; std::string path, file, extension; SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); #ifdef _WIN32 path = ReplaceAll(path, "/", "\\"); #endif DirectoryFileSystem *fs = new DirectoryFileSystem(&pspFileSystem, path); pspFileSystem.Mount("umd0:", fs); std::string finalName = "umd0:/" + file + extension; return __KernelLoadExec(finalName.c_str(), 0, error_string); }
void RemoveFilenameIllegalCharacters(GString &S, bool removeSlash) { // size_t len = strlen(fn); ReplaceAll(S, "[<>:\\|?*]", ""); if (removeSlash) ReplaceAll(S, "/", ""); }
std::string EncodeJSONString(std::string &str) { ReplaceAll(str, "\n", "\\n"); ReplaceAll(str, "\r", "\\r"); ReplaceAll(str, "\"", "\\\""); return str; }
std::string ProxyData::AuthToString() { if(UserName.empty() || Password.empty()) return std::string(); return ReplaceAll(UserName,":","%3A") + ":" + ReplaceAll(Password,":","%3A"); }
void RemoveFilenameIllegalCharacters(std::string &S, bool removeSlash, bool noAbsolute) { // size_t len = strlen(fn); if (!noAbsolute) ReplaceAll(S, "[<>\\|?*]", ""); else ReplaceAll(S, "[<>\\|?*]", ""); if (removeSlash) ReplaceAll(S, "/", ""); }
xml_node<TCHAR>* CXmlConfig::FindChild(const TCHAR* path){ _tstring allPath=path; ReplaceAll(allPath,_T("/"),_T("\\")); while(allPath.find(_T("\\\\"))!=_tstring::npos){ ReplaceAll(allPath,_T("\\\\"),_T("\\")); } xml_node<TCHAR>* node = m_xmlRoot->search_node(path); return node; }
bool Load_PSP_ELF_PBP(const char *filename, std::string *error_string) { std::string full_path = filename; std::string path, file, extension; SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); #ifdef _WIN32 path = ReplaceAll(path, "/", "\\"); #endif DirectoryFileSystem *fs = new DirectoryFileSystem(&pspFileSystem, path); pspFileSystem.Mount("umd0:/", fs); std::string finalName = "umd0:/" + file + extension; return __KernelLoadExec(finalName.c_str(), 0, error_string); }
void CGameListCtrl::OnWiki(wxCommandEvent& WXUNUSED (event)) { const GameListItem *iso = GetSelectedISO(); if (!iso) return; std::string wikiUrl = "http://wiki.dolphin-emu.org/dolphin-redirect.php?gameid=[GAME_ID]"; wikiUrl = ReplaceAll(wikiUrl, "[GAME_ID]", UriEncode(iso->GetUniqueID())); if (UriEncode(iso->GetName(0)).length() < 100) wikiUrl = ReplaceAll(wikiUrl, "[GAME_NAME]", UriEncode(iso->GetName(0))); else wikiUrl = ReplaceAll(wikiUrl, "[GAME_NAME]", ""); WxUtils::Launch(wikiUrl.c_str()); }
LRESULT EditFind::FindReplaceCmd(WPARAM, LPARAM lParam) { FindReplaceDialog* dialog = FindReplaceDialog::GetNotifier(lParam); ASSERT(dialog == m_dialog); bool found = true; if (dialog->IsTerminating()) { m_lastFind = dialog->GetFindString(); m_searchDown = dialog->SearchDown(); m_matchCase = dialog->MatchCase(); m_matchWholeWord = dialog->MatchWholeWord(); m_dialog = NULL; } else if (dialog->FindNext()) { found = FindNext(true); if (!found) found = FindNext(false); } else if (dialog->ReplaceCurrent()) found = Replace(); else if (dialog->ReplaceAll()) found = ReplaceAll(); if (!found) ::MessageBeep(MB_ICONEXCLAMATION); return 0; }
void FindAndReplace::OnReplaceAll(LPFINDREPLACE& lpfr) { wyString findwhat; wyString replacewith; if(lpfr->lpstrFindWhat) findwhat.SetAs(lpfr->lpstrFindWhat); if(lpfr->lpstrReplaceWith) replacewith.SetAs(lpfr->lpstrReplaceWith); wyInt32 replacements = ReplaceAll(findwhat, replacewith, lpfr->Flags & FR_WHOLEWORD, lpfr->Flags & FR_MATCHCASE); if(replacements == -1) return; if(!replacements) { NotFoundMsg(lpfr->lpstrFindWhat); } else { wyString msg; msg.Sprintf(_("Replaced %d instance(s)."), replacements); ShowMessage(msg.GetAsWideChar(), MB_OK | MB_ICONINFORMATION); } return; }
std::string CreateTempDir() { #ifdef _WIN32 TCHAR temp[MAX_PATH]; if (!GetTempPath(MAX_PATH, temp)) return ""; GUID guid; CoCreateGuid(&guid); TCHAR tguid[40]; StringFromGUID2(guid, tguid, 39); tguid[39] = 0; std::string dir = TStrToUTF8(temp) + "/" + TStrToUTF8(tguid); if (!CreateDir(dir)) return ""; dir = ReplaceAll(dir, "\\", DIR_SEP); return dir; #else const char* base = getenv("TMPDIR") ?: "/tmp"; std::string path = std::string(base) + "/DolphinWii.XXXXXX"; if (!mkdtemp(&path[0])) return ""; return path; #endif }
std::string JavaScriptExtensions::GetUserAgentExtension(const std::string& UserAgent) { std::string rescode; if(!UserAgent.empty()) { rescode += std::string("Object.defineProperty(window.navigator, 'userAgent', {" " get: function() {" " return ") + picojson::value(UserAgent).serialize() + std::string(";" " }" "});"); rescode += std::string("Object.defineProperty(window.navigator, 'appVersion', {" " get: function() {" " return ") + picojson::value(ReplaceAll( UserAgent, "Mozilla/", "")).serialize() + std::string(";" " }" "});"); rescode += std::string("Object.defineProperty(window.navigator, 'vendor', {" " get: function() {" " return ") + picojson::value("").serialize() + std::string(";" " }" "});"); rescode += std::string("Object.defineProperty(window.navigator, 'platform', {" " get: function() {" " return ") + picojson::value("").serialize() + std::string(";" " }" "});"); } return rescode; }
BString& BString::ReplaceAllChars(const char* replaceThis, const char* withThis, int32 fromCharOffset) { return ReplaceAll(replaceThis, withThis, UTF8CountBytes(fPrivateData, fromCharOffset)); }
LRESULT CAgentCfg::WriteDevicesFile(std::string xmlFile, std::string destFolder) { std::string contents; contents+="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; contents+="<MTConnectDevices xmlns=\"urn:mtconnect.org:MTConnectDevices:1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:mtconnect.org:MTConnectDevices:1.1 http://www.mtconnect.org/schemas/MTConnectDevices_1.1.xsd\">\n"; contents+=StdStringFormat("<Header bufferSize=\"130000\" instanceId=\"1\" creationTime=\"%s\" sender=\"local\" version=\"1.1\"/>\n", GetTimeStamp().c_str()); contents+="<Devices>\n"; // Check all machine names unique // Generate Devices.xml file with all devices in it. for(UINT i=0; i<devices.size(); i++) { std::string config = ReadXmlDevicesFile(devices[i]); ReplaceAll(config,"####", names[i]); config=ReplaceOnce(config,"name=\"NNNNNN\"","name=\""+names[i]+"\""); contents+=config+"\n"; } contents+="</Devices>\n"; contents+="</MTConnectDevices>\n"; if(!xmlFile.empty()) WriteFile(destFolder + "\\" + xmlFile , contents); return 0; }
void SourceTASReader::ReplaceVariables() { for (auto& variable : variables.variableMap) { ReplaceAll(line, GetVarIdentifier(variable.first), variable.second.GetValue()); } }
int main(int argc, char * argv[]) { std::string response; if (argc == 1) { char response_buffer[1024]; std::cin.getline(response_buffer, 1024); response = std::string(response_buffer); } else { response = std::string(argv[1]); } response = ReplaceAll(response, "\\r\\n", "\r\n"); std::cout << "Parsing response:" <<std::endl; std::cout << response.c_str() << std::endl; ResponseParser respParser(response.c_str()); std::cout << "Status: " << respParser.getStatus() << std::endl; std::cout << "HTTP Version: " << respParser.getVersion() << std::endl; std::cout << "Headers:" << std::endl; uint8_t i = 0; for (i = 0; i < respParser.headerCount(); i++) { std::cout << i << "- " << respParser.getHeaderByIndex(i)->getName() << ": " << respParser.getHeaderByIndex(i)->getValue() << std::endl; } return 0; }
bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) { // This is really just for headless, might need tweaking later. if (PSP_CoreParameter().mountIsoLoader != nullptr) { auto bd = constructBlockDevice(PSP_CoreParameter().mountIsoLoader); if (bd != NULL) { ISOFileSystem *umd2 = new ISOFileSystem(&pspFileSystem, bd); pspFileSystem.Mount("umd1:", umd2); pspFileSystem.Mount("disc0:", umd2); pspFileSystem.Mount("umd:", umd2); } } std::string full_path = fileLoader->Path(); std::string path, file, extension; SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); #ifdef _WIN32 path = ReplaceAll(path, "/", "\\"); #endif if (!PSP_CoreParameter().mountRoot.empty()) { // We don't want to worry about .. and cwd and such. const std::string rootNorm = NormalizePath(PSP_CoreParameter().mountRoot + "/"); const std::string pathNorm = NormalizePath(path + "/"); // If root is not a subpath of path, we can't boot the game. if (!startsWith(pathNorm, rootNorm)) { *error_string = "Cannot boot ELF located outside mountRoot."; return false; } const std::string filepath = ReplaceAll(pathNorm.substr(rootNorm.size()), "\\", "/"); file = filepath + "/" + file; path = rootNorm + "/"; pspFileSystem.SetStartingDirectory(filepath); } DirectoryFileSystem *fs = new DirectoryFileSystem(&pspFileSystem, path); pspFileSystem.Mount("umd0:", fs); std::string finalName = "umd0:/" + file + extension; return __KernelLoadExec(finalName.c_str(), 0, error_string); }
void I18NCategory::SetMap(const std::map<std::string, std::string> &m) { for (auto iter = m.begin(); iter != m.end(); ++iter) { if (map_.find(iter->first) == map_.end()) { std::string text = ReplaceAll(iter->second, "\\n", "\n"); map_[iter->first] = I18NEntry(text); } } }
void main(void) { char source[]="Ligne de texte"; char *res; res=ReplaceAll(source,"e","ur","\0"); printf("%s\n%s\n",source,res); free(res); }
void main(void) { char source[]="abcadeafghaijkalmnaopa"; char *res; res=ReplaceAll(source,"z","-","\0"); printf("%s\n%s\n",source,res); free(res); }
/// Loads a Launcher DAT file bool Load_DAT(std::string &filename) { std::string full_path = filename; std::string path, file, extension; SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); #if EMU_PLATFORM == PLATFORM_WINDOWS path = ReplaceAll(path, "/", "\\"); #endif File::IOFile f(filename, "rb"); if (f.IsOpen()) { u64 size = f.GetSize(); u8* buffer = new u8[size]; f.ReadBytes(buffer, size); /** * (mattvail) We shouldn't really support this type of file * but for the sake of making it easier... we'll temporarily/hackishly * allow it. No sense in making a proper reader for this. */ u32 entry_point = 0x00100000; // write to same entrypoint as elf u32 payload_offset = 0xA150; const u8 *src = &buffer[payload_offset]; u8 *dst = Memory::GetPointer(entry_point); u32 srcSize = size - payload_offset; //just load everything... u32 *s = (u32*)src; u32 *d = (u32*)dst; for (int j = 0; j < (int)(srcSize + 3) / 4; j++) { *d++ = (*s++); } Kernel::LoadExec(entry_point); delete[] buffer; } else { return false; } f.Close(); return true; }
CheatFileParser(const std::string &filename, const std::string &gameID = "") { #if defined(_WIN32) && !defined(__MINGW32__) file_.open(ConvertUTF8ToWString(activeCheatFile)); #else file_.open(activeCheatFile.c_str()); #endif validGameID_ = ReplaceAll(gameID, "-", ""); }
string UnmungePluginDsoPath(const string& munged) { #if defined(OS_LINUX) return ReplaceAll(munged, "netsc@pe", "netscape"); #else return munged; #endif }
void VisionConductor::Load(string pathfile) { // $IT_DATA environmet variable, NULL if not set const char *it_data = getenv("IT_DATA"); string std_it_data; if (it_data!=NULL) { std_it_data = ConvertPathToStandard(it_data); } else { std_it_data = ""; } // substitute $IT_DATA environment variable, if requested string::size_type pos = pathfile.find("$IT_DATA"); if (pos!=string::npos) { if (it_data==NULL) { throw HVEFile(pathfile, "The filename requests the environment variable " "$IT_DATA to be set."); } // substitute "$IT_DATA" for the value of that environment variable ReplaceAll(pathfile, "$IT_DATA", std_it_data); } // all paths in the VisionConductor file "filename" are relative // to the path of "filename". so, let's cd to that directory, load // all cascades etc., and in the end restore the previous cwd. string old_cwd = GetCWD(); string vc_path, fname; SplitPathFile(pathfile, vc_path, fname); VERBOSE1(5, "HandVu: loading supplemental conductor files from path %s", vc_path.c_str()); if (old_cwd!=vc_path) { SetCWD(vc_path); } m_masks.clear(); m_orig_areas.clear(); try { // the actual parsing function ParseFromFile(fname); } catch (HVException& hve) { if (old_cwd!=vc_path) { SetCWD(old_cwd); } throw HVException(hve.GetMessage() + "\n" + "note: paths in VisionConductor files are relative;\n" "in this case to " + vc_path); } if (old_cwd!=vc_path) { SetCWD(old_cwd); } SanityCheckMasks(); m_is_loaded = true; }
void I18NRepo::SaveSection(IniFile &ini, IniFile::Section *section, I18NCategory *cat) { const std::map<std::string, std::string> &missed = cat->Missed(); for (auto iter = missed.begin(); iter != missed.end(); ++iter) { if (!section->Exists(iter->first.c_str())) { std::string text = ReplaceAll(iter->second, "\n", "\\n"); section->Set(iter->first, text); } } const std::map<std::string, I18NEntry> &entries = cat->GetMap(); for (auto iter = entries.begin(); iter != entries.end(); ++iter) { std::string text = ReplaceAll(iter->second.text, "\n", "\\n"); section->Set(iter->first, text); } cat->ClearMissed(); }
/// Loads an extracted CXI from a directory bool LoadDirectory_CXI(std::string &filename) { std::string full_path = filename; std::string path, file, extension; SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); #if EMU_PLATFORM == PLATFORM_WINDOWS path = ReplaceAll(path, "/", "\\"); #endif DirectoryFileSystem *fs = new DirectoryFileSystem(&System::g_ctr_file_system, path); System::g_ctr_file_system.Mount("fs:", fs); std::string final_name = "fs:/" + file + extension; File::IOFile f(filename, "rb"); if (f.IsOpen()) { // TODO(ShizZy): read here to memory.... } ERROR_LOG(TIME, "Unimplemented function!"); return true; }
string MungePluginDsoPath(const string& path) { #if defined(OS_LINUX) // https://bugzilla.mozilla.org/show_bug.cgi?id=519601 return ReplaceAll(path, "netscape", "netsc@pe"); #else return path; #endif }
std::string CCMSDIntegrator::GenerateSchema(std::string schema) { std::stringstream buffer; std::string table; buffer << "CREATE SCHEMA IF NOT EXISTS `" << schema << "` DEFAULT CHARACTER SET latin1;" << std::endl; buffer << "USE "<< schema << ";" << std::endl ; schema="`"+schema+"`"; buffer << std::endl << std::endl ; buffer << "DROP TABLE IF EXISTS " << schema << "." << "Properties" << ";" << std::endl; buffer << "CREATE TABLE IF NOT EXISTS " << schema << "." << "Properties" << "(" << std::endl; buffer << "identifier CHAR(255) NOT NULL,"; buffer << "name CHAR(255) NOT NULL DEFAULT '',"; buffer << "value NOT NULL DEFAULT '', "; buffer << "units CHAR(255) NULL DEFAULT '',"; buffer << "description NULL DEFAULT '',"; buffer << std::endl << "PRIMARY KEY (`identifier`)" << std::endl; buffer << ") ENGINE=InnoDB DEFAULT CHARSET=utf8;" << std::endl; std::vector<IObject::CreatorFcn> & creators = IObject::GetAllCreators(); for(int j=0; j< creators.size(); j++) { IObject::CreatorFcn fcn = creators[j]; //Part * apart = (Part*) new Part(); IObject * apart = fcn(); table=apart->GetClassname(); // "`Part`"; buffer << std::endl << std::endl; buffer << "-- -----------------------------------------------------" << std::endl; buffer << "-- Table " << schema << "." << table << std::endl; buffer << "-- -----------------------------------------------------" << std::endl; buffer << "DROP TABLE IF EXISTS "<< schema << "." << table << ";" << std::endl; buffer << "CREATE TABLE IF NOT EXISTS "<< schema << "." << table << "(" << std::endl; std::vector<std::string> fields = apart->GetHeaders(); for(int i=0; i< fields.size(); i++) { MetaType type = apart->GetType(i); std::string field = fields[i]; ReplaceAll(field,".", "_"); buffer << "`" << field << "` " << GetDDLType(type ) << " " ; buffer << (( fields[i]=="identifier")? "NOT NULL " : "NULL "); buffer << GetDDLDefault(type ); if((i+1)!=fields.size()) buffer << ", " << std::endl; } if(std::find(fields.begin(), fields.end(), "identifier")!=fields.end()) buffer << ", " << std::endl << "PRIMARY KEY (`identifier`)" << std::endl; buffer << ") ENGINE=InnoDB DEFAULT CHARSET=utf8;" << std::endl; } return buffer.str(); }
bool GameInfo::Delete() { switch (fileType) { case FILETYPE_PSP_ISO: case FILETYPE_PSP_ISO_NP: { // Just delete the one file (TODO: handle two-disk games as well somehow). const char *fileToRemove = filePath_.c_str(); File::Delete(fileToRemove); auto i = std::find(g_Config.recentIsos.begin(), g_Config.recentIsos.end(), fileToRemove); if (i != g_Config.recentIsos.end()) { g_Config.recentIsos.erase(i); } return true; } case FILETYPE_PSP_PBP_DIRECTORY: case FILETYPE_PSP_SAVEDATA_DIRECTORY: { // TODO: This could be handled by Core/Util/GameManager too somehow. const char *directoryToRemove = filePath_.c_str(); INFO_LOG(HLE, "Deleting %s", directoryToRemove); if (!File::DeleteDirRecursively(directoryToRemove)) { ERROR_LOG(HLE, "Failed to delete file"); return false; } g_Config.CleanRecent(); return true; } case FILETYPE_PSP_ELF: case FILETYPE_UNKNOWN_BIN: case FILETYPE_UNKNOWN_ELF: case FILETYPE_ARCHIVE_RAR: case FILETYPE_ARCHIVE_ZIP: case FILETYPE_ARCHIVE_7Z: { const std::string &fileToRemove = filePath_; File::Delete(fileToRemove); return true; } case FILETYPE_PPSSPP_SAVESTATE: { const std::string &ppstPath = filePath_; File::Delete(ppstPath); const std::string screenshotPath = ReplaceAll(filePath_, ".ppst", ".jpg"); if (File::Exists(screenshotPath)) { File::Delete(screenshotPath); } return true; } default: return false; } }