Skip to content

Commit 55ef87e

Browse files
committed
3.8.0.0
1 parent 2f08de9 commit 55ef87e

6 files changed

Lines changed: 78 additions & 63 deletions

File tree

OpenWithPPGUI/MainForm.vb

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,6 @@ Public Class MainForm
733733
If Not BlockEvents AndAlso Not SelectedItem Is Nothing Then
734734
SelectedItem.Path = tbPath.Text
735735
End If
736-
737-
If tbPath.Text.Contains(":\") AndAlso Not File.Exists(tbPath.Text) Then
738-
tbPath.BackColor = Color.OrangeRed
739-
Else
740-
tbPath.ResetBackColor()
741-
End If
742736
End Sub
743737

744738
Sub tbArgs_TextChanged(sender As Object, e As EventArgs) Handles tbArguments.TextChanged
@@ -1031,8 +1025,8 @@ Public Class MainForm
10311025
For Each line In lines
10321026
If line.Contains("=") Then
10331027
g.Settings.Macros.Add(New Macro() With {
1034-
.Name = line.Substring(0, line.IndexOf("=")).Trim,
1035-
.Value = line.Substring(line.IndexOf("=") + 1).Trim})
1028+
.Name = line.Substring(0, line.IndexOf("=")).Trim,
1029+
.Value = line.Substring(line.IndexOf("=") + 1).Trim})
10361030
End If
10371031
Next
10381032

@@ -1085,9 +1079,6 @@ Public Class MainForm
10851079
tsbInstallUninstall.Text = " Uninstall "
10861080
End If
10871081
End Using
1088-
1089-
tbPath_TextChanged(Nothing, Nothing)
1090-
tbIcon_TextChanged(Nothing, Nothing)
10911082
End Sub
10921083

10931084
Sub bnWorkingDirectory_Click(sender As Object, e As EventArgs) Handles bnWorkingDirectory.Click
@@ -1132,24 +1123,13 @@ Public Class MainForm
11321123
match = Regex.Match(tbIcon.Text, "^(.+),(\d+)$")
11331124
End If
11341125

1135-
If File.Exists(tbIcon.Text) Then
1136-
SelectedItem.IconFile = tbIcon.Text
1137-
SelectedItem.IconIndex = 0
1138-
ElseIf match.Success Then
1126+
If match.Success Then
11391127
SelectedItem.IconFile = match.Groups(1).Value
11401128
SelectedItem.IconIndex = CInt(match.Groups(2).Value)
11411129
Else
1142-
SelectedItem.IconFile = ""
1130+
SelectedItem.IconFile = tbIcon.Text
11431131
SelectedItem.IconIndex = 0
11441132
End If
11451133
End If
1146-
1147-
Dim iconFile = If(match.Success, match.Groups(1).Value, tbIcon.Text)
1148-
1149-
If iconFile <> "" AndAlso Not File.Exists(iconFile) Then
1150-
tbIcon.BackColor = Color.OrangeRed
1151-
Else
1152-
tbIcon.ResetBackColor()
1153-
End If
11541134
End Sub
11551135
End Class

OpenWithPPGUI/Misc.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Public Class g
5151
Next
5252
Else
5353
g.Settings = New AppSettings
54-
g.Settings.Macros.Add(New Macro() With {.Name = "%video%", .Value = "mpg avi vob mp4 d2v mkv avs 264 mov wmv part flv ifo h264 asf webm dgi mpeg mpv y4m avc hevc 265 h265 m2v m2ts vpy mts webm ts m4v part"})
54+
g.Settings.Macros.Add(New Macro() With {.Name = "%video%", .Value = "mpg avi vob mp4 d2v mkv avs 264 mov wmv part flv ifo h264 asf webm mpeg mpv y4m avc hevc 265 h265 m2v m2ts vpy mts webm ts m4v part"})
5555
g.Settings.Macros.Add(New Macro() With {.Name = "%audio%", .Value = "mp2 mp3 ac3 wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 ogg mka aac opus flac mpa"})
5656
g.Settings.Macros.Add(New Macro() With {.Name = "%subtitle%", .Value = "sub sup idx ass aas srt"})
5757
g.Settings.Macros.Add(New Macro() With {.Name = "%image%", .Value = "png jpg jpeg gif bmp"})

OpenWithPPGUI/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ Imports System.Runtime.InteropServices
2929
' You can specify all the values or you can default the Build and Revision Numbers
3030
' by using the '*' as shown below:
3131

32-
<Assembly: AssemblyVersion("3.7.0.0")>
33-
<Assembly: AssemblyFileVersion("3.7.0.0")>
32+
<Assembly: AssemblyVersion("3.8.0.0")>
33+
<Assembly: AssemblyFileVersion("3.8.0.0")>

OpenWithPPShellExtension/DLL.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ COpenWithPPShellExtensionModule _AtlModule;
1919
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
2020
{
2121
g_hmodThis = (HMODULE)hInstance;
22+
23+
WCHAR szModuleName[500];
24+
25+
if (!GetModuleFileNameW(g_hmodThis, szModuleName, std::size(szModuleName)))
26+
return HRESULT_FROM_WIN32(GetLastError());
27+
28+
PathRemoveFileSpec(szModuleName);
29+
SetEnvironmentVariable(L"OpenWithPPDir", szModuleName);
2230
return _AtlModule.DllMain(dwReason, lpReserved);
2331
}
2432

@@ -150,4 +158,4 @@ STDAPI DllUnregisterServer(void)
150158
}
151159

152160
return _AtlModule.DllUnregisterServer(FALSE);
153-
}
161+
}

OpenWithPPShellExtension/Main.cpp

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,24 @@ HBITMAP ConvertIconToBitmap(HICON hicon)
8686

8787
HRESULT SetIcon(HMENU menu, UINT position, UINT flags, Item* item)
8888
{
89-
if (!FileExists(item->IconFile))
89+
std::wstring path(item->IconFile);
90+
91+
if (path.find(L"%") != std::string::npos)
92+
{
93+
WCHAR szPath[500];
94+
DWORD result = ExpandEnvironmentStrings(path.c_str(), szPath, std::size(szPath));
95+
96+
if (result)
97+
path = szPath;
98+
}
99+
100+
if (!FileExists(path))
90101
return S_OK;
91102

92103
if (!item->Icon)
93104
{
94105
HICON iconSmall;
95-
int res = ExtractIconEx(item->IconFile.c_str(), item->IconIndex, NULL, &iconSmall, 1);
106+
int res = ExtractIconEx(path.c_str(), item->IconIndex, NULL, &iconSmall, 1);
96107

97108
if (!res)
98109
return E_FAIL;
@@ -492,23 +503,6 @@ STDMETHODIMP CMain::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
492503
args = value.GetBuffer();
493504
}
494505

495-
WCHAR szDir[500];
496-
497-
if (g_ShellItems.size() > 0)
498-
{
499-
std::wstring firstItem = *g_ShellItems.begin();
500-
501-
if (FileExists(firstItem))
502-
{
503-
wcscpy_s(szDir, firstItem.c_str());
504-
PathRemoveFileSpec(szDir);
505-
}
506-
else if (DirectoryExist(firstItem))
507-
{
508-
wcscpy_s(szDir, firstItem.c_str());
509-
}
510-
}
511-
512506
std::wstring verb;
513507

514508
if (g_Items[i]->RunAsAdmin || GetKeyState(VK_SHIFT) < 0)
@@ -519,26 +513,20 @@ STDMETHODIMP CMain::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
519513

520514
if (path.find(var) != std::string::npos)
521515
{
522-
WCHAR szEnvPath[500];
523-
DWORD result = ExpandEnvironmentStrings(path.c_str(), szEnvPath, std::size(szEnvPath));
516+
WCHAR szPath[500];
517+
DWORD result = ExpandEnvironmentStrings(path.c_str(), szPath, std::size(szPath));
524518

525519
if (result)
526-
{
527-
std::wstring newPath(szEnvPath);
528-
path = newPath;
529-
}
520+
path = szPath;
530521
}
531522

532523
if (args.find(var) != std::string::npos)
533524
{
534-
WCHAR szEnvArgs[900];
535-
DWORD result = ExpandEnvironmentStrings(args.c_str(), szEnvArgs, std::size(szEnvArgs));
525+
WCHAR szArgs[900];
526+
DWORD result = ExpandEnvironmentStrings(args.c_str(), szArgs, std::size(szArgs));
536527

537528
if (result)
538-
{
539-
std::wstring newArgs(szEnvArgs);
540-
args = newArgs;
541-
}
529+
args = szArgs;
542530
}
543531

544532
std::wstring guiExe(L"OpenWithPPGUI.exe");
@@ -561,9 +549,40 @@ STDMETHODIMP CMain::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
561549
info.lpParameters = args.c_str();
562550

563551
if (g_Items[i]->WorkingDirectory.length() == 0)
552+
{
553+
WCHAR szDir[500];
554+
555+
if (g_ShellItems.size() > 0)
556+
{
557+
std::wstring firstItem = *g_ShellItems.begin();
558+
559+
if (FileExists(firstItem))
560+
{
561+
wcscpy_s(szDir, firstItem.c_str());
562+
PathRemoveFileSpec(szDir);
563+
}
564+
else if (DirectoryExist(firstItem))
565+
{
566+
wcscpy_s(szDir, firstItem.c_str());
567+
}
568+
}
569+
564570
info.lpDirectory = DirectoryExist(szDir) ? szDir : NULL;
571+
}
565572
else
573+
{
574+
if (g_Items[i]->WorkingDirectory.find(var) != std::string::npos)
575+
{
576+
WCHAR szWorkingDirectory[500];
577+
DWORD result = ExpandEnvironmentStrings(
578+
g_Items[i]->WorkingDirectory.c_str(), szWorkingDirectory, std::size(szWorkingDirectory));
579+
580+
if (result)
581+
g_Items[i]->WorkingDirectory = szWorkingDirectory;
582+
}
583+
566584
info.lpDirectory = g_Items[i]->WorkingDirectory.c_str();
585+
}
567586

568587
info.nShow = g_Items[i]->HideWindow ? SW_HIDE : SW_NORMAL;
569588
info.hInstApp = NULL;

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ txt and md: `txt md`
6161
The options dialog defines macros for common file types:
6262

6363
```
64-
%video% = mpg avi vob mp4 d2v divx mkv avs 264 mov wmv part flv ifo h264 asf webm dgi mpeg mpv y4m avc hevc 265 h265 m2v m2ts vpy mts webm ts m4v part vpy rar crdownload
64+
%video% = mpg avi vob mp4 d2v divx mkv avs 264 mov wmv part flv ifo h264 asf webm mpeg mpv y4m avc hevc 265 h265 m2v m2ts vpy mts webm ts m4v part vpy rar crdownload
6565
%audio% = mp2 mp3 ac3 wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 ogg mka aac opus flac mpa
6666
%subtitle% = sub sup idx ass aas srt
6767
%image% = png jpg jpeg gif bmp ico
6868
```
69-
69+
W
7070
Media files: `%audio% %video% %image%`
7171

7272
Macros are only supported in the File Types property.
@@ -76,21 +76,26 @@ Macros are only supported in the File Types property.
7676

7777
Specifies the program to be used for opening the selected files or folders.
7878

79+
Environment variables get expanded.
7980

8081
### Arguments
8182

8283
Specifies the arguments that are passed to the program when the command is executed. You can use the predefined variable %paths% which expands to the paths of the selected files or folders. Do not enclose the %paths% macro in quotes as Open with++ adds them automatically when the macro is expanded, each path is enclosed in double quotation marks and separated by a space.
8384

85+
Environment variables get expanded.
8486

8587
### Working Directory
8688

8789
The working directory the process will use, if not specified the working directory will be set to the directory of the selected files or folders.
8890

91+
Environment variables get expanded.
8992

9093
### Icon
9194

9295
Supported file types are ICO, EXE and DLL. EXE and DLL files can contain different icons, Open with++ will show a dialog that allows to choose which icon in the EXE or DLL file to use.
9396

97+
Environment variables get expanded.
98+
9499
[IrfanView](https://www.irfanview.com/) can be used to create icons.
95100

96101
[Here is an article](https://www.digitalcitizen.life/where-find-most-windows-10s-native-icons) that shows which Windows DLLs contain icon resources.
@@ -123,8 +128,11 @@ Runs the process with hidden window. Useful to hide terminal tools like PowerShe
123128

124129
## Tips & Tricks
125130

126-
- Holding down the Shift key while selecting a command from the Open with++ menu will execute the command with elevated privileges.
131+
Holding down the Shift key while selecting a command from the Open with++ menu will execute the command with elevated privileges.
132+
133+
Path, Arguments, Working Directory and Icon support the usage of environment variables.
127134

135+
The location of Open with++ is available as environment variable %OpenWithPPDir%.
128136

129137
## Configuration Suggestions
130138

@@ -169,7 +177,7 @@ Start CMD at the given folder.
169177
**Name**: `Command Prompt`
170178
**Path**: `cmd.exe`
171179
**Show in submenu**: `checked`
172-
**Icon**: `C:\Windows\System32\cmd.exe,0`
180+
**Icon**: `cmd.exe,0`
173181

174182

175183
### Windows Terminal

0 commit comments

Comments
 (0)