diff --git a/Data/Scripts/ImageSearch/yandex.nut b/Data/Scripts/ImageSearch/yandex.nut index 17748de1..42b779ce 100644 --- a/Data/Scripts/ImageSearch/yandex.nut +++ b/Data/Scripts/ImageSearch/yandex.nut @@ -9,7 +9,7 @@ function SearchByImage(FileName, options) { nm.setUrl("https://yandex.ru/images/search?rpt=imageview"); nm.addQueryHeader("Origin", "https://yandex.ru"); - nm.addQueryParamFile("upfile", FileName, ExtractFileName(FileName), ""); + nm.addQueryParamFile("upfile", FileName, ExtractFileName(FileName), GetFileMimeType(FileName)); nm.addQueryParam("original_width", imageInfo.Width); nm.addQueryParam("original_height", imageInfo.Height); nm.addQueryParam("prg", "1"); diff --git a/Source/Core/OutputGenerator/AbstractOutputGenerator.h b/Source/Core/OutputGenerator/AbstractOutputGenerator.h index 3c3160a3..e4ead296 100644 --- a/Source/Core/OutputGenerator/AbstractOutputGenerator.h +++ b/Source/Core/OutputGenerator/AbstractOutputGenerator.h @@ -71,7 +71,7 @@ class AbstractOutputGenerator bool loadTemplate(const std::string& templateFileName); std::string generate(const std::vector& items, bool withTemplate = true); protected: - CodeType codeType_; + CodeType codeType_ = ctTableOfThumbnails; bool preferDirectLinks_ = true, shortenUrl_ = false, groupByFile_ = false; int itemsPerLine_ = 4; std::optional templateHead_, templateFoot_; diff --git a/Source/Core/Upload/Filters/UrlShorteningFilter.cpp b/Source/Core/Upload/Filters/UrlShorteningFilter.cpp index 084b9fe2..048147d2 100644 --- a/Source/Core/Upload/Filters/UrlShorteningFilter.cpp +++ b/Source/Core/Upload/Filters/UrlShorteningFilter.cpp @@ -38,7 +38,6 @@ bool UrlShorteningFilter::PostUpload(UploadTask* task) shorteningTask->setParentUrlType(UrlShorteningTask::DirectUrl); task->setShorteningStarted(true); fileTask->addChildTask(shorteningTask); - res = true; } else if (!downloadUrl.empty()) { std::shared_ptr shorteningTask = std::make_shared(downloadUrl, task); @@ -47,7 +46,6 @@ bool UrlShorteningFilter::PostUpload(UploadTask* task) shorteningTask->setParentUrlType(UrlShorteningTask::DownloadUrl); task->setShorteningStarted(true); fileTask->addChildTask(shorteningTask); - res = true; } return res; } diff --git a/Source/Core/WinServerIconCache.cpp b/Source/Core/WinServerIconCache.cpp index 0505050b..854fae49 100644 --- a/Source/Core/WinServerIconCache.cpp +++ b/Source/Core/WinServerIconCache.cpp @@ -65,7 +65,7 @@ NativeIcon WinServerIconCache::getIconForServer(const std::string& name) { NativeIcon WinServerIconCache::getBigIconForServer(const std::string& name) { CString iconFileName = IuCoreUtils::Utf8ToWstring(getIconNameForServer(name, true)).c_str(); - if (!iconFileName) { + if (iconFileName.IsEmpty()) { return {}; } const int w = GetSystemMetrics(SM_CXICON); diff --git a/Source/Gui/Dialogs/AddFtpServerDialog.cpp b/Source/Gui/Dialogs/AddFtpServerDialog.cpp index fcf30dbc..9516b0a2 100644 --- a/Source/Gui/Dialogs/AddFtpServerDialog.cpp +++ b/Source/Gui/Dialogs/AddFtpServerDialog.cpp @@ -228,24 +228,21 @@ LRESULT CAddFtpServerDialog::OnClickedTestConnection(WORD wNotifyCode, WORD wID, void CAddFtpServerDialog::addServer(bool test) { CString serverName = GuiTools::GetDlgItemText(m_hWnd, IDC_SERVEREDIT); - serverName.TrimLeft(L" "); - serverName.TrimRight(L" "); + serverName.Trim(_T(" ")); if (serverName.IsEmpty()) { MessageBox(TR("Server's name cannot be empty"), TR("Error"), MB_ICONERROR); return; } CString connectionName = GuiTools::GetDlgItemText(m_hWnd, IDC_CONNECTIONNAMEEDIT); - connectionName.TrimLeft(L" "); - connectionName.TrimRight(L" "); + connectionName.Trim(_T(" ")); if (connectionName.IsEmpty()) { LocalizedMessageBox(TR("Connection name cannot be empty"), TR("Error"), MB_ICONERROR); return; } CString downloadUrl = GuiTools::GetDlgItemText(m_hWnd, IDC_DOWNLOADURLEDIT); - downloadUrl.TrimLeft(L" "); - downloadUrl.TrimRight(L" "); + downloadUrl.Trim(_T(" ")); if (downloadUrl.IsEmpty()) { LocalizedMessageBox(TR("Download URL cannot be empty."), TR("Error"), MB_ICONERROR); return; @@ -312,7 +309,6 @@ void CAddFtpServerDialog::addServer(bool test) { } else { EndDialog(IDOK); } - } catch (const std::exception& ex) { CString errorMessage = TR("Could not add server."); @@ -329,7 +325,6 @@ void CAddFtpServerDialog::enableControls(bool enable) { GuiTools::EnableDialogItem(m_hWnd, IDC_TESTCONNECTIONBTN, enable); } - LRESULT CAddFtpServerDialog::OnCtlColorMsgDlg(HDC hdc, HWND hwndChild) { if (hwndChild == GetDlgItem(IDC_CONNECTIONSTATUSLABEL)) { if (testSuccess_) { @@ -341,4 +336,4 @@ LRESULT CAddFtpServerDialog::OnCtlColorMsgDlg(HDC hdc, HWND hwndChild) { return reinterpret_cast(backgroundBrush_.m_hBrush); } return 0; -} \ No newline at end of file +} diff --git a/Source/Gui/Dialogs/FloatingWindow.cpp b/Source/Gui/Dialogs/FloatingWindow.cpp index e08e143a..ff447f70 100644 --- a/Source/Gui/Dialogs/FloatingWindow.cpp +++ b/Source/Gui/Dialogs/FloatingWindow.cpp @@ -939,7 +939,9 @@ void CFloatingWindow::ShowImageUploadedMessage(UploadTask* task, const CString& if (generatorId == gidXmlTemplate) { int templateIndex = settings->CodeType - 4; auto xmlTemplateGenerator = dynamic_cast(generator.get()); - xmlTemplateGenerator->setTemplateIndex(templateIndex); + if (xmlTemplateGenerator) { + xmlTemplateGenerator->setTemplateIndex(templateIndex); + } } code = U2W(generator->generate(objects, settings->UseTxtTemplate)); diff --git a/Source/Gui/Dialogs/FolderAddDlg.cpp b/Source/Gui/Dialogs/FolderAddDlg.cpp index 5b8aeb32..015361e1 100644 --- a/Source/Gui/Dialogs/FolderAddDlg.cpp +++ b/Source/Gui/Dialogs/FolderAddDlg.cpp @@ -7,6 +7,7 @@ #include "WizardDlg.h" #include "MainDlg.h" #include "Func/IuCommonFunctions.h" +#include "Core/Settings/WtlGuiSettings.h" CFolderAdd::CFolderAdd(CWizardDlg *WizardDlg): count(0), @@ -84,6 +85,7 @@ int CFolderAdd::ProcessDir(CString currentDir, bool bRecursive /* = true */) DWORD CFolderAdd::Run() { + auto* settings = ServiceLocator::instance()->settings(); EnableWindow(m_pWizardDlg->m_hWnd, false); ServiceLocator::instance()->taskRunner()->runInGuiThread([&] { m_pWizardDlg->beginAddFiles(); @@ -118,8 +120,12 @@ DWORD CFolderAdd::Run() GuiTools::LocalizedMessageBox(m_pWizardDlg->m_hWnd, m_bImagesOnly ? TR("No pictures were found.") : TR("No files were found."), APPNAME, MB_ICONINFORMATION); else { if (m_pWizardDlg->getQuickUploadMarker()) { + if (settings->CheckFileTypesBeforeUpload && !m_pWizardDlg->checkFileFormats(m_pWizardDlg->getSessionImageServer(), m_pWizardDlg->getSessionFileServer())) { + m_pWizardDlg->ShowPage(CWizardDlg::wpUploadSettingsPage); + } else { + m_pWizardDlg->ShowPage(CWizardDlg::wpUploadPage); + } - m_pWizardDlg->ShowPage(CWizardDlg::wpUploadPage); } else { m_pWizardDlg->ShowPage(CWizardDlg::wpMainPage); //m_pWizardDlg->getPage(CWizardDlg::wpMainPage)->ThumbsView.LoadThumbnails(); diff --git a/Source/Gui/Dialogs/HistoryWindow.cpp b/Source/Gui/Dialogs/HistoryWindow.cpp index 691c427f..494f0eb4 100644 --- a/Source/Gui/Dialogs/HistoryWindow.cpp +++ b/Source/Gui/Dialogs/HistoryWindow.cpp @@ -367,7 +367,7 @@ LRESULT CHistoryWindow::OnEditFileOnServer(WORD wNotifyCode, WORD wID, HWND hWnd TreeItem* item = m_treeView.selectedItem(); if (!item) return 0; HistoryItem* historyItem = CHistoryTreeControl::getItemData(item); - if (historyItem) { + if (!historyItem) { return 0; } WinUtils::ShellOpenFileOrUrl(U2W(historyItem->editUrl), m_hWnd); diff --git a/Source/Gui/Dialogs/MainDlg.h b/Source/Gui/Dialogs/MainDlg.h index 8618f9d8..d7bec88d 100644 --- a/Source/Gui/Dialogs/MainDlg.h +++ b/Source/Gui/Dialogs/MainDlg.h @@ -35,8 +35,6 @@ limitations under the License. class WinServerIconCache; - - class CMainDlg : public CDialogImpl,public CThreadImpl,public CWizardPage, public CMessageFilter { @@ -53,8 +51,6 @@ class CMainDlg : public CDialogImpl,public CThreadImpl,publi MENUITEM_DELETE, MENUITEM_PROPERTIES, MENUITEM_OPENWITH - - }; enum { kStatusTimer = 1 }; explicit CMainDlg(WinServerIconCache* iconCache); diff --git a/Source/Gui/Dialogs/ResultsPanel.cpp b/Source/Gui/Dialogs/ResultsPanel.cpp index 2265f91a..750d77d5 100644 --- a/Source/Gui/Dialogs/ResultsPanel.cpp +++ b/Source/Gui/Dialogs/ResultsPanel.cpp @@ -50,7 +50,6 @@ CResultsPanel::CResultsPanel(CWizardDlg *dlg, std::vectorUseTxtTemplate; + bool useTemplate = settings->UseTxtTemplate; bool preferDirectLinks = settings->UseDirectLinks; groupByFileName_ = settings->GroupByFilename; - settings->UseTxtTemplate = UseTemplate; OG::GeneratorID generatorId = OG::gidBBCode; OG::CodeLang lang = OG::clBBCode; @@ -262,10 +260,12 @@ std::string CResultsPanel::GenerateOutput() if (generatorId == OG::gidXmlTemplate) { int templateIndex = Index - 4; auto xmlTemplateGenerator = dynamic_cast(generator); - xmlTemplateGenerator->setTemplateIndex(templateIndex); + if (xmlTemplateGenerator) { + xmlTemplateGenerator->setTemplateIndex(templateIndex); + } } - return generator->generate(UrlList, UseTemplate); + return generator->generate(UrlList, useTemplate); } void CResultsPanel::UpdateOutput(bool immediately) diff --git a/Source/Gui/Dialogs/UploadSettings.cpp b/Source/Gui/Dialogs/UploadSettings.cpp index cbc23500..63deed8e 100644 --- a/Source/Gui/Dialogs/UploadSettings.cpp +++ b/Source/Gui/Dialogs/UploadSettings.cpp @@ -106,38 +106,6 @@ void CUploadSettings::settingsChanged(BasicSettings* settingsBase) } } -bool CUploadSettings::checkFileFormats() { - auto* mainDlg = WizardDlg->getPage(CWizardDlg::wpMainPage); - - auto task = std::make_shared(&mainDlg->FileList, sessionImageServer_, sessionFileServer_); - std::string message; - std::vector errors; - - boost::signals2::scoped_connection taskFinishedConnection = task->onTaskFinished.connect([&](BackgroundTask*, BackgroundTaskResult taskResult) { - if (taskResult == BackgroundTaskResult::Success) { - message = task->message(); - errors = std::move(task->errors()); - } - }); - CStatusDlg dlg(task); - if (dlg.DoModal(m_hWnd) == IDOK) { - if (!errors.empty()) { - CFileFormatCheckErrorDlg fileFormatDlg(&mainDlg->FileList, errors); - if (fileFormatDlg.DoModal() != IDOK) { - return false; - } - } - /* if (!message.empty()) { - GuiTools::LocalizedMessageBox(m_hWnd, U2W(message), TR("Error"), MB_ICONERROR); - return false; - }*/ - } else { - return false; - } - - return true; -} - void CUploadSettings::TranslateUI() { TRC(IDC_FORMATLABEL, "Format:"); @@ -432,6 +400,10 @@ bool CUploadSettings::OnNext() sessionFileServer.setShortenLinks(shorten); } + if (settings->CheckFileTypesBeforeUpload && !WizardDlg->checkFileFormats(sessionImageServer_, sessionFileServer_)) { + return false; + } + WizardDlg->setSessionImageServer(sessionImageServer_); WizardDlg->setSessionFileServer(sessionFileServer_); if ( settings->RememberImageServer ) { @@ -441,9 +413,6 @@ bool CUploadSettings::OnNext() settings->fileServer = sessionFileServer_; } - if (settings->CheckFileTypesBeforeUpload && !checkFileFormats()) { - return false; - } SaveCurrentProfile(); return true; diff --git a/Source/Gui/Dialogs/UploadSettings.h b/Source/Gui/Dialogs/UploadSettings.h index 5f5df40c..80e2ed47 100644 --- a/Source/Gui/Dialogs/UploadSettings.h +++ b/Source/Gui/Dialogs/UploadSettings.h @@ -208,7 +208,6 @@ class CUploadSettings : void updateUrlShorteningCheckboxLabel(); void shorteningUrlServerChanged(CServerSelectorControl* selectorControl); void settingsChanged(BasicSettings* settings); - bool checkFileFormats(); HWND useServerThumbnailsTooltip_; UploadEngineManager * uploadEngineManager_; CIcon iconEdit_, iconDropdown_; diff --git a/Source/Gui/Dialogs/WizardDlg.cpp b/Source/Gui/Dialogs/WizardDlg.cpp index 5972c4a3..8f60cd74 100644 --- a/Source/Gui/Dialogs/WizardDlg.cpp +++ b/Source/Gui/Dialogs/WizardDlg.cpp @@ -69,6 +69,8 @@ #include "Gui/Components/WinToastHandler.h" #include "ServerListTool/ServersCheckerDlg.h" #include "Core/WinServerIconCache.h" +#include "Core/FileTypeCheckTask.h" +#include "Gui/Dialogs/FileFormatCheckErrorDlg.h" using namespace Gdiplus; namespace @@ -646,7 +648,7 @@ LRESULT CWizardDlg::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam* pLoop->RemoveMessageFilter(this); pLoop->RemoveIdleHandler(this); - CBitmapHandle bmpOld = headBitmap_.SetBitmap(nullptr); + CBitmapHandle bmpOld { headBitmap_.SetBitmap(nullptr) }; if (bmpOld) { bmpOld.DeleteObject(); } @@ -693,7 +695,7 @@ bool CWizardDlg::ShowPage(WizardPageId idPage, int prev, int next) headBitmap_.ShowWindow(SW_HIDE); } else { headBitmap_.ShowWindow(SW_SHOW); - CBitmapHandle bmpOld = headBitmap_.SetBitmap(bmp); + CBitmapHandle bmpOld { headBitmap_.SetBitmap(bmp) }; if (bmpOld) { bmpOld.DeleteObject(); } @@ -1435,9 +1437,10 @@ bool CWizardDlg::funcAddImages(bool AnyFiles) CString filterBuffer = CString(TR("Images")) + _T(" (jpeg, bmp, png, gif ...)"); CString imageFilter = IuCommonFunctions::PrepareFileDialogImageFilter(); + CString anyFileStr = TR("Any file"); COMDLG_FILTERSPEC aFileTypes[] = { {filterBuffer, imageFilter}, - {TR("Any file"), _T("*.*")} + {anyFileStr, _T("*.*") } }; DWORD dwFlags = 0; @@ -1894,7 +1897,7 @@ bool CWizardDlg::funcMediaInfo() #endif bool CWizardDlg::funcAddFiles() { - IMyFileDialog::FileFilterArray filters = { + IMyFileDialog::FileFilterArray filters { { CString(TR("Images")) + _T(" (jpeg, bmp, png, gif ...)"), IuCommonFunctions::PrepareFileDialogImageFilter() }, { CString(TR("Video files")) + _T(" (avi, mpg, vob, wmv ...)"), PrepareVideoDialogFilters(), }, { TR("Any file"), _T("*.*") } @@ -2487,3 +2490,36 @@ void CWizardDlg::endAddFiles() { } MainDlg->ThumbsView.endAdd(); } + +bool CWizardDlg::checkFileFormats(const ServerProfileGroup& imageServer, const ServerProfileGroup& fileServer) +{ + auto* mainDlg = getPage(CWizardDlg::wpMainPage); + + auto task = std::make_shared(&mainDlg->FileList, sessionImageServer_, sessionFileServer_); + std::string message; + std::vector errors; + + boost::signals2::scoped_connection taskFinishedConnection = task->onTaskFinished.connect([&](BackgroundTask*, BackgroundTaskResult taskResult) { + if (taskResult == BackgroundTaskResult::Success) { + message = task->message(); + errors = std::move(task->errors()); + } + }); + CStatusDlg dlg(task); + if (dlg.DoModal(m_hWnd) == IDOK) { + if (!errors.empty()) { + CFileFormatCheckErrorDlg fileFormatDlg(&mainDlg->FileList, errors); + if (fileFormatDlg.DoModal() != IDOK) { + return false; + } + } + /* if (!message.empty()) { + GuiTools::LocalizedMessageBox(m_hWnd, U2W(message), TR("Error"), MB_ICONERROR); + return false; + }*/ + } else { + return false; + } + + return true; +} diff --git a/Source/Gui/Dialogs/WizardDlg.h b/Source/Gui/Dialogs/WizardDlg.h index 0e31c7cf..0575165e 100644 --- a/Source/Gui/Dialogs/WizardDlg.h +++ b/Source/Gui/Dialogs/WizardDlg.h @@ -272,6 +272,8 @@ class CWizardDlg : void beginAddFiles(); void endAddFiles(); void showScreenshotCopiedToClipboardMessage(std::shared_ptr resultBitmap); + bool checkFileFormats(const ServerProfileGroup& imageServer, const ServerProfileGroup& fileServer); + protected: bool acceptsDragnDrop() const; CIcon hIcon; diff --git a/Source/Gui/FileList.h b/Source/Gui/FileList.h index 35b414d4..705010cd 100644 --- a/Source/Gui/FileList.h +++ b/Source/Gui/FileList.h @@ -7,7 +7,7 @@ class CFileListItem: public IFileListItem { CString FilePath; CString FileName; CString VirtualFileName; - bool selected; + bool selected = false; std::string getFileName() const override; std::string getMimeType() const override; void setMimeType(const std::string& mimeType) override; diff --git a/Source/ImageEditor/Document.cpp b/Source/ImageEditor/Document.cpp index 02524bb6..45cc19fa 100644 --- a/Source/ImageEditor/Document.cpp +++ b/Source/ImageEditor/Document.cpp @@ -35,6 +35,7 @@ Document::Document(int width, int height) { } Document::Document(const wchar_t* fileName) { + hasTransparentPixels_ = false; currentImage_ = ImageUtils::LoadImageFromFileWithoutLocking(fileName, &isSrcMultiFrame_); init(); if ( currentImage_ ) { diff --git a/Source/ServerListTool/ServersCheckerModel.h b/Source/ServerListTool/ServersCheckerModel.h index e144bd23..3fb0f479 100644 --- a/Source/ServerListTool/ServersCheckerModel.h +++ b/Source/ServerListTool/ServersCheckerModel.h @@ -22,7 +22,7 @@ namespace ServersListTool { class ServerData { public: std::atomic_bool skip; - int stars[3]; // 0 - direct url, 1 - thumbnail url, 2 - download (view) url + int stars[10]; // 0 - direct url, 1 - thumbnail url, 2 - download (view) url uint32_t color; std::atomic fileToCheck; std::atomic filesChecked; diff --git a/Source/qimageuploader/QtScriptFunctionsImpl.cpp b/Source/qimageuploader/QtScriptFunctionsImpl.cpp index 2da4dc19..51e5cb47 100644 --- a/Source/qimageuploader/QtScriptFunctionsImpl.cpp +++ b/Source/qimageuploader/QtScriptFunctionsImpl.cpp @@ -1,8 +1,6 @@ #include "Core/Scripting/API/ScriptFunctionsImpl.h" -#include "Core/Utils/StringUtils.h" - namespace ScriptAPI::Impl { std::string GetAppLanguageImpl() {