Skip to content
This repository was archived by the owner on May 29, 2020. It is now read-only.

Commit 8abbad0

Browse files
Fixed bug in PDB age
1 parent 141b104 commit 8abbad0

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

SymbolFetch/App.config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
3-
<!--<appSettings>
4-
<add key="SymbolServer" value="http://symweb"/>
5-
</appSettings>-->
63
<startup>
74
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
85
</startup>

SymbolFetch/FileDownloader.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ private void bgwDownloader_DoWork(object sender, DoWorkEventArgs e)
264264
private void calculateFilesSize()
265265
{
266266
fireEventFromBgw(Event.CalculationFileSizesStarted);
267+
bool headVerb = true;
267268
m_totalSize = 0;
268269
string message;
269270
for (Int32 fileNr = 0; fileNr < this.Files.Count; fileNr++)
@@ -274,12 +275,13 @@ private void calculateFilesSize()
274275
//Probe 1
275276
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(this.Files[fileNr].Path);
276277
webReq.UserAgent = Constants.SymbolServer;
278+
webReq.Method = "HEAD";
277279
HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponseNoException();
278280

279281
//Probe 2
280282
if (webResp.StatusCode == HttpStatusCode.NotFound)
281283
{
282-
webResp = Retry(fileNr);
284+
webResp = Retry(fileNr, headVerb);
283285
}
284286

285287
if (webResp.StatusCode == HttpStatusCode.OK)
@@ -310,12 +312,14 @@ private void calculateFilesSize()
310312
fireEventFromBgw(Event.FileSizesCalculationComplete);
311313
}
312314

313-
private HttpWebResponse Retry(int fileNr)
315+
private HttpWebResponse Retry(int fileNr, bool headVerb)
314316
{
315317
string path = this.Files[fileNr].Path;
316318
path = ProbeWithUnderscore(path);
317319
var webReq = (HttpWebRequest)System.Net.WebRequest.Create(path);
318320
webReq.UserAgent = Constants.SymbolServer;
321+
if(headVerb)
322+
webReq.Method = "HEAD";
319323
return (HttpWebResponse)webReq.GetResponseNoException();
320324
}
321325

@@ -344,11 +348,18 @@ private long ProcessFileSize(HttpWebResponse webResp, out string filePath)
344348
{
345349
file = file.Substring(5, file.Length - 5); //Removing PATH: from the output
346350

347-
System.IO.FileInfo fInfo = new System.IO.FileInfo(file);
348-
if (fInfo.Exists)
351+
try
352+
{
353+
System.IO.FileInfo fInfo = new System.IO.FileInfo(file);
354+
if (fInfo.Exists)
355+
{
356+
length = fInfo.Length;
357+
filePath = file;
358+
}
359+
}
360+
catch(Exception ex)
349361
{
350-
length = fInfo.Length;
351-
filePath = file;
362+
WriteToLog(file, ex);
352363
}
353364
}
354365
else
@@ -389,6 +400,7 @@ private void fireEventFromBgw(Event eventName)
389400

390401
private void downloadFile(Int32 fileNr)
391402
{
403+
bool headVerb = false;
392404
m_currentFileSize = 0;
393405
bool fileptr = false;
394406
fireEventFromBgw(Event.FileDownloadAttempting);
@@ -417,7 +429,7 @@ private void downloadFile(Int32 fileNr)
417429
webResp = (HttpWebResponse)webReq.GetResponseNoException();
418430
if (webResp.StatusCode == HttpStatusCode.NotFound)
419431
{
420-
webResp = Retry(fileNr);
432+
webResp = Retry(fileNr, headVerb);
421433

422434
if (webResp.StatusCode == HttpStatusCode.OK)
423435
{
@@ -433,7 +445,8 @@ private void downloadFile(Int32 fileNr)
433445

434446
if (webResp.StatusCode != HttpStatusCode.OK)
435447
{
436-
FailedFiles.Add(file.Name, " - " + webResp.StatusCode + " " + webResp.StatusDescription);
448+
if (!FailedFiles.ContainsKey(file.Name))
449+
FailedFiles.Add(file.Name, " - " + webResp.StatusCode + " " + webResp.StatusDescription);
437450
}
438451
}
439452
else if(webResp.StatusCode == HttpStatusCode.OK)
@@ -559,7 +572,7 @@ public static void WriteToLog(string fileName, Exception exc)
559572
using (FileStream fs = new FileStream("Log.txt", FileMode.Append))
560573
using (StreamWriter sr = new StreamWriter(fs))
561574
{
562-
sr.WriteLine(DateTime.Now.ToString() + " " + fileName + ": " + exc.Message);
575+
sr.WriteLine(DateTime.Now.ToString() + " " + fileName + " - " + exc.Message);
563576
}
564577
}
565578

@@ -568,7 +581,7 @@ public static void WriteToLog(string fileName, string text)
568581
using (FileStream fs = new FileStream("Log.txt", FileMode.Append))
569582
using (StreamWriter sr = new StreamWriter(fs))
570583
{
571-
sr.WriteLine(DateTime.Now.ToString() + " " + fileName + ": " + text);
584+
sr.WriteLine(DateTime.Now.ToString() + " " + fileName + " - " + text);
572585
}
573586
}
574587

SymbolFetch/MainWindow.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.IO;
66
using System.Windows;
77
using System.Windows.Input;
8+
using System.Linq;
9+
810

911
namespace SymbolFetch
1012
{
@@ -170,6 +172,9 @@ private void btnBulk_Click(object sender, RoutedEventArgs e)
170172
{
171173
fileList.Add(line);
172174
}
175+
176+
fileList = fileList.Distinct().ToList();
177+
173178
if (fileList.Count > 0)
174179
{
175180
lstFiles.Visibility = Visibility.Visible;

SymbolFetch/PeHeaderReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public struct IMAGE_DEBUG_DIRECTORY_RAW
288288
private IMAGE_DEBUG_DIRECTORY_RAW DebugInfo;
289289

290290
private string _pdbName = "";
291-
private int _pdbage = 0;
291+
private string _pdbage = "";
292292
private Guid _debugGUID;
293293

294294
#endregion Private Fields
@@ -402,7 +402,7 @@ public PeHeaderReader(string filePath)
402402
_pdbName = new string(DebugInfo.name);
403403
_pdbName = _pdbName.Remove(_pdbName.IndexOf("\0"));
404404

405-
_pdbage = (int)DebugInfo.age;
405+
_pdbage = DebugInfo.age.ToString("X");
406406
_debugGUID = DebugInfo.guid;
407407
}
408408

@@ -425,7 +425,7 @@ public static T FromBinaryReader<T>(BinaryReader reader)
425425
#region Properties
426426

427427
public string pdbName { get { return _pdbName; } }
428-
public int pdbage { get { return _pdbage; } }
428+
public string pdbage { get { return _pdbage; } }
429429
public Guid debugGUID { get { return _debugGUID; } }
430430

431431
public bool Is32BitHeader

SymbolFetch/UrlBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public string BuildUrl(string filename)
4040
SymbolServerUrl = ConfigurationReader.SymbolServerUrl;
4141

4242
if (string.IsNullOrEmpty(SymbolServerUrl))
43-
downloadURL = "http://msdl.microsoft.com/download/symbols/" + pdbName + "/" + reader.debugGUID.ToString("N").ToUpper() + reader.pdbage.ToString() + "/" + pdbName;
43+
downloadURL = "http://msdl.microsoft.com/download/symbols/" + pdbName + "/" + reader.debugGUID.ToString("N").ToUpper() + reader.pdbage + "/" + pdbName;
4444
else
45-
downloadURL = SymbolServerUrl + "/" + pdbName + "/" + reader.debugGUID.ToString("N").ToUpper() + reader.pdbage.ToString() + "/" + pdbName;
45+
downloadURL = SymbolServerUrl + "/" + pdbName + "/" + reader.debugGUID.ToString("N").ToUpper() + reader.pdbage + "/" + pdbName;
4646
}
4747
}
4848
return downloadURL;

0 commit comments

Comments
 (0)