| 7 | #pragma comment(lib,"Wininet.lib") |
| 8 | |
| 9 | bool SymbolFileInfo::SymDownloadSymbol(std::wstring localPath) { |
| 10 | std::string url = "http://msdl.microsoft.com/download/symbols"; |
| 11 | |
| 12 | _dlg.ShowCancelButton(false); |
| 13 | |
| 14 | if (url.back() != '/') |
| 15 | url += '/'; |
| 16 | |
| 17 | CString temp = _pdbFile + L"/" + _pdbSignature + L"/" + _pdbFile; |
| 18 | std::wstring symbolUrl = temp.GetBuffer(); |
| 19 | url+= std::string(symbolUrl.begin(), symbolUrl.end()); |
| 20 | std::wstring oldFileName = _pdbFile.GetBuffer(); |
| 21 | std::string deleteFile(oldFileName.begin(), oldFileName.end()); |
| 22 | std::wstring fileName = localPath + L"\\" + _pdbSignature.GetBuffer() + L"_" + _pdbFile.GetBuffer(); |
| 23 | bool isExist = std::filesystem::is_regular_file(fileName); |
| 24 | if (isExist) { |
| 25 | auto fileSize = std::filesystem::file_size(fileName); |
| 26 | if(fileSize) |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | for (auto& iter : std::filesystem::directory_iterator(localPath)) { |
| 31 | auto filename = iter.path().filename().string(); |
| 32 | if (filename.find(deleteFile.c_str()) != std::string::npos) { |
| 33 | std::filesystem::remove(iter.path()); |
| 34 | break; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | _dlg.SetMessageText(L"Starting download " + _pdbFile); |
| 39 | |
| 40 | wil::unique_handle hThread(::CreateThread(nullptr, 0, [](auto params)->DWORD { |
| 41 | SymbolFileInfo* info = (SymbolFileInfo*)params; |
| 42 | info->_dlg.DoModal(); |
| 43 | return 0; |
| 44 | }, this, 0, nullptr)); |
| 45 | |
| 46 | auto result = Download(url, fileName, "WinArk", 1000, |
| 47 | [](void* userdata,unsigned long long readBytes,unsigned long long totalBytes) { |
| 48 | CProgressDlg* pDlg = (CProgressDlg*)userdata; |
| 49 | if (totalBytes) { |
| 50 | pDlg->UpdateProgress(readBytes); |
| 51 | } |
| 52 | return true; |
| 53 | }, |
| 54 | (void*)&_dlg); |
| 55 | _dlg.EndDialog(IDCANCEL); |
| 56 | return result == downslib_error::ok ? true : false; |
| 57 | } |
| 58 | |
| 59 | bool SymbolFileInfo::GetPdbSignature(ULONG_PTR imageBase,PIMAGE_DEBUG_DIRECTORY entry) { |
| 60 | if (entry->SizeOfData < sizeof(CV_INFO_PDB20)) |
no test coverage detected