xx 2 лет назад
Родитель
Сommit
27c1a49923
4 измененных файлов с 138 добавлено и 62 удалено
  1. 53 15
      CMakeLists.txt
  2. 1 3
      src/core/define.h
  3. 17 13
      src/module/filesystem.cpp
  4. 67 31
      tests/main.cpp

+ 53 - 15
CMakeLists.txt

@@ -92,6 +92,7 @@ if(MSVC)
 	)
 
 else()
+	set(CMAKE_INSTALL_RPATH "/usr/local/lib")
 	link_directories(/usr/lib/x86_64-linux-gnu)
 	link_directories(/usr/local/lib)
 	target_link_libraries(${FASTWEBCORE} 
@@ -107,30 +108,67 @@ endif()
 
 # 编译测试调用示例
 add_executable(${PROJECT_NAME} tests/main.cpp)
-target_link_libraries(${PROJECT_NAME} ${FASTWEBCORE})
+if(MSVC)
+	target_link_libraries(${PROJECT_NAME} PRIVATE
+				${FASTWEBCORE}
+				odbc32.lib
+				User32.lib
+				Advapi32.lib
+				IPHLPAPI.lib
+				WS2_32.lib
+				Shell32.lib
+				${YLIB}/lib/libcrypto_static_win64.lib
+				$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.lib>
+				$<$<CONFIG:Debug>:${YLIB}/lib/ylib_d.lib>
+				$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.lib>
+				$<$<CONFIG:Release>:${YLIB}/lib/ylib.lib>
+		)
+else()
+	target_link_libraries(${PROJECT_NAME} 
+			${FASTWEBCORE}
+			hpsocket
+			ylib
+			pthread
+	)
+endif()
+
 set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
  
 
 
 ########################  安装  ########################
-install(TARGETS ${FASTWEBCORE} DESTINATION $<IF:$<CONFIG:Debug>,bin/debug,bin/release>)
-install(TARGETS ${PROJECT_NAME} DESTINATION $<IF:$<CONFIG:Debug>,bin/debug,bin/release>)
 if(MSVC)
+	install(TARGETS ${FASTWEBCORE} DESTINATION $<IF:$<CONFIG:Debug>,bin/debug,bin/release>)
+	install(TARGETS ${PROJECT_NAME} DESTINATION $<IF:$<CONFIG:Debug>,bin/debug,bin/release>)
 	install(FILES ${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.dll DESTINATION bin/debug)
 	install(FILES ${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.dll DESTINATION bin/release)
+
+	install(FILES config.ini DESTINATION bin/debug)
+	install(FILES config.ini DESTINATION bin/release)
+	install(DIRECTORY ${PROJECT_SOURCE_DIR}/www DESTINATION bin/debug)
+	install(DIRECTORY ${PROJECT_SOURCE_DIR}/config DESTINATION bin/debug)
+	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}/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()
+	
+	install(TARGETS ${FASTWEBCORE} DESTINATION lib)
+	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}/src/module/basemodule.h DESTINATION include/${PROJECT_NAME})
+
+
+	install(FILES config.ini DESTINATION share/${PROJECT_NAME})
+	install(DIRECTORY ${PROJECT_SOURCE_DIR}/www DESTINATION share/${PROJECT_NAME})
+	install(DIRECTORY ${PROJECT_SOURCE_DIR}/config DESTINATION share/${PROJECT_NAME})
+
 endif()
-install(FILES config.ini DESTINATION bin/debug)
-install(FILES config.ini DESTINATION bin/release)
-install(DIRECTORY ${PROJECT_SOURCE_DIR}/www DESTINATION bin/debug)
-install(DIRECTORY ${PROJECT_SOURCE_DIR}/config DESTINATION bin/debug)
-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}/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)
 
 
 

+ 1 - 3
src/core/define.h

@@ -19,6 +19,4 @@
 
 
 
-#define GET_APP										\
-	sol::state_view lua(ts);							\
-	fastweb::app* app = lua["____app"]
+#define GET_APP		sol::state_view lua(ts);fastweb::app* app = lua["____app"]

+ 17 - 13
src/module/filesystem.cpp

@@ -23,14 +23,14 @@ void module::filesystem::copy_dir(const std::string& src_dir, const std::string&
 }
 bool module::filesystem::create_dir(const std::string& dirpath)
 {
-    return ylib::file::create_dir(dirpath,true);
+    return ylib::file::create_dir(dirpath, true);
 }
 sol::object module::filesystem::read(const std::string& filepath, sol::this_state s)
 {
     sol::object result;
     ylib::buffer data;
     if (ylib::file::read(filepath, data) == false)
-        result = sol::make_object(s,data.to_string());
+        result = sol::make_object(s, data.to_string());
     else
         result = sol::make_object(s, sol::nil);
     return result;
@@ -45,7 +45,11 @@ bool module::filesystem::remove(const std::string& filepath)
 }
 bool module::filesystem::remove_dir(const std::string& dirpath, bool recycle)
 {
-    return ylib::file::remove_dir(dirpath,recycle);
+#ifdef _WIN32
+    return ylib::file::remove_dir(dirpath, recycle);
+#else
+    return ylib::file::remove_dir(dirpath);
+#endif
 }
 bool module::filesystem::exist(const std::string& filepath)
 {
@@ -61,7 +65,7 @@ int64 module::filesystem::size(const std::string& filepath)
 }
 bool module::filesystem::copy(const std::string& src, const std::string& dst)
 {
-    return ylib::file::copy(src,dst);
+    return ylib::file::copy(src, dst);
 }
 timestamp module::filesystem::last_write_time(const std::string& filepath)
 {
@@ -77,14 +81,14 @@ void module::filesystem::regist(sol::state* lua)
         "list", &module::filesystem::list,
         "copy_dir", &module::filesystem::copy_dir,
         "create_dir", &module::filesystem::create_dir,
-        "read",module::filesystem::read,
-        "write",module::filesystem::write,
-        "remove",module::filesystem::remove,
-        "remove_dir",module::filesystem::remove_dir,
-        "exist",module::filesystem::exist,
-        "exist_dir",module::filesystem::exist_dir,
-        "size",module::filesystem::size,
-        "copy",module::filesystem::copy,
-        "last_write_time",module::filesystem::last_write_time
+        "read", module::filesystem::read,
+        "write", module::filesystem::write,
+        "remove", module::filesystem::remove,
+        "remove_dir", module::filesystem::remove_dir,
+        "exist", module::filesystem::exist,
+        "exist_dir", module::filesystem::exist_dir,
+        "size", module::filesystem::size,
+        "copy", module::filesystem::copy,
+        "last_write_time", module::filesystem::last_write_time
     );
 }

+ 67 - 31
tests/main.cpp

@@ -2,52 +2,88 @@
 #include <iostream>
 #include "core/entry.h"
 #include <filesystem>
-std::string config_filepath;
-void* fastweb_app_ptr = nullptr;
-void start()
+#include "util/file.h"
+#include "util/strutils.h"
+#define QUIT_WAIT 				std::cout << "Please exit after entering any character...";std::cin.get();return -1
+
+void* start(const char* config_filepath)
 {
-	fastweb_app_ptr = fastweb_start(config_filepath.c_str());
+	return fastweb_start(config_filepath);
 }
-void close()
+void close(void* app)
 {
-	if(fastweb_app_ptr == nullptr)
-		fastweb_close(fastweb_app_ptr);
-	fastweb_app_ptr = nullptr;
+	if(app == nullptr)
+		fastweb_close(app);
 }
-int main()
+void ouput_help()
 {
-	config_filepath = std::filesystem::current_path().string() + "/config.ini";
+	std::cerr << "No configuration file path provided. Please provide the path to a config.ini file as an argument." << std::endl;
 
-	std::string input = "restart";
-	while (true)
+	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[]) 
+{
+	if (argc < 2) { ouput_help(); QUIT_WAIT; }
+	std::string type = argv[1];
+	if (type == "help")
 	{
-		if (input == "restart")
+		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()))
 		{
-			std::cout << "closing..." << std::endl;
-			close();
-			std::cout << "starting..." << std::endl;
-			start();
-			if (fastweb_app_ptr == nullptr)
+			app = start(std::filesystem::absolute(value).string().c_str());
+			if (app == nullptr)
 			{
-				std::cin.get();
-				return -1;
+				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;
+				}
 			}
-			std::cout << "started" << std::endl;
-		}
-		else if (input == "quit" || input == "exit")
-		{
-			close();
-			std::cout << "closed";
-			break;
 		}
 		else
 		{
-			std::cout << "Enter \"quit\" or \"exit\" to exit the application" << std::endl;
-			std::cout << "Enter \"restart\"  to restart the application" << std::endl;
+			std::cerr << "file not found: " << std::filesystem::absolute(value).string() << std::endl;
+			QUIT_WAIT;
 		}
+	}
+	if (argc < 4) { ouput_help(); QUIT_WAIT; }
 
-
-		std::cin >> input;
+	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 0;
 }