mirror of
https://github.com/SteamRE/DepotDownloader.git
synced 2026-10-19 15:51:50 +00:00
Fix potential collision when creating directories. Remove staging files from unclean exit.
This commit is contained in:
1 parent
6f6eb5f48a
commit
2d82c9dd5e
1 file changed
+23
-18
@@ -547,39 +547,44 @@ namespace DepotDownloader
|
||||
|
||||
newProtoManifest = new ProtoManifest(depotManifest, depot.manifestId);
|
||||
|
||||
foreach (var file in depotManifest.Files)
|
||||
// Pre-process
|
||||
depotManifest.Files.ForEach(file =>
|
||||
{
|
||||
var fileFinalPath = Path.Combine(depot.installDir, file.FileName);
|
||||
var fileStagingPath = Path.Combine(stagingDir, file.FileName);
|
||||
|
||||
if (file.Flags.HasFlag(EDepotFileFlag.Directory))
|
||||
{
|
||||
Directory.CreateDirectory(fileFinalPath);
|
||||
Directory.CreateDirectory(fileStagingPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Some manifests don't explicitly include all necessary directories
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fileFinalPath));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(fileStagingPath));
|
||||
|
||||
complete_download_size += file.TotalSize;
|
||||
}
|
||||
});
|
||||
|
||||
var rand = new Random();
|
||||
|
||||
depotManifest.Files.AsParallel().WithDegreeOfParallelism(4).ForAll(file =>
|
||||
depotManifest.Files.Where(f => !f.Flags.HasFlag(EDepotFileFlag.Directory))
|
||||
.AsParallel().WithDegreeOfParallelism(4)
|
||||
.ForAll(file =>
|
||||
{
|
||||
var clientIndex = rand.Next(0, cdnClients.Count);
|
||||
|
||||
string download_path = Path.Combine(depot.installDir, file.FileName);
|
||||
string fileStagingPath = Path.Combine(stagingDir, file.FileName);
|
||||
|
||||
if (file.Flags.HasFlag(EDepotFileFlag.Directory))
|
||||
// This may still exist if the previous run exited before cleanup
|
||||
if (File.Exists(fileStagingPath))
|
||||
{
|
||||
if (!Directory.Exists(download_path))
|
||||
Directory.CreateDirectory(download_path);
|
||||
if (!Directory.Exists(fileStagingPath))
|
||||
Directory.CreateDirectory(fileStagingPath);
|
||||
return;
|
||||
File.Delete(fileStagingPath);
|
||||
}
|
||||
|
||||
// TODO: review this section compared to above
|
||||
string dir_path = Path.GetDirectoryName(download_path);
|
||||
string dir_staging_path = Path.GetDirectoryName(fileStagingPath);
|
||||
|
||||
if (!Directory.Exists(dir_path))
|
||||
Directory.CreateDirectory(dir_path);
|
||||
if (!Directory.Exists(Path.Combine(stagingDir, dir_path)))
|
||||
Directory.CreateDirectory(dir_staging_path);
|
||||
////
|
||||
|
||||
FileStream fs = null;
|
||||
List<DepotManifest.ChunkData> neededChunks;
|
||||
FileInfo fi = new FileInfo(download_path);
|
||||
|
||||
Reference in new issue
Block a user