Skip to content

Commit

Permalink
Bug fixes and minor changes
Browse files Browse the repository at this point in the history
.: Fixed: regressions in DownloadListCtrl
.: Added: hide sources on download rename or name cleanup (issue found by Enig123)
  • Loading branch information
irwir committed Jun 25, 2018
1 parent e6eaafc commit db47e49
Show file tree
Hide file tree
Showing 16 changed files with 905 additions and 1,063 deletions.
218 changes: 90 additions & 128 deletions Collection.cpp

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@
class CAbstractFile;
class CCollectionFile;

typedef CMap<CSKey,const CSKey&,CCollectionFile*,CCollectionFile*> CCollectionFilesMap;
typedef CMap<CSKey,const CSKey &, CCollectionFile *, CCollectionFile *> CCollectionFilesMap;

class CCollection
{
friend class CCollectionCreateDialog;
friend class CCollectionViewDialog;
public:
CCollection();
explicit CCollection(const CCollection* pCollection);
explicit CCollection(const CCollection *pCollection);
~CCollection();
CCollection(const CCollection&) = delete;
CCollection& operator=(const CCollection&) = delete;
bool InitCollectionFromFile(const CString& sFilePath, CString sFileName);
CCollectionFile* AddFileToCollection(CAbstractFile* pAbstractFile, bool bCreateClone);
void RemoveFileFromCollection(CAbstractFile* pAbstractFile);
void WriteToFileAddShared(CryptoPP::RSASSA_PKCS1v15_SHA_Signer* pSignKey = NULL);
void SetCollectionAuthorKey(const byte* abyCollectionAuthorKey, uint32 nSize);
bool InitCollectionFromFile(const CString &sFilePath, CString sFileName);
CCollectionFile *AddFileToCollection(CAbstractFile *pAbstractFile, bool bCreateClone);
void RemoveFileFromCollection(CAbstractFile *pAbstractFile);
void WriteToFileAddShared(CryptoPP::RSASSA_PKCS1v15_SHA_Signer *pSignKey = NULL);
void SetCollectionAuthorKey(const byte *abyCollectionAuthorKey, uint32 nSize);
CString GetCollectionAuthorKeyString();
static bool HasCollectionExtention(const CString& sFileName);
CString GetAuthorKeyHashString();
static bool HasCollectionExtention(const CString &sFileName);
CString GetAuthorKeyHashString() const;

CString m_sCollectionName;
CString m_sCollectionAuthorName;
Expand All @@ -54,6 +54,6 @@ class CCollection

private:
CCollectionFilesMap m_CollectionFilesMap;
byte* m_pabyCollectionAuthorKey;
byte *m_pabyCollectionAuthorKey;
uint32 m_nKeySize;
};
77 changes: 32 additions & 45 deletions DownloadListCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ void CDownloadListCtrl::AddSource(CPartFile *owner, CUpDownClient *source, bool
{
// Update the other instances of this source
bool bFound = false;
std::pair<ListItems::const_iterator, ListItems::const_iterator> rangeIt = m_ListItems.equal_range(source);
for (ListItems::const_iterator it = rangeIt.first; it != rangeIt.second; ++it) {
for (ListItems::const_iterator it = m_ListItems.find(source); it != m_ListItems.end() && it->first == source; ++it) {
CtrlItem_Struct *cur_item = it->second;

// Check if this source has been already added to this file => to be sure
Expand Down Expand Up @@ -334,8 +333,7 @@ void CDownloadListCtrl::RemoveSource(CUpDownClient *source, CPartFile *owner)
return;

// Retrieve all entries matching the source
std::pair<ListItems::iterator, ListItems::iterator> rangeIt = m_ListItems.equal_range(source);
for (ListItems::const_iterator it = rangeIt.first; it != rangeIt.second;) {
for (ListItems::const_iterator it = m_ListItems.find(source); it != m_ListItems.end() && it->first == source;) {
const CtrlItem_Struct *delItem = it->second;
if (owner == NULL || owner == delItem->owner) {
// Remove it from the m_ListItems
Expand Down Expand Up @@ -394,8 +392,7 @@ void CDownloadListCtrl::UpdateItem(void *toupdate)
return;

// Retrieve all entries matching the source
std::pair<ListItems::const_iterator, ListItems::const_iterator> rangeIt = m_ListItems.equal_range(toupdate);
for (ListItems::const_iterator it = rangeIt.first; it != rangeIt.second; ++it) {
for (ListItems::const_iterator it = m_ListItems.find(toupdate); it != m_ListItems.end() && it->first == toupdate; ++it) {
CtrlItem_Struct *updateItem = it->second;

// Find entry in CListCtrl and update object
Expand Down Expand Up @@ -1041,16 +1038,15 @@ void CDownloadListCtrl::HideSources(CPartFile *toCollapse)
SetRedraw(false);
int pre = 0;
int post = 0;
for (int i = 0; i < GetItemCount();) {
for (int i = GetItemCount(); --i >= 0;) {
CtrlItem_Struct *item = reinterpret_cast<CtrlItem_Struct *>(GetItemData(i));
if (item != NULL && item->owner == toCollapse) {
++pre;
item->dwUpdated = 0;
item->status.DeleteObject();
DeleteItem(i);
++post;
} else
++i;
}
}
if (pre - post == 0)
toCollapse->srcarevisible = false;
Expand Down Expand Up @@ -1474,7 +1470,7 @@ BOOL CDownloadListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
if (content != NULL && content->type == FILE_TYPE) {
//for multiple selections
unsigned selectedCount = 0;
CTypedPtrList<CPtrList, CPartFile*> selectedList;
CTypedPtrList<CPtrList, CPartFile *> selectedList;
for (POSITION pos = GetFirstSelectedItemPosition(); pos != NULL;) {
int index = GetNextSelectedItem(pos);
if (index > -1 && reinterpret_cast<CtrlItem_Struct *>(GetItemData(index))->type == FILE_TYPE) {
Expand All @@ -1499,11 +1495,11 @@ BOOL CDownloadListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
if (cur_file->GetStatus() != PS_COMPLETING && (cur_file->GetStatus() != PS_COMPLETE || wParam == MP_CANCEL)) {
validdelete = true;
++cFiles;
fileList += _T('\n');
if (cFiles < iMaxDisplayFiles)
if (cFiles < iMaxDisplayFiles) {
fileList += _T('\n');
fileList += cur_file->GetFileName();
else if (cFiles == iMaxDisplayFiles && pos != NULL)
fileList += _T("...");
} else if (cFiles == iMaxDisplayFiles && pos != NULL)
fileList += _T("\n...");
} else if (cur_file->GetStatus() == PS_COMPLETE)
removecompl = true;
}
Expand Down Expand Up @@ -1628,8 +1624,10 @@ BOOL CDownloadListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
if (IDYES == LocMessageBox(IDS_MANUAL_FILENAMECLEANUP, MB_YESNO, 0))
while (!selectedList.IsEmpty()) {
CPartFile *partfile = selectedList.RemoveHead();
if (partfile->IsPartFile())
if (partfile->IsPartFile()) {
HideSources(partfile);
partfile->SetFileName(CleanupFilename(partfile->GetFileName()));
}
}
} else {
if (file->GetStatus() != PS_COMPLETE && file->GetStatus() != PS_COMPLETING) {
Expand All @@ -1639,6 +1637,7 @@ BOOL CDownloadListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
inputbox.SetLabels(title, GetResString(IDS_DL_FILENAME), file->GetFileName());
inputbox.SetEditFilenameMode();
if (inputbox.DoModal() == IDOK && !inputbox.GetInput().IsEmpty() && IsValidEd2kString(inputbox.GetInput())) {
HideSources(file);
file->SetFileName(inputbox.GetInput(), true);
file->UpdateDisplayedInfo();
file->SavePartFile();
Expand Down Expand Up @@ -1696,7 +1695,6 @@ BOOL CDownloadListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
CPartFile *pPartFile = selectedList.RemoveHead();
if (pPartFile->IsPreviewableFileType() && !pPartFile->IsReadyForPreview())
pPartFile->SetPauseOnPreview(!bAllPausedOnPreview);

}
break;
}
Expand Down Expand Up @@ -1753,9 +1751,9 @@ BOOL CDownloadListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
UpdateCurrentCategoryView();
if (thePrefs.ShowCatTabInfos())
theApp.emuledlg->transferwnd->UpdateCatTabTitles();
} else if (wParam >= MP_PREVIEW_APP_MIN && wParam <= MP_PREVIEW_APP_MAX) {
} else if (wParam >= MP_PREVIEW_APP_MIN && wParam <= MP_PREVIEW_APP_MAX)
thePreviewApps.RunApp(file, (UINT)wParam);
}

break;
}
} else if (content != NULL) {
Expand Down Expand Up @@ -1823,8 +1821,8 @@ void CDownloadListCtrl::OnLvnColumnClick(NMHDR *pNMHDR, LRESULT *pResult)
sortAscending = false;
break;
case 9:
default:
// Keep the current 'm_bRemainSort' for that column, but reset to 'ascending'
default:
sortAscending = true;
}
} else
Expand Down Expand Up @@ -1908,13 +1906,13 @@ void CDownloadListCtrl::ClearCompleted(int incat)
// Search for completed file(s)
for (ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end();) {
const CtrlItem_Struct *cur_item = it->second;
++it; // Already point to the next iterator.
if (cur_item->type == FILE_TYPE) {
CPartFile *file = static_cast<CPartFile *>(cur_item->value);
if (!file->IsPartFile() && (file->CheckShowItemInGivenCat(incat) || incat == -1))
if (RemoveFile(file))
it = m_ListItems.begin();
} else
++it; // Already point to the next iterator.
}
}
if (thePrefs.ShowCatTabInfos())
theApp.emuledlg->transferwnd->UpdateCatTabTitles();
Expand Down Expand Up @@ -2062,7 +2060,7 @@ int CDownloadListCtrl::Compare(const CUpDownClient *client1, const CUpDownClient

case 7: //qr asc
if (client1->GetDownloadState() == DS_DOWNLOADING)
return static_cast<int>(client2->GetDownloadState() != DS_DOWNLOADING);
return (client2->GetDownloadState() == DS_DOWNLOADING) ? 0 : -1;
if (client2->GetDownloadState() == DS_DOWNLOADING)
return 1;

Expand Down Expand Up @@ -2115,9 +2113,9 @@ void CDownloadListCtrl::OnNmDblClk(NMHDR* /*pNMHDR*/, LRESULT *pResult)
&& pt.x <= sm_iIconOffset + iconcx + RATING_ICON_WIDTH)
{
ShowFileDialog(IDD_COMMENTLST);
} else if (thePrefs.GetPreviewOnIconDblClk()
&& pt.x >= sm_iIconOffset
&& pt.x < sm_iIconOffset + iconcx)
} else if (thePrefs.GetPreviewOnIconDblClk()
&& pt.x >= sm_iIconOffset
&& pt.x < sm_iIconOffset + iconcx)
{
if (file->IsReadyForPreview())
file->PreviewFile();
Expand All @@ -2129,7 +2127,7 @@ void CDownloadListCtrl::OnNmDblClk(NMHDR* /*pNMHDR*/, LRESULT *pResult)
}
}
} else
ShowClientDialog((CUpDownClient*)content->value);
ShowClientDialog(static_cast<CUpDownClient *>(content->value));
}
}

Expand Down Expand Up @@ -2242,7 +2240,6 @@ float CDownloadListCtrl::GetFinishedSize()
const CPartFile *file = static_cast<CPartFile *>(cur_item->value);
if (file->GetStatus() == PS_COMPLETE)
fsize += (uint64)file->GetFileSize();

}
}
return fsize;
Expand Down Expand Up @@ -2284,14 +2281,11 @@ void CDownloadListCtrl::ShowSelectedFileDetails()
if (content != NULL)
if (content->type == FILE_TYPE) {
const CPartFile *file = static_cast<CPartFile *>(content->value);
if (thePrefs.ShowRatingIndicator()
bool b = (thePrefs.ShowRatingIndicator()
&& (file->HasComment() || file->HasRating() || file->IsKadCommentSearchRunning())
&& pt.x >= sm_iIconOffset + theApp.GetSmallSytemIconSize().cx
&& pt.x <= sm_iIconOffset + theApp.GetSmallSytemIconSize().cx + RATING_ICON_WIDTH)
{
ShowFileDialog(IDD_COMMENTLST);
} else
ShowFileDialog(0);
&& pt.x <= sm_iIconOffset + theApp.GetSmallSytemIconSize().cx + RATING_ICON_WIDTH);
ShowFileDialog(b ? IDD_COMMENTLST : 0);
} else
ShowClientDialog(static_cast<CUpDownClient *>(content->value));
}
Expand All @@ -2303,7 +2297,7 @@ int CDownloadListCtrl::GetCompleteDownloads(int cat, int &total)
for (ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); ++it) {
const CtrlItem_Struct *cur_item = it->second;
if (cur_item->type == FILE_TYPE) {
/*const*/ CPartFile *file = static_cast<CPartFile*>(cur_item->value);
/*const*/ CPartFile *file = static_cast<CPartFile *>(cur_item->value);
if (file->CheckShowItemInGivenCat(cat) || cat == -1) {
++total;
count += static_cast<int>(file->GetStatus() == PS_COMPLETE);
Expand All @@ -2320,25 +2314,21 @@ void CDownloadListCtrl::UpdateCurrentCategoryView()

void CDownloadListCtrl::UpdateCurrentCategoryView(CPartFile *thisfile)
{

ListItems::const_iterator it = m_ListItems.find(thisfile);
if (it != m_ListItems.end()) {
const CtrlItem_Struct *cur_item = it->second;
if (cur_item->type == FILE_TYPE) {
CPartFile *file = static_cast<CPartFile *>(cur_item->value);

if (!file->CheckShowItemInGivenCat(curTab))
HideFile(file);
else
ShowFile(file);
}
}

}

void CDownloadListCtrl::ChangeCategory(int newsel)
{

SetRedraw(FALSE);

// remove all displayed files with a different cat and show the correct ones
Expand All @@ -2363,8 +2353,7 @@ void CDownloadListCtrl::HideFile(CPartFile *tohide)
HideSources(tohide);

// Retrieve all entries matching the source
std::pair<ListItems::const_iterator, ListItems::const_iterator> rangeIt = m_ListItems.equal_range(tohide);
for (ListItems::const_iterator it = rangeIt.first; it != rangeIt.second; ++it) {
for (ListItems::const_iterator it = m_ListItems.find(tohide); it != m_ListItems.end() && it->first == tohide; ++it) {
CtrlItem_Struct *updateItem = it->second;

// Find entry in CListCtrl and update object
Expand All @@ -2381,10 +2370,8 @@ void CDownloadListCtrl::HideFile(CPartFile *tohide)

void CDownloadListCtrl::ShowFile(CPartFile *toshow)
{
// Retrieve all entries matching the source
std::pair<ListItems::const_iterator, ListItems::const_iterator> rangeIt = m_ListItems.equal_range(toshow);
ListItems::const_iterator it = rangeIt.first;
if (it != rangeIt.second) {
ListItems::const_iterator it = m_ListItems.find(toshow);
if (it != m_ListItems.end()) {
CtrlItem_Struct *updateItem = it->second;

// Check if entry is already in the List
Expand All @@ -2396,7 +2383,7 @@ void CDownloadListCtrl::ShowFile(CPartFile *toshow)
}
}

void CDownloadListCtrl::GetDisplayedFiles(CArray<CPartFile*, CPartFile*> *list)
void CDownloadListCtrl::GetDisplayedFiles(CArray<CPartFile *, CPartFile *> *list)
{
for (ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); ++it) {
const CtrlItem_Struct *cur_item = it->second;
Expand Down
6 changes: 3 additions & 3 deletions DownloadListCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ class CDownloadListCtrl : public CMuleListCtrl, public CDownloadListListCtrlItem
CTitleMenu m_PreviewMenu;
CMenu m_SourcesMenu;
bool m_bRemainSort;
typedef std::pair<void*, CtrlItem_Struct*> ListItemsPair;
typedef std::multimap<void*, CtrlItem_Struct*> ListItems;
typedef std::pair<void *, CtrlItem_Struct *> ListItemsPair;
typedef std::multimap<void *, CtrlItem_Struct *> ListItems;
ListItems m_ListItems;
CFont m_fontBold; // may contain a locally created bold font
CFont* m_pFontBold;// points to the bold font which is to be used (may be the locally created or the default bold font)
CFont *m_pFontBold;// points to the bold font which is to be used (may be the locally created or the default bold font)
CToolTipCtrlX *m_tooltip;
uint32 m_dwLastAvailableCommandsCheck;
bool m_availableCommandsDirty;
Expand Down
Loading

0 comments on commit db47e49

Please sign in to comment.