mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 11:06:16 +02:00
save config
This commit is contained in:
parent
8a684233a2
commit
9200fec700
4 changed files with 24 additions and 1 deletions
|
@ -17,16 +17,34 @@
|
|||
***/
|
||||
|
||||
#include "config.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Config::Config()
|
||||
{
|
||||
string dir = getenv("HOME") + string("/.config/SnapCast/");
|
||||
mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
filename_ = dir + "settings.json";
|
||||
cerr << filename_ << "\n";
|
||||
// fs::create_directory(filename_.parent_path());
|
||||
}
|
||||
|
||||
|
||||
void Config::save()
|
||||
{
|
||||
std::ofstream ofs(filename_.c_str(), std::ofstream::out|std::ofstream::trunc);
|
||||
json clients = {
|
||||
{"Client", getClientInfos()}
|
||||
};
|
||||
ofs << std::setw(4) << clients;
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
|
||||
void Config::test()
|
||||
{
|
||||
|
|
|
@ -139,8 +139,11 @@ public:
|
|||
std::vector<ClientInfoPtr> clients;
|
||||
json getClientInfos() const;
|
||||
|
||||
void save();
|
||||
|
||||
private:
|
||||
Config();
|
||||
std::string filename_;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ int main(int argc, char* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
Config::instance();
|
||||
std::clog.rdbuf(new Log("snapserver", LOG_DAEMON));
|
||||
|
||||
signal(SIGHUP, signal_handler);
|
||||
|
|
|
@ -152,6 +152,7 @@ void StreamServer::onMessageReceived(ServerSession* connection, const msg::BaseM
|
|||
client->version = helloMsg.getVersion();
|
||||
client->connected = true;
|
||||
gettimeofday(&client->lastSeen, NULL);
|
||||
Config::instance().save();
|
||||
|
||||
json notification = JsonNotification::getJson("Client.OnConnect", client->toJson());
|
||||
controlServer->send(notification.dump(4));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue