More cleanup:

- Don't calculate matching chunks if file hash matches (now that related SK2 bug is fixed).
- When file doesn't already exist, set length immediately after creation.
- Remove redundant file existance check before copying existing file to staging.
- Normalize more var names.
- Print account name for which password is asked.
pull/8/head
Nicholas Hastings 12 years ago
parent 2d82c9dd5e
commit de37262e9d

@ -576,7 +576,7 @@ namespace DepotDownloader
{
var clientIndex = rand.Next(0, cdnClients.Count);
string download_path = Path.Combine(depot.installDir, file.FileName);
string fileFinalPath = Path.Combine(depot.installDir, file.FileName);
string fileStagingPath = Path.Combine(stagingDir, file.FileName);
// This may still exist if the previous run exited before cleanup
@ -587,11 +587,12 @@ namespace DepotDownloader
FileStream fs = null;
List<DepotManifest.ChunkData> neededChunks;
FileInfo fi = new FileInfo(download_path);
FileInfo fi = new FileInfo(fileFinalPath);
if (!fi.Exists)
{
// create new file. need all chunks
fs = File.Create(download_path);
fs = File.Create(fileFinalPath);
fs.SetLength((long)file.TotalSize);
neededChunks = new List<DepotManifest.ChunkData>(file.Chunks);
}
else
@ -607,7 +608,9 @@ namespace DepotDownloader
{
neededChunks = new List<DepotManifest.ChunkData>();
// we have a version of this file. it may or may not match what we want
if (oldManifestFile.FileHash != file.FileHash)
{
// we have a version of this file, but it doesn't fully match what we want
var matchingChunks = new List<ChunkMatch>();
@ -624,14 +627,9 @@ namespace DepotDownloader
}
}
// can't use FileHash here. It doesn't seem to actually change...
if (matchingChunks.Count != file.Chunks.Count)
{
if (File.Exists(download_path))
{
File.Move(download_path, fileStagingPath);
File.Move(fileFinalPath, fileStagingPath);
fs = File.Open(download_path, FileMode.Create);
fs = File.Open(fileFinalPath, FileMode.Create);
fs.SetLength((long)file.TotalSize);
using (var fsOld = File.Open(fileStagingPath, FileMode.Open))
@ -649,30 +647,24 @@ namespace DepotDownloader
File.Delete(fileStagingPath);
}
else
{
fs = File.Open(download_path, FileMode.Create);
fs.SetLength((long)file.TotalSize);
neededChunks = new List<DepotManifest.ChunkData>(file.Chunks);
}
}
}
else
{
fs = File.Open(download_path, FileMode.Open);
// No old manifest or file not in old manifest. We must validate.
fs = File.Open(fileFinalPath, FileMode.Open);
if ((ulong)fi.Length != file.TotalSize)
{
fs.SetLength((long)file.TotalSize);
}
// find which chunks we need, in order so that we aren't seeking every which way
neededChunks = Util.ValidateSteam3FileChecksums(fs, file.Chunks.OrderBy(x => x.Offset).ToArray());
}
if (neededChunks.Count() == 0)
{
size_downloaded += file.TotalSize;
Console.WriteLine("{0,6:#00.00}% {1}", ((float)size_downloaded / (float)complete_download_size) * 100.0f, download_path);
Console.WriteLine("{0,6:#00.00}% {1}", ((float)size_downloaded / (float)complete_download_size) * 100.0f, fileFinalPath);
if (fs != null)
fs.Close();
return;
@ -725,7 +717,7 @@ namespace DepotDownloader
fs.Close();
Console.WriteLine("{0,6:#00.00}% {1}", ((float)size_downloaded / (float)complete_download_size) * 100.0f, download_path);
Console.WriteLine("{0,6:#00.00}% {1}", ((float)size_downloaded / (float)complete_download_size) * 100.0f, fileFinalPath);
});
newProtoManifest.SaveToFile(Path.Combine(configDir, string.Format("{0}.bin", depot.id)));

@ -92,7 +92,7 @@ namespace DepotDownloader
if (username != null && password == null)
{
Console.Write("Enter account password: ");
Console.Write("Enter account password for \"{0}\": ", username);
password = Util.ReadPassword();
Console.WriteLine();
}

Loading…
Cancel
Save