From 8ba4a4a5748f36240f7c98196941993b348f56e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 24 Feb 2012 20:35:09 +0000 Subject: [PATCH] Copy wrapper dll to executable directory on windows in apitrace trace. --- common/os_string.hpp | 3 +++ common/os_win32.cpp | 12 ++++++++++++ common/trace_tools_trace.cpp | 34 ++++++++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/common/os_string.hpp b/common/os_string.hpp index c3fcf83..29ae5cf 100644 --- a/common/os_string.hpp +++ b/common/os_string.hpp @@ -373,6 +373,9 @@ public: String getProcessName(); String getCurrentDir(); +bool copyFile(const String &srcFileName, const String &dstFileName, bool override = true); + +bool removeFile(const String &fileName); } /* namespace os */ diff --git a/common/os_win32.cpp b/common/os_win32.cpp index 33fe427..e00fe64 100644 --- a/common/os_win32.cpp +++ b/common/os_win32.cpp @@ -76,6 +76,18 @@ String::exists(void) const return attrs != INVALID_FILE_ATTRIBUTES; } +bool +copyFile(const String &srcFileName, const String &dstFileName, bool override) +{ + return CopyFileA(srcFileName, dstFileName, !override); +} + +bool +removeFile(const String &srcFilename) +{ + return DeleteFileA(srcFilename); +} + /** * Determine whether an argument should be quoted. */ diff --git a/common/trace_tools_trace.cpp b/common/trace_tools_trace.cpp index dc40896..39c6ddf 100644 --- a/common/trace_tools_trace.cpp +++ b/common/trace_tools_trace.cpp @@ -89,16 +89,25 @@ traceProgram(API api, } #if defined(_WIN32) + /* On Windows copt the wrapper to the program directory. + */ + os::String wrapperName (wrapper); + wrapperName.trimDirectory(); - std::cerr << - "The 'apitrace trace' command is not supported for this operating system.\n" - "Instead, you will need to copy opengl32.dll, d3d8.dll, or d3d9.dll from\n" - APITRACE_WRAPPER_INSTALL_DIR "\n" - "to the directory with the application to trace, then run the application.\n"; + os::String tmpWrapper(argv[0]); + tmpWrapper.trimFilename(); + tmpWrapper.join(wrapperName); - return 1; + if (tmpWrapper.exists()) { + std::cerr << "error: not overwriting " << tmpWrapper << "\n"; + return 1; + } -#else + if (!os::copyFile(wrapper, tmpWrapper, false)) { + std::cerr << "error: failed to copy " << wrapper << " into " << tmpWrapper << "\n"; + return 1; + } +#endif /* _WIN32 */ #if defined(__APPLE__) /* On Mac OS X, using DYLD_LIBRARY_PATH, we actually set the @@ -106,6 +115,8 @@ traceProgram(API api, wrapper.trimFilename(); #endif +#if defined(TRACE_VARIABLE) + if (verbose) { std::cerr << TRACE_VARIABLE << "=" << wrapper.str() << "\n"; } @@ -113,6 +124,8 @@ traceProgram(API api, /* FIXME: Don't modify the current environment */ os::setEnvironment(TRACE_VARIABLE, wrapper.str()); +#endif /* TRACE_VARIABLE */ + if (output) { os::setEnvironment("TRACE_FILE", output); } @@ -128,13 +141,18 @@ traceProgram(API api, int status = os::execute(argv); +#if defined(TRACE_VARIABLE) os::unsetEnvironment(TRACE_VARIABLE); +#endif +#if defined(_WIN32) + os::removeFile(tmpWrapper); +#endif + if (output) { os::unsetEnvironment("TRACE_FILE"); } return status; -#endif } -- 2.45.2