Ejemplo n.º 1
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(curt_app);
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);

    /* 参数解析 <网页文件> */
    if (argc < 1)
        return (QST_ERROR);
    g_html = argv[0];

    /* 标准 VCL 过程开始 */
    try
    {
        Application->Initialize();
        Application->Title = WIN_TITLE;
        Application->CreateForm(__classid(TfrmMain), &frmMain);
        Application->Run();
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
            throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }
    return (QST_OKAY);
}
Ejemplo n.º 2
0
/*
=======================================
    主程序
=======================================
*/
int main (int argc, char *argv[])
{
    fbuf_t file;
    const ansi_t *root;

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_CUI))
        return (QST_ERROR);

    /* 参数解析 [搜索根目录] */
    if (argc < 1) {
        printf("filehash [directory]\n");
        return (QST_ERROR);
    }

    /* 生成性能测试对象 */
    s_profile = timer_new();

    /* 生成输出文件 */
    file_deleteA("__hash__.old");
    file_renameA("__hash__.old", "__hash__.txt");
    file = file_buf_openA("__hash__.txt", CR_FO_WO);
    if (file == NULL) {
        printf("can't create output file\n");
        return (QST_ERROR);
    }

    /* 枚举所有文件 */
    if (argc == 1)
        root = "";
    else
        root = argv[1];
    s_rdata = NULL;
    mem_info(&s_total, &s_avail);
    s_total = (s_total * 618) / 1000;
    file_searchA(root, TRUE, FALSE, FALSE, "*.*", hasher, file);

    /* 释放内存 */
    file_buf_close(file);
    timer_del(s_profile);
    TRY_FREE(s_rdata);
    return (QST_OKAY);
}
Ejemplo n.º 3
0
/*
=======================================
    命令行主函数
=======================================
*/
int main (int argc, char *argv[])
{
    sCP_PARAM ft;

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_CUI))
        return (QST_ERROR);

    /* 参数解析 <源编码> <目标编码> <搜索根目录> <通配符> */
    if (argc < 5) {
        usage();
        return (QST_ERROR);
    }

    /* 填充结构 */
    ft.tot = ft.cvt = 0;
    ft.from = str2intA(argv[1]);
    if (ft.from == CR_LOCAL)
        ft.from = get_sys_codepage();
    ft.to = str2intA(argv[2]);
    if (ft.to == CR_LOCAL)
        ft.to = get_sys_codepage();

    /* 已经是 UTF-8 的文件不用转换 */
    if (ft.to == CR_UTF8)
        ft.skip_utf8 = TRUE;
    else
        ft.skip_utf8 = FALSE;

    /* 两个编码值相等表示删除 UTF-8 BOM 标志 */
    if (ft.from == ft.to)
        ft.del_u8_bom = TRUE;
    else
        ft.del_u8_bom = FALSE;

    /* 子目录递归 + 跳过隐藏目录和文件 */
    file_searchA(argv[3], TRUE, TRUE, FALSE, argv[4], do_each_file, &ft);
    printf("%u file(s) found. %u file(s) converted.\n", ft.tot, ft.cvt);
    return (QST_OKAY);
}
Ejemplo n.º 4
0
void fn00000001400011D4(word64 rbx, word64 r8, word64 r13)
{
	word64 rsp_8;
	word64 rbx_9;
	byte SCZO_10;
	word32 ecx_11;
	word32 eax_12;
	word64 rax_13;
	byte al_14;
	byte SZO_15;
	byte C_16;
	byte Z_17;
	word64 rcx_18;
	word64 r8_19;
	word64 r13_20;
	byte bl_21;
	set_app_type();
	fn0000000140001920();
	_set_fmode(dwLoc2C);
	word64 rax_26 = __p__commode();
	fn0000000140001ABC();
	Mem29[rax_26 + 0x00:word32] = 0x00;
	word32 eax_31 = fn000000014000164C(0x01, r8_19, r13_20, qwLoc2C);
	byte al_33 = (byte) eax_31;
	if (al_33 != 0x00)
	{
		fn0000000140001B5C(qwArg00, qwArg04, qwArg08, qwArg0C);
		fn0000000140001854(eax_31);
		fn0000000140001918();
		word64 rsp_74;
		word64 rbx_75;
		byte SCZO_76;
		word32 ecx_77;
		word32 eax_78;
		word64 rax_79;
		byte al_80;
		byte SZO_81;
		byte C_82;
		byte Z_83;
		word64 rcx_84;
		word64 r8_85;
		word64 r13_86;
		byte bl_87;
		configure_narrow_argv();
		if (false)
		{
			fn0000000140001928();
			word32 eax_92 = fn0000000140001958();
			if (eax_92 != 0x00)
			{
				word64 rsp_147;
				word64 rbx_148;
				byte SCZO_149;
				word32 ecx_150;
				word32 eax_151;
				word64 rax_152;
				byte al_153;
				byte SZO_154;
				byte C_155;
				byte Z_156;
				word64 rcx_157;
				word64 r8_158;
				word64 r13_159;
				byte bl_160;
				_setusermatherr();
			}
			fn0000000140001DD0();
			fn0000000140001DD0();
			fn0000000140001ABC();
			word64 rsp_97;
			word64 rbx_98;
			byte SCZO_99;
			word32 ecx_100;
			word32 eax_101;
			word64 rax_102;
			byte al_103;
			byte SZO_104;
			byte C_105;
			byte Z_106;
			word64 rcx_107;
			word64 r8_108;
			word64 r13_109;
			byte bl_110;
			configthreadlocale();
			fn0000000140001938();
			if (0x01 != 0x00)
			{
				word64 rsp_131;
				word64 rbx_132;
				byte SCZO_133;
				word32 ecx_134;
				word32 eax_135;
				word64 rax_136;
				byte al_137;
				byte SZO_138;
				byte C_139;
				byte Z_140;
				word64 rcx_141;
				word64 r8_142;
				word64 r13_143;
				byte bl_144;
				initialize_narrow_environment();
			}
			fn0000000140001ABC();
			return;
		}
	}
	else
	{
		word64 rcx_164;
		byte bl_165;
		fn0000000140001974(0x07, qwLoc04, qwArg00, qwArg04, qwArg0C, out rcx_164, out bl_165);
		int3();
	}
	word64 rcx_68;
	byte bl_69;
	fn0000000140001974(0x07, qwLoc04, qwArg00, qwArg04, qwArg0C, out rcx_68, out bl_69);
	int3();
	int3();
	fn0000000140001290();
	return;
}
Ejemplo n.º 5
0
/*
=======================================
    主程序
=======================================
*/
int main (int argc, char *argv[])
{
    CR_NOUSE(argc);
    CR_NOUSE(argv);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_CUI))
        return (QST_ERROR);
    SetConsoleTitleA(WIN_TITLE);

    sint_t  x1, y1;
    uint_t  ww, hh;

    /* 初始化窗口 */
    s_hcui = GetStdHandle(STD_OUTPUT_HANDLE);
    if (s_hcui == INVALID_HANDLE_VALUE)
        return (QST_ERROR);
    s_hwnd = GetConsoleWindow();
    if (s_hwnd == NULL)
        return (QST_ERROR);
    misc_desk_init(WIN_ICONF, &x1, &y1, &ww, &hh,
                   QSRV_DEF_WIDTH, QSRV_DEF_HEIGHT);
    misc_cui_setwin(s_hwnd, s_hcui, x1, y1, ww, hh);

    sINIu*  ini;
    uint_t  temp;
    ansi_t* text;
    int16u  port = QST_DEF_PORT;
    ansi_t* addr = QST_DEF_ADDR;
    uint_t  count = QST_DEF_CLIENT;

    /* 读取参数 */
    text = file_load_as_strA(QST_CFG_STARTUP);
    if (text != NULL) {
        ini = ini_parseU(text);
        mem_free(text);
        text = NULL;
        if (ini != NULL) {
            text = ini_key_stringU("serv::bind", ini);
            if (text != NULL)
                addr = text;
            temp = ini_key_intxU("serv::port", QST_DEF_PORT, ini);
            if (temp > 1024 && temp < 32768)
                port = (int16u)temp;
            temp = ini_key_intxU("serv::count", QST_DEF_CLIENT, ini);
            if (temp > 0 && temp <= QST_MAX_CLIENT)
                count = temp;
            ini_closeU(ini);
        }
    }

    socket_t    serv;
    sQstWork*   work;

    /* 建立工作单元组 */
    work = qst_wrk_create(count);
    if (work == NULL)
        return (QST_ERROR);

    /* 初始化网络 */
    if (!socket_init())
        return (QST_ERROR);
    serv = server_tcp_open(addr, port);
    TRY_FREE(text);
    if (serv == NULL)
        return (QST_ERROR);

    /* 初始化锁 */
    mtlock_init(&s_qst_lck_shw);
    mtlock_init(&s_qst_lck_wrk);

    int16u  logo_color;

    /* 建立颜色值 */
    logo_color = cui_make_attr(0, CR_CUI_TEXT_LIGHT |
                        CR_CUI_TEXT_GREEN | CR_CUI_TEXT_RED |
                        CR_CUI_TEXT_BLUE);
    s_qst_clr_cin = cui_make_attr(0, CR_CUI_TEXT_LIGHT |
                        CR_CUI_TEXT_GREEN | CR_CUI_TEXT_RED);
    s_qst_clr_say = cui_make_attr(0, CR_CUI_TEXT_LIGHT |
                        CR_CUI_TEXT_GREEN);
    s_qst_clr_out = cui_make_attr(0, CR_CUI_TEXT_LIGHT |
                        CR_CUI_TEXT_RED);
    /* 工作循环 */
    cui_set_color(logo_color);
    printf("######################################\n");
    printf("##    QUESTLAB BROADCAST SERVER     ##\n");
    printf("######################################\n");
    while (!s_quit)
    {
        ansi_t*     ptr;
        bool_t      okay;
        ansi_t*     name;
        socket_t    netw;

        /* 接受一个客户端 */
        netw = server_tcp_accept(serv);
        if (netw == NULL)
            continue;

        /* 接收客户端名称 */
        socket_set_timeout(netw, -1, QST_TCP_TOUT);
        name = netw_cmd_recv(netw);
        if (name == NULL) {
            socket_close(netw);
            continue;
        }

        /* 客户端名称过滤 */
        if (str_lenA(name) > QST_MAX_NAME) {
            netw_ack_send(netw, FALSE);
            netw_cli_close(netw);
            mem_free(name);
            continue;
        }
        ptr = name;
        okay = TRUE;
        while (*ptr != NIL) {
            if (is_cntrlA(*ptr++)) {
                okay = FALSE;
                break;
            }
        }
        if (!okay) {
            netw_ack_send(netw, FALSE);
            netw_cli_close(netw);
            mem_free(name);
            continue;
        }

        /* 启动一个工作单元 */
        if (!qst_wrk_wakeup(work, name, netw, qst_srv_main)) {
            netw_cli_close(netw);
            mem_free(name);
            continue;
        }
    }
    return (QST_OKAY);
}
Ejemplo n.º 6
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(curt_app);
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    ximp_stop_running();
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);

    sINIu*  ini;
    ansi_t* str;
    bool_t  old = TRUE;

    /* 加载配置文件 */
    str = file_load_as_strA(QST_PATH_CONFIG WIN_ICONF);
    if (str != NULL) {
        ini = ini_parseU(str);
        mem_free(str);
        if (ini != NULL) {
            old = ini_key_intxU("sdir::old_style", TRUE, ini);
            ini_closeU(ini);
        }
    }

    /* 参数解析 [起始目录] */
    g_root = NULL;
    if (argc > 0)
    {
        /* 验证目录是否存在 */
        if (misc_dir_exist(argv[0]))
            g_root = argv[0];
    }

    /* 未指定目录则使用上次结果 */
    if (g_root == NULL)
        g_root = file_load_as_strA(QST_SELECT_DIR);
    if (!old)
    {
        BROWSEINFOA     bi;
        LPITEMIDLIST    pidl;
        ansi_t  path[MAX_PATH];

        /* 使用新风格的目录打开窗口 */
        CoInitialize(NULL);
        bi.hwndOwner = NULL;
        bi.pidlRoot  = NULL;
        bi.pszDisplayName = path;
        bi.lpszTitle = "";
        bi.ulFlags = BIF_RETURNONLYFSDIRS;
        if (g_root == NULL)
            bi.lpfn = NULL;
        else
            bi.lpfn = BrowseCallbackProc;
        bi.lParam = 0;
        bi.iImage = 0;
        pidl = SHBrowseForFolderA(&bi);
        if (pidl != NULL &&
            SHGetPathFromIDListA(pidl, path))
            ximp_dir_write(path);
        CoUninitialize();
        return (QST_OKAY);
    }

    /* 标准 VCL 过程开始 */
    try
    {
        Application->Initialize();
        Application->Title = WIN_TITLE;
        Application->CreateForm(__classid(TfrmMain), &frmMain);
        Application->Run();
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
            throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }
    return (QST_OKAY);
}
Ejemplo n.º 7
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_line);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);
    mem_zero(&s_wrk_ctx, sizeof(s_wrk_ctx));

    sint_t  x1, y1;
    uint_t  ww, hh;

    /* 生成一个可变大小的窗口 */
    mtlock_init(&s_wrk_ctx.lock);
    qst_load_cfg(&s_wrk_ctx.cfgs);
    misc_desk_init(WIN_ICONF, &x1, &y1, &ww, &hh,
                   QV2D_DEF_WIDTH, QV2D_DEF_HEIGHT);
    if (ww < QV2D_DEF_WIDTH)  ww = QV2D_DEF_WIDTH;
    if (hh < QV2D_DEF_HEIGHT) hh = QV2D_DEF_HEIGHT;
    s_wrk_ctx.hwnd = (HWND)window_open(curt_app, (void_t*)WindowProc,
                        x1, y1, ww, hh, WIN_TITLE, WIN_CLASS, (ansi_t*)101,
                                    CR_WSTYLE_NORMAL);
    if (s_wrk_ctx.hwnd == NULL)
        return (QST_ERROR);
    SetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE,
        GetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE) & (~WS_MAXIMIZEBOX));

    iGFX2*  draw;
    sIMAGE* imgs;

    /* 创建 GDI 绘制对象 (只支持32位色屏幕) */
    draw = (iGFX2*)create_gdi_canvas(s_wrk_ctx.hwnd, 0, 0, FALSE);
    if (draw == NULL) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    imgs = CR_VCALL(draw)->lock(draw);
    if (imgs == NULL || imgs->fmt != CR_ARGB8888) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    CR_VCALL(draw)->unlock(draw);
    CR_VCALL(draw)->clear(draw, s_wrk_ctx.cfgs.bkcolor, 0);
    s_wrk_ctx.draw = draw;

    /* 初始化网络 */
    if (!socket_init()) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    s_wrk_ctx.netw = netw_cli_open(EXE_XNAME);
    if (s_wrk_ctx.netw == NULL) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }
    /* 读取需要超时, 不然线程无法退出 */
    socket_set_timeout(s_wrk_ctx.netw, -1, QST_TCP_TOUT);

    thrd_t  thrd;

    /* 生成工作线程 */
    s_wrk_ctx.send = TRUE;
    s_wrk_ctx.quit = FALSE;
    s_wrk_ctx.cur_busy = LoadCursor(NULL, IDC_WAIT);
    s_wrk_ctx.cur_free = LoadCursor(NULL, IDC_ARROW);
    s_wrk_ctx.res_loader = res_loader_get();
    if (s_wrk_ctx.res_loader->init != NULL)
        s_wrk_ctx.res_loader->init(s_wrk_ctx.netw, NULL);
    qst_load_filter(&s_wrk_ctx);
    thrd = thread_new(0, qst_v2d_main, &s_wrk_ctx, FALSE);
    if (thrd == NULL) {
        window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
        return (QST_ERROR);
    }

    /* 消息循环 */
    while (!s_wrk_ctx.quit)
    {
        MSG     msg;

        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            if (msg.message == WM_QUIT) {
                s_wrk_ctx.quit = TRUE;
                break;
            }
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else {
            qst_do_keyboard(&s_wrk_ctx);
        }
    }
    thread_wait(thrd);
    thread_del(thrd);
    window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS);
    netw_cli_close(s_wrk_ctx.netw);
    return (QST_OKAY);
}
Ejemplo n.º 8
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 只允许一个例程 */
    if (misc_is_running(EXE_XNAME))
        return (QST_ERROR);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);
    mem_zero(&s_wrk_ctx, sizeof(s_wrk_ctx));

    int qt_argc;

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);
    qt_argc = (int)argc;

    QApplication    qt_app(qt_argc, argv);

    qt_app.setApplicationName("QstComm");
    qt_app.setOrganizationName("QuestLAB");

    sint_t  x1, y1;
    uint_t  ww, hh;

    /* 生成一个可变大小的窗口 */
    mtlock_init(&s_wrk_ctx.lock);
    qst_load_cfg(&s_wrk_ctx.cfgs);
    misc_desk_init(WIN_ICONF, &x1, &y1, &ww, &hh,
                   QCOM_DEF_WIDTH, QCOM_DEF_HEIGHT);
    if (ww < QCOM_DEF_WIDTH)  ww = QCOM_DEF_WIDTH;
    if (hh < QCOM_DEF_HEIGHT) hh = QCOM_DEF_HEIGHT;

    RECT            w_rect;
    sint_t          fw, fh;
    QMainWindow     qt_win;

    /* Qt 里的宽高都不包括边框
       需要自己用 Win32 API 获取 */
    qt_win.setWindowFlags(qt_win.windowFlags()
        & (~Qt::WindowMaximizeButtonHint));
    qt_win.move(x1, y1);
    qt_win.resize(ww, hh);
    s_wrk_ctx.hwnd = (HWND)qt_win.winId();
    if (!GetWindowRect(s_wrk_ctx.hwnd, &w_rect))
        return (QST_ERROR);
    fw = w_rect.right - w_rect.left - ww;
    fh = w_rect.bottom - w_rect.top - hh;
    qt_win.setMinimumSize(QCOM_DEF_WIDTH  - fw,
                          QCOM_DEF_HEIGHT - fh);
    qt_win.resize(ww - fw, hh - fh);

    QWidget*        cent = new QWidget (&qt_win);
    CTextEdit*      edit = new CTextEdit (cent);
    QHBoxLayout*    hori = new QHBoxLayout (cent);

    /* 创建窗体里的控件 */
    hori->setSpacing(6);
    hori->setContentsMargins(8, 8, 8, 8);
    hori->addWidget(edit);
    qt_win.setCentralWidget(cent);

    CTextOper   oper(&qt_win, edit);

    s_wrk_ctx.oper = (void_t*)(&oper);
    SetClassLongPtr(s_wrk_ctx.hwnd, GCLP_HICON, (LONG_PTR)
                    LoadIconA(curt_app, (ansi_t*)101));

    /* 初始化 ANSI 上下文 */
    if (!qst_csi_init())
        return (QST_ERROR);
    qst_set_viewer(&s_wrk_ctx);

    /* 初始化网络 */
    if (!socket_init())
        return (QST_ERROR);
    s_wrk_ctx.netw = netw_cli_open(EXE_XNAME);
    if (s_wrk_ctx.netw == NULL)
        return (QST_ERROR);

    /* 读取需要超时, 不然线程无法退出 */
    socket_set_timeout(s_wrk_ctx.netw, -1, QST_TCP_TOUT);

    thrd_t  thrd;

    /* 生成工作线程 */
    s_wrk_ctx.quit = FALSE;
    s_wrk_ctx.comm.quit = FALSE;
    s_wrk_ctx.comm.text = TRUE;
    s_wrk_ctx.comm.rtype = "text";
    s_wrk_ctx.comm.stype = "text";
    s_wrk_ctx.comm.title = NULL;
    s_wrk_ctx.comm.render = qst_txt_show;
    s_wrk_ctx.page = get_sys_codepage();
    qst_update_title(&s_wrk_ctx);
    thrd = thread_new(0, qst_com_main, &s_wrk_ctx, FALSE);
    if (thrd == NULL)
        return (QST_ERROR);
    sio_init();

    /* 开始 Qt 流程 */
    qt_win.show();
    qt_app.exec();

    /* 关闭线程直接退出 */
    if (!s_wrk_ctx.quit)
        s_wrk_ctx.quit = TRUE;
    thread_wait(thrd);
    thread_del(thrd);
    netw_cli_close(s_wrk_ctx.netw);
    sio_free();
    qst_csi_free();
    return (QST_OKAY);
}
Ejemplo n.º 9
0
/*
=======================================
    WinMain 程序入口
=======================================
*/
int WINAPI
WinMain (
  __CR_IN__ HINSTANCE   curt_app,
  __CR_IN__ HINSTANCE   prev_app,
  __CR_IN__ LPSTR       cmd_line,
  __CR_IN__ int         cmd_show
    )
{
    uint_t      argc;
    ansi_t**    argv;

    CR_NOUSE(curt_app);
    CR_NOUSE(prev_app);
    CR_NOUSE(cmd_show);

    /* 建立 CrHack 系统 */
    if (!set_app_type(CR_APP_GUI))
        return (QST_ERROR);

    /* 获取命令行参数, 不包括进程文件名 */
    argv = misc_get_param(cmd_line, &argc);

    /* 参数解析 <脚本文件> */
    if (argc < 1)
        return (QST_ERROR);

    leng_t  size;
    ansi_t* root;
    ansi_t* temp;
    ansi_t* exec;
    ansi_t  path[MAX_PATHA];

    /* 合成 LUA_PATH & LUA_CPATH 目录 */
    exec = file_load_as_strA(QST_ROOT_START);
    if (exec == NULL) {
        size = GetCurrentDirectoryA(sizeof(path), path);
        if (size == 0 || size > sizeof(path))
            return (QST_ERROR);
        if (path[size - 1] == '\\')
            path[size - 1] = 0x00;
        exec = str_dupA(path);
        if (exec == NULL)
            return (QST_ERROR);
    }
    temp = str_dupA(exec);
    if (temp == NULL) {
        mem_free(exec);
        return (QST_ERROR);
    }
    root = str_fmtA("%s\\lualib", exec);
    mem_free(exec);
    if (root == NULL) {
        mem_free(temp);
        return (QST_ERROR);
    }

    DWORD   cf = 0;

    /* 根据扩展名选择用哪个启动 */
    if (filext_checkA(argv[0], ".lua")) {
        exec = str_fmtA("%s\\lua.exe \"%s\"", temp, argv[0]);
        cf = CREATE_NEW_CONSOLE;
    }
    else
    if (filext_checkA(argv[0], ".wlua")) {
        exec = str_fmtA("%s\\wlua.exe \"%s\"", temp, argv[0]);
        cf = CREATE_NO_WINDOW;
    }
    else {
        exec = NULL;
    }
    mem_free(temp);
    if (exec == NULL) {
        mem_free(root);
        return (QST_ERROR);
    }

    STARTUPINFOA        si;
    PROCESS_INFORMATION pi;

    /* 启动脚本 */
    mem_zero(&si, sizeof(si));
    si.cb = sizeof(STARTUPINFOA);
    SetEnvironmentVariableA("LUA_PATH", root);
    SetEnvironmentVariableA("LUA_CPATH", root);
    size  = str_lenA(root);
    size -= str_lenA("\\lualib");
    root[size] = 0x00;
    if (CreateProcessA(NULL, exec, NULL, NULL, FALSE,
                       cf, NULL, root, &si, &pi)) {
        WaitForSingleObject(pi.hProcess, INFINITE);
        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);
    }
    mem_free(exec);
    mem_free(root);
    return (QST_OKAY);
}