@@ -719,29 +719,48 @@ int mt_snprintf(char *buf, const size_t buf_size, const char *fmt, ...)
719
719
return c;
720
720
}
721
721
722
- bool openURL (const std::string &url )
722
+ static bool open_uri (const std::string &uri )
723
723
{
724
- if ((url.substr (0 , 7 ) != " http://" && url.substr (0 , 8 ) != " https://" ) ||
725
- url.find_first_of (" \r\n " ) != std::string::npos) {
726
- errorstream << " Invalid url: " << url << std::endl;
724
+ if (uri.find_first_of (" \r\n " ) != std::string::npos) {
725
+ errorstream << " Unable to open URI as it is invalid, contains new line: " << uri << std::endl;
727
726
return false ;
728
727
}
729
728
730
729
#if defined(_WIN32)
731
- return (intptr_t )ShellExecuteA (NULL , NULL , url .c_str (), NULL , NULL , SW_SHOWNORMAL) > 32 ;
730
+ return (intptr_t )ShellExecuteA (NULL , NULL , uri .c_str (), NULL , NULL , SW_SHOWNORMAL) > 32 ;
732
731
#elif defined(__ANDROID__)
733
- openURLAndroid (url );
732
+ openURIAndroid (uri );
734
733
return true ;
735
734
#elif defined(__APPLE__)
736
- const char *argv[] = {" open" , url .c_str (), NULL };
735
+ const char *argv[] = {" open" , uri .c_str (), NULL };
737
736
return posix_spawnp (NULL , " open" , NULL , NULL , (char **)argv,
738
737
(*_NSGetEnviron ())) == 0 ;
739
738
#else
740
- const char *argv[] = {" xdg-open" , url .c_str (), NULL };
739
+ const char *argv[] = {" xdg-open" , uri .c_str (), NULL };
741
740
return posix_spawnp (NULL , " xdg-open" , NULL , NULL , (char **)argv, environ) == 0 ;
742
741
#endif
743
742
}
744
743
744
+ bool open_url (const std::string &url)
745
+ {
746
+ if (url.substr (0 , 7 ) != " http://" && url.substr (0 , 8 ) != " https://" ) {
747
+ errorstream << " Unable to open browser as URL is missing schema: " << url << std::endl;
748
+ return false ;
749
+ }
750
+
751
+ return open_uri (url);
752
+ }
753
+
754
+ bool open_directory (const std::string &path)
755
+ {
756
+ if (!fs::IsDir (path)) {
757
+ errorstream << " Unable to open directory as it does not exist: " << path << std::endl;
758
+ return false ;
759
+ }
760
+
761
+ return open_uri (path);
762
+ }
763
+
745
764
// Load performance counter frequency only once at startup
746
765
#ifdef _WIN32
747
766
0 commit comments