mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-30 12:47:48 +02:00
Added --install flag.
This commit is contained in:
parent
c741382fc9
commit
3ef89718a1
5 changed files with 84 additions and 9 deletions
|
@ -125,6 +125,11 @@ namespace config {
|
|||
return nDefault;
|
||||
}
|
||||
|
||||
bool HasArg(const std::string& strArg)
|
||||
{
|
||||
return mapArgs.count(strArg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace filesystem
|
||||
|
@ -258,6 +263,46 @@ namespace filesystem
|
|||
{
|
||||
return GetDataDir () / "certificates";
|
||||
}
|
||||
|
||||
void InstallFiles()
|
||||
{
|
||||
namespace bfs = boost::filesystem;
|
||||
boost::system::error_code e;
|
||||
const bfs::path source = bfs::canonical(
|
||||
config::GetArg("-install", "webui"), e
|
||||
);
|
||||
|
||||
const bfs::path destination = GetWebuiDataDir();
|
||||
|
||||
if(e || !bfs::is_directory(source))
|
||||
throw std::runtime_error("Given directory is invalid or does not exist");
|
||||
|
||||
// TODO: check that destination is not in source
|
||||
|
||||
try {
|
||||
CopyDir(source, destination);
|
||||
} catch(...) {
|
||||
throw std::runtime_error("Could not copy webui folder to i2pd folder.");
|
||||
}
|
||||
}
|
||||
|
||||
void CopyDir(const boost::filesystem::path& src, const boost::filesystem::path& dest)
|
||||
{
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
bfs::create_directory(dest);
|
||||
|
||||
for(bfs::directory_iterator file(src); file != bfs::directory_iterator(); ++file) {
|
||||
const bfs::path current(file->path());
|
||||
if(bfs::is_directory(current))
|
||||
CopyDir(current, dest / current.filename());
|
||||
else
|
||||
bfs::copy_file(
|
||||
current, dest / current.filename(),
|
||||
bfs::copy_option::overwrite_if_exists
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace http
|
||||
|
|
|
@ -41,6 +41,11 @@ namespace util
|
|||
* @param nDefault the default value to be returned
|
||||
*/
|
||||
const char* GetCharArg(const std::string& strArg, const std::string& nDefault);
|
||||
|
||||
/**
|
||||
* @return true if the argument is set, false otherwise
|
||||
*/
|
||||
bool HasArg(const std::string& strArg);
|
||||
}
|
||||
|
||||
namespace filesystem
|
||||
|
@ -95,6 +100,18 @@ namespace util
|
|||
* @return the path of the certificates directory
|
||||
*/
|
||||
boost::filesystem::path GetCertificatesDir();
|
||||
|
||||
/**
|
||||
* Installs the webui files.
|
||||
* @throw std::runtime_error when installation fails
|
||||
*/
|
||||
void InstallFiles();
|
||||
|
||||
/**
|
||||
* Copies all files and directories in src to dest.
|
||||
* @warning overrides existing files
|
||||
*/
|
||||
void CopyDir(const boost::filesystem::path& src, const boost::filesystem::path& dest);
|
||||
}
|
||||
|
||||
namespace http
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue