コード例 #1
0
void initializeSegments(void)
{
    driver = (WCHAR *)malloc(128);
    ctow(driver,sysname);
    bool ret = InitializeWinIo();
    printf("InitializeWinIo returned %d\n", ret);
    fflush(stdout);
    ret = InstallWinIoDriver(driver, false);
    printf("InstallWinIoDriver returned %d\n", ret);
    fflush(stdout);
}
コード例 #2
0
ファイル: win.cpp プロジェクト: nekocode/FScript0.2
void ReadConf()
{
	//设置工作目录为exe所在目录
	MySetCurrentDirectory(std::string(""));

	Lua::LuaContext conf;
	try
	{
		conf.executeCode(std::ifstream("init.conf"));

		//初始化窗体大小
		ClientRect.right = conf.readVariable<int>("窗口设置.宽");
		ClientRect.bottom = conf.readVariable<int>("窗口设置.高");
		std::string ctile = conf.readVariable<std::string>("窗口设置.标题");

		szTitle = ctow(ctile.c_str());

		//初始化渲染表面大小
		RenderRect.right = conf.readVariable<int>("渲染表面.宽");
		RenderRect.bottom = conf.readVariable<int>("渲染表面.高");

		//读取各种目录属性
		data_path = conf.readVariable<std::string>("公用数据目录");
		games_path = conf.readVariable<std::string>("游戏目录");

		//设置字库路径
		font_lib = conf.readVariable<std::string>("字库");
		if(!font_lib.length())
			font_lib = "default.ttf";

		//设置脚本入口
		fs_entry = conf.readVariable<std::string>("脚本入口");
		if(!fs_entry.length())
			fs_entry = "0.txt";
	}
	catch(Lua::LuaContext::ExecutionErrorException &err)		{MessageBoxA(0,err.what(),"读取配置出错",0);}
	catch(Lua::LuaContext::VariableDoesntExistException &err)	{MessageBoxA(0,err.what(),"读取配置出错",0);}
	catch(Lua::LuaContext::SyntaxErrorException &err)			{MessageBoxA(0,err.what(),"读取配置出错",0);}
	catch(Lua::LuaContext::WrongTypeException &err)				{MessageBoxA(0,err.what(),"读取配置出错",0);}


}
コード例 #3
0
ファイル: OSBasics.cpp プロジェクト: RobLach/Polycode
vector<OSFileEntry> OSBasics::parseFolder(String pathString, bool showHidden) {
	vector<OSFileEntry> returnVector;
	
	if(pathString.size() < 128) {
		if(PHYSFS_exists(pathString.c_str())) {
			if(PHYSFS_isDirectory(pathString.c_str())) {
				return parsePhysFSFolder(pathString, showHidden);
			}
		}
	}
	
	
#ifdef _WINDOWS

	WIN32_FIND_DATA findFileData;

	WCHAR curDir[4096];
	GetCurrentDirectory(4096, curDir);

	WCHAR tmp[4096];
	memset(tmp, 0, sizeof(WCHAR)*4096);
	ctow(tmp, pathString.c_str());
	SetCurrentDirectory(tmp);

	HANDLE hFind = FindFirstFile((LPCWSTR)"*", &findFileData);
	if(hFind  == INVALID_HANDLE_VALUE) {
		SetCurrentDirectory(curDir);
		return returnVector;
	}

	char fileName[260];
	do {		
		memset(fileName, 0, 260);
		wtoc(fileName, findFileData.cFileName);
		String fname = string(fileName);
		
		if((fname.c_str()[0] != '.' || (fname.c_str()[0] == '.'  && showHidden)) && fname != "..") {
			if( findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
				returnVector.push_back(OSFileEntry(pathString, fname, OSFileEntry::TYPE_FOLDER));
			} else {
				returnVector.push_back(OSFileEntry(pathString, fname, OSFileEntry::TYPE_FILE));
			}
		}
    } while(FindNextFile(hFind, &findFileData));	
	FindClose(hFind);
	SetCurrentDirectory(curDir);
#else
	DIR           *d;
	struct dirent *dir;
	
	d = opendir(pathString.c_str());
	if(d) {
		while ((dir = readdir(d)) != NULL) {
			if(dir->d_name[0] != '.' || (dir->d_name[0] == '.'  && showHidden)) {
				if(dir->d_type == DT_DIR) {
					returnVector.push_back(OSFileEntry(pathString, dir->d_name, OSFileEntry::TYPE_FOLDER));
				} else {
					returnVector.push_back(OSFileEntry(pathString, dir->d_name, OSFileEntry::TYPE_FILE));
				}
			}
		}
		closedir(d);
	}
	
#endif
		
	return returnVector;
}
コード例 #4
0
ファイル: disk.c プロジェクト: kerneltravel/netdisk4tc
int ndisk_dir(Dictionary *dict, const NDiskEntry *entry, NDisk *disk, const wchar_t *path) {
    WIN32_FIND_DATAW fData;
    char *tmp = NULL, *sTmp = NULL;
    wchar_t *pTmp = NULL;
    unsigned long size = 0;
    int i = 0;
    SYSTEMTIME time;
    lua_reset();
    lua_getglobal(script, "entries");
    tmp = wtoc(entry->name);
    lua_getfield(script, -1, tmp);
    free(tmp);
    tmp = NULL;
    i = lua_gettop(script);
    if(lua_pcall(script, 0, 0, 0)) {
        OutputDebugStringA("Error Msg is: ");
        OutputDebugStringA(lua_tostring(script, -1));
    }
    lua_pop(script, 1);
    lua_getglobal(script, "dir");
    if(!lua_isfunction(script, -1)) {
        RequestProcW(PluginNumber, RT_MsgOK, L"ÅäÖôíÎó", L"ÍøÅ̽ű¾´íÎó, ²»ÄܶÁÈ¡µ±Ç°Ä¿Â¼µÄÄÚÈÝ. ", NULL, 0);
        return NDISK_FATAL;
    }
    if(ndisk_lua_push(script, disk) == NDISK_FATAL) {
        lua_settop(script, 0);
        return NDISK_FATAL;
    }
    tmp = wtoc(path);
    lua_pushstring(script, tmp);
    free(tmp);
    tmp = NULL;
    lua_setfield(script, -2, "path");
    if(lua_pcall(script, 1, 1, 0)) {
        OutputDebugStringA("Error Msg is: ");
        OutputDebugStringA(lua_tostring(script, -1));
    }

    if(lua_istable(script, -1)) {
        lua_pushnil(script);
        while (lua_next(script, -2)) {
            if(lua_istable(script, -1)) {
                memset(&fData, 0, sizeof(WIN32_FIND_DATAW));
                lua_pushnil(script);
                while(lua_next(script, -2)) {
                    tmp = (char *)lua_tostring(script, -2);
                    if(strcmp(tmp, "attribute") == 0) {
                        sTmp = (char *)lua_tostring(script, -1);
                        if(strcmp(sTmp, "file") == 0) {
                            fData.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
                        }
                        if(strcmp(sTmp, "directory") == 0) {
                            fData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
                        }
                    }
                    if(strcmp(tmp, "filename") == 0) {
                        sTmp = (char *)lua_tostring(script, -1);
                        pTmp = ctow(sTmp);
                        wcslcpy(fData.cFileName, pTmp, PATH_MAX);
                        free(pTmp);
                        pTmp = NULL;
                    }
                    if(strcmp(tmp, "size") == 0) {
                        size = (unsigned long)lua_tonumber(script, -1);
                        fData.nFileSizeHigh = HIWORD(size);
                        fData.nFileSizeLow = LOWORD(size);
                    }
                    if(strcmp(tmp, "create") == 0) {
                        sTmp = (char *)lua_tostring(script, -1);
                        pTmp = ctow(sTmp);
                        memset(&time, 0, sizeof(SYSTEMTIME));
                        if(strtotime(pTmp, &time)) {
                            SystemTimeToFileTime(&time, &fData.ftCreationTime);
                        }
                        free(pTmp);
                        pTmp = NULL;
                    }
                    if(strcmp(tmp, "access") == 0) {
                        sTmp = (char *)lua_tostring(script, -1);
                        pTmp = ctow(sTmp);
                        memset(&time, 0, sizeof(SYSTEMTIME));
                        if(strtotime(pTmp, &time)) {
                            SystemTimeToFileTime(&time, &fData.ftLastAccessTime);
                        }
                        free(pTmp);
                        pTmp = NULL;
                    }
                    if(strcmp(tmp, "write") == 0) {
                        sTmp = (char *)lua_tostring(script, -1);
                        pTmp = ctow(sTmp);
                        memset(&time, 0, sizeof(SYSTEMTIME));
                        if(strtotime(pTmp, &time)) {
                            SystemTimeToFileTime(&time, &fData.ftLastWriteTime);
                        }
                        free(pTmp);
                        pTmp = NULL;
                    }
                    lua_pop(script, 1);
                }
                if(fData.cFileName) {
                    dict_set_element(dict, fData.cFileName, &fData, sizeof(WIN32_FIND_DATAW));
                }
            }
            lua_pop(script, 1);
        }
    }
    lua_pop(script, 1);
    return NDISK_OK;
}
コード例 #5
0
ファイル: ndpluginw.c プロジェクト: kerneltravel/netdisk4tc
BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
    int i = 0;
    WIN32_FIND_DATAW fData;
    wchar_t tmp[PATH_MAX];
    char *sTmp;
    HANDLE fHandle = NULL;
    lua_State *lua = NULL;
    NDiskEntry *pEntry = NULL;
    
    if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
        hInst = hModule;
        // init
        GetModuleFileNameW((HMODULE)hInst, my_dir, MAX_PATH);
        i = MAX_PATH;
        while (my_dir[--i] != '\\') {
            my_dir[i] = '\0';
        }
        wcslcpy(tmp, my_dir, PATH_MAX);
        wcscat_s(tmp, PATH_MAX, L"entries\\*.lua");
        fHandle = FindFirstFileW(tmp, &fData);
        i = 0;

        script = luaL_newstate();
        luaL_openlibs(script);
        wcslcpy(tmp, my_dir, PATH_MAX);
        wcscat_s(tmp, PATH_MAX, L"?.lua");
        sTmp = wtoc(tmp);
        lua_getglobal(script, "package");
        lua_pushstring(script, sTmp);
        lua_setfield(script, -2, "path");
        lua_pop(script, 1);
        free(sTmp);
        sTmp = NULL;
        lua_getglobal(script, "require");
        lua_pushstring(script, "Json");
        lua_call(script, 1, 1);
        lua_setglobal(script, "json");
        lua_register(script, "http", wp_http);
        lua_register(script, "expl", wp_explorer);
        lua_register(script, "savt", wp_savt);
        //lua_register(script, "utoc", wp_utoc);
        lua_newtable(script);

        if(fHandle != INVALID_HANDLE_VALUE) {
            do {
                lua_reset();
                wcslcpy(tmp, my_dir, PATH_MAX);
                wcscat_s(tmp, PATH_MAX, L"entries\\");
                wcscat_s(tmp, PATH_MAX, fData.cFileName);
                sTmp = wtoc(tmp);
                if(luaL_loadfile(script, sTmp)) {
                    free(sTmp);
                    sTmp = NULL;
                    OutputDebugStringA("Error Msg is: ");
                    OutputDebugStringA(lua_tostring(script,-1));
                    continue;
                }
                free(sTmp);
                sTmp = NULL;
                _wsplitpath_s(fData.cFileName, NULL, 0, NULL, 0, (wchar_t *)&tmp, PATH_MAX, NULL, 0);
                sTmp = wtoc(tmp);
                lua_setfield(script, -2, sTmp);
                lua_getfield(script, -1, sTmp);
                free(sTmp);
                sTmp = NULL;
                if(lua_pcall(script, 0, 0, 0)) {
                    OutputDebugStringA("Error Msg is: ");
                    OutputDebugStringA(lua_tostring(script,-1));
                    continue;
                }
                lua_getglobal(script, "signin");
                if(!lua_isstring(script, -1)) {
                    lua_pop(script, 1);
                    continue;
                }
                lua_getglobal(script, "description");
                if(!lua_isstring(script, -1)) {
                    lua_pop(script, 1);
                    continue;
                }

                if(available_disk_entries == NULL) {
                    available_disk_entries = (NDiskEntry *)malloc(sizeof(NDiskEntry));
                } else {
                    pEntry = (NDiskEntry *)realloc(available_disk_entries, (i + 1) * sizeof(NDiskEntry));
                    if(pEntry != available_disk_entries) {
                        available_disk_entries = pEntry;
                    }
                }
                available_disk_entries[i].name = _wcsdup(tmp);
                available_disk_entries[i].signin = ctow(lua_tostring(script, -2));
                available_disk_entries[i].description = ctow(lua_tostring(script, -1));
                lua_pop(script, 2);

                i++;
            } while (FindNextFileW(fHandle, &fData));
        }
        lua_setglobal(script, "entries");
        available_disk_entries_length = i;
        available_disks = dict_initialize();
        ndisks_load();
        OleInitialize(0);
    }
    if(ul_reason_for_call == DLL_PROCESS_DETACH) {
        // destory
        lua_close(script);
        script = NULL;
        if(available_disk_entries != NULL) {
            for(i = 0; i < available_disk_entries_length; i++) {
                free(available_disk_entries[i].name);
                free(available_disk_entries[i].description);
                free(available_disk_entries[i].signin);
            }
        }
        if(available_disks != NULL) {
            dict_destroy(&available_disks);
        }
        OleUninitialize();
    }
    return TRUE;
}