mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Use base::ComPtr in the FileSystemModule
This commit is contained in:
parent
5f00e6f96a
commit
92c5222aa7
2
laf
2
laf
@ -1 +1 @@
|
||||
Subproject commit 08c0a7bc1405a7e521c5790c72710d229469fa19
|
||||
Subproject commit 12dea43b35daf92a6087f3a980aff767ac0b7043
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
#include "base/fs.h"
|
||||
#include "base/string.h"
|
||||
#include "base/win/comptr.h"
|
||||
#include "os/display.h"
|
||||
#include "os/surface.h"
|
||||
#include "os/system.h"
|
||||
@ -64,8 +65,8 @@ FileItemMap* fileitems_map = nullptr;
|
||||
unsigned int current_file_system_version = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
IMalloc* shl_imalloc = nullptr;
|
||||
IShellFolder* shl_idesktop = nullptr;
|
||||
base::ComPtr<IMalloc> shl_imalloc;
|
||||
base::ComPtr<IShellFolder> shl_idesktop;
|
||||
#endif
|
||||
|
||||
// a position in the file-system
|
||||
@ -213,17 +214,14 @@ FileSystemModule::~FileSystemModule()
|
||||
fileitems_map->clear();
|
||||
|
||||
#ifdef _WIN32
|
||||
// relase desktop IShellFolder interface
|
||||
shl_idesktop->Release();
|
||||
|
||||
// release IMalloc interface
|
||||
shl_imalloc->Release();
|
||||
shl_imalloc = NULL;
|
||||
// Release interfaces
|
||||
shl_idesktop.reset();
|
||||
shl_imalloc.reset();
|
||||
#endif
|
||||
|
||||
delete fileitems_map;
|
||||
|
||||
m_instance = NULL;
|
||||
m_instance = nullptr;
|
||||
}
|
||||
|
||||
FileSystemModule* FileSystemModule::instance()
|
||||
@ -437,28 +435,31 @@ const FileItemList& FileItem::children()
|
||||
//LOG("FS: Loading files for %p (%s)\n", fileitem, fileitem->displayname);
|
||||
#ifdef _WIN32
|
||||
{
|
||||
IShellFolder* pFolder = NULL;
|
||||
base::ComPtr<IShellFolder> pFolder;
|
||||
HRESULT hr;
|
||||
|
||||
if (this == rootitem)
|
||||
if (this == rootitem) {
|
||||
pFolder = shl_idesktop;
|
||||
}
|
||||
else {
|
||||
hr = shl_idesktop->BindToObject(m_fullpidl,
|
||||
NULL, IID_IShellFolder, (LPVOID *)&pFolder);
|
||||
hr = shl_idesktop->BindToObject(
|
||||
m_fullpidl, nullptr,
|
||||
IID_IShellFolder, (LPVOID *)&pFolder);
|
||||
|
||||
if (hr != S_OK)
|
||||
pFolder = NULL;
|
||||
pFolder = nullptr;
|
||||
}
|
||||
|
||||
if (pFolder != NULL) {
|
||||
IEnumIDList *pEnum = NULL;
|
||||
if (pFolder) {
|
||||
base::ComPtr<IEnumIDList> pEnum;
|
||||
ULONG c, fetched;
|
||||
|
||||
// Get the interface to enumerate subitems
|
||||
hr = pFolder->EnumObjects(reinterpret_cast<HWND>(os::instance()->defaultDisplay()->nativeHandle()),
|
||||
hr = pFolder->EnumObjects(
|
||||
reinterpret_cast<HWND>(os::instance()->defaultDisplay()->nativeHandle()),
|
||||
SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum);
|
||||
|
||||
if (hr == S_OK && pEnum != NULL) {
|
||||
if (hr == S_OK && pEnum) {
|
||||
LPITEMIDLIST itempidl[256];
|
||||
SFGAOF attribs[256];
|
||||
|
||||
@ -468,7 +469,7 @@ const FileItemList& FileItem::children()
|
||||
// item is file or a folder
|
||||
for (c=0; c<fetched; ++c) {
|
||||
attribs[c] = SFGAO_FOLDER;
|
||||
pFolder->GetAttributesOf(1, (LPCITEMIDLIST *)itempidl, attribs+c);
|
||||
pFolder->GetAttributesOf(1, (LPCITEMIDLIST*)itempidl, attribs+c);
|
||||
}
|
||||
|
||||
// Generate the FileItems
|
||||
@ -495,12 +496,7 @@ const FileItemList& FileItem::children()
|
||||
insertChildSorted(child);
|
||||
}
|
||||
}
|
||||
|
||||
pEnum->Release();
|
||||
}
|
||||
|
||||
if (pFolder != shl_idesktop)
|
||||
pFolder->Release();
|
||||
}
|
||||
}
|
||||
#else
|
||||
@ -688,7 +684,7 @@ static SFGAOF get_pidl_attrib(FileItem* fileitem, SFGAOF attrib)
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
IShellFolder* pFolder = nullptr;
|
||||
base::ComPtr<IShellFolder> pFolder;
|
||||
if (fileitem->m_parent == rootitem)
|
||||
pFolder = shl_idesktop;
|
||||
else {
|
||||
@ -703,8 +699,6 @@ static SFGAOF get_pidl_attrib(FileItem* fileitem, SFGAOF attrib)
|
||||
hr = pFolder->GetAttributesOf(1, (LPCITEMIDLIST*)&fileitem->m_pidl, &attrib2);
|
||||
if (hr == S_OK)
|
||||
attrib = attrib2;
|
||||
if (pFolder && pFolder != shl_idesktop)
|
||||
pFolder->Release();
|
||||
}
|
||||
return attrib;
|
||||
}
|
||||
@ -714,7 +708,7 @@ static void update_by_pidl(FileItem* fileitem, SFGAOF attrib)
|
||||
{
|
||||
STRRET strret;
|
||||
WCHAR pszName[MAX_PATH];
|
||||
IShellFolder* pFolder = NULL;
|
||||
base::ComPtr<IShellFolder> pFolder;
|
||||
HRESULT hr;
|
||||
|
||||
if (fileitem == rootitem)
|
||||
@ -724,7 +718,7 @@ static void update_by_pidl(FileItem* fileitem, SFGAOF attrib)
|
||||
hr = shl_idesktop->BindToObject(fileitem->m_parent->m_fullpidl,
|
||||
nullptr, IID_IShellFolder, (LPVOID*)&pFolder);
|
||||
if (hr != S_OK)
|
||||
pFolder = NULL;
|
||||
pFolder = nullptr;
|
||||
}
|
||||
|
||||
// Get the file name
|
||||
@ -769,10 +763,6 @@ static void update_by_pidl(FileItem* fileitem, SFGAOF attrib)
|
||||
else {
|
||||
fileitem->m_displayname = base::get_file_name(fileitem->m_filename);
|
||||
}
|
||||
|
||||
if (pFolder && pFolder != shl_idesktop) {
|
||||
pFolder->Release();
|
||||
}
|
||||
}
|
||||
|
||||
static LPITEMIDLIST concat_pidl(LPITEMIDLIST pidlHead, LPITEMIDLIST pidlTail)
|
||||
|
Loading…
x
Reference in New Issue
Block a user