Skip to content

Commit

Permalink
Check file types when started from Explorer's context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Sep 30, 2024
1 parent 535d0e0 commit 2e8a081
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Data/Scripts/ImageSearch/yandex.nut
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/OutputGenerator/AbstractOutputGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AbstractOutputGenerator
bool loadTemplate(const std::string& templateFileName);
std::string generate(const std::vector<UploadObject>& items, bool withTemplate = true);
protected:
CodeType codeType_;
CodeType codeType_ = ctTableOfThumbnails;
bool preferDirectLinks_ = true, shortenUrl_ = false, groupByFile_ = false;
int itemsPerLine_ = 4;
std::optional<std::string> templateHead_, templateFoot_;
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/Upload/Filters/UrlShorteningFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UrlShorteningTask> shorteningTask = std::make_shared<UrlShorteningTask>(downloadUrl, task);
Expand All @@ -47,7 +46,6 @@ bool UrlShorteningFilter::PostUpload(UploadTask* task)
shorteningTask->setParentUrlType(UrlShorteningTask::DownloadUrl);
task->setShorteningStarted(true);
fileTask->addChildTask(shorteningTask);
res = true;
}
return res;
}
2 changes: 1 addition & 1 deletion Source/Core/WinServerIconCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions Source/Gui/Dialogs/AddFtpServerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -312,7 +309,6 @@ void CAddFtpServerDialog::addServer(bool test) {
} else {
EndDialog(IDOK);
}

}
catch (const std::exception& ex) {
CString errorMessage = TR("Could not add server.");
Expand All @@ -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_) {
Expand All @@ -341,4 +336,4 @@ LRESULT CAddFtpServerDialog::OnCtlColorMsgDlg(HDC hdc, HWND hwndChild) {
return reinterpret_cast<LRESULT>(backgroundBrush_.m_hBrush);
}
return 0;
}
}
4 changes: 3 additions & 1 deletion Source/Gui/Dialogs/FloatingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,9 @@ void CFloatingWindow::ShowImageUploadedMessage(UploadTask* task, const CString&
if (generatorId == gidXmlTemplate) {
int templateIndex = settings->CodeType - 4;
auto xmlTemplateGenerator = dynamic_cast<XmlTemplateGenerator*>(generator.get());
xmlTemplateGenerator->setTemplateIndex(templateIndex);
if (xmlTemplateGenerator) {
xmlTemplateGenerator->setTemplateIndex(templateIndex);
}
}

code = U2W(generator->generate(objects, settings->UseTxtTemplate));
Expand Down
8 changes: 7 additions & 1 deletion Source/Gui/Dialogs/FolderAddDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -84,6 +85,7 @@ int CFolderAdd::ProcessDir(CString currentDir, bool bRecursive /* = true */)

DWORD CFolderAdd::Run()
{
auto* settings = ServiceLocator::instance()->settings<WtlGuiSettings>();
EnableWindow(m_pWizardDlg->m_hWnd, false);
ServiceLocator::instance()->taskRunner()->runInGuiThread([&] {
m_pWizardDlg->beginAddFiles();
Expand Down Expand Up @@ -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<CMainDlg>(CWizardDlg::wpMainPage)->ThumbsView.LoadThumbnails();
Expand Down
2 changes: 1 addition & 1 deletion Source/Gui/Dialogs/HistoryWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions Source/Gui/Dialogs/MainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ limitations under the License.

class WinServerIconCache;



class CMainDlg : public CDialogImpl<CMainDlg>,public CThreadImpl<CMainDlg>,public CWizardPage,
public CMessageFilter
{
Expand All @@ -53,8 +51,6 @@ class CMainDlg : public CDialogImpl<CMainDlg>,public CThreadImpl<CMainDlg>,publi
MENUITEM_DELETE,
MENUITEM_PROPERTIES,
MENUITEM_OPENWITH


};
enum { kStatusTimer = 1 };
explicit CMainDlg(WinServerIconCache* iconCache);
Expand Down
10 changes: 5 additions & 5 deletions Source/Gui/Dialogs/ResultsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ CResultsPanel::CResultsPanel(CWizardDlg *dlg, std::vector<ImageUploader::Core::O
openedFromHistory_ = openedFromHistory;
rectNeeded = {};
rectNeeded.left = -1;
CString TemplateLoadError;
shortenUrl_ = false;
outputChanged_ = false;
m_Page = OG::clBBCode;
Expand Down Expand Up @@ -236,10 +235,9 @@ std::string CResultsPanel::GenerateOutput()
if (p < 1) {
p = 4;
}
bool UseTemplate = settings->UseTxtTemplate;
bool useTemplate = settings->UseTxtTemplate;
bool preferDirectLinks = settings->UseDirectLinks;
groupByFileName_ = settings->GroupByFilename;
settings->UseTxtTemplate = UseTemplate;

OG::GeneratorID generatorId = OG::gidBBCode;
OG::CodeLang lang = OG::clBBCode;
Expand All @@ -262,10 +260,12 @@ std::string CResultsPanel::GenerateOutput()
if (generatorId == OG::gidXmlTemplate) {
int templateIndex = Index - 4;
auto xmlTemplateGenerator = dynamic_cast<OG::XmlTemplateGenerator*>(generator);
xmlTemplateGenerator->setTemplateIndex(templateIndex);
if (xmlTemplateGenerator) {
xmlTemplateGenerator->setTemplateIndex(templateIndex);
}
}

return generator->generate(UrlList, UseTemplate);
return generator->generate(UrlList, useTemplate);
}

void CResultsPanel::UpdateOutput(bool immediately)
Expand Down
39 changes: 4 additions & 35 deletions Source/Gui/Dialogs/UploadSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,38 +106,6 @@ void CUploadSettings::settingsChanged(BasicSettings* settingsBase)
}
}

bool CUploadSettings::checkFileFormats() {
auto* mainDlg = WizardDlg->getPage<CMainDlg>(CWizardDlg::wpMainPage);

auto task = std::make_shared<FileTypeCheckTask>(&mainDlg->FileList, sessionImageServer_, sessionFileServer_);
std::string message;
std::vector<BadFileFormat> 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:");
Expand Down Expand Up @@ -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 ) {
Expand All @@ -441,9 +413,6 @@ bool CUploadSettings::OnNext()
settings->fileServer = sessionFileServer_;
}

if (settings->CheckFileTypesBeforeUpload && !checkFileFormats()) {
return false;
}
SaveCurrentProfile();

return true;
Expand Down
1 change: 0 additions & 1 deletion Source/Gui/Dialogs/UploadSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
44 changes: 40 additions & 4 deletions Source/Gui/Dialogs/WizardDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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("*.*") }
Expand Down Expand Up @@ -2487,3 +2490,36 @@ void CWizardDlg::endAddFiles() {
}
MainDlg->ThumbsView.endAdd();
}

bool CWizardDlg::checkFileFormats(const ServerProfileGroup& imageServer, const ServerProfileGroup& fileServer)
{
auto* mainDlg = getPage<CMainDlg>(CWizardDlg::wpMainPage);

auto task = std::make_shared<FileTypeCheckTask>(&mainDlg->FileList, sessionImageServer_, sessionFileServer_);
std::string message;
std::vector<BadFileFormat> 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;
}
2 changes: 2 additions & 0 deletions Source/Gui/Dialogs/WizardDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ class CWizardDlg :
void beginAddFiles();
void endAddFiles();
void showScreenshotCopiedToClipboardMessage(std::shared_ptr<Gdiplus::Bitmap> resultBitmap);
bool checkFileFormats(const ServerProfileGroup& imageServer, const ServerProfileGroup& fileServer);

protected:
bool acceptsDragnDrop() const;
CIcon hIcon;
Expand Down
2 changes: 1 addition & 1 deletion Source/Gui/FileList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/ImageEditor/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_ ) {
Expand Down
2 changes: 1 addition & 1 deletion Source/ServerListTool/ServersCheckerModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> fileToCheck;
std::atomic<int> filesChecked;
Expand Down
2 changes: 0 additions & 2 deletions Source/qimageuploader/QtScriptFunctionsImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

#include "Core/Scripting/API/ScriptFunctionsImpl.h"

#include "Core/Utils/StringUtils.h"

namespace ScriptAPI::Impl {

std::string GetAppLanguageImpl() {
Expand Down

0 comments on commit 2e8a081

Please sign in to comment.