更新兼容linux包管理器

This commit is contained in:
2024-06-19 14:49:32 +08:00
parent 843f7ea33e
commit f5eb5559d3
12 changed files with 688 additions and 260 deletions

64
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,64 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"filesystem": "cpp"
}
}

View File

@@ -10,7 +10,7 @@ if(MSVC)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Build config types" FORCE)
endif()
# C++等级
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(FASTWEBCORE ${PROJECT_NAME}core)
# 安装复制
@@ -63,6 +63,7 @@ else()
endif()
# 根据构建类型添加定义
add_library(${FASTWEBCORE} SHARED ${SOURCE_FILES} ${HEADER_FILES})
set_target_properties(${FASTWEBCORE} PROPERTIES OUTPUT_NAME_DEBUG "${FASTWEBCORE}_d" OUTPUT_NAME_RELEASE ${FASTWEBCORE})
@@ -114,10 +115,11 @@ else()
endif()
add_definitions(-DFASTWEB_EXE)
# 编译测试调用示例
add_executable(${PROJECT_NAME}
tests/main.cpp
tests/slave.cpp
tests/fastweb.cpp
)
if(MSVC)
target_link_libraries(${PROJECT_NAME} PRIVATE
@@ -163,9 +165,9 @@ if(MSVC)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/www DESTINATION bin/release)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/config DESTINATION bin/release)
install(FILES ${PROJECT_SOURCE_DIR}/src/core/entry.h DESTINATION include)
install(FILES ${PROJECT_SOURCE_DIR}/module/dll_interface.h DESTINATION include)
install(FILES ${PROJECT_SOURCE_DIR}/include/dll_interface.h DESTINATION include)
install(FILES ${PROJECT_SOURCE_DIR}/src/module/basemodule.h DESTINATION include)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/3rdparty/sol DESTINATION include)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/3rdparty/lua/include/ DESTINATION include/lua)
else()
@@ -173,7 +175,7 @@ else()
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES ${PROJECT_SOURCE_DIR}/src/core/entry.h DESTINATION include/${PROJECT_NAME})
install(FILES ${PROJECT_SOURCE_DIR}/module/dll_interface.h DESTINATION include/${PROJECT_NAME})
install(FILES ${PROJECT_SOURCE_DIR}/include/dll_interface.h DESTINATION include/${PROJECT_NAME})
install(FILES ${PROJECT_SOURCE_DIR}/src/module/basemodule.h DESTINATION include/${PROJECT_NAME})
@@ -186,4 +188,5 @@ endif()
install(DIRECTORY ${PROJECT_SOURCE_DIR}/3rdparty/sol DESTINATION include)

View File

@@ -82,7 +82,7 @@ bool fastweb::app::start(const std::string& config_filepath)
ws_config.name = "master";
ws_config.router.threadpool.size = 40;
ws_config.router.threadpool.size = 10;
ws_config.router.threadpool.queuemax = 10000;
ws_config.session.dirpath = this->config->website.session_dir;
ws_config.session.timeout_sec = this->config->website.session_timeout_sec;

View File

@@ -17,51 +17,20 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
#include "config.h"
#include <regex>
#include "core/app.h"
#include "utils/parseconfig.hpp"
fastweb::config::config(fastweb::app* ptr):Interface(ptr)
{
}
bool fastweb::config::open(const std::string& ini_filepath)
{
m_ini_filepath = ini_filepath;
if (ylib::file::exist(ini_filepath) == false)
auto [result,err] = parseconfig(m_ini,ini_filepath);
if(result == false)
{
LOG_ERROR("not found file: " + ini_filepath);
LOG_ERROR(err);
return false;
}
std::string temp_filepath = ylib::file::temp_filepath() + ".bak";
if (ylib::file::copy(ini_filepath, temp_filepath) == false)
{
LOG_ERROR("Failed to copy temporary INI configuration file from '" + ini_filepath + "' to '" + temp_filepath + "'.");
return false;
}
std::string src_content = ylib::file::read(temp_filepath);
// EXE运行目录
src_content = strutils::replace(src_content, "${current_dir}", strutils::replace(system::current_dir(),'\\','/'));
// 配置文件目录
{
std::string ini_dir = ylib::file::parent_dir(ini_filepath);
src_content = strutils::replace(strutils::replace(src_content, "${config_dir}", ini_dir), '\\', '/');
}
ylib::file::write(temp_filepath,src_content);
if (m_ini.open(temp_filepath))
{
auto vars = extractVariableNames(ylib::file::read(temp_filepath));
for (size_t i = 0; i < vars.size(); i++)
{
if (m_ini.read("variable", vars[i]) == "")
{
LOG_ERROR("Variable declaration not found or empty content: ${" + vars[i] + "}");
return false;
}
src_content = strutils::replace(src_content, "${" + vars[i] + "}", m_ini.read("variable", vars[i]));
}
}
ylib::file::write(temp_filepath,src_content);
m_ini.close();
m_ini.open(temp_filepath);
cache();
return true;
}
@@ -92,19 +61,6 @@ ylib::json fastweb::config::read_runtime()
{
return ylib::json::from(ylib::file::read(ylib::file::parent_dir(m_ini_filepath) + "/.fastweb_runtime"));
}
std::vector<std::string> fastweb::config::extractVariableNames(const std::string& text)
{
std::regex pattern("\\$\\{([^}]+)\\}"); // 使用捕获组提取中间的内容
std::vector<std::string> results;
// 使用 std::sregex_iterator 迭代所有匹配项
auto begin = std::sregex_iterator(text.begin(), text.end(), pattern);
auto end = std::sregex_iterator();
for (std::sregex_iterator i = begin; i != end; ++i) {
std::smatch match = *i;
results.push_back(match[1]); // 仅添加捕获组的内容
}
return results;
}
void fastweb::config::cache()
{

View File

@@ -80,7 +80,7 @@ void fastweb::log::print(log_type type,const std::string& msg,const std::string&
#ifdef _WIN32
ylib::println(codec::to_gbk(msg), (ylib::ConsoleTextColor)color);
#else
ylib::println(msg, (ylib::ConsoleTextColor)color);
ylib::print(msg, (ylib::ConsoleTextColor)color);
#endif
log_info li;

71
src/utils/parseconfig.hpp Normal file
View File

@@ -0,0 +1,71 @@
#pragma once
#include <vector>
#include <regex>
#include <string>
#include <tuple>
#include "util/ini.h"
#include "util/file.h"
#include "util/system.h"
#include "util/strutils.h"
std::vector<std::string> __extractVariableNames(const std::string& text)
{
std::regex pattern("\\$\\{([^}]+)\\}"); // 使用捕获组提取中间的内容
std::vector<std::string> results;
// 使用 std::sregex_iterator 迭代所有匹配项
auto begin = std::sregex_iterator(text.begin(), text.end(), pattern);
auto end = std::sregex_iterator();
for (std::sregex_iterator i = begin; i != end; ++i) {
std::smatch match = *i;
results.push_back(match[1]); // 仅添加捕获组的内容
}
return results;
}
std::tuple<bool,std::string> parseconfig(ylib::ini &ini,const std::string& ini_filepath)
{
if (ylib::file::exist(ini_filepath) == false)
{
#ifdef FASTWEB_EXE
return std::make_tuple(false,"未找到配置文件: " + ini_filepath);
#else
return std::make_tuple(false,"not found ini: " + ini_filepath);
#endif
}
std::string temp_filepath = ylib::file::temp_filepath() + ".bak";
if (ylib::file::copy(ini_filepath, temp_filepath) == false)
{
#ifdef FASTWEB_EXE
return std::make_tuple(false,"Failed to copy temporary INI configuration file from '" + ini_filepath + "' to '" + temp_filepath + "'.");
#else
return std::make_tuple(false,"配置文件复制到临时目录失败 from '" + ini_filepath + "' to '" + temp_filepath + "'.");
#endif
}
std::string src_content = ylib::file::read(temp_filepath);
// EXE运行目录
src_content = strutils::replace(src_content, "${current_dir}", strutils::replace(system::current_dir(),'\\','/'));
// 配置文件目录
{
std::string ini_dir = ylib::file::parent_dir(ini_filepath);
src_content = strutils::replace(strutils::replace(src_content, "${config_dir}", ini_dir), '\\', '/');
}
ylib::file::write(temp_filepath,src_content);
if (ini.open(temp_filepath))
{
auto vars = __extractVariableNames(ylib::file::read(temp_filepath));
for (size_t i = 0; i < vars.size(); i++)
{
if (ini.read("variable", vars[i]) == "")
{
return std::make_tuple(false,"Variable declaration not found or empty content: ${" + vars[i] + "}");
}
src_content = strutils::replace(src_content, "${" + vars[i] + "}", ini.read("variable", vars[i]));
}
}
ylib::file::write(temp_filepath,src_content);
ini.close();
ini.open(temp_filepath);
return std::make_tuple(true,"");
}

455
tests/fastweb.cpp Normal file
View File

@@ -0,0 +1,455 @@
/*Software License
Copyright(C) 2024[liuyingjie]
License Terms
Usage Rights
Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
If the source code is modified, the modifications must be open - sourced under the same license.This means that the modifications must be disclosed and accompanied by a copy of this license.
Future Versions Updates
From this version onwards, all future releases will be governed by the terms of the latest version of the license.This license will automatically be nullified and replaced by the new version.
Users must comply with the terms of the new license issued in future releases.
Liability and Disclaimer
This software is provided “as is”, without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non - infringement.In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Contact Information
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
*/
#include "fastweb.h"
#include <filesystem>
#include "util/strutils.h"
#include "util/system.h"
#include "util/codec.h"
#include "util/file.h"
#include "util/print.h"
#include "../src/utils/parseconfig.hpp"
#include "net/http_client_plus.h"
#include "core/entry.h"
bool exsit_install_software(std::string name){
std::string command = "which " + name + " > /dev/null 2>&1";
int result = std::system(command.c_str());
return (result == 0);
};
std::pair<int,std::string> execute_command(const std::string& command){
std::array<char, 128> buffer;
std::string result;
int return_code = 0;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen((command + " 2>&1").c_str(), "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
// Read the output a line at a time - output it.
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
// Get the return code
return_code = pclose(pipe.release());
return std::make_pair(return_code, command+"\n"+result);
};
fastweb::fastweb(const std::vector<std::string> &param)
{
auto equals=[&](std::vector<std::string> p2,int all_size)->bool{
if(param.size() < all_size)
return false;
if(param.size()<p2.size())
return false;
for(size_t i=0;i<p2.size();i++)
{
if(param[i] != p2[i])
return false;
}
return true;
};
std::cout << "|------------------------[FASTWEB]----------------------------" << std::endl;
std::cout << "| 软件版本:\t"<< FASTWEB_VERSION << std::endl;
std::cout << "| 工作目录:\t"<< strutils::replace(system::current_dir(),'\\','/') << std::endl;
#ifdef _WIN32
std::cout << "| Windows平台推荐使用网站管理器部署https://fwlua.com/thread-3-1-1.html"<<std::endl;
#endif
std::cout << "| 启动参数" << std::endl;
for (int i = 0; i < param.size(); i++)
{
std::cout << "|\t" << param[i] << std::endl;
}
std::cout << "|----------------------------------------------------------------" << std::endl;
if(equals({"start"},2))
{
start(param[1],false);
}
else if(equals({"start2"},2))
{
start(param[1],true);
}
else if(equals({"create","config"},3))
{
create_config(param[2]);
}
else if(equals({"create","website"},3))
{
create_website(param[2]);
}
else if(equals({"instmod"},3))
{
install_module(param[1],param[2]);
}
else if(equals({"uninstmod"},3))
{
uninstall_module(param[1],param[2]);
}
else if(equals({"module","list"},2))
{
module_list();
}
else
{
output_help();
}
}
fastweb::~fastweb()
{
}
void fastweb::start(std::string ini_filepath, bool wait)
{
ini_filepath = std::filesystem::absolute(ini_filepath).string();
if (ylib::file::exist(ini_filepath))
{
if (fastweb_start(ini_filepath.c_str()) == nullptr)
return;
}
else
{
std::cerr << "未找到配置文件: " << ini_filepath<< std::endl;
}
}
void fastweb::stop(void *app)
{
if(app != nullptr)
{
fastweb_close(app);
}
}
void fastweb::output_help()
{
int index = 1;
std::cout << "------------------------------------------------------------------------------" << std::endl;
std::cout << "| Fastweb指令说明:" << std::endl;
std::cout << "|"<<index++<<"、fastweb start config.ini\t\t [加载配置文件并启动Fastweb]" << std::endl;
#ifndef _WIN32
std::cout << "|"<<index++<<"、fastweb create config .\t\t [创建配置文件模板到指定路径]" << std::endl;
std::cout << "|"<<index++<<"、fastweb create website .\t\t [创建网站示例模板到指定路径]" << std::endl;
#endif
std::cout << "|"<<index++<<"、fastweb instmod config.ini mysql\t\t [为指定项目安装模块]" << std::endl;
std::cout << "|"<<index++<<"、fastweb uninstmod config.ini mysql\t\t [为指定项目卸载模块]" << std::endl;
std::cout << "|"<<index++<<"、fastweb module list\t\t [显示所有模块列表]" << std::endl;
std::cout << "------------------------------------------------------------------------------" << std::endl;
}
void fastweb::create_config(std::string dirpath)
{
ylib::file::copy("/usr/local/share/fastweb/config.ini",dirpath);
}
void fastweb::create_website(std::string dirpath)
{
ylib::file::copy_dir("/usr/local/share/fastweb", dirpath);
}
void fastweb::install_module(std::string ini_filepath, std::string name)
{
if(parse_config(ini_filepath) == false)
return;
std::vector<fastweb::module_info> list;
if(module_infos(list) == false)
return;
fastweb::module_info info;
for(size_t i=0;i<list.size();i++)
{
if(list[i].name_en == name)
{
info = list[i];
break;
}
}
if(info.name == "")
{
std::cout<<"未找到 `"<<name<<"` 模块"<<std::endl;
return;
}
#ifdef _WIN32
install_module_windows(info);
#else
install_module_linux(info);
#endif
}
void fastweb::uninstall_module(std::string ini_filepath, std::string name)
{
if(parse_config(ini_filepath) == false)
return;
std::vector<fastweb::module_info> list;
if(module_infos(list) == false)
return;
fastweb::module_info info;
for(size_t i=0;i<list.size();i++)
{
if(list[i].name_en == name)
{
info = list[i];
break;
}
}
if(info.name == "")
{
std::cout<<"未找到 `"<<name<<"` 模块"<<std::endl;
return;
}
std::string module_dirpath = m_ini.read("scripts","module_dir")+"/.install/"+info.id;
if(ylib::file::exist_dir(module_dirpath))
{
if(ylib::file::remove_dir(module_dirpath) == false)
{
std::cerr<<"删除模块目录失败("+module_dirpath+")"<<std::endl;
}
else
{
std::cerr<<"删除模块目录成功("+module_dirpath+")"<<std::endl;
}
}
#ifndef _WIN32
if(info.type == "lua")
{
std::cout<<"正在卸载 `"<<info.name_en<<"` 库"<<std::endl;
auto [code,err] = execute_command("sudo luarocks remove "+info.name_en);
if(code == 0)
{
std::cout<<"卸载成功"<<std::endl;
}
else
{
std::cout<<"卸载失败:"<<std::endl;
std::cout<<err<<std::endl;
}
}
#endif
std::cout<<"OK"<<std::endl;
}
void fastweb::module_list()
{
std::vector<fastweb::module_info> list;
if(module_infos(list) == false)
return;
std::cout<<"--------------------------模块列表---------------------------"<<std::endl;
for(size_t i=0;i<list.size();i++)
{
#ifdef _WIN32
if(list[i].download_win64.empty())
continue;
#else
if(list[i].download_linux_type.empty())
continue;
#endif
if(i!=0)
std::cout<<"|-------------------------------------------------------------"<<std::endl;
std::cout<<"| 模块名称:\t"<<list[i].name_en<<std::endl;
std::cout<<"| 中文名称:\t"<<list[i].name<<std::endl;
std::cout<<"| 描述信息:\t"<<list[i].desc<<std::endl;
std::cout<<"| 文档地址:\t"<<list[i].doc<<std::endl;
std::cout<<"| 模块类型:\t";
if(list[i].type == "fastweb")
std::cout<<"FastWeb"<<std::endl;
else if(list[i].type == "lua")
std::cout<<"LUA"<<std::endl;
else if(list[i].type == "other")
std::cout<<"网友上传"<<std::endl;
}
std::cout<<"|------------------------------------------------------------"<<std::endl;
}
bool fastweb::module_infos(std::vector<fastweb::module_info>& list)
{
std::cout<<"正在获取最新模块列表信息..."<<std::endl;
network::http::client_plus client;
if(client.get(FASTWEB_MODULE_JSON_URL) == false)
{
std::cerr<<"下载模块列表信息失败: "<<FASTWEB_MODULE_JSON_URL<<", "<<client.last_error()<<std::endl;
return false;
}
if(client.status() != 200)
{
std::cerr<<"下载模块列表信息失败: "<<FASTWEB_MODULE_JSON_URL<<", status: "<<client.status()<<std::endl;
return false;
}
auto data = ylib::json::from(client.response());
std::vector<std::string> types = {"fastweb","lua","other"};
for(size_t i=0;i<types.size();i++)
{
auto td = data[types[i]];
for(size_t k = 0;k<td.size();k++)
{
module_info info;
info.id = std::to_string(td[k]["id"].to<int>());
info.name = td[k]["name"].to<std::string>();
info.name_en = td[k]["name_en"].to<std::string>();
info.desc = td[k]["desc"].to<std::string>();
info.doc = td[k]["doc"].to<std::string>();
info.type = types[i];
info.download_win64 = td[k]["doc"].to<std::string>();
info.download_linux_url = td[k]["download"]["linux"]["url"].to<std::string>();
info.download_linux_type = td[k]["download"]["linux"]["type"].to<std::string>();
list.push_back(info);
}
}
return true;
}
void fastweb::wait()
{
while(true)
system::sleep_msec(1000*60);
}
void fastweb::install_module_linux(fastweb::module_info info)
{
if(exsit_install_software("lua") == false)
{
std::cout<<"LUA未安装请重新执行fastweb一键构建脚本并确认lua编译安装部分正确执行"<<std::endl;
return;
}
if(info.type == "fastweb" || info.type == "other")
{
if(info.download_linux_type == "zip")
{
std::cout<<"正在安装 `"<<info.name_en<<"` 库"<<std::endl;
network::http::client_plus client;
if(client.get(info.download_linux_url) == false)
{
std::cerr<<"下载模块压缩包失败: "<<info.download_linux_url<<", "<<client.last_error()<<std::endl;
return;
}
if(client.status() != 200)
{
std::cerr<<"下载模块压缩包失败: "<<info.download_linux_url<<", status: "<<client.status()<<std::endl;
return;
}
std::string zip_filepath = ylib::file::temp_filepath()+".zip";
ylib:file::write(zip_filepath,client.response());
std::string new_module_dirpath = m_ini.read("scripts","module_dir")+"/.install/"+info.id;
ylib::file::create_dir(new_module_dirpath,true);
std::string cmd = "unzip -o -q "+zip_filepath+" -d "+new_module_dirpath;
auto [code,err] = execute_command(cmd);
if(code != 0)
{
std::cerr<<"安装失败:"<<std::endl;
std::cerr<<cmd<<std::endl;
std::cerr<<err<<std::endl;
}
else
{
std::cerr<<"安装成功"<<std::endl;
}
}
else if(info.download_linux_type == "github")
{
std::cout<<"正在安装 `"<<info.name_en<<"` 库"<<std::endl;
std::string tdir = ylib::file::temp_filepath();
ylib::file::create_dir(tdir,true);
std::string cmd = "git clone "+info.download_linux_url+" "+tdir;
auto [code,result] = execute_command(cmd);
if(code != 0)
{
std::cerr<<"克隆仓库失败:"<<std::endl;
std::cerr << cmd << std::endl;
std::cerr << result << std::endl;
return;
}
cmd = tdir+"/build.sh";
auto [code2,result2] = execute_command(cmd);
if(code2 != 0)
{
std::cerr<<"执行安装命令失败:"<<std::endl;
std::cerr << cmd << std::endl;
std::cerr << result2 << std::endl;
return;
}
std::string new_module_dirpath = m_ini.read("scripts","module_dir")+"/.install/"+info.id;
ylib::file::create_dir(new_module_dirpath,true);
ylib::file::copy_dir(tdir+"/target",new_module_dirpath);
std::cout<<"安装成功"<<std::endl;
}
}
else if(info.type == "lua")
{
if(exsit_install_software("luarocks") == false)
{
std::cout<<"`luarocks` 未安装请先执行以下命令安装sudo apt install luarocks"<<std::endl;
return;
}
std::cout<<"正在安装 `"<<info.name_en<<"` 库"<<std::endl;
auto [code,err] = execute_command("sudo luarocks install "+info.name_en+" LUA_INCDIR=/usr/local/include LUA_LIBDIR=/usr/loca/lib/liblua.a");
if(code == 0)
{
std::cout<<"安装成功"<<std::endl;
}
else
{
std::cout<<"安装失败:"<<std::endl;
std::cout<<err<<std::endl;
}
}
}
void fastweb::install_module_windows(fastweb::module_info info)
{
}
bool fastweb::parse_config(const std::string &ini_filepath)
{
auto [result,err] = parseconfig(m_ini,ini_filepath);
if(result == false)
{
std::cerr<<err<<std::endl;
return false;
}
return true;
}

75
tests/fastweb.h Normal file
View File

@@ -0,0 +1,75 @@
#pragma once
#include <vector>
#include <string>
#include "base/define.h"
#include "util/ini.h"
#define FASTWEB_VERSION "V1.0.5"
#define FASTWEB_MODULE_JSON_URL "https://download.fwlua.com/module/module.json"
class fastweb
{
public:
fastweb(const std::vector<std::string>& param);
~fastweb();
private:
struct module_info{
std::string id;
std::string name;
std::string name_en;
std::string doc;
std::string desc;
std::string type;
std::string download_win64;
std::string download_linux_type;
std::string download_linux_url;
};
private:
/// @brief 启动
/// @param ini_filepath
/// @param wait
void start(std::string ini_filepath,bool wait);
/// @brief 停止
/// @param app
void stop(void* app);
/// @brief 输出HELP信息
void output_help();
/// @brief 创建配置文件
/// @param dirpath
void create_config(std::string dirpath);
/// @brief 创建网站木板
/// @param dirpath
void create_website(std::string dirpath);
/// @brief 安装模块
/// @param ini_filepath
/// @param name
void install_module(std::string ini_filepath,std::string name);
/// @brief 卸载模块
/// @param ini_filepath
/// @param name
void uninstall_module(std::string ini_filepath,std::string name);
/// @brief 模块列表
void module_list();
/// @brief 模块信息
/// @return
bool module_infos(std::vector<fastweb::module_info>& list);
private:
/// @brief 无限等待
void wait();
void install_module_linux(fastweb::module_info info);
void install_module_windows(fastweb::module_info info);
/// @brief 解析INI配置文件
/// @param ini_filepath
bool parse_config(const std::string& ini_filepath);
private:
ylib::ini m_ini;
};

View File

@@ -14,136 +14,15 @@ This software is provided “as is”, without any express or implied warranties
Contact Information
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
*/
#pragma once
#include <iostream>
#include "core/entry.h"
#include <filesystem>
#include "util/file.h"
#include "util/strutils.h"
#include "util/system.h"
#include "slave.h"
#include "fastweb.h"
int main(int argv,char* argc[])
{
std::vector<std::string> param;
for(size_t i=1;i<argv;i++)
param.push_back(argc[i]);
#define FASTWEB_VERSION "V1.0.5"
#define QUIT_WAIT std::cout << "Please exit after entering any character...";std::cin.get();return -1
void* start(const char* config_filepath)
{
return fastweb_start(config_filepath);
}
void close(void* app)
{
if(app == nullptr)
fastweb_close(app);
}
void ouput_help()
{
std::cerr << "No configuration file path provided. Please provide the path to a config.ini file as an argument." << std::endl;
std::cout << "------------------------------------------------------------------------------" << std::endl;
std::cout << "| The instructions are as follows:" << std::endl;
std::cout << "| 1、fastweb start config.ini\t\t [load the specified configuration and start Fastweb]" << std::endl;
std::cout << "| 2、fastweb create config .\t\t [create a default configuration file]" << std::endl;
std::cout << "| 3、fastweb create website .\t\t [create a default website directory]" << std::endl;
std::cout << "------------------------------------------------------------------------------" << std::endl;
}
int main(int argc, char* argv[])
{
std::cout << "|------------------------[FASTWEB]----------------------------" << std::endl;
std::cout << "| Version:\t"<< FASTWEB_VERSION << std::endl;
std::cout << "| WorkingDirectory:\t"<< strutils::replace(system::current_dir(),'\\','/') << std::endl;
std::cout << "| Args" << std::endl;
for (int i = 0; i < argc; i++)
{
std::cout << "|\t" << argv[i] << std::endl;
}
std::cout << "|----------------------------------------------------------------" << std::endl;
if (argc < 2) { ouput_help(); QUIT_WAIT; }
std::string type = argv[1];
if (type == "help")
{
ouput_help();
QUIT_WAIT;
}
if (argc < 3){ouput_help();QUIT_WAIT;}
void* app = nullptr;
std::string value = argv[2];
if (type == "start")
{
if (ylib::file::exist(std::filesystem::absolute(value).string()))
{
app = start(std::filesystem::absolute(value).string().c_str());
if (app == nullptr)
{
QUIT_WAIT;
}
while (true) {
std::string input;
std::cin >> input;
if (input == "quit" || input == "exit")
{
close(app);
std::cout << "closed";
return 0;
}
else
{
std::cout << "Enter \"quit\" or \"exit\" to exit the application" << std::endl;
std::cout << "Enter \"restart\" to restart the application" << std::endl;
}
}
}
else
{
std::cerr << "file not found: " << std::filesystem::absolute(value).string() << std::endl;
QUIT_WAIT;
}
}
else if (type == "start2")
{
if (ylib::file::exist(std::filesystem::absolute(value).string()))
{
app = start(std::filesystem::absolute(value).string().c_str());
if (app == nullptr)
return -1;
while (true)
system::sleep_msec(1000 * 60);
}
else
return -1;
}
else if (type == "fastwebmanager")
{
int flag = ylib::stoi(argv[2]);
slave s("fastweb_shardmemory", flag);
app = start(argv[3]);
if (app == nullptr)
{
s.write(1);
return -1;
}
s.write(2);
// 等待关闭信号
s.wait();
fastweb fw(param);
return 0;
}
if (argc < 4) { ouput_help(); QUIT_WAIT; }
if (type == "create")
{
std::string path = std::filesystem::absolute(argv[3]).string();
if (value == "config")
{
ylib::file::copy("/usr/local/share/fastweb/config.ini",path);
}
else if (value == "website")
{
ylib::file::copy_dir("/usr/local/share/fastweb", path);
}
}
return -1;
}

View File

@@ -1,44 +0,0 @@
/*Software License
Copyright(C) 2024[liuyingjie]
License Terms
Usage Rights
Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
If the source code is modified, the modifications must be open - sourced under the same license.This means that the modifications must be disclosed and accompanied by a copy of this license.
Future Versions Updates
From this version onwards, all future releases will be governed by the terms of the latest version of the license.This license will automatically be nullified and replaced by the new version.
Users must comply with the terms of the new license issued in future releases.
Liability and Disclaimer
This software is provided “as is”, without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non - infringement.In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
Contact Information
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
*/
#include "slave.h"
#include "util/system.h"
slave::slave(const std::string& name,int flag):m_flag(flag)
{
m_sm = std::make_unique<ylib::sharedmem>(false);
if (m_sm->create(name, 128 * 2) == false)
{
std::cerr << m_sm->last_error() << std::endl;
abort();
}
}
slave::~slave()
{
m_sm->destory();
}
void slave::wait()
{
while ((*m_sm)[m_flag] == 0)
system::sleep_msec(10);
}
void slave::write(uchar data)
{
((char*)m_sm->mem())[m_flag+128] = data;
}

View File

@@ -1,31 +0,0 @@
#pragma once
#include <tuple>
#include <memory>
#include "util/thread.h"
#include "util/sharedmem.h"
#include "net/udp_node.h"
#include "base/error.h"
/// <summary>
/// 从设备
/// </summary>
class slave:public ylib::error_base
{
public:
slave(const std::string& name,int flag);
~slave();
/// <summary>
/// 等待
/// </summary>
void wait();
/// <summary>
/// 写入
/// </summary>
/// <param name="data"></param>
void write(uchar data);
private:
std::string m_name;
// 共享内存
std::unique_ptr<ylib::sharedmem> m_sm;
// 标记
int m_flag = -1;
};