Skip to content

Commit d7ccd06

Browse files
committed
fix extension list match bug, issues/231
1 parent 20af5e7 commit d7ccd06

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

ContextMenuCustom/ContextMenuCustomHost/CustomSubExplorerCommand.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,32 @@ CustomSubExplorerCommand::CustomSubExplorerCommand(const winrt::hstring& configC
3535
_show_window_flag = static_cast<int>(result.GetNamedNumber(L"showWindowFlag", 0));
3636
_working_directory = result.GetNamedString(L"workingDirectory", L"");
3737

38-
//
38+
//TODO remove next version
3939
if (_accept_file_flag == 0 && _accept_file) {
4040
_accept_file_flag = FILE_EXT;
4141
}
42+
//TODO remove next version
4243
if (_accept_directory_flag == 0 && _accept_directory) {
4344
_accept_directory_flag = DIRECTORY_DIRECTORY | DIRECTORY_BACKGROUND | DIRECTORY_DESKTOP;
4445
}
46+
47+
if (_accept_file_flag == FileMatchFlagEnum::FILE_EXT2 && !_accept_exts.empty()) {
48+
std::wstring_view acceptExtsView{ _accept_exts };
49+
50+
for (std::size_t start = 0; start <= acceptExtsView.size ();)
51+
{
52+
const auto pos = acceptExtsView.find(L'|', start);
53+
const auto last = pos == std::wstring_view::npos;
54+
std::wstring_view token = last ? acceptExtsView.substr(start) : acceptExtsView.substr(start, pos - start);
55+
if (!token.empty ()) {
56+
_accept_exts_set.emplace(token);
57+
}
58+
if (last) {
59+
break;
60+
}
61+
start = pos + 1;
62+
}
63+
}
4564
}
4665
catch (winrt::hresult_error const& e)
4766
{
@@ -80,18 +99,7 @@ bool CustomSubExplorerCommand::Accept(bool multipleFiles, FileType fileType, con
8099
return false;
81100
}
82101

83-
const size_t position = _accept_exts.find(ext);
84-
if (position != std::string::npos) {
85-
//check for .c .cpp
86-
const bool isStart = position == 0;
87-
const bool isEnd = position + ext.size() == _accept_exts.size();
88-
const bool isPrevComma = !isStart && _accept_exts[position - 1] == L'|';
89-
const bool isNextComma = !isEnd && _accept_exts[position + ext.size()] == L'|';
90-
if ((isStart || isPrevComma) && (isEnd || isNextComma)) {
91-
return true;
92-
}
93-
}
94-
return false;
102+
return _accept_exts_set.contains(ext);
95103
}
96104
else if (_accept_file_flag == FileMatchFlagEnum::FILE_REGEX) {
97105
DEBUG_LOG(L"CustomSubExplorerCommand::Accept menu={}, file=regex, ext={}", _title, _accept_file_regex);

ContextMenuCustom/ContextMenuCustomHost/CustomSubExplorerCommand.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include "BaseExplorerCommand.h"
33
#include <string>
4+
#include <unordered_set>
45

56
enum FilesMatchFlagEnum {
67
FILES_OFF = 0,
@@ -61,6 +62,7 @@ class CustomSubExplorerCommand final : public BaseExplorerCommand {
6162
int _accept_directory_flag;
6263
int _show_window_flag;
6364
std::wstring _working_directory;
65+
std::unordered_set<std::wstring_view> _accept_exts_set;
6466

6567
public:
6668
int m_index;

0 commit comments

Comments
 (0)