Skip to content

Commit 22162fb

Browse files
authored
move config files to player profile dir (#304)
1 parent 654af60 commit 22162fb

File tree

15 files changed

+199
-112
lines changed

15 files changed

+199
-112
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Allow to limit client operations (e.g. playlist modification)
88
- Fix various issues in API documentation
99
- Fix view height initialization on mobile browsers
10+
- BREAKING CHANGE: no longer use .dll/.so directory or "beefweb" directory in user profile for configuration files,
11+
use "beefweb" directory in player profile instead. Existing config files will be copied to new location.
1012
### foobar2000
1113
- Add support for custom volume controls (e.g. for foo_out_upnp)
1214

cpp/server/browser_controller.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ ResponsePtr BrowserController::getRoots()
7171

7272
for (auto& dir : settings_->musicDirs)
7373
{
74-
auto path = pathFromUtf8(dir);
75-
auto info = file_io::tryQueryInfo(path);
74+
auto info = file_io::tryQueryInfo(dir);
7675

7776
if (info && info->type == FileType::DIRECTORY)
78-
roots.emplace_back(makeFsEntry(path, path, *info));
77+
roots.emplace_back(makeFsEntry(dir, dir, *info));
7978
}
8079

8180
return Response::json({ {"roots", roots}, {"pathSeparator", pathSeparator()} });
@@ -87,15 +86,14 @@ ResponsePtr BrowserController::getEntries()
8786
auto normalizedPath = pathFromUtf8(requestedPath).lexically_normal().make_preferred();
8887

8988
if (!settings_->isAllowedPath(normalizedPath))
90-
return Response::error(HttpStatus::S_403_FORBIDDEN);
89+
return Response::error(HttpStatus::S_403_FORBIDDEN, "listing directory is not allowed");
9190

9291
std::vector<FileSystemEntry> entries;
92+
boost::system::error_code ec;
9393

94-
for (auto iter = fs::directory_iterator(normalizedPath);
95-
iter != fs::directory_iterator();
96-
++iter)
94+
for (auto& entry : fs::directory_iterator(normalizedPath, ec))
9795
{
98-
auto& path = iter->path();
96+
auto& path = entry.path();
9997
auto info = file_io::tryQueryInfo(path);
10098

10199
if (info && info->type != FileType::UNKNOWN)

cpp/server/client_config_controller.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
namespace msrv {
77

8-
ClientConfigController::ClientConfigController(Request* request, SettingsDataPtr settings, const char* appName)
9-
: ControllerBase(request), settings_(std::move(settings)), appName_(appName)
8+
ClientConfigController::ClientConfigController(Request* request, SettingsDataPtr settings)
9+
: ControllerBase(request), settings_(std::move(settings))
1010
{
1111
}
1212

@@ -49,25 +49,19 @@ Path ClientConfigController::getFilePath()
4949
auto id = param<std::string>("id");
5050

5151
if (!std::regex_match(id, idPattern))
52-
{
5352
throw InvalidRequestException("invalid configuration id: " + id);
54-
}
5553

56-
auto configDir = SettingsData::getConfigDir(appName_);
57-
if (configDir.empty())
58-
{
59-
throw std::runtime_error("No config dir is available");
60-
}
54+
if (settings_->clientConfigDir.empty())
55+
throw OperationForbiddenException();
6156

62-
return configDir / MSRV_PATH_LITERAL("clientconfig") / pathFromUtf8(id + ".json");
57+
return settings_->clientConfigDir / pathFromUtf8(id + ".json");
6358
}
6459

65-
void ClientConfigController::defineRoutes(
66-
Router* router, WorkQueue* workQueue, SettingsDataPtr settings, const char* appName)
60+
void ClientConfigController::defineRoutes(Router* router, WorkQueue* workQueue, SettingsDataPtr settings)
6761
{
6862
auto routes = router->defineRoutes<ClientConfigController>();
6963

70-
routes.createWith([=](Request* r) { return new ClientConfigController(r, settings, appName); });
64+
routes.createWith([=](Request* r) { return new ClientConfigController(r, settings); });
7165
routes.useWorkQueue(workQueue);
7266
routes.setPrefix("api/clientconfig");
7367

cpp/server/client_config_controller.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class Router;
1111
class ClientConfigController : public ControllerBase
1212
{
1313
public:
14-
ClientConfigController(Request* request, SettingsDataPtr settings, const char* appName);
14+
ClientConfigController(Request* request, SettingsDataPtr settings);
1515
~ClientConfigController() = default;
1616

1717
ResponsePtr getConfig();
1818
void setConfig();
1919
void removeConfig();
2020

21-
static void defineRoutes(Router* router, WorkQueue* workQueue, SettingsDataPtr settings, const char* appName);
21+
static void defineRoutes(Router* router, WorkQueue* workQueue, SettingsDataPtr settings);
2222

2323
private:
2424
Path getFilePath();
@@ -29,7 +29,6 @@ class ClientConfigController : public ControllerBase
2929
}
3030

3131
SettingsDataPtr settings_;
32-
const char* appName_;
3332
};
3433

3534
}

cpp/server/deadbeef/plugin.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ void Plugin::handleConfigChanged()
4646
void Plugin::handlePluginsLoaded()
4747
{
4848
pluginsLoaded_ = true;
49+
50+
SettingsData::migrate(MSRV_PLAYER_DEADBEEF, getProfileDir());
51+
4952
refreshSettings();
5053
reconfigure();
5154
}
@@ -56,13 +59,13 @@ void Plugin::reconfigure()
5659

5760
settings->port = port_;
5861
settings->allowRemote = allowRemote_;
59-
settings->musicDirs = parseValueList<std::string>(musicDirs_, ';');
62+
settings->musicDirsStr = parseValueList<std::string>(musicDirs_, ';');
6063
settings->authRequired = authRequired_;
6164
settings->authUser = authUser_;
6265
settings->authPassword = authPassword_;
6366
settings->permissions = permissions_;
6467

65-
settings->loadAll(MSRV_PLAYER_DEADBEEF);
68+
settings->initialize(getProfileDir());
6669

6770
host_.reconfigure(std::move(settings));
6871
}

cpp/server/deadbeef/plugin.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class Plugin
3232
private:
3333
static ApiPermissions getPermissionsFromConfig();
3434

35+
static Path getProfileDir()
36+
{
37+
return {ddbApi->get_system_dir(DDB_SYS_DIR_CONFIG)};
38+
}
39+
3540
void handleConfigChanged();
3641
void handlePluginsLoaded();
3742
bool refreshSettings();

cpp/server/foobar2000/plugin.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
#include <memory>
77

8-
namespace msrv {
9-
namespace player_foobar2000 {
8+
namespace msrv::player_foobar2000 {
109

1110
Plugin::Plugin()
1211
: player_(),
@@ -22,19 +21,29 @@ Plugin::~Plugin()
2221
current_ = nullptr;
2322
}
2423

24+
Path Plugin::getProfileDir()
25+
{
26+
const char* path = core_api::get_profile_path();
27+
28+
if (strncmp(path, "file://", 7) == 0)
29+
path = path + 7;
30+
31+
return pathFromUtf8(path);
32+
}
33+
2534
void Plugin::reconfigure()
2635
{
2736
auto settings = std::make_shared<SettingsData>();
2837

2938
settings->port = settings_store::port;
3039
settings->allowRemote = settings_store::allowRemote;
31-
settings->musicDirs = settings_store::getMusicDirs();
40+
settings->musicDirsStr = settings_store::getMusicDirs();
3241
settings->authRequired = settings_store::authRequired;
3342
settings->authUser = settings_store::authUser;
3443
settings->authPassword = settings_store::authPassword;
3544
settings->permissions = settings_store::getPermissions();
3645

37-
settings->loadAll(MSRV_PLAYER_FOOBAR2000);
46+
settings->initialize(getProfileDir());
3847

3948
host_.reconfigure(std::move(settings));
4049
}
@@ -49,12 +58,13 @@ class InitQuit : public initquit
4958
void on_init() override
5059
{
5160
Logger::setCurrent(&logger_);
61+
SettingsData::migrate(MSRV_PLAYER_FOOBAR2000, Plugin::getProfileDir());
5262
tryCatchLog([this] { plugin_ = std::make_unique<Plugin>(); });
5363
}
5464

5565
void on_quit() override
5666
{
57-
tryCatchLog([this] { plugin_.reset(); });
67+
plugin_.reset();
5868
Logger::setCurrent(nullptr);
5969
}
6070

@@ -78,4 +88,3 @@ VALIDATE_COMPONENT_FILENAME(MSRV_FOOBAR2000_FILE);
7888
}
7989

8090
}
81-
}

cpp/server/foobar2000/plugin.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#include "../settings.hpp"
88
#include "../server_host.hpp"
99

10-
namespace msrv {
11-
namespace player_foobar2000 {
10+
namespace msrv::player_foobar2000 {
1211

1312
class Plugin
1413
{
@@ -23,6 +22,8 @@ class Plugin
2322

2423
void reconfigure();
2524

25+
static Path getProfileDir();
26+
2627
private:
2728
static Plugin* current_;
2829

@@ -33,4 +34,3 @@ class Plugin
3334
};
3435

3536
}
36-
}

cpp/server/project_info.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
#define MSRV_PROJECT_NAME "Beefweb Remote Control"
88
#define MSRV_WEB_ROOT "beefweb.root"
99
#define MSRV_3RD_PARTY_LICENSES "third-party-licenses.txt"
10-
#define MSRV_CONFIG_FILE "beefweb.config.json"
10+
#define MSRV_CONFIG_FILE "config.json"
11+
#define MSRV_CONFIG_FILE_OLD "beefweb.config.json"
1112
#define MSRV_CONFIG_FILE_ENV "BEEFWEB_CONFIG_FILE"
13+
#define MSRV_CLIENT_CONFIG_DIR "clientconfig"
1214
#define MSRV_PROJECT_DESC "Provides web UI and HTTP API for controlling player remotely"
1315
#define MSRV_PROJECT_URL "https://github.com/hyperblast/beefweb/"
1416
#define MSRV_DONATE_URL "https://hyperblast.org/donate/"

cpp/server/server_host.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void ServerHost::reconfigure(SettingsDataPtr settings)
6464

6565
BrowserController::defineRoutes(router, &utilityQueue_, settings);
6666
StaticController::defineRoutes(router, &utilityQueue_, settings, contentTypes_);
67-
ClientConfigController::defineRoutes(router, &utilityQueue_, settings, player_->name());
67+
ClientConfigController::defineRoutes(router, &utilityQueue_, settings);
6868

6969
serverThread_->restart(std::move(config));
7070
}

0 commit comments

Comments
 (0)