| 920 | } |
| 921 | |
| 922 | void 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: |
no test coverage detected