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

Commit 1990c1b

Browse files
Fixed bug in file pointer probing and enhanced logging
1 parent a96cf4e commit 1990c1b

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-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://msdl.microsoft.com/download/symbols"/>
5-
</appSettings>
63
<startup>
74
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
85
</startup>

SymbolFetch/FileDownloader.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,24 @@ private long ProcessFileSize(HttpWebResponse webResp, out string filePath)
339339
readStream.Read(read, 0, (int)webResp.ContentLength);
340340

341341
string file = new string(read, 0, (int)webResp.ContentLength);
342-
file = file.Substring(5, file.Length - 5); //Removing PATH: from the output
343342

344-
System.IO.FileInfo fInfo = new System.IO.FileInfo(file);
345-
if (fInfo.Exists)
343+
if (file.Contains("PATH"))
346344
{
347-
length = fInfo.Length;
348-
filePath = file;
345+
file = file.Substring(5, file.Length - 5); //Removing PATH: from the output
346+
347+
System.IO.FileInfo fInfo = new System.IO.FileInfo(file);
348+
if (fInfo.Exists)
349+
{
350+
length = fInfo.Length;
351+
filePath = file;
352+
}
353+
}
354+
else
355+
{
356+
int position= webResp.ResponseUri.PathAndQuery.IndexOf(".pdb");
357+
string fileName = webResp.ResponseUri.PathAndQuery.Substring(1, position + 3);
358+
if (!FailedFiles.ContainsKey(fileName))
359+
FailedFiles.Add(fileName, " - No matching PDBs found - " + file);
349360
}
350361

351362
return length;
@@ -422,7 +433,7 @@ private void downloadFile(Int32 fileNr)
422433

423434
if (webResp.StatusCode != HttpStatusCode.OK)
424435
{
425-
FailedFiles.Add(file.Name, webResp.StatusCode + ": " + webResp.StatusDescription);
436+
FailedFiles.Add(file.Name, " - " + webResp.StatusCode + " " + webResp.StatusDescription);
426437
}
427438
}
428439
else if(webResp.StatusCode == HttpStatusCode.OK)
@@ -443,14 +454,16 @@ private void downloadFile(Int32 fileNr)
443454
string filePath = dirPath + "\\" +
444455
file.Name;
445456
string srcFile = null;
446-
457+
FileStream reader;
447458
size = ProcessFileSize(webResp, out srcFile);
448-
var reader = new FileStream(srcFile, FileMode.Open,FileAccess.Read);
449-
writer = new FileStream(filePath,
450-
System.IO.FileMode.Create);
451459
m_currentFileSize = size;
460+
452461
if (srcFile != null)
453462
{
463+
reader = new FileStream(srcFile, FileMode.Open, FileAccess.Read);
464+
writer = new FileStream(filePath,
465+
System.IO.FileMode.Create);
466+
454467
// DownloadFile(srcFile, filePath);
455468
fireEventFromBgw(Event.FileDownloadStarted);
456469
m_currentFileProgress = 0;
@@ -546,7 +559,7 @@ public static void WriteToLog(string fileName, Exception exc)
546559
using (FileStream fs = new FileStream("Log.txt", FileMode.Append))
547560
using (StreamWriter sr = new StreamWriter(fs))
548561
{
549-
sr.WriteLine(fileName + ": " + exc.Message);
562+
sr.WriteLine(DateTime.Now.ToString() + " " + fileName + ": " + exc.Message);
550563
}
551564
}
552565

@@ -555,7 +568,7 @@ public static void WriteToLog(string fileName, string text)
555568
using (FileStream fs = new FileStream("Log.txt", FileMode.Append))
556569
using (StreamWriter sr = new StreamWriter(fs))
557570
{
558-
sr.WriteLine(fileName + ": " + text);
571+
sr.WriteLine(DateTime.Now.ToString() + " " + fileName + ": " + text);
559572
}
560573
}
561574

SymbolFetch/MainWindow.xaml.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void btnStart_Click(object sender, RoutedEventArgs e)
9898
downloader.Files.Add(fileInfo);
9999
}
100100
else
101-
downloader.FailedFiles.Add(item.ToString(), ": Invalid download URL, not probing");
101+
downloader.FailedFiles.Add(item.ToString(), " - No Debug information in PE header");
102102
}
103103

104104
downloader.Start();
@@ -258,11 +258,17 @@ private void downloader_Completed(object sender, EventArgs e)
258258
{
259259
foreach (var item in downloader.FailedFiles)
260260
{
261-
sr.WriteLine(item.Key + (!string.IsNullOrEmpty(item.Value) ? item.Value : ": Failure after probing"));
261+
sr.WriteLine(DateTime.Now.ToString() + " " + item.Key + (!string.IsNullOrEmpty(item.Value) ? item.Value : " - Failure after probing"));
262262
}
263263
}
264264

265-
MessageBox.Show("Some symbols could not be downloaded. Please check the log file for more info.", "Error");
265+
if (downloader.Files.Count > 1)
266+
{
267+
MessageBox.Show("Some symbols could not be downloaded. Please check the log file for more info.", "Error");
268+
}
269+
else
270+
MessageBox.Show("Symbol could not be downloaded. Please check the log file for more info.", "Error");
271+
266272
downloader.FailedFiles = new Dictionary<string, string>();
267273
}
268274
}

0 commit comments

Comments
 (0)