Skip to content

Commit

Permalink
Small fix, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Jul 14, 2023
1 parent d8014b9 commit 4d69b93
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 1,393 deletions.
1,365 changes: 0 additions & 1,365 deletions Source/3rdpart/Win7.h

This file was deleted.

11 changes: 2 additions & 9 deletions Source/Core/Images/GdiplusImageReader.cpp
Expand Up @@ -4,8 +4,6 @@
#include "Func/WinUtils.h"
#include "Core/Utils/CoreUtils.h"

typedef IStream * (STDAPICALLTYPE *SHCreateMemStreamFuncType)(const BYTE *pInit, UINT cbInit);

std::unique_ptr<GdiPlusImage> GdiplusImageReader::readFromFile(const wchar_t* fileName) {
std::unique_ptr<Gdiplus::Bitmap> bm = std::make_unique<Gdiplus::Bitmap>(fileName);
std::unique_ptr<GdiPlusImage> img = std::make_unique<GdiPlusImage>(bm.release());
Expand All @@ -18,12 +16,7 @@ std::unique_ptr<GdiPlusImage> GdiplusImageReader::readFromFile(const wchar_t* fi
}

std::unique_ptr<GdiPlusImage> GdiplusImageReader::readFromMemory(uint8_t* data, size_t size) {
auto SHCreateMemStreamFunc = shlwapiLib.GetProcAddress<SHCreateMemStreamFuncType>("SHCreateMemStream");
if (!SHCreateMemStreamFunc) {
return nullptr;
}

IStream* pStream = SHCreateMemStreamFunc(data, size);
IStream* pStream = SHCreateMemStream(data, size);
if (pStream) {
auto bitmap = readFromStream(pStream);
pStream->Release();
Expand Down Expand Up @@ -54,7 +47,7 @@ bool GdiplusImageReader::checkLastStatus(Gdiplus::Bitmap* bm) {
if (!bm) {
return false;
}
int lastError = ::GetLastError();
DWORD lastError = ::GetLastError();
Gdiplus::Status status = bm->GetLastStatus();
if (status != Gdiplus::Ok) {

Expand Down
4 changes: 1 addition & 3 deletions Source/Core/Images/GdiplusImageReader.h
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include "AbstractImageReader.h"
#include "Func/Library.h"

class GdiplusImageReader: public AbstractImageReader {
public:
Expand All @@ -14,9 +13,8 @@ class GdiplusImageReader: public AbstractImageReader {
std::wstring getLastError() override;
private:
std::wstring lastError_;
Library shlwapiLib{ L"Shlwapi.dll" };
bool checkLastStatus(Gdiplus::Bitmap* bm);
void postLoad(GdiPlusImage* bm);
};

#endif
#endif
2 changes: 1 addition & 1 deletion Source/Core/Images/Utils.cpp
Expand Up @@ -661,7 +661,7 @@ bool SaveImageToFile(Gdiplus::Bitmap* img, const CString& fileName, IStream* str
}

if (result != Ok) {
int lastError = GetLastError();
DWORD lastError = GetLastError();
CString error = GdiplusStatusToString(result);
if (result == Gdiplus::Win32Error) {
error += L"\r\n" + WinUtils::FormatWindowsErrorMessage(lastError) + L"";
Expand Down
59 changes: 56 additions & 3 deletions Source/Func/WinUtils.cpp
Expand Up @@ -3,6 +3,7 @@
#include <sstream>

#include <Aclapi.h>
#include <ComDef.h>
#include <strsafe.h>
#include <TlHelp32.h>
#include <Winhttp.h>
Expand Down Expand Up @@ -465,7 +466,7 @@ CString GetSystemSpecialPath(int csidl)
return result;
}

CString FormatWindowsErrorMessage(int idCode)
CString FormatWindowsErrorMessage(DWORD idCode)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,
Expand Down Expand Up @@ -1415,8 +1416,59 @@ bool ShellOpenFileOrUrl(CString path, HWND wnd, CString directory) {
return true;
}

bool ShowFilesInFolder(const std::vector<CString>& files, HWND wnd) {
PIDLIST_ABSOLUTE folderPidl = nullptr;

CComPtr<IShellFolder> desktop; // namespace root for parsing the path
HRESULT hr = SHGetDesktopFolder(&desktop);

if (!SUCCEEDED(hr)) {
return false;
}

std::vector<LPCITEMIDLIST> list;
for (const auto& file : files) {
PIDLIST_RELATIVE newPIdL;
hr = desktop->ParseDisplayName(wnd, nullptr, const_cast<LPWSTR>(file.GetString()), nullptr, &newPIdL, nullptr);
if (SUCCEEDED(hr)) {
LPCITEMIDLIST relativePidl = nullptr;
CComPtr<IShellFolder> folder;

hr = SHBindToParent(newPIdL, IID_IShellFolder, reinterpret_cast<void**>(&folder), &relativePidl);
if (SUCCEEDED(hr)) {
list.push_back(relativePidl);
if (!folderPidl) {
CComQIPtr<IPersistFolder2> persistFolder(folder);
if (persistFolder) {
persistFolder->GetCurFolder(&folderPidl);
}
}
}
}
}
if (!list.empty() && folderPidl != nullptr) {
// Will be opened the parent folder of the first file.
// Files laying in another folders will be ignored.
hr = SHOpenFolderAndSelectItems(folderPidl, list.size(), &list[0], 0);
if (!SUCCEEDED(hr)) {
_com_error err(hr);
LOG(ERROR) << "Unable to open folder in shell, error code=" << hr << std::endl << err.ErrorMessage();
} else {
return true;
}

// SHBindToParent does not allocate a new PIDL;
// it simply receives a pointer through this parameter.
// Therefore, we are not responsible for freeing this resource.
/*for (auto& pidl : list) {
SHFree(const_cast<LPITEMIDLIST>(pidl));
}*/
}
return false;
}

bool ShowFileInFolder(CString fileName, HWND wnd) {
SHELLEXECUTEINFO ShInfo;
/*SHELLEXECUTEINFO ShInfo;
ZeroMemory(&ShInfo, sizeof(SHELLEXECUTEINFO));
ShInfo.cbSize = sizeof(SHELLEXECUTEINFO);
Expand All @@ -1434,7 +1486,8 @@ bool ShowFileInFolder(CString fileName, HWND wnd) {
}
return false;
}
return true;
return true;*/
return ShowFilesInFolder({ fileName }, wnd);
}

/*SYSTEMTIME SystemTimeAdd(const SYSTEMTIME& s, double seconds) {
Expand Down
3 changes: 2 additions & 1 deletion Source/Func/WinUtils.h
Expand Up @@ -57,7 +57,7 @@ namespace WinUtils {
CString GetModuleFullName(HMODULE module = NULL);
CString GetAppFolder();
CString GetAppFileName();
CString FormatWindowsErrorMessage(int idCode);
CString FormatWindowsErrorMessage(DWORD idCode);
bool IsElevated();
void DeleteDir2(LPCTSTR Dir);
CString GetUniqFileName(const CString& filePath);
Expand Down Expand Up @@ -105,6 +105,7 @@ namespace WinUtils {
bool DisplaySystemPrintDialogForImage(const std::vector<CString>& files, HWND hwnd = NULL);
bool ShellOpenFileOrUrl(CString path, HWND wnd = nullptr, CString directory = {});
bool ShowFileInFolder(CString fileName, HWND wnd = nullptr);
bool ShowFilesInFolder(const std::vector<CString>& files, HWND wnd);
//SYSTEMTIME SystemTimeAdd(const SYSTEMTIME& s, double seconds);
time_t SystemTimeToTime(const SYSTEMTIME &s);
bool CheckFileName(const CString& fileName);
Expand Down
3 changes: 2 additions & 1 deletion Source/Gui/Dialogs/MainDlg.cpp
Expand Up @@ -525,7 +525,8 @@ LRESULT CMainDlg::OnOpenInFolder(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd
// Files laying in another folders will be ignored.
hr = SHOpenFolderAndSelectItems(folderPidl, list.size(), &list[0], 0);
if (!SUCCEEDED(hr)) {
LOG(ERROR) << "Unable to open folder in shell, error code=" << hr;
_com_error err(hr);
LOG(ERROR) << "Unable to open folder in shell, error code=" << hr << std::endl << err.ErrorMessage();
}

// SHBindToParent does not allocate a new PIDL;
Expand Down
3 changes: 1 addition & 2 deletions Source/Gui/Dialogs/ShortenUrlDlg.cpp
Expand Up @@ -19,7 +19,6 @@
*/
#include "ShortenUrlDlg.h"

#include "Func/Common.h"
#include "Gui/GuiTools.h"
#include "Core/Upload/FileQueueUploader.h"
#include "Core/Upload/UrlShorteningTask.h"
Expand Down Expand Up @@ -180,7 +179,7 @@ bool CShortenUrlDlg::StartProcess() {
wndAnimation_.ShowWindow(SW_SHOW);
CString url = GuiTools::GetDlgItemText(m_hWnd, IDC_INPUTEDIT);

std::shared_ptr<UrlShorteningTask> task = std::make_unique<UrlShorteningTask>(WCstringToUtf8(url));
auto task = std::make_shared<UrlShorteningTask>(WCstringToUtf8(url));

task->setServerProfile(profile);
using namespace std::placeholders;
Expand Down
8 changes: 5 additions & 3 deletions Source/Gui/Dialogs/UploadParamsDlg.cpp
Expand Up @@ -88,8 +88,10 @@ LRESULT CUploadParamsDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
std::vector<CString> files;
CString folder = IuCommonFunctions::GetDataFolder()+_T("\\Thumbnails\\");
WinUtils::GetFolderFileList(files, folder , _T("*.xml"));
for(size_t i=0; i<files.size(); i++) {
GuiTools::AddComboBoxItems(m_hWnd, IDC_THUMBTEMPLATECOMBO, 1, Utf8ToWCstring(IuCoreUtils::ExtractFileNameNoExt( WCstringToUtf8( files[i]))) );
for (const auto& file : files) {
GuiTools::AddComboBoxItems(m_hWnd, IDC_THUMBTEMPLATECOMBO, 1, Utf8ToWCstring(
IuCoreUtils::ExtractFileNameNoExt( WCstringToUtf8(file))
));
}
SendDlgItemMessage(IDC_THUMBTEMPLATECOMBO, CB_SELECTSTRING, static_cast<WPARAM>(-1),(LPARAM)(LPCTSTR) U2W(params_.getThumbRef().TemplateName));

Expand Down Expand Up @@ -284,4 +286,4 @@ void CUploadParamsDlg::useServerThumbnailsChanged() {

ImageUploadParams CUploadParamsDlg::imageUploadParams() const {
return params_;
}
}
3 changes: 0 additions & 3 deletions Source/Gui/Dialogs/WizardDlg.cpp
Expand Up @@ -286,9 +286,6 @@ LRESULT CWizardDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
#endif
SetWindowText(APPNAME);

CClientDC hdc(m_hWnd);
float dpiScaleX = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0f;
float dpiScaleY = GetDeviceCaps(hdc, LOGPIXELSY) / 96.0f;
const int iconWidth = GetSystemMetrics(SM_CXSMICON);
const int iconHeight = GetSystemMetrics(SM_CYSMICON);
helpButtonIcon_.LoadIconWithScaleDown(MAKEINTRESOURCE(IDI_ICON_HELP_DROPDOWN), iconWidth, iconHeight);
Expand Down
3 changes: 1 addition & 2 deletions Source/Gui/Dialogs/WizardDlg.h
Expand Up @@ -37,7 +37,6 @@
#include "FolderAddDlg.h"
#include "Core/Upload/ServerProfileGroup.h"
#include "Gui/HwndScopedWrapper.h"
#include "Gui/Controls/IconButton.h"
#include "Gui/CommonDefines.h"
#include "Gui/Controls/DialogIndirect.h"
#include "Gui/Components/DragndropOverlay.h"
Expand Down Expand Up @@ -74,7 +73,7 @@ class CWizardDlg :
enum { IDD = IDD_WIZARDDLG };
enum { IDM_OPENSCREENSHOTS_FOLDER = 9889, IDM_OPENSERVERSCHECKER };
enum { kNewFilesTimer = 1 };
static const WPARAM kWmMyExitParam = 5;
static constexpr WPARAM kWmMyExitParam = 5;

enum WizardPageId { wpWelcomePage = 0, wpVideoGrabberPage = 1, wpMainPage = 2, wpUploadSettingsPage = 3, wpUploadPage = 4 };

Expand Down

0 comments on commit 4d69b93

Please sign in to comment.