int CFolderItem::FolderCreateDirectory(int showFolder) { int res = FOLDER_SUCCESS; if (IsUnicode()) { wchar_t buffer[MAX_FOLDER_SIZE]; if (szFormatW) { ExpandPathW(buffer, szFormatW, MAX_FOLDER_SIZE); CreateDirectories(buffer); if (showFolder) { ShellExecuteW(NULL, L"explore", buffer, NULL, NULL, SW_SHOW); } res = (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE; } } else{ char buffer[MAX_FOLDER_SIZE]; if (szFormat) { ExpandPath(buffer, szFormat, MAX_FOLDER_SIZE); CreateDirectories(buffer); if (showFolder) { ShellExecuteA(NULL, "explore", buffer, NULL, NULL, SW_SHOW); } res = (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE; } } return res; }
Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint) { if(path.empty()) return INFO::OK; struct stat s; if(wstat(path, &s) == 0) { if(!S_ISDIR(s.st_mode)) // encountered a file WARN_RETURN(ERR::FAIL); return INFO::OK; } // If we were passed a path ending with '/', strip the '/' now so that // we can consistently use Parent to find parent directory names if(path.IsDirectory()) return CreateDirectories(path.Parent(), mode, breakpoint); RETURN_STATUS_IF_ERR(CreateDirectories(path.Parent(), mode)); errno = 0; if(wmkdir(path, mode) != 0) { debug_printf("CreateDirectories: failed to mkdir %s (mode %d)\n", path.string8().c_str(), mode); if (breakpoint) WARN_RETURN(StatusFromErrno()); else return StatusFromErrno(); } return INFO::OK; }
bool RageFileDriverDirect::Move( const RString &sOldPath_, const RString &sNewPath_ ) { RString sOldPath = sOldPath_; RString sNewPath = sNewPath_; FDB->ResolvePath( sOldPath ); FDB->ResolvePath( sNewPath ); if( this->GetFileType(sOldPath) == RageFileManager::TYPE_NONE ) return false; { const RString sDir = Dirname(sNewPath); CreateDirectories( m_sRoot + sDir ); } int size = FDB->GetFileSize( sOldPath ); int hash = FDB->GetFileHash( sOldPath ); TRACE( ssprintf("rename \"%s\" -> \"%s\"", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str()) ); if( DoRename(m_sRoot + sOldPath, m_sRoot + sNewPath) == -1 ) { WARN( ssprintf("rename(%s,%s) failed: %s", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str(), strerror(errno)) ); return false; } FDB->DelFile( sOldPath ); FDB->AddFile( sNewPath, size, hash, NULL ); return true; }
void CSimulation2Impl::ReportSerializationFailure( SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter, SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter) { OsPath path = psLogDir() / "oos_log"; CreateDirectories(path, 0700); // Clean up obsolete files from previous runs wunlink(path / "hash.before.a"); wunlink(path / "hash.before.b"); wunlink(path / "debug.before.a"); wunlink(path / "debug.before.b"); wunlink(path / "state.before.a"); wunlink(path / "state.before.b"); wunlink(path / "hash.after.a"); wunlink(path / "hash.after.b"); wunlink(path / "debug.after.a"); wunlink(path / "debug.after.b"); wunlink(path / "state.after.a"); wunlink(path / "state.after.b"); if (primaryStateBefore) DumpSerializationTestState(*primaryStateBefore, path, L"before.a"); if (primaryStateAfter) DumpSerializationTestState(*primaryStateAfter, path, L"after.a"); if (secondaryStateBefore) DumpSerializationTestState(*secondaryStateBefore, path, L"before.b"); if (secondaryStateAfter) DumpSerializationTestState(*secondaryStateAfter, path, L"after.b"); debug_warn(L"Serialization test failure"); }
bool RageFileDriverDirect::Move( const CString &sOldPath_, const CString &sNewPath_ ) { CString sOldPath = sOldPath_; CString sNewPath = sNewPath_; FDB->ResolvePath( sOldPath ); FDB->ResolvePath( sNewPath ); if( this->GetFileType(sOldPath) == RageFileManager::TYPE_NONE ) return false; { const CString sDir = Dirname(sNewPath); CreateDirectories( m_sRoot + sDir ); } LOG->Trace( ssprintf("rename \"%s\" -> \"%s\"", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str()) ); if( DoRename(m_sRoot + sOldPath, m_sRoot + sNewPath) == -1 ) { LOG->Warn( ssprintf("rename(%s,%s) failed: %s", (m_sRoot + sOldPath).c_str(), (m_sRoot + sNewPath).c_str(), strerror(errno)) ); return false; } return true; }
RageFileBasic *RageFileDriverDirect::Open( const CString &sPath_, int iMode, int &iError ) { CString sPath = sPath_; ASSERT( sPath.size() && sPath[0] == '/' ); /* This partially resolves. For example, if "abc/def" exists, and we're opening * "ABC/DEF/GHI/jkl/mno", this will resolve it to "abc/def/GHI/jkl/mno"; we'll * create the missing parts below. */ FDB->ResolvePath( sPath ); if( iMode & RageFile::WRITE ) { const CString dir = Dirname(sPath); if( this->GetFileType(dir) != RageFileManager::TYPE_DIR ) CreateDirectories( m_sRoot + dir ); } RageFileObjDirect *ret = this->CreateInternal( m_sRoot + sPath ); if( ret->OpenInternal( m_sRoot + sPath, iMode, iError) ) return ret; SAFE_DELETE( ret ); return NULL; }
void CSimulation2Impl::DumpState() { PROFILE("DumpState"); std::stringstream pid; pid << getpid(); std::stringstream name;\ name << std::setw(5) << std::setfill('0') << m_TurnNumber << ".txt"; OsPath path = psLogDir() / "sim_log" / pid.str() / name.str(); CreateDirectories(path.Parent(), 0700); std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); file << "State hash: " << std::hex; std::string hashRaw; m_ComponentManager.ComputeStateHash(hashRaw, false); for (size_t i = 0; i < hashRaw.size(); ++i) file << std::setfill('0') << std::setw(2) << (int)(unsigned char)hashRaw[i]; file << std::dec << "\n"; file << "\n"; m_ComponentManager.DumpDebugState(file, true); std::ofstream binfile (OsString(path.ChangeExtension(L".dat")).c_str(), std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); m_ComponentManager.SerializeState(binfile); }
void HK_CALL DumpHavokClassSignature(hkClass* hclass) { if (hclass == NULL) return; char buffer[260]; const char *ptr = hclass->getName(); if (_strnicmp(ptr, "hc", 2) == 0 ) return; if (hclass->getNumDeclaredMembers() > 0) { const hkClassMember& mem = hclass->getDeclaredMember(0); if (mem.getName() == NULL) return; } int ver = hclass->getDescribedVersion(); sprintf_s(buffer, 256, "%s\\sig\\%s_%d.sig", s_rootPath, ptr, ver); { char outdir[MAX_PATH]; strcpy(outdir, buffer); PathRemoveFileSpec(outdir); CreateDirectories(outdir); hkOstream stream(buffer); hclass->writeSignature(stream.getStreamWriter()); } }
void CReplayLogger::StartGame(JS::MutableHandleValue attribs) { // Add timestamp, since the file-modification-date can change m_ScriptInterface.SetProperty(attribs, "timestamp", std::to_string(std::time(nullptr))); // Add engine version and currently loaded mods for sanity checks when replaying m_ScriptInterface.SetProperty(attribs, "engine_version", CStr(engine_version)); m_ScriptInterface.SetProperty(attribs, "mods", g_modsLoaded); // Construct the directory name based on the PID, to be relatively unique. // Append "-1", "-2" etc if we run multiple matches in a single session, // to avoid accidentally overwriting earlier logs. static int run = -1; do { std::wstringstream name; name << getpid(); if (++run) name << "-" << run; m_Directory = psLogDir() / L"sim_log" / name.str(); } while (DirectoryExists(m_Directory)); CreateDirectories(m_Directory, 0700); m_Stream = new std::ofstream(OsString(m_Directory / L"commands.txt").c_str(), std::ofstream::out | std::ofstream::trunc); *m_Stream << "start " << m_ScriptInterface.StringifyJSON(attribs, false) << "\n"; }
/** * Return an unused directory, based on date and index (for example 2016-02-09_0001) */ OsPath createDateIndexSubdirectory(const OsPath& parentDir) { const std::time_t timestamp = std::time(nullptr); const struct std::tm* now = std::localtime(×tamp); // Two processes executing this simultaneously might attempt to create the same directory. int tries = 0; const int maxTries = 10; int i = 0; OsPath path; char directory[256]; do { sprintf(directory, "%04d-%02d-%02d_%04d", now->tm_year+1900, now->tm_mon+1, now->tm_mday, ++i); path = parentDir / CStr(directory); if (DirectoryExists(path) || FileExists(path)) continue; if (CreateDirectories(path, 0700, ++tries > maxTries) == INFO::OK) break; } while(tries <= maxTries); return path; }
bool RageFileDriverDirect::Remount( const RString &sPath ) { m_sRoot = sPath; ((DirectFilenameDB *) FDB)->SetRoot( sPath ); /* If the root path doesn't exist, create it. */ CreateDirectories( m_sRoot ); return true; }
static void InitVfs(const CmdLineArgs& args) { TIMER(L"InitVfs"); const Paths paths(args); OsPath logs(paths.Logs()); CreateDirectories(logs, 0700); psSetLogDir(logs); // desired location for crashlog is now known. update AppHooks ASAP // (particularly before the following error-prone operations): AppHooks hooks = {0}; hooks.bundle_logs = psBundleLogs; hooks.get_log_dir = psLogDir; hooks.display_error = psDisplayError; app_hooks_update(&hooks); const size_t cacheSize = ChooseCacheSize(); g_VFS = CreateVfs(cacheSize); std::vector<CStr> mods = args.GetMultiple("mod"); mods.insert(mods.begin(), "public"); if (!args.Has("noUserMod")) mods.push_back("user"); OsPath modPath = paths.RData()/"mods"; OsPath modUserPath = paths.UserData()/"mods"; for (size_t i = 0; i < mods.size(); ++i) { size_t priority = i+1; // mods are higher priority than regular mountings, which default to priority 0 size_t flags = VFS_MOUNT_WATCH|VFS_MOUNT_ARCHIVABLE|VFS_MOUNT_MUST_EXIST; OsPath modName(mods[i]); g_VFS->Mount(L"", modPath / modName/"", flags, priority); g_VFS->Mount(L"", modUserPath / modName/"", flags, priority); } // We mount these dirs last as otherwise writing could result in files being placed in a mod's dir. g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/""); g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH); const OsPath readonlyConfig = paths.RData()/"config"/""; // Mounting with highest priority, so that a mod supplied user.cfg is harmless g_VFS->Mount(L"config/", readonlyConfig, 0, (size_t)-1); if(readonlyConfig != paths.Config()) g_VFS->Mount(L"config/", paths.Config(), 0, (size_t)-1); g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE); // (adding XMBs to archive speeds up subsequent reads) // note: don't bother with g_VFS->TextRepresentation - directories // haven't yet been populated and are empty. }
int Console::Run(int argc,char* argv[]) { CreateDirectories(); bool isUser=false; string cmd; if (PasswordManager::ValidatePassword()) { pair<bool, tVecStr> valPass=ValidatePassword(); if(valPass.first) isUser=true; else IntrudersManager::writeIntruder(valPass.second); } else { /*PEDIR PASS Y CREAR TODAS LAS ESTRUCTURAS*/ Message pass; bool isOk=Console::InsertNewPassword(pass); if(isOk){ FileSystem::CreateStruture(pass); isUser=true; pass.Delete(); } } if (isUser) { ShowInitialMessage(); if (IntrudersManager::ExistNewIntruder() ) { Console::ShowIntruderMessage(); } UpdatesImage(); while(!CommandFactory::IsQuitCommand(cmd)) { ReadCommand(cmd); Command* command = CommandFactory::CreateCommand(cmd); if(command != NULL) { command->Run(cmd); delete command; } } Destroy(); } return 0; }
static void InitVfs(const CmdLineArgs& args, int flags) { TIMER(L"InitVfs"); const bool setup_error = (flags & INIT_HAVE_DISPLAY_ERROR) == 0; const Paths paths(args); OsPath logs(paths.Logs()); CreateDirectories(logs, 0700); psSetLogDir(logs); // desired location for crashlog is now known. update AppHooks ASAP // (particularly before the following error-prone operations): AppHooks hooks = {0}; hooks.bundle_logs = psBundleLogs; hooks.get_log_dir = psLogDir; if (setup_error) hooks.display_error = psDisplayError; app_hooks_update(&hooks); const size_t cacheSize = ChooseCacheSize(); g_VFS = CreateVfs(cacheSize); const OsPath readonlyConfig = paths.RData()/"config"/""; g_VFS->Mount(L"config/", readonlyConfig); // Engine localization files. g_VFS->Mount(L"l10n/", paths.RData()/"l10n"/""); MountMods(paths, GetMods(args, flags)); // We mount these dirs last as otherwise writing could result in files being placed in a mod's dir. g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/""); g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH); // Mounting with highest priority, so that a mod supplied user.cfg is harmless g_VFS->Mount(L"config/", readonlyConfig, 0, (size_t)-1); if(readonlyConfig != paths.Config()) g_VFS->Mount(L"config/", paths.Config(), 0, (size_t)-1); g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE); // (adding XMBs to archive speeds up subsequent reads) // note: don't bother with g_VFS->TextRepresentation - directories // haven't yet been populated and are empty. }
CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) : m_ScriptInterface(scriptInterface) { // Construct the directory name based on the PID, to be relatively unique. // Append "-1", "-2" etc if we run multiple matches in a single session, // to avoid accidentally overwriting earlier logs. std::wstringstream name; name << getpid(); static int run = -1; if (++run) name << "-" << run; OsPath path = psLogDir() / L"sim_log" / name.str() / L"commands.txt"; CreateDirectories(path.Parent(), 0700); m_Stream = new std::ofstream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); }
virtual Status Mount(const VfsPath& mountPoint, const OsPath& path, size_t flags /* = 0 */, size_t priority /* = 0 */) { ScopedLock s; if(!DirectoryExists(path)) { if(flags & VFS_MOUNT_MUST_EXIST) return ERR::VFS_DIR_NOT_FOUND; // NOWARN else RETURN_STATUS_IF_ERR(CreateDirectories(path, 0700)); } VfsDirectory* directory; WARN_RETURN_STATUS_IF_ERR(vfs_Lookup(mountPoint, &m_rootDirectory, directory, 0, VFS_LOOKUP_ADD|VFS_LOOKUP_SKIP_POPULATE)); PRealDirectory realDirectory(new RealDirectory(path, priority, flags)); RETURN_STATUS_IF_ERR(vfs_Attach(directory, realDirectory)); return INFO::OK; }
void HK_CALL DumpHavokClassImpl(hkClass* hclass) { char fbuffer[260], buffer[1024]; const char *ptr = hclass->getName(); int ver = hclass->getDescribedVersion(); sprintf_s(fbuffer, 256, "%s\\%s_%d.cpp", s_rootPath, ptr, ver); char outdir[MAX_PATH]; strcpy(outdir, fbuffer); PathRemoveFileSpec(outdir); CreateDirectories(outdir); hkClass* pParent = hclass->getParent(); FILE *hFile = NULL; fopen_s(&hFile, fbuffer, "wt" ); if ( hFile != NULL ) { PrintLine(hFile, "#include \"StdAfx.h\""); PrintLine(hFile, "#include \"%s_%d.h\"", ptr, ver); PrintLine(hFile, ""); PrintLine(hFile, "#include <Common/Serialize/hkSerialize.h>"); PrintLine(hFile, "#include <Common/Serialize/Util/hkSerializeUtil.h>"); PrintLine(hFile, "#include <Common/Serialize/Version/hkVersionPatchManager.h>"); PrintLine(hFile, "#include <Common/Serialize/Data/Dict/hkDataObjectDict.h>"); PrintLine(hFile, "#include <Common/Serialize/Data/Native/hkDataObjectNative.h>"); PrintLine(hFile, "#include <Common/Serialize/Data/Util/hkDataObjectUtil.h>"); PrintLine(hFile, "#include <Common/Base/Reflection/Registry/hkDynamicClassNameRegistry.h>"); PrintLine(hFile, "#include <Common/Base/Reflection/Registry/hkVtableClassRegistry.h>"); PrintLine(hFile, "#include <Common/Base/Reflection/hkClass.h>"); PrintLine(hFile, "#include <Common/Base/Reflection/hkInternalClassMember.h>"); PrintLine(hFile, "#include <Common/Serialize/Util/hkSerializationCheckingUtils.h>"); PrintLine(hFile, "#include <Common/Serialize/Util/hkVersionCheckingUtils.h>"); PrintLine(hFile, ""); PrintLine(hFile, ""); if ( 0 < hclass->getNumDeclaredEnums()) { for (int i=0,n=hclass->getNumDeclaredEnums();i<n;++i) { const hkClassEnum &hEnum = hclass->getDeclaredEnum(i); PrintLine(hFile, "static const hkInternalClassEnumItem %sEnumItems[] =", hEnum.getName()); PrintLine(hFile, "{"); for (int j=0,m=hEnum.getNumItems();j<m;++j) { const hkClassEnum::Item& item = hEnum.getItem(j); PrintLine(hFile, " {%d, \"%s\"},", item.getValue(), item.getName()); } PrintLine(hFile, "};"); PrintLine(hFile, ""); } PrintLine(hFile, "static const hkInternalClassEnum %sClass_Enums[] = {", ptr); for (int i=0,n=hclass->getNumDeclaredEnums();i<n;++i) { const hkClassEnum &hEnum = hclass->getDeclaredEnum(i); PrintLine(hFile, " {\"%s\", %sEnumItems, _countof(%sEnumItems), HK_NULL, %d },", hEnum.getName(),hEnum.getName(),hEnum.getName(), hEnum.getFlags()); } PrintLine(hFile, "};"); for (int i=0,n=hclass->getNumDeclaredEnums();i<n;++i) { const hkClassEnum &hEnum = hclass->getDeclaredEnum(i); PrintLine(hFile, "const hkClassEnum* %sEnum = reinterpret_cast<const hkClassEnum*>(&%sClass_Enums[%d]);", hEnum.getName(), ptr, i); } PrintLine(hFile, ""); } if ( hclass->getNumDeclaredMembers() > 0) { PrintLine(hFile, "static const hkInternalClassMember %sClass_Members[] =", ptr); PrintLine(hFile, "{"); for (int i=0,n=hclass->getNumDeclaredMembers();i<n;++i) { const hkClassMember &mem = hclass->getDeclaredMember(i); mem.getTypeName(buffer, 1024); fprintf(hFile, " { \"%s\"", mem.getName()); if ( !mem.hasClass() ) fprintf(hFile, ",HK_NULL"); else if (const hkClass* mclass = mem.getClass()) fprintf(hFile, ",&%sClass", mclass->getName()); else fprintf(hFile, ",HK_NULL"); if ( !mem.hasEnumClass() ) fprintf(hFile, ",HK_NULL"); else fprintf(hFile, ",%sEnum", mem.getEnumClass().getName()); string typeStr = EnumToString(mem.getType(), TypeEnums); fprintf(hFile, ",%s", typeStr.c_str()); string subTypeStr = EnumToString(mem.getSubType(), TypeEnums); fprintf(hFile, ",%s", subTypeStr.c_str()); fprintf(hFile, ",%d", mem.getCstyleArraySize()); string flagsStr = FlagsToString((int)*(short*)&mem.getFlags(), TypeFlags); fprintf(hFile, ",%s", flagsStr.c_str()); fprintf(hFile, ",HK_OFFSET_OF(%s,m_%s) /*%d*/", ptr, mem.getName(), mem.getOffset()); if ( hclass->hasDeclaredDefault(i) ) { //hkTypedUnion value; //if (HK_SUCCESS == hclass->getDeclaredDefault(i, value)) // fprintf(hFile, ",%08lx", value.getStorage().m_int32); //else fprintf(hFile, ",HK_NULL"); } else fprintf(hFile, ",HK_NULL"); fprintf(hFile, "},\n"); } PrintLine(hFile, "};"); PrintLine(hFile, ""); } PrintLine(hFile, "// Signature: %08lx", hclass->getSignature()); if (pParent != NULL) PrintLine(hFile, "extern const hkClass %sClass;", pParent->getName()); PrintLine(hFile, "extern const hkClass %sClass;", ptr); PrintLine(hFile, "const hkClass %sClass(", ptr); PrintLine(hFile, " \"%s\",", ptr); if (pParent == NULL) PrintLine(hFile, " HK_NULL, // parent"); else PrintLine(hFile, " &%sClass, // parent", pParent->getName()); PrintLine(hFile, " sizeof(%s),", ptr); if (hclass->getNumDeclaredInterfaces() > 0) PrintLine(hFile, " reinterpret_cast<const hkClassMember*>(%sClass_IFaces), HK_COUNT_OF(%sClass_IFaces),", ptr, ptr); else PrintLine(hFile, " HK_NULL, 0, // interfaces"); if (hclass->getNumDeclaredEnums() > 0) PrintLine(hFile, " reinterpret_cast<const hkClassEnum*>(%sClass_Enums), HK_COUNT_OF(%sClass_Enums),", ptr, ptr); else PrintLine(hFile, " HK_NULL, 0, // enums"); if (hclass->getNumDeclaredMembers() > 0) PrintLine(hFile, " reinterpret_cast<const hkClassMember*>(%sClass_Members), HK_COUNT_OF(%sClass_Members),", ptr, ptr); else PrintLine(hFile, " HK_NULL, 0, // members"); PrintLine(hFile, " HK_NULL, // defaults"); PrintLine(hFile, " HK_NULL, // attributes"); PrintLine(hFile, " %d, // flags", hclass->getFlags()); PrintLine(hFile, " %d // version", ver); PrintLine(hFile, " );"); if (hclass->hasVtable()) PrintLine(hFile, "HK_REFLECTION_DEFINE_VIRTUAL(%s, %s);", ptr, ptr); else PrintLine(hFile, "HK_REFLECTION_DEFINE_SIMPLE(%s, %s);", ptr, ptr); PrintLine(hFile, ""); fflush(hFile); fclose(hFile); } }
int CompileAspPage(lua_State *L, const char *asp_path, const struct AspEngineConfig *config, char **error_message) { int requires_recompilation = 0; struct _stat asp_file_stat; struct _stat luac_file_stat; char cache_path[MAX_PATH]; char lua_file[MAX_PATH]; char luac_file[MAX_PATH]; struct membuf *lua_content; lua_State *LL; int result; struct ReaderState reader_state; int use_cache; assert(((!config->cache_lua && !config->cache_luac) || ((config->cache_lua || config->cache_luac)) && config->root_path && config->cache_path)); if (error_message != NULL) *error_message = NULL; if (config->cache_path && !RetargetPath(config->root_path, asp_path, config->cache_path, cache_path)) { use_cache = config->cache_lua || config->cache_luac; } else { use_cache = 0; } if (_stat(asp_path, &asp_file_stat) != 0) { if (error_message) *error_message = strdup(strerror(errno)); return errno; } requires_recompilation = 1; if (use_cache) { CreateDirectories(cache_path); strcat(strcpy(lua_file, cache_path), ".lua"); strcat(strcpy(luac_file, cache_path), ".luac"); if (_stat(luac_file, &luac_file_stat) == 0) { if (asp_file_stat.st_mtime < luac_file_stat.st_mtime) requires_recompilation = 0; } } if (requires_recompilation) { lua_content = GenerateLuaFile(asp_path, (use_cache && config->cache_lua) ? lua_file : NULL, error_message); if (lua_content == NULL) return 1; } else { FILE *luac_fp = fopen(luac_file, "rb"); if (luac_fp == NULL) { if (error_message) *error_message = strdup(strerror(errno)); return 1; } lua_content = membuf_create(luac_file_stat.st_size, _dup(_fileno(luac_fp)), 1, 0); fclose(luac_fp); } reader_state.ptr = (char *)membuf_begin(lua_content); reader_state.end = (char *)membuf_end(lua_content); LL = L ? L : luaL_newstate(); result = lua_load(LL, StringStreamReader, &reader_state, asp_path, NULL); if (result != LUA_OK) { membuf_close(lua_content); if (error_message) *error_message = strdup(lua_tostring(LL, -1)); if (L == NULL) lua_close(LL); return 1; } membuf_close(lua_content); if (use_cache && requires_recompilation && config->cache_luac) { struct FileWriterState writer_state; writer_state.fp = fopen(luac_file, "wb"); if (writer_state.fp != NULL) { lua_dump(LL, FileWriter, &writer_state); fclose(writer_state.fp); } } if (L != NULL) { result = lua_pcall(LL, 0, 0, 0); if (result && error_message) *error_message = strdup(lua_tostring(LL, -1)); } else { lua_close(LL); } return result; }
void HK_CALL DumpHavokClassHeader(hkClass* hclass) { char fbuffer[260], buffer[1024]; const char *ptr = hclass->getName(); int ver = hclass->getDescribedVersion(); sprintf_s(fbuffer, 256, "%s\\%s_%d.h", s_rootPath, ptr, ver); char outdir[MAX_PATH]; strcpy(outdir, fbuffer); PathRemoveFileSpec(outdir); CreateDirectories(outdir); hkClass* pParent = hclass->getParent(); FILE *hFile = NULL; fopen_s(&hFile, fbuffer, "wt" ); if ( hFile != NULL ) { PrintLine(hFile, "#pragma once"); PrintLine(hFile, ""); PrintLine(hFile, "#include <Common/Base/hkBase.h>"); std::set<string> nameMap; if (pParent != NULL) { LPCSTR hdrName = LookupClassHeader(pParent->getName()); if (hdrName != NULL) PrintLine(hFile, "#include <%s>", hdrName); else PrintLine(hFile, "#include \"%s_%d.h\"", pParent->getName(), pParent->getDescribedVersion()); nameMap.insert(string(pParent->getName())); } for (int i=0,n=hclass->getNumDeclaredMembers();i<n;++i) { const hkClassMember &mem = hclass->getDeclaredMember(i); if ( mem.hasClass() ) { if ( const hkClass* mClass = mem.getClass() ) { string name = mClass->getName(); if (nameMap.find(name) == nameMap.end()) { nameMap.insert(name); LPCSTR hdrName = LookupClassHeader(mClass->getName()); if (hdrName != NULL) PrintLine(hFile, "#include <%s>", hdrName); else PrintLine(hFile, "#include \"%s_%d.h\"", name.c_str(), mClass->getDescribedVersion()); } } } } PrintLine(hFile, ""); if (!hclass->hasVtable()) { if (pParent != NULL) PrintLine(hFile, "struct %s : public %s", ptr, pParent->getName()); else PrintLine(hFile, "struct %s", ptr); } else { if (pParent != NULL) PrintLine(hFile, "class %s : public %s", ptr, pParent->getName()); else PrintLine(hFile, "class %s", ptr); } PrintLine(hFile, "{"); if (hclass->hasVtable()) { PrintLine(hFile, "public:"); PrintLine(hFile, " HK_DECLARE_CLASS_ALLOCATOR( HK_MEMORY_CLASS_BEHAVIOR_RUNTIME );"); } else { PrintLine(hFile, " HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( HK_MEMORY_CLASS_BEHAVIOR_RUNTIME, %s );", ptr); } PrintLine(hFile, " HK_DECLARE_REFLECTION();"); PrintLine(hFile, ""); if (hclass->hasVtable()) PrintLine(hFile, "public:"); PrintLine(hFile, " HK_FORCE_INLINE %s(void) {}", ptr); if (hclass->hasVtable()) { bool first = pParent == NULL; if (pParent == NULL) PrintLine(hFile, " HK_FORCE_INLINE %s( hkFinishLoadedObjectFlag flag ) ", ptr); else PrintLine(hFile, " HK_FORCE_INLINE %s( hkFinishLoadedObjectFlag flag ) : %s(flag) ", ptr, pParent->getName()); for (int i=0,n=hclass->getNumDeclaredMembers();i<n;++i) { const hkClassMember &mem = hclass->getDeclaredMember(i); switch (mem.getType()) { case hkClassMember::TYPE_POINTER: case hkClassMember::TYPE_ARRAY: case hkClassMember::TYPE_STRINGPTR: case hkClassMember::TYPE_VARIANT: if (first) PrintLine(hFile, " m_%s(flag)", mem.getName()); else PrintLine(hFile, " , m_%s(flag)", mem.getName()); first = false; break; } } PrintLine(hFile, " {}"); } for (int i=0,n=hclass->getNumDeclaredEnums();i<n;++i) { const hkClassEnum &hEnum = hclass->getDeclaredEnum(i); PrintLine(hFile, " enum %s", hEnum.getName()); PrintLine(hFile, " {"); for (int j=0,m=hEnum.getNumItems();j<m;++j) { const hkClassEnum::Item& item = hEnum.getItem(j); PrintLine(hFile, " %s = %d,", item.getName(),item.getValue()); } PrintLine(hFile, " };"); PrintLine(hFile, ""); } PrintLine(hFile, " // Properties"); for (int i=0,n=hclass->getNumDeclaredMembers();i<n;++i) { const hkClassMember &mem = hclass->getDeclaredMember(i); bool print=true; string typeName; switch (mem.getType()) { case hkClassMember::TYPE_ENUM: typeName = EnumToString(mem.getSubType(), CTypeEnums); if (mem.hasEnumClass()) { PrintLine(hFile, " hkEnum<%s,%s> m_%s;", mem.getEnumClass().getName(), typeName.c_str(), mem.getName()); print=false; } else if (typeName.substr(0,2).compare("0x") != 0) { PrintLine(hFile, " /*enum*/ %s m_%s;", typeName.c_str(), mem.getName()); print=false; } break; case hkClassMember::TYPE_FLAGS: typeName = EnumToString(mem.getSubType(), CTypeEnums); if (mem.hasEnumClass()) { PrintLine(hFile, " hkFlags<%s,%s> m_%s;", mem.getEnumClass().getName(), typeName.c_str(), mem.getName()); print=false; } else if (typeName.substr(0,2).compare("0x") != 0) { PrintLine(hFile, " /*flags*/ %s m_%s;", typeName.c_str(), mem.getName()); print=false; } else break; } if (print) { mem.getTypeName(buffer, 1024); typeName = buffer; typeName = replaceSubstring(typeName, "<", "<"); typeName = replaceSubstring(typeName, ">", ">"); typeName = replaceSubstring(typeName, "void*", "hkRefVariant"); typeName = replaceSubstring(typeName, "<void>", "<hkRefVariant>"); if ( hkClassMember::TYPE_POINTER == mem.getType() ) { if ( typeName.substr(typeName.length()-1,1).compare("*") == 0 ) { typeName.replace(typeName.length()-1,1,1,'>'); typeName.insert(0, "hkRefPtr<"); } } typeName = replaceSubstring(typeName, "struct ", ""); if (mem.getCstyleArraySize() > 0) { string arString = FormatString("[%d]",mem.getCstyleArraySize()); typeName = replaceSubstring(typeName, arString, ""); PrintLine(hFile, " %s m_%s%s;", typeName.c_str(), mem.getName(), arString.c_str()); } else { PrintLine(hFile, " %s m_%s;", typeName.c_str(), mem.getName()); } } } PrintLine(hFile, "};"); PrintLine(hFile, "extern const hkClass %sClass;", ptr); PrintLine(hFile, ""); fflush(hFile); fclose(hFile); } }
static void InitVfs(const CmdLineArgs& args, int flags) { TIMER(L"InitVfs"); const bool setup_error = (flags & INIT_HAVE_DISPLAY_ERROR) == 0; const Paths paths(args); OsPath logs(paths.Logs()); CreateDirectories(logs, 0700); psSetLogDir(logs); // desired location for crashlog is now known. update AppHooks ASAP // (particularly before the following error-prone operations): AppHooks hooks = {0}; hooks.bundle_logs = psBundleLogs; hooks.get_log_dir = psLogDir; if (setup_error) hooks.display_error = psDisplayError; app_hooks_update(&hooks); const size_t cacheSize = ChooseCacheSize(); g_VFS = CreateVfs(cacheSize); // Work out whether we are a dev version to make sure saved files // (maps, etc) end up in version control. const OsPath readonlyConfig = paths.RData()/"config"/""; g_VFS->Mount(L"config/", readonlyConfig); bool dev = (g_VFS->GetFileInfo(L"config/dev.cfg", NULL) == INFO::OK); const std::vector<CStr> mods = GetMods(args, dev); OsPath modPath = paths.RData()/"mods"; OsPath modUserPath = paths.UserData()/"mods"; for (size_t i = 0; i < mods.size(); ++i) { size_t priority = (i+1)*2; // mods are higher priority than regular mountings, which default to priority 0 size_t userFlags = VFS_MOUNT_WATCH|VFS_MOUNT_ARCHIVABLE|VFS_MOUNT_REPLACEABLE; size_t baseFlags = userFlags|VFS_MOUNT_MUST_EXIST; OsPath modName(mods[i]); if (dev) { // We are running a dev copy, so only mount mods in the user mod path // if the mod does not exist in the data path. if (DirectoryExists(modPath / modName/"")) g_VFS->Mount(L"", modPath / modName/"", baseFlags, priority); else g_VFS->Mount(L"", modUserPath / modName/"", userFlags, priority); } else { g_VFS->Mount(L"", modPath / modName/"", baseFlags, priority); // Ensure that user modified files are loaded, if they are present g_VFS->Mount(L"", modUserPath / modName/"", userFlags, priority+1); } } // We mount these dirs last as otherwise writing could result in files being placed in a mod's dir. g_VFS->Mount(L"screenshots/", paths.UserData()/"screenshots"/""); g_VFS->Mount(L"saves/", paths.UserData()/"saves"/"", VFS_MOUNT_WATCH); // Mounting with highest priority, so that a mod supplied user.cfg is harmless g_VFS->Mount(L"config/", readonlyConfig, 0, (size_t)-1); if(readonlyConfig != paths.Config()) g_VFS->Mount(L"config/", paths.Config(), 0, (size_t)-1); g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE); // (adding XMBs to archive speeds up subsequent reads) // note: don't bother with g_VFS->TextRepresentation - directories // haven't yet been populated and are empty. }
void HK_CALL DumpHavokClassReport(hkClass* hclass) { char fbuffer[260], buffer[1024]; const char *ptr = hclass->getName(); int ver = hclass->getDescribedVersion(); sprintf_s(fbuffer, 256, "%s\\rpt\\%s_%d.rpt", s_rootPath, ptr, ver); { char outdir[MAX_PATH]; strcpy(outdir, fbuffer); PathRemoveFileSpec(outdir); CreateDirectories(outdir); hkOstream stream(fbuffer); //stream.printf("Address:\t%08lx\n", hclass); stream.printf("Signature:\t%08lx\n", hclass->getSignature()); stream.printf("VTable:\t%s\n", hclass->hasVtable() ? "TRUE" : "FALSE"); stream.printf("Name:\t%s\n", hclass->getName()); if ( hkClass* pParent = hclass->getParent() ) stream.printf("Parent:\t%s (%08lx)\n", pParent->getName(), pParent->getSignature()); else stream.printf("Parent:\t%s\n", "HK_NULL"); stream.printf("Size:\t%d\n", hclass->getObjectSize()); stream.printf("#IFace:\t%d\n", hclass->getNumDeclaredInterfaces()); for (int i=0,n=hclass->getNumDeclaredInterfaces();i<n;++i) { if ( const hkClass* iface = hclass->getDeclaredInterface(i) ) stream.printf(" %.3d\t%s (%08lx)\n", i, iface->getName(), iface); else stream.printf(" %.3d\t%s\n", i, "HK_NULL"); } stream.printf("#Enums:\t%d\n", hclass->getNumDeclaredEnums()); for (int i=0,n=hclass->getNumDeclaredEnums();i<n;++i) { const hkClassEnum &hEnum = hclass->getDeclaredEnum(i); stream.printf(" %.3d\t%s (", i, hEnum.getName()); for (int j=0,m=hEnum.getNumItems();j<m;++j) { const hkClassEnum::Item& item = hEnum.getItem(j); if (j != 0) stream.printf(";"); stream.printf("%s=%d", item.getName(), item.getValue()); } stream.printf(") {%08lx}\n", hEnum.getFlags()); } stream.printf("#Members:\t%d\n", hclass->getNumDeclaredMembers()); for (int i=0,n=hclass->getNumDeclaredMembers();i<n;++i) { const hkClassMember &mem = hclass->getDeclaredMember(i); stream.printf(" %.3d\t%s", i, mem.getName()); if ( !mem.hasClass() ) stream.printf(",HK_NULL"); else if (const hkClass* mclass = mem.getClass()) stream.printf(",%s", mclass->getName()); else stream.printf(",HK_NULL"); if ( !mem.hasEnumClass() ) stream.printf(",HK_NULL"); else stream.printf(",%s", mem.getEnumClass().getName()); mem.getTypeName(buffer, 1024); stream.printf(",%s", buffer); stream.printf(",%08lx", mem.getType()); stream.printf(",%08lx", mem.getSubType()); stream.printf(",%d", mem.getCstyleArraySize()); stream.printf(",%08lx", mem.getFlags()); stream.printf(",%d", mem.getOffset()); stream.printf(",HK_NULL"); if ( hclass->hasDeclaredDefault(i) ) { hkTypedUnion value; if (HK_SUCCESS == hclass->getDeclaredDefault(i, value)) stream.printf(",%08lx", value.getStorage().m_int32); else stream.printf(",HK_NULL"); } else stream.printf(",HK_NULL"); stream.printf("\n"); } stream.printf("Version:\t%d\n", hclass->getDescribedVersion()); stream.flush(); } }