Windows uses std::system instead of bp::child

This commit is contained in:
badaix 2020-05-04 15:43:14 +02:00
parent 89679de108
commit 8de5a7a069
2 changed files with 23 additions and 10 deletions

View file

@ -178,7 +178,7 @@ before_install:
if [ ! -f "vcpkg/vcpkg.exe" ]; then # if not in cache from a previous run if [ ! -f "vcpkg/vcpkg.exe" ]; then # if not in cache from a previous run
git clone https://github.com/Microsoft/vcpkg.git git clone https://github.com/Microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.bat ./vcpkg/bootstrap-vcpkg.bat
travis-wait-enhanced --interval=1m --timeout=30m -- ./vcpkg/vcpkg.exe install libflac libvorbis soxr opus boost-asio boost-process --triplet x64-windows travis-wait-enhanced --interval=1m --timeout=30m -- ./vcpkg/vcpkg.exe install libflac libvorbis soxr opus boost-asio --triplet x64-windows
else else
./vcpkg/vcpkg.exe update # make sure dependencies are up to date ./vcpkg/vcpkg.exe update # make sure dependencies are up to date
fi fi

View file

@ -19,7 +19,11 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#ifdef WINDOWS
#include <cstdlib>
#else
#include <boost/process.hpp> #include <boost/process.hpp>
#endif
#include "common/aixlog.hpp" #include "common/aixlog.hpp"
#include "common/snap_exception.hpp" #include "common/snap_exception.hpp"
@ -156,27 +160,36 @@ void Player::setVolume(double volume, bool mute)
{ {
string param; string param;
string mode = utils::string::split_left(settings_.mixer.parameter, ':', param); string mode = utils::string::split_left(settings_.mixer.parameter, ':', param);
double dparam; double dparam = -1.;
try if (!param.empty())
{ {
if (!param.empty()) try
{
dparam = cpt::stod(param); dparam = cpt::stod(param);
} if (dparam < 0)
catch(...) throw SnapException("must be a positive number");
{ }
throw SnapException("Invalid mixer param: " + param); catch (const std::exception& e)
{
throw SnapException("Invalid mixer param: " + param + ", error: " + string(e.what()));
}
} }
if (mode == "poly") if (mode == "poly")
setVolume_poly(volume, param.empty() ? 3. : dparam); setVolume_poly(volume, (dparam < 0) ? 3. : dparam);
else else
setVolume_exp(volume, param.empty() ? 10. : dparam); setVolume_exp(volume, (dparam < 0) ? 10. : dparam);
} }
else if (settings_.mixer.mode == ClientSettings::Mixer::Mode::script) else if (settings_.mixer.mode == ClientSettings::Mixer::Mode::script)
{ {
try try
{ {
#ifdef WINDOWS
string cmd = settings_.mixer.parameter + " --volume " + cpt::to_string(volume) + " --mute " + (mute ? "true" : "false");
std::system(cmd.c_str());
#else
child c(exe = settings_.mixer.parameter, args = {"--volume", cpt::to_string(volume), "--mute", mute ? "true" : "false"}); child c(exe = settings_.mixer.parameter, args = {"--volume", cpt::to_string(volume), "--mute", mute ? "true" : "false"});
c.detach(); c.detach();
#endif
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {