Skip to content

Commit

Permalink
v3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed May 2, 2021
1 parent ef4e988 commit 839f7bd
Show file tree
Hide file tree
Showing 12 changed files with 469 additions and 343 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

### v3.9

- GUI redesign
- Relative paths
- Regex filters
- Fix 'Show only when Ctrl key is pressed'
- Tab order fix
2 changes: 1 addition & 1 deletion License.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

MIT License

Copyright (C) 2008-2020 Frank Skare (stax76)
Copyright (C) 2008-2021 Frank Skare (stax76)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and ssociated documentation
Expand Down
19 changes: 0 additions & 19 deletions OpenWithPPGUI/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="tsMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>81, 40</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="ddbHelp.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAALEoAACxKAXd6dE0AAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>142</value>
</metadata>
Expand Down
570 changes: 320 additions & 250 deletions OpenWithPPGUI/MainForm.vb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions OpenWithPPGUI/Misc.vb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ Public Class Item
Public Directories As Boolean
Public FileTypes As String = ""
Public FileTypesDisplay As String = ""
Public HideWindow As Boolean
Public Filter As String = ""
Public Hidden As Boolean
Public HideWindow As Boolean
Public IconFile As String = ""
Public IconIndex As Integer
Public Name As String = ""
Expand All @@ -118,7 +119,7 @@ Public Class Item
Public SubMenu As Boolean = True
Public WorkingDirectory As String = ""

Public Function CompareTo(obj As Object) As Integer Implements System.IComparable.CompareTo
Function CompareTo(obj As Object) As Integer Implements System.IComparable.CompareTo
Return Name.CompareTo(DirectCast(obj, Item).Name)
End Function
End Class
Expand Down
8 changes: 4 additions & 4 deletions OpenWithPPGUI/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Imports System.Runtime.InteropServices
' Review the values of the assembly attributes

<Assembly: AssemblyTitle("Open with++")>
<Assembly: AssemblyDescription("Shell extension allowing to customize File Explorer context menu")>
<Assembly: AssemblyDescription("A shell extension that allows customizing the File Explorer context menu.")>
<Assembly: AssemblyCompany("Frank Skare (stax76)")>
<Assembly: AssemblyProduct("Open with++")>
<Assembly: AssemblyCopyright("Copyright (C) 2008-2020 Frank Skare (stax76)")>
<Assembly: AssemblyCopyright("Copyright (C) 2008-2021 Frank Skare (stax76)")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>
Expand All @@ -29,5 +29,5 @@ Imports System.Runtime.InteropServices
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:

<Assembly: AssemblyVersion("3.8.0.0")>
<Assembly: AssemblyFileVersion("3.8.0.0")>
<Assembly: AssemblyVersion("3.9.0.0")>
<Assembly: AssemblyFileVersion("3.9.0.0")>
6 changes: 6 additions & 0 deletions OpenWithPPGUI/OpenWithPPGUI.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="..\Changelog.md">
<Link>Changelog.md</Link>
</None>
<None Include="..\README.md">
<Link>README.md</Link>
</None>
<None Include="app.config">
<SubType>Designer</SubType>
</None>
Expand Down
9 changes: 7 additions & 2 deletions OpenWithPPGUI/OptionsForm.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 77 additions & 48 deletions OpenWithPPShellExtension/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "stdafx.h"
#include "Main.h"

#include <regex>
#include <filesystem>

Item::~Item()
{
Expand All @@ -13,6 +15,40 @@ Item::~Item()
}


std::wstring JoinList(std::list<std::wstring>* list, const std::wstring& sep)
{
std::wstring ret;

if ((*list).size() > 0)
ret = *(*list).begin();

if ((*list).size() > 1)
{
std::list<std::wstring>::iterator it = (*list).begin();
it++;

for (it; it != (*list).end(); it++)
ret += sep + (*it);
}

return ret;
}


std::wstring ToLower(std::wstring val)
{
std::transform(val.begin(), val.end(), val.begin(), tolower);
return val;
}


std::wstring GetExtNoDot(std::wstring pathName)
{
size_t period = pathName.find_last_of(L".");
return ToLower(pathName.substr(period + 1));
}


BOOL FileExists(std::wstring file)
{
if (file.length() == 0)
Expand All @@ -23,6 +59,13 @@ BOOL FileExists(std::wstring file)
}


BOOL DirectoryExist(std::wstring path)
{
DWORD dwAttrib = GetFileAttributes(path.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}


HBITMAP Create32BitHBITMAP(UINT cx, UINT cy, PBYTE* ppbBits)
{
BITMAPINFO bmi;
Expand Down Expand Up @@ -97,6 +140,15 @@ HRESULT SetIcon(HMENU menu, UINT position, UINT flags, Item* item)
path = szPath;
}

// starts with
if (path.rfind(L"..\\", 0) == 0)
{
WCHAR szExeDir[500];
SHRegGetPath(HKEY_CURRENT_USER, L"Software\\" PRODUCT_NAME, L"ExeDir", szExeDir, NULL);
std::wstring exeDir(szExeDir);
path = exeDir + path;
}

if (!FileExists(path))
return S_OK;

Expand Down Expand Up @@ -128,47 +180,6 @@ HRESULT SetIcon(HMENU menu, UINT position, UINT flags, Item* item)
}


std::wstring JoinList(std::list<std::wstring>* list, const std::wstring& sep)
{
std::wstring ret;

if ((*list).size() > 0)
ret = *(*list).begin();

if ((*list).size() > 1)
{
std::list<std::wstring>::iterator it = (*list).begin();
it++;

for (it; it != (*list).end(); it++)
ret += sep + (*it);
}

return ret;
}


std::wstring ToLower(std::wstring val)
{
std::transform(val.begin(), val.end(), val.begin(), tolower);
return val;
}


std::wstring GetExtNoDot(std::wstring pathName)
{
size_t period = pathName.find_last_of(L".");
return ToLower(pathName.substr(period + 1));
}


BOOL DirectoryExist(std::wstring path)
{
DWORD dwAttrib = GetFileAttributes(path.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}


HRESULT CMain::LoadXML()
{
for (Item* item : g_Items)
Expand Down Expand Up @@ -246,6 +257,8 @@ HRESULT CMain::LoadXML()
item->IconIndex = std::stoi(std::wstring(cNodeText));
else if (cNodeName == L"FileTypes")
item->FileTypes = cNodeText;
else if (cNodeName == L"Filter")
item->Filter = cNodeText;
else if (cNodeName == L"SubMenu")
item->SubMenu = (cNodeText == L"true") ? true : false;
else if (cNodeName == L"Directories")
Expand Down Expand Up @@ -348,6 +361,9 @@ STDMETHODIMP CMain::QueryContextMenu(
bool isFile = FileExists(*g_ShellItems.begin());
bool isDirectory = !isFile && DirectoryExist(*g_ShellItems.begin());

std::wstring ext = GetExtNoDot(*g_ShellItems.begin());
std::wstring path = *g_ShellItems.begin();

g_EditCommandIndex = -1;

int res = InsertMenu(hmenu, uMenuIndex, MF_BYPOSITION | MF_POPUP, (UINT_PTR)subMenu, L"Open with++");
Expand All @@ -364,10 +380,10 @@ STDMETHODIMP CMain::QueryContextMenu(
for (UINT i = 0; i < g_Items.size(); i++)
{
g_Items[i]->CommandIndex = -1;
std::wstring ext = GetExtNoDot(*g_ShellItems.begin());

if (isFile && g_Items[i]->FileTypes != L"" && ext != L""
&& (L" " + g_Items[i]->FileTypes + L" ").find(L" " + ext + L" ") != std::wstring::npos
&& (g_Items[i]->Filter == L"" || std::regex_search(path, std::wregex(g_Items[i]->Filter)))
&& (!g_Items[i]->Hidden || (g_Items[i]->Hidden && isCtrlPressed)))
{
g_Items[i]->CommandIndex = command - uidFirstCmd;
Expand Down Expand Up @@ -411,7 +427,8 @@ STDMETHODIMP CMain::QueryContextMenu(

for (UINT i = 0; i < g_Items.size(); i++)
{
if ((g_Items[i]->FileTypes == L"*.*" && isFile) || (g_Items[i]->Directories && isDirectory)
if ((g_Items[i]->FileTypes == L"*.*" && isFile || g_Items[i]->Directories && isDirectory)
&& (g_Items[i]->Filter == L"" || std::regex_search(path, std::wregex(g_Items[i]->Filter)))
&& (!g_Items[i]->Hidden || (g_Items[i]->Hidden && isCtrlPressed)))
{
g_Items[i]->CommandIndex = command - uidFirstCmd;
Expand Down Expand Up @@ -503,6 +520,15 @@ STDMETHODIMP CMain::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
args = value.GetBuffer();
}

if (args.find(L"%filename-no-ext%") != std::wstring::npos)
{
std::wstring firstFile = g_ShellItems.front();
std::filesystem::path fp(firstFile);
ATL::CString value = args.c_str();
value.Replace(L"%filename-no-ext%", fp.stem().c_str());
args = value.GetBuffer();
}

std::wstring verb;

if (g_Items[i]->RunAsAdmin || GetKeyState(VK_SHIFT) < 0)
Expand All @@ -520,6 +546,14 @@ STDMETHODIMP CMain::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
path = szPath;
}

WCHAR szExeDir[500];
SHRegGetPath(HKEY_CURRENT_USER, L"Software\\" PRODUCT_NAME, L"ExeDir", szExeDir, NULL);
std::wstring exeDir(szExeDir);

// starts with
if (path.rfind(L"..\\", 0) == 0)
path = exeDir + path;

if (args.find(var) != std::string::npos)
{
WCHAR szArgs[900];
Expand All @@ -532,12 +566,7 @@ STDMETHODIMP CMain::InvokeCommand(LPCMINVOKECOMMANDINFO pCmdInfo)
std::wstring guiExe(L"OpenWithPPGUI.exe");

if (guiExe == path)
{
WCHAR szExeDir[500];
SHRegGetPath(HKEY_CURRENT_USER, L"Software\\" PRODUCT_NAME, L"ExeDir", szExeDir, NULL);
std::wstring exeDir(szExeDir);
path = exeDir + guiExe;
}

SHELLEXECUTEINFO info;

Expand Down
8 changes: 4 additions & 4 deletions OpenWithPPShellExtension/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "Util.h"
#include "Common.h"


EXTERN_C const CLSID CLSID_Main;

// {E7B8ACF5-FC18-4f0d-BC50-D0184481A5DC}
Expand All @@ -15,12 +14,13 @@ class Item
public:
HBITMAP Icon = NULL;

std::wstring Arguments;
std::wstring FileTypes;
std::wstring Filter;
std::wstring IconFile;
std::wstring Name;
std::wstring Path;
std::wstring Arguments;
std::wstring WorkingDirectory;
std::wstring IconFile;
std::wstring FileTypes;

bool SubMenu;
bool Directories;
Expand Down
Loading

0 comments on commit 839f7bd

Please sign in to comment.