更新兼容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

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"
#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)
#include "fastweb.h"
int main(int argv,char* argc[])
{
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::vector<std::string> param;
for(size_t i=1;i<argv;i++)
param.push_back(argc[i]);
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;
}
fastweb fw(param);
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();
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;
}
return 0;
}