ソースを参照

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 年 前
コミット
5e8b50c9d3
1 ファイル変更17 行追加11 行削除
  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<String> downloadedPackages;
-    if (!packageCacheDir.Empty())
-        GetSubsystem<FileSystem>()->ScanDir(downloadedPackages, packageCacheDir, "*.*", SCAN_FILES, false);
+    bool packagesScanned = false;
     
     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
         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
         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;