Skip to content

Commit

Permalink
more work on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
mhogomchungu committed May 19, 2024
1 parent acd3631 commit f8447a4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
30 changes: 14 additions & 16 deletions src/engines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@
#include <QNetworkProxyFactory>
#include <QDir>

static QStringList _dirEntries( const QString& e )
{
auto filters = QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot ;

return QDir( e ).entryList( filters ) ;
}

static QProcessEnvironment _getEnvPaths( const engines::enginePaths& paths,settings& settings )
{
auto env = QProcessEnvironment::systemEnvironment() ;

const auto& basePath = paths.binPath() ;

const auto m = QDir( basePath ).entryList( QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot ) ;

auto separator = [ & ](){

if( utility::platformIsLikeWindows() ){
Expand All @@ -68,7 +73,7 @@ static QProcessEnvironment _getEnvPaths( const engines::enginePaths& paths,setti

s += separator + mm ;

auto m = QDir( mm ).entryList( QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot ) ;
auto m = _dirEntries( mm ) ;

m.removeOne( "aria2-1.36.0-win-32bit-build1" ) ;
m.removeOne( "aria2-1.37.0-win-32bit-build1" ) ;
Expand All @@ -85,21 +90,19 @@ static QProcessEnvironment _getEnvPaths( const engines::enginePaths& paths,setti

}else if( utility::platformIsOSX() ){

auto m = QCoreApplication::applicationDirPath() ;

const auto e = m ;
auto m = utility::OSXApplicationDirPath() ;

auto filters = QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot ;
const auto e = m ;

for( const auto& it : QDir( e ).entryList( filters ) ){
for( const auto& it : _dirEntries( e ) ){

m += separator + e + "/" + it ;
}

s = m + separator + s ;
s += separator + m ;
}

for( const auto& it : m ){
for( const auto& it : _dirEntries( basePath ) ){

s += separator + basePath + "/" + it ;
s += separator + basePath + "/" + it + "/bin" ;
Expand Down Expand Up @@ -520,12 +523,7 @@ settings& engines::Settings() const

bool engines::filePathIsValid( const QFileInfo& info )
{
if( utility::platformIsLikeWindows() ){

return info.exists() && info.isFile() ;
}else{
return info.exists() && info.isFile() && info.isExecutable() ;
}
return info.exists() && info.isFile() ;
}

static QString _findExecutable( const QString& exeName,const QStringList& paths,QFileInfo& info )
Expand Down
14 changes: 14 additions & 0 deletions src/engines/yt-dlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ void yt_dlp::checkIfBinaryExist( const QString& runTimeBinPath,const QString& th

auto srcPath = thirdPartyBinPath + "/ytdlp/" + _Windows32BitBinaryName() ;

utility::copyFile( srcPath,destPath ) ;
}

}else if( utility::platformIsOSX() ){

auto destPath = runTimeBinPath + "/yt-dlp_macos" ;

if( !QFile::exists( destPath ) ){

auto srcPath = utility::OSXApplicationDirPath() + "/extra/yt-dlp_macos" ;

utility::copyFile( srcPath,destPath ) ;
}
}
Expand Down Expand Up @@ -259,6 +270,9 @@ QJsonObject yt_dlp::init( const QString& name,
json.add( { { "Windows" },{ { "x86",x86Name,{ x86Name } },
{ "amd64",amd64,{ amd64 } } } } ) ;

json.add( { { "MacOS" },{ { "x86","yt-dlp_macos",{ "yt-dlp_macos" } },
{ "amd64","yt-dlp_macos",{ "yt-dlp_macos" } } } } ) ;

json.done() ;

mainObj.insert( "DefaultListCmdOptions",[](){
Expand Down
14 changes: 13 additions & 1 deletion src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,7 @@ void utility::addToListOptionsFromsDownload( QStringList& args,
mm.setDefaultProxy() ;
}

bool utility::copyFile( const QString& s,const QString& d )
bool utility::copyFile( const QString& s,const QString& d,bool setExePermssion )
{
QFile src( s ) ;

Expand All @@ -2095,6 +2095,13 @@ bool utility::copyFile( const QString& s,const QString& d )
}else{
if( src.size() == dst.size() ){

if( setExePermssion ){

auto s = dst.permissions() | QFileDevice::ExeOwner ;

dst.setPermissions( s ) ;
}

return true ;
}else{
dst.remove() ;
Expand Down Expand Up @@ -2236,3 +2243,8 @@ bool utility::Qt6Version()
return false ;
#endif
}

QString utility::OSXApplicationDirPath()
{
return QCoreApplication::applicationDirPath() ;
}
3 changes: 2 additions & 1 deletion src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ namespace utility
QString downloadOptions ;
} ;
utility::downLoadOptions setDownloadOptions( const engines::engine&,tableWidget&,int,const QString& = {} ) ;
bool copyFile( const QString& src,const QString& dst ) ;
bool copyFile( const QString& src,const QString& dst,bool = true ) ;
bool pathIsFolderAndExists( const QString& ) ;
bool platformIsWindows() ;
bool platformIs32Bit() ;
Expand All @@ -489,6 +489,7 @@ namespace utility
bool addData( const QByteArray& ) ;
void contextMenuForDirectUrl( const QJsonArray&,const Context& ) ;
void deleteTmpFiles( const QString&,std::vector< QByteArray > ) ;
QString OSXApplicationDirPath() ;
QString windowsApplicationDirPath() ;
QString windowsGateWayAddress() ;
QString windowsGetClipBoardText( const ContextWinId& ) ;
Expand Down

0 comments on commit f8447a4

Please sign in to comment.