Skip to content

Commit 6ede568

Browse files
Refactor FileSystemService to use static methods and encapsulate FileSystemEntry
- Changed FileSystemService from a singleton to a class with static methods. - Moved all FileSystemEntry member function definitions to FileSystemService.cpp. - Updated all call sites to use static method calls. - Standardized return values to use standard bool types. - Cleaned up Windows-specific type dependencies in public headers. - Ensured consistent CRLF line endings. Co-authored-by: funap <31555185+funap@users.noreply.github.com>
1 parent a902c62 commit 6ede568

7 files changed

Lines changed: 123 additions & 71 deletions

File tree

Explorer.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@
108108
<ClCompile Include="src\Explorer\Settings.cpp">
109109
<Filter>src\Explorer</Filter>
110110
</ClCompile>
111-
<ClCompile Include="src\Explorer\FileSystemService.cpp">
112-
<Filter>src\Explorer</Filter>
113-
</ClCompile>
114111
</ItemGroup>
115112
<ItemGroup>
116113
<ResourceCompile Include="src\Explorer\version.rc">
@@ -256,9 +253,6 @@
256253
<ClInclude Include="src\Explorer\Settings.h">
257254
<Filter>src\Explorer</Filter>
258255
</ClInclude>
259-
<ClInclude Include="src\Explorer\FileSystemService.h">
260-
<Filter>src\Explorer</Filter>
261-
</ClInclude>
262256
</ItemGroup>
263257
<ItemGroup>
264258
<Image Include="src\Explorer\res\explore.bmp">

src/Explorer/Explorer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ bool IsValidFile(const WIN32_FIND_DATA & Find);
110110
HIMAGELIST GetSmallImageList(BOOL bSystem);
111111
void ExtractIcons(LPCTSTR currentPath, LPCTSTR fileName, DevType type, LPINT iIconNormal, LPINT iIconSelected, LPINT iIconOverlayed);
112112

113+
/* Resolve Links */
114+
113115
/* current open files */
114116
void UpdateDocs();
115117
void UpdateCurrUsedDocs(LPTSTR *ppFiles, UINT numFiles);

src/Explorer/ExplorerDialog.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ void ExplorerDialog::tb_cmd(WPARAM message)
771771
}
772772
newFilePath /= szFileName;
773773

774-
if (FileSystemService::Instance().CreateNewFile(newFilePath.wstring())) {
774+
if (FileSystemService::CreateNewFile(newFilePath.wstring())) {
775775
::SendMessage(_hParent, NPPM_DOOPEN, 0, (LPARAM)newFilePath.c_str());
776776
}
777777
break;
@@ -801,7 +801,7 @@ void ExplorerDialog::tb_cmd(WPARAM message)
801801
}
802802
newFolderPath /= szFolderName;
803803

804-
if (FileSystemService::Instance().CreateNewDirectory(newFolderPath.wstring()) == false) {
804+
if (FileSystemService::CreateNewDirectory(newFolderPath.wstring()) == false) {
805805
::MessageBox(_hParent, L"Folder couldn't be created.", L"Error", MB_OK);
806806
}
807807
break;
@@ -1096,7 +1096,7 @@ BOOL ExplorerDialog::SelectItem(const std::filesystem::path& path)
10961096
WCHAR szLongPath[MAX_PATH] = {};
10971097
std::wstring remotePath;
10981098
/* convert possible net path name and get the full path name for compare */
1099-
if (FileSystemService::Instance().ConvertNetPathName(path.wstring(), remotePath)) {
1099+
if (FileSystemService::ConvertNetPathName(path.wstring(), remotePath)) {
11001100
::GetLongPathName(remotePath.c_str(), szLongPath, MAX_PATH);
11011101
}
11021102
else {
@@ -1347,7 +1347,7 @@ void ExplorerDialog::onDelete(bool immediate)
13471347
path.pop_back();
13481348
}
13491349

1350-
FileSystemService::Instance().DeleteFiles(_hParent, { path }, immediate);
1350+
FileSystemService::DeleteFiles(_hParent, { path }, immediate);
13511351
}
13521352

13531353
void ExplorerDialog::onCut()
@@ -1405,7 +1405,7 @@ void ExplorerDialog::onPaste()
14051405
*/
14061406
void ExplorerDialog::UpdateRoots()
14071407
{
1408-
auto drives = FileSystemService::Instance().GetLogicalDrives();
1408+
auto drives = FileSystemService::GetLogicalDrives();
14091409

14101410
HTREEITEM hCurrentItem = _hTreeCtrl.GetNextItem(TVI_ROOT, TVGN_CHILD);
14111411

@@ -1417,13 +1417,13 @@ void ExplorerDialog::UpdateRoots()
14171417
auto it = std::find(drives.begin(), drives.end(), drivePath);
14181418

14191419
if (it != drives.end()) {
1420-
auto volumeInfo = FileSystemService::Instance().GetVolumeName(drivePath);
1420+
auto volumeInfo = FileSystemService::GetVolumeName(drivePath);
14211421
std::wstring volumeName = std::format(L"{}:", driveLetter);
14221422
bool haveChildren = false;
14231423

14241424
if (volumeInfo) {
14251425
volumeName = std::format(L"{}: [{}]", driveLetter, *volumeInfo);
1426-
haveChildren = FileSystemService::Instance().HaveChildren(drivePath, _pSettings->IsUseFullTree(), _pSettings->IsShowHidden());
1426+
haveChildren = FileSystemService::HaveChildren(drivePath, _pSettings->IsUseFullTree(), _pSettings->IsShowHidden());
14271427
}
14281428

14291429
if (hCurrentItem != nullptr) {
@@ -1522,7 +1522,7 @@ HTREEITEM ExplorerDialog::InsertChildFolder(const std::wstring& childFolderName,
15221522
/* look if children test id allowed */
15231523
BOOL haveChildren = FALSE;
15241524
if (bChildrenTest == TRUE) {
1525-
haveChildren = FileSystemService::Instance().HaveChildren(path, _pSettings->IsUseFullTree(), _pSettings->IsShowHidden());
1525+
haveChildren = FileSystemService::HaveChildren(path, _pSettings->IsUseFullTree(), _pSettings->IsShowHidden());
15261526
}
15271527

15281528
/* insert item */
@@ -1565,7 +1565,7 @@ void ExplorerDialog::UpdateChildren(const std::wstring& path, HTREEITEM parentIt
15651565
return;
15661566
}
15671567

1568-
auto entries = FileSystemService::Instance().GetDirectoryEntries(path, _pSettings->IsShowHidden());
1568+
auto entries = FileSystemService::GetDirectoryEntries(path, _pSettings->IsShowHidden());
15691569

15701570
if (!entries.empty()) {
15711571
std::vector<FileSystemEntry> folders;
@@ -1621,7 +1621,7 @@ void ExplorerDialog::UpdateChildren(const std::wstring& path, HTREEITEM parentIt
16211621

16221622
/* update icons and expandable information */
16231623
std::wstring currentPath = GetPath(hCurrentItem);
1624-
BOOL haveChildren = FileSystemService::Instance().HaveChildren(currentPath, _pSettings->IsUseFullTree(), _pSettings->IsShowHidden());
1624+
BOOL haveChildren = FileSystemService::HaveChildren(currentPath, _pSettings->IsUseFullTree(), _pSettings->IsShowHidden());
16251625

16261626
/* get icons and update item */
16271627
INT iIconNormal = 0;
@@ -1660,7 +1660,7 @@ void ExplorerDialog::FetchChildren(HTREEITEM parentItem)
16601660
{
16611661
auto parentFolderPath = GetPath(parentItem);
16621662

1663-
auto entries = FileSystemService::Instance().GetDirectoryEntries(parentFolderPath, _pSettings->IsShowHidden());
1663+
auto entries = FileSystemService::GetDirectoryEntries(parentFolderPath, _pSettings->IsShowHidden());
16641664

16651665
if (!entries.empty()) {
16661666
std::vector<FileSystemEntry> folders;
@@ -2068,7 +2068,7 @@ void ExplorerDialog::Open(const std::wstring &path)
20682068

20692069
/* open possible link */
20702070
std::wstring resolvedPath;
2071-
if (FileSystemService::Instance().ResolveShortCut(filePath, resolvedPath)) {
2071+
if (FileSystemService::ResolveShortCut(filePath, resolvedPath)) {
20722072
if (::PathIsDirectory(resolvedPath.c_str()) != FALSE) {
20732073
SelectItem(resolvedPath);
20742074
}

src/Explorer/FavesDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ void FavesDialog::OpenLink(FavesItemPtr pElem)
13301330
case FAVES_FILE: {
13311331
/* open possible link */
13321332
std::wstring resolvedPath;
1333-
if (FileSystemService::Instance().ResolveShortCut(pElem->Link(), resolvedPath)) {
1333+
if (FileSystemService::ResolveShortCut(pElem->Link(), resolvedPath)) {
13341334
Editor::Instance().DoOpen(resolvedPath);
13351335
} else {
13361336
Editor::Instance().DoOpen(pElem->Link());

src/Explorer/FileList.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ void FileList::viewPath(const std::wstring& currentDir, BOOL redraw)
718718
std::vector<FileSystemEntry> vFoldersTemp;
719719
std::vector<FileSystemEntry> vFilesTemp;
720720

721-
auto entries = FileSystemService::Instance().GetDirectoryEntries(currentDir, _pSettings->IsShowHidden(), true);
721+
auto entries = FileSystemService::GetDirectoryEntries(currentDir, _pSettings->IsShowHidden(), true);
722722

723723
for (const auto& entry : entries) {
724724
if (entry.IsDirectory()) {
@@ -1127,7 +1127,7 @@ void FileList::onDelete(bool immediate)
11271127
}
11281128

11291129
if (!filesToDelete.empty()) {
1130-
FileSystemService::Instance().DeleteFiles(_hParent, filesToDelete, immediate);
1130+
FileSystemService::DeleteFiles(_hParent, filesToDelete, immediate);
11311131
}
11321132
}
11331133

@@ -1593,10 +1593,10 @@ bool FileList::doPaste(LPCTSTR pszTo, LPDROPFILES hData, const DWORD& dwEffect)
15931593

15941594
if (::MessageBox(_hSelf, message.c_str(), L"Explorer", MB_YESNO) == IDYES) {
15951595
if (dwEffect == DROPEFFECT_MOVE) {
1596-
FileSystemService::Instance().MoveFiles(_hParent, filesFrom, pszTo);
1596+
FileSystemService::MoveFiles(_hParent, filesFrom, pszTo);
15971597
}
15981598
else {
1599-
FileSystemService::Instance().CopyFiles(_hParent, filesFrom, pszTo);
1599+
FileSystemService::CopyFiles(_hParent, filesFrom, pszTo);
16001600
}
16011601

16021602
::KillTimer(_hParent, EXT_UPDATEACTIVATEPATH);

src/Explorer/FileSystemService.cpp

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,84 @@
88
#include <algorithm>
99
#include <format>
1010

11-
FileSystemService& FileSystemService::Instance()
11+
FileSystemEntry::FileSystemEntry(const std::wstring& name, unsigned int attributes, size_t fileSize, time_t lastWriteTime, bool isParent)
12+
: _name(name)
13+
, _attributes(attributes)
14+
, _fileSize(fileSize)
15+
, _lastWriteTime(lastWriteTime)
16+
, _isParent(isParent)
17+
, _iIcon(-1)
18+
, _iOverlay(0)
19+
, _state(0)
1220
{
13-
static FileSystemService instance;
14-
return instance;
1521
}
1622

23+
const std::wstring& FileSystemEntry::Name() const
24+
{
25+
return _name;
26+
}
27+
28+
unsigned int FileSystemEntry::Attributes() const
29+
{
30+
return _attributes;
31+
}
32+
33+
size_t FileSystemEntry::FileSize() const
34+
{
35+
return _fileSize;
36+
}
37+
38+
time_t FileSystemEntry::LastWriteTime() const
39+
{
40+
return _lastWriteTime;
41+
}
42+
43+
bool FileSystemEntry::IsDirectory() const
44+
{
45+
return (_attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
46+
}
47+
48+
bool FileSystemEntry::IsHidden() const
49+
{
50+
return (_attributes & FILE_ATTRIBUTE_HIDDEN) != 0;
51+
}
52+
53+
bool FileSystemEntry::IsParent() const
54+
{
55+
return _isParent;
56+
}
57+
58+
int FileSystemEntry::Icon() const
59+
{
60+
return _iIcon;
61+
}
62+
63+
void FileSystemEntry::SetIcon(int icon) const
64+
{
65+
_iIcon = icon;
66+
}
67+
68+
int FileSystemEntry::Overlay() const
69+
{
70+
return _iOverlay;
71+
}
72+
73+
void FileSystemEntry::SetOverlay(int overlay) const
74+
{
75+
_iOverlay = overlay;
76+
}
77+
78+
unsigned int FileSystemEntry::State() const
79+
{
80+
return _state;
81+
}
82+
83+
void FileSystemEntry::SetState(unsigned int state) const
84+
{
85+
_state = state;
86+
}
87+
88+
1789
std::vector<std::wstring> FileSystemService::GetLogicalDrives()
1890
{
1991
std::vector<std::wstring> drives;
@@ -101,7 +173,7 @@ std::vector<FileSystemEntry> FileSystemService::GetDirectoryEntries(const std::w
101173
continue;
102174
}
103175

104-
size_t fileSize = (static_cast<unsigned __int64>(findData.nFileSizeHigh) << 32) + findData.nFileSizeLow;
176+
size_t fileSize = static_cast<size_t>((static_cast<unsigned __int64>(findData.nFileSizeHigh) << 32) + findData.nFileSizeLow);
105177

106178
unsigned __int64 ull = (static_cast<unsigned __int64>(findData.ftLastWriteTime.dwHighDateTime) << 32) + findData.ftLastWriteTime.dwLowDateTime;
107179
time_t lastWriteTime = static_cast<time_t>((ull - 116444736000000000ULL) / 10000000ULL);
@@ -192,12 +264,12 @@ bool FileSystemService::ConvertNetPathName(const std::wstring& pathName, std::ws
192264
remotePath += L"\\";
193265
}
194266
remotePath += subPath;
195-
return TRUE;
267+
return true;
196268
}
197269
}
198270
}
199271
}
200-
return FALSE;
272+
return false;
201273
}
202274

203275
bool FileSystemService::ResolveShortCut(const std::wstring& shortcutPath, std::wstring& resolvedPath)

src/Explorer/FileSystemService.h

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,24 @@
77

88
class FileSystemEntry {
99
public:
10-
FileSystemEntry(const std::wstring& name, unsigned int attributes, size_t fileSize, time_t lastWriteTime, bool isParent = false)
11-
: _name(name)
12-
, _attributes(attributes)
13-
, _fileSize(fileSize)
14-
, _lastWriteTime(lastWriteTime)
15-
, _isParent(isParent)
16-
, _iIcon(-1)
17-
, _iOverlay(0)
18-
, _state(0)
19-
{}
10+
FileSystemEntry(const std::wstring& name, unsigned int attributes, size_t fileSize, time_t lastWriteTime, bool isParent = false);
2011

21-
const std::wstring& Name() const { return _name; }
22-
unsigned int Attributes() const { return _attributes; }
23-
size_t FileSize() const { return _fileSize; }
24-
time_t LastWriteTime() const { return _lastWriteTime; }
12+
const std::wstring& Name() const;
13+
unsigned int Attributes() const;
14+
size_t FileSize() const;
15+
time_t LastWriteTime() const;
2516

26-
bool IsDirectory() const { return (_attributes & 0x00000010) != 0; } // FILE_ATTRIBUTE_DIRECTORY
27-
bool IsHidden() const { return (_attributes & 0x00000002) != 0; } // FILE_ATTRIBUTE_HIDDEN
28-
bool IsParent() const { return _isParent; }
17+
bool IsDirectory() const;
18+
bool IsHidden() const;
19+
bool IsParent() const;
2920

3021
// UI specific state
31-
int Icon() const { return _iIcon; }
32-
void SetIcon(int icon) const { _iIcon = icon; }
33-
int Overlay() const { return _iOverlay; }
34-
void SetOverlay(int overlay) const { _iOverlay = overlay; }
35-
unsigned int State() const { return _state; }
36-
void SetState(unsigned int state) const { _state = state; }
22+
int Icon() const;
23+
void SetIcon(int icon) const;
24+
int Overlay() const;
25+
void SetOverlay(int overlay) const;
26+
unsigned int State() const;
27+
void SetState(unsigned int state) const;
3728

3829
private:
3930
std::wstring _name;
@@ -49,29 +40,22 @@ class FileSystemEntry {
4940

5041
class FileSystemService {
5142
public:
52-
static FileSystemService& Instance();
43+
static std::vector<std::wstring> GetLogicalDrives();
44+
static std::optional<std::wstring> GetVolumeName(const std::wstring& drivePath);
5345

54-
std::vector<std::wstring> GetLogicalDrives();
55-
std::optional<std::wstring> GetVolumeName(const std::wstring& drivePath);
46+
static bool HaveChildren(const std::wstring& folderPath, bool useFullTree, bool showHidden);
47+
static std::vector<FileSystemEntry> GetDirectoryEntries(const std::wstring& path, bool showHidden, bool includeParent = false);
5648

57-
bool HaveChildren(const std::wstring& folderPath, bool useFullTree, bool showHidden);
58-
std::vector<FileSystemEntry> GetDirectoryEntries(const std::wstring& path, bool showHidden, bool includeParent = false);
49+
static bool CreateNewFile(const std::wstring& filePath);
50+
static bool CreateNewDirectory(const std::wstring& directoryPath);
5951

60-
bool CreateNewFile(const std::wstring& filePath);
61-
bool CreateNewDirectory(const std::wstring& directoryPath);
52+
static bool DeleteFiles(void* hWnd, const std::vector<std::wstring>& paths, bool immediate);
53+
static bool CopyFiles(void* hWnd, const std::vector<std::wstring>& from, const std::wstring& to);
54+
static bool MoveFiles(void* hWnd, const std::vector<std::wstring>& from, const std::wstring& to);
6255

63-
bool DeleteFiles(void* hWnd, const std::vector<std::wstring>& paths, bool immediate);
64-
bool CopyFiles(void* hWnd, const std::vector<std::wstring>& from, const std::wstring& to);
65-
bool MoveFiles(void* hWnd, const std::vector<std::wstring>& from, const std::wstring& to);
66-
67-
bool ConvertNetPathName(const std::wstring& pathName, std::wstring& remotePath);
68-
bool ResolveShortCut(const std::wstring& shortcutPath, std::wstring& resolvedPath);
56+
static bool ConvertNetPathName(const std::wstring& pathName, std::wstring& remotePath);
57+
static bool ResolveShortCut(const std::wstring& shortcutPath, std::wstring& resolvedPath);
6958

7059
private:
71-
FileSystemService() = default;
72-
~FileSystemService() = default;
73-
FileSystemService(const FileSystemService&) = delete;
74-
FileSystemService& operator=(const FileSystemService&) = delete;
75-
76-
std::wstring ToDoubleNullTerminatedString(const std::vector<std::wstring>& paths);
60+
static std::wstring ToDoubleNullTerminatedString(const std::vector<std::wstring>& paths);
7761
};

0 commit comments

Comments
 (0)