Skip to content

Commit 158d87b

Browse files
committed
add env support for icon path
1 parent 501d8fe commit 158d87b

File tree

7 files changed

+57
-43
lines changed

7 files changed

+57
-43
lines changed

ContextMenuCustom/ContextMenuCustomApp/Common/AppLang.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public partial class AppLang
165165
public string SettingOtherRestart { get; set; } = "Restart App";
166166

167167
//update tip
168-
public string UpdateTipTitle { get; set; } = "V5.5";
168+
public string UpdateTipTitle { get; set; } = "V5.7";
169169
public string UpdateTipCloseButton { get; set; } = "Close";
170170
public string UpdateTip1 { get; set; } = "ChangeLog";
171171
public string UpdateTip1Content { get; set; } = "1. Add ARM64 package for Win Store\r\n2. Add more PARAM for multiple files\r\n3. Optimize UI \r\n4. Optimize language\r\n5. Optimize menu json format\r\n6. Other fix";

ContextMenuCustom/ContextMenuCustomDevPackage/ContextMenuCustomDevPackage.wapproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,43 @@
6666
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
6767
</PropertyGroup>
6868
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
69-
<AppxBundle>Always</AppxBundle>
69+
<AppxBundle>Never</AppxBundle>
7070
<DefaultLanguage>en-US</DefaultLanguage>
7171
</PropertyGroup>
7272
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
73-
<AppxBundle>Always</AppxBundle>
73+
<AppxBundle>Never</AppxBundle>
7474
<DefaultLanguage>en-US</DefaultLanguage>
7575
</PropertyGroup>
7676
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
77-
<AppxBundle>Always</AppxBundle>
77+
<AppxBundle>Never</AppxBundle>
7878
<DefaultLanguage>en-US</DefaultLanguage>
7979
</PropertyGroup>
8080
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
81-
<AppxBundle>Always</AppxBundle>
81+
<AppxBundle>Never</AppxBundle>
8282
<DefaultLanguage>en-US</DefaultLanguage>
8383
</PropertyGroup>
8484
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
85-
<AppxBundle>Always</AppxBundle>
85+
<AppxBundle>Never</AppxBundle>
8686
<DefaultLanguage>en-US</DefaultLanguage>
8787
</PropertyGroup>
8888
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
89-
<AppxBundle>Always</AppxBundle>
89+
<AppxBundle>Never</AppxBundle>
9090
<DefaultLanguage>en-US</DefaultLanguage>
9191
</PropertyGroup>
9292
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
93-
<AppxBundle>Always</AppxBundle>
93+
<AppxBundle>Never</AppxBundle>
9494
<DefaultLanguage>en-US</DefaultLanguage>
9595
</PropertyGroup>
9696
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
97-
<AppxBundle>Always</AppxBundle>
97+
<AppxBundle>Never</AppxBundle>
9898
<DefaultLanguage>en-US</DefaultLanguage>
9999
</PropertyGroup>
100100
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
101-
<AppxBundle>Always</AppxBundle>
101+
<AppxBundle>Never</AppxBundle>
102102
<DefaultLanguage>en-US</DefaultLanguage>
103103
</PropertyGroup>
104104
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
105-
<AppxBundle>Always</AppxBundle>
105+
<AppxBundle>Never</AppxBundle>
106106
<DefaultLanguage>en-US</DefaultLanguage>
107107
</PropertyGroup>
108108
<ItemGroup>

ContextMenuCustom/ContextMenuCustomDevPackage/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Identity
1616
Name="91b3cc93-5e27-4b3e-9d97-dd137b7fb3ea"
1717
Publisher="CN=ikas-mc-dev"
18-
Version="5.6.0.0" />
18+
Version="5.7.0.0" />
1919

2020
<Properties>
2121
<DisplayName>Custom Context Menu (Dev)</DisplayName>

ContextMenuCustom/ContextMenuCustomHost/BaseExplorerCommand.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@ IFACEMETHODIMP BaseExplorerCommand::GetIcon(_In_opt_ IShellItemArray* items, _Ou
2020
}
2121
else {
2222
DEBUG_LOG(L"BaseExplorerCommand::GetIcon ,m_theme_type={},custom icon={}", static_cast<int>(m_theme_type), customIcon);
23-
auto iconPath = wil::make_cotaskmem_string_nothrow(customIcon.c_str());
24-
RETURN_IF_NULL_ALLOC(iconPath);
25-
*icon = iconPath.release();
23+
std::wstring_view iconPath{ customIcon.data() };
24+
if (iconPath.find(L"%") != std::string::npos)
25+
{
26+
wil::unique_cotaskmem_string path{};
27+
if (S_OK == wil::ExpandEnvironmentStringsW(iconPath.data(), path))
28+
{
29+
*icon=path.release();
30+
return S_OK;
31+
}
32+
}
33+
else if (!iconPath.empty())
34+
{
35+
auto path{ wil::make_cotaskmem_string(iconPath.data(), iconPath.size()) };
36+
*icon=path.release();
37+
return S_OK;
38+
}
39+
2640
}
2741
return S_OK;
2842
}

ContextMenuCustom/ContextMenuCustomHost/CustomSubExplorerCommand.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,30 @@ bool CustomSubExplorerCommand::Accept(bool multipleFiles, FileType fileType, con
129129
}
130130

131131
IFACEMETHODIMP CustomSubExplorerCommand::GetIcon(_In_opt_ IShellItemArray* items, _Outptr_result_nullonfailure_ PWSTR* icon) {
132-
*icon = nullptr;
132+
wil::assign_null_to_opt_param(icon);
133133

134-
if (m_theme_type == ThemeType::Dark && !_icon_dark.empty()) {
135-
auto iconPath = wil::make_cotaskmem_string_nothrow(_icon_dark.c_str());
136-
RETURN_IF_NULL_ALLOC(iconPath);
137-
*icon = iconPath.release();
138-
return S_OK;
134+
std::wstring_view iconPath{ m_theme_type == ThemeType::Dark && _icon_dark.empty() ? _icon: _icon_dark };
135+
if (iconPath.find(L"%") != std::string::npos)
136+
{
137+
wil::unique_cotaskmem_string path{};
138+
if (S_OK == wil::ExpandEnvironmentStringsW(iconPath.data(), path))
139+
{
140+
*icon=path.release();
141+
return S_OK;
142+
}
139143
}
140-
141-
//TODO light or default
142-
if (!_icon.empty()) {
143-
auto iconPath = wil::make_cotaskmem_string_nothrow(_icon.c_str());
144-
RETURN_IF_NULL_ALLOC(iconPath);
145-
*icon = iconPath.release();
144+
else if(!iconPath.empty())
145+
{
146+
auto path{ wil::make_cotaskmem_string(iconPath.data(), iconPath.size()) };
147+
*icon=path.release();
146148
return S_OK;
147149
}
148150

149151
return BaseExplorerCommand::GetIcon(items, icon);
150152
}
151153

152154
IFACEMETHODIMP CustomSubExplorerCommand::GetTitle(_In_opt_ IShellItemArray* items, _Outptr_result_nullonfailure_ PWSTR* name) {
153-
*name = nullptr;
155+
wil::assign_null_to_opt_param(name);
154156
auto title = wil::make_cotaskmem_string_nothrow(_title.c_str());
155157
RETURN_IF_NULL_ALLOC(title);
156158
*name = title.release();
@@ -199,21 +201,20 @@ IFACEMETHODIMP CustomSubExplorerCommand::Invoke(_In_opt_ IShellItemArray* select
199201
}
200202
std::wstring param =PathHelper::simpleFormat(paramView, replacements);
201203

202-
//TODO
203-
std::wstring workingDirectory{ _working_directory };
204+
std::wstring workingDirectory{ _working_directory.find(L"%") == std::string::npos ?_working_directory : wil::ExpandEnvironmentStringsW(_working_directory.c_str()).get() };
204205
if (workingDirectory.empty()) {
205206
workingDirectory = parentPath;
206207
}
207208
else {
208209
PathHelper::replaceAll(workingDirectory, PARAM_PARENT, replacements[PARAM_PARENT]);
209210
PathHelper::replaceAll(workingDirectory, PARAM_PATH0, replacements[PARAM_PATH0]);
210211
}
212+
DEBUG_LOG(L"CustomSubExplorerCommand::Invoke menu={}, workingDirectoryPath={}", _title, workingDirectory);
213+
214+
const std::wstring exePath{ _exe.find(L"%") == std::string::npos ? _exe : wil::ExpandEnvironmentStringsW(_exe.c_str()).get() };
215+
DEBUG_LOG(L"CustomSubExplorerCommand::Invoke menu={}, exePath={}, param={}", _title, exePath, param);
211216

212-
const auto workingDirectoryPath = wil::ExpandEnvironmentStringsW(workingDirectory.c_str());
213-
DEBUG_LOG(L"CustomSubExplorerCommand::Invoke menu={}, workingDirectoryPath={}", _title, workingDirectoryPath.get());
214-
const auto exePath = wil::ExpandEnvironmentStringsW(_exe.c_str());
215-
DEBUG_LOG(L"CustomSubExplorerCommand::Invoke menu={}, exePath={}, param={}", _title, exePath.get(), param);
216-
ShellExecute(parent, L"open", exePath.get(), param.c_str(), workingDirectoryPath.get(), _show_window_flag + 1);
217+
ShellExecute(parent, L"open", exePath.c_str(), param.c_str(), workingDirectory.c_str(), _show_window_flag + 1);
217218
}
218219
}
219220
else if (count > 1 && _accept_multiple_files_flag == FILES_EACH) {
@@ -254,7 +255,7 @@ void CustomSubExplorerCommand::Execute(HWND parent, const std::wstring& path) {
254255
std::wstring param = PathHelper::simpleFormat(_param, replacements);
255256

256257
// TODO
257-
std::wstring workingDirectory{ _working_directory };
258+
std::wstring workingDirectory{ _working_directory.find(L"%") == std::string::npos?_working_directory:wil::ExpandEnvironmentStringsW(_working_directory.c_str()).get() };
258259
if (workingDirectory.empty()) {
259260
workingDirectory = file.parent_path().wstring();
260261
}
@@ -265,9 +266,8 @@ void CustomSubExplorerCommand::Execute(HWND parent, const std::wstring& path) {
265266
PathHelper::replaceAll(workingDirectory, PARAM_PATH0, replacements[PARAM_PATH]);
266267
}
267268

268-
const auto workingDirectoryPath = wil::ExpandEnvironmentStringsW(workingDirectory.c_str());
269-
DEBUG_LOG(L"CustomSubExplorerCommand::Invoke menu={}, workingDirectoryPath={}", _title, workingDirectoryPath.get());
270-
const auto exePath = wil::ExpandEnvironmentStringsW(_exe.c_str());
271-
DEBUG_LOG(L"CustomSubExplorerCommand::Invoke menu={}, exe={}, param={}", _title, exePath.get(), param);
272-
ShellExecute(parent, L"open", exePath.get(), param.c_str(), workingDirectoryPath.get(), _show_window_flag + 1);
269+
const std::wstring exePath{ _exe.find(L"%") == std::string::npos? _exe : wil::ExpandEnvironmentStringsW(_exe.c_str()).get() };
270+
DEBUG_LOG(L"CustomSubExplorerCommand::Invoke menu={}, exe={}, param={}", _title, exePath, param);
271+
272+
ShellExecute(parent, L"open", exePath.c_str(), param.c_str(), workingDirectory.c_str(), _show_window_flag + 1);
273273
}

ContextMenuCustom/ContextMenuCustomPackage/ContextMenuCustomPackage.wapproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
3636
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
3737
<GenerateTestArtifacts>False</GenerateTestArtifacts>
38-
<AppxBundlePlatforms>x64</AppxBundlePlatforms>
38+
<AppxBundlePlatforms>x64|arm64</AppxBundlePlatforms>
3939
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
4040
<EntryPointProjectUniqueName>..\ContextMenuCustomApp\ContextMenuCustomApp.csproj</EntryPointProjectUniqueName>
4141
<AppxSymbolPackageEnabled>True</AppxSymbolPackageEnabled>

ContextMenuCustom/ContextMenuCustomPackage/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<Identity
1616
Name="7061touchwp.CustomContextMenu"
17-
Publisher="CN=ikas-mc-dev"
17+
Publisher="CN=289FD761-763C-412C-A71B-BE59DC5ACE3A"
1818
Version="5.6.0.0" />
1919

2020
<Properties>

0 commit comments

Comments
 (0)