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

Function UploadDialogProc

src/windows/UploadDialog.cpp:134–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134INT_PTR CALLBACK UploadDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
135{
136 UploadDialogData* pData = (UploadDialogData*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
137
138 switch (uMsg)
139 {
140 case WM_INITDIALOG:
141 {
142 Channel* pChan = GetDiscordInstance()->GetCurrentChannel();
143 if (!pChan) {
144 EndDialog(hWnd, IDCANCEL);
145 return TRUE;
146 }
147 if (!pChan->HasPermission(PERM_SEND_MESSAGES) ||
148 !pChan->HasPermission(PERM_ATTACH_FILES)) {
149 EndDialog(hWnd, IDCANCEL);
150 return TRUE;
151 }
152
153 SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lParam);
154 pData = (UploadDialogData*)lParam;
155 pData->m_comment[0] = 0;
156
157 if (pData->m_lpstrFile)
158 {
159 DbgPrintW("Reading file %S", pData->m_lpstrFile);
160
161 int erc = UploadDialogTryReadFile(pData->m_lpstrFile, pData->m_fileSize, pData->m_pFileData);
162 if (erc > 0) {
163 g_FailDialogs[erc](hWnd);
164 EndDialog(hWnd, IDCANCEL);
165 return TRUE;
166 }
167
168 // TODO: Win32 docs say we should do this in a background thread.
169#ifdef UNICODE
170 DbgPrintW("Getting file info for %S", pData->m_lpstrFile);
171#else
172 DbgPrintW("Getting file info for %s", pData->m_lpstrFile);
173#endif
174 ri::SHGetFileInfo(pData->m_lpstrFile, 0, &pData->m_sfi, sizeof(SHFILEINFO), SHGFI_ICON);
175 DbgPrintW("Got the file info!");
176 }
177 else
178 {
179 DbgPrintW("Using memory file to upload");
180
181 // Load in not-shared mode, so that DestroyIcon works
182 pData->m_sfi.hIcon = (HICON) ri::LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_FILE), IMAGE_ICON, 0, 0, LR_CREATEDIBSECTION);
183 }
184
185 SetDlgItemText(hWnd, IDC_FILE_NAME, pData->m_lpstrFileTitle);
186
187 LPTSTR tstr = ConvertCppStringToTString("#" + pChan->m_name);
188 SetDlgItemText(hWnd, IDC_CHANNEL_NAME, tstr);
189 SendMessage(GetDlgItem(hWnd, IDC_CHANNEL_NAME), WM_SETFONT, (WPARAM)g_AuthorTextFont, TRUE);
190 free(tstr);
191

Callers

nothing calls this directly

Calls 7

GetDiscordInstanceFunction · 0.85
DbgPrintWFunction · 0.85
UploadDialogTryReadFileFunction · 0.85
CenterWindowFunction · 0.85
HasPermissionMethod · 0.80
GetCurrentChannelMethod · 0.45

Tested by

no test coverage detected