]> git.cworth.org Git - apitrace/commitdiff
Copy wrapper dll to executable directory on windows in apitrace trace.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 24 Feb 2012 20:35:09 +0000 (20:35 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 24 Feb 2012 20:35:09 +0000 (20:35 +0000)
common/os_string.hpp
common/os_win32.cpp
common/trace_tools_trace.cpp

index c3fcf83396c405595c33e9cec55b69569bf10622..29ae5cf12bd1e37f5edb71f4ad70be5b97533bea 100644 (file)
@@ -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 */
 
index 33fe427bad7370784d32c42c416e172ed97bcd89..e00fe64bd50edeacb197d8f04a704b3bf83b9bfc 100644 (file)
@@ -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.
  */
index dc40896a222fee0968d8bdf4f883b863b9e1c8ed..39c6ddf9339b20a67592843f09147efa1df4dbb1 100644 (file)
@@ -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
 
 }