Browse Source

more tempfile nonsense

David Rose 16 years ago
parent
commit
42bef14dac
2 changed files with 38 additions and 4 deletions
  1. 36 3
      direct/src/plugin/p3dInstanceManager.cxx
  2. 2 1
      direct/src/plugin/p3dInstanceManager.h

+ 36 - 3
direct/src/plugin/p3dInstanceManager.cxx

@@ -278,7 +278,8 @@ initialize(const string &contents_filename, const string &download_url,
 //       Access: Public
 //       Access: Public
 //  Description: Reads the contents.xml file in the indicated
 //  Description: Reads the contents.xml file in the indicated
 //               filename.  On success, copies the contents.xml file
 //               filename.  On success, copies the contents.xml file
-//               into the standard location.
+//               into the standard location (if it's not there
+//               already).
 //
 //
 //               Returns true on success, false on failure.
 //               Returns true on success, false on failure.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -300,7 +301,8 @@ read_contents_file(const string &contents_filename) {
   _xcontents = (TiXmlElement *)xcontents->Clone();
   _xcontents = (TiXmlElement *)xcontents->Clone();
 
 
   string standard_filename = _root_dir + "/contents.xml";
   string standard_filename = _root_dir + "/contents.xml";
-  if (standard_filename != contents_filename) {
+  if (standardize_filename(standard_filename) != 
+      standardize_filename(contents_filename)) {
     copy_file(contents_filename, standard_filename);
     copy_file(contents_filename, standard_filename);
   }
   }
 
 
@@ -696,9 +698,39 @@ delete_global_ptr() {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: P3DInstanceManager::standardize_filename
+//       Access: Private, Static
+//  Description: Attempts to change the filename into some standard
+//               form for comparison with other filenames.  On a
+//               case-insensitive filesystem, this converts the
+//               filename to lowercase.  On Windows, it further
+//               replaces forward slashes with backslashes.
+////////////////////////////////////////////////////////////////////
+string P3DInstanceManager::
+standardize_filename(const string &filename) {
+#if defined(_WIN32) || defined(__APPLE__)
+  string new_filename;
+  for (string::const_iterator si = filename.begin();
+       si != filename.end();
+       ++si) {
+    char ch = *si;
+#ifdef _WIN32
+    if (ch == '/') {
+      ch = '\\';
+    }
+#endif  // _WIN32
+    new_filename += tolower(ch);
+  }
+  return new_filename;
+#else  // _WIN32 || __APPLE__
+  return filename;
+#endif  // _WIN32 || __APPLE__
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DInstanceManager::copy_file
 //     Function: P3DInstanceManager::copy_file
-//       Access: Private
+//       Access: Private, Static
 //  Description: Copies the data in the file named by from_filename
 //  Description: Copies the data in the file named by from_filename
 //               into the file named by to_filename.
 //               into the file named by to_filename.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -734,6 +766,7 @@ copy_file(const string &from_filename, const string &to_filename) {
     in.read(buffer, buffer_size);
     in.read(buffer, buffer_size);
     count = in.gcount();
     count = in.gcount();
   }
   }
+  out.close();
 
 
   if (!in.eof()) {
   if (!in.eof()) {
     unlink(temp_filename.c_str());
     unlink(temp_filename.c_str());

+ 2 - 1
direct/src/plugin/p3dInstanceManager.h

@@ -98,7 +98,8 @@ public:
   static void delete_global_ptr();
   static void delete_global_ptr();
 
 
 private:
 private:
-  bool copy_file(const string &from_filename, const string &to_filename);
+  static string standardize_filename(const string &filename);
+  static bool copy_file(const string &from_filename, const string &to_filename);
 
 
 private:
 private:
   // The notify thread.  This thread runs only for the purpose of
   // The notify thread.  This thread runs only for the purpose of