Notify about pre-allocation. Just lock the counter object.

pull/132/head
Ryan Kistner 6 years ago
parent ea911fde13
commit 3db9c5dbe3

@ -602,16 +602,16 @@ namespace DepotDownloader
private class GlobalDownloadCounter private class GlobalDownloadCounter
{ {
public long TotalBytesCompressed; public ulong TotalBytesCompressed;
public long TotalBytesUncompressed; public ulong TotalBytesUncompressed;
} }
private class DepotDownloadCounter private class DepotDownloadCounter
{ {
public long CompleteDownloadSize; public ulong CompleteDownloadSize;
public long SizeDownloaded; public ulong SizeDownloaded;
public long DepotBytesCompressed; public ulong DepotBytesCompressed;
public long DepotBytesUncompressed; public ulong DepotBytesUncompressed;
} }
@ -831,7 +831,7 @@ namespace DepotDownloader
Directory.CreateDirectory(Path.GetDirectoryName(fileFinalPath)); Directory.CreateDirectory(Path.GetDirectoryName(fileFinalPath));
Directory.CreateDirectory(Path.GetDirectoryName(fileStagingPath)); Directory.CreateDirectory(Path.GetDirectoryName(fileStagingPath));
Interlocked.Add(ref depotCounter.CompleteDownloadSize, (long)file.TotalSize); depotCounter.CompleteDownloadSize += file.TotalSize;
} }
}); });
@ -884,6 +884,8 @@ namespace DepotDownloader
FileInfo fi = new FileInfo(fileFinalPath); FileInfo fi = new FileInfo(fileFinalPath);
if (!fi.Exists) if (!fi.Exists)
{ {
Console.WriteLine("Pre-allocating {0}", fileFinalPath);
// create new file. need all chunks // create new file. need all chunks
fs = File.Create(fileFinalPath); fs = File.Create(fileFinalPath);
fs.SetLength((long)file.TotalSize); fs.SetLength((long)file.TotalSize);
@ -973,8 +975,11 @@ namespace DepotDownloader
if (neededChunks.Count() == 0) if (neededChunks.Count() == 0)
{ {
var sizeDownloaded = Interlocked.Add(ref depotDownloadCounter.SizeDownloaded, (long)file.TotalSize); lock (depotDownloadCounter)
Console.WriteLine("{0,6:#00.00}% {1}", ((float)sizeDownloaded / (float)depotDownloadCounter.CompleteDownloadSize) * 100.0f, fileFinalPath); {
depotDownloadCounter.SizeDownloaded += (ulong)file.TotalSize;
Console.WriteLine("{0,6:#00.00}% {1}", ((float)depotDownloadCounter.SizeDownloaded / (float)depotDownloadCounter.CompleteDownloadSize) * 100.0f, fileFinalPath);
}
if (fs != null) if (fs != null)
fs.Dispose(); fs.Dispose();
@ -982,8 +987,11 @@ namespace DepotDownloader
} }
else else
{ {
var sizeDownloaded = ((long)file.TotalSize - (long)neededChunks.Select(x => (long)x.UncompressedLength).Sum()); var sizeOnDisk = (file.TotalSize - (ulong)neededChunks.Select(x => (long)x.UncompressedLength).Sum());
Interlocked.Add(ref depotDownloadCounter.SizeDownloaded, sizeDownloaded); lock (depotDownloadCounter)
{
depotDownloadCounter.SizeDownloaded += sizeOnDisk;
}
} }
} }
@ -1087,19 +1095,30 @@ namespace DepotDownloader
fileStreamData.fileLock.Release(); fileStreamData.fileLock.Release();
} }
Interlocked.Add(ref downloadCounter.TotalBytesCompressed, chunk.CompressedLength);
Interlocked.Add(ref depotDownloadCounter.DepotBytesCompressed, chunk.CompressedLength);
Interlocked.Add(ref downloadCounter.TotalBytesUncompressed, chunk.UncompressedLength);
Interlocked.Add(ref depotDownloadCounter.DepotBytesUncompressed, chunk.UncompressedLength);
var sizeDownloaded = Interlocked.Add(ref depotDownloadCounter.SizeDownloaded, chunkData.Data.Length);
int remainingChunks = Interlocked.Decrement(ref fileStreamData.chunksToDownload); int remainingChunks = Interlocked.Decrement(ref fileStreamData.chunksToDownload);
if (remainingChunks == 0) if (remainingChunks == 0)
{ {
fileStreamData.fileStream.Dispose(); fileStreamData.fileStream.Dispose();
fileStreamData.fileLock.Dispose(); fileStreamData.fileLock.Dispose();
}
ulong sizeDownloaded = 0;
lock (depotDownloadCounter)
{
sizeDownloaded = depotDownloadCounter.SizeDownloaded + (ulong)chunkData.Data.Length;
depotDownloadCounter.SizeDownloaded = sizeDownloaded;
depotDownloadCounter.DepotBytesCompressed += chunk.CompressedLength;
depotDownloadCounter.DepotBytesUncompressed += chunk.UncompressedLength;
}
lock (downloadCounter)
{
downloadCounter.TotalBytesCompressed += chunk.CompressedLength;
downloadCounter.TotalBytesUncompressed += chunk.UncompressedLength;
}
if (remainingChunks == 0)
{
var fileFinalPath = Path.Combine(depot.installDir, file.FileName); var fileFinalPath = Path.Combine(depot.installDir, file.FileName);
Console.WriteLine("{0,6:#00.00}% {1}", ((float)sizeDownloaded / (float)depotDownloadCounter.CompleteDownloadSize) * 100.0f, fileFinalPath); Console.WriteLine("{0,6:#00.00}% {1}", ((float)sizeDownloaded / (float)depotDownloadCounter.CompleteDownloadSize) * 100.0f, fileFinalPath);
} }

Loading…
Cancel
Save