Browse Source

fix failure to run p3d file from cache without internet connection

David Rose 14 years ago
parent
commit
77552be22a

+ 10 - 1
direct/src/p3d/AppRunner.py

@@ -824,8 +824,17 @@ class AppRunner(DirectObject):
             host.readContentsFile()
             host.readContentsFile()
 
 
         if not host.downloadContentsFile(self.http):
         if not host.downloadContentsFile(self.http):
+            # Couldn't download?  Must have failed to download in the
+            # plugin as well.  But since we launched, we probably have
+            # a copy already local; let's use it.
             message = "Host %s cannot be downloaded, cannot preload %s." % (hostUrl, name)
             message = "Host %s cannot be downloaded, cannot preload %s." % (hostUrl, name)
-            raise OSError, message
+            if not host.hasContentsFile:
+                # This is weird.  How did we launch without having
+                # this file at all?
+                raise OSError, message
+
+            # Just make it a warning and continue.
+            self.notify.warning(message)
 
 
         if name == 'panda3d' and not self.pandaHostUrl:
         if name == 'panda3d' and not self.pandaHostUrl:
             # A special case: in case we don't have the PackageHostUrl
             # A special case: in case we don't have the PackageHostUrl

+ 25 - 1
direct/src/p3d/Packager.py

@@ -413,7 +413,10 @@ class Packager:
 
 
                 # Every p3dapp requires panda3d.
                 # Every p3dapp requires panda3d.
                 if 'panda3d' not in map(lambda p: p.packageName, self.requires):
                 if 'panda3d' not in map(lambda p: p.packageName, self.requires):
+                    assert not self.packager.currentPackage
+                    self.packager.currentPackage = self
                     self.packager.do_require('panda3d')
                     self.packager.do_require('panda3d')
+                    self.packager.currentPackage = None
 
 
                 # If this flag is set, enable allow_python_dev.
                 # If this flag is set, enable allow_python_dev.
                 if self.packager.allowPythonDev:
                 if self.packager.allowPythonDev:
@@ -1605,6 +1608,9 @@ class Packager:
             self.packageSeq.storeXml(xpackage, 'seq')
             self.packageSeq.storeXml(xpackage, 'seq')
             self.packageSetVer.storeXml(xpackage, 'set_ver')
             self.packageSetVer.storeXml(xpackage, 'set_ver')
 
 
+            requireHosts = {}
+            requireHosts[self.host] = True
+
             for package in self.requires:
             for package in self.requires:
                 xrequires = TiXmlElement('requires')
                 xrequires = TiXmlElement('requires')
                 xrequires.SetAttribute('name', package.packageName)
                 xrequires.SetAttribute('name', package.packageName)
@@ -1612,11 +1618,20 @@ class Packager:
                     xrequires.SetAttribute('platform', package.platform)
                     xrequires.SetAttribute('platform', package.platform)
                 if package.version:
                 if package.version:
                     xrequires.SetAttribute('version', package.version)
                     xrequires.SetAttribute('version', package.version)
+                xrequires.SetAttribute('host', package.host)
                 package.packageSeq.storeXml(xrequires, 'seq')
                 package.packageSeq.storeXml(xrequires, 'seq')
                 package.packageSetVer.storeXml(xrequires, 'set_ver')
                 package.packageSetVer.storeXml(xrequires, 'set_ver')
-                xrequires.SetAttribute('host', package.host)
+                requireHosts[package.host] = True
                 xpackage.InsertEndChild(xrequires)
                 xpackage.InsertEndChild(xrequires)
 
 
+            # Make sure we also write the full host descriptions for
+            # any hosts we reference, so we can find these guys later.
+            for host in requireHosts.keys():
+                he = self.packager.hosts.get(host, None)
+                if he:
+                    xhost = he.makeXml(packager = self.packager)
+                    xpackage.InsertEndChild(xhost)
+
             self.components.sort()
             self.components.sort()
             for type, name, xcomponent in self.components:
             for type, name, xcomponent in self.components:
                 xpackage.InsertEndChild(xcomponent)
                 xpackage.InsertEndChild(xcomponent)
@@ -1643,6 +1658,15 @@ class Packager:
             self.version = xpackage.Attribute('version')
             self.version = xpackage.Attribute('version')
             self.host = xpackage.Attribute('host')
             self.host = xpackage.Attribute('host')
 
 
+            # Get any new host descriptors.
+            xhost = xpackage.FirstChildElement('host')
+            while xhost:
+                he = self.packager.HostEntry()
+                he.loadXml(xhost, self)
+                if he.url not in self.packager.hosts:
+                    self.packager.hosts[he.url] = he
+                xhost = xhost.NextSiblingElement('host')
+
             self.packageSeq.loadXml(xpackage, 'seq')
             self.packageSeq.loadXml(xpackage, 'seq')
             self.packageSetVer.loadXml(xpackage, 'set_ver')
             self.packageSetVer.loadXml(xpackage, 'set_ver')
 
 

+ 18 - 2
direct/src/plugin/p3dHost.I

@@ -13,15 +13,31 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: P3DHost::has_host_dir
+//       Access: Public
+//  Description: Returns true if the host_dir has already been set,
+//               false if not.  If this returns true it is safe to
+//               call get_host_dir().
+////////////////////////////////////////////////////////////////////
+inline bool P3DHost::
+has_host_dir() const {
+  return (!_host_dir.empty());
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DHost::get_host_dir
 //     Function: P3DHost::get_host_dir
 //       Access: Public
 //       Access: Public
 //  Description: Returns the local directory into which files
 //  Description: Returns the local directory into which files
-//               downloaded from this host will be installed.
+//               downloaded from this host will be installed.  It may
+//               not be safe to call this before the host has fully
+//               bootstrapped; if there is some danger of calling this
+//               early in the initialization process, you should check
+//               has_host_dir() first.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 inline const string &P3DHost::
 inline const string &P3DHost::
 get_host_dir() const {
 get_host_dir() const {
-  assert(!_host_dir.empty());
+  assert(has_host_dir());
   return _host_dir;
   return _host_dir;
 }
 }
 
 

+ 1 - 0
direct/src/plugin/p3dHost.h

@@ -34,6 +34,7 @@ private:
   ~P3DHost();
   ~P3DHost();
 
 
 public:
 public:
+  inline bool has_host_dir() const;
   inline const string &get_host_dir() const;
   inline const string &get_host_dir() const;
   inline const string &get_host_url() const;
   inline const string &get_host_url() const;
   inline const string &get_host_url_prefix() const;
   inline const string &get_host_url_prefix() const;

+ 14 - 5
direct/src/plugin/p3dPackage.cxx

@@ -446,11 +446,20 @@ contents_file_download_finished(bool success) {
       }
       }
 
 
       // Maybe we can read an already-downloaded contents.xml file.
       // Maybe we can read an already-downloaded contents.xml file.
-      string standard_filename = _host->get_host_dir() + "/contents.xml";
-      if (_host->get_host_dir().empty() || 
-          !_host->read_contents_file(standard_filename, false)) {
-        // Couldn't even read that.  Fail.
-        nout << "Couldn't read " << standard_filename << "\n";
+      bool success = false;
+      if (_host->has_host_dir()) {
+        string standard_filename = _host->get_host_dir() + "/contents.xml";
+        if (_host->read_contents_file(standard_filename, false)) {
+          success = true;
+        } else {
+          nout << "Couldn't read " << standard_filename << "\n";
+        }
+      } else {
+        nout << "No host_dir available for " << _host->get_host_url()
+             << "\n";
+      }
+      if (!success) {
+        // Couldn't read an already-downloaded file either.  Fail.
         report_done(false);
         report_done(false);
         if (_temp_contents_file) {
         if (_temp_contents_file) {
           delete _temp_contents_file;
           delete _temp_contents_file;