同步操作将从 寻根/cppweb 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <stdx/all.h>const char* GetTemplateConfig();#ifndef XG_LINUXconst char* GetResourceTemplate();SmartBuffer GetApplicationIconData();#endifclass CppShellApplication : public Application{protected:string cmd;string path;string appname;string exepath;string reslink;ConfigFile cfg;time_t utime = 0;time_t etime = 0;time_t rtime = 0;const char* srcpath = NULL;string checkResource(){#ifndef XG_LINUXconst char* end = strstr(srcpath, ".");if (end){string content;string respath = string(srcpath, end) + ".rc";rtime = path::mtime(respath);if (rtime <= 0){content = GetResourceTemplate();rtime = etime;}else{stdx::GetFileContent(content, respath);}string reslink = respath + ".o";if (rtime >= etime || path::type(reslink) == eNONE){XFile file;string icon = appname + ".ico";string data = stdx::replace(content, "${ICON}", icon);if (data != content){SmartBuffer tmp = GetApplicationIconData();file.open(icon, eCREATE);file.write(tmp.str(), tmp.size());file.close();}data = stdx::replace(data, "${NAME}", appname);data = stdx::replace(data, "${VERSION}", "1.0.0");data = stdx::replace(data, "${COPYRIGHT}", "copyright@winfeng");if (data != content){file.open(respath, eCREATE);file.write(data.c_str(), data.size());file.close();}proc::exec("windres", respath, reslink);rtime = etime;}return reslink;}#endifreturn stdx::EmptyString();}bool loadConifg(){path = path::parent(srcpath = GetCmdParam(1));if (path.empty()){path = Process::GetCurrentDirectory();if (path.empty()) path = ".";appname = srcpath;}else{static string filename = appname = path::name(srcpath);Process::SetCurrentDirectory(path);srcpath = filename.c_str();}appname = appname.substr(0, appname.rfind('.'));exepath = path + "/.bin/" + appname;#ifndef XG_LINUXexepath += ".exe";#endifetime = path::mtime(exepath);utime = path::mtime(srcpath);reslink = checkResource();if (path::size("config.lua") > 0){if (etime > utime && etime > rtime && etime > path::mtime("config.lua")) return true;CHECK_FALSE_RETURN(cfg.open("config.lua"));}else{if (etime > utime && etime > rtime) return true;if (proc::exec("which", "g++").str()){cfg.setVariable("CC", "g++");}else{cfg.setVariable("CC", "gcc");}}string cc = cfg.getVariable("CC");string flag = cfg.getVariable("FLAG");string link = cfg.getVariable("LIB_LINK");auto checklink = [&](const string& lib){string tag = " " + lib + " ";string tmp = " " + link + " ";if (tmp.find(tag) == string::npos) link += " " + lib;};auto checkflag = [&](const string& lib){string tag = " " + lib + " ";string tmp = " " + flag + " ";if (tmp.find(tag) == string::npos) flag += " " + lib;};link = stdx::replace(link, "\t", " ");link = stdx::replace(link, " ", " ");checkflag("-pthread");if (reslink.length() > 0) checklink(reslink);#ifdef XG_LINUXcheckflag("-DXG_LINUX");checklink("-lutil");checklink("-ldl");checklink("-lm");#elseflag = stdx::replace(flag, "-DXG_LINUX", "");if (GetCmdParam("--{hidden}")) checkflag("-mwindows");checklink("-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,-Bdynamic,--no-whole-archive");checklink("-static-libstdc++ -static-libgcc");checklink("-lcomdlg32");checklink("-lws2_32");checklink("-lole32");checklink("-lgdi32");checklink("-lpsapi");checklink("-luuid");checklink("-lm");#endifstdx::format(cmd, "%s %s -o \"%s\" %s %s", cc.c_str(), flag.c_str(), exepath.c_str(), srcpath, link.c_str());path::mkdir(".bin");return true;}public:bool main(){string msg;const char* param = NULL;int cnt = GetCmdParamCount();static char buffer[40960] = { 0 };if ((param = GetCmdParam("-etc"))){if (*param){TextFile out;if (GetCmdParam("-i") && path::size(param) > 0){CHECK_FALSE_RETURN(cmdx::CheckCommand("file[%s] exists, overwrite or not ? (y/n)", path::name(param).c_str()));}if (out.open(param, true)){out.puts(GetTemplateConfig());puts("export template config success");}else{puts("export template config failed");return false;}}else{puts(GetTemplateConfig());}return true;}if (GetCmdParam(1) == NULL){ColorPrint(eRED, "%s\n", "please input source file");return false;}if (path::size(GetCmdParam(1)) < 0){ColorPrint(eRED, "%s\n", "load source file failed");return false;}loadConifg();if (exepath.empty()){ColorPrint(eRED, "%s\n", "load build-essential failed");return false;}if (cmd.length() > 0){if (cmdx::RunCommand(cmd, buffer, sizeof(buffer)) > 0) msg = buffer;if (path::mtime(exepath) <= utime){if (msg.empty()) msg = "compile failed";ColorPrint(eRED, "%s\n", msg.c_str());return false;}}if (GetCmdParam("--{compile}")){ColorPrint(eGREEN, "%s\n", "compile success");return true;}cmd = stdx::quote(exepath);for (int i = 2; i < cnt; i++){const char* param = GetCmdParam(i);if (strcmp(param, "--{hidden}")){cmd += " " + stdx::quote(param);}}return System(cmd.c_str()) >= 0;}};START_APP(CppShellApplication)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。