2424
2525#include " shellanything/ActionOpen.h"
2626#include " rapidassist/process.h"
27+ #include " rapidassist/filesystem.h"
2728#include " PropertyManager.h"
2829#include " Platform.h"
30+ #include " utf_strings.h"
2931
3032#pragma warning( push )
3133#pragma warning( disable: 4355 ) // glog\install_dir\include\glog/logging.h(1167): warning C4355: 'this' : used in base member initializer list
3234#include < glog/logging.h>
3335#pragma warning( pop )
3436
37+ // #define WIN32_LEAN_AND_MEAN 1
38+ #include < windows.h>
39+ #undef GetEnvironmentVariable
40+ #undef DeleteFile
41+ #undef CreateDirectory
42+ #undef CopyFile
43+ #undef CreateFile
44+
45+ #pragma comment(lib, "Urlmon.lib") // for IsValidURL()
46+
3547namespace shellanything
3648{
3749
@@ -43,17 +55,58 @@ namespace shellanything
4355 {
4456 }
4557
58+ bool OpenPathGeneric (const std::string & iPath) {
59+ SHELLEXECUTEINFO info = { 0 };
60+
61+ info.cbSize = sizeof (SHELLEXECUTEINFO);
62+
63+ info.fMask |= SEE_MASK_NOCLOSEPROCESS;
64+ info.fMask |= SEE_MASK_NOASYNC;
65+ info.fMask |= SEE_MASK_FLAG_DDEWAIT;
66+
67+ info.hwnd = HWND_DESKTOP;
68+ info.nShow = SW_SHOWDEFAULT;
69+ info.lpVerb = " open" ;
70+ info.lpFile = iPath.c_str ();
71+ info.lpParameters = NULL ; // arguments
72+ info.lpDirectory = NULL ; // default directory
73+
74+ BOOL success = ShellExecuteEx (&info);
75+ return (success == TRUE );
76+ }
77+
4678 bool ActionOpen::execute (const Context & iContext) const
4779 {
4880 PropertyManager & pmgr = PropertyManager::getInstance ();
4981 std::string path = pmgr.expand (mPath );
5082
51- // debug
52- LOG (INFO) << " Open file '" << path << " '" ;
83+ // is path a file?
84+ if (ra::filesystem::FileExists (path.c_str ()))
85+ {
86+ LOG (INFO) << " Open file '" << path << " '" ;
87+ uint32_t pId = ra::process::OpenDocument (path);
88+ return pId != ra::process::INVALID_PROCESS_ID;
89+ }
90+
91+ // is path a directory?
92+ if (ra::filesystem::DirectoryExists (path.c_str ()))
93+ {
94+ LOG (INFO) << " Open directory '" << path << " '" ;
95+ bool success = OpenPathGeneric (path);
96+ return success;
97+ }
5398
54- uint32_t pId = ra::process::OpenDocument (path);
99+ // is path a valid url?
100+ std::wstring wide_path = encoding::utf::ansi_to_unicode (path);
101+ if (IsValidURL (NULL , wide_path.c_str (), 0 ) == S_OK)
102+ {
103+ LOG (INFO) << " Open url '" << path << " '" ;
104+ bool success = OpenPathGeneric (path);
105+ return success;
106+ }
55107
56- return pId != 0 ;
108+ LOG (ERROR) << " Unable to open '" << path << " '" ;
109+ return false ; // file not found
57110 }
58111
59112 const std::string & ActionOpen::getPath () const
0 commit comments