Browse Source

Further package download logic fixes to ensure a package is not potentially entered into the resource cache several times, and that packages in the cache are scanned for only when necessary.

Lasse Öörni 11 years ago
parent
commit
5e8b50c9d3
1 changed files with 17 additions and 11 deletions
  1. 17 11
      Source/Engine/Network/Connection.cpp

+ 17 - 11
Source/Engine/Network/Connection.cpp

@@ -1304,8 +1304,7 @@ bool Connection::RequestNeededPackages(unsigned numPackages, MemoryBuffer& msg)
     
     
     Vector<SharedPtr<PackageFile> > packages = cache->GetPackageFiles();
     Vector<SharedPtr<PackageFile> > packages = cache->GetPackageFiles();
     Vector<String> downloadedPackages;
     Vector<String> downloadedPackages;
-    if (!packageCacheDir.Empty())
-        GetSubsystem<FileSystem>()->ScanDir(downloadedPackages, packageCacheDir, "*.*", SCAN_FILES, false);
+    bool packagesScanned = false;
     
     
     for (unsigned i = 0; i < numPackages; ++i)
     for (unsigned i = 0; i < numPackages; ++i)
     {
     {
@@ -1327,6 +1326,21 @@ bool Connection::RequestNeededPackages(unsigned numPackages, MemoryBuffer& msg)
             }
             }
         }
         }
         
         
+        if (found)
+            continue;
+        
+        if (!packagesScanned)
+        {
+            if (packageCacheDir.Empty())
+            {
+                LOGERROR("Can not check/download required packages, as package cache directory is not set");
+                return false;
+            }
+            
+            GetSubsystem<FileSystem>()->ScanDir(downloadedPackages, packageCacheDir, "*.*", SCAN_FILES, false);
+            packagesScanned = true;
+        }
+        
         // Then the download cache
         // Then the download cache
         for (unsigned j = 0; j < downloadedPackages.Size(); ++j)
         for (unsigned j = 0; j < downloadedPackages.Size(); ++j)
         {
         {
@@ -1348,15 +1362,7 @@ bool Connection::RequestNeededPackages(unsigned numPackages, MemoryBuffer& msg)
         
         
         // Package not found, need to request a download
         // Package not found, need to request a download
         if (!found)
         if (!found)
-        {
-            if (!packageCacheDir.Empty())
-                RequestPackage(name, fileSize, checksum);
-            else
-            {
-                LOGERROR("Can not download required packages, as package cache directory is not set");
-                return false;
-            }
-        }
+            RequestPackage(name, fileSize, checksum);
     }
     }
     
     
     return true;
     return true;