Skip to content

Commit

Permalink
Fixed crash on exit in CThumbsView; Update scripting API docs
Browse files Browse the repository at this point in the history
Small fixes in the code (thanks to static analyzer)
Update scripting API docs: GetServerParamList() example
  • Loading branch information
zenden2k committed Nov 10, 2024
1 parent 2a81014 commit 3118721
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 43 deletions.
46 changes: 36 additions & 10 deletions Dist/DocGen/implement.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,43 @@ array GetFolderAccessTypeList();

/**
@code{.nut}
function GetServerParamList()
{
return
{
function GetServerParamList() {
return {
useWebdav = "Use WebDav",
token = "Token",
enableOAuth ="enableOAuth",
tokenType = "tokenType",
PrevLogin = "PrevLogin",
OAuthLogin = "OAuthLogin"
someOption = {
title = "Some option",
type = "text"
},
useOAuth = {
title = "Use OAUth",
type = "boolean"
},
expiration = {
title = "Expiration",
type = "choice",
items = [
{
id = "",
label = Never"
},
{
id = "PT5M",
label = "15 minutes"
},
{
id = "PT30M",
label = "30 minutes"
},
{
id = "PT1H",
label = "1 hour"
}
]
},
privateKeyPath = {
title = "Private key path",
type = "filename"
}
};
}
@endcode
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Network/NetworkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct CurlInitializer {
wchar_t buffer[1024] = { 0 };
if (GetModuleFileNameW(nullptr, buffer, 1024) != 0) {
int len = lstrlenW(buffer);
for (int i = len; i >= 0; i--) {
for (int i = len - 1; i >= 0; i--) {
if (buffer[i] == '\\') {
buffer[i + 1] = 0;
break;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Settings/BasicSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool BasicSettings::LoadAccounts(SimpleXmlNode root)
std::string value = server.Attribute(attribName);
attribName = attribName.substr(1, attribName.size() - 1);
if (!value.empty())
tempSettings.params[attribName] = value;
tempSettings.params[attribName] = std::move(value);
}
}
tempSettings.authData.DoAuth = server.AttributeBool("Auth");
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Upload/ScriptUploadEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CScriptUploadEngine : public CAdvancedUploadEngine,
int checkAuth();
bool needStop() override;
bool newAuthMode_;
bool hasRefreshTokenFunc_;
bool hasRefreshTokenFunc_ = false;
DISALLOW_COPY_AND_ASSIGN(CScriptUploadEngine);
};
#endif
31 changes: 27 additions & 4 deletions Source/Core/WinServerIconCache.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "WinServerIconCache.h"

#include <ComDef.h>

#include "Core/UploadEngineList.h"
#include "Gui/IconBitmapUtils.h"
#include "Core/Utils/StringUtils.h"
Expand Down Expand Up @@ -32,21 +34,32 @@ WinServerIconCache::WinIcon WinServerIconCache::tryIconLoad(const std::string& n
HICON icon = nullptr;
CString iconFileName = IuCoreUtils::Utf8ToWstring(getIconNameForServer(name, true)).c_str();

if (!WinUtils::FileExists(iconFileName)) {
/*if (!WinUtils::FileExists(iconFileName)) {
serverIcons_[name] = {};
return {};
}
}*/

const int w = GetSystemMetrics(SM_CXSMICON);
const int h = GetSystemMetrics(SM_CYSMICON);

LoadIconWithScaleDown(nullptr, iconFileName, w, h, &icon);
HRESULT hr = LoadIconWithScaleDown(nullptr, iconFileName, w, h, &icon);

if (FAILED(hr)) {
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) {
serverIcons_[name] = {};
return {};
} else {
_com_error err(hr);
LOG(WARNING) << "LoadIconWithScaleDown" << std::endl << err.ErrorMessage();
}
}

if (!icon) {
icon = static_cast<HICON>(LoadImage(nullptr, iconFileName, IMAGE_ICON, w, h, LR_LOADFROMFILE));
}

if (!icon) {
serverIcons_[name] = {};
return {};
}
WinIcon item(icon, iconBitmapUtils_->HIconToBitmapPARGB32(icon));
Expand All @@ -71,7 +84,17 @@ NativeIcon WinServerIconCache::getBigIconForServer(const std::string& name) {
const int w = GetSystemMetrics(SM_CXICON);
const int h = GetSystemMetrics(SM_CYICON);
HICON icon {};
LoadIconWithScaleDown(nullptr, iconFileName, w, h, &icon);
HRESULT hr = LoadIconWithScaleDown(nullptr, iconFileName, w, h, &icon);

if (FAILED(hr)) {
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) {
return {};
} else {
_com_error err(hr);
LOG(WARNING) << "getBigIconForServer() LoadIconWithScaleDown" << std::endl
<< err.ErrorMessage();
}
}

if (!icon) {
icon = static_cast<HICON>(LoadImage(nullptr, iconFileName, IMAGE_ICON, w, h, LR_LOADFROMFILE));
Expand Down
2 changes: 1 addition & 1 deletion Source/Func/UpdatePackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ bool CUpdatePackage::LoadUpdateFromFile(const CString& filename)
SimpleXmlNode root = m_xml.getRoot("UpdatePackage", false);
if(root.IsNull()) return false;

CString packageName = IuCoreUtils::Utf8ToWstring(root.Attribute("Name")).c_str();
//CString packageName = IuCoreUtils::Utf8ToWstring(root.Attribute("Name")).c_str();
m_TimeStamp = root.AttributeInt("TimeStamp");

int core=root.AttributeInt("CoreUpdate");
Expand Down
4 changes: 2 additions & 2 deletions Source/Gui/Components/ParameterListAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ChoiceParameterController : public IParameterController {
std::vector<CString> s; // Maybe only this vector of CString is enough?
std::vector<LPCTSTR> choices;
for (const auto& it : items) {
s.push_back(U2W(it.second));
s.emplace_back(IuCoreUtils::Utf8ToWstring(it.second).c_str());
choices.push_back(s.back().GetString());
}
choices.push_back(nullptr);
Expand Down Expand Up @@ -145,7 +145,7 @@ void ParameterListAdapter::saveValues(ServerSettingsStruct* serverSettings) {
}
}

serverSettings->params[parameter->getName()] = result;
serverSettings->params[parameter->getName()] = std::move(result);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion Source/Gui/Controls/DialogIndirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Core/ServiceLocator.h"
#include "Core/i18n/Translator.h"
#include "Gui/GuiTools.h"
#include "Func/WinUtils.h"

template <class T, class TBase = CWindow>
class ATL_NO_VTABLE CDialogIndirectImpl : public CDialogImplBaseT< TBase >
Expand Down Expand Up @@ -92,6 +93,10 @@ class ATL_NO_VTABLE CCustomDialogIndirectImpl : public CDialogIndirectImpl< T >

size_t sizeDlg = ::SizeofResource(hInst, res);
m_hDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg);
if (!m_hDlgTemplate) {
MessageBox(WinUtils::FormatWindowsErrorMessage(GetLastError()), APPNAME, MB_ICONERROR);
return nullptr;
}
auto pMyDlgTemplate = reinterpret_cast<ATL::_DialogSplitHelper::DLGTEMPLATEEX*>(::GlobalLock(m_hDlgTemplate));
::memcpy(pMyDlgTemplate, dit, sizeDlg);

Expand Down Expand Up @@ -123,4 +128,4 @@ class ATL_NO_VTABLE CCustomDialogIndirectImpl : public CDialogIndirectImpl< T >

};

#endif // DIALOGINDIRECT_H
#endif // DIALOGINDIRECT_H
14 changes: 7 additions & 7 deletions Source/Gui/Controls/ThumbsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void CThumbsView::Init(bool Extended)
ExtendedView = Extended;
ImageView.Create(m_hWnd);
DWORD rtlStyle = ServiceLocator::instance()->translator()->isRTL() ? ILC_MIRROR | ILC_PERITEMMIRROR : 0;
ImageList.Create(thumbnailWidth_, fullThumbHeight_, ILC_COLOR24 | rtlStyle, 0, 3);
SetImageList(ImageList, LVSIL_NORMAL);
imageList_.Create(thumbnailWidth_, fullThumbHeight_, ILC_COLOR24 | rtlStyle, 0, 3);
SetImageList(imageList_, LVSIL_NORMAL);
DWORD style = GetExtendedListViewStyle();
style = style | LVS_EX_DOUBLEBUFFER | LVS_EX_BORDERSELECT;
SetExtendedListViewStyle(style);
Expand All @@ -82,7 +82,7 @@ int CThumbsView::AddImage(LPCTSTR FileName, LPCTSTR Title, bool ensureVisible, G

int n = GetItemCount();

if(ImageList.GetImageCount() < 1)
if(imageList_.GetImageCount() < 1)
LoadThumbnail(-1, nullptr, nullptr);

AddItem(n, 0, Title, 0);
Expand Down Expand Up @@ -424,17 +424,17 @@ bool CThumbsView::LoadThumbnail(int itemId, ThumbsViewItem* tvi, Gdiplus::Image

int oldImageIndex = GetImageIndex(itemId);
if (oldImageIndex != 0) {
ImageList.Replace(oldImageIndex, bmp, nullptr);
imageList_.Replace(oldImageIndex, bmp, nullptr);
RedrawItems(itemId, itemId);
// SetItem(ItemID, 0, LVIF_IMAGE, 0, oldImageIndex, 0, 0, 0);
} else {
int imageIndex = ImageList.Add(bmp, (COLORREF)0);
int imageIndex = imageList_.Add(bmp, (COLORREF)0);
SetItem(itemId, 0, LVIF_IMAGE, 0, imageIndex, 0, 0, 0);
}
DeleteObject(bmp);
} else {
defaultImage_ = bmp;
ImageList.Add(bmp, (COLORREF)0);
imageList_.Add(bmp, (COLORREF)0);
}

return true;
Expand Down Expand Up @@ -769,7 +769,7 @@ void CThumbsView::getThumbnail(int itemIndex) {

void CThumbsView::clearImageList() {
// Default thumbnail (index=0) will be regenerated in AddImage()
ImageList.RemoveAll();
imageList_.RemoveAll();
}

void CThumbsView::beginAdd() {
Expand Down
6 changes: 4 additions & 2 deletions Source/Gui/Controls/ThumbsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class CThumbsView :
public CWindowImpl<CThumbsView, CListViewCtrl>, public CThreadImpl<CThumbsView>, public CImageViewCallback
{
public:

CImageListManaged ImageList;
CThumbsView();
~CThumbsView() override;
DECLARE_WND_SUPERCLASS(_T("CThumbsView"), CListViewCtrl::GetWndClassName())
Expand Down Expand Up @@ -127,6 +125,10 @@ class CThumbsView :
int fullThumbHeight_ = 0;
bool batchAdd_ = false;
bool isFFmpegAvailable_;

// The image list will be destroyed when the list-view control is destroyed,
// no need to use 'managed' class
CImageList imageList_;
};


Expand Down
5 changes: 3 additions & 2 deletions Source/Gui/Dialogs/ImageDownloaderDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ bool ExtractLinks(CString text, std::vector<CString>& result) {
}

// CImageDownloaderDlg
CImageDownloaderDlg::CImageDownloaderDlg(CWizardDlg *wizardDlg, const CString &initialBuffer) {
CImageDownloaderDlg::CImageDownloaderDlg(CWizardDlg* wizardDlg, const CString& initialBuffer)
: m_InitialBuffer(initialBuffer)
{
m_WizardDlg = wizardDlg;
m_InitialBuffer = initialBuffer;
m_retCode = 0;
m_nFilesCount = 0;
m_nFileDownloaded = 0;
Expand Down
15 changes: 8 additions & 7 deletions Source/Gui/Dialogs/ImageReuploaderDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,8 @@ bool CImageReuploaderDlg::addUploadTask(const CFileDownloader::DownloadFileListI

auto* dit = static_cast<DownloadItemData*>(it.id);

auto* uploadItemData = new UploadItemData;
{
std::lock_guard<std::mutex> lk(uploadItemsMutex_);
uploadItems_.push_back(std::unique_ptr<UploadItemData>(uploadItemData));
}
auto uploadItemData = std::make_unique<UploadItemData>();
uploadItemData->sourceUrl = it.url;

uploadItemData->sourceIndex = dit->sourceIndex;
uploadItemData->originalUrl = dit->originalUrl;

Expand All @@ -268,9 +263,15 @@ bool CImageReuploaderDlg::addUploadTask(const CFileDownloader::DownloadFileListI
std::shared_ptr<FileUploadTask> fileUploadTask = std::make_shared<FileUploadTask>(localFileName, displayName);
fileUploadTask->setServerProfile(serverProfile_);
fileUploadTask->setIsImage(true);
fileUploadTask->setUserData(uploadItemData);
fileUploadTask->setUserData(uploadItemData.get());
auto* settings = ServiceLocator::instance()->settings<WtlGuiSettings>();
fileUploadTask->setUrlShorteningServer(settings->urlShorteningServer);

{
std::lock_guard<std::mutex> lk(uploadItemsMutex_);
uploadItems_.push_back(std::move(uploadItemData));
}

using namespace std::placeholders;
fileUploadTask->addTaskFinishedCallback(std::bind(&CImageReuploaderDlg::OnFileFinished, this, _1, _2));
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Gui/Dialogs/ServerFolderSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ LRESULT CServerFolderSelect::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCt
HTREEITEM parentItem = item;
while ((parentItem = m_FolderTree.GetParentItem(parentItem))) {
auto* tid2 = reinterpret_cast<TreeItemData*>(m_FolderTree.GetItemData(parentItem));
m_SelectedFolder.parentIds.push_back(tid2->folder.getId());
m_SelectedFolder.parentIds.emplace_back(tid2->folder.getId());
}
std::reverse(m_SelectedFolder.parentIds.begin(), m_SelectedFolder.parentIds.end());

Expand Down
2 changes: 1 addition & 1 deletion Source/Video/AvcodecFrameGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AvcodecFrameGrabberPrivate
const AVCodec* pCodec;
AVFrame* pFrame;
AVFrame* pFrameRGB;
AVPacket packet;
AVPacket packet {};
AVFormatContext* ic;
uint8_t* buffer;
int frameFinished;
Expand Down
5 changes: 3 additions & 2 deletions Source/Video/DirectshowFrameGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ class DirectshowFrameGrabberPrivate {
CComQIPtr<IObjectWithSite> pObjectWithSite;
CSampleGrabberCB CB;
NoDirectVobSub graphBuilderCallback;
VIDEOINFOHEADER vih;
protected:
VIDEOINFOHEADER vih {};

protected:
std::unique_ptr<DirectshowVideoFrame> currentFrame_;
};

Expand Down

0 comments on commit 3118721

Please sign in to comment.