MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / DownloadFileDialog

Function DownloadFileDialog

src/windows/WinUtils.cpp:922–981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

920}
921
922void DownloadFileDialog(HWND hWnd, const std::string& url, const std::string& fileName)
923{
924 const int MAX_FILE = 4096;
925
926 LPTSTR fileTitle2 = ConvertCppStringToTString(fileName);
927
928 LPTSTR buff = (LPTSTR) new TCHAR[MAX_FILE];
929 buff[MAX_FILE - 1] = 0;
930 buff[0] = 0;
931 _tcsncpy(buff, fileTitle2, MAX_FILE);
932 free(fileTitle2);
933
934 OPENFILENAME ofn{};
935 ofn.lStructSize = SIZEOF_OPENFILENAME_NT4;
936 ofn.hwndOwner = hWnd;
937 ofn.hInstance = g_hInstance;
938 ofn.lpstrFilter = GetFilter(fileName);
939 ofn.lpstrFile = buff;
940 ofn.nMaxFile = MAX_FILE;
941 ofn.lpstrTitle = TmGetTString(IDS_SAVE_FILE_AS_TITLE);
942
943 int nFileExtension = 0;
944 for (int i = int(fileName.size()) - 1; i > 0 && !nFileExtension; i--)
945 {
946 if (fileName[i] == '.')
947 nFileExtension = i + 1;
948 }
949
950 ofn.nFileExtension = nFileExtension;
951 ofn.lpstrDefExt = nFileExtension ? (buff + nFileExtension) : TEXT("");
952
953 std::string fileNameSave;
954
955 if (!GetSaveFileName(&ofn)) {
956 // maybe they cancelled. I hope there's no error!
957 goto _cleanup;
958 }
959
960 // perform the save
961 fileNameSave = MakeStringFromTString(ofn.lpstrFile);
962
963 GetHTTPClient()->PerformRequest(
964 true,
965 NetRequest::GET_PROGRESS,
966 url,
967 0,
968 (uint64_t) hWnd,
969 "",
970 "",
971 fileNameSave,
972 DownloadFileResponse
973 );
974
975 SendMessage(hWnd, WM_IMAGESAVING, 0, 0);
976
977 ProgressDialog::Show(fileNameSave, (Snowflake) hWnd, false, hWnd);
978
979_cleanup:

Callers 3

ImageViewerRequestSaveFunction · 0.85
WindowProcFunction · 0.85
OpenAttachmentMethod · 0.85

Calls 5

GetFilterFunction · 0.85
GetHTTPClientFunction · 0.85
PerformRequestMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected