bool FileUtils::ReadFileContent(const wxFileName& fn, wxString& data, const wxMBConv& conv) { wxString filename = fn.GetFullPath(); data.clear(); const char* cfile = filename.mb_str(wxConvUTF8).data(); FILE* fp = fopen(cfile, "rb"); if(!fp) { // Nothing to be done clERROR() << "Failed to open file:" << fn << "." << strerror(errno); return false; } // Get the file size fseek(fp, 0, SEEK_END); long fsize = ftell(fp); fseek(fp, 0, SEEK_SET); // Allocate buffer for the read char* buffer = (char*)malloc(fsize + 1); long bytes_read = fread(buffer, 1, fsize, fp); if(bytes_read != fsize) { // failed to read clERROR() << "Failed to read file content:" << fn << "." << strerror(errno); fclose(fp); free(buffer); return false; } buffer[fsize] = 0; // Close the handle fclose(fp); // Convert it into wxString data = wxString(buffer, conv, fsize); if(data.IsEmpty() && fsize != 0) { // Conversion failed data = wxString::From8BitData(buffer, fsize); } // Release the C-buffer allocated earlier free(buffer); return true; }
size_t FileUtils::GetFileSize(const wxFileName& filename) { struct stat b; wxString file_name = filename.GetFullPath(); const char* cfile = file_name.mb_str(wxConvUTF8).data(); if(::stat(cfile, &b) == 0) { return b.st_size; } else { clERROR() << "Failed to open file:" << file_name << "." << strerror(errno); return 0; } }
bool FileUtils::ReadBufferFromFile(const wxFileName& fn, wxString& data, size_t bufferSize) { if(!fn.FileExists()) { return false; } std::wifstream fin(fn.GetFullPath().c_str(), std::ios::binary); if(fin.bad()) { clERROR() << "Failed to open file:" << fn; return false; } std::vector<wchar_t> buffer(bufferSize, 0); if(!fin.eof()) { fin.read(buffer.data(), buffer.size()); } data.reserve(buffer.size()); data << std::wstring(buffer.begin(), buffer.begin() + buffer.size()); return true; }
bool LLDBConnector::LaunchLocalDebugServer() { #if !BUILD_CODELITE_LLDB // Not supported :( ::wxMessageBox(_("Locally debugging with LLDB on Windows is not supported by LLDB"), "CodeLite", wxICON_WARNING | wxOK | wxCENTER); return false; #endif clDEBUG() << "Launching codelite-lldb"; // Start the debugger if(m_process) { // another debugger process is already running return false; } // Apply the environment before we start // set the LLDB_DEBUGSERVER_PATH env variable wxStringMap_t om; om["LLDB_DEBUGSERVER_PATH"] = m_debugserver; EnvSetter es(NULL, &om); wxFileName fnCodeLiteLLDB(clStandardPaths::Get().GetBinaryFullPath("codelite-lldb")); wxString command; command << fnCodeLiteLLDB.GetFullPath() << " -s " << GetDebugServerPath(); clDEBUG() << "LLDB_DEBUGSERVER_PATH is set to" << m_debugserver; m_process = ::CreateAsyncProcess(this, command); if(!m_process) { clERROR() << "LLDBConnector: failed to launch codelite-lldb:" << fnCodeLiteLLDB.GetFullPath(); return false; } else { clDEBUG() << "codelite-lldb launched successfully. PID=" << m_process->GetPid(); } return true; }