client/config, server/config: Check configured paths at startup
This commit is contained in:
parent
adde3a86fd
commit
928706b36e
@ -57,6 +57,7 @@ set(CLIENT_SRCS
|
||||
src/client/main.cpp
|
||||
src/client/state.cpp
|
||||
src/client/app.cpp
|
||||
src/client/config.cpp
|
||||
src/core/log.cpp
|
||||
src/impl/fs.cpp
|
||||
src/impl/tcpsocket.cpp
|
||||
@ -76,6 +77,7 @@ set(SERVER_SRCS
|
||||
src/server/main.cpp
|
||||
src/server/state.cpp
|
||||
src/server/rccpp.cpp
|
||||
src/server/config.cpp
|
||||
src/core/log.cpp
|
||||
src/impl/fs.cpp
|
||||
src/impl/event.cpp
|
||||
|
60
src/client/config.cpp
Normal file
60
src/client/config.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
||||
#include "client/config.h"
|
||||
#include "core/log.h"
|
||||
#include "interface/fs.h"
|
||||
#include <fstream>
|
||||
#define MODULE "config"
|
||||
|
||||
namespace client {
|
||||
|
||||
static bool check_file_readable(const ss_ &path)
|
||||
{
|
||||
std::ifstream ifs(path);
|
||||
bool readable = ifs.good();
|
||||
if(!readable)
|
||||
log_e(MODULE, "File is not readable: \"%s\"", cs(path));
|
||||
return readable;
|
||||
}
|
||||
|
||||
static bool check_file_writable(const ss_ &path)
|
||||
{
|
||||
std::ofstream ofs(path);
|
||||
bool writable = ofs.good();
|
||||
if(!writable)
|
||||
log_e(MODULE, "File is not writable: \"%s\"", cs(path));
|
||||
return writable;
|
||||
}
|
||||
|
||||
bool Config::check_paths()
|
||||
{
|
||||
bool fail = false;
|
||||
|
||||
if(!check_file_readable(polycode_path+"/Core/Contents/Include/Polycode.h")){
|
||||
log_e(MODULE, "Polycode doesn't seem to exist in polycode_path=\"%s\"",
|
||||
cs(polycode_path));
|
||||
fail = true;
|
||||
}
|
||||
|
||||
if(!check_file_readable(share_path+"/extensions/test/init.lua")){
|
||||
log_e(MODULE, "Static files don't seem to exist in share_path=\"%s\"",
|
||||
cs(share_path));
|
||||
fail = true;
|
||||
}
|
||||
else if(!check_file_readable(share_path+"/client/init.lua")){
|
||||
log_e(MODULE, "Static files don't seem to exist in share_path=\"%s\"",
|
||||
cs(share_path));
|
||||
fail = true;
|
||||
}
|
||||
|
||||
auto *fs = interface::getGlobalFilesystem();
|
||||
fs->create_directories(cache_path);
|
||||
if(!check_file_writable(cache_path+"/write.test")){
|
||||
log_e(MODULE, "Cannot write into cache_path=\"%s\"", cs(cache_path));
|
||||
fail = true;
|
||||
}
|
||||
|
||||
return !fail;
|
||||
}
|
||||
|
||||
}
|
@ -8,8 +8,10 @@ namespace client
|
||||
struct Config
|
||||
{
|
||||
ss_ server_address;
|
||||
ss_ polycode_path = "/home/celeron55/softat/polycode/";
|
||||
ss_ polycode_path = "../../polycode";
|
||||
ss_ share_path = "..";
|
||||
ss_ cache_path = "../cache";
|
||||
|
||||
bool check_paths();
|
||||
};
|
||||
}
|
||||
|
@ -94,6 +94,10 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if(!config.check_paths()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
Polycode::PolycodeView *view = new Polycode::PolycodeView("Hello Polycode!");
|
||||
sp_<app::App> app0(app::createApp(view));
|
||||
|
||||
|
57
src/server/config.cpp
Normal file
57
src/server/config.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
||||
#include "server/config.h"
|
||||
#include "core/log.h"
|
||||
#include "interface/fs.h"
|
||||
#include <fstream>
|
||||
#define MODULE "config"
|
||||
|
||||
namespace server {
|
||||
|
||||
static bool check_file_readable(const ss_ &path)
|
||||
{
|
||||
std::ifstream ifs(path);
|
||||
bool readable = ifs.good();
|
||||
if(!readable)
|
||||
log_e(MODULE, "File is not readable: \"%s\"", cs(path));
|
||||
return readable;
|
||||
}
|
||||
|
||||
static bool check_file_writable(const ss_ &path)
|
||||
{
|
||||
std::ofstream ofs(path);
|
||||
bool writable = ofs.good();
|
||||
if(!writable)
|
||||
log_e(MODULE, "File is not writable: \"%s\"", cs(path));
|
||||
return writable;
|
||||
}
|
||||
|
||||
bool Config::check_paths()
|
||||
{
|
||||
bool fail = false;
|
||||
|
||||
if(!check_file_readable(share_path+"/builtin/network/network.cpp")){
|
||||
log_e(MODULE, "Static files don't seem to exist in share_path=\"%s\"",
|
||||
cs(share_path));
|
||||
fail = true;
|
||||
}
|
||||
|
||||
if(!check_file_readable(interface_path+"/event.h")){
|
||||
log_e(MODULE, "Static files don't seem to exist in interface_path=\"%s\"",
|
||||
cs(interface_path));
|
||||
fail = true;
|
||||
}
|
||||
|
||||
auto *fs = interface::getGlobalFilesystem();
|
||||
fs->create_directories(rccpp_build_path);
|
||||
if(!check_file_writable(rccpp_build_path+"/write.test")){
|
||||
log_e(MODULE, "Cannot write into rccpp_build_path=\"%s\"",
|
||||
cs(rccpp_build_path));
|
||||
fail = true;
|
||||
}
|
||||
|
||||
return !fail;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ namespace server
|
||||
ss_ rccpp_build_path = "../cache/rccpp_build";
|
||||
ss_ interface_path = "../src/interface";
|
||||
ss_ share_path = "..";
|
||||
|
||||
bool check_paths();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
std::cerr<<"Buildat server"<<std::endl;
|
||||
|
||||
if(!config.check_paths()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(module_path.empty()){
|
||||
std::cerr<<"Module path (-m) is empty"<<std::endl;
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user