diff --git a/qrenderdoc/Code/CaptureContext.cpp b/qrenderdoc/Code/CaptureContext.cpp index 200a5b68e..a04f77691 100644 --- a/qrenderdoc/Code/CaptureContext.cpp +++ b/qrenderdoc/Code/CaptureContext.cpp @@ -1095,7 +1095,7 @@ void CaptureContext::RecompressCapture() { // for remote files we open a new short-lived handle on the temporary file tempCap = cap = RENDERDOC_OpenCaptureFile(); - cap->OpenFile(tempFilename.toUtf8().data(), "rdc", NULL); + cap->OpenFile(tempFilename, "rdc", NULL); } if(!cap) @@ -1127,7 +1127,7 @@ void CaptureContext::RecompressCapture() float progress = 0.0f; LambdaThread *th = new LambdaThread([cap, destFilename, &progress]() { - cap->Convert(destFilename.toUtf8().data(), "rdc", NULL, [&progress](float p) { progress = p; }); + cap->Convert(destFilename, "rdc", NULL, [&progress](float p) { progress = p; }); }); th->setName(lit("RecompressCapture")); th->start(); @@ -1155,7 +1155,7 @@ void CaptureContext::RecompressCapture() QFile::rename(destFilename, GetCaptureFilename()); // and re-open - cap->OpenFile(GetCaptureFilename().c_str(), "rdc", NULL); + cap->OpenFile(GetCaptureFilename(), "rdc", NULL); } else { @@ -1213,7 +1213,7 @@ bool CaptureContext::SaveCaptureTo(const rdcstr &captureFile) if(capFile) { // this will overwrite - success = capFile->CopyFileTo(captureFile.c_str()); + success = capFile->CopyFileTo(captureFile); } else { @@ -1341,7 +1341,7 @@ bool CaptureContext::ImportCapture(const CaptureFileFormat &fmt, const rdcstr &i ICaptureFile *file = RENDERDOC_OpenCaptureFile(); - status = file->OpenFile(importfile.c_str(), ext.toUtf8().data(), + status = file->OpenFile(importfile, ext.toUtf8().data(), [&progress](float p) { progress = p * 0.5f; }); if(status != ReplayStatus::Succeeded) @@ -1351,8 +1351,8 @@ bool CaptureContext::ImportCapture(const CaptureFileFormat &fmt, const rdcstr &i return; } - status = file->Convert(rdcfile.c_str(), "rdc", NULL, - [&progress](float p) { progress = 0.5f + p * 0.5f; }); + status = + file->Convert(rdcfile, "rdc", NULL, [&progress](float p) { progress = 0.5f + p * 0.5f; }); file->Shutdown(); }); th->setName(lit("ImportCapture")); @@ -1404,7 +1404,7 @@ void CaptureContext::ExportCapture(const CaptureFileFormat &fmt, const rdcstr &e if(!file) { local = file = RENDERDOC_OpenCaptureFile(); - status = file->OpenFile(m_CaptureFile.toUtf8().data(), "rdc", NULL); + status = file->OpenFile(m_CaptureFile, "rdc", NULL); } QString filename = QFileInfo(m_CaptureFile).fileName(); @@ -1428,8 +1428,7 @@ void CaptureContext::ExportCapture(const CaptureFileFormat &fmt, const rdcstr &e float progress = 0.0f; LambdaThread *th = new LambdaThread([file, sdfile, ext, exportfile, &progress, &status]() { - status = file->Convert(exportfile.c_str(), ext.toUtf8().data(), sdfile, - [&progress](float p) { progress = p; }); + status = file->Convert(exportfile, ext, sdfile, [&progress](float p) { progress = p; }); }); th->setName(lit("ExportCapture")); th->start(); @@ -2386,8 +2385,7 @@ void CaptureContext::ApplyShaderEdit(IShaderViewer *viewer, ResourceId id, Shade ResourceId from = id; ResourceId to; - rdctie(to, errs) = - r->BuildTargetShader(entryFunc.c_str(), shaderEncoding, shaderBytes, flags, stage); + rdctie(to, errs) = r->BuildTargetShader(entryFunc, shaderEncoding, shaderBytes, flags, stage); if(to == ResourceId()) { diff --git a/qrenderdoc/Code/Interface/RemoteHost.cpp b/qrenderdoc/Code/Interface/RemoteHost.cpp index c2cc1d8be..2ef72f0f7 100644 --- a/qrenderdoc/Code/Interface/RemoteHost.cpp +++ b/qrenderdoc/Code/Interface/RemoteHost.cpp @@ -125,13 +125,13 @@ void RemoteHost::CheckStatus() return; } - UpdateStatus(RENDERDOC_CheckRemoteServerConnection(m_hostname.c_str())); + UpdateStatus(RENDERDOC_CheckRemoteServerConnection(m_hostname)); } ReplayStatus RemoteHost::Connect(IRemoteServer **server) { QMutexLocker autolock(&m_data->mutex); - return RENDERDOC_CreateRemoteServerConnection(m_hostname.c_str(), server); + return RENDERDOC_CreateRemoteServerConnection(m_hostname, server); } void RemoteHost::SetConnected(bool connected) diff --git a/qrenderdoc/Code/ReplayManager.cpp b/qrenderdoc/Code/ReplayManager.cpp index 6042f78ef..008081d96 100644 --- a/qrenderdoc/Code/ReplayManager.cpp +++ b/qrenderdoc/Code/ReplayManager.cpp @@ -82,7 +82,7 @@ void ReplayManager::DeleteCapture(const rdcstr &capture, bool local) if(m_Remote) { QMutexLocker autolock(&m_RemoteLock); - m_Remote->TakeOwnershipCapture(capture.c_str()); + m_Remote->TakeOwnershipCapture(capture); } } } @@ -136,9 +136,7 @@ void ReplayManager::ListFolder(const rdcstr &path, bool synchronous, DirectoryBr if(IsRunning() && m_Thread->isCurrentThread()) { - auto lambda = [cb, path, this](IReplayController *r) { - cb(path, m_Remote->ListFolder(path.c_str())); - }; + auto lambda = [cb, path, this](IReplayController *r) { cb(path, m_Remote->ListFolder(path)); }; if(synchronous) BlockInvoke(lambda); @@ -152,7 +150,7 @@ void ReplayManager::ListFolder(const rdcstr &path, bool synchronous, DirectoryBr // prevent pings while fetching remote FS data { QMutexLocker autolock(&m_RemoteLock); - contents = m_Remote->ListFolder(path.c_str()); + contents = m_Remote->ListFolder(path); } cb(path, contents); @@ -172,8 +170,7 @@ rdcstr ReplayManager::CopyCaptureToRemote(const rdcstr &localpath, QWidget *wind auto lambda = [this, localpath, &remotepath, &progress, &copied](IReplayController *r) { QMutexLocker autolock(&m_RemoteLock); - remotepath = - m_Remote->CopyCaptureToRemote(localpath.c_str(), [&progress](float p) { progress = p; }); + remotepath = m_Remote->CopyCaptureToRemote(localpath, [&progress](float p) { progress = p; }); copied = 1; }; @@ -207,8 +204,7 @@ void ReplayManager::CopyCaptureFromRemote(const rdcstr &remotepath, const rdcstr auto lambda = [this, localpath, remotepath, &progress, &copied](IReplayController *r) { QMutexLocker autolock(&m_RemoteLock); - m_Remote->CopyCaptureFromRemote(remotepath.c_str(), localpath.c_str(), - [&progress](float p) { progress = p; }); + m_Remote->CopyCaptureFromRemote(remotepath, localpath, [&progress](float p) { progress = p; }); copied = 1; }; @@ -395,7 +391,7 @@ void ReplayManager::ReopenCaptureFile(const QString &path) { if(!m_CaptureFile) m_CaptureFile = RENDERDOC_OpenCaptureFile(); - m_CaptureFile->OpenFile(path.toUtf8().data(), "rdc", NULL); + m_CaptureFile->OpenFile(path, "rdc", NULL); } ExecuteResult ReplayManager::ExecuteAndInject(const rdcstr &exe, const rdcstr &workingDir, @@ -408,12 +404,11 @@ ExecuteResult ReplayManager::ExecuteAndInject(const rdcstr &exe, const rdcstr &w if(m_Remote) { QMutexLocker autolock(&m_RemoteLock); - ret = m_Remote->ExecuteAndInject(exe.c_str(), workingDir.c_str(), cmdLine.c_str(), env, opts); + ret = m_Remote->ExecuteAndInject(exe, workingDir, cmdLine, env, opts); } else { - ret = RENDERDOC_ExecuteAndInject(exe.c_str(), workingDir.c_str(), cmdLine.c_str(), env, - capturefile.c_str(), opts, false); + ret = RENDERDOC_ExecuteAndInject(exe, workingDir, cmdLine, env, capturefile, opts, false); } return ret; @@ -443,13 +438,13 @@ void ReplayManager::run(int proxyRenderer, const QString &capturefile, const Rep if(m_Remote) { rdctie(m_CreateStatus, m_Renderer) = - m_Remote->OpenCapture(proxyRenderer, capturefile.toUtf8().data(), opts, progress); + m_Remote->OpenCapture(proxyRenderer, capturefile, opts, progress); } else { m_CaptureFile = RENDERDOC_OpenCaptureFile(); - m_CreateStatus = m_CaptureFile->OpenFile(capturefile.toUtf8().data(), "rdc", NULL); + m_CreateStatus = m_CaptureFile->OpenFile(capturefile, "rdc", NULL); if(m_CreateStatus == ReplayStatus::Succeeded) rdctie(m_CreateStatus, m_Renderer) = m_CaptureFile->OpenCapture(opts, progress); diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index fafd6d02b..764b04419 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -1242,7 +1242,7 @@ PyObject *PythonContext::outstream_write(PyObject *self, PyObject *args) if(!message.empty()) RENDERDOC_LogMessage(redirector->isStdError ? LogType::Error : LogType::Comment, "EXTN", - filename.toUtf8().data(), line, message.c_str()); + filename, line, message); } } @@ -1342,7 +1342,7 @@ extern "C" void HandleException(PyObject *global_handle) linenum = PyFrame_GetLineNumber(frame); } - RENDERDOC_LogMessage(LogType::Error, "EXTN", filename.toUtf8().data(), linenum, exString.c_str()); + RENDERDOC_LogMessage(LogType::Error, "EXTN", filename, linenum, exString); } } diff --git a/qrenderdoc/Code/qrenderdoc.cpp b/qrenderdoc/Code/qrenderdoc.cpp index 4a21666a5..1eb345303 100644 --- a/qrenderdoc/Code/qrenderdoc.cpp +++ b/qrenderdoc/Code/qrenderdoc.cpp @@ -61,7 +61,7 @@ void sharedLogOutput(QtMsgType type, const QMessageLogContext &context, const QS case QtFatalMsg: logtype = LogType::Fatal; break; } - RENDERDOC_LogMessage(logtype, "QTRD", context.file, context.line, msg.toUtf8().data()); + RENDERDOC_LogMessage(logtype, "QTRD", context.file ? context.file : rdcstr(), context.line, msg); } static QString tr(const char *string) @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) if(errors) { - RENDERDOC_LogMessage(LogType::Error, "EXTN", __FILE__, __LINE__, errorLog.c_str()); + RENDERDOC_LogMessage(LogType::Error, "EXTN", __FILE__, __LINE__, errorLog); fputs("Found errors in python bindings. Please fix!\n", logOut); fputs(errorLog.c_str(), logOut); return 1; @@ -259,7 +259,7 @@ int main(int argc, char *argv[]) else { // no port specified, find the first open port. - ident = RENDERDOC_EnumerateRemoteTargets(host.toLocal8Bit().data(), ident); + ident = RENDERDOC_EnumerateRemoteTargets(host, ident); ok = (ident != 0); } diff --git a/qrenderdoc/Windows/ConstantBufferPreviewer.cpp b/qrenderdoc/Windows/ConstantBufferPreviewer.cpp index 7b06c269f..937cd6fb4 100644 --- a/qrenderdoc/Windows/ConstantBufferPreviewer.cpp +++ b/qrenderdoc/Windows/ConstantBufferPreviewer.cpp @@ -112,7 +112,7 @@ void ConstantBufferPreviewer::OnEventChanged(uint32_t eventId) m_pipe = m_stage == ShaderStage::Compute ? m_Ctx.CurPipelineState().GetComputePipelineObject() : m_Ctx.CurPipelineState().GetGraphicsPipelineObject(); m_shader = m_Ctx.CurPipelineState().GetShader(m_stage); - QString entryPoint = m_Ctx.CurPipelineState().GetShaderEntryPoint(m_stage); + rdcstr entryPoint = m_Ctx.CurPipelineState().GetShaderEntryPoint(m_stage); const ShaderReflection *reflection = m_Ctx.CurPipelineState().GetShaderReflection(m_stage); bool wasEmpty = ui->variables->topLevelItemCount() == 0; @@ -161,7 +161,7 @@ void ConstantBufferPreviewer::OnEventChanged(uint32_t eventId) m_Ctx.Replay().AsyncInvoke( [this, prevShader, entryPoint, offset, size, wasEmpty](IReplayController *r) { rdcarray vars = r->GetCBufferVariableContents( - m_pipe, m_shader, entryPoint.toUtf8().data(), m_slot, m_cbuffer, offset, size); + m_pipe, m_shader, entryPoint, m_slot, m_cbuffer, offset, size); GUIInvoke::call(this, [this, prevShader, vars, wasEmpty] { RDTreeViewExpansionState &prevShaderExpansionState = diff --git a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp index 4d2794b2f..90acc87f7 100644 --- a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp @@ -570,7 +570,7 @@ void CaptureDialog::CheckAndroidSetup(QString &filename) LambdaThread *scan = new LambdaThread([this, filename]() { rdcstr host = m_Ctx.Replay().CurrentRemote().Hostname(); - RENDERDOC_CheckAndroidPackage(host.c_str(), filename.toUtf8().data(), &m_AndroidFlags); + RENDERDOC_CheckAndroidPackage(host, filename, &m_AndroidFlags); const bool debuggable = bool(m_AndroidFlags & AndroidFlags::Debuggable); const bool hasroot = bool(m_AndroidFlags & AndroidFlags::RootAccess); @@ -636,8 +636,8 @@ Would you like RenderDoc to try patching your package? // call into APK pull, patch, install routine, then continue LambdaThread *patch = new LambdaThread([this, host, exe, &patchSucceeded, &progress]() { - AndroidFlags result = RENDERDOC_MakeDebuggablePackage(host.c_str(), exe.toUtf8().data(), - [&progress](float p) { progress = p; }); + AndroidFlags result = + RENDERDOC_MakeDebuggablePackage(host, exe, [&progress](float p) { progress = p; }); if(result & AndroidFlags::Debuggable) { @@ -893,8 +893,7 @@ void CaptureDialog::on_toggleGlobal_clicked() QString capturefile = m_Ctx.TempCaptureFilename(QFileInfo(exe).baseName()); - bool success = RENDERDOC_StartGlobalHook(exe.toUtf8().data(), capturefile.toUtf8().data(), - Settings().options); + bool success = RENDERDOC_StartGlobalHook(exe, capturefile, Settings().options); if(!success) { diff --git a/qrenderdoc/Windows/Dialogs/CrashDialog.cpp b/qrenderdoc/Windows/Dialogs/CrashDialog.cpp index 3699c0189..433a1aeb3 100644 --- a/qrenderdoc/Windows/Dialogs/CrashDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/CrashDialog.cpp @@ -79,7 +79,7 @@ CrashDialog::CrashDialog(PersistantConfig &cfg, QVariantMap crashReportJSON, QWi ICaptureFile *cap = RENDERDOC_OpenCaptureFile(); - ReplayStatus status = cap->OpenFile(capInfo.absoluteFilePath().toUtf8().data(), "", NULL); + ReplayStatus status = cap->OpenFile(capInfo.absoluteFilePath(), "", NULL); if(status == ReplayStatus::Succeeded) { diff --git a/qrenderdoc/Windows/Dialogs/LiveCapture.cpp b/qrenderdoc/Windows/Dialogs/LiveCapture.cpp index 4070f2fbe..807910f04 100644 --- a/qrenderdoc/Windows/Dialogs/LiveCapture.cpp +++ b/qrenderdoc/Windows/Dialogs/LiveCapture.cpp @@ -1159,8 +1159,8 @@ void LiveCapture::selfClose() void LiveCapture::connectionThreadEntry() { - ITargetControl *conn = RENDERDOC_CreateTargetControl(m_Hostname.toUtf8().data(), m_RemoteIdent, - GetSystemUsername().toUtf8().data(), true); + ITargetControl *conn = + RENDERDOC_CreateTargetControl(m_Hostname, m_RemoteIdent, GetSystemUsername(), true); m_Connected.release(); if(!conn || !conn->Connected()) @@ -1181,7 +1181,7 @@ void LiveCapture::connectionThreadEntry() } uint32_t pid = conn->GetPID(); - QString target = QString::fromUtf8(conn->GetTarget()); + QString target = conn->GetTarget(); GUIInvoke::call(this, [this, pid, target]() { if(!m_Connected.available()) @@ -1214,7 +1214,7 @@ void LiveCapture::connectionThreadEntry() if(m_CopyCapture.tryAcquire()) { - conn->CopyCapture(m_CopyCaptureID, m_CopyCaptureLocalPath.toUtf8().data()); + conn->CopyCapture(m_CopyCaptureID, m_CopyCaptureLocalPath); m_CopyCaptureLocalPath = QString(); m_CopyCaptureID = ~0U; } @@ -1305,7 +1305,7 @@ void LiveCapture::connectionThreadEntry() NewCaptureData cap = msg.newCapture; if(cap.api.isEmpty()) cap.api = conn->GetAPI(); - QString name = QString::fromUtf8(conn->GetTarget()); + QString name = conn->GetTarget(); GUIInvoke::call(this, [this, name, cap]() { captureAdded(name, cap); }); } diff --git a/qrenderdoc/Windows/Dialogs/RemoteManager.cpp b/qrenderdoc/Windows/Dialogs/RemoteManager.cpp index 7e6e3631b..da46c8d93 100644 --- a/qrenderdoc/Windows/Dialogs/RemoteManager.cpp +++ b/qrenderdoc/Windows/Dialogs/RemoteManager.cpp @@ -233,19 +233,19 @@ void RemoteManager::refreshHost(RDTreeWidgetItem *node) // just a sanity check to make sure we don't hit some unexpected case and infinite loop uint32_t prevIdent = nextIdent; - nextIdent = RENDERDOC_EnumerateRemoteTargets(host.Hostname().c_str(), nextIdent); + nextIdent = RENDERDOC_EnumerateRemoteTargets(host.Hostname(), nextIdent); if(nextIdent == 0 || prevIdent >= nextIdent) break; ITargetControl *conn = - RENDERDOC_CreateTargetControl(host.Hostname().c_str(), nextIdent, username.data(), false); + RENDERDOC_CreateTargetControl(host.Hostname(), nextIdent, username.data(), false); if(conn) { - QString target = QString::fromUtf8(conn->GetTarget()); - QString api = QString::fromUtf8(conn->GetAPI()); - QString busy = QString::fromUtf8(conn->GetBusyClient()); + QString target = conn->GetTarget(); + QString api = conn->GetAPI(); + QString busy = conn->GetBusyClient(); QString running; diff --git a/qrenderdoc/Windows/Dialogs/UpdateDialog.cpp b/qrenderdoc/Windows/Dialogs/UpdateDialog.cpp index 376f8fc89..8793fa882 100644 --- a/qrenderdoc/Windows/Dialogs/UpdateDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/UpdateDialog.cpp @@ -150,12 +150,7 @@ void UpdateDialog::on_update_clicked() if(!runningPrograms.isEmpty()) runningPrograms += lit("\n"); - QString target = - conn->GetTarget() ? QString::fromUtf8(conn->GetTarget()) : lit(""); - if(conn->GetAPI()) - runningPrograms += tr("%1 running %2").arg(target).arg(QString::fromUtf8(conn->GetAPI())); - else - runningPrograms += target; + runningPrograms += tr("%1 running %2").arg(conn->GetTarget()).arg(conn->GetAPI()); conn->Shutdown(); } diff --git a/qrenderdoc/Windows/MainWindow.cpp b/qrenderdoc/Windows/MainWindow.cpp index 7ea65e43b..2d763d205 100644 --- a/qrenderdoc/Windows/MainWindow.cpp +++ b/qrenderdoc/Windows/MainWindow.cpp @@ -715,8 +715,7 @@ void MainWindow::OnInjectTrigger(uint32_t PID, const rdcarrayOpenFile(filename.toUtf8().data(), "rdc", NULL); + ReplayStatus status = file->OpenFile(filename, "rdc", NULL); if(status != ReplayStatus::Succeeded) { @@ -798,7 +797,7 @@ void MainWindow::LoadCapture(const QString &filename, const ReplayOptions &opts, } driver = file->DriverName(); - machineIdent = QString::fromUtf8(file->RecordedMachineIdent()); + machineIdent = file->RecordedMachineIdent(); support = file->LocalReplaySupport(); file->Shutdown(); @@ -3133,6 +3132,6 @@ bool MainWindow::isUnshareableDeviceInUse() if(m_Ctx.Replay().CurrentRemote().Protocol()->SupportsMultiplePrograms(host)) return false; - uint32_t ident = RENDERDOC_EnumerateRemoteTargets(host.c_str(), 0); + uint32_t ident = RENDERDOC_EnumerateRemoteTargets(host, 0); return ident != 0; } diff --git a/qrenderdoc/Windows/ShaderViewer.cpp b/qrenderdoc/Windows/ShaderViewer.cpp index 3b13e05ea..536675750 100644 --- a/qrenderdoc/Windows/ShaderViewer.cpp +++ b/qrenderdoc/Windows/ShaderViewer.cpp @@ -1517,7 +1517,6 @@ void ShaderViewer::disassemble_typeChanged(int index) return; QString targetStr = m_DisassemblyType->currentText(); - QByteArray target = targetStr.toUtf8(); for(const ShaderProcessingTool &disasm : m_Ctx.Config().ShaderProcessors) { @@ -1562,11 +1561,11 @@ void ShaderViewer::disassemble_typeChanged(int index) QPointer me(this); - m_Ctx.Replay().AsyncInvoke([me, this, target](IReplayController *r) { + m_Ctx.Replay().AsyncInvoke([me, this, targetStr](IReplayController *r) { if(!me) return; - rdcstr disasm = r->DisassembleShader(m_Pipeline, m_ShaderDetails, target.data()); + rdcstr disasm = r->DisassembleShader(m_Pipeline, m_ShaderDetails, targetStr); if(!me) return; diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index 5eaf83e57..c293ae0bf 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -3925,9 +3925,8 @@ void TextureViewer::on_saveTex_clicked() bool ret = false; QString fn = saveDialog.filename(); - m_Ctx.Replay().BlockInvoke([this, &ret, fn](IReplayController *r) { - ret = r->SaveTexture(m_SaveConfig, fn.toUtf8().data()); - }); + m_Ctx.Replay().BlockInvoke( + [this, &ret, fn](IReplayController *r) { ret = r->SaveTexture(m_SaveConfig, fn); }); if(!ret) { diff --git a/qrenderdoc/qrenderdoc_local.vcxproj b/qrenderdoc/qrenderdoc_local.vcxproj index fd3e98cb2..ee918988d 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj +++ b/qrenderdoc/qrenderdoc_local.vcxproj @@ -115,7 +115,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/3rdparty/catch/catch.cpp b/renderdoc/3rdparty/catch/catch.cpp index ba71454a7..0a5d36e23 100644 --- a/renderdoc/3rdparty/catch/catch.cpp +++ b/renderdoc/3rdparty/catch/catch.cpp @@ -143,33 +143,35 @@ struct AppVeyorListener : Catch::TestEventListenerBase // it should at least by identified as an issue. virtual void testRunEnded(Catch::TestRunStats const &testRunStats) override { - const char *url = Process::GetEnvVariable("APPVEYOR_API_URL"); + rdcstr url = Process::GetEnvVariable("APPVEYOR_API_URL"); - if(url) + if(!url.empty()) { - if(strncmp(url, "http://", 7)) + if(!url.beginsWith("http://")) return; - url += 7; + const char *urlc = url.c_str(); - const char *sep = strchr(url, ':'); + urlc += 7; + + const char *sep = strchr(urlc, ':'); if(!sep) return; - rdcstr hostname = rdcstr(url, sep - url); + rdcstr hostname = rdcstr(urlc, sep - urlc); - url = sep + 1; + urlc = sep + 1; uint16_t port = 0; - while(*url >= '0' && *url <= '9') + while(*urlc >= '0' && *urlc <= '9') { port *= 10; - port += int((*url) - '0'); - url++; + port += int((*urlc) - '0'); + urlc++; } - Network::Socket *sock = Network::CreateClientSocket(hostname.c_str(), port, 10); + Network::Socket *sock = Network::CreateClientSocket(hostname, port, 10); if(sock) { diff --git a/renderdoc/3rdparty/superluminal/superluminal.cpp b/renderdoc/3rdparty/superluminal/superluminal.cpp index 54027dc35..f513a3a63 100644 --- a/renderdoc/3rdparty/superluminal/superluminal.cpp +++ b/renderdoc/3rdparty/superluminal/superluminal.cpp @@ -74,7 +74,7 @@ void Init() path += "PerformanceAPI.dll"; - module = Process::LoadModule(path.c_str()); + module = Process::LoadModule(path); } } diff --git a/renderdoc/android/android.cpp b/renderdoc/android/android.cpp index d73497165..b078c2221 100644 --- a/renderdoc/android/android.cpp +++ b/renderdoc/android/android.cpp @@ -381,7 +381,7 @@ ReplayStatus InstallRenderDocServer(const rdcstr &deviceID) rdcstr apkpath = paths[i] + apk + ".apk"; - if(FileIO::exists(apkpath.c_str())) + if(FileIO::exists(apkpath)) { apksFolder = paths[i]; RDCLOG("APKs found: %s", apksFolder.c_str()); @@ -408,7 +408,7 @@ ReplayStatus InstallRenderDocServer(const rdcstr &deviceID) apk += GetRenderDocPackageForABI(abi) + ".apk"; - if(!FileIO::exists(apk.c_str())) + if(!FileIO::exists(apk)) RDCWARN( "%s missing - ensure you build all ABIs your device can support for full compatibility", apk.c_str()); @@ -553,7 +553,7 @@ struct AndroidRemoteServer : public RemoteServer } virtual rdcpair OpenCapture( - uint32_t proxyid, const char *filename, const ReplayOptions &opts, + uint32_t proxyid, const rdcstr &filename, const ReplayOptions &opts, RENDERDOC_ProgressCallback progress) override { ResetAndroidSettings(); @@ -575,9 +575,9 @@ struct AndroidRemoteServer : public RemoteServer } virtual rdcstr GetHomeFolder() override { return ""; } - virtual rdcarray ListFolder(const char *path) override + virtual rdcarray ListFolder(const rdcstr &path) override { - if(path[0] == 0 || (path[0] == '/' && path[1] == 0)) + if(path.empty() || (path[0] == '/' && path.size() == 1)) { SCOPED_TIMER("Fetching android packages and activities"); @@ -761,7 +761,8 @@ struct AndroidRemoteServer : public RemoteServer } } - virtual ExecuteResult ExecuteAndInject(const char *a, const char *w, const char *c, + virtual ExecuteResult ExecuteAndInject(const rdcstr &packageAndActivity, const rdcstr &, + const rdcstr &intentArgs, const rdcarray &env, const CaptureOptions &opts) override; @@ -1114,15 +1115,13 @@ void AndroidRemoteServer::ShutdownConnection() RemoteServer::ShutdownConnection(); } -ExecuteResult AndroidRemoteServer::ExecuteAndInject(const char *a, const char *w, const char *c, +ExecuteResult AndroidRemoteServer::ExecuteAndInject(const rdcstr &packageAndActivity, + const rdcstr &, const rdcstr &intentArgs, const rdcarray &env, const CaptureOptions &opts) { LazilyStartLogcatThread(); - rdcstr packageAndActivity = a && a[0] ? a : ""; - rdcstr intentArgs = c && c[0] ? c : ""; - // we spin up a thread to Ping() every second, since starting a package can block for a long time. int32_t done = 0; Threading::ThreadHandle pingThread = Threading::CreateThread([&done, this]() { @@ -1379,7 +1378,7 @@ ExecuteResult AndroidRemoteServer::ExecuteAndInject(const char *a, const char *w { // Check if the target app has started yet and we can connect to it. ITargetControl *control = RENDERDOC_CreateTargetControl( - (AndroidController::m_Inst.GetProtocolName() + "://" + m_deviceID).c_str(), ret.ident, + AndroidController::m_Inst.GetProtocolName() + "://" + m_deviceID, ret.ident, "testConnection", false); if(control) { diff --git a/renderdoc/android/android_patch.cpp b/renderdoc/android/android_patch.cpp index 5bb881a8c..0147615db 100644 --- a/renderdoc/android/android_patch.cpp +++ b/renderdoc/android/android_patch.cpp @@ -179,7 +179,7 @@ bool RealignAPK(const rdcstr &apk, rdcstr &alignedAPK, const rdcstr &tmpDir) uint32_t timeout = 10000; // 10 seconds while(elapsed < timeout) { - if(FileIO::exists(alignedAPK.c_str())) + if(FileIO::exists(alignedAPK)) { RDCLOG("Aligned APK ready to go, continuing..."); return true; @@ -198,13 +198,13 @@ rdcstr GetAndroidDebugKey() rdcstr keystore = getToolPath(ToolDir::None, keystoreName, false); // if we found the keystore, use that. - if(FileIO::exists(keystore.c_str())) + if(FileIO::exists(keystore)) return keystore; // otherwise, generate a temporary one rdcstr key = FileIO::GetTempFolderFilename() + keystoreName; - FileIO::Delete(key.c_str()); + FileIO::Delete(key); // locate keytool and use it to generate a keystore rdcstr create; @@ -225,7 +225,7 @@ rdcstr GetAndroidDebugKey() Process::ProcessResult verifyResult; // if the keystore was created, check that the key we expect to be in it is there - if(FileIO::exists(key.c_str())) + if(FileIO::exists(key)) { rdcstr verify; verify += " -list"; @@ -418,7 +418,7 @@ bool PullAPK(const rdcstr &deviceID, const rdcstr &pkgPath, const rdcstr &apk) uint32_t timeout = 10000; // 10 seconds while(elapsed < timeout) { - if(FileIO::exists(apk.c_str())) + if(FileIO::exists(apk)) { RDCLOG("Original APK ready to go, continuing..."); return true; @@ -496,8 +496,8 @@ bool IsDebuggable(const rdcstr &deviceID, const rdcstr &packageName) } }; -extern "C" RENDERDOC_API void RENDERDOC_CC -RENDERDOC_CheckAndroidPackage(const char *URL, const char *packageAndActivity, AndroidFlags *flags) +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_CheckAndroidPackage( + const rdcstr &URL, const rdcstr &packageAndActivity, AndroidFlags *flags) { IDeviceProtocolHandler *adb = RenderDoc::Inst().GetDeviceProtocol("adb"); @@ -512,7 +512,7 @@ RENDERDOC_CheckAndroidPackage(const char *URL, const char *packageAndActivity, A } else { - RDCLOG("%s is not debuggable", packageAndActivity); + RDCLOG("%s is not debuggable", packageAndActivity.c_str()); } if(Android::HasRootAccess(deviceID)) @@ -525,7 +525,7 @@ RENDERDOC_CheckAndroidPackage(const char *URL, const char *packageAndActivity, A } extern "C" RENDERDOC_API AndroidFlags RENDERDOC_CC RENDERDOC_MakeDebuggablePackage( - const char *URL, const char *packageAndActivity, RENDERDOC_ProgressCallback progress) + const rdcstr &URL, const rdcstr &packageAndActivity, RENDERDOC_ProgressCallback progress) { rdcstr package = Android::GetPackageName(packageAndActivity); diff --git a/renderdoc/android/android_tools.cpp b/renderdoc/android/android_tools.cpp index 2e2a0e133..9c884f760 100644 --- a/renderdoc/android/android_tools.cpp +++ b/renderdoc/android/android_tools.cpp @@ -43,7 +43,7 @@ bool toolExists(const rdcstr &path) { if(path.empty()) return false; - return FileIO::exists(path.c_str()) || FileIO::exists((path + ".exe").c_str()); + return FileIO::exists(path) || FileIO::exists(path + ".exe"); } rdcstr getToolInSDK(ToolDir subdir, const rdcstr &jdkroot, const rdcstr &sdkroot, const rdcstr &toolname) @@ -90,7 +90,7 @@ rdcstr getToolInSDK(ToolDir subdir, const rdcstr &jdkroot, const rdcstr &sdkroot toolpath = sdkroot + "/build-tools/"; rdcarray paths; - FileIO::GetFilesInDirectory(toolpath.c_str(), paths); + FileIO::GetFilesInDirectory(toolpath, paths); if(paths.empty()) break; @@ -235,44 +235,37 @@ rdcstr getToolPath(ToolDir subdir, const rdcstr &toolname, bool checkExist) } // now try to find it based on heuristics/environment variables - const char *env = Process::GetEnvVariable("JAVA_HOME"); + jdk = Process::GetEnvVariable("JAVA_HOME"); + sdk = Process::GetEnvVariable("ANDROID_HOME"); - jdk = env ? env : ""; - - env = Process::GetEnvVariable("ANDROID_HOME"); - sdk = env ? env : ""; - - if(sdk.empty() || !FileIO::exists(sdk.c_str())) + if(sdk.empty() || !FileIO::exists(sdk)) { - env = Process::GetEnvVariable("ANDROID_SDK_ROOT"); - sdk = env ? env : ""; + sdk = Process::GetEnvVariable("ANDROID_SDK_ROOT"); } - if(sdk.empty() || !FileIO::exists(sdk.c_str())) + if(sdk.empty() || !FileIO::exists(sdk)) { - env = Process::GetEnvVariable("ANDROID_SDK"); - sdk = env ? env : ""; + sdk = Process::GetEnvVariable("ANDROID_SDK"); } - if(sdk.empty() || !FileIO::exists(sdk.c_str())) + if(sdk.empty() || !FileIO::exists(sdk)) { - env = Process::GetEnvVariable("ANDROID_SDK_HOME"); - sdk = env ? env : ""; + sdk = Process::GetEnvVariable("ANDROID_SDK_HOME"); } #if ENABLED(RDOC_APPLE) // on macOS it's common not to have the environment variable globally available, so try the home // Library folder first, then the global folder - if(sdk.empty() || !FileIO::exists(sdk.c_str())) + if(sdk.empty() || !FileIO::exists(sdk)) { rdcstr librarySDK = FileIO::GetHomeFolderFilename() + "/Library/Android/sdk"; - sdk = FileIO::exists(librarySDK.c_str()) ? librarySDK : ""; + sdk = FileIO::exists(librarySDK) ? librarySDK : ""; } - if(sdk.empty() || !FileIO::exists(sdk.c_str())) + if(sdk.empty() || !FileIO::exists(sdk)) { rdcstr librarySDK = "/Library/Android/sdk"; - sdk = FileIO::exists(librarySDK.c_str()) ? librarySDK : ""; + sdk = FileIO::exists(librarySDK) ? librarySDK : ""; } #endif @@ -318,7 +311,7 @@ Process::ProcessResult execScript(const rdcstr &script, const rdcstr &args, cons RDCLOG("SCRIPT: %s", script.c_str()); Process::ProcessResult result; - Process::LaunchScript(script.c_str(), workDir.c_str(), args.c_str(), true, &result); + Process::LaunchScript(script, workDir, args, true, &result); return result; } Process::ProcessResult execCommand(const rdcstr &exe, const rdcstr &args, const rdcstr &workDir, @@ -328,7 +321,7 @@ Process::ProcessResult execCommand(const rdcstr &exe, const rdcstr &args, const RDCLOG("COMMAND: %s '%s'", exe.c_str(), args.c_str()); Process::ProcessResult result; - Process::LaunchProcess(exe.c_str(), workDir.c_str(), args.c_str(), true, &result); + Process::LaunchProcess(exe, workDir, args, true, &result); return result; } Process::ProcessResult adbExecCommand(const rdcstr &device, const rdcstr &args, @@ -353,16 +346,16 @@ void initAdb() RDCLOG("Initialising adb using '%s'", adb.c_str()); - if(adb.empty() || (!FileIO::exists(adb.c_str()) && !FileIO::exists((adb + ".exe").c_str()))) + if(adb.empty() || (!FileIO::exists(adb) && !FileIO::exists(adb + ".exe"))) { - if(FileIO::FindFileInPath(adb.c_str()) == "") + if(FileIO::FindFileInPath(adb) == "") RDCWARN( "Couldn't locate adb. Ensure adb is in PATH, ANDROID_SDK or ANDROID_HOME is set, or you " "configure your SDK location"); } Process::ProcessResult res = {}; - Process::LaunchProcess(adb.c_str(), workdir.c_str(), "start-server", true, &res); + Process::LaunchProcess(adb, workdir, "start-server", true, &res); if(res.strStdout.find("daemon") >= 0 || res.strStderror.find("daemon") >= 0) { diff --git a/renderdoc/api/replay/control_types.h b/renderdoc/api/replay/control_types.h index 92c8caeea..75cdece46 100644 --- a/renderdoc/api/replay/control_types.h +++ b/renderdoc/api/replay/control_types.h @@ -585,7 +585,7 @@ struct EnvironmentModification DOCUMENT(""); EnvironmentModification() : mod(EnvMod::Set), sep(EnvSep::NoSep), name(""), value("") {} EnvironmentModification(const EnvironmentModification &) = default; - EnvironmentModification(EnvMod m, EnvSep s, const char *n, const char *v) + EnvironmentModification(EnvMod m, EnvSep s, const rdcstr &n, const rdcstr &v) : mod(m), sep(s), name(n), value(v) { } diff --git a/renderdoc/api/replay/data_types.h b/renderdoc/api/replay/data_types.h index 4eef92f8b..d34092995 100644 --- a/renderdoc/api/replay/data_types.h +++ b/renderdoc/api/replay/data_types.h @@ -79,7 +79,7 @@ struct PathEntry DOCUMENT(""); PathEntry() : flags(PathProperty::NoFlags), lastmod(0), size(0) {} PathEntry(const PathEntry &) = default; - PathEntry(const char *fn, PathProperty f) : filename(fn), flags(f), lastmod(0), size(0) {} + PathEntry(const rdcstr &fn, PathProperty f) : filename(fn), flags(f), lastmod(0), size(0) {} PathEntry &operator=(const PathEntry &) = default; bool operator==(const PathEntry &o) const { @@ -525,7 +525,7 @@ typically it is one parent to many derived. inline void SetCustomName(const rdcstr &givenName) { autogeneratedName = false; - name = givenName.isEmpty() ? "" : givenName; + name = givenName.isEmpty() ? ""_lit : givenName; } }; diff --git a/renderdoc/api/replay/renderdoc_replay.h b/renderdoc/api/replay/renderdoc_replay.h index 4d8123e84..5cc7973d1 100644 --- a/renderdoc/api/replay/renderdoc_replay.h +++ b/renderdoc/api/replay/renderdoc_replay.h @@ -538,7 +538,7 @@ or hardware-specific ISA formats. :rtype: ``str`` )"); virtual rdcstr DisassembleShader(ResourceId pipeline, const ShaderReflection *refl, - const char *target) = 0; + const rdcstr &target) = 0; DOCUMENT(R"(Builds a shader suitable for running on the local replay instance as a custom shader. @@ -553,7 +553,7 @@ See :data:`TextureDisplay.customShaderId`. :meth:`ResourceId.Null` otherwise, and a ``str`` with any warnings/errors from compilation. :rtype: ``tuple`` of :class:`ResourceId` and ``str``. )"); - virtual rdcpair BuildCustomShader(const char *entry, + virtual rdcpair BuildCustomShader(const rdcstr &entry, ShaderEncoding sourceEncoding, bytebuf source, const ShaderCompileFlags &compileFlags, ShaderStage type) = 0; @@ -577,7 +577,7 @@ See :meth:`BuildCustomShader`. :meth:`ResourceId.Null` otherwise, and a ``str`` with any warnings/errors from compilation. :rtype: ``tuple`` of :class:`ResourceId` and ``str``. )"); - virtual rdcpair BuildTargetShader(const char *entry, + virtual rdcpair BuildTargetShader(const rdcstr &entry, ShaderEncoding sourceEncoding, bytebuf source, const ShaderCompileFlags &flags, ShaderStage type) = 0; @@ -920,7 +920,7 @@ otherwise. :rtype: ``list`` of :class:`ShaderVariable` )"); virtual rdcarray GetCBufferVariableContents(ResourceId pipeline, ResourceId shader, - const char *entryPoint, + const rdcstr &entryPoint, uint32_t cbufslot, ResourceId buffer, uint64_t offset, uint64_t length) = 0; @@ -932,7 +932,7 @@ texture to something compatible with the target file format. :return: ``True`` if the texture was saved successfully, ``False`` otherwise. :rtype: ``bool`` )"); - virtual bool SaveTexture(const TextureSave &saveData, const char *path) = 0; + virtual bool SaveTexture(const TextureSave &saveData, const rdcstr &path) = 0; DOCUMENT(R"(Retrieve the generated data from one of the geometry processing shader stages. @@ -992,14 +992,14 @@ struct ITargetControl :return: The target name. :rtype: ``str`` )"); - virtual const char *GetTarget() = 0; + virtual rdcstr GetTarget() = 0; DOCUMENT(R"(Retrieves the API currently in use by the target. :return: The API name, or empty if no API is initialised yet. :rtype: ``str`` )"); - virtual const char *GetAPI() = 0; + virtual rdcstr GetAPI() = 0; DOCUMENT(R"(Retrieves the Process ID (PID) of the target on its local system. @@ -1013,7 +1013,7 @@ struct ITargetControl :return: The name of the client currently connected to the target. :rtype: ``str`` )"); - virtual const char *GetBusyClient() = 0; + virtual rdcstr GetBusyClient() = 0; DOCUMENT(R"(Trigger a capture on the target, with the same semantics as if the capture key had been pressed - from the next presentation call after this message is processed on the target to the @@ -1042,7 +1042,7 @@ target control connection. :param int captureId: The identifier of the remote capture. :param str localpath: The absolute path on the local system where the file should be saved. )"); - virtual void CopyCapture(uint32_t captureId, const char *localpath) = 0; + virtual void CopyCapture(uint32_t captureId, const rdcstr &localpath) = 0; DOCUMENT(R"(Delete a capture from the remote machine. @@ -1106,7 +1106,7 @@ This index should not be cached, as writing sections could re-order the indices. :return: The index of the section, or ``-1`` if not found. :rtype: ``int``. )"); - virtual int FindSectionByName(const char *name) = 0; + virtual int FindSectionByName(const rdcstr &name) = 0; DOCUMENT(R"(Locate the index of a section by its type. Returns ``-1`` if the section is not found. @@ -1249,7 +1249,7 @@ If an error occurs, a single :class:`PathEntry` will be returned with appropriat :return: The contents of the specified folder. :rtype: ``list`` of :class:`PathEntry` )"); - virtual rdcarray ListFolder(const char *path) = 0; + virtual rdcarray ListFolder(const rdcstr &path) = 0; DOCUMENT(R"(Launch an application and inject into it to allow capturing. @@ -1267,7 +1267,8 @@ This happens on the remote system, so all paths are relative to the remote files control if everything succeeded. :rtype: ExecuteResult )"); - virtual ExecuteResult ExecuteAndInject(const char *app, const char *workingDir, const char *cmdLine, + virtual ExecuteResult ExecuteAndInject(const rdcstr &app, const rdcstr &workingDir, + const rdcstr &cmdLine, const rdcarray &env, const CaptureOptions &opts) = 0; @@ -1282,7 +1283,7 @@ until the server closes, at which point it will delete any files it owns. :param str filename: The remote path to take ownership of. )"); - virtual void TakeOwnershipCapture(const char *filename) = 0; + virtual void TakeOwnershipCapture(const rdcstr &filename) = 0; DOCUMENT(R"(Copy a capture file that is stored on the local system to the remote system. @@ -1297,7 +1298,7 @@ the capture must be available on the machine where the replay happens. :return: The path on the remote system where the capture was saved temporarily. :rtype: ``str`` )"); - virtual rdcstr CopyCaptureToRemote(const char *filename, RENDERDOC_ProgressCallback progress) = 0; + virtual rdcstr CopyCaptureToRemote(const rdcstr &filename, RENDERDOC_ProgressCallback progress) = 0; DOCUMENT(R"(Copy a capture file that is stored on the remote system to the local system. @@ -1308,7 +1309,7 @@ This function will block until the copy is fully complete, or an error has occur :param ProgressCallback progress: A callback that will be repeatedly called with an updated progress value for the copy. Can be ``None`` if no progress is desired. )"); - virtual void CopyCaptureFromRemote(const char *remotepath, const char *localpath, + virtual void CopyCaptureFromRemote(const rdcstr &remotepath, const rdcstr &localpath, RENDERDOC_ProgressCallback progress) = 0; DOCUMENT(R"(Open a capture file for remote capture and replay. The capture will be opened and @@ -1334,7 +1335,7 @@ or an error has occurred. :rtype: ``tuple`` of :class:`ReplayStatus` and :class:`ReplayController` )"); virtual rdcpair OpenCapture( - uint32_t proxyid, const char *logfile, const ReplayOptions &opts, + uint32_t proxyid, const rdcstr &logfile, const ReplayOptions &opts, RENDERDOC_ProgressCallback progress) = 0; DOCUMENT(R"(Close a capture analysis handle previously opened by :meth:`OpenCapture`. @@ -1374,7 +1375,7 @@ empty or unrecognised. :return: The status of the open operation, whether it succeeded or failed (and how it failed). :rtype: ReplayStatus )"); - virtual ReplayStatus OpenFile(const char *filename, const char *filetype, + virtual ReplayStatus OpenFile(const rdcstr &filename, const rdcstr &filetype, RENDERDOC_ProgressCallback progress) = 0; DOCUMENT(R"(Initialises the file handle from a raw memory buffer. @@ -1390,7 +1391,7 @@ For the :paramref:`OpenBuffer.filetype` parameter, see :meth:`OpenFile`. :return: The status of the open operation, whether it succeeded or failed (and how it failed). :rtype: ReplayStatus )"); - virtual ReplayStatus OpenBuffer(const bytebuf &buffer, const char *filetype, + virtual ReplayStatus OpenBuffer(const bytebuf &buffer, const rdcstr &filetype, RENDERDOC_ProgressCallback progress) = 0; DOCUMENT(R"(When a capture file is opened, an exclusive lock is held on the file on disk. This @@ -1405,7 +1406,7 @@ file. :return: ``True`` if the operation succeeded. :rtype: ``bool`` )"); - virtual bool CopyFileTo(const char *filename) = 0; + virtual bool CopyFileTo(const rdcstr &filename) = 0; DOCUMENT(R"(Converts the currently loaded file to a given format and saves it to disk. @@ -1423,7 +1424,7 @@ representation back to native RDC. :return: The status of the conversion operation, whether it succeeded or failed (and how it failed). :rtype: ReplayStatus )"); - virtual ReplayStatus Convert(const char *filename, const char *filetype, const SDFile *file, + virtual ReplayStatus Convert(const rdcstr &filename, const rdcstr &filetype, const SDFile *file, RENDERDOC_ProgressCallback progress) = 0; DOCUMENT(R"(Returns the human-readable error string for the last error received. @@ -1458,7 +1459,7 @@ replay support. :return: A string identifying the machine ident used to make the capture. :rtype: ``str`` )"); - virtual const char *RecordedMachineIdent() = 0; + virtual rdcstr RecordedMachineIdent() = 0; DOCUMENT(R"(Retrieves the timestamp basis that all timestamps in the capture are relative to. May be 0 if all timestamps are already absolute. @@ -1502,7 +1503,7 @@ This function may only be called if the handle is 'empty' - i.e. no file has bee microseconds. Can be set to 1.0 to indicate that timestamps and durations are already in microseconds. )"); - virtual void SetMetadata(const char *driverName, uint64_t machineIdent, FileType thumbType, + virtual void SetMetadata(const rdcstr &driverName, uint64_t machineIdent, FileType thumbType, uint32_t thumbWidth, uint32_t thumbHeight, const bytebuf &thumbData, uint64_t timeBase, double timeFreq) = 0; @@ -1738,7 +1739,7 @@ This function will block until the control connection is ready, or an error occu :rtype: TargetControl )"); extern "C" RENDERDOC_API ITargetControl *RENDERDOC_CC RENDERDOC_CreateTargetControl( - const char *URL, uint32_t ident, const char *clientName, bool forceConnection); + const rdcstr &URL, uint32_t ident, const rdcstr &clientName, bool forceConnection); DOCUMENT(R"(Repeatedly query to enumerate which targets are active on a given machine and their idents. @@ -1755,7 +1756,7 @@ This function will block for a variable timeout depending on how many targets ar :return: The ident of the next active target, or ``0`` if no other targets exist. :rtype: ``int`` )"); -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteTargets(const char *URL, +extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteTargets(const rdcstr &URL, uint32_t nextIdent); ////////////////////////////////////////////////////////////////////////// @@ -1771,7 +1772,7 @@ DOCUMENT(R"(Create a connection to a remote server running on given hostname. :rtype: ``pair`` of ReplayStatus and RemoteServer )"); extern "C" RENDERDOC_API ReplayStatus RENDERDOC_CC -RENDERDOC_CreateRemoteServerConnection(const char *URL, IRemoteServer **rend); +RENDERDOC_CreateRemoteServerConnection(const rdcstr &URL, IRemoteServer **rend); DOCUMENT(R"(Check the connection to a remote server running on given hostname. @@ -1784,7 +1785,7 @@ the status can be checked without interfering with making connections. :rtype: ReplayStatus )"); extern "C" RENDERDOC_API ReplayStatus RENDERDOC_CC -RENDERDOC_CheckRemoteServerConnection(const char *URL); +RENDERDOC_CheckRemoteServerConnection(const rdcstr &URL); DOCUMENT(R"(This launches a remote server which will continually run in a loop to server requests from external sources. @@ -1799,7 +1800,7 @@ This function will block until a remote connection tells the server to shut down when the server wants to display some preview of the ongoing replay. )"); extern "C" RENDERDOC_API void RENDERDOC_CC -RENDERDOC_BecomeRemoteServer(const char *listenhost, RENDERDOC_KillCallback killReplay, +RENDERDOC_BecomeRemoteServer(const rdcstr &listenhost, RENDERDOC_KillCallback killReplay, RENDERDOC_PreviewWindowCallback previewWindow); ////////////////////////////////////////////////////////////////////////// @@ -1831,8 +1832,8 @@ This function must be called when the process is running with administrator/supe with :func:`StopGlobalHook` before the application is closed. :rtype: ``bool`` )"); -extern "C" RENDERDOC_API bool RENDERDOC_CC RENDERDOC_StartGlobalHook(const char *pathmatch, - const char *logfile, +extern "C" RENDERDOC_API bool RENDERDOC_CC RENDERDOC_StartGlobalHook(const rdcstr &pathmatch, + const rdcstr &logfile, const CaptureOptions &opts); DOCUMENT(R"(Stop the global hook that was activated by :func:`StartGlobalHook`. @@ -1875,8 +1876,8 @@ DOCUMENT(R"(Launch an application and inject into it to allow capturing. :rtype: ExecuteResult )"); extern "C" RENDERDOC_API ExecuteResult RENDERDOC_CC -RENDERDOC_ExecuteAndInject(const char *app, const char *workingDir, const char *cmdLine, - const rdcarray &env, const char *capturefile, +RENDERDOC_ExecuteAndInject(const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, + const rdcarray &env, const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit); DOCUMENT(R"(Where supported by operating system and permissions, inject into a running process. @@ -1893,21 +1894,21 @@ DOCUMENT(R"(Where supported by operating system and permissions, inject into a r )"); extern "C" RENDERDOC_API ExecuteResult RENDERDOC_CC RENDERDOC_InjectIntoProcess(uint32_t pid, const rdcarray &env, - const char *capturefile, const CaptureOptions &opts, bool waitForExit); + const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit); DOCUMENT(R"(When debugging RenderDoc it can be useful to capture itself by doing a side-build with a temporary name. This function wraps up the use of the in-application API to start a capture. :param str dllname: The name of the self-hosted capture module. )"); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartSelfHostCapture(const char *dllname); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartSelfHostCapture(const rdcstr &dllname); DOCUMENT(R"(When debugging RenderDoc it can be useful to capture itself by doing a side-build with a temporary name. This function wraps up the use of the in-application API to end a capture. :param str dllname: The name of the self-hosted capture module. )"); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_EndSelfHostCapture(const char *dllname); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_EndSelfHostCapture(const rdcstr &dllname); ////////////////////////////////////////////////////////////////////////// // Vulkan layer handling @@ -1961,8 +1962,8 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_ShutdownReplay(); #if !defined(SWIG) DOCUMENT("INTERNAL: Create a bug report zip."); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_CreateBugReport(const char *logfile, - const char *dumpfile, +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_CreateBugReport(const rdcstr &logfile, + const rdcstr &dumpfile, rdcstr &report); DOCUMENT("INTERNAL: Register a memory region to be saved with crash dumps."); @@ -1977,7 +1978,7 @@ analysis program. :param str filename: The path to the new log file. )"); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetDebugLogFile(const char *filename); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetDebugLogFile(const rdcstr &filename); DOCUMENT(R"(Gets the location for the diagnostic log output, shared by captured programs and the analysis program. @@ -2002,9 +2003,9 @@ DOCUMENT(R"(Add a message to RenderDoc's logfile. :param int line: The line number in :paramref:`file` where this log message came from. :param str text: The text of the message. )"); -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_LogMessage(LogType type, const char *project, - const char *file, unsigned int line, - const char *text); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_LogMessage(LogType type, const rdcstr &project, + const rdcstr &file, unsigned int line, + const rdcstr &text); DOCUMENT(R"(Retrieves the version string. @@ -2058,7 +2059,7 @@ If no such setting exists, `None` is returned. :return: The specified setting. :rtype: ``SDObject`` )"); -extern "C" RENDERDOC_API const SDObject *RENDERDOC_CC RENDERDOC_GetConfigSetting(const char *name); +extern "C" RENDERDOC_API const SDObject *RENDERDOC_CC RENDERDOC_GetConfigSetting(const rdcstr &name); DOCUMENT(R"(Return a mutable handle to the :class:`SDObject` corresponding to a given setting's value object. @@ -2068,7 +2069,7 @@ If no such setting exists, `None` is returned. :return: The specified setting. :rtype: ``SDObject`` )"); -extern "C" RENDERDOC_API SDObject *RENDERDOC_CC RENDERDOC_SetConfigSetting(const char *name); +extern "C" RENDERDOC_API SDObject *RENDERDOC_CC RENDERDOC_SetConfigSetting(const rdcstr &name); DOCUMENT(R"(Flush the current config settings as they are in memory to the config file on disk. @@ -2090,12 +2091,12 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetColors(FloatVector darkC bool darkTheme); DOCUMENT("INTERNAL: Check remote Android package for requirements"); -extern "C" RENDERDOC_API void RENDERDOC_CC -RENDERDOC_CheckAndroidPackage(const char *URL, const char *packageAndActivity, AndroidFlags *flags); +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_CheckAndroidPackage( + const rdcstr &URL, const rdcstr &packageAndActivity, AndroidFlags *flags); DOCUMENT("INTERNAL: Patch an APK to add debuggable flag."); extern "C" RENDERDOC_API AndroidFlags RENDERDOC_CC RENDERDOC_MakeDebuggablePackage( - const char *URL, const char *packageAndActivity, RENDERDOC_ProgressCallback progress); + const rdcstr &URL, const rdcstr &packageAndActivity, RENDERDOC_ProgressCallback progress); DOCUMENT("An interface for enumerating and controlling remote devices."); struct IDeviceProtocolController diff --git a/renderdoc/api/replay/structured_data.h b/renderdoc/api/replay/structured_data.h index 1a0e9960a..74ba38803 100644 --- a/renderdoc/api/replay/structured_data.h +++ b/renderdoc/api/replay/structured_data.h @@ -805,14 +805,12 @@ returned. return false; return true; } - const char *Type() const { return type.name.c_str(); } - const char *Name() const { return name.c_str(); } - SDObject *SetTypeName(const char *customTypeName) + SDObject *SetTypeName(const rdcstr &customTypeName) { type.name = customTypeName; return this; } - SDObject *SetCustomString(const char *customString) + SDObject *SetCustomString(const rdcstr &customString) { data.str = customString; type.flags = SDTypeFlags::HasCustomString; @@ -1165,9 +1163,9 @@ inline SDObject *makeSDStruct(const rdcinflexiblestr &name, const rdcinflexibles { \ SDObject *ptr = makeSDFunc(name, value); \ if(customString) \ - ptr->SetCustomString(customString); \ + ptr->SetCustomString(rdcstr(customString)); \ if(customTypeName) \ - ptr->SetTypeName(customTypeName); \ + ptr->SetTypeName(rdcstr(customTypeName)); \ return ptr; \ } diff --git a/renderdoc/common/common.cpp b/renderdoc/common/common.cpp index d0cdf54dd..f77a546e0 100644 --- a/renderdoc/common/common.cpp +++ b/renderdoc/common/common.cpp @@ -265,13 +265,13 @@ void rdclog_filename(const char *filename) if(filename && filename[0]) *logfile = filename; - FileIO::logfile_close(logfileHandle, NULL); + FileIO::logfile_close(logfileHandle, rdcstr()); logfileHandle = NULL; if(!logfile->empty()) { - logfileHandle = FileIO::logfile_open(logfile->c_str()); + logfileHandle = FileIO::logfile_open(*logfile); if(logfileHandle && previous.c_str()) { @@ -279,9 +279,9 @@ void rdclog_filename(const char *filename) FileIO::ReadAll(previous, previousContents); if(!previousContents.empty()) - FileIO::logfile_append(logfileHandle, previousContents.c_str(), previousContents.size()); + FileIO::logfile_append(logfileHandle, previousContents.c_str(), previousContents.length()); - FileIO::Delete(previous.c_str()); + FileIO::Delete(previous); } } } @@ -296,7 +296,7 @@ void rdclog_enableoutput() void rdclog_closelog() { log_output_enabled = false; - FileIO::logfile_close(logfileHandle, logfile->c_str()); + FileIO::logfile_close(logfileHandle, *logfile); } void rdclog_flush() diff --git a/renderdoc/common/common.h b/renderdoc/common/common.h index df82905b8..f3155e2b7 100644 --- a/renderdoc/common/common.h +++ b/renderdoc/common/common.h @@ -507,9 +507,10 @@ void rdcassert(const char *msg, const char *file, unsigned int line, const char #include "custom_assert.h" #else -#define RDCASSERTMSG(cond) \ - do \ - { \ +#define RDCASSERTMSG(...) \ + do \ + { \ + (void)(__VA_ARGS__); \ } while((void)0, 0) #endif diff --git a/renderdoc/common/shader_cache.h b/renderdoc/common/shader_cache.h index 1a8dffe74..2069d262a 100644 --- a/renderdoc/common/shader_cache.h +++ b/renderdoc/common/shader_cache.h @@ -32,12 +32,12 @@ static const uint32_t ShaderCacheMagic = MAKE_FOURCC('R', 'D', '$', '$'); template -bool LoadShaderCache(const char *filename, const uint32_t magicNumber, const uint32_t versionNumber, +bool LoadShaderCache(const rdcstr &filename, const uint32_t magicNumber, const uint32_t versionNumber, std::map &resultCache, const ShaderCallbacks &callbacks) { rdcstr shadercache = FileIO::GetAppFolderFilename(filename); - StreamReader fileReader(FileIO::fopen(shadercache.c_str(), "rb")); + StreamReader fileReader(FileIO::fopen(shadercache, FileIO::ReadBinary)); uint32_t globalMagic = 0, localMagic = 0, version = 0; fileReader.Read(globalMagic); @@ -86,12 +86,12 @@ bool LoadShaderCache(const char *filename, const uint32_t magicNumber, const uin } template -void SaveShaderCache(const char *filename, uint32_t magicNumber, uint32_t versionNumber, +void SaveShaderCache(const rdcstr &filename, uint32_t magicNumber, uint32_t versionNumber, const std::map &cache, const ShaderCallbacks &callbacks) { rdcstr shadercache = FileIO::GetAppFolderFilename(filename); - FILE *f = FileIO::fopen(shadercache.c_str(), "wb"); + FILE *f = FileIO::fopen(shadercache, FileIO::WriteBinary); if(!f) { diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index bb060ca9c..e3d3e1035 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -414,9 +414,7 @@ void RenderDoc::Initialise() { rdcstr capture_filename; - const char *base = "RenderDoc_app"; - if(IsReplayApp()) - base = "RenderDoc"; + const rdcstr base = IsReplayApp() ? "RenderDoc" : "RenderDoc_app"; FileIO::GetDefaultFiles(base, capture_filename, m_LoggingFilename, m_Target); @@ -500,7 +498,7 @@ RenderDoc::~RenderDoc() if(m_Captures[i].retrieved) { RDCLOG("Removing remotely retrieved capture %s", m_Captures[i].path.c_str()); - FileIO::Delete(m_Captures[i].path.c_str()); + FileIO::Delete(m_Captures[i].path); } else { @@ -1340,11 +1338,8 @@ StructuredProcessor RenderDoc::GetStructuredProcessor(RDCDriver driver) return it->second; } -CaptureExporter RenderDoc::GetCaptureExporter(const char *filetype) +CaptureExporter RenderDoc::GetCaptureExporter(const rdcstr &filetype) { - if(!filetype) - return NULL; - auto it = m_Exporters.find(filetype); if(it == m_Exporters.end()) @@ -1353,11 +1348,8 @@ CaptureExporter RenderDoc::GetCaptureExporter(const char *filetype) return it->second; } -CaptureImporter RenderDoc::GetCaptureImporter(const char *filetype) +CaptureImporter RenderDoc::GetCaptureImporter(const rdcstr &filetype) { - if(!filetype) - return NULL; - auto it = m_Importers.find(filetype); if(it == m_Importers.end()) @@ -1640,9 +1632,9 @@ void RenderDoc::SetCaptureOptions(const CaptureOptions &opts) LibraryHooks::OptionsUpdated(); } -void RenderDoc::SetCaptureFileTemplate(const char *pathtemplate) +void RenderDoc::SetCaptureFileTemplate(const rdcstr &pathtemplate) { - if(pathtemplate == NULL || pathtemplate[0] == '\0') + if(pathtemplate.empty()) return; m_CaptureFileTemplate = pathtemplate; diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index 310bbc0fd..126c5507b 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -330,9 +330,9 @@ typedef ReplayStatus (*ReplayDriverProvider)(RDCFile *rdc, const ReplayOptions & typedef void (*StructuredProcessor)(RDCFile *rdc, SDFile &structData); -typedef ReplayStatus (*CaptureImporter)(const char *filename, StreamReader &reader, RDCFile *rdc, +typedef ReplayStatus (*CaptureImporter)(const rdcstr &filename, StreamReader &reader, RDCFile *rdc, SDFile &structData, RENDERDOC_ProgressCallback progress); -typedef ReplayStatus (*CaptureExporter)(const char *filename, const RDCFile &rdc, +typedef ReplayStatus (*CaptureExporter)(const rdcstr &filename, const RDCFile &rdc, const SDFile &structData, RENDERDOC_ProgressCallback progress); typedef IDeviceProtocolHandler *(*ProtocolHandler)(); @@ -404,9 +404,9 @@ public: } // set from outside of the device creation interface - void SetCaptureFileTemplate(const char *logFile); + void SetCaptureFileTemplate(const rdcstr &logFile); const char *GetCaptureFileTemplate() const { return m_CaptureFileTemplate.c_str(); } - const char *GetCurrentTarget() const { return m_Target.c_str(); } + const rdcstr &GetCurrentTarget() const { return m_Target; } void Initialise(); void RemoveHooks(); @@ -418,7 +418,7 @@ public: void RegisterShutdownFunction(ShutdownFunction func); void SetReplayApp(bool replay) { m_Replay = replay; } bool IsReplayApp() const { return m_Replay; } - void BecomeRemoteServer(const char *listenhost, uint16_t port, RENDERDOC_KillCallback killReplay, + void BecomeRemoteServer(const rdcstr &listenhost, uint16_t port, RENDERDOC_KillCallback killReplay, RENDERDOC_PreviewWindowCallback previewWindow); const SDObject *GetConfigSetting(const rdcstr &name); @@ -466,8 +466,8 @@ public: StructuredProcessor GetStructuredProcessor(RDCDriver driver); - CaptureExporter GetCaptureExporter(const char *filetype); - CaptureImporter GetCaptureImporter(const char *filetype); + CaptureExporter GetCaptureExporter(const rdcstr &filetype); + CaptureImporter GetCaptureImporter(const rdcstr &filetype); rdcarray GetSupportedDeviceProtocols(); IDeviceProtocolHandler *GetDeviceProtocol(const rdcstr &protocol); diff --git a/renderdoc/core/image_viewer.cpp b/renderdoc/core/image_viewer.cpp index 63e61bcab..819769215 100644 --- a/renderdoc/core/image_viewer.cpp +++ b/renderdoc/core/image_viewer.cpp @@ -495,7 +495,7 @@ void ImageViewer::RefreshFile() for(int attempt = 0; attempt < 10 && f == NULL; attempt++) { - f = FileIO::fopen(m_Filename.c_str(), "rb"); + f = FileIO::fopen(m_Filename, FileIO::ReadBinary); if(f) break; Threading::Sleep(40); diff --git a/renderdoc/core/plugins.cpp b/renderdoc/core/plugins.cpp index c87a3e3b9..51fcc803b 100644 --- a/renderdoc/core/plugins.cpp +++ b/renderdoc/core/plugins.cpp @@ -73,7 +73,7 @@ rdcstr LocatePluginFile(const rdcstr &path, const rdcstr &fileName) for(uint32_t i = 0; i < paths.size(); i++) { rdcstr check = paths[i] + "/" + path + "/" + fileName; - if(FileIO::exists(check.c_str())) + if(FileIO::exists(check)) { ret = check; break; diff --git a/renderdoc/core/remote_server.cpp b/renderdoc/core/remote_server.cpp index 0d90bc31f..06bcf2f99 100644 --- a/renderdoc/core/remote_server.cpp +++ b/renderdoc/core/remote_server.cpp @@ -278,9 +278,9 @@ static void ActiveRemoteClientThread(ClientThread *threadData, RDCLOG("Logging remote server work to '%s'", filename.c_str()); // truncate the log - debugLog = FileIO::logfile_open(filename.c_str()); - FileIO::logfile_close(debugLog, filename.c_str()); - debugLog = FileIO::logfile_open(filename.c_str()); + debugLog = FileIO::logfile_open(filename); + FileIO::logfile_close(debugLog, filename); + debugLog = FileIO::logfile_open(filename); reader.EnableDumping(debugLog); writer.EnableDumping(debugLog); @@ -363,7 +363,7 @@ static void ActiveRemoteClientThread(ClientThread *threadData, reader.EndChunk(); rdcarray files; - FileIO::GetFilesInDirectory(path.c_str(), files); + FileIO::GetFilesInDirectory(path, files); { WRITE_DATA_SCOPE(); @@ -386,7 +386,7 @@ static void ActiveRemoteClientThread(ClientThread *threadData, WRITE_DATA_SCOPE(); SCOPED_SERIALISE_CHUNK(eRemoteServer_CopyCaptureFromRemote); - StreamReader fileStream(FileIO::fopen(path.c_str(), "rb")); + StreamReader fileStream(FileIO::fopen(path, FileIO::ReadBinary)); ser.SerialiseStream(path, fileStream); } } @@ -403,16 +403,16 @@ static void ActiveRemoteClientThread(ClientThread *threadData, { READ_DATA_SCOPE(); - StreamWriter streamWriter(FileIO::fopen(path.c_str(), "wb"), Ownership::Stream); + StreamWriter streamWriter(FileIO::fopen(path, FileIO::WriteBinary), Ownership::Stream); - ser.SerialiseStream(path.c_str(), streamWriter, NULL); + ser.SerialiseStream(path, streamWriter, NULL); } reader.EndChunk(); if(reader.IsErrored()) { - FileIO::Delete(path.c_str()); + FileIO::Delete(path); RDCERR("Network error receiving file"); break; @@ -486,7 +486,7 @@ static void ActiveRemoteClientThread(ClientThread *threadData, ReplayStatus status = ReplayStatus::InternalError; rdc = new RDCFile(); - rdc->Open(path.c_str()); + rdc->Open(path); if(rdc->ErrorCode() != ContainerError::NoError) { @@ -710,7 +710,7 @@ static void ActiveRemoteClientThread(ClientThread *threadData, reader.EndChunk(); - int index = rdc ? rdc->SectionIndex(name.c_str()) : -1; + int index = rdc ? rdc->SectionIndex(name) : -1; { WRITE_DATA_SCOPE(); @@ -859,8 +859,8 @@ static void ActiveRemoteClientThread(ClientThread *threadData, if(threadData->allowExecution) { - rdcpair status = Process::LaunchAndInjectIntoProcess( - app.c_str(), workingDir.c_str(), cmdLine.c_str(), env, "", opts, false); + rdcpair status = + Process::LaunchAndInjectIntoProcess(app, workingDir, cmdLine, env, "", opts, false); ret.status = status.first; ret.ident = status.second; @@ -887,7 +887,7 @@ static void ActiveRemoteClientThread(ClientThread *threadData, } } - FileIO::logfile_close(debugLog, NULL); + FileIO::logfile_close(debugLog, rdcstr()); SAFE_DELETE(proxy); @@ -900,7 +900,7 @@ static void ActiveRemoteClientThread(ClientThread *threadData, for(size_t i = 0; i < tempFiles.size(); i++) { - FileIO::Delete(tempFiles[i].c_str()); + FileIO::Delete(tempFiles[i]); } RDCLOG("Closing active connection from %u.%u.%u.%u.", Network::GetIPOctet(ip, 0), @@ -911,7 +911,7 @@ static void ActiveRemoteClientThread(ClientThread *threadData, SAFE_DELETE(client); } -void RenderDoc::BecomeRemoteServer(const char *listenhost, uint16_t port, +void RenderDoc::BecomeRemoteServer(const rdcstr &listenhost, uint16_t port, std::function killReplay, RENDERDOC_PreviewWindowCallback previewWindow) { @@ -923,7 +923,7 @@ void RenderDoc::BecomeRemoteServer(const char *listenhost, uint16_t port, rdcarray > listenRanges; bool allowExecution = true; - FILE *f = FileIO::fopen(FileIO::GetAppFolderFilename("remoteserver.conf").c_str(), "r"); + FILE *f = FileIO::fopen(FileIO::GetAppFolderFilename("remoteserver.conf"), FileIO::ReadText); rdcstr configFile; @@ -957,7 +957,7 @@ void RenderDoc::BecomeRemoteServer(const char *listenhost, uint16_t port, uint32_t ip = 0, mask = 0; // CIDR notation - bool found = Network::ParseIPRangeCIDR(line.c_str() + sizeof("whitelist"), ip, mask); + bool found = Network::ParseIPRangeCIDR(line.substr(sizeof("whitelist")), ip, mask); if(found) { @@ -1126,10 +1126,10 @@ void RenderDoc::BecomeRemoteServer(const char *listenhost, uint16_t port, } extern "C" RENDERDOC_API ReplayStatus RENDERDOC_CC -RENDERDOC_CreateRemoteServerConnection(const char *URL, IRemoteServer **rend) +RENDERDOC_CreateRemoteServerConnection(const rdcstr &URL, IRemoteServer **rend) { rdcstr host = "localhost"; - if(URL != NULL && URL[0] != '\0') + if(!URL.empty()) host = URL; rdcstr deviceID = host; @@ -1148,7 +1148,7 @@ RENDERDOC_CreateRemoteServerConnection(const char *URL, IRemoteServer **rend) port = protocol->RemapPort(deviceID, port); } - Network::Socket *sock = Network::CreateClientSocket(host.c_str(), port, 750); + Network::Socket *sock = Network::CreateClientSocket(host, port, 750); if(sock == NULL) return ReplayStatus::NetworkIOFailed; @@ -1210,7 +1210,8 @@ RENDERDOC_CreateRemoteServerConnection(const char *URL, IRemoteServer **rend) return ReplayStatus::Succeeded; } -extern "C" RENDERDOC_API ReplayStatus RENDERDOC_CC RENDERDOC_CheckRemoteServerConnection(const char *URL) +extern "C" RENDERDOC_API ReplayStatus RENDERDOC_CC +RENDERDOC_CheckRemoteServerConnection(const rdcstr &URL) { return RENDERDOC_CreateRemoteServerConnection(URL, NULL); } @@ -1236,9 +1237,9 @@ RemoteServer::RemoteServer(Network::Socket *sock, const rdcstr &deviceID) RDCLOG("Logging remote server work to '%s'", filename.c_str()); // truncate the log - debugLog = FileIO::logfile_open(filename.c_str()); - FileIO::logfile_close(debugLog, filename.c_str()); - debugLog = FileIO::logfile_open(filename.c_str()); + debugLog = FileIO::logfile_open(filename); + FileIO::logfile_close(debugLog, filename); + debugLog = FileIO::logfile_open(filename); reader->EnableDumping(debugLog); writer->EnableDumping(debugLog); @@ -1260,7 +1261,7 @@ RemoteServer::RemoteServer(Network::Socket *sock, const rdcstr &deviceID) RemoteServer::~RemoteServer() { - FileIO::logfile_close(debugLog, NULL); + FileIO::logfile_close(debugLog, rdcstr()); SAFE_DELETE(writer); SAFE_DELETE(reader); SAFE_DELETE(m_Socket); @@ -1400,7 +1401,7 @@ rdcstr RemoteServer::GetHomeFolder() return home; } -rdcarray RemoteServer::ListFolder(const char *path) +rdcarray RemoteServer::ListFolder(const rdcstr &path) { { WRITE_DATA_SCOPE(); @@ -1433,14 +1434,11 @@ rdcarray RemoteServer::ListFolder(const char *path) return files; } -ExecuteResult RemoteServer::ExecuteAndInject(const char *a, const char *w, const char *c, +ExecuteResult RemoteServer::ExecuteAndInject(const rdcstr &app, const rdcstr &workingDir, + const rdcstr &cmdline, const rdcarray &env, const CaptureOptions &opts) { - rdcstr app = a && a[0] ? a : ""; - rdcstr workingDir = w && w[0] ? w : ""; - rdcstr cmdline = c && c[0] ? c : ""; - { WRITE_DATA_SCOPE(); SCOPED_SERIALISE_CHUNK(eRemoteServer_ExecuteAndInject); @@ -1472,15 +1470,13 @@ ExecuteResult RemoteServer::ExecuteAndInject(const char *a, const char *w, const return ret; } -void RemoteServer::CopyCaptureFromRemote(const char *remotepath, const char *localpath, +void RemoteServer::CopyCaptureFromRemote(const rdcstr &remotepath, const rdcstr &localpath, RENDERDOC_ProgressCallback progress) { - rdcstr path = remotepath; - { WRITE_DATA_SCOPE(); SCOPED_SERIALISE_CHUNK(eRemoteServer_CopyCaptureFromRemote); - SERIALISE_ELEMENT(path); + SERIALISE_ELEMENT(remotepath); } { @@ -1489,7 +1485,7 @@ void RemoteServer::CopyCaptureFromRemote(const char *remotepath, const char *loc if(type == eRemoteServer_CopyCaptureFromRemote) { - StreamWriter streamWriter(FileIO::fopen(localpath, "wb"), Ownership::Stream); + StreamWriter streamWriter(FileIO::fopen(localpath, FileIO::WriteBinary), Ownership::Stream); ser.SerialiseStream(localpath, streamWriter, progress); @@ -1508,13 +1504,13 @@ void RemoteServer::CopyCaptureFromRemote(const char *remotepath, const char *loc } } -rdcstr RemoteServer::CopyCaptureToRemote(const char *filename, RENDERDOC_ProgressCallback progress) +rdcstr RemoteServer::CopyCaptureToRemote(const rdcstr &filename, RENDERDOC_ProgressCallback progress) { - FILE *fileHandle = FileIO::fopen(filename, "rb"); + FILE *fileHandle = FileIO::fopen(filename, FileIO::ReadBinary); if(!fileHandle) { - RDCERR("Can't open file '%s'", filename); + RDCERR("Can't open file '%s'", filename.c_str()); return ""; } @@ -1548,19 +1544,17 @@ rdcstr RemoteServer::CopyCaptureToRemote(const char *filename, RENDERDOC_Progres return path; } -void RemoteServer::TakeOwnershipCapture(const char *filename) +void RemoteServer::TakeOwnershipCapture(const rdcstr &filename) { - rdcstr path = filename; - { WRITE_DATA_SCOPE(); SCOPED_SERIALISE_CHUNK(eRemoteServer_TakeOwnershipCapture); - SERIALISE_ELEMENT(path); + SERIALISE_ELEMENT(filename); } } rdcpair RemoteServer::OpenCapture( - uint32_t proxyid, const char *filename, const ReplayOptions &opts, + uint32_t proxyid, const rdcstr &filename, const ReplayOptions &opts, RENDERDOC_ProgressCallback progress) { rdcpair ret; @@ -1772,7 +1766,7 @@ int RemoteServer::GetSectionCount() return count; } -int RemoteServer::FindSectionByName(const char *name) +int RemoteServer::FindSectionByName(const rdcstr &name) { if(!Connected()) return -1; diff --git a/renderdoc/core/remote_server.h b/renderdoc/core/remote_server.h index 6fcdeca06..ed9cb1c79 100644 --- a/renderdoc/core/remote_server.h +++ b/renderdoc/core/remote_server.h @@ -57,21 +57,22 @@ public: virtual rdcstr GetHomeFolder(); - virtual rdcarray ListFolder(const char *path); + virtual rdcarray ListFolder(const rdcstr &path); - virtual ExecuteResult ExecuteAndInject(const char *a, const char *w, const char *c, + virtual ExecuteResult ExecuteAndInject(const rdcstr &app, const rdcstr &workingDir, + const rdcstr &cmdline, const rdcarray &env, const CaptureOptions &opts); - virtual void CopyCaptureFromRemote(const char *remotepath, const char *localpath, + virtual void CopyCaptureFromRemote(const rdcstr &remotepath, const rdcstr &localpath, RENDERDOC_ProgressCallback progress); - virtual rdcstr CopyCaptureToRemote(const char *filename, RENDERDOC_ProgressCallback progress); + virtual rdcstr CopyCaptureToRemote(const rdcstr &filename, RENDERDOC_ProgressCallback progress); - virtual void TakeOwnershipCapture(const char *filename); + virtual void TakeOwnershipCapture(const rdcstr &filename); virtual rdcpair OpenCapture(uint32_t proxyid, - const char *filename, + const rdcstr &filename, const ReplayOptions &opts, RENDERDOC_ProgressCallback progress); @@ -83,7 +84,7 @@ public: virtual int GetSectionCount(); - virtual int FindSectionByName(const char *name); + virtual int FindSectionByName(const rdcstr &name); virtual int FindSectionByType(SectionType sectionType); diff --git a/renderdoc/core/settings.cpp b/renderdoc/core/settings.cpp index 6385436f4..12998c7cf 100644 --- a/renderdoc/core/settings.cpp +++ b/renderdoc/core/settings.cpp @@ -273,14 +273,14 @@ static bool MergeConfigValues(const rdcstr &prefix, SDObject *dstConfig, const S // for every child in the destination, see if it has a source node. If not, we're out of date for(size_t i = 0; i < dstConfig->NumChildren(); i++) - ret |= (srcConfig->FindChild(dstConfig->GetChild(i)->name.c_str()) == NULL); + ret |= (srcConfig->FindChild(dstConfig->GetChild(i)->name) == NULL); // for every child in the source for(size_t i = 0; i < srcConfig->NumChildren(); i++) { // see if it's present in the destination const SDObject *srcChild = srcConfig->GetChild(i); - SDObject *dstChild = dstConfig->FindChild(srcChild->name.c_str()); + SDObject *dstChild = dstConfig->FindChild(srcChild->name); if(dstChild) { @@ -461,7 +461,7 @@ void RenderDoc::ProcessConfig() SDObject *loadedConfig = NULL; { - StreamReader reader(FileIO::fopen(confFile.c_str(), "rb")); + StreamReader reader(FileIO::fopen(confFile, FileIO::ReadBinary)); loadedConfig = importXMLConfig(reader); } @@ -484,7 +484,7 @@ void RenderDoc::ProcessConfig() MergeConfigValues(rdcstr(), loadedConfig, m_Config, true); { - StreamWriter writer(FileIO::fopen((confFile + ".tmp").c_str(), "wb"), Ownership::Stream); + StreamWriter writer(FileIO::fopen(confFile + ".tmp", FileIO::WriteBinary), Ownership::Stream); exportXMLConfig(writer, loadedConfig); @@ -494,7 +494,7 @@ void RenderDoc::ProcessConfig() // if we successfully wrote the file, move it over the original if(success) - FileIO::Move((confFile + ".tmp").c_str(), confFile.c_str(), true); + FileIO::Move(confFile + ".tmp", confFile, true); } // delete the loaded config if we have it @@ -510,7 +510,7 @@ void RenderDoc::SaveConfigSettings() bool success = false; { - StreamWriter writer(FileIO::fopen((confFile + ".tmp").c_str(), "wb"), Ownership::Stream); + StreamWriter writer(FileIO::fopen(confFile + ".tmp", FileIO::WriteBinary), Ownership::Stream); exportXMLConfig(writer, m_Config); @@ -520,7 +520,7 @@ void RenderDoc::SaveConfigSettings() // if we successfully wrote the file, move it over the original if(success) - FileIO::Move((confFile + ".tmp").c_str(), confFile.c_str(), true); + FileIO::Move(confFile + ".tmp", confFile, true); } } @@ -548,7 +548,7 @@ SDObject *RenderDoc::FindConfigSetting(const rdcstr &settingPath) rdcstr node = path.substr(0, idx); path.erase(0, idx + 1); - SDObject *child = cur->FindChild(node.c_str()); + SDObject *child = cur->FindChild(node); if(!child) return NULL; @@ -556,7 +556,7 @@ SDObject *RenderDoc::FindConfigSetting(const rdcstr &settingPath) idx = path.find_first_of("_."); } - SDObject *obj = cur->FindChild(path.c_str()); + SDObject *obj = cur->FindChild(path); if(obj) return obj->FindChild("value"); @@ -577,7 +577,7 @@ void RenderDoc::RegisterSetting(const rdcstr &settingPath, SDObject *setting) rdcstr node = path.substr(0, idx); path.erase(0, idx + 1); - SDObject *child = cur->FindChild(node.c_str()); + SDObject *child = cur->FindChild(node); if(!child) { child = new SDObject(node, "category"_lit); @@ -592,7 +592,7 @@ void RenderDoc::RegisterSetting(const rdcstr &settingPath, SDObject *setting) idx = path.indexOf('_'); } - SDObject *obj = cur->FindChild(path.c_str()); + SDObject *obj = cur->FindChild(path); if(obj != NULL) RDCFATAL("Duplicate setting %s", settingPath.c_str()); diff --git a/renderdoc/core/target_control.cpp b/renderdoc/core/target_control.cpp index 7a44ab6ab..6a0da233d 100644 --- a/renderdoc/core/target_control.cpp +++ b/renderdoc/core/target_control.cpp @@ -215,7 +215,7 @@ void RenderDoc::TargetControlClientThread(uint32_t version, Network::Socket *cli bytebuf buf; ICaptureFile *file = RENDERDOC_OpenCaptureFile(); - if(file->OpenFile(captures.back().path.c_str(), "rdc", NULL) == ReplayStatus::Succeeded) + if(file->OpenFile(captures.back().path, "rdc", NULL) == ReplayStatus::Succeeded) { buf = file->GetThumbnail(FileType::JPG, 0).data; } @@ -356,7 +356,7 @@ void RenderDoc::TargetControlClientThread(uint32_t version, Network::Socket *cli rdcstr filename = caps[id].path; - StreamReader fileStream(FileIO::fopen(filename.c_str(), "rb")); + StreamReader fileStream(FileIO::fopen(filename, FileIO::ReadBinary)); ser.SerialiseStream(filename, fileStream); if(fileStream.IsErrored() || ser.IsErrored()) @@ -598,10 +598,10 @@ public: delete this; } - const char *GetTarget() { return m_Target.c_str(); } - const char *GetAPI() { return m_API.c_str(); } + rdcstr GetTarget() { return m_Target; } + rdcstr GetAPI() { return m_API; } uint32_t GetPID() { return m_PID; } - const char *GetBusyClient() { return m_BusyClient.c_str(); } + rdcstr GetBusyClient() { return m_BusyClient; } void TriggerCapture(uint32_t numFrames) { WRITE_DATA_SCOPE(); @@ -625,7 +625,7 @@ public: SAFE_DELETE(m_Socket); } - void CopyCapture(uint32_t remoteID, const char *localpath) + void CopyCapture(uint32_t remoteID, const rdcstr &localpath) { WRITE_DATA_SCOPE(); SCOPED_SERIALISE_CHUNK(ePacket_CopyCapture); @@ -777,7 +777,7 @@ public: if(driver != RDCDriver::Unknown) msg.newCapture.api = ToStr(driver); - msg.newCapture.local = FileIO::exists(msg.newCapture.path.c_str()); + msg.newCapture.local = FileIO::exists(msg.newCapture.path); RDCLOG("Got a new capture: %d (frame %u) (%u bytes) (time %llu) %d byte thumbnail", msg.newCapture.captureId, msg.newCapture.frameNumber, msg.newCapture.byteSize, @@ -842,9 +842,10 @@ public: msg.newCapture.path = m_CaptureCopies[msg.newCapture.captureId]; - StreamWriter streamWriter(FileIO::fopen(msg.newCapture.path.c_str(), "wb"), Ownership::Stream); + StreamWriter streamWriter(FileIO::fopen(msg.newCapture.path, FileIO::WriteBinary), + Ownership::Stream); - ser.SerialiseStream(msg.newCapture.path.c_str(), streamWriter, progress); + ser.SerialiseStream(msg.newCapture.path, streamWriter, progress); if(reader.IsErrored()) { @@ -890,10 +891,10 @@ private: }; extern "C" RENDERDOC_API ITargetControl *RENDERDOC_CC RENDERDOC_CreateTargetControl( - const char *URL, uint32_t ident, const char *clientName, bool forceConnection) + const rdcstr &URL, uint32_t ident, const rdcstr &clientName, bool forceConnection) { rdcstr host = "localhost"; - if(URL != NULL && URL[0] != '\0') + if(!URL.empty()) host = URL; rdcstr deviceID = host; @@ -911,7 +912,7 @@ extern "C" RENDERDOC_API ITargetControl *RENDERDOC_CC RENDERDOC_CreateTargetCont port = protocol->RemapPort(deviceID, port); } - Network::Socket *sock = Network::CreateClientSocket(host.c_str(), port, 750); + Network::Socket *sock = Network::CreateClientSocket(host, port, 750); if(sock == NULL) return NULL; diff --git a/renderdoc/driver/d3d11/renderdoc_d3d11.vcxproj b/renderdoc/driver/d3d11/renderdoc_d3d11.vcxproj index 650ed0468..e3a9a2e80 100644 --- a/renderdoc/driver/d3d11/renderdoc_d3d11.vcxproj +++ b/renderdoc/driver/d3d11/renderdoc_d3d11.vcxproj @@ -76,7 +76,7 @@ ProgramDatabase precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) 4100 diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index 5661baa5d..dd82bd9ad 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -3793,13 +3793,12 @@ ReplayStatus D3D12_CreateReplayDevice(RDCFile *rdc, const ReplayOptions &opts, I d3d12on7 = true; // if it fails, try in the plugin directory - d3d12lib = (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "d3d12.dll").c_str()); + d3d12lib = (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "d3d12.dll")); // if that succeeded, also load dxilconv7.dll from there if(d3d12lib) { - HMODULE dxilconv = - (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "dxilconv7.dll").c_str()); + HMODULE dxilconv = (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "dxilconv7.dll")); if(!dxilconv) { diff --git a/renderdoc/driver/d3d12/d3d12_shader_cache.cpp b/renderdoc/driver/d3d12/d3d12_shader_cache.cpp index 09f36cbca..6ab3cc0ff 100644 --- a/renderdoc/driver/d3d12/d3d12_shader_cache.cpp +++ b/renderdoc/driver/d3d12/d3d12_shader_cache.cpp @@ -54,7 +54,7 @@ static HMODULE GetDXC() // first try normal plugin search path. This will prioritise any one placed locally with // RenderDoc, otherwise it will try just the unadorned dll in case it's in the PATH somewhere. { - dxilHandle = (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "dxil.dll").c_str()); + dxilHandle = (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "dxil.dll")); // don't try to load dxcompiler.dll until we've got dxil.dll successfully, or if we're not // trying to get dxil. Otherwise we could load dxcompiler (to check for its existence) and @@ -62,7 +62,7 @@ static HMODULE GetDXC() if(dxilHandle || sdkPass == 1) { HMODULE dxcompiler = - (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "dxcompiler.dll").c_str()); + (HMODULE)Process::LoadModule(LocatePluginFile("d3d12", "dxcompiler.dll")); if(dxcompiler) { ret = dxcompiler; @@ -118,7 +118,7 @@ static HMODULE GetDXC() // sort by name rdcarray entries; - FileIO::GetFilesInDirectory(path.c_str(), entries); + FileIO::GetFilesInDirectory(path, entries); std::sort(entries.begin(), entries.end()); // do a reverse iteration so we get the latest SDK first @@ -136,16 +136,16 @@ static HMODULE GetDXC() rdcstr dxilPath = path + e.filename + "\\x64\\dxil.dll"; rdcstr dxcompilerPath = path + e.filename + "\\x64\\dxcompiler.dll"; - bool dxil = FileIO::exists(dxilPath.c_str()); - bool dxcompiler = FileIO::exists(dxcompilerPath.c_str()); + bool dxil = FileIO::exists(dxilPath); + bool dxcompiler = FileIO::exists(dxcompilerPath); // if we have both, or we're on the second pass (given up on dxil.dll) and have // dxcompiler, then load this. if((dxil && dxcompiler) || (sdkPass == 1 && dxcompiler)) { if(dxil) - dxilHandle = (HMODULE)Process::LoadModule(dxilPath.c_str()); - ret = (HMODULE)Process::LoadModule(dxcompilerPath.c_str()); + dxilHandle = (HMODULE)Process::LoadModule(dxilPath); + ret = (HMODULE)Process::LoadModule(dxcompilerPath); } if(ret) @@ -163,16 +163,16 @@ static HMODULE GetDXC() rdcstr dxilPath = path + "..\\Redist\\D3D\\x64\\dxil.dll"; rdcstr dxcompilerPath = path + "..\\Redist\\D3D\\x64\\dxcompiler.dll"; - bool dxil = FileIO::exists(dxilPath.c_str()); - bool dxcompiler = FileIO::exists(dxcompilerPath.c_str()); + bool dxil = FileIO::exists(dxilPath); + bool dxcompiler = FileIO::exists(dxcompilerPath); // if we have both, or we're on the second pass (given up on dxil.dll) and have // dxcompiler, then load this. if((dxil && dxcompiler) || (sdkPass == 1 && dxcompiler)) { if(dxil) - dxilHandle = (HMODULE)Process::LoadModule(dxilPath.c_str()); - ret = (HMODULE)Process::LoadModule(dxcompilerPath.c_str()); + dxilHandle = (HMODULE)Process::LoadModule(dxilPath); + ret = (HMODULE)Process::LoadModule(dxcompilerPath); } if(ret) @@ -189,16 +189,16 @@ static HMODULE GetDXC() rdcstr dxilPath = path + "x64\\dxil.dll"; rdcstr dxcompilerPath = path + "x64\\dxcompiler.dll"; - bool dxil = FileIO::exists(dxilPath.c_str()); - bool dxcompiler = FileIO::exists(dxcompilerPath.c_str()); + bool dxil = FileIO::exists(dxilPath); + bool dxcompiler = FileIO::exists(dxcompilerPath); // if we have both, or we're on the second pass (given up on dxil.dll) and have // dxcompiler, then load this. if((dxil && dxcompiler) || (sdkPass == 1 && dxcompiler)) { if(dxil) - dxilHandle = (HMODULE)Process::LoadModule(dxilPath.c_str()); - ret = (HMODULE)Process::LoadModule(dxcompilerPath.c_str()); + dxilHandle = (HMODULE)Process::LoadModule(dxilPath); + ret = (HMODULE)Process::LoadModule(dxcompilerPath); } if(ret) diff --git a/renderdoc/driver/d3d12/renderdoc_d3d12.vcxproj b/renderdoc/driver/d3d12/renderdoc_d3d12.vcxproj index cc9cf9909..ca93792dc 100644 --- a/renderdoc/driver/d3d12/renderdoc_d3d12.vcxproj +++ b/renderdoc/driver/d3d12/renderdoc_d3d12.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/d3d8/renderdoc_d3d8.vcxproj b/renderdoc/driver/d3d8/renderdoc_d3d8.vcxproj index 5a47c8241..5ee5a165b 100644 --- a/renderdoc/driver/d3d8/renderdoc_d3d8.vcxproj +++ b/renderdoc/driver/d3d8/renderdoc_d3d8.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj b/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj index 28055480e..33ba7dfee 100644 --- a/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj +++ b/renderdoc/driver/d3d9/renderdoc_d3d9.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/dxgi/renderdoc_dxgi.vcxproj b/renderdoc/driver/dxgi/renderdoc_dxgi.vcxproj index 94d9586b8..a8d9b9cb1 100644 --- a/renderdoc/driver/dxgi/renderdoc_dxgi.vcxproj +++ b/renderdoc/driver/dxgi/renderdoc_dxgi.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/gl/egl_hooks.cpp b/renderdoc/driver/gl/egl_hooks.cpp index c19b2f674..c1d5dd1f5 100644 --- a/renderdoc/driver/gl/egl_hooks.cpp +++ b/renderdoc/driver/gl/egl_hooks.cpp @@ -931,10 +931,10 @@ static void EGLHooked(void *handle) bool ShouldHookEGL() { - const char *toggle = Process::GetEnvVariable("RENDERDOC_HOOK_EGL"); + rdcstr toggle = Process::GetEnvVariable("RENDERDOC_HOOK_EGL"); // if the var is set to 0, then don't hook EGL - if(toggle && toggle[0] == '0') + if(toggle.size() >= 1 && toggle[0] == '0') { RDCLOG( "EGL hooks disabled by RENDERDOC_HOOK_EGL environment variable - " @@ -957,11 +957,11 @@ bool ShouldHookEGL() return true; } - const char *ignore_layers = Process::GetEnvVariable("IGNORE_LAYERS"); + rdcstr ignore_layers = Process::GetEnvVariable("IGNORE_LAYERS"); // if we set IGNORE_LAYERS externally that means the layers are broken or can't be configured, so // hook EGL in spite of the layers being present - if(ignore_layers && ignore_layers[0] == '1') + if(ignore_layers.size() >= 1 && ignore_layers[0] == '1') return true; const char *eglExts = query_string(EGL_NO_DISPLAY, EGL_EXTENSIONS); diff --git a/renderdoc/driver/gl/egl_platform.cpp b/renderdoc/driver/gl/egl_platform.cpp index 105f9470e..f16b8ea24 100644 --- a/renderdoc/driver/gl/egl_platform.cpp +++ b/renderdoc/driver/gl/egl_platform.cpp @@ -44,7 +44,7 @@ static void *GetEGLHandle() libEGL = libpath + "/libEGL.dll"; } - return Process::LoadModule(libEGL.c_str()); + return Process::LoadModule(libEGL); #else void *handle = Process::LoadModule("libEGL.so"); diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index 4d2ab50cf..edf1456e9 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -774,8 +774,7 @@ rdcstr GLReplay::DisassembleShader(ResourceId pipeline, const ShaderReflection * rdcstr &disasm = shaderDetails.disassembly; if(disasm.empty()) - disasm = shaderDetails.spirv.Disassemble(refl->entryPoint.c_str(), - shaderDetails.spirvInstructionLines); + disasm = shaderDetails.spirv.Disassemble(refl->entryPoint, shaderDetails.spirvInstructionLines); return disasm; } diff --git a/renderdoc/driver/gl/gl_shader_refl.cpp b/renderdoc/driver/gl/gl_shader_refl.cpp index 5baf2f3ce..d4bfe507a 100644 --- a/renderdoc/driver/gl/gl_shader_refl.cpp +++ b/renderdoc/driver/gl/gl_shader_refl.cpp @@ -2313,7 +2313,7 @@ void GetBindpointMapping(GLuint curProg, int shadIdx, const ShaderReflection *re } // handle sampler arrays, use the base name - rdcstr name = refl->readOnlyResources[i].name.c_str(); + rdcstr name = refl->readOnlyResources[i].name; if(name.back() == ']') { do @@ -2363,7 +2363,7 @@ void GetBindpointMapping(GLuint curProg, int shadIdx, const ShaderReflection *re } // handle sampler arrays, use the base name - rdcstr name = refl->readWriteResources[i].name.c_str(); + rdcstr name = refl->readWriteResources[i].name; if(name.back() == ']') { do diff --git a/renderdoc/driver/gl/renderdoc_gl.vcxproj b/renderdoc/driver/gl/renderdoc_gl.vcxproj index 90a9029da..d1f727370 100644 --- a/renderdoc/driver/gl/renderdoc_gl.vcxproj +++ b/renderdoc/driver/gl/renderdoc_gl.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/ihv/amd/AMD.vcxproj b/renderdoc/driver/ihv/amd/AMD.vcxproj index 45a943814..d14c83ec2 100644 --- a/renderdoc/driver/ihv/amd/AMD.vcxproj +++ b/renderdoc/driver/ihv/amd/AMD.vcxproj @@ -70,7 +70,7 @@ false ProgramDatabase 4100 - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/ihv/amd/AMD_RGP.vcxproj b/renderdoc/driver/ihv/amd/AMD_RGP.vcxproj index ccc160e5b..689641bbf 100644 --- a/renderdoc/driver/ihv/amd/AMD_RGP.vcxproj +++ b/renderdoc/driver/ihv/amd/AMD_RGP.vcxproj @@ -70,7 +70,7 @@ false ProgramDatabase 4100;4201;4324;4189;4127;4996 - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/ihv/amd/amd_counters.cpp b/renderdoc/driver/ihv/amd/amd_counters.cpp index 2c5760788..32c367940 100644 --- a/renderdoc/driver/ihv/amd/amd_counters.cpp +++ b/renderdoc/driver/ihv/amd/amd_counters.cpp @@ -99,12 +99,12 @@ bool AMDCounters::Init(ApiType apiType, void *pContext) #endif // first try in the plugin location it will be in distributed builds - rdcstr dllPath = LocatePluginFile("amd/counters", dllName.c_str()); + rdcstr dllPath = LocatePluginFile("amd/counters", dllName); - void *module = Process::LoadModule(dllPath.c_str()); + void *module = Process::LoadModule(dllPath); if(module == NULL) { - module = Process::LoadModule(dllName.c_str()); + module = Process::LoadModule(dllName); } if(module == NULL) diff --git a/renderdoc/driver/ihv/amd/amd_isa.cpp b/renderdoc/driver/ihv/amd/amd_isa.cpp index 6639d4c2a..9fd66171d 100644 --- a/renderdoc/driver/ihv/amd/amd_isa.cpp +++ b/renderdoc/driver/ihv/amd/amd_isa.cpp @@ -52,7 +52,7 @@ static bool CheckForSupport(ShaderEncoding encoding) rdcstr vc = LocatePluginFile(pluginPath, virtualcontext_name); Process::ProcessResult result = {}; - Process::LaunchProcess(vc.c_str(), get_dirname(vc).c_str(), "", true, &result); + Process::LaunchProcess(vc, get_dirname(vc), "", true, &result); // running with no parameters produces an error, so if there's no output something went wrong. if(result.strStdout.empty()) @@ -67,7 +67,7 @@ static bool CheckForSupport(ShaderEncoding encoding) rdcstr amdspv = LocatePluginFile(pluginPath, amdspv_name); Process::ProcessResult result = {}; - Process::LaunchProcess(amdspv.c_str(), get_dirname(amdspv).c_str(), "", true, &result); + Process::LaunchProcess(amdspv, get_dirname(amdspv), "", true, &result); // running with no parameters produces help text, so if there's no output something went wrong. if(result.strStdout.empty()) @@ -243,7 +243,7 @@ rdcstr DisassembleSPIRV(ShaderStage stage, const bytebuf &shaderBytes, const rdc rdcstr amdspv = LocatePluginFile(pluginPath, amdspv_name); Process::ProcessResult result = {}; - Process::LaunchProcess(amdspv.c_str(), get_dirname(amdspv).c_str(), cmdLine.c_str(), true, &result); + Process::LaunchProcess(amdspv, get_dirname(amdspv), cmdLine, true, &result); if(result.strStdout.find("SUCCESS") < 0) { @@ -251,9 +251,9 @@ rdcstr DisassembleSPIRV(ShaderStage stage, const bytebuf &shaderBytes, const rdc } // remove artifacts we don't need - FileIO::Delete(StringFormat::Fmt("%sin.spv", tempPath.c_str()).c_str()); - FileIO::Delete(StringFormat::Fmt("%sout.log", tempPath.c_str()).c_str()); - FileIO::Delete(StringFormat::Fmt("%sout.bin", tempPath.c_str()).c_str()); + FileIO::Delete(StringFormat::Fmt("%sin.spv", tempPath.c_str())); + FileIO::Delete(StringFormat::Fmt("%sout.log", tempPath.c_str())); + FileIO::Delete(StringFormat::Fmt("%sout.bin", tempPath.c_str())); rdcstr ret; @@ -267,7 +267,7 @@ rdcstr DisassembleSPIRV(ShaderStage stage, const bytebuf &shaderBytes, const rdc rdcstr statsfile = StringFormat::Fmt("%sstats.txt", tempPath.c_str()); - if(FileIO::exists(statsfile.c_str())) + if(FileIO::exists(statsfile)) { rdcstr stats; FileIO::ReadAll(statsfile, stats); @@ -276,9 +276,9 @@ rdcstr DisassembleSPIRV(ShaderStage stage, const bytebuf &shaderBytes, const rdc } } - FileIO::Delete(StringFormat::Fmt("%sout.il", tempPath.c_str()).c_str()); - FileIO::Delete(StringFormat::Fmt("%sout.txt", tempPath.c_str()).c_str()); - FileIO::Delete(StringFormat::Fmt("%sstats.txt", tempPath.c_str()).c_str()); + FileIO::Delete(StringFormat::Fmt("%sout.il", tempPath.c_str())); + FileIO::Delete(StringFormat::Fmt("%sout.txt", tempPath.c_str())); + FileIO::Delete(StringFormat::Fmt("%sstats.txt", tempPath.c_str())); rdcstr header = StringFormat::Fmt("; Disassembly for %s\n\n", target.c_str()); @@ -414,17 +414,17 @@ rdcstr DisassembleGLSL(ShaderStage stage, const bytebuf &shaderBytes, const rdcs rdcstr vc = LocatePluginFile(pluginPath, virtualcontext_name); Process::ProcessResult result = {}; - Process::LaunchProcess(vc.c_str(), get_dirname(vc).c_str(), cmdLine.c_str(), true, &result); + Process::LaunchProcess(vc, get_dirname(vc), cmdLine, true, &result); if(result.retCode != 0 || result.strStdout.find("Error") >= 0 || result.strStdout.empty() || - !FileIO::exists(outPath.c_str())) + !FileIO::exists(outPath)) { return "; Failed to Disassemble - check AMD driver is currently running\n\n; " + result.strStdout; } // remove artifacts we don't need - FileIO::Delete(inPath.c_str()); - FileIO::Delete(binPath.c_str()); + FileIO::Delete(inPath); + FileIO::Delete(binPath); rdcstr ret; @@ -434,7 +434,7 @@ rdcstr DisassembleGLSL(ShaderStage stage, const bytebuf &shaderBytes, const rdcs while(ret.back() == '\0') ret.pop_back(); - if(FileIO::exists(statsPath.c_str())) + if(FileIO::exists(statsPath)) { rdcstr stats; FileIO::ReadAll(statsPath, stats); @@ -442,8 +442,8 @@ rdcstr DisassembleGLSL(ShaderStage stage, const bytebuf &shaderBytes, const rdcs } } - FileIO::Delete(outPath.c_str()); - FileIO::Delete(statsPath.c_str()); + FileIO::Delete(outPath); + FileIO::Delete(statsPath); rdcstr header = StringFormat::Fmt("; Disassembly for %s\n\n", target.c_str()); diff --git a/renderdoc/driver/ihv/amd/amd_rgp.cpp b/renderdoc/driver/ihv/amd/amd_rgp.cpp index 4e8b4853b..8d9094f5e 100644 --- a/renderdoc/driver/ihv/amd/amd_rgp.cpp +++ b/renderdoc/driver/ihv/amd/amd_rgp.cpp @@ -95,12 +95,12 @@ AMDRGPControl::AMDRGPControl() #endif // first try in the plugin location it will be in distributed builds - rdcstr dllPath = LocatePluginFile("amd/rgp", dllName.c_str()); + rdcstr dllPath = LocatePluginFile("amd/rgp", dllName); - void *module = Process::LoadModule(dllPath.c_str()); + void *module = Process::LoadModule(dllPath); if(module == NULL) { - module = Process::LoadModule(dllName.c_str()); + module = Process::LoadModule(dllName); } if(module == NULL) diff --git a/renderdoc/driver/ihv/arm/ARM.vcxproj b/renderdoc/driver/ihv/arm/ARM.vcxproj index 9867f9bdc..0705ce588 100644 --- a/renderdoc/driver/ihv/arm/ARM.vcxproj +++ b/renderdoc/driver/ihv/arm/ARM.vcxproj @@ -70,7 +70,7 @@ false ProgramDatabase 4100 - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/ihv/intel/Intel.vcxproj b/renderdoc/driver/ihv/intel/Intel.vcxproj index 7bce8f68d..91408f273 100644 --- a/renderdoc/driver/ihv/intel/Intel.vcxproj +++ b/renderdoc/driver/ihv/intel/Intel.vcxproj @@ -70,7 +70,7 @@ false ProgramDatabase 4100 - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/ihv/nv/NV.vcxproj b/renderdoc/driver/ihv/nv/NV.vcxproj index 54d465ce7..58f2215a8 100644 --- a/renderdoc/driver/ihv/nv/NV.vcxproj +++ b/renderdoc/driver/ihv/nv/NV.vcxproj @@ -70,7 +70,7 @@ false ProgramDatabase 4100 - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/ihv/nv/nv_counters.cpp b/renderdoc/driver/ihv/nv/nv_counters.cpp index 973611e34..c6aabe80d 100644 --- a/renderdoc/driver/ihv/nv/nv_counters.cpp +++ b/renderdoc/driver/ihv/nv/nv_counters.cpp @@ -200,7 +200,7 @@ bool NVCounters::Init() #endif - m_NvPmLib = Process::LoadModule(dllPath.c_str()); + m_NvPmLib = Process::LoadModule(dllPath); if(m_NvPmLib == NULL) { RDCWARN("NV GPU performance counters could not locate 'NvPmApi.Core.dll'"); diff --git a/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp b/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp index 274e38f55..f9919811a 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_compile.cpp @@ -35,7 +35,7 @@ static HMODULE GetLocalD3DCompiler() rdcstr dll = get_dirname(dllFile) + "/d3dcompiler_47.dll"; - return LoadLibraryW(StringFormat::UTF82Wide(dll.c_str()).data()); + return LoadLibraryW(StringFormat::UTF82Wide(dll).data()); } HMODULE GetD3DCompiler() diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp index 3df3ac5b8..1efec2cca 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp @@ -865,7 +865,7 @@ void DXBCContainer::TryFetchSeparateDebugInfo(bytebuf &byteCode, const rdcstr &d { if(i == 0) { - originalShaderFile = FileIO::fopen(originalPath.c_str(), "rb"); + originalShaderFile = FileIO::fopen(originalPath, FileIO::ReadBinary); foundPath = originalPath; continue; } @@ -873,7 +873,7 @@ void DXBCContainer::TryFetchSeparateDebugInfo(bytebuf &byteCode, const rdcstr &d { const rdcstr &searchPath = searchPaths[i - 1]; foundPath = searchPath + "/" + originalPath; - originalShaderFile = FileIO::fopen(foundPath.c_str(), "rb"); + originalShaderFile = FileIO::fopen(foundPath, FileIO::ReadBinary); } } diff --git a/renderdoc/driver/shaders/dxbc/renderdoc_dxbc.vcxproj b/renderdoc/driver/shaders/dxbc/renderdoc_dxbc.vcxproj index 87fd82f00..53313d97d 100644 --- a/renderdoc/driver/shaders/dxbc/renderdoc_dxbc.vcxproj +++ b/renderdoc/driver/shaders/dxbc/renderdoc_dxbc.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/shaders/dxil/renderdoc_dxil.vcxproj b/renderdoc/driver/shaders/dxil/renderdoc_dxil.vcxproj index ececcb80c..a9a28fef1 100644 --- a/renderdoc/driver/shaders/dxil/renderdoc_dxil.vcxproj +++ b/renderdoc/driver/shaders/dxil/renderdoc_dxil.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/shaders/spirv/renderdoc_spirv.vcxproj b/renderdoc/driver/shaders/spirv/renderdoc_spirv.vcxproj index 1681862ef..b3e5dbad4 100644 --- a/renderdoc/driver/shaders/spirv/renderdoc_spirv.vcxproj +++ b/renderdoc/driver/shaders/spirv/renderdoc_spirv.vcxproj @@ -73,7 +73,7 @@ AMD_EXTENSIONS;NV_EXTENSIONS;GLSLANG_OSINCLUDE_WIN32;RENDERDOC_EXPORTS;RENDERDOC_PLATFORM_WIN32;WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) Level3 true - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) 4100 diff --git a/renderdoc/driver/vulkan/renderdoc_vulkan.vcxproj b/renderdoc/driver/vulkan/renderdoc_vulkan.vcxproj index 7d4a62ca6..41e12b7ec 100644 --- a/renderdoc/driver/vulkan/renderdoc_vulkan.vcxproj +++ b/renderdoc/driver/vulkan/renderdoc_vulkan.vcxproj @@ -77,7 +77,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/driver/vulkan/vk_apple.cpp b/renderdoc/driver/vulkan/vk_apple.cpp index da326158f..158c44dc9 100644 --- a/renderdoc/driver/vulkan/vk_apple.cpp +++ b/renderdoc/driver/vulkan/vk_apple.cpp @@ -157,7 +157,7 @@ void *LoadVulkanLibrary() { // first try to load the module globally. If so we assume the user has a global (or at least // user-wide) configuration that we should use. - void *ret = Process::LoadModule(VulkanLibraryName.c_str()); + void *ret = Process::LoadModule(VulkanLibraryName); if(ret) { @@ -166,7 +166,7 @@ void *LoadVulkanLibrary() } // then try the standard SDK install path under /usr/local/lib - ret = Process::LoadModule(("/usr/local/lib/" + VulkanLibraryName).c_str()); + ret = Process::LoadModule("/usr/local/lib/" + VulkanLibraryName); if(ret) { @@ -183,9 +183,9 @@ void *LoadVulkanLibrary() libpath.c_str()); Process::RegisterEnvironmentModification(EnvironmentModification( - EnvMod::Set, EnvSep::NoSep, "VK_ICD_FILENAMES", (libpath + "MoltenVK_icd.json").c_str())); + EnvMod::Set, EnvSep::NoSep, "VK_ICD_FILENAMES", libpath + "MoltenVK_icd.json")); Process::ApplyEnvironmentModification(); - return Process::LoadModule((libpath + VulkanLibraryName).c_str()); + return Process::LoadModule(libpath + VulkanLibraryName)); } diff --git a/renderdoc/driver/vulkan/vk_core.cpp b/renderdoc/driver/vulkan/vk_core.cpp index bc26283b9..06a6cce49 100644 --- a/renderdoc/driver/vulkan/vk_core.cpp +++ b/renderdoc/driver/vulkan/vk_core.cpp @@ -3092,7 +3092,7 @@ bool WrappedVulkan::ProcessChunk(ReadSerialiser &ser, VulkanChunk chunk) case VulkanChunk::vkDebugMarkerSetObjectNameEXT: return Serialise_vkDebugMarkerSetObjectNameEXT(ser, VK_NULL_HANDLE, NULL); case VulkanChunk::SetShaderDebugPath: - return Serialise_SetShaderDebugPath(ser, VK_NULL_HANDLE, NULL); + return Serialise_SetShaderDebugPath(ser, VK_NULL_HANDLE, rdcstr()); case VulkanChunk::vkCreateSwapchainKHR: return Serialise_vkCreateSwapchainKHR(ser, VK_NULL_HANDLE, NULL, NULL, NULL); diff --git a/renderdoc/driver/vulkan/vk_info.cpp b/renderdoc/driver/vulkan/vk_info.cpp index b8d899034..82263b9eb 100644 --- a/renderdoc/driver/vulkan/vk_info.cpp +++ b/renderdoc/driver/vulkan/vk_info.cpp @@ -1296,7 +1296,7 @@ void VulkanCreationInfo::ShaderModuleReflection::Init(VulkanResourceManager *res void VulkanCreationInfo::ShaderModuleReflection::PopulateDisassembly(const rdcspv::Reflector &spirv) { if(disassembly.empty()) - disassembly = spirv.Disassemble(refl.entryPoint.c_str(), instructionLines); + disassembly = spirv.Disassemble(refl.entryPoint, instructionLines); } void VulkanCreationInfo::QueryPool::Init(VulkanResourceManager *resourceMan, VulkanCreationInfo &info, diff --git a/renderdoc/driver/vulkan/vk_layer.cpp b/renderdoc/driver/vulkan/vk_layer.cpp index 1f865d2b9..2ad0d3d79 100644 --- a/renderdoc/driver/vulkan/vk_layer.cpp +++ b/renderdoc/driver/vulkan/vk_layer.cpp @@ -122,7 +122,7 @@ class VulkanHook : LibraryHook if(module_name != "RENDERDOC") { Process::RegisterEnvironmentModification(EnvironmentModification( - EnvMod::Set, EnvSep::NoSep, ("ENABLE_VULKAN_" + module_name + "_CAPTURE").c_str(), "1")); + EnvMod::Set, EnvSep::NoSep, "ENABLE_VULKAN_" + module_name + "_CAPTURE", "1")); } #endif diff --git a/renderdoc/driver/vulkan/vk_posix.cpp b/renderdoc/driver/vulkan/vk_posix.cpp index 0d6042634..4e9592226 100644 --- a/renderdoc/driver/vulkan/vk_posix.cpp +++ b/renderdoc/driver/vulkan/vk_posix.cpp @@ -309,13 +309,13 @@ static rdcstr GetSOFromJSON(const rdcstr &json) char *json_string = new char[1024]; memset(json_string, 0, 1024); - FILE *f = fopen(json.c_str(), "r"); + FILE *f = FileIO::fopen(json, FileIO::ReadText); if(f) { - fread(json_string, 1, 1024, f); + FileIO::fread(json_string, 1, 1024, f); - fclose(f); + FileIO::fclose(f); } rdcstr ret = ""; @@ -601,13 +601,13 @@ void VulkanReplay::InstallVulkanLayer(bool systemLevel) { MakeParentDirs(jsonPath); - FILE *f = fopen(jsonPath.c_str(), "w"); + FILE *f = FileIO::fopen(jsonPath, FileIO::WriteText); if(f) { fputs(GenerateJSON(libPath).c_str(), f); - fclose(f); + FileIO::fclose(f); } else { diff --git a/renderdoc/os/os_specific.cpp b/renderdoc/os/os_specific.cpp index 08f7ef0a9..885ceb91e 100644 --- a/renderdoc/os/os_specific.cpp +++ b/renderdoc/os/os_specific.cpp @@ -29,6 +29,38 @@ int utf8printv(char *buf, size_t bufsize, const char *fmt, va_list args); +bool Network::ParseIPRangeCIDR(const rdcstr &str, uint32_t &ip, uint32_t &mask) +{ + uint32_t a = 0, b = 0, c = 0, d = 0, num = 0; + +#if ENABLED(RDOC_WIN32) + int ret = sscanf_s(str.c_str(), "%u.%u.%u.%u/%u", &a, &b, &c, &d, &num); +#else + int ret = sscanf(str.c_str(), "%u.%u.%u.%u/%u", &a, &b, &c, &d, &num); +#endif + + if(ret != 5 || a > 255 || b > 255 || c > 255 || d > 255 || num > 32) + { + ip = 0; + mask = 0; + return false; + } + + ip = MakeIP(a, b, c, d); + + if(num == 0) + { + mask = 0; + } + else + { + num = 32 - num; + mask = ((~0U) >> num) << num; + } + + return true; +} + namespace StringFormat { rdcstr Fmt(const char *format, ...) @@ -53,13 +85,13 @@ rdcstr Fmt(const char *format, ...) }; // namespace StringFormat -rdcstr Callstack::AddressDetails::formattedString(const char *commonPath) +rdcstr Callstack::AddressDetails::formattedString(const rdcstr &commonPath) { const char *f = filename.c_str(); - if(commonPath) + if(!commonPath.empty()) { - rdcstr common = strlower(rdcstr(commonPath)); + rdcstr common = strlower(commonPath); rdcstr fn = strlower(filename.substr(0, common.length())); if(common == fn) @@ -129,20 +161,16 @@ TEST_CASE("Test OS-specific functions", "[osspecific]") } SECTION("Environment Variables") { - const char *var = Process::GetEnvVariable("TMP"); + rdcstr var = Process::GetEnvVariable("TMP"); + var = Process::GetEnvVariable("TEMP"); + var = Process::GetEnvVariable("HOME"); - if(!var) - var = Process::GetEnvVariable("TEMP"); - - if(!var) - var = Process::GetEnvVariable("HOME"); - - CHECK(var); - CHECK(strlen(var) > 1); + CHECK(!var.empty()); + CHECK(var.length() > 1); var = Process::GetEnvVariable("__renderdoc__unit_test_var"); - CHECK_FALSE(var); + CHECK(var.empty()); EnvironmentModification mod; mod.name = "__renderdoc__unit_test_var"; @@ -155,15 +183,13 @@ TEST_CASE("Test OS-specific functions", "[osspecific]") var = Process::GetEnvVariable("__renderdoc__unit_test_var"); - CHECK(var); - CHECK(var == rdcstr("test_value")); + CHECK(var == "test_value"); Process::RegisterEnvironmentModification(mod); Process::ApplyEnvironmentModification(); var = Process::GetEnvVariable("__renderdoc__unit_test_var"); - CHECK(var); CHECK(var == rdcstr("test_value;test_value")); mod.sep = EnvSep::Colon; @@ -173,7 +199,6 @@ TEST_CASE("Test OS-specific functions", "[osspecific]") var = Process::GetEnvVariable("__renderdoc__unit_test_var"); - CHECK(var); CHECK(var == rdcstr("test_value;test_value:test_value")); mod.value = "prepend"; @@ -185,7 +210,6 @@ TEST_CASE("Test OS-specific functions", "[osspecific]") var = Process::GetEnvVariable("__renderdoc__unit_test_var"); - CHECK(var); CHECK(var == rdcstr("prepend;test_value;test_value:test_value")); mod.value = "reset"; @@ -197,7 +221,6 @@ TEST_CASE("Test OS-specific functions", "[osspecific]") var = Process::GetEnvVariable("__renderdoc__unit_test_var"); - CHECK(var); CHECK(var == rdcstr("reset")); }; diff --git a/renderdoc/os/os_specific.h b/renderdoc/os/os_specific.h index 4d3f95fa5..c9a003ad6 100644 --- a/renderdoc/os/os_specific.h +++ b/renderdoc/os/os_specific.h @@ -54,35 +54,35 @@ void RegisterEnvironmentModification(const EnvironmentModification &modif); void ApplyEnvironmentModification(); -const char *GetEnvVariable(const char *name); +rdcstr GetEnvVariable(const rdcstr &name); uint64_t GetMemoryUsage(); bool CanGlobalHook(); -bool StartGlobalHook(const char *pathmatch, const char *capturefile, const CaptureOptions &opts); +bool StartGlobalHook(const rdcstr &pathmatch, const rdcstr &capturefile, const CaptureOptions &opts); bool IsGlobalHookActive(); void StopGlobalHook(); rdcpair InjectIntoProcess(uint32_t pid, const rdcarray &env, - const char *capturefile, + const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit); struct ProcessResult { rdcstr strStdout, strStderror; int retCode; }; -uint32_t LaunchProcess(const char *app, const char *workingDir, const char *cmdLine, bool internal, - ProcessResult *result = NULL); -uint32_t LaunchScript(const char *script, const char *workingDir, const char *args, bool internal, - ProcessResult *result = NULL); +uint32_t LaunchProcess(const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, + bool internal, ProcessResult *result = NULL); +uint32_t LaunchScript(const rdcstr &script, const rdcstr &workingDir, const rdcstr &args, + bool internal, ProcessResult *result = NULL); rdcpair LaunchAndInjectIntoProcess( - const char *app, const char *workingDir, const char *cmdLine, - const rdcarray &env, const char *capturefile, + const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, + const rdcarray &env, const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit); -bool IsModuleLoaded(const char *module); -void *LoadModule(const char *module); -void *GetFunctionAddress(void *module, const char *function); +bool IsModuleLoaded(const rdcstr &module); +void *LoadModule(const rdcstr &module); +void *GetFunctionAddress(void *module, const rdcstr &function); uint32_t GetCurrentPID(); void Shutdown(); @@ -190,8 +190,8 @@ private: uint32_t timeoutMS; }; -Socket *CreateServerSocket(const char *addr, uint16_t port, int queuesize); -Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS); +Socket *CreateServerSocket(const rdcstr &addr, uint16_t port, int queuesize); +Socket *CreateClientSocket(const rdcstr &host, uint16_t port, int timeoutMS); // ip is packed in HOST byte order inline uint32_t GetIPOctet(uint32_t ip, uint32_t octet) @@ -216,7 +216,7 @@ inline bool MatchIPMask(uint32_t ip, uint32_t range, uint32_t mask) // parses the null-terminated string at 'str' for CIDR notation IP range // aaa.bbb.ccc.ddd/nn -bool ParseIPRangeCIDR(const char *str, uint32_t &ip, uint32_t &mask); +bool ParseIPRangeCIDR(const rdcstr &str, uint32_t &ip, uint32_t &mask); void Init(); void Shutdown(); @@ -251,7 +251,7 @@ struct AddressDetails rdcstr filename; uint32_t line; - rdcstr formattedString(const char *commonPath = NULL); + rdcstr formattedString(const rdcstr &commonPath = rdcstr()); }; class StackResolver @@ -274,7 +274,7 @@ bool GetLoadedModules(byte *buf, size_t &size); namespace FileIO { -void GetDefaultFiles(const char *logBaseName, rdcstr &capture_filename, rdcstr &logging_filename, +void GetDefaultFiles(const rdcstr &logBaseName, rdcstr &capture_filename, rdcstr &logging_filename, rdcstr &target); rdcstr GetHomeFolderFilename(); rdcstr GetAppFolderFilename(const rdcstr &filename); @@ -293,17 +293,26 @@ void GetLibraryFilename(rdcstr &selfName); uint64_t GetModifiedTimestamp(const rdcstr &filename); uint64_t GetFileSize(const rdcstr &filename); -bool Copy(const char *from, const char *to, bool allowOverwrite); -bool Move(const char *from, const char *to, bool allowOverwrite); -void Delete(const char *path); -void GetFilesInDirectory(const char *path, rdcarray &entries); +bool Copy(const rdcstr &from, const rdcstr &to, bool allowOverwrite); +bool Move(const rdcstr &from, const rdcstr &to, bool allowOverwrite); +void Delete(const rdcstr &path); +void GetFilesInDirectory(const rdcstr &path, rdcarray &entries); -FILE *fopen(const char *filename, const char *mode); +enum FileMode +{ + ReadText, + ReadBinary, + WriteText, + WriteBinary, + UpdateBinary, + OverwriteBinary, +}; +FILE *fopen(const rdcstr &filename, FileMode mode); size_t fread(void *buf, size_t elementSize, size_t count, FILE *f); size_t fwrite(const void *buf, size_t elementSize, size_t count, FILE *f); -bool exists(const char *filename); +bool exists(const rdcstr &filename); rdcstr ErrorString(); @@ -321,19 +330,19 @@ int fclose(FILE *f); // functions for atomically appending to a log that may be in use in multiple // processes struct LogFileHandle; -LogFileHandle *logfile_open(const char *filename); +LogFileHandle *logfile_open(const rdcstr &filename); void logfile_append(LogFileHandle *logHandle, const char *msg, size_t length); -void logfile_close(LogFileHandle *logHandle, const char *deleteFilename); +void logfile_close(LogFileHandle *logHandle, const rdcstr &deleteFilename); // read the whole logfile into memory starting at a given offset. This may race with processes // writing, but it will read the whole of the file at some point. Useful since normal file reading // may fail on the shared logfile -rdcstr logfile_readall(uint64_t offset, const char *filename); +rdcstr logfile_readall(uint64_t offset, const rdcstr &filename); // utility functions inline bool WriteAll(const rdcstr &filename, const void *buffer, size_t size) { - FILE *f = FileIO::fopen(filename.c_str(), "wb"); + FILE *f = FileIO::fopen(filename, FileIO::WriteBinary); if(f == NULL) return false; @@ -358,7 +367,7 @@ inline bool WriteAll(const rdcstr &filename, const rdcstr &buffer) template bool ReadAll(const rdcstr &filename, rdcarray &buffer) { - FILE *f = FileIO::fopen(filename.c_str(), "rb"); + FILE *f = FileIO::fopen(filename, FileIO::ReadBinary); if(f == NULL) return false; @@ -377,7 +386,7 @@ bool ReadAll(const rdcstr &filename, rdcarray &buffer) inline bool ReadAll(const rdcstr &filename, rdcstr &str) { - FILE *f = FileIO::fopen(filename.c_str(), "rb"); + FILE *f = FileIO::fopen(filename, FileIO::ReadBinary); if(f == NULL) return false; diff --git a/renderdoc/os/posix/android/android_hook.cpp b/renderdoc/os/posix/android/android_hook.cpp index 542e76768..a8b213f58 100644 --- a/renderdoc/os/posix/android/android_hook.cpp +++ b/renderdoc/os/posix/android/android_hook.cpp @@ -292,7 +292,7 @@ static int dl_iterate_callback(struct dl_phdr_info *info, size_t size, void *dat void **relro_end = NULL; bool relro_failed = false; - FILE *f = FileIO::fopen(info->dlpi_name, "r"); + FILE *f = FileIO::fopen(info->dlpi_name, FileIO::ReadText); // read the file on disk to get the .relro section if(f) @@ -735,7 +735,7 @@ void LibraryHooks::EndHookRegistration() { rdcstr selfLib; FileIO::GetLibraryFilename(selfLib); - if(FileIO::exists(selfLib.c_str())) + if(FileIO::exists(selfLib)) { void *handle = dlopen(selfLib.c_str(), RTLD_NOW | RTLD_NOLOAD | RTLD_LOCAL); if(handle) diff --git a/renderdoc/os/posix/android/android_network.cpp b/renderdoc/os/posix/android/android_network.cpp index 1207c2b7c..b5c8426b7 100644 --- a/renderdoc/os/posix/android/android_network.cpp +++ b/renderdoc/os/posix/android/android_network.cpp @@ -49,7 +49,7 @@ uint32_t Socket::GetRemoteIP() const return MakeIP(127, 0, 0, 1); } -Socket *CreateServerSocket(const char * /* bindaddr */, uint16_t port, int queuesize) +Socket *CreateServerSocket(const rdcstr &, uint16_t port, int queuesize) { return CreateAbstractServerSocket(port, queuesize); } diff --git a/renderdoc/os/posix/android/android_process.cpp b/renderdoc/os/posix/android/android_process.cpp index 9114528f6..8c1862a2c 100644 --- a/renderdoc/os/posix/android/android_process.cpp +++ b/renderdoc/os/posix/android/android_process.cpp @@ -47,7 +47,7 @@ int GetIdentPort(pid_t childPid) // back-off for each retry usleep(1000 + 500 * retry); - FILE *f = FileIO::fopen(procfile.c_str(), "r"); + FILE *f = FileIO::fopen(procfile, FileIO::ReadText); if(f == NULL) { @@ -119,7 +119,7 @@ bool debuggerPresent = false; void CacheDebuggerPresent() { - FILE *f = FileIO::fopen("/proc/self/status", "r"); + FILE *f = FileIO::fopen("/proc/self/status", FileIO::ReadText); int ret = 0; if(f == NULL) @@ -155,27 +155,27 @@ bool OSUtility::DebuggerPresent() return debuggerPresent; } -const char *Process::GetEnvVariable(const char *name) +rdcstr Process::GetEnvVariable(const rdcstr &name) { // we fake environment variables with properties Process::ProcessResult result; Process::LaunchProcess("getprop", ".", - StringFormat::Fmt("debug.rdoc.%s variable_is_not_set", name).c_str(), true, + StringFormat::Fmt("debug.rdoc.%s variable_is_not_set", name.c_str()), true, &result); - static rdcstr settingsOutput; + rdcstr settingsOutput; settingsOutput = result.strStdout.trimmed(); if(settingsOutput == "variable_is_not_set") - return NULL; + return rdcstr(); - return settingsOutput.c_str(); + return settingsOutput; } uint64_t Process::GetMemoryUsage() { - FILE *f = FileIO::fopen("/proc/self/statm", "r"); + FILE *f = FileIO::fopen("/proc/self/statm", FileIO::ReadText); if(f == NULL) { diff --git a/renderdoc/os/posix/android/android_stringio.cpp b/renderdoc/os/posix/android/android_stringio.cpp index 253f13c48..270f656b7 100644 --- a/renderdoc/os/posix/android/android_stringio.cpp +++ b/renderdoc/os/posix/android/android_stringio.cpp @@ -116,7 +116,7 @@ void GetLibraryFilename(rdcstr &selfName) rdcstr librenderdoc_path; - FILE *f = fopen("/proc/self/maps", "r"); + FILE *f = fopen("/proc/self/maps", FileIO::ReadText); if(f) { diff --git a/renderdoc/os/posix/apple/apple_network.cpp b/renderdoc/os/posix/apple/apple_network.cpp index 7f7c6dff9..e3c9b967b 100644 --- a/renderdoc/os/posix/apple/apple_network.cpp +++ b/renderdoc/os/posix/apple/apple_network.cpp @@ -37,7 +37,7 @@ uint32_t Socket::GetRemoteIP() const return GetIPFromTCPSocket((int)socket); } -Socket *CreateServerSocket(const char *bindaddr, uint16_t port, int queuesize) +Socket *CreateServerSocket(const rdcstr &bindaddr, uint16_t port, int queuesize) { return CreateTCPServerSocket(bindaddr, port, queuesize); } diff --git a/renderdoc/os/posix/apple/apple_process.cpp b/renderdoc/os/posix/apple/apple_process.cpp index 65c50783d..ef3492719 100644 --- a/renderdoc/os/posix/apple/apple_process.cpp +++ b/renderdoc/os/posix/apple/apple_process.cpp @@ -38,7 +38,7 @@ char **GetCurrentEnvironment() rdcstr execcmd(const char *cmd) { - FILE *pipe = popen(cmd, "r"); + FILE *pipe = popen(cmd, FileIO::ReadText); if(!pipe) return "ERROR"; @@ -181,9 +181,9 @@ bool OSUtility::DebuggerPresent() #endif } -const char *Process::GetEnvVariable(const char *name) +rdcstr Process::GetEnvVariable(const rdcstr &name) { - return getenv(name); + return getenv(name.c_str()); } uint64_t Process::GetMemoryUsage() diff --git a/renderdoc/os/posix/ggp/ggp_callstack.cpp b/renderdoc/os/posix/ggp/ggp_callstack.cpp index ae23120b7..4f4923181 100644 --- a/renderdoc/os/posix/ggp/ggp_callstack.cpp +++ b/renderdoc/os/posix/ggp/ggp_callstack.cpp @@ -84,7 +84,7 @@ namespace Callstack void Init() { // look for our own line - FILE *f = FileIO::fopen("/proc/self/maps", "r"); + FILE *f = FileIO::fopen("/proc/self/maps", FileIO::ReadText); if(f) { @@ -119,7 +119,7 @@ bool GetLoadedModules(byte *buf, size_t &size) { // we just dump the whole file rather than pre-parsing, that way we can improve // parsing without needing to recapture - FILE *f = FileIO::fopen("/proc/self/maps", "r"); + FILE *f = FileIO::fopen("/proc/self/maps", FileIO::ReadText); size = 0; @@ -181,7 +181,7 @@ private: uint64_t relative = addr - m_Modules[i].base + m_Modules[i].offset; rdcstr cmd = StringFormat::Fmt("addr2line -fCe \"%s\" 0x%llx", m_Modules[i].path, relative); - FILE *f = ::popen(cmd.c_str(), "r"); + FILE *f = ::popen(cmd.c_str(), FileIO::ReadText); char result[2048] = {0}; fread(result, 1, 2047, f); diff --git a/renderdoc/os/posix/ggp/ggp_network.cpp b/renderdoc/os/posix/ggp/ggp_network.cpp index 7f7c6dff9..e3c9b967b 100644 --- a/renderdoc/os/posix/ggp/ggp_network.cpp +++ b/renderdoc/os/posix/ggp/ggp_network.cpp @@ -37,7 +37,7 @@ uint32_t Socket::GetRemoteIP() const return GetIPFromTCPSocket((int)socket); } -Socket *CreateServerSocket(const char *bindaddr, uint16_t port, int queuesize) +Socket *CreateServerSocket(const rdcstr &bindaddr, uint16_t port, int queuesize) { return CreateTCPServerSocket(bindaddr, port, queuesize); } diff --git a/renderdoc/os/posix/ggp/ggp_process.cpp b/renderdoc/os/posix/ggp/ggp_process.cpp index b1110ed39..8e9204640 100644 --- a/renderdoc/os/posix/ggp/ggp_process.cpp +++ b/renderdoc/os/posix/ggp/ggp_process.cpp @@ -46,7 +46,7 @@ rdcarray getSockets(pid_t childPid) rdcarray sockets; rdcstr dirPath = StringFormat::Fmt("/proc/%d/fd", (int)childPid); rdcarray files; - FileIO::GetFilesInDirectory(dirPath.c_str(), files); + FileIO::GetFilesInDirectory(dirPath, files); if(files.empty()) return sockets; @@ -83,7 +83,7 @@ int GetIdentPort(pid_t childPid) waitTime *= 2; - FILE *f = FileIO::fopen(procfile.c_str(), "r"); + FILE *f = FileIO::fopen(procfile, FileIO::ReadText); if(f == NULL) { @@ -126,7 +126,7 @@ int GetIdentPort(pid_t childPid) (uint32_t)RenderDoc_FirstTargetControlPort, (uint32_t)RenderDoc_LastTargetControlPort, procfile.c_str()); - if(!FileIO::exists(procfile.c_str())) + if(!FileIO::exists(procfile)) { RDCWARN("Process %u is no longer running - did it exit during initialisation or fail to run?", childPid); @@ -157,7 +157,7 @@ bool debuggerPresent = false; void CacheDebuggerPresent() { - FILE *f = FileIO::fopen("/proc/self/status", "r"); + FILE *f = FileIO::fopen("/proc/self/status", FileIO::ReadText); if(f == NULL) { @@ -192,14 +192,14 @@ bool OSUtility::DebuggerPresent() return debuggerPresent; } -const char *Process::GetEnvVariable(const char *name) +rdcstr Process::GetEnvVariable(const rdcstr &name) { - return getenv(name); + return getenv(name.c_str()); } uint64_t Process::GetMemoryUsage() { - FILE *f = FileIO::fopen("/proc/self/statm", "r"); + FILE *f = FileIO::fopen("/proc/self/statm", FileIO::ReadText); if(f == NULL) { diff --git a/renderdoc/os/posix/ggp/ggp_stringio.cpp b/renderdoc/os/posix/ggp/ggp_stringio.cpp index a9411adb0..2b0e8f7cb 100644 --- a/renderdoc/os/posix/ggp/ggp_stringio.cpp +++ b/renderdoc/os/posix/ggp/ggp_stringio.cpp @@ -109,7 +109,7 @@ void GetLibraryFilename(rdcstr &selfName) rdcstr librenderdoc_path; - FILE *f = fopen("/proc/self/maps", "r"); + FILE *f = fopen("/proc/self/maps", FileIO::ReadText); if(f) { diff --git a/renderdoc/os/posix/linux/linux_callstack.cpp b/renderdoc/os/posix/linux/linux_callstack.cpp index 485bb1edc..4ec3a7433 100644 --- a/renderdoc/os/posix/linux/linux_callstack.cpp +++ b/renderdoc/os/posix/linux/linux_callstack.cpp @@ -94,7 +94,7 @@ namespace Callstack void Init() { // look for our own line - FILE *f = FileIO::fopen("/proc/self/maps", "r"); + FILE *f = FileIO::fopen("/proc/self/maps", FileIO::ReadText); if(f) { diff --git a/renderdoc/os/posix/linux/linux_network.cpp b/renderdoc/os/posix/linux/linux_network.cpp index 7f7c6dff9..e3c9b967b 100644 --- a/renderdoc/os/posix/linux/linux_network.cpp +++ b/renderdoc/os/posix/linux/linux_network.cpp @@ -37,7 +37,7 @@ uint32_t Socket::GetRemoteIP() const return GetIPFromTCPSocket((int)socket); } -Socket *CreateServerSocket(const char *bindaddr, uint16_t port, int queuesize) +Socket *CreateServerSocket(const rdcstr &bindaddr, uint16_t port, int queuesize) { return CreateTCPServerSocket(bindaddr, port, queuesize); } diff --git a/renderdoc/os/posix/linux/linux_process.cpp b/renderdoc/os/posix/linux/linux_process.cpp index 2ffb25103..981664108 100644 --- a/renderdoc/os/posix/linux/linux_process.cpp +++ b/renderdoc/os/posix/linux/linux_process.cpp @@ -61,7 +61,7 @@ rdcarray getSockets(pid_t childPid) rdcarray sockets; rdcstr dirPath = StringFormat::Fmt("/proc/%d/fd", (int)childPid); rdcarray files; - FileIO::GetFilesInDirectory(dirPath.c_str(), files); + FileIO::GetFilesInDirectory(dirPath, files); if(files.empty()) return sockets; @@ -98,7 +98,7 @@ int GetIdentPort(pid_t childPid) waitTime *= 2; - FILE *f = FileIO::fopen(procfile.c_str(), "r"); + FILE *f = FileIO::fopen(procfile, FileIO::ReadText); if(f == NULL) { @@ -141,7 +141,7 @@ int GetIdentPort(pid_t childPid) (uint32_t)RenderDoc_FirstTargetControlPort, (uint32_t)RenderDoc_LastTargetControlPort, procfile.c_str()); - if(!FileIO::exists(procfile.c_str())) + if(!FileIO::exists(procfile)) { RDCWARN("Process %u is no longer running - did it exit during initialisation or fail to run?", childPid); @@ -349,7 +349,7 @@ bool StopChildAtMain(pid_t childPid) rdcstr mapsName = StringFormat::Fmt("/proc/%u/maps", childPid); - FILE *maps = FileIO::fopen(mapsName.c_str(), "r"); + FILE *maps = FileIO::fopen(mapsName, FileIO::ReadText); if(!maps) { @@ -394,7 +394,7 @@ bool StopChildAtMain(pid_t childPid) FileIO::fclose(maps); - FILE *elf = FileIO::fopen(exepath.c_str(), "r"); + FILE *elf = FileIO::fopen(exepath, FileIO::ReadText); if(!elf) { @@ -621,7 +621,7 @@ bool debuggerPresent = false; void CacheDebuggerPresent() { - FILE *f = FileIO::fopen("/proc/self/status", "r"); + FILE *f = FileIO::fopen("/proc/self/status", FileIO::ReadText); if(f == NULL) { @@ -656,14 +656,14 @@ bool OSUtility::DebuggerPresent() return debuggerPresent; } -const char *Process::GetEnvVariable(const char *name) +rdcstr Process::GetEnvVariable(const rdcstr &name) { - return getenv(name); + return getenv(name.c_str()); } uint64_t Process::GetMemoryUsage() { - FILE *f = FileIO::fopen("/proc/self/statm", "r"); + FILE *f = FileIO::fopen("/proc/self/statm", FileIO::ReadText); if(f == NULL) { diff --git a/renderdoc/os/posix/linux/linux_stringio.cpp b/renderdoc/os/posix/linux/linux_stringio.cpp index b5102d678..b1558d6a0 100644 --- a/renderdoc/os/posix/linux/linux_stringio.cpp +++ b/renderdoc/os/posix/linux/linux_stringio.cpp @@ -622,7 +622,7 @@ void GetLibraryFilename(rdcstr &selfName) rdcstr librenderdoc_path; - FILE *f = fopen("/proc/self/maps", "r"); + FILE *f = fopen("/proc/self/maps", FileIO::ReadText); if(f) { diff --git a/renderdoc/os/posix/posix_libentry.cpp b/renderdoc/os/posix/posix_libentry.cpp index 4b5b9f733..f04b38858 100644 --- a/renderdoc/os/posix/posix_libentry.cpp +++ b/renderdoc/os/posix/posix_libentry.cpp @@ -45,10 +45,10 @@ void library_loaded() { RenderDoc::Inst().Initialise(); - const char *capturefile = Process::GetEnvVariable("RENDERDOC_CAPFILE"); - const char *opts = Process::GetEnvVariable("RENDERDOC_CAPOPTS"); + rdcstr capturefile = Process::GetEnvVariable("RENDERDOC_CAPFILE"); + rdcstr opts = Process::GetEnvVariable("RENDERDOC_CAPOPTS"); - if(opts) + if(!opts.empty()) { CaptureOptions optstruct; optstruct.DecodeFromString(opts); @@ -58,7 +58,7 @@ void library_loaded() RenderDoc::Inst().SetCaptureOptions(optstruct); } - if(capturefile) + if(!capturefile.empty()) { RenderDoc::Inst().SetCaptureFileTemplate(capturefile); } diff --git a/renderdoc/os/posix/posix_network.cpp b/renderdoc/os/posix/posix_network.cpp index 34fcc2e10..928b92dfe 100644 --- a/renderdoc/os/posix/posix_network.cpp +++ b/renderdoc/os/posix/posix_network.cpp @@ -348,7 +348,7 @@ uint32_t GetIPFromTCPSocket(int socket) return ntohl(addr.sin_addr.s_addr); } -Socket *CreateTCPServerSocket(const char *bindaddr, uint16_t port, int queuesize) +Socket *CreateTCPServerSocket(const rdcstr &bindaddr, uint16_t port, int queuesize) { int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -361,7 +361,7 @@ Socket *CreateTCPServerSocket(const char *bindaddr, uint16_t port, int queuesize sockaddr_in addr; RDCEraseEl(addr); - hostent *hp = gethostbyname(bindaddr); + hostent *hp = gethostbyname(bindaddr.c_str()); addr.sin_family = AF_INET; memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); @@ -370,7 +370,7 @@ Socket *CreateTCPServerSocket(const char *bindaddr, uint16_t port, int queuesize int result = bind(s, (sockaddr *)&addr, sizeof(addr)); if(result == -1) { - RDCWARN("Failed to bind to %s:%d - %d", bindaddr, port, errno); + RDCWARN("Failed to bind to %s:%d - %d", bindaddr.c_str(), port, errno); close(s); return NULL; } @@ -378,7 +378,7 @@ Socket *CreateTCPServerSocket(const char *bindaddr, uint16_t port, int queuesize result = listen(s, queuesize); if(result == -1) { - RDCWARN("Failed to listen on %s:%d - %d", bindaddr, port, errno); + RDCWARN("Failed to listen on %s:%d - %d", bindaddr.c_str(), port, errno); close(s); return NULL; } @@ -438,7 +438,7 @@ Socket *CreateAbstractServerSocket(uint16_t port, int queuesize) return new Socket((ptrdiff_t)s); } -Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) +Socket *CreateClientSocket(const rdcstr &host, uint16_t port, int timeoutMS) { addrinfo hints; RDCEraseEl(hints); @@ -447,7 +447,7 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) hints.ai_protocol = IPPROTO_TCP; addrinfo *addrResult = NULL; - int res = getaddrinfo(host, ToStr(port).c_str(), &hints, &addrResult); + int res = getaddrinfo(host.c_str(), ToStr(port).c_str(), &hints, &addrResult); if(res != 0) { RDCDEBUG("%s", gai_strerror(res)); @@ -514,35 +514,7 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) freeaddrinfo(addrResult); - RDCDEBUG("Failed to connect to %s:%d", host, port); + RDCDEBUG("Failed to connect to %s:%d", host.c_str(), port); return NULL; } - -bool ParseIPRangeCIDR(const char *str, uint32_t &ip, uint32_t &mask) -{ - uint32_t a = 0, b = 0, c = 0, d = 0, num = 0; - - int ret = sscanf(str, "%u.%u.%u.%u/%u", &a, &b, &c, &d, &num); - - if(ret != 5 || a > 255 || b > 255 || c > 255 || d > 255 || num > 32) - { - ip = 0; - mask = 0; - return false; - } - - ip = MakeIP(a, b, c, d); - - if(num == 0) - { - mask = 0; - } - else - { - num = 32 - num; - mask = ((~0U) >> num) << num; - } - - return true; -} }; diff --git a/renderdoc/os/posix/posix_network.h b/renderdoc/os/posix/posix_network.h index 5978dabb6..7d95970b8 100644 --- a/renderdoc/os/posix/posix_network.h +++ b/renderdoc/os/posix/posix_network.h @@ -28,5 +28,5 @@ namespace Network { uint32_t GetIPFromTCPSocket(int socket); Socket *CreateAbstractServerSocket(uint16_t port, int queuesize); -Socket *CreateTCPServerSocket(const char *bindaddr, uint16_t port, int queuesize); +Socket *CreateTCPServerSocket(const rdcstr &bindaddr, uint16_t port, int queuesize); } diff --git a/renderdoc/os/posix/posix_process.cpp b/renderdoc/os/posix/posix_process.cpp index 31985623f..2fb62d711 100644 --- a/renderdoc/os/posix/posix_process.cpp +++ b/renderdoc/os/posix/posix_process.cpp @@ -415,15 +415,15 @@ static void CleanupStringArray(char **arr) delete[] arr_delete; } -static rdcarray ParseCommandLine(const rdcstr &appName, const char *cmdLine) +static rdcarray ParseCommandLine(const rdcstr &appName, const rdcstr &cmdLine) { // argv[0] is the application name, by convention rdcarray argv = {appName}; - const char *c = cmdLine; + const char *c = cmdLine.c_str(); // parse command line into argv[], similar to how bash would - if(cmdLine) + if(!cmdLine.empty()) { rdcstr a; bool haveArg = false; @@ -479,7 +479,7 @@ static rdcarray ParseCommandLine(const rdcstr &appName, const char *cmdL } else { - RDCERR("Malformed command line:\n%s", cmdLine); + RDCERR("Malformed command line:\n%s", cmdLine.c_str()); return {}; } } @@ -504,7 +504,7 @@ static rdcarray ParseCommandLine(const rdcstr &appName, const char *cmdL if(squot || dquot) { - RDCERR("Malformed command line\n%s", cmdLine); + RDCERR("Malformed command line\n%s", cmdLine.c_str()); return {}; } } @@ -512,14 +512,14 @@ static rdcarray ParseCommandLine(const rdcstr &appName, const char *cmdL return argv; } -static pid_t RunProcess(const char *app, const char *workingDir, const char *cmdLine, char **envp, +static pid_t RunProcess(rdcstr appName, rdcstr workDir, const rdcstr &cmdLine, char **envp, bool pauseAtMain, int stdoutPipe[2] = NULL, int stderrPipe[2] = NULL) { - if(!app) + if(appName.empty()) return (pid_t)0; - rdcstr appName = app; - rdcstr workDir = (workingDir && workingDir[0]) ? workingDir : get_dirname(appName); + if(workDir.empty()) + workDir = get_dirname(appName); // handle funky apple .app folders that aren't actually executables #if ENABLED(RDOC_APPLE) @@ -528,7 +528,7 @@ static pid_t RunProcess(const char *app, const char *workingDir, const char *cmd rdcstr realAppName = appName + "/Contents/MacOS/" + get_basename(appName); realAppName.erase(realAppName.size() - 4, ~0U); - if(FileIO::exists(realAppName.c_str())) + if(FileIO::exists(realAppName)) { RDCLOG("Running '%s' the actual executable for '%s'", realAppName.c_str(), appName.c_str()); appName = realAppName; @@ -626,17 +626,17 @@ static pid_t RunProcess(const char *app, const char *workingDir, const char *cmd } rdcpair Process::InjectIntoProcess( - uint32_t pid, const rdcarray &env, const char *logfile, + uint32_t pid, const rdcarray &env, const rdcstr &logfile, const CaptureOptions &opts, bool waitForExit) { RDCUNIMPLEMENTED("Injecting into already running processes on linux"); return {ReplayStatus::InjectionFailed, 0}; } -uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const char *cmdLine, +uint32_t Process::LaunchProcess(const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, bool internal, ProcessResult *result) { - if(app == NULL || app[0] == 0) + if(app.empty()) { RDCERR("Invalid empty 'app'"); return 0; @@ -703,21 +703,21 @@ uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const c return (uint32_t)ret; } -uint32_t Process::LaunchScript(const char *script, const char *workingDir, const char *argList, - bool internal, ProcessResult *result) +uint32_t Process::LaunchScript(const rdcstr &script, const rdcstr &workingDir, + const rdcstr &argList, bool internal, ProcessResult *result) { // Change parameters to invoke command interpreter - rdcstr args = "-lc \"" + rdcstr(script) + " " + rdcstr(argList) + "\""; + rdcstr args = "-lc \"" + script + " " + argList + "\""; - return LaunchProcess("bash", workingDir, args.c_str(), internal, result); + return LaunchProcess("bash", workingDir, args, internal, result); } rdcpair Process::LaunchAndInjectIntoProcess( - const char *app, const char *workingDir, const char *cmdLine, - const rdcarray &envList, const char *capturefile, + const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, + const rdcarray &envList, const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit) { - if(app == NULL || app[0] == 0) + if(app.empty()) { RDCERR("Invalid empty 'app'"); return {ReplayStatus::InternalError, 0}; @@ -731,9 +731,6 @@ rdcpair Process::LaunchAndInjectIntoProcess( for(const EnvironmentModification &e : envList) modifications.push_back(e); - if(capturefile == NULL) - capturefile = ""; - rdcstr binpath, libpath, ownlibpath; { FileIO::GetExecutableFilename(binpath); @@ -763,17 +760,17 @@ rdcpair Process::LaunchAndInjectIntoProcess( rdcstr optstr = opts.EncodeAsString(); modifications.push_back( - EnvironmentModification(EnvMod::Append, EnvSep::Platform, LIB_PATH_ENV_VAR, binpath.c_str())); + EnvironmentModification(EnvMod::Append, EnvSep::Platform, LIB_PATH_ENV_VAR, binpath)); modifications.push_back( - EnvironmentModification(EnvMod::Append, EnvSep::Platform, LIB_PATH_ENV_VAR, libpath.c_str())); - modifications.push_back(EnvironmentModification(EnvMod::Append, EnvSep::Platform, - LIB_PATH_ENV_VAR, ownlibpath.c_str())); + EnvironmentModification(EnvMod::Append, EnvSep::Platform, LIB_PATH_ENV_VAR, libpath)); modifications.push_back( - EnvironmentModification(EnvMod::Append, EnvSep::Platform, PRELOAD_ENV_VAR, libfile.c_str())); + EnvironmentModification(EnvMod::Append, EnvSep::Platform, LIB_PATH_ENV_VAR, ownlibpath)); + modifications.push_back( + EnvironmentModification(EnvMod::Append, EnvSep::Platform, PRELOAD_ENV_VAR, libfile)); modifications.push_back( EnvironmentModification(EnvMod::Set, EnvSep::NoSep, "RENDERDOC_CAPFILE", capturefile)); modifications.push_back( - EnvironmentModification(EnvMod::Set, EnvSep::NoSep, "RENDERDOC_CAPOPTS", optstr.c_str())); + EnvironmentModification(EnvMod::Set, EnvSep::NoSep, "RENDERDOC_CAPOPTS", optstr)); modifications.push_back(EnvironmentModification(EnvMod::Set, EnvSep::NoSep, "RENDERDOC_DEBUG_LOG_FILE", RDCGETLOGFILE())); @@ -828,7 +825,7 @@ rdcpair Process::LaunchAndInjectIntoProcess( i++; } - RDCLOG("Running process %s for injection", app); + RDCLOG("Running process %s for injection", app.c_str()); pid_t childPid = RunProcess(app, workingDir, cmdLine, envp, true); @@ -853,7 +850,8 @@ rdcpair Process::LaunchAndInjectIntoProcess( return {ret == 0 ? ReplayStatus::InjectionFailed : ReplayStatus::Succeeded, (uint32_t)ret}; } -bool Process::StartGlobalHook(const char *pathmatch, const char *logfile, const CaptureOptions &opts) +bool Process::StartGlobalHook(const rdcstr &pathmatch, const rdcstr &logfile, + const CaptureOptions &opts) { RDCUNIMPLEMENTED("Global hooking of all processes on linux"); return false; @@ -873,22 +871,22 @@ void Process::StopGlobalHook() { } -bool Process::IsModuleLoaded(const char *module) +bool Process::IsModuleLoaded(const rdcstr &module) { - return dlopen(module, RTLD_NOW | RTLD_NOLOAD) != NULL; + return dlopen(module.c_str(), RTLD_NOW | RTLD_NOLOAD) != NULL; } -void *Process::LoadModule(const char *module) +void *Process::LoadModule(const rdcstr &module) { - return dlopen(module, RTLD_NOW); + return dlopen(module.c_str(), RTLD_NOW); } -void *Process::GetFunctionAddress(void *module, const char *function) +void *Process::GetFunctionAddress(void *module, const rdcstr &function) { if(module == NULL) return NULL; - return dlsym(module, function); + return dlsym(module, function.c_str()); } uint32_t Process::GetCurrentPID() diff --git a/renderdoc/os/posix/posix_specific.h b/renderdoc/os/posix/posix_specific.h index 4a3ecff1f..ed10026b6 100644 --- a/renderdoc/os/posix/posix_specific.h +++ b/renderdoc/os/posix/posix_specific.h @@ -87,7 +87,6 @@ inline void DebugBreak() raise(SIGTRAP); } bool DebuggerPresent(); -void WriteOutput(int channel, const char *str); }; namespace Threading diff --git a/renderdoc/os/posix/posix_stringio.cpp b/renderdoc/os/posix/posix_stringio.cpp index 6441c211a..637fd1237 100644 --- a/renderdoc/os/posix/posix_stringio.cpp +++ b/renderdoc/os/posix/posix_stringio.cpp @@ -142,7 +142,7 @@ rdcstr GetReplayAppFilename() path = get_dirname(path); rdcstr replay = path + "/qrenderdoc"; - FILE *f = FileIO::fopen(replay.c_str(), "r"); + FILE *f = FileIO::fopen(replay, FileIO::ReadText); if(f) { FileIO::fclose(f); @@ -162,7 +162,7 @@ rdcstr GetReplayAppFilename() // leave the lib/ folder, and go into bin/ replay += "../bin/qrenderdoc"; - f = FileIO::fopen(replay.c_str(), "r"); + f = FileIO::fopen(replay, FileIO::ReadText); if(f) { FileIO::fclose(f); @@ -175,7 +175,7 @@ rdcstr GetReplayAppFilename() for(size_t i = 0; i < ARRAY_COUNT(guess); i++) { - f = FileIO::fopen(guess[i], "r"); + f = FileIO::fopen(guess[i], FileIO::ReadText); if(f) { FileIO::fclose(f); @@ -187,7 +187,7 @@ rdcstr GetReplayAppFilename() return "qrenderdoc"; } -void GetDefaultFiles(const char *logBaseName, rdcstr &capture_filename, rdcstr &logging_filename, +void GetDefaultFiles(const rdcstr &logBaseName, rdcstr &capture_filename, rdcstr &logging_filename, rdcstr &target) { rdcstr path; @@ -229,7 +229,7 @@ void GetDefaultFiles(const char *logBaseName, rdcstr &capture_filename, rdcstr & logging_filename = rdcstr(logfile_override); else logging_filename = StringFormat::Fmt( - "%s/RenderDoc/%s_%04d.%02d.%02d_%02d.%02d.%02d.log", temp_folder, logBaseName, + "%s/RenderDoc/%s_%04d.%02d.%02d_%02d.%02d.%02d.log", temp_folder, logBaseName.c_str(), 1900 + now.tm_year, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec); } @@ -259,76 +259,76 @@ uint64_t GetFileSize(const rdcstr &filename) return 0; } -bool Copy(const char *from, const char *to, bool allowOverwrite) +bool Copy(const rdcstr &from, const rdcstr &to, bool allowOverwrite) { - if(from[0] == 0 || to[0] == 0) + if(from.empty() || to.empty()) return false; - FILE *ff = ::fopen(from, "r"); + FILE *ff = FileIO::fopen(from, ReadText); if(!ff) { - RDCERR("Can't open source file for copy '%s'", from); + RDCERR("Can't open source file for copy '%s'", from.c_str()); return false; } - FILE *tf = ::fopen(to, "r"); + FILE *tf = FileIO::fopen(to, FileIO::ReadText); if(tf && !allowOverwrite) { - RDCERR("Destination file for non-overwriting copy '%s' already exists", from); - ::fclose(ff); - ::fclose(tf); + RDCERR("Destination file for non-overwriting copy '%s' already exists", from.c_str()); + FileIO::fclose(ff); + FileIO::fclose(tf); return false; } if(tf) - ::fclose(tf); + FileIO::fclose(tf); - tf = ::fopen(to, "w"); + tf = FileIO::fopen(to, WriteText); if(!tf) { - ::fclose(ff); - RDCERR("Can't open destination file for copy '%s'", to); + FileIO::fclose(ff); + RDCERR("Can't open destination file for copy '%s'", to.c_str()); return false; } char buffer[BUFSIZ]; - while(!::feof(ff)) + while(!FileIO::feof(ff)) { - size_t nread = ::fread(buffer, 1, BUFSIZ, ff); - ::fwrite(buffer, 1, nread, tf); + size_t nread = FileIO::fread(buffer, 1, BUFSIZ, ff); + FileIO::fwrite(buffer, 1, nread, tf); } - ::fclose(ff); - ::fclose(tf); + FileIO::fclose(ff); + FileIO::fclose(tf); return true; } -bool Move(const char *from, const char *to, bool allowOverwrite) +bool Move(const rdcstr &from, const rdcstr &to, bool allowOverwrite) { - if(exists(to)) + if(exists(to.c_str())) { if(!allowOverwrite) return false; } - return ::rename(from, to) == 0; + return ::rename(from.c_str(), to.c_str()) == 0; } -void Delete(const char *path) +void Delete(const rdcstr &path) { - unlink(path); + unlink(path.c_str()); } -void GetFilesInDirectory(const char *path, rdcarray &ret) +void GetFilesInDirectory(const rdcstr &path, rdcarray &ret) { ret.clear(); - DIR *d = opendir(path); + DIR *d = opendir(path.c_str()); if(d == NULL) { @@ -391,9 +391,13 @@ void GetFilesInDirectory(const char *path, rdcarray &ret) closedir(d); } -FILE *fopen(const char *filename, const char *mode) +const char *modeString[] = { + "r", "rb", "w", "wb", "r+b", "w+b", +}; + +FILE *fopen(const rdcstr &filename, FileMode mode) { - return ::fopen(filename, mode); + return ::fopen(filename.c_str(), modeString[mode]); } rdcstr ErrorString() @@ -447,10 +451,10 @@ int fclose(FILE *f) return ::fclose(f); } -bool exists(const char *filename) +bool exists(const rdcstr &filename) { struct ::stat st; - int res = stat(filename, &st); + int res = stat(filename.c_str(), &st); return (res == 0); } @@ -466,9 +470,9 @@ void ReleaseFDAfterFork() close(log); } -rdcstr logfile_readall(uint64_t offset, const char *filename) +rdcstr logfile_readall(uint64_t offset, const rdcstr &filename) { - FILE *f = FileIO::fopen(filename, "r"); + FILE *f = FileIO::fopen(filename, FileIO::ReadText); rdcstr ret; @@ -493,13 +497,14 @@ rdcstr logfile_readall(uint64_t offset, const char *filename) return ret; } -LogFileHandle *logfile_open(const char *filename) +LogFileHandle *logfile_open(const rdcstr &filename) { - int fd = open(filename, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = + open(filename.c_str(), O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(fd < 0) { - RDCWARN("Couldn't open logfile '%s': %d", filename, (int)errno); + RDCWARN("Couldn't open logfile '%s': %d", filename.c_str(), (int)errno); return NULL; } @@ -511,7 +516,7 @@ LogFileHandle *logfile_open(const char *filename) int err = flock(fd, LOCK_SH | LOCK_NB); if(err < 0) - RDCWARN("Couldn't acquire shared lock to '%s': %d", filename, (int)errno); + RDCWARN("Couldn't acquire shared lock to '%s': %d", filename.c_str(), (int)errno); return (LogFileHandle *)(uintptr_t)fd; } @@ -526,7 +531,7 @@ void logfile_append(LogFileHandle *logHandle, const char *msg, size_t length) } } -void logfile_close(LogFileHandle *logHandle, const char *deleteFilename) +void logfile_close(LogFileHandle *logHandle, const rdcstr &deleteFilename) { if(logHandle) { @@ -535,7 +540,7 @@ void logfile_close(LogFileHandle *logHandle, const char *deleteFilename) // release our shared lock int err = flock(fd, LOCK_UN | LOCK_NB); - if(err == 0 && deleteFilename) + if(err == 0 && !deleteFilename.empty()) { // now try to acquire an exclusive lock. If this succeeds, no other processes are using the // file (since no other shared locks exist), so we can delete it. If it fails, some other @@ -552,11 +557,11 @@ void logfile_close(LogFileHandle *logHandle, const char *deleteFilename) // can't really error handle here apart from retrying if(err != 0) - RDCWARN("Couldn't release exclusive lock to '%s': %d", deleteFilename, (int)errno); + RDCWARN("Couldn't release exclusive lock to '%s': %d", deleteFilename.c_str(), (int)errno); close(fd); - unlink(deleteFilename); + unlink(deleteFilename.c_str()); // return immediately so we don't close again below. return; @@ -564,7 +569,7 @@ void logfile_close(LogFileHandle *logHandle, const char *deleteFilename) } else if(err) { - RDCWARN("Couldn't release shared lock to '%s': %d", deleteFilename, (int)errno); + RDCWARN("Couldn't release shared lock to '%s': %d", deleteFilename.c_str(), (int)errno); // nothing to do, we won't try again, just exit. The log might lie around, but that's // relatively harmless. } diff --git a/renderdoc/os/win32/win32_network.cpp b/renderdoc/os/win32/win32_network.cpp index 490e76ccb..e92c1082e 100644 --- a/renderdoc/os/win32/win32_network.cpp +++ b/renderdoc/os/win32/win32_network.cpp @@ -359,7 +359,7 @@ bool Socket::RecvDataBlocking(void *buf, uint32_t length) return true; } -Socket *CreateServerSocket(const char *bindaddr, uint16_t port, int queuesize) +Socket *CreateServerSocket(const rdcstr &bindaddr, uint16_t port, int queuesize) { SOCKET s = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED); @@ -371,13 +371,13 @@ Socket *CreateServerSocket(const char *bindaddr, uint16_t port, int queuesize) RDCEraseEl(addr); addr.sin_family = AF_INET; - inet_pton(AF_INET, bindaddr, &addr.sin_addr); + inet_pton(AF_INET, bindaddr.c_str(), &addr.sin_addr); addr.sin_port = htons(port); int result = bind(s, (SOCKADDR *)&addr, sizeof(addr)); if(result == SOCKET_ERROR) { - RDCWARN("Failed to bind to %s:%d - %d", bindaddr, port, WSAGetLastError()); + RDCWARN("Failed to bind to %s:%d - %d", bindaddr.c_str(), port, WSAGetLastError()); closesocket(s); return NULL; } @@ -385,7 +385,7 @@ Socket *CreateServerSocket(const char *bindaddr, uint16_t port, int queuesize) result = listen(s, queuesize); if(result == SOCKET_ERROR) { - RDCWARN("Failed to listen on %s:%d - %d", bindaddr, port, WSAGetLastError()); + RDCWARN("Failed to listen on %s:%d - %d", bindaddr.c_str(), port, WSAGetLastError()); closesocket(s); return NULL; } @@ -396,7 +396,7 @@ Socket *CreateServerSocket(const char *bindaddr, uint16_t port, int queuesize) return new Socket((ptrdiff_t)s); } -Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) +Socket *CreateClientSocket(const rdcstr &host, uint16_t port, int timeoutMS) { wchar_t portwstr[7] = {0}; @@ -412,7 +412,7 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; - rdcwstr whost = StringFormat::UTF82Wide(rdcstr(host)); + rdcwstr whost = StringFormat::UTF82Wide(host); addrinfoW *addrResult = NULL; int res = GetAddrInfoW(whost.c_str(), portwstr, &hints, &addrResult); @@ -490,35 +490,7 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS) FreeAddrInfoW(addrResult); - RDCDEBUG("Failed to connect to %s:%d", host, port); + RDCDEBUG("Failed to connect to %s:%d", host.c_str(), port); return NULL; } - -bool ParseIPRangeCIDR(const char *str, uint32_t &ip, uint32_t &mask) -{ - uint32_t a = 0, b = 0, c = 0, d = 0, num = 0; - - int ret = sscanf_s(str, "%u.%u.%u.%u/%u", &a, &b, &c, &d, &num); - - if(ret != 5 || a > 255 || b > 255 || c > 255 || d > 255 || num > 32) - { - ip = 0; - mask = 0; - return false; - } - - ip = MakeIP(a, b, c, d); - - if(num == 0) - { - mask = 0; - } - else - { - num = 32 - num; - mask = ((~0U) >> num) << num; - } - - return true; -} }; diff --git a/renderdoc/os/win32/win32_process.cpp b/renderdoc/os/win32/win32_process.cpp index b196e8a21..0e253293e 100644 --- a/renderdoc/os/win32/win32_process.cpp +++ b/renderdoc/os/win32/win32_process.cpp @@ -151,19 +151,18 @@ void Process::ApplyEnvironmentModification() modifications.clear(); } -const char *Process::GetEnvVariable(const char *name) +rdcstr Process::GetEnvVariable(const rdcstr &name) { - DWORD ret = GetEnvironmentVariableA(name, NULL, 0); - if(ret == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND) - return NULL; + DWORD len = GetEnvironmentVariableA(name.c_str(), NULL, 0); + if(len == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND) + return rdcstr(); - static char buf[1024] = {}; - if(ret >= 1024) - RDCERR("Static buffer insufficiently sized"); + rdcstr ret; + ret.resize(len + 1); - RDCEraseEl(buf); - GetEnvironmentVariableA(name, buf, RDCMIN((DWORD)1023U, ret)); - return buf; + GetEnvironmentVariableA(name.c_str(), ret.data(), len); + ret.trim(); + return ret; } uint64_t Process::GetMemoryUsage() @@ -211,6 +210,11 @@ extern "C" __declspec(dllexport) void __cdecl INTERNAL_SetCaptureFile(const char RenderDoc::Inst().SetCaptureFileTemplate(capfile); } +extern "C" __declspec(dllexport) void __cdecl INTERNAL_SetDebugLogFile(const char *logfile) +{ + RENDERDOC_SetDebugLogFile(logfile ? logfile : rdcstr()); +} + static EnvironmentModification tempEnvMod; extern "C" __declspec(dllexport) void __cdecl INTERNAL_EnvModName(const char *name) @@ -428,7 +432,8 @@ void InjectFunctionCall(HANDLE hProcess, uintptr_t renderdoc_remote, const char VirtualFreeEx(hProcess, remoteMem, 0, MEM_RELEASE); } -static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, const char *cmdLine, +static PROCESS_INFORMATION RunProcess(const rdcstr &app, const rdcstr &workingDir, + const rdcstr &cmdLine, const rdcarray &env, bool internal, HANDLE *phChildStdOutput_Rd, HANDLE *phChildStdError_Rd) { @@ -447,7 +452,7 @@ static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, c rdcwstr workdir = L""; - if(workingDir != NULL && workingDir[0] != 0) + if(!workingDir.empty()) workdir = StringFormat::UTF82Wide(workingDir); else workdir = StringFormat::UTF82Wide(get_dirname(app)); @@ -461,9 +466,9 @@ static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, c rdcwstr wcmd = L""; - if(cmdLine != NULL && cmdLine[0] != 0) + if(!cmdLine.empty()) { - wcmd = StringFormat::UTF82Wide(rdcstr(cmdLine)); + wcmd = StringFormat::UTF82Wide(cmdLine); len += wcmd.length(); } @@ -475,7 +480,7 @@ static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, c wcscat_s(paramsAlloc, len, wapp.c_str()); wcscat_s(paramsAlloc, len, L"\""); - if(cmdLine != NULL && cmdLine[0] != 0) + if(!cmdLine.empty()) { wcscat_s(paramsAlloc, len, L" "); wcscat_s(paramsAlloc, len, wcmd.c_str()); @@ -511,7 +516,7 @@ static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, c si.dwFlags |= STARTF_USESHOWWINDOW; if(!internal) - RDCLOG("Running process %s", app); + RDCLOG("Running process %s", app.c_str()); // turn environment string to a UTF-8 map std::wstring envString; @@ -550,7 +555,7 @@ static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, c if(!retValue) { if(!internal) - RDCWARN("Process %s could not be loaded.", app); + RDCWARN("Process %s could not be loaded.", app.c_str()); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); RDCEraseEl(pi); @@ -560,10 +565,10 @@ static PROCESS_INFORMATION RunProcess(const char *app, const char *workingDir, c } rdcpair Process::InjectIntoProcess( - uint32_t pid, const rdcarray &env, const char *capturefile, + uint32_t pid, const rdcarray &env, const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit) { - rdcwstr wcapturefile = capturefile == NULL ? L"" : StringFormat::UTF82Wide(capturefile); + rdcwstr wcapturefile = StringFormat::UTF82Wide(capturefile); HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | @@ -944,13 +949,13 @@ rdcpair Process::InjectIntoProcess( { // safe to cast away the const as we know these functions don't modify the parameters - if(capturefile != NULL) - InjectFunctionCall(hProcess, loc, "INTERNAL_SetCaptureFile", (void *)capturefile, - strlen(capturefile) + 1); + if(!capturefile.empty()) + InjectFunctionCall(hProcess, loc, "INTERNAL_SetCaptureFile", (void *)capturefile.c_str(), + capturefile.size() + 1); rdcstr debugLogfile = RDCGETLOGFILE(); - InjectFunctionCall(hProcess, loc, "RENDERDOC_SetDebugLogFile", (void *)debugLogfile.c_str(), + InjectFunctionCall(hProcess, loc, "INTERNAL_SetDebugLogFile", (void *)debugLogfile.c_str(), debugLogfile.size() + 1); InjectFunctionCall(hProcess, loc, "INTERNAL_SetCaptureOptions", (CaptureOptions *)&opts, @@ -993,7 +998,7 @@ rdcpair Process::InjectIntoProcess( return result; } -uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const char *cmdLine, +uint32_t Process::LaunchProcess(const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, bool internal, ProcessResult *result) { HANDLE hChildStdOutput_Rd = NULL, hChildStdError_Rd = NULL; @@ -1007,8 +1012,8 @@ uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const c appPath += ".exe"; PROCESS_INFORMATION pi = - RunProcess(appPath.c_str(), workingDir, cmdLine, {}, internal, - result ? &hChildStdOutput_Rd : NULL, result ? &hChildStdError_Rd : NULL); + RunProcess(appPath, workingDir, cmdLine, {}, internal, result ? &hChildStdOutput_Rd : NULL, + result ? &hChildStdError_Rd : NULL); if(pi.dwProcessId == 0) { @@ -1018,7 +1023,7 @@ uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const c } if(!internal) - RDCLOG("Launched process '%s' with '%s'", appPath.c_str(), cmdLine); + RDCLOG("Launched process '%s' with '%s'", appPath.c_str(), cmdLine.c_str()); ResumeThread(pi.hThread); @@ -1064,18 +1069,18 @@ uint32_t Process::LaunchProcess(const char *app, const char *workingDir, const c return pi.dwProcessId; } -uint32_t Process::LaunchScript(const char *script, const char *workingDir, const char *argList, - bool internal, ProcessResult *result) +uint32_t Process::LaunchScript(const rdcstr &script, const rdcstr &workingDir, + const rdcstr &argList, bool internal, ProcessResult *result) { // Change parameters to invoke command interpreter - rdcstr args = "/C " + rdcstr(script) + " " + rdcstr(argList); + rdcstr args = "/C " + script + " " + argList; - return LaunchProcess("cmd.exe", workingDir, args.c_str(), internal, result); + return LaunchProcess("cmd.exe", workingDir, args, internal, result); } rdcpair Process::LaunchAndInjectIntoProcess( - const char *app, const char *workingDir, const char *cmdLine, - const rdcarray &env, const char *capturefile, + const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, + const rdcarray &env, const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit) { void *func = @@ -1383,10 +1388,10 @@ static void GlobalHookThread() } } -bool Process::StartGlobalHook(const char *pathmatch, const char *capturefile, +bool Process::StartGlobalHook(const rdcstr &pathmatch, const rdcstr &capturefile, const CaptureOptions &opts) { - if(pathmatch == NULL) + if(pathmatch.empty()) return false; rdcstr renderdocPath; @@ -1466,7 +1471,7 @@ bool Process::StartGlobalHook(const char *pathmatch, const char *capturefile, rdcstr params = StringFormat::Fmt( "\"%s\" globalhook --match \"%s\" --capfile \"%s\" --debuglog \"%s\" --capopts \"%s\"", - cmdpathNative.c_str(), pathmatch, capturefile ? capturefile : "", debugLogfile.c_str(), + cmdpathNative.c_str(), pathmatch.c_str(), capturefile.c_str(), debugLogfile.c_str(), optstr.c_str()); rdcwstr paramsAlloc = StringFormat::UTF82Wide(params); @@ -1534,7 +1539,7 @@ bool Process::StartGlobalHook(const char *pathmatch, const char *capturefile, #if ENABLED(RDOC_X64) params = StringFormat::Fmt( "\"%s\" globalhook --match \"%s\" --capfile \"%s\" --debuglog \"%s\" --capopts \"%s\"", - cmdpathWow32.c_str(), pathmatch, capturefile ? capturefile : "", debugLogfile.c_str(), + cmdpathWow32.c_str(), pathmatch.c_str(), capturefile.c_str(), debugLogfile.c_str(), optstr.c_str()); paramsAlloc = StringFormat::UTF82Wide(params); @@ -1618,26 +1623,26 @@ void Process::StopGlobalHook() globalHook = NULL; } -bool Process::IsModuleLoaded(const char *module) +bool Process::IsModuleLoaded(const rdcstr &module) { - return GetModuleHandleA(module) != NULL; + return GetModuleHandleA(module.c_str()) != NULL; } -void *Process::LoadModule(const char *module) +void *Process::LoadModule(const rdcstr &module) { - HMODULE mod = GetModuleHandleA(module); + HMODULE mod = GetModuleHandleA(module.c_str()); if(mod != NULL) return mod; - return LoadLibraryA(module); + return LoadLibraryA(module.c_str()); } -void *Process::GetFunctionAddress(void *module, const char *function) +void *Process::GetFunctionAddress(void *module, const rdcstr &function) { if(module == NULL) return NULL; - return (void *)GetProcAddress((HMODULE)module, function); + return (void *)GetProcAddress((HMODULE)module, function.c_str()); } uint32_t Process::GetCurrentPID() diff --git a/renderdoc/os/win32/win32_specific.h b/renderdoc/os/win32/win32_specific.h index aa2d8595a..478352d21 100644 --- a/renderdoc/os/win32/win32_specific.h +++ b/renderdoc/os/win32/win32_specific.h @@ -57,7 +57,6 @@ inline bool DebuggerPresent() { return ::IsDebuggerPresent() == TRUE; } -void WriteOutput(int channel, const char *str); }; namespace Threading diff --git a/renderdoc/os/win32/win32_stringio.cpp b/renderdoc/os/win32/win32_stringio.cpp index 77050f991..1ea210f8a 100644 --- a/renderdoc/os/win32/win32_stringio.cpp +++ b/renderdoc/os/win32/win32_stringio.cpp @@ -287,7 +287,7 @@ rdcstr GetReplayAppFilename() path = get_dirname(path); rdcstr exe = path + "/qrenderdoc.exe"; - FILE *f = FileIO::fopen(exe.c_str(), "rb"); + FILE *f = FileIO::fopen(exe, FileIO::ReadBinary); if(f) { FileIO::fclose(f); @@ -298,7 +298,7 @@ rdcstr GetReplayAppFilename() // so look one up the tree. exe = path + "/../qrenderdoc.exe"; - f = FileIO::fopen(exe.c_str(), "rb"); + f = FileIO::fopen(exe, FileIO::ReadBinary); if(f) { FileIO::fclose(f); @@ -323,7 +323,7 @@ rdcstr GetReplayAppFilename() return ""; } -void GetDefaultFiles(const char *logBaseName, rdcstr &capture_filename, rdcstr &logging_filename, +void GetDefaultFiles(const rdcstr &logBaseName, rdcstr &capture_filename, rdcstr &logging_filename, rdcstr &target) { wchar_t temp_filename[MAX_PATH]; @@ -445,7 +445,7 @@ uint64_t GetFileSize(const rdcstr &filename) return 0; } -bool Copy(const char *from, const char *to, bool allowOverwrite) +bool Copy(const rdcstr &from, const rdcstr &to, bool allowOverwrite) { rdcwstr wfrom = StringFormat::UTF82Wide(from); rdcwstr wto = StringFormat::UTF82Wide(to); @@ -453,7 +453,7 @@ bool Copy(const char *from, const char *to, bool allowOverwrite) return ::CopyFileW(wfrom.c_str(), wto.c_str(), allowOverwrite == false) != 0; } -bool Move(const char *from, const char *to, bool allowOverwrite) +bool Move(const rdcstr &from, const rdcstr &to, bool allowOverwrite) { rdcwstr wfrom = StringFormat::UTF82Wide(from); rdcwstr wto = StringFormat::UTF82Wide(to); @@ -469,17 +469,17 @@ bool Move(const char *from, const char *to, bool allowOverwrite) return ::MoveFileW(wfrom.c_str(), wto.c_str()) != 0; } -void Delete(const char *path) +void Delete(const rdcstr &path) { rdcwstr wpath = StringFormat::UTF82Wide(path); ::DeleteFileW(wpath.c_str()); } -void GetFilesInDirectory(const char *path, rdcarray &ret) +void GetFilesInDirectory(const rdcstr &path, rdcarray &ret) { ret.clear(); - if(path[0] == '/' && path[1] == 0) + if(path.size() == 1 && path[0] == '/') { DWORD driveMask = GetLogicalDrives(); @@ -492,7 +492,7 @@ void GetFilesInDirectory(const char *path, rdcarray &ret) rdcstr fn = "A:/"; fn[0] = char('A' + i); - ret.push_back(PathEntry(fn.c_str(), PathProperty::Directory)); + ret.push_back(PathEntry(fn, PathProperty::Directory)); } } @@ -560,7 +560,7 @@ void GetFilesInDirectory(const char *path, rdcarray &ret) flags |= PathProperty::Executable; } - PathEntry f(StringFormat::Wide2UTF8(findData.cFileName).c_str(), flags); + PathEntry f(StringFormat::Wide2UTF8(findData.cFileName), flags); uint64_t nanosecondsSinceWindowsEpoch = uint64_t(findData.ftLastWriteTime.dwHighDateTime) << 8 | uint64_t(findData.ftLastWriteTime.dwLowDateTime); @@ -582,17 +582,20 @@ void GetFilesInDirectory(const char *path, rdcarray &ret) FindClose(find); } -FILE *fopen(const char *filename, const char *mode) +const wchar_t *modeString[] = { + L"r", L"rb", L"w", L"wb", L"r+b", L"w+b", +}; + +FILE *fopen(const rdcstr &filename, FileMode mode) { rdcwstr wfn = StringFormat::UTF82Wide(filename); - rdcwstr wmode = StringFormat::UTF82Wide(mode); FILE *ret = NULL; - ::_wfopen_s(&ret, wfn.c_str(), wmode.c_str()); + ::_wfopen_s(&ret, wfn.c_str(), modeString[mode]); return ret; } -bool exists(const char *filename) +bool exists(const rdcstr &filename) { rdcwstr wfn = StringFormat::UTF82Wide(filename); @@ -653,7 +656,7 @@ int fclose(FILE *f) return ::fclose(f); } -LogFileHandle *logfile_open(const char *filename) +LogFileHandle *logfile_open(const rdcstr &filename) { rdcwstr wfn = StringFormat::UTF82Wide(filename); return (LogFileHandle *)CreateFileW(wfn.c_str(), FILE_APPEND_DATA, @@ -692,7 +695,7 @@ static rdcstr logfile_readall_fallback(uint64_t offset, const wchar_t *filename) return ""; } -rdcstr logfile_readall(uint64_t offset, const char *filename) +rdcstr logfile_readall(uint64_t offset, const rdcstr &filename) { rdcwstr wfn = StringFormat::UTF82Wide(filename); HANDLE h = CreateFileW(wfn.c_str(), FILE_READ_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, @@ -705,7 +708,7 @@ rdcstr logfile_readall(uint64_t offset, const char *filename) DWORD err = GetLastError(); if(err == ERROR_FILE_NOT_FOUND) - return StringFormat::Fmt("Logfile '%s' doesn't exist", filename); + return StringFormat::Fmt("Logfile '%s' doesn't exist", filename.c_str()); ret = logfile_readall_fallback(offset, wfn.c_str()); ret += StringFormat::Fmt("\n\nCouldn't open logfile, CreateFile() threw %u\n\n", err); @@ -756,11 +759,11 @@ void logfile_append(LogFileHandle *logHandle, const char *msg, size_t length) } } -void logfile_close(LogFileHandle *logHandle, const char *deleteFilename) +void logfile_close(LogFileHandle *logHandle, const rdcstr &deleteFilename) { CloseHandle((HANDLE)logHandle); - if(deleteFilename) + if(!deleteFilename.empty()) { // we can just try to delete the file. If it's open elsewhere in another process, the delete // will fail. diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index 5ba148744..08668a589 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -78,7 +78,7 @@ Use precompiled.h precompiled.h - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Windows diff --git a/renderdoc/replay/app_api.cpp b/renderdoc/replay/app_api.cpp index d65e27a4b..554989532 100644 --- a/renderdoc/replay/app_api.cpp +++ b/renderdoc/replay/app_api.cpp @@ -126,7 +126,7 @@ static void SetCaptureFileComments(const char *filePath, const char *comments) } RDCFile rdc; - rdc.Open(path.c_str()); + rdc.Open(path); if(rdc.ErrorCode() != ContainerError::NoError) { RDCERR("Error opening '%s' to add capture comments", path.c_str()); @@ -205,7 +205,7 @@ static uint32_t LaunchReplayUI(uint32_t connectTargetControl, const char *cmdlin cmd += StringFormat::Fmt(" --targetcontrol localhost:%u", RenderDoc::Inst().GetTargetControlIdent()); - return Process::LaunchProcess(replayapp.c_str(), "", cmd.c_str(), false); + return Process::LaunchProcess(replayapp, "", cmd, false); } static void SetActiveWindow(void *device, void *wndHandle) diff --git a/renderdoc/replay/capture_file.cpp b/renderdoc/replay/capture_file.cpp index 22092dfc1..32fdeb59f 100644 --- a/renderdoc/replay/capture_file.cpp +++ b/renderdoc/replay/capture_file.cpp @@ -38,7 +38,7 @@ static void writeToBytebuf(void *context, void *data, int size) buf->append((byte *)data, size); } -static RDCDriver driverFromName(const char *driverName) +static RDCDriver driverFromName(const rdcstr &driverName) { for(int d = (int)RDCDriver::Unknown; d < (int)RDCDriver::MaxBuiltin; d++) { @@ -103,26 +103,26 @@ public: CaptureFile(); virtual ~CaptureFile(); - ReplayStatus OpenFile(const char *filename, const char *filetype, + ReplayStatus OpenFile(const rdcstr &filename, const rdcstr &filetype, RENDERDOC_ProgressCallback progress); - ReplayStatus OpenBuffer(const bytebuf &buffer, const char *filetype, + ReplayStatus OpenBuffer(const bytebuf &buffer, const rdcstr &filetype, RENDERDOC_ProgressCallback progress); - bool CopyFileTo(const char *filename); + bool CopyFileTo(const rdcstr &filename); rdcstr ErrorString() { return m_ErrorString; } void Shutdown() { delete this; } ReplaySupport LocalReplaySupport() { return m_Support; } rdcstr DriverName() { return m_DriverName; } - const char *RecordedMachineIdent() { return m_Ident.c_str(); } + rdcstr RecordedMachineIdent() { return m_Ident; } uint64_t TimestampBase() { return m_RDC ? m_RDC->GetTimestampBase() : 0; } double TimestampFrequency() { return m_RDC ? m_RDC->GetTimestampFrequency() : 1.0; } rdcpair OpenCapture(const ReplayOptions &opts, RENDERDOC_ProgressCallback progress); - void SetMetadata(const char *driverName, uint64_t machineIdent, FileType thumbType, + void SetMetadata(const rdcstr &driverName, uint64_t machineIdent, FileType thumbType, uint32_t thumbWidth, uint32_t thumbHeight, const bytebuf &thumbData, uint64_t timeBase, double timeFreq); - ReplayStatus Convert(const char *filename, const char *filetype, const SDFile *file, + ReplayStatus Convert(const rdcstr &filename, const rdcstr &filetype, const SDFile *file, RENDERDOC_ProgressCallback progress); rdcarray GetCaptureFileFormats() @@ -159,7 +159,7 @@ public: // ICaptureAccess int GetSectionCount(); - int FindSectionByName(const char *name); + int FindSectionByName(const rdcstr &name); int FindSectionByType(SectionType type); SectionProperties GetSectionProperties(int index); bytebuf GetSectionContents(int index); @@ -193,7 +193,7 @@ CaptureFile::~CaptureFile() SAFE_DELETE(m_Resolver); } -ReplayStatus CaptureFile::OpenFile(const char *filename, const char *filetype, +ReplayStatus CaptureFile::OpenFile(const rdcstr &filename, const rdcstr &filetype, RENDERDOC_ProgressCallback progress) { CaptureImporter importer = RenderDoc::Inst().GetCaptureImporter(filetype); @@ -203,7 +203,7 @@ ReplayStatus CaptureFile::OpenFile(const char *filename, const char *filetype, ReplayStatus ret; { - StreamReader reader(FileIO::fopen(filename, "rb")); + StreamReader reader(FileIO::fopen(filename, FileIO::ReadBinary)); SAFE_DELETE(m_RDC); m_RDC = new RDCFile; ret = importer(filename, reader, m_RDC, m_StructuredData, progress); @@ -211,15 +211,15 @@ ReplayStatus CaptureFile::OpenFile(const char *filename, const char *filetype, if(ret != ReplayStatus::Succeeded) { - m_ErrorString = StringFormat::Fmt("Importer '%s' failed to import file.", filetype); + m_ErrorString = StringFormat::Fmt("Importer '%s' failed to import file.", filetype.c_str()); SAFE_DELETE(m_RDC); return ret; } } else { - if(filetype != NULL && strcmp(filetype, "") != 0 && strcmp(filetype, "rdc") != 0) - RDCWARN("Opening file with unrecognised filetype '%s' - treating as 'rdc'", filetype); + if(filetype != "" && filetype != "rdc") + RDCWARN("Opening file with unrecognised filetype '%s' - treating as 'rdc'", filetype.c_str()); if(progress) progress(0.0f); @@ -235,7 +235,7 @@ ReplayStatus CaptureFile::OpenFile(const char *filename, const char *filetype, return Init(); } -ReplayStatus CaptureFile::OpenBuffer(const bytebuf &buffer, const char *filetype, +ReplayStatus CaptureFile::OpenBuffer(const bytebuf &buffer, const rdcstr &filetype, RENDERDOC_ProgressCallback progress) { CaptureImporter importer = RenderDoc::Inst().GetCaptureImporter(filetype); @@ -248,20 +248,20 @@ ReplayStatus CaptureFile::OpenBuffer(const bytebuf &buffer, const char *filetype StreamReader reader(buffer); SAFE_DELETE(m_RDC); m_RDC = new RDCFile; - ret = importer(NULL, reader, m_RDC, m_StructuredData, progress); + ret = importer(rdcstr(), reader, m_RDC, m_StructuredData, progress); } if(ret != ReplayStatus::Succeeded) { - m_ErrorString = StringFormat::Fmt("Importer '%s' failed to import file.", filetype); + m_ErrorString = StringFormat::Fmt("Importer '%s' failed to import file.", filetype.c_str()); SAFE_DELETE(m_RDC); return ret; } } else { - if(filetype != NULL && strcmp(filetype, "") != 0 && strcmp(filetype, "rdc") != 0) - RDCWARN("Opening file with unrecognised filetype '%s' - treating as 'rdc'", filetype); + if(filetype != "" && filetype != "rdc") + RDCWARN("Opening file with unrecognised filetype '%s' - treating as 'rdc'", filetype.c_str()); if(progress) progress(0.0f); @@ -277,7 +277,7 @@ ReplayStatus CaptureFile::OpenBuffer(const bytebuf &buffer, const char *filetype return Init(); } -bool CaptureFile::CopyFileTo(const char *filename) +bool CaptureFile::CopyFileTo(const rdcstr &filename) { if(m_RDC) return m_RDC->CopyFileTo(filename); @@ -371,7 +371,7 @@ rdcpair CaptureFile::OpenCapture(const Replay return rdcpair(ret, render); } -void CaptureFile::SetMetadata(const char *driverName, uint64_t machineIdent, FileType thumbType, +void CaptureFile::SetMetadata(const rdcstr &driverName, uint64_t machineIdent, FileType thumbType, uint32_t thumbWidth, uint32_t thumbHeight, const bytebuf &thumbData, uint64_t timeBase, double timeFreq) { @@ -394,7 +394,7 @@ void CaptureFile::SetMetadata(const char *driverName, uint64_t machineIdent, Fil if(driver == RDCDriver::Unknown) { - RDCERR("Unrecognised driver name '%s'.", driverName); + RDCERR("Unrecognised driver name '%s'.", driverName.c_str()); return; } @@ -402,8 +402,8 @@ void CaptureFile::SetMetadata(const char *driverName, uint64_t machineIdent, Fil m_RDC->SetData(driver, driverName, machineIdent, thumb, timeBase, timeFreq); } -ReplayStatus CaptureFile::Convert(const char *filename, const char *filetype, const SDFile *file, - RENDERDOC_ProgressCallback progress) +ReplayStatus CaptureFile::Convert(const rdcstr &filename, const rdcstr &filetype, + const SDFile *file, RENDERDOC_ProgressCallback progress) { if(!m_RDC) { @@ -436,12 +436,12 @@ ReplayStatus CaptureFile::Convert(const char *filename, const char *filetype, co } } - if(filetype != NULL && strcmp(filetype, "") != 0 && strcmp(filetype, "rdc") != 0) - RDCWARN("Converting file to unrecognised filetype '%s' - treating as 'rdc'", filetype); + if(filetype != "" && filetype != "rdc") + RDCWARN("Converting file to unrecognised filetype '%s' - treating as 'rdc'", filetype.c_str()); RDCFile output; - output.SetData(m_RDC->GetDriver(), m_RDC->GetDriverName().c_str(), m_RDC->GetMachineIdent(), + output.SetData(m_RDC->GetDriver(), m_RDC->GetDriverName(), m_RDC->GetMachineIdent(), &m_RDC->GetThumbnail(), m_RDC->GetTimestampBase(), m_RDC->GetTimestampFrequency()); output.Create(filename); @@ -685,7 +685,7 @@ int CaptureFile::GetSectionCount() return m_RDC->NumSections(); } -int CaptureFile::FindSectionByName(const char *name) +int CaptureFile::FindSectionByName(const rdcstr &name) { if(!m_RDC) return -1; diff --git a/renderdoc/replay/entry_points.cpp b/renderdoc/replay/entry_points.cpp index 183fde72b..0c1f5a407 100644 --- a/renderdoc/replay/entry_points.cpp +++ b/renderdoc/replay/entry_points.cpp @@ -202,12 +202,12 @@ extern "C" RENDERDOC_API uint64_t RENDERDOC_CC RENDERDOC_GetCurrentProcessMemory return Process::GetMemoryUsage(); } -extern "C" RENDERDOC_API const SDObject *RENDERDOC_CC RENDERDOC_GetConfigSetting(const char *name) +extern "C" RENDERDOC_API const SDObject *RENDERDOC_CC RENDERDOC_GetConfigSetting(const rdcstr &name) { return RenderDoc::Inst().GetConfigSetting(name); } -extern "C" RENDERDOC_API SDObject *RENDERDOC_CC RENDERDOC_SetConfigSetting(const char *name) +extern "C" RENDERDOC_API SDObject *RENDERDOC_CC RENDERDOC_SetConfigSetting(const rdcstr &name) { return RenderDoc::Inst().SetConfigSetting(name); } @@ -226,11 +226,11 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetColors(FloatVector darkC RenderDoc::Inst().SetDarkTheme(darkTheme); } -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetDebugLogFile(const char *log) +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetDebugLogFile(const rdcstr &log) { - if(log) + if(!log.empty()) { - RDCLOGFILE(log); + RDCLOGFILE(log.c_str()); // need to recreate the crash handler to propagate the new log filename. if(RenderDoc::Inst().GetCrashHandler() != NULL) @@ -238,12 +238,12 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetDebugLogFile(const char } } -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_LogMessage(LogType type, const char *project, - const char *file, unsigned int line, - const char *text) +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_LogMessage(LogType type, const rdcstr &project, + const rdcstr &file, + unsigned int line, const rdcstr &text) { - rdclog_direct(FILL_AUTO_VALUE, FILL_AUTO_VALUE, type, project ? project : "UNK?", - file ? file : "unknown", line, "%s", text); + rdclog_direct(FILL_AUTO_VALUE, FILL_AUTO_VALUE, type, project.c_str(), file.c_str(), line, "%s", + text.c_str()); // see comment in common.h RDCCOMPILE_ASSERT((uint32_t)LogType::Debug == (uint32_t)LogType__Internal::Debug, @@ -283,12 +283,7 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_GetLogFileContents(uint64_t extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_InitialiseReplay(GlobalEnvironment env, const rdcarray &args) { - rdcarray argsVec; - argsVec.reserve(args.size()); - for(const rdcstr &a : args) - argsVec.push_back(a.c_str()); - - RenderDoc::Inst().InitialiseReplay(env, argsVec); + RenderDoc::Inst().InitialiseReplay(env, args); if(RenderDoc::Inst().GetCrashHandler() == NULL) return; @@ -310,8 +305,8 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_ShutdownReplay() RenderDoc::Inst().ShutdownReplay(); } -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_CreateBugReport(const char *logfile, - const char *dumpfile, +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_CreateBugReport(const rdcstr &logfile, + const rdcstr &dumpfile, rdcstr &report) { mz_zip_archive zip; @@ -323,14 +318,14 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_CreateBugReport(const char StringFormat::sntimef(Timing::GetUTCTime(), "/renderdoc_report_%H%M%S.zip"); } - FileIO::Delete(report.c_str()); + FileIO::Delete(report); mz_zip_writer_init_file(&zip, report.c_str(), 0); - if(dumpfile && dumpfile[0]) - mz_zip_writer_add_file(&zip, "minidump.dmp", dumpfile, NULL, 0, MZ_BEST_COMPRESSION); + if(!dumpfile.empty()) + mz_zip_writer_add_file(&zip, "minidump.dmp", dumpfile.c_str(), NULL, 0, MZ_BEST_COMPRESSION); - if(logfile && logfile[0]) + if(!logfile.empty()) { rdcstr contents = FileIO::logfile_readall(0, logfile); mz_zip_writer_add_mem(&zip, "error.log", contents.data(), contents.length(), MZ_BEST_COMPRESSION); @@ -357,8 +352,8 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_UnregisterMemoryRegion(void } extern "C" RENDERDOC_API ExecuteResult RENDERDOC_CC -RENDERDOC_ExecuteAndInject(const char *app, const char *workingDir, const char *cmdLine, - const rdcarray &env, const char *capturefile, +RENDERDOC_ExecuteAndInject(const rdcstr &app, const rdcstr &workingDir, const rdcstr &cmdLine, + const rdcarray &env, const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit) { rdcpair status = Process::LaunchAndInjectIntoProcess( @@ -375,8 +370,8 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_GetDefaultCaptureOptions(Ca *opts = CaptureOptions(); } -extern "C" RENDERDOC_API bool RENDERDOC_CC RENDERDOC_StartGlobalHook(const char *pathmatch, - const char *capturefile, +extern "C" RENDERDOC_API bool RENDERDOC_CC RENDERDOC_StartGlobalHook(const rdcstr &pathmatch, + const rdcstr &capturefile, const CaptureOptions &opts) { return Process::StartGlobalHook(pathmatch, capturefile, opts); @@ -399,7 +394,7 @@ extern "C" RENDERDOC_API bool RENDERDOC_CC RENDERDOC_CanGlobalHook() extern "C" RENDERDOC_API ExecuteResult RENDERDOC_CC RENDERDOC_InjectIntoProcess(uint32_t pid, const rdcarray &env, - const char *capturefile, const CaptureOptions &opts, bool waitForExit) + const rdcstr &capturefile, const CaptureOptions &opts, bool waitForExit) { rdcpair status = Process::InjectIntoProcess(pid, env, capturefile, opts, waitForExit != 0); @@ -429,11 +424,11 @@ extern "C" RENDERDOC_API void *RENDERDOC_CC RENDERDOC_AllocArrayMem(uint64_t sz) return ret; } -extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteTargets(const char *URL, +extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteTargets(const rdcstr &URL, uint32_t nextIdent) { rdcstr host = "localhost"; - if(URL != NULL && URL[0] != '\0') + if(!URL.empty()) host = URL; rdcstr deviceID = host; @@ -465,7 +460,7 @@ extern "C" RENDERDOC_API uint32_t RENDERDOC_CC RENDERDOC_EnumerateRemoteTargets( if(port == 0) return 0; - Network::Socket *sock = Network::CreateClientSocket(host.c_str(), port, 250); + Network::Socket *sock = Network::CreateClientSocket(host, port, 250); if(sock) { @@ -502,12 +497,9 @@ RENDERDOC_GetDeviceProtocolController(const rdcstr &protocol) } extern "C" RENDERDOC_API void RENDERDOC_CC -RENDERDOC_BecomeRemoteServer(const char *listenhost, RENDERDOC_KillCallback killReplay, +RENDERDOC_BecomeRemoteServer(const rdcstr &listenhost, RENDERDOC_KillCallback killReplay, RENDERDOC_PreviewWindowCallback previewWindow) { - if(listenhost == NULL || listenhost[0] == 0) - listenhost = "0.0.0.0"; - // ensure a sensible default if no callback is provided, that just never kills if(!killReplay) killReplay = []() { return false; }; @@ -519,11 +511,11 @@ RENDERDOC_BecomeRemoteServer(const char *listenhost, RENDERDOC_KillCallback kill return ret; }; - RenderDoc::Inst().BecomeRemoteServer(listenhost, RenderDoc_RemoteServerPort, killReplay, - previewWindow); + RenderDoc::Inst().BecomeRemoteServer(listenhost.empty() ? "0.0.0.0" : listenhost, + RenderDoc_RemoteServerPort, killReplay, previewWindow); } -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartSelfHostCapture(const char *dllname) +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartSelfHostCapture(const rdcstr &dllname) { if(!Process::IsModuleLoaded(dllname)) return; @@ -549,7 +541,7 @@ extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_StartSelfHostCapture(const rdoc->StartFrameCapture(NULL, NULL); } -extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_EndSelfHostCapture(const char *dllname) +extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_EndSelfHostCapture(const rdcstr &dllname) { if(!Process::IsModuleLoaded(dllname)) return; @@ -905,7 +897,7 @@ extern "C" RENDERDOC_API int RENDERDOC_CC RENDERDOC_RunFunctionalTests(int pytho rdcstr moduleFilename = modulePath + "/" + modulename; - if(!FileIO::exists(moduleFilename.c_str())) + if(!FileIO::exists(moduleFilename)) { TestPrintMsg(StringFormat::Fmt("Couldn't locate python module at %s\n", moduleFilename.c_str())); return 1; @@ -917,7 +909,7 @@ extern "C" RENDERDOC_API int RENDERDOC_CC RENDERDOC_RunFunctionalTests(int pytho // directly. This is just intended as a useful shortcut for common cases. rdcstr scriptPath = libPath + "/../../util/test/run_tests.py"; - if(!FileIO::exists(scriptPath.c_str())) + if(!FileIO::exists(scriptPath)) { TestPrintMsg(StringFormat::Fmt("Couldn't locate run_tests.py script at %s\n", scriptPath.c_str())); return 1; @@ -931,7 +923,7 @@ extern "C" RENDERDOC_API int RENDERDOC_CC RENDERDOC_RunFunctionalTests(int pytho char *ver = strchr(&py[0], '?'); *ver = char('0' + pythonMinorVersion); - handle = Process::LoadModule(py.c_str()); + handle = Process::LoadModule(py); if(handle) { RDCLOG("Loaded python from %s", py.c_str()); diff --git a/renderdoc/replay/replay_controller.cpp b/renderdoc/replay/replay_controller.cpp index 558055d9a..71d91b8cb 100644 --- a/renderdoc/replay/replay_controller.cpp +++ b/renderdoc/replay/replay_controller.cpp @@ -162,7 +162,7 @@ rdcarray ReplayController::GetDisassemblyTargets(bool withPipeline) } rdcstr ReplayController::DisassembleShader(ResourceId pipeline, const ShaderReflection *refl, - const char *target) + const rdcstr &target) { CHECK_REPLAY_THREAD(); @@ -555,7 +555,7 @@ bytebuf ReplayController::GetTextureData(ResourceId tex, const Subresource &sub) return ret; } -bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path) +bool ReplayController::SaveTexture(const TextureSave &saveData, const rdcstr &path) { CHECK_REPLAY_THREAD(); RENDERDOC_PROFILEFUNCTION(); @@ -1169,12 +1169,12 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path rowPitch = td.width * 3; } - FILE *f = FileIO::fopen(path, "wb"); + FILE *f = FileIO::fopen(path, FileIO::WriteBinary); if(!f) { success = false; - RDCERR("Couldn't write to path %s, error: %s", path, FileIO::ErrorString().c_str()); + RDCERR("Couldn't write to path %s, error: %s", path.c_str(), FileIO::ErrorString().c_str()); } else { @@ -1656,7 +1656,7 @@ void ReplayController::FreeTrace(ShaderDebugTrace *trace) } rdcarray ReplayController::GetCBufferVariableContents( - ResourceId pipeline, ResourceId shader, const char *entryPoint, uint32_t cbufslot, + ResourceId pipeline, ResourceId shader, const rdcstr &entryPoint, uint32_t cbufslot, ResourceId buffer, uint64_t offset, uint64_t length) { CHECK_REPLAY_THREAD(); @@ -1703,7 +1703,7 @@ rdcstr ReplayController::CreateRGPProfile(WindowingData window) rdcstr path = FileIO::GetTempFolderFilename() + "/renderdoc_rgp_capture.rgp"; - FileIO::Delete(path.c_str()); + FileIO::Delete(path); ReplayOutput *output = CreateOutput(window, ReplayOutputType::Texture); @@ -1872,7 +1872,7 @@ rdcarray ReplayController::GetTargetShaderEncodings() } rdcpair ReplayController::BuildTargetShader( - const char *entry, ShaderEncoding sourceEncoding, bytebuf source, + const rdcstr &entry, ShaderEncoding sourceEncoding, bytebuf source, const ShaderCompileFlags &compileFlags, ShaderStage type) { CHECK_REPLAY_THREAD(); @@ -1912,7 +1912,7 @@ rdcpair ReplayController::BuildTargetShader( } rdcpair ReplayController::BuildCustomShader( - const char *entry, ShaderEncoding sourceEncoding, bytebuf source, + const rdcstr &entry, ShaderEncoding sourceEncoding, bytebuf source, const ShaderCompileFlags &compileFlags, ShaderStage type) { CHECK_REPLAY_THREAD(); diff --git a/renderdoc/replay/replay_controller.h b/renderdoc/replay/replay_controller.h index 4ec4ccd0b..710e87326 100644 --- a/renderdoc/replay/replay_controller.h +++ b/renderdoc/replay/replay_controller.h @@ -144,9 +144,9 @@ public: const PipeState &GetPipelineState(); rdcarray GetDisassemblyTargets(bool withPipeline); - rdcstr DisassembleShader(ResourceId pipeline, const ShaderReflection *refl, const char *target); + rdcstr DisassembleShader(ResourceId pipeline, const ShaderReflection *refl, const rdcstr &target); - rdcpair BuildCustomShader(const char *entry, ShaderEncoding sourceEncoding, + rdcpair BuildCustomShader(const rdcstr &entry, ShaderEncoding sourceEncoding, bytebuf source, const ShaderCompileFlags &compileFlags, ShaderStage type); @@ -154,7 +154,7 @@ public: rdcarray GetCustomShaderEncodings(); rdcarray GetTargetShaderEncodings(); - rdcpair BuildTargetShader(const char *entry, ShaderEncoding sourceEncoding, + rdcpair BuildTargetShader(const rdcstr &entry, ShaderEncoding sourceEncoding, bytebuf source, const ShaderCompileFlags &compileFlags, ShaderStage type); @@ -198,10 +198,10 @@ public: bytebuf GetBufferData(ResourceId buff, uint64_t offset, uint64_t len); bytebuf GetTextureData(ResourceId buff, const Subresource &sub); - bool SaveTexture(const TextureSave &saveData, const char *path); + bool SaveTexture(const TextureSave &saveData, const rdcstr &path); rdcarray GetCBufferVariableContents(ResourceId pipeline, ResourceId shader, - const char *entryPoint, uint32_t cbufslot, + const rdcstr &entryPoint, uint32_t cbufslot, ResourceId buffer, uint64_t offset, uint64_t length); diff --git a/renderdoc/serialise/codecs/chrome_json_codec.cpp b/renderdoc/serialise/codecs/chrome_json_codec.cpp index 790145a6d..b1f045961 100644 --- a/renderdoc/serialise/codecs/chrome_json_codec.cpp +++ b/renderdoc/serialise/codecs/chrome_json_codec.cpp @@ -28,10 +28,10 @@ #include "common/formatting.h" #include "serialise/rdcfile.h" -ReplayStatus exportChrome(const char *filename, const RDCFile &rdc, const SDFile &structData, +ReplayStatus exportChrome(const rdcstr &filename, const RDCFile &rdc, const SDFile &structData, RENDERDOC_ProgressCallback progress) { - FILE *f = FileIO::fopen(filename, "w"); + FILE *f = FileIO::fopen(filename, FileIO::WriteText); if(!f) return ReplayStatus::FileIOFailed; diff --git a/renderdoc/serialise/codecs/xml_codec.cpp b/renderdoc/serialise/codecs/xml_codec.cpp index 4dbfe0dd9..a39b7f9cd 100644 --- a/renderdoc/serialise/codecs/xml_codec.cpp +++ b/renderdoc/serialise/codecs/xml_codec.cpp @@ -63,7 +63,8 @@ struct xml_file_writer : pugi::xml_writer { StreamWriter stream; - xml_file_writer(const char *filename) : stream(FileIO::fopen(filename, "wb"), Ownership::Stream) + xml_file_writer(const rdcstr &filename) + : stream(FileIO::fopen(filename, FileIO::WriteBinary), Ownership::Stream) { } @@ -274,7 +275,7 @@ static void Obj2XML(pugi::xml_node &parent, SDObject &child) } } -static ReplayStatus Structured2XML(const char *filename, const RDCFile &file, uint64_t version, +static ReplayStatus Structured2XML(const rdcstr &filename, const RDCFile &file, uint64_t version, const StructuredChunkList &chunks, RENDERDOC_ProgressCallback progress) { @@ -558,14 +559,14 @@ static SDObject *XML2Obj(pugi::xml_node &obj) return ret; } -static ReplayStatus XML2Structured(const char *xml, const ThumbTypeAndData &thumb, +static ReplayStatus XML2Structured(const rdcstr &xml, const ThumbTypeAndData &thumb, const ThumbTypeAndData &extThumb, const bytebuf &logfile, const StructuredBufferList &buffers, RDCFile *rdc, uint64_t &version, StructuredChunkList &chunks, RENDERDOC_ProgressCallback progress) { pugi::xml_document doc; - doc.load_string(xml); + doc.load_string(xml.c_str()); pugi::xml_node root = doc.child("rdc"); @@ -938,7 +939,7 @@ static bool ZIP2Buffers(const rdcstr &filename, ThumbTypeAndData &thumb, ThumbTy { rdcstr zipFile = strip_extension(filename); - if(!FileIO::exists(zipFile.c_str())) + if(!FileIO::exists(zipFile)) { RDCERR("Expected to file zip for %s at %s", filename.c_str(), zipFile.c_str()); return false; @@ -1012,17 +1013,17 @@ static bool ZIP2Buffers(const rdcstr &filename, ThumbTypeAndData &thumb, ThumbTy return true; } -ReplayStatus importXMLZ(const char *filename, StreamReader &reader, RDCFile *rdc, +ReplayStatus importXMLZ(const rdcstr &filename, StreamReader &reader, RDCFile *rdc, SDFile &structData, RENDERDOC_ProgressCallback progress) { ThumbTypeAndData thumb, extThumb; bytebuf logfile; - if(filename) + if(!filename.empty()) { bool success = ZIP2Buffers(filename, thumb, extThumb, logfile, structData.buffers, progress); if(!success) { - RDCERR("Couldn't load zip to go with %s", filename); + RDCERR("Couldn't load zip to go with %s", filename.c_str()); return ReplayStatus::FileCorrupted; } } @@ -1035,7 +1036,7 @@ ReplayStatus importXMLZ(const char *filename, StreamReader &reader, RDCFile *rdc structData.version, structData.chunks, progress); } -ReplayStatus exportXMLZ(const char *filename, const RDCFile &rdc, const SDFile &structData, +ReplayStatus exportXMLZ(const rdcstr &filename, const RDCFile &rdc, const SDFile &structData, RENDERDOC_ProgressCallback progress) { ReplayStatus ret = Buffers2ZIP(filename, rdc, structData.buffers, progress); @@ -1046,7 +1047,7 @@ ReplayStatus exportXMLZ(const char *filename, const RDCFile &rdc, const SDFile & return Structured2XML(filename, rdc, structData.version, structData.chunks, progress); } -ReplayStatus exportXMLOnly(const char *filename, const RDCFile &rdc, const SDFile &structData, +ReplayStatus exportXMLOnly(const rdcstr &filename, const RDCFile &rdc, const SDFile &structData, RENDERDOC_ProgressCallback progress) { return Structured2XML(filename, rdc, structData.version, structData.chunks, progress); diff --git a/renderdoc/serialise/rdcfile.cpp b/renderdoc/serialise/rdcfile.cpp index 3fb29f446..cc9c14756 100644 --- a/renderdoc/serialise/rdcfile.cpp +++ b/renderdoc/serialise/rdcfile.cpp @@ -250,28 +250,28 @@ RDCFile::~RDCFile() FileIO::fclose(m_File); } -void RDCFile::Open(const char *path) +void RDCFile::Open(const rdcstr &path) { // silently fail when opening the empty string, to allow 'releasing' a capture file by opening an // empty path. - if(path == NULL || path[0] == 0) + if(path.empty()) { RETURNERROR(ContainerError::FileNotFound, "Invalid file path specified"); } - RDCLOG("Opening RDCFile %s", path); + RDCLOG("Opening RDCFile %s", path.c_str()); // ensure section header is compiled correctly RDCCOMPILE_ASSERT(offsetof(BinarySectionHeader, name) == sizeof(uint32_t) * 10, "BinarySectionHeader size has changed or contains padding"); - m_File = FileIO::fopen(path, "rb"); + m_File = FileIO::fopen(path, FileIO::ReadBinary); m_Filename = path; if(!m_File) { RETURNERROR(ContainerError::FileNotFound, "Can't open capture file '%s' for read - errno %d", - path, errno); + path.c_str(), errno); } // try to identify if this is an image @@ -641,7 +641,7 @@ void RDCFile::Init(StreamReader &reader) } } -bool RDCFile::CopyFileTo(const char *filename) +bool RDCFile::CopyFileTo(const rdcstr &filename) { if(!m_File) return false; @@ -651,20 +651,20 @@ bool RDCFile::CopyFileTo(const char *filename) FileIO::fclose(m_File); // try to move to the new location - bool success = FileIO::Copy(m_Filename.c_str(), filename, true); + bool success = FileIO::Copy(m_Filename, filename, true); // if it succeeded, update our filename if(success) m_Filename = filename; // re-open the file (either the new one, or the old one if it failed) and re-seek - m_File = FileIO::fopen(m_Filename.c_str(), "rb"); + m_File = FileIO::fopen(m_Filename, FileIO::ReadBinary); FileIO::fseek64(m_File, prevPos, SEEK_SET); return success; } -void RDCFile::SetData(RDCDriver driver, const char *driverName, uint64_t machineIdent, +void RDCFile::SetData(RDCDriver driver, const rdcstr &driverName, uint64_t machineIdent, const RDCThumb *thumb, uint64_t timeBase, double timeFreq) { m_Driver = driver; @@ -678,9 +678,9 @@ void RDCFile::SetData(RDCDriver driver, const char *driverName, uint64_t machine m_TimeFrequency = timeFreq; } -void RDCFile::Create(const char *filename) +void RDCFile::Create(const rdcstr &filename) { - m_File = FileIO::fopen(filename, "wb"); + m_File = FileIO::fopen(filename, FileIO::WriteBinary); m_Filename = filename; RDCDEBUG("creating RDC file."); @@ -688,7 +688,7 @@ void RDCFile::Create(const char *filename) if(!m_File) { RETURNERROR(ContainerError::FileIO, "Can't open capture file '%s' for write, errno %d", - filename, errno); + filename.c_str(), errno); } RDCDEBUG("Opened capture file for write"); @@ -780,13 +780,13 @@ void RDCFile::Create(const char *filename) // re-open as read-only now. FileIO::fclose(m_File); - m_File = FileIO::fopen(filename, "rb"); + m_File = FileIO::fopen(filename, FileIO::ReadBinary); FileIO::fseek64(m_File, 0, SEEK_END); if(!m_File) { RETURNERROR(ContainerError::FileIO, "Can't open capture file '%s' as read-only, errno %d", - filename, errno); + filename.c_str(), errno); } } @@ -804,7 +804,7 @@ int RDCFile::SectionIndex(SectionType type) const return -1; } -int RDCFile::SectionIndex(const char *name) const +int RDCFile::SectionIndex(const rdcstr &name) const { for(size_t i = 0; i < m_Sections.size(); i++) if(m_Sections[i].name == name) @@ -886,12 +886,12 @@ StreamWriter *RDCFile::WriteSection(const SectionProperties &props) { uint64_t offs = FileIO::ftell64(m_File); FileIO::fclose(m_File); - m_File = FileIO::fopen(m_Filename.c_str(), "r+b"); + m_File = FileIO::fopen(m_Filename, FileIO::UpdateBinary); if(m_File == NULL) { RDCERR("Couldn't re-open file as read/write to write section."); - m_File = FileIO::fopen(m_Filename.c_str(), "rb"); + m_File = FileIO::fopen(m_Filename, FileIO::ReadBinary); if(m_File) FileIO::fseek64(m_File, offs, SEEK_SET); return new StreamWriter(StreamWriter::InvalidStream); @@ -936,7 +936,7 @@ StreamWriter *RDCFile::WriteSection(const SectionProperties &props) // fixups. We need to be able to fixup any pre-existing sections that got shifted around. StreamCloseCallback modifySectionCallback; - if(SectionIndex(type) >= 0 || SectionIndex(name.c_str()) >= 0) + if(SectionIndex(type) >= 0 || SectionIndex(name) >= 0) { if(type == SectionType::FrameCapture || name == ToStr(SectionType::FrameCapture)) { @@ -976,7 +976,7 @@ StreamWriter *RDCFile::WriteSection(const SectionProperties &props) // create the file, this will overwrite m_File with the new file and file header using the // existing loaded metadata - Create(tempFilename.c_str()); + Create(tempFilename); // after we've written the frame capture, we need to copy over the other sections into the // temporary file and finally move the temporary file over the top of the existing file. @@ -1026,10 +1026,10 @@ StreamWriter *RDCFile::WriteSection(const SectionProperties &props) FileIO::fclose(m_File); // move the temp file over the original - FileIO::Move(tempFilename.c_str(), m_Filename.c_str(), true); + FileIO::Move(tempFilename, m_Filename, true); // re-open the file after it's been overwritten. - m_File = FileIO::fopen(m_Filename.c_str(), "r+b"); + m_File = FileIO::fopen(m_Filename, FileIO::UpdateBinary); }; // fall through - we'll write to m_File immediately after the file header @@ -1049,7 +1049,7 @@ StreamWriter *RDCFile::WriteSection(const SectionProperties &props) int index = SectionIndex(type); if(index < 0) - index = SectionIndex(name.c_str()); + index = SectionIndex(name); RDCASSERT(index >= 0); @@ -1235,7 +1235,7 @@ StreamWriter *RDCFile::WriteSection(const SectionProperties &props) FileIO::fclose(m_File); // re-open the file and re-seek - m_File = FileIO::fopen(m_Filename.c_str(), "rb"); + m_File = FileIO::fopen(m_Filename, FileIO::ReadBinary); FileIO::fseek64(m_File, prevPos, SEEK_SET); }); diff --git a/renderdoc/serialise/rdcfile.h b/renderdoc/serialise/rdcfile.h index c4ea3d086..fe0539959 100644 --- a/renderdoc/serialise/rdcfile.h +++ b/renderdoc/serialise/rdcfile.h @@ -71,17 +71,17 @@ public: ~RDCFile(); // opens an existing file for read and/or modification. Error if file doesn't exist - void Open(const char *filename); + void Open(const rdcstr &filename); void Open(const bytebuf &buffer); - bool CopyFileTo(const char *filename); + bool CopyFileTo(const rdcstr &filename); // Sets the parameters of an RDCFile in memory. - void SetData(RDCDriver driver, const char *driverName, uint64_t machineIdent, + void SetData(RDCDriver driver, const rdcstr &driverName, uint64_t machineIdent, const RDCThumb *thumb, uint64_t timeBase, double timeFreq); // creates a new file with current properties, file will be overwritten if it already exists - void Create(const char *filename); + void Create(const rdcstr &filename); ContainerError ErrorCode() const { return m_Error; } rdcstr ErrorString() const { return m_ErrorString; } @@ -92,7 +92,7 @@ public: double GetTimestampFrequency() const { return m_TimeFrequency; } const RDCThumb &GetThumbnail() const { return m_Thumb; } int SectionIndex(SectionType type) const; - int SectionIndex(const char *name) const; + int SectionIndex(const rdcstr &name) const; int NumSections() const { return int(m_Sections.size()); } const SectionProperties &GetSectionProperties(int index) const { return m_Sections[index]; } StreamReader *ReadSection(int index) const; diff --git a/renderdoc/serialise/serialiser.cpp b/renderdoc/serialise/serialiser.cpp index 1b896f0e7..acd84805e 100644 --- a/renderdoc/serialise/serialiser.cpp +++ b/renderdoc/serialise/serialiser.cpp @@ -43,7 +43,7 @@ void DumpObject(FileIO::LogFileHandle *log, const rdcstr &indent, SDObject *obj) rdcstr msg = StringFormat::Fmt("%s%s%s %s:\n", indent.c_str(), obj->type.name.c_str(), obj->type.basetype == SDBasic::Array ? "[]" : "", obj->name.c_str()); - FileIO::logfile_append(log, msg.c_str(), msg.size()); + FileIO::logfile_append(log, msg.c_str(), msg.length()); for(size_t i = 0; i < obj->NumChildren(); i++) DumpObject(log, indent + " ", obj->GetChild(i)); } @@ -71,7 +71,7 @@ void DumpObject(FileIO::LogFileHandle *log, const rdcstr &indent, SDObject *obj) } rdcstr msg = StringFormat::Fmt("%s%s %s = %s\n", indent.c_str(), obj->type.name.c_str(), obj->name.c_str(), val.c_str()); - FileIO::logfile_append(log, msg.c_str(), msg.size()); + FileIO::logfile_append(log, msg.c_str(), msg.length()); } } @@ -79,7 +79,7 @@ void DumpChunk(bool reading, FileIO::LogFileHandle *log, SDChunk *chunk) { rdcstr msg = StringFormat::Fmt("%s %s @ %llu:\n", reading ? "Read" : "Wrote", chunk->name.c_str(), chunk->metadata.timestampMicro); - FileIO::logfile_append(log, msg.c_str(), msg.size()); + FileIO::logfile_append(log, msg.c_str(), msg.length()); DumpObject(log, " ", chunk); } diff --git a/renderdoc/serialise/serialiser_tests.cpp b/renderdoc/serialise/serialiser_tests.cpp index 75fb8fe35..f39908781 100644 --- a/renderdoc/serialise/serialiser_tests.cpp +++ b/renderdoc/serialise/serialiser_tests.cpp @@ -487,7 +487,7 @@ TEST_CASE("Read/writing large buffers", "[serialiser]") { WriteSerialiser ser(new StreamWriter(StreamWriter::DefaultScratchSize), Ownership::Stream); WriteSerialiser fileser( - new StreamWriter(FileIO::fopen(filename.c_str(), "wb"), Ownership::Stream), + new StreamWriter(FileIO::fopen(filename, FileIO::WriteBinary), Ownership::Stream), Ownership::Stream); uint32_t dummy1 = 99; @@ -530,7 +530,7 @@ TEST_CASE("Read/writing large buffers", "[serialiser]") for(size_t pass = 0; pass < 2; pass++) { - StreamReader reader(FileIO::fopen(filename.c_str(), "rb")); + StreamReader reader(FileIO::fopen(filename, FileIO::ReadBinary)); ReadSerialiser ser(&reader, Ownership::Nothing); @@ -592,7 +592,7 @@ TEST_CASE("Read/writing large buffers", "[serialiser]") CHECK(reader.GetOffset() == 80 * 1024 * 1024 + 64 * 4); } - FileIO::Delete(filename.c_str()); + FileIO::Delete(filename); }; TEST_CASE("Read/write chunk metadata", "[serialiser]") diff --git a/renderdoccmd/renderdoccmd.cpp b/renderdoccmd/renderdoccmd.cpp index 443b14b7a..75806cc41 100644 --- a/renderdoccmd/renderdoccmd.cpp +++ b/renderdoccmd/renderdoccmd.cpp @@ -259,7 +259,7 @@ public: bytebuf buf; ICaptureFile *file = RENDERDOC_OpenCaptureFile(); - ReplayStatus st = file->OpenFile(infile.c_str(), "rdc", NULL); + ReplayStatus st = file->OpenFile(conv(infile), "rdc", NULL); if(st == ReplayStatus::Succeeded) { buf = file->GetThumbnail(type, maxsize).data; @@ -356,10 +356,8 @@ public: rdcarray env; - ExecuteResult res = - RENDERDOC_ExecuteAndInject(executable.c_str(), workingDir.empty() ? "" : workingDir.c_str(), - cmdLine.empty() ? "" : cmdLine.c_str(), env, - logFile.empty() ? "" : logFile.c_str(), opts, wait_for_exit); + ExecuteResult res = RENDERDOC_ExecuteAndInject( + conv(executable), conv(workingDir), conv(cmdLine), env, conv(logFile), opts, wait_for_exit); if(res.status != ReplayStatus::Succeeded) { @@ -430,8 +428,7 @@ public: rdcarray env; - ExecuteResult res = - RENDERDOC_InjectIntoProcess(PID, env, captureFile.c_str(), opts, wait_for_exit); + ExecuteResult res = RENDERDOC_InjectIntoProcess(PID, env, conv(captureFile), opts, wait_for_exit); if(res.status != ReplayStatus::Succeeded) { @@ -507,8 +504,7 @@ public: if(DisplayRemoteServerPreview(false, {}).system != WindowingSystem::Unknown) previewWindow = &DisplayRemoteServerPreview; - RENDERDOC_BecomeRemoteServer(host.empty() ? NULL : host.c_str(), []() { return killSignal; }, - previewWindow); + RENDERDOC_BecomeRemoteServer(conv(host), []() { return killSignal; }, previewWindow); std::cerr << std::endl << "Cleaning up from replay hosting." << std::endl; @@ -577,7 +573,7 @@ public: std::cout << "Replaying '" << filename << "' on " << remote_host << "." << std::endl; IRemoteServer *remote = NULL; - ReplayStatus status = RENDERDOC_CreateRemoteServerConnection(remote_host.c_str(), &remote); + ReplayStatus status = RENDERDOC_CreateRemoteServerConnection(conv(remote_host), &remote); if(remote == NULL || status != ReplayStatus::Succeeded) { @@ -590,10 +586,10 @@ public: std::cerr << "Copying capture file to remote server" << std::endl; - rdcstr remotePath = remote->CopyCaptureToRemote(filename.c_str(), NULL); + rdcstr remotePath = remote->CopyCaptureToRemote(conv(filename), NULL); IReplayController *renderer = NULL; - rdctie(status, renderer) = remote->OpenCapture(~0U, remotePath.c_str(), ReplayOptions(), NULL); + rdctie(status, renderer) = remote->OpenCapture(~0U, remotePath, ReplayOptions(), NULL); if(status == ReplayStatus::Succeeded) { @@ -614,7 +610,7 @@ public: ICaptureFile *file = RENDERDOC_OpenCaptureFile(); - if(file->OpenFile(filename.c_str(), "rdc", NULL) != ReplayStatus::Succeeded) + if(file->OpenFile(conv(filename), "rdc", NULL) != ReplayStatus::Succeeded) { std::cerr << "Couldn't load '" << filename << "'." << std::endl; return 1; @@ -801,7 +797,7 @@ public: ICaptureFile *file = RENDERDOC_OpenCaptureFile(); - ReplayStatus st = file->OpenFile(infile.c_str(), infmt.c_str(), NULL); + ReplayStatus st = file->OpenFile(conv(infile), conv(infmt), NULL); if(st != ReplayStatus::Succeeded) { @@ -810,7 +806,7 @@ public: return 1; } - st = file->Convert(outfile.c_str(), outfmt.c_str(), NULL, NULL); + st = file->Convert(conv(outfile), conv(outfmt), NULL, NULL); if(st != ReplayStatus::Succeeded) { @@ -996,8 +992,7 @@ public: return 0; } - env.push_back( - EnvironmentModification(type, sep, rest[i * 3 + 1].c_str(), rest[i * 3 + 2].c_str())); + env.push_back(EnvironmentModification(type, sep, conv(rest[i * 3 + 1]), conv(rest[i * 3 + 2]))); } debuglog = parser.get("debuglog"); @@ -1008,9 +1003,9 @@ public: } virtual int Execute(const CaptureOptions &) { - RENDERDOC_SetDebugLogFile(debuglog.c_str()); + RENDERDOC_SetDebugLogFile(conv(debuglog)); - ExecuteResult result = RENDERDOC_InjectIntoProcess(pid, env, capfile.c_str(), cmdopts, false); + ExecuteResult result = RENDERDOC_InjectIntoProcess(pid, env, conv(capfile), cmdopts, false); if(result.status == ReplayStatus::Succeeded) return result.ident; @@ -1107,7 +1102,7 @@ public: ICaptureFile *capfile = RENDERDOC_OpenCaptureFile(); - ReplayStatus status = capfile->OpenFile(rdc.c_str(), "", NULL); + ReplayStatus status = capfile->OpenFile(conv(rdc), "", NULL); if(status != ReplayStatus::Succeeded) { @@ -1118,7 +1113,7 @@ public: if(m_Extract) { - int idx = capfile->FindSectionByName(section.c_str()); + int idx = capfile->FindSectionByName(conv(section)); if(idx < 0) { @@ -1178,7 +1173,7 @@ public: } else // insert/embed { - int idx = capfile->FindSectionByName(section.c_str()); + int idx = capfile->FindSectionByName(conv(section)); if(idx >= 0) { diff --git a/renderdoccmd/renderdoccmd.vcxproj b/renderdoccmd/renderdoccmd.vcxproj index f89278023..4d2c870fe 100644 --- a/renderdoccmd/renderdoccmd.vcxproj +++ b/renderdoccmd/renderdoccmd.vcxproj @@ -106,7 +106,7 @@ MultiThreadedDLL true ProgramDatabase - /w44062 %(AdditionalOptions) + /w44062 /w44840 %(AdditionalOptions) Console diff --git a/renderdoccmd/renderdoccmd_win32.cpp b/renderdoccmd/renderdoccmd_win32.cpp index 758d596df..499f9cfc4 100644 --- a/renderdoccmd/renderdoccmd_win32.cpp +++ b/renderdoccmd/renderdoccmd_win32.cpp @@ -587,8 +587,8 @@ public: std::string reportPath = conv(dumpFolder) + "\\" + dumpId + ".zip"; { - rdcstr tmp = rdcstr(reportPath.c_str(), reportPath.size()); - RENDERDOC_CreateBugReport(conv(wlogpath).c_str(), conv(wdump).c_str(), tmp); + rdcstr tmp = conv(reportPath); + RENDERDOC_CreateBugReport(conv(conv(wlogpath)), conv(conv(wdump)), tmp); } for(size_t i = 0; i < reportPath.size(); i++) diff --git a/renderdocshim/renderdocshim.cpp b/renderdocshim/renderdocshim.cpp index 6714f72d0..e79f9f96f 100644 --- a/renderdocshim/renderdocshim.cpp +++ b/renderdocshim/renderdocshim.cpp @@ -37,7 +37,7 @@ struct CaptureOptions; typedef void(__cdecl *pINTERNAL_SetCaptureOptions)(const CaptureOptions *opts); typedef void(__cdecl *pINTERNAL_SetLogFile)(const char *logfile); -typedef void(__cdecl *pRENDERDOC_SetDebugLogFile)(const char *logfile); +typedef void(__cdecl *pINTERNAL_SetDebugLogFile)(const char *logfile); #if defined(RELEASE) #define LOGPRINT(txt) \ @@ -118,8 +118,8 @@ void CheckHook() (pINTERNAL_SetCaptureOptions)GetProcAddress(mod, "INTERNAL_SetCaptureOptions"); pINTERNAL_SetLogFile setlogfile = (pINTERNAL_SetLogFile)GetProcAddress(mod, "INTERNAL_SetLogFile"); - pRENDERDOC_SetDebugLogFile setdebuglog = - (pRENDERDOC_SetDebugLogFile)GetProcAddress(mod, "RENDERDOC_SetDebugLogFile"); + pINTERNAL_SetDebugLogFile setdebuglog = + (pINTERNAL_SetDebugLogFile)GetProcAddress(mod, "INTERNAL_SetDebugLogFile"); if(setopts) setopts((const CaptureOptions *)data->opts);