Browse Source

fix logfile issue

David Rose 16 years ago
parent
commit
4b99d6a3f1

+ 2 - 0
direct/src/plugin_npapi/nppanda3d_common.h

@@ -37,6 +37,8 @@ using namespace std;
 extern ostream *nout_stream;
 extern ostream *nout_stream;
 #define nout (*nout_stream)
 #define nout (*nout_stream)
 
 
+extern string global_root_dir;
+
 #ifdef _WIN32
 #ifdef _WIN32
 
 
 // Gecko requires all these symbols to be defined for Windows.
 // Gecko requires all these symbols to be defined for Windows.

+ 1 - 1
direct/src/plugin_npapi/ppInstance.cxx

@@ -61,7 +61,7 @@ PPInstance(NPMIMEType pluginType, NPP instance, uint16 mode,
     _tokens.push_back(token);
     _tokens.push_back(token);
   }
   }
 
 
-  _root_dir = find_root_dir(nout);
+  _root_dir = global_root_dir;
 
 
   _got_instance_url = false;
   _got_instance_url = false;
   _got_window = false;
   _got_window = false;

+ 12 - 1
direct/src/plugin_npapi/startup.cxx

@@ -24,6 +24,8 @@
 static ofstream logfile;
 static ofstream logfile;
 ostream *nout_stream = &logfile;
 ostream *nout_stream = &logfile;
 
 
+string global_root_dir;
+
 NPNetscapeFuncs *browser;
 NPNetscapeFuncs *browser;
 
 
 static bool logfile_is_open = false;
 static bool logfile_is_open = false;
@@ -46,7 +48,7 @@ open_logfile() {
 #endif
 #endif
       if (log_directory.empty()) {
       if (log_directory.empty()) {
 #ifdef _WIN32
 #ifdef _WIN32
-        static const size_t buffer_size = 4096;
+        static const size_t buffer_size = MAX_PATH;
         char buffer[buffer_size];
         char buffer[buffer_size];
         if (GetTempPath(buffer_size, buffer) != 0) {
         if (GetTempPath(buffer_size, buffer) != 0) {
           log_directory = buffer;
           log_directory = buffer;
@@ -56,6 +58,14 @@ open_logfile() {
 #endif  // _WIN32
 #endif  // _WIN32
       }
       }
 
 
+      // Ensure that the log directory ends with a slash.
+      if (!log_directory.empty() && log_directory[log_directory.size() - 1] != '/') {
+#ifdef _WIN32
+        if (log_directory[log_directory.size() - 1] != '\\')
+#endif
+          log_directory += "/";
+      }
+
       // Construct the full logfile pathname.
       // Construct the full logfile pathname.
       string log_pathname = log_directory;
       string log_pathname = log_directory;
       log_pathname += log_basename;
       log_pathname += log_basename;
@@ -138,6 +148,7 @@ NP_Initialize(NPNetscapeFuncs *browserFuncs,
 
 
   open_logfile();
   open_logfile();
   nout << "initializing\n";
   nout << "initializing\n";
+  global_root_dir = find_root_dir(nout);
 
 
   nout << "browserFuncs = " << browserFuncs << "\n";
   nout << "browserFuncs = " << browserFuncs << "\n";