/* =========================================================================== * If not in exclude mode, expand the pattern based on the contents * of the file system. * This function is used while gathering filenames to be added or updated *w :: Path/pattern to match. Possible return values: ZEN_MISS, ZEN_OK, ZEN_ABORT, ZEN_MEM or ZEN_PARMS. */ int Wild( char *w, struct Globals *pG ) { zDIR *d; /* Stream for reading directory */ char *e; /* File or directory name found. */ char *n; /* Constructed name from directory */ int WError; /* Result of Wild() */ char *p, *a; /* path originale and fixed. */ char *q; /* Filename / pattern. */ int r; /* Result / temp var. */ char v[5]; /* space for device current directory.*/ bool StopRecurs = false; /* No recursion if filespec is file. */ // sprintf( pG->ewemsg, "in Wild of win32zip.c, pattern=%s recurse=%d", w, pG->recurse ); // diag( pG->ewemsg, pG ); // "zip -$ foo a:" can be used to force a drive name once. // v1.6017 if ( pG->volume_label == 1 ) { pG->volume_label = 2; pG->label = getVolumeLabel( pG, (w != NULL && w[ 1 ] == ':') ? to_up( w[ 0 ] ) : '\0', &pG->label_time, &pG->label_mode, &pG->label_utim ); if ( pG->label != NULL ) (void)newname( pG->label, 0, pG ); if ( w == NULL || (w[1] == ':' && w[2] == '\0') ) return ZEN_OK; } /* Allocate and copy pattern */ if ( (p = a = MALLOC( lstrlen( w ) + 1) ) == NULL ) return ZEN_MEM19; lstrcpy( p, w ); /* Separate path and name into p and q */ // We have '\' or '\name' or 'path1\path2\name2' or 'C:\path\name' but NOT 'C:\name' if ( (q = strrchr( p, '\\' )) != NULL && (q == p || q[-1] != ':') ) { // SLASH *q++ = '\0'; if ( *p == '\0' ) p = lstrcpy( v, "\\." ); /* if path is just '\' SLASH */ } else if ( (q = strrchr( p, ':' )) != NULL ) { /* We have 'C:' or 'C:\' or 'C:\name' */ *q++ = '\0'; p = lstrcat( lstrcpy( v, p ), ":" ); /* copy device as path eg. 'C:' */ if ( *q == '\\' ) { /* -> device:/., name eg. 'C:\.' SLASH */ lstrcat( p, "\\" ); // SLASH q++; /* name or nothing. */ } lstrcat( p, "." ); /* eg. 'C:.' or 'C:\.' */ } else if ( pG->recurse && (!strcmp( p, "." ) || !strcmp( p, ".." )) ) { /* current or parent directory */ /* Get "zip -r foo ." to work. Allow the dubious "zip -r foo .." but * reject "zip -r -m foo ..". "dispose" means wipe out source path. */ if ( pG->dispose && !strcmp( p, ".." ) ) ziperr( ZEN_PARMS15, pG ); q = (char *)pG->wild_match_all; } else { /* no path or device */ q = p; p = lstrcpy( v, "." ); } if ( pG->recurse && *q == '\0' ) q = (char *)pG->wild_match_all; /* take out a possibly redundant dir name of "." */ if ( (r = lstrlen( p )) > 1 && (strcmp( p + r - 2, ":." ) == 0 || strcmp( p + r - 2, "\\." ) == 0) ) // SLASH *(p + r - 1) = '\0'; /* Only filename (not the path) can have special matching characters */ if ( IsShExp( p ) ) { diag( "path has illegal chars", pG ); FREE( a ); return ZEN_PARMS16; } // sprintf( ewemsg, "at break up place in Wild: path=%s name=%s", p, q ); // diag( ewemsg ); if ( !IsShExp( q ) ) { // Speed up checking if file exits in case there are no wildcards struct stat s; // and no recursion and no archiving v1.6016 if ( !pG->recurse && !pG->ArchiveFiles ) { if ( !LSSTAT( GetFullPath( pG, w ), &s ) ) /* file exists ? */ return procname( w, false, pG ); return ZEN_MISS02; /* woops, no wildcards where is the file! */ } if ( pG->norecursefiles ) StopRecurs = true; } /* Now that we have a dir spec, along with an fspec, we'll step * in the dir specified to see if there's any matches against the fspec. */ WError = ZEN_MISS02; if ( (d = Opendir( p, pG )) != NULL ) { while ( (e = readd( d, pG )) != NULL ) { if ( pG->global_abort_sw ) { WError = ZEN_ABORT; break; } // sprintf( ewemsg, "Found %s: %s", d->d_attr & FILE_ATTRIBUTE_DIRECTORY ? "directory" : "file", e ); // diag( ewemsg ); /* if e is NOT '.' or '..', and is a dir or match fspec. */ if ( strcmp( e, "." ) && strcmp( e, ".." ) && (d->d_attr & FILE_ATTRIBUTE_DIRECTORY || dosmatch( q, e, pG )) ) { // diag( "Matched" ); /* we matched fspec or it's a dir and entry is not '.' or '..' */ if ( d->d_attr & FILE_ATTRIBUTE_DIRECTORY ) { // We do not save dirs or go into dirs if norecursefiles==1 and we a file without * or ? specs. if ( !StopRecurs && (pG->dirnames || pG->recurse) ) { if ( (n = MALLOC( lstrlen( p ) + lstrlen( e ) + lstrlen( q ) + 3 )) == NULL ) { WError = ZEN_MEM20; break; } *n = '\0'; if ( *p != '.' ) AddSlash( lstrcpy( n, p ) ); // No ./ as first dir. lstrcat( n, e ); if ( pG->dirnames ) { // Save directory names also. r = procname( n, false, pG ); if ( (int)(char)(r & 0xFF) > ZEN_OK || !pG->recurse ) FREE( n ); if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r; if ( (int)(char)(r & 0xFF) > ZEN_OK ) break; } if ( pG->recurse ) { // Recursively go into dir and check for other pattern matches. r = Wild( lstrcat( AddSlash( n ), q ), pG ); // Add the original pattern. FREE( n ); // We keep a ZEN_OK even when ZEN_MISS occurs. if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r; if ( (int)(char)(r & 0xFF) > ZEN_OK ) break; // An error, stop processing. } } } else { if ( (n = MALLOC( lstrlen( p ) + lstrlen( e ) + 2 )) == NULL ) { WError = ZEN_MEM21; break; } if ( !strcmp( p, "." ) ) r = procname( e, false, pG ); else r = procname( lstrcat( AddSlash( lstrcpy( n, p ) ), e ), false, pG ); FREE( n ); if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r; if ( (int)(char)(r & 0xFF) > ZEN_OK ) break; } } /* end "if (strcmp..." */ } /* end while */ Closedir( d ); } else diag( "can't open dir", pG ); FREE( a ); // sprintf( ewemsg, "Wild returned: %d", WError ); // diag( ewemsg ); return WError; }
void DoEditHomeFiles(struct Edit *ptr) { DIR *dirh, *dirh2; struct dirent *dirp, *dirp2; char *sp,homedir[CF_BUFSIZE],dest[CF_BUFSIZE]; struct passwd *pw; struct stat statbuf; struct Item *ip; uid_t uid; if (!MountPathDefined()) { CfLog(cfinform,"Mountpattern is undefined\n",""); return; } for (ip = VMOUNTLIST; ip != NULL; ip=ip->next) { if (IsExcluded(ip->classes)) { continue; } if ((dirh = opendir(ip->name)) == NULL) { snprintf(OUTPUT,CF_BUFSIZE*2,"Can't open directory %s\n",ip->name); CfLog(cferror,OUTPUT,"opendir"); return; } for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) { if (!SensibleFile(dirp->d_name,ip->name,NULL)) { continue; } strcpy(homedir,ip->name); AddSlash(homedir); strcat(homedir,dirp->d_name); if (! IsHomeDir(homedir)) { continue; } if ((dirh2 = opendir(homedir)) == NULL) { snprintf(OUTPUT,CF_BUFSIZE*2,"Can't open directory%s\n",homedir); CfLog(cferror,OUTPUT,"opendir"); return; } for (dirp2 = readdir(dirh2); dirp2 != NULL; dirp2 = readdir(dirh2)) { if (!SensibleFile(dirp2->d_name,homedir,NULL)) { continue; } strcpy(dest,homedir); AddSlash(dest); strcat(dest,dirp2->d_name); AddSlash(dest); sp = ptr->fname + strlen("home/"); strcat(dest,sp); if (stat(dest,&statbuf)) { EditVerbose("File %s doesn't exist for editing, skipping\n",dest); continue; } if ((pw = getpwnam(dirp2->d_name)) == NULL) { Debug2("cfengine: directory corresponds to no user %s - ignoring\n",dirp2->d_name); continue; } else { Debug2("(Setting user id to %s)\n",dirp2->d_name); } uid = statbuf.st_uid; WrapDoEditFile(ptr,dest); chown(dest,uid,CF_SAME_OWNER); } closedir(dirh2); } closedir(dirh); } }
void *CopyFileSources(char *destination, Attributes attr, Promise *pp, const ReportContext *report_context) { char *source = attr.copy.source; char *server = pp->this_server; char vbuff[CF_BUFSIZE]; struct stat ssb, dsb; struct timespec start; char eventname[CF_BUFSIZE]; CfDebug("CopyFileSources(%s,%s)", source, destination); if (pp->conn != NULL && !pp->conn->authenticated) { cfPS(cf_verbose, CF_FAIL, "", pp, attr, "No authenticated source %s in files.copyfrom promise\n", source); return NULL; } if (cf_stat(attr.copy.source, &ssb, attr, pp) == -1) { cfPS(cf_inform, CF_FAIL, "", pp, attr, "Can't stat %s in files.copyfrom promise\n", source); return NULL; } start = BeginMeasure(); strncpy(vbuff, destination, CF_BUFSIZE - 4); if (S_ISDIR(ssb.st_mode)) /* could be depth_search */ { AddSlash(vbuff); strcat(vbuff, "."); } if (!MakeParentDirectory(vbuff, attr.move_obstructions, report_context)) { cfPS(cf_inform, CF_FAIL, "", pp, attr, "Can't make directories for %s in files.copyfrom promise\n", vbuff); return NULL; } if (S_ISDIR(ssb.st_mode)) /* could be depth_search */ { if (attr.copy.purge) { CfOut(cf_verbose, "", " !! (Destination purging enabled)\n"); } CfOut(cf_verbose, "", " ->> Entering %s\n", source); SetSearchDevice(&ssb, pp); SourceSearchAndCopy(source, destination, attr.recursion.depth, attr, pp, report_context); if (cfstat(destination, &dsb) != -1) { if (attr.copy.check_root) { VerifyCopiedFileAttributes(destination, &dsb, &ssb, attr, pp, report_context); } } } else { VerifyCopy(source, destination, attr, pp, report_context); } snprintf(eventname, CF_BUFSIZE - 1, "Copy(%s:%s > %s)", server, source, destination); EndMeasure(eventname, start); return NULL; }
void plFileUtils::ConcatFileName(char* path, const char* fileName) { AddSlash(path); strcat(path, fileName); }
int ConsiderFile(const char *nodename, char *path, Attributes attr, Promise *pp) { int i; struct stat statbuf; char vbuff[CF_BUFSIZE]; const char *sp; static char *skipfiles[] = { ".", "..", "lost+found", ".cfengine.rm", NULL }; if (strlen(nodename) < 1) { CfOut(cf_error, "", "Empty (null) filename detected in %s\n", path); return true; } if (IsItemIn(SUSPICIOUSLIST, nodename)) { struct stat statbuf; if (cfstat(nodename, &statbuf) != -1) { if (S_ISREG(statbuf.st_mode)) { CfOut(cf_error, "", "Suspicious file %s found in %s\n", nodename, path); return false; } } } if (strcmp(nodename, "...") == 0) { CfOut(cf_verbose, "", "Possible DFS/FS cell node detected in %s...\n", path); return true; } for (i = 0; skipfiles[i] != NULL; i++) { if (strcmp(nodename, skipfiles[i]) == 0) { CfDebug("Filename %s/%s is classified as ignorable\n", path, nodename); return false; } } if ((strcmp("[", nodename) == 0) && (strcmp("/usr/bin", path) == 0)) { if (VSYSTEMHARDCLASS == linuxx) { return true; } } for (sp = nodename; *sp != '\0'; sp++) { if ((*sp > 31) && (*sp < 127)) { break; } } strcpy(vbuff, path); AddSlash(vbuff); strcat(vbuff, nodename); for (sp = nodename; *sp != '\0'; sp++) /* Check for files like ".. ." */ { if ((*sp != '.') && !isspace(*sp)) { return true; } } if (cf_lstat(vbuff, &statbuf, attr, pp) == -1) { CfOut(cf_verbose, "lstat", "Couldn't stat %s", vbuff); return true; } if (statbuf.st_size == 0 && !(VERBOSE || INFORM)) /* No sense in warning about empty files */ { return false; } CfOut(cf_error, "", "Suspicious looking file object \"%s\" masquerading as hidden file in %s\n", nodename, path); CfDebug("Filename looks suspicious\n"); if (S_ISLNK(statbuf.st_mode)) { CfOut(cf_inform, "", " %s is a symbolic link\n", nodename); } else if (S_ISDIR(statbuf.st_mode)) { CfOut(cf_inform, "", " %s is a directory\n", nodename); } CfOut(cf_verbose, "", "[%s] has size %ld and full mode %o\n", nodename, (unsigned long) (statbuf.st_size), (unsigned int) (statbuf.st_mode)); return true; }
void RunBsp( char* command ) { char sys[2048]; char batpath[2048]; char outputpath[2048]; char temppath[1024]; char name[2048]; char cWork[2048]; FILE* hFile; BOOL ret; PROCESS_INFORMATION ProcessInformation; STARTUPINFO startupinfo; HWND hwndPClient = NULL; g_hWnd = g_pParentWnd->GetSafeHwnd(); SetInspectorMode( W_CONSOLE ); g_tBegin = CTime::GetCurrentTime(); DWORD dwExitcode; ret = GetExitCodeProcess( g_hToolThread, &dwExitcode ); if ( dwExitcode != STILL_ACTIVE ) g_hToolThread = NULL; if ( bsp_process || g_hToolThread ) { Sys_Printf( "BSP is still going...\n" ); return; } outputpath[0] = '\0'; GetTempPath( 512, temppath ); CString strOutFile = temppath; AddSlash( strOutFile ); strOutFile += "junk.txt"; sprintf( outputpath, " >>%s\r\n", strOutFile ); strcpy( name, currentmap ); if ( region_active ) { Map_SaveFile( name, false ); StripExtension( name ); strcat( name, ".reg" ); } Map_SaveFile( name, region_active ); // FIXME: this code just gets worse and worse CString strPath, strFile; char* rsh = ValueForKey( g_qeglobals.d_project_entity, "rshcmd" ); if ( rsh == NULL ) { ExtractPath_and_Filename( name, strPath, strFile ); AddSlash( strPath ); BuildShortPathName( strPath, cWork, 1024 ); strcat( cWork, strFile ); } else { strcpy( cWork, name ); } hwndPClient = FindWindow( NULL, "Q3Map Process Client" ); if ( hwndPClient == NULL ) { hwndPClient = FindAnyWindow( "Q3Map Process Client" ); } Sys_Printf( "Window info for Process Client %i\n", reinterpret_cast<int>( hwndPClient ) ); bool processServer = ( rsh && strlen( rsh ) > 0 && hwndPClient ); QE_ExpandBspString( command, sys, cWork, processServer ); // if we can find the q3map process server running // we will submit maps to it instead of via createprocess // if ( processServer ) { CString str; char cBuff[2048]; char* pStart = sys; char* pEnd = strstr( pStart, "&&" ); while ( pEnd ) { int nLen = pEnd - pStart - 1; strncpy( cBuff, pStart, nLen ); cBuff[nLen] = 0; str = cBuff; FindReplace( str, rsh, "" ); str.TrimLeft( ' ' ); str.TrimRight( ' ' ); ATOM a = GlobalAddAtom( str ); PostMessage( hwndPClient, wm_AddCommand, 0, ( LPARAM )a ); pStart = pEnd + 2; pEnd = strstr( pStart, "&&" ); } str = pStart; FindReplace( str, rsh, "" ); str.TrimLeft( ' ' ); str.TrimRight( ' ' ); ATOM a = GlobalAddAtom( str ); PostMessage( hwndPClient, wm_AddCommand, 0, ( LPARAM )a ); Sys_Printf( "Commands sent to Q3Map Process Client\n" ); return; } CString strSys = sys; FindReplace( strSys, "&&", outputpath ); strcpy( sys, strSys ); strcat( sys, outputpath ); Sys_ClearPrintf(); Sys_Printf( "==================\nRunning bsp command...\n" ); Sys_Printf( "\n%s\n", sys ); //++timo removed the old way BSP commands .. dumping to junk.txt doesn't work on my win98 box // FIXME : will most likely break Quake2 BSP commands, is fitted to a one-lined sys command // // write qe3bsp.bat // //const char *basePath = ValueForKey(g_qeglobals.d_project_entity, "basepath"); //if(basePath) { //const char *mapName = //sprintf(batpath,"%s/maps/%s.bat",basePath,mapName); strcpy( batpath, currentmap ); char* dot = strchr( batpath, '.' ); strcpy( dot, ".bat" ); //} else { // sprintf (batpath, "%sqe3bsp.bat", temppath); //} hFile = fopen( batpath, "w" ); if ( !hFile ) Error( "Can't write to %s", batpath ); fprintf( hFile, sys ); fclose( hFile ); Pointfile_Delete(); // delete junk.txt file remove( strOutFile ); GetStartupInfo( &startupinfo ); ret = CreateProcess( batpath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupinfo, &ProcessInformation ); if ( !ret ) Error( "CreateProcess failed" ); bsp_process = ProcessInformation.hProcess; Sleep( 100 ); // give the new process a chance to open it's window BringWindowToTop( g_qeglobals.d_hwndMain ); // pop us back on top #if 0 // // write qe3bsp.bat // sprintf( batpath, "%sqe3bsp.bat", temppath ); hFile = fopen( batpath, "w" ); if ( !hFile ) Error( "Can't write to %s", batpath ); fprintf( hFile, sys ); fclose( hFile ); // // write qe3bsp2.bat // sprintf( batpath, "%sqe3bsp2.bat", temppath ); hFile = fopen( batpath, "w" ); if ( !hFile ) Error( "Can't write to %s", batpath ); fprintf( hFile, "%sqe3bsp.bat > %s", temppath, outputpath ); fclose( hFile ); Pointfile_Delete(); GetStartupInfo( &startupinfo ); ret = CreateProcess( batpath, // pointer to name of executable module NULL, // pointer to command line string NULL, // pointer to process security attributes NULL, // pointer to thread security attributes FALSE, // handle inheritance flag 0 /*DETACHED_PROCESS*/, // creation flags NULL, // pointer to new environment block NULL, // pointer to current directory name &startupinfo, // pointer to STARTUPINFO &ProcessInformation // pointer to PROCESS_INFORMATION ); if ( !ret ) Error( "CreateProcess failed" ); bsp_process = ProcessInformation.hProcess; Sleep( 100 ); // give the new process a chance to open it's window //BringWindowToTop( g_qeglobals.d_hwndMain ); // pop us back on top //SetFocus (g_qeglobals.d_hwndCamera); #endif }
int main(int argc, char* argv[]) { // Basic syntax checking for "-x name" format while ((argc > 2) && (argv[1][0] == '-') && (argv[1][1] != '\x00') && (argv[1][2] == '\x00') && (argv[2][0] != '\x00') && (argv[2][0] != '-')) { switch (argv[1][1]) { case 's': --argc; ++argv; pSourceDirectory = argv[1]; break; } ++argv; --argc; } if (pSourceDirectory == NULL) { printf("\nWrong Arguments given !\n"); PrintUsage(); return 1; } printf("\nXBMC-XML2PO v0.96 by Team XBMC\n"); ProjRootDir = pSourceDirectory; ProjRootDir = AddSlash(ProjRootDir); if ((FileExist(ProjRootDir + "addon.xml")) && (FileExist(ProjRootDir + "resources" + DirSepChar + "language" + DirSepChar + "English" + DirSepChar + "strings.xml"))) projType = ADDON; else if ((FileExist(ProjRootDir + "addon.xml")) && (FileExist(ProjRootDir + "language" + DirSepChar + "English" + DirSepChar + "strings.xml"))) projType = SKIN; else if (FileExist(ProjRootDir + "addon.xml")) projType = ADDON_NOSTRINGS; else if (FileExist(ProjRootDir + "xbmc" + DirSepChar + "GUIInfoManager.h")) projType = CORE; else projType = UNKNOWN; std::string strprojType; switch (projType) { case ADDON: strprojType = "Addon with translatable strings"; WorkingDir = ProjRootDir + DirSepChar + "resources" + DirSepChar + "language"+ DirSepChar; break; case SKIN: strprojType = "Skin addon"; WorkingDir = ProjRootDir + DirSepChar + "language"+ DirSepChar; break; case ADDON_NOSTRINGS: strprojType = "Addon without any translatable strings"; break; case CORE: strprojType = "XBMC core"; WorkingDir = ProjRootDir + DirSepChar + "language" + DirSepChar; break; default: strprojType = "Unknown"; WorkingDir = ProjRootDir; break; } if (projType == ADDON || projType == ADDON_NOSTRINGS || projType == SKIN) loadAddonXMLFile(ProjRootDir + "addon.xml"); else if (projType == CORE) { ProjTextName = "XBMC Core"; ProjProvider = "Team XBMC"; ProjName = "xbmc.core"; LoadCoreVersion(ProjRootDir + "xbmc" + DirSepChar + "GUIInfoManager.h"); } printf ("Project type detected:\t%s\n", strprojType.c_str()); printf ("\nProject name:\t\t%s\n", ProjTextName.c_str()); printf ("Project id:\t\t%s\n", ProjName.c_str()); printf ("Project version:\t%s\n", ProjVersion.c_str()); printf ("Project provider:\t%s\n", ProjProvider.c_str()); if (projType == ADDON_NOSTRINGS) { if (!DirExists(ProjRootDir + "resources") && (!MakeDir(ProjRootDir + "resources"))) { printf ("fatal error: not able to create resources directory at dir: %s", ProjRootDir.c_str()); return 1; } if (!DirExists(ProjRootDir + "resources" + DirSepChar + "language") && (!MakeDir(ProjRootDir + "resources"+ DirSepChar + "language"))) { printf ("fatal error: not able to create language directory at dir: %s", (ProjRootDir + "resources").c_str()); return 1; } WorkingDir = ProjRootDir + "resources"+ DirSepChar + "language" + DirSepChar; for (itAddonXMLData = mapAddonXMLData.begin(); itAddonXMLData != mapAddonXMLData.end(); itAddonXMLData++) { if (!DirExists(WorkingDir + FindLang(itAddonXMLData->first)) && (!MakeDir(WorkingDir + FindLang(itAddonXMLData->first)))) { printf ("fatal error: not able to create %s language directory at dir: %s", itAddonXMLData->first.c_str(), WorkingDir.c_str()); return 1; } } } if (projType !=ADDON_NOSTRINGS && !loadXMLFile(xmlDocSourceInput, WorkingDir + "English" + DirSepChar + "strings.xml", &mapSourceXmlId, true)) { printf("Fatal error: no English source xml file found or it is corrupted\n"); return 1; } printf("\nResults:\n\n"); printf("Langcode\tString match\tOutput file\n"); printf("--------------------------------------------------------------\n"); ConvertXML2PO(WorkingDir + "English" + DirSepChar, "en", 2, "(n != 1)", false); DIR* Dir; struct dirent *DirEntry; Dir = opendir(WorkingDir.c_str()); int langcounter =0; std::map<std::string, CLangData> mapLangList; std::map<std::string, CLangData>::iterator itmapLangList; while((DirEntry=readdir(Dir))) { if (DirEntry->d_type == DT_DIR && DirEntry->d_name[0] != '.' && strcmp(DirEntry->d_name, "English")) { CLangData Langdat; Langdat.LLangCode = FindLangCode(DirEntry->d_name); Langdat.LPlurals = GetnPlurals(DirEntry->d_name); Langdat.LPlurForm = GetPlurForm(DirEntry->d_name); mapLangList [DirEntry->d_name] = Langdat; } } for (itmapLangList = mapLangList.begin(); itmapLangList != mapLangList.end(); itmapLangList++) { bool bRunConvert = false;; if (projType == ADDON_NOSTRINGS || projType == ADDON || projType == SKIN) bRunConvert = true; if ((projType != ADDON_NOSTRINGS && loadXMLFile(xmlDocForeignInput, WorkingDir + itmapLangList->first + DirSepChar + "strings.xml", &mapForeignXmlId, false)) || bRunConvert) { ConvertXML2PO(WorkingDir + itmapLangList->first + DirSepChar, itmapLangList->second.LLangCode, itmapLangList->second.LPlurals, itmapLangList->second.LPlurForm, true); langcounter++; } } printf("\nReady. Processed %i languages.\n", langcounter+1); if (bUnknownLangFound) printf("\nWarning: At least one language found with unpaired language code !\n" "Please edit the .po file manually and correct the language code, plurals !\n" "Also please report this to [email protected] if possible !\n\n"); return 0; }
int CompressPath(char *dest, const char *src) { char node[CF_BUFSIZE]; int nodelen; int rootlen; CfDebug("CompressPath(%s,%s)\n", dest, src); memset(dest, 0, CF_BUFSIZE); rootlen = RootDirLength(src); strncpy(dest, src, rootlen); for (const char *sp = src + rootlen; *sp != '\0'; sp++) { if (IsFileSep(*sp)) { continue; } for (nodelen = 0; (sp[nodelen] != '\0') && (!IsFileSep(sp[nodelen])); nodelen++) { if (nodelen > CF_MAXLINKSIZE) { Log(LOG_LEVEL_ERR, "Link in path suspiciously large"); return false; } } strncpy(node, sp, nodelen); node[nodelen] = '\0'; sp += nodelen - 1; if (strcmp(node, ".") == 0) { continue; } if (strcmp(node, "..") == 0) { if (!ChopLastNode(dest)) { CfDebug("cfengine: used .. beyond top of filesystem!\n"); return false; } continue; } else { AddSlash(dest); } if (!JoinPath(dest, node)) { return false; } } return true; }
void AssignModel() { #ifdef QUAKE3 if (strASSIGNMODEL.GetLength()) { SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"model"); SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM) ((LPCSTR)strASSIGNMODEL));//.GetBuffer(0)); strASSIGNMODEL=""; gEntityToSetBoundsOf = edit_entity; AddProp(); edit_entity->md3Class = NULL; g_pParentWnd->GetXYWnd()->SetFocus(); //----------- #if 1 // brush is currently built at 0 angle, now fake a rotate away and back to fill inthe mins/maxs fields... // SetKeyValue(edit_entity, "angle", "0", false); // tell it that it has no angle, and don't rebuild SetFocus (g_qeglobals.d_hwndCamera); SetKeyValuePairs (); SetKeyValue(edit_entity, "angle", "90", true); // true = rebuild brush, rotate to some other angle SetFocus (g_qeglobals.d_hwndCamera); SetKeyValuePairs (); SetKeyValue(edit_entity, "angle", "0", true); // true = rebuild brush, rotate back to 0 SetFocus (g_qeglobals.d_hwndCamera); SetKeyValuePairs (); #endif //----------- } else #endif { CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath"); AddSlash(strBasePath); CString strPath = strBasePath; strPath += "models\\mapobjects\\"; CFileDialog dlgFile(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT, "Model files (*.md3)|*.md3||", g_pParentWnd); dlgFile.m_ofn.lpstrInitialDir = strPath; if (dlgFile.DoModal() == IDOK) { SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"model"); CString str = dlgFile.GetPathName().GetBuffer(0); str.MakeLower(); strBasePath.MakeLower(); QE_ConvertDOSToUnixName(str.GetBuffer(0), str.GetBuffer(0)); QE_ConvertDOSToUnixName(strBasePath.GetBuffer(0), strBasePath.GetBuffer(0)); int n = str.Find(strBasePath); if (n == 0) { str = str.Right(str.GetLength() - strBasePath.GetLength()); } SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)str.GetBuffer(0)); gEntityToSetBoundsOf = edit_entity; AddProp(); edit_entity->md3Class = NULL; g_pParentWnd->GetXYWnd()->SetFocus(); } } }
int CheckForModule(char *actiontxt,char *args) { struct stat statbuf; char line[CF_BUFSIZE],command[CF_EXPANDSIZE],name[CF_MAXVARSIZE],content[CF_BUFSIZE],ebuff[CF_EXPANDSIZE],*sp; FILE *pp; int print; if (NOMODULES) { return false; } if (*actiontxt == '/') { snprintf(OUTPUT,CF_BUFSIZE,"Absolute module path (%s) should be named relative to the authorized module directory",actiontxt); CfLog(cferror,OUTPUT,""); } if (GetMacroValue(CONTEXTID,"moduledirectory")) { ExpandVarstring("$(moduledirectory)",ebuff,NULL); } else { snprintf(ebuff,CF_BUFSIZE,"%s/modules",VLOCKDIR); } AddSlash(ebuff); strcat(ebuff,actiontxt); if (stat(ebuff,&statbuf) == -1) { snprintf(OUTPUT,CF_BUFSIZE*2,"(Plug-in %s not found)",ebuff); Banner(OUTPUT); return false; } if ((statbuf.st_uid != 0) && (statbuf.st_uid != getuid())) { snprintf(OUTPUT,CF_BUFSIZE*2,"Module %s was not owned by uid=%d executing cfagent\n",ebuff,getuid()); CfLog(cferror,OUTPUT,""); return false; } snprintf(OUTPUT,CF_BUFSIZE*2,"Plug-in `%s\'",actiontxt); Banner(OUTPUT); strcat(ebuff," "); if (BufferOverflow(ebuff,args)) { snprintf(OUTPUT,CF_BUFSIZE*2,"Culprit: class list for module (shouldn't happen)\n" ); CfLog(cferror,OUTPUT,""); return false; } strcat(ebuff,args); ExpandVarstring(ebuff,command,NULL); Verbose("Exec module [%s]\n",command); if ((pp = cfpopen(command,"r")) == NULL) { snprintf(OUTPUT,CF_BUFSIZE*2,"Couldn't open pipe from %s\n",actiontxt); CfLog(cferror,OUTPUT,"cfpopen"); return false; } while (!feof(pp)) { if (ferror(pp)) /* abortable */ { snprintf(OUTPUT,CF_BUFSIZE*2,"Shell command pipe %s\n",actiontxt); CfLog(cferror,OUTPUT,"ferror"); break; } ReadLine(line,CF_BUFSIZE,pp); if (strlen(line) > CF_BUFSIZE - 80) { snprintf(OUTPUT,CF_BUFSIZE*2,"Line from module %s is too long to be sensible\n",actiontxt); CfLog(cferror,OUTPUT,""); break; } if (ferror(pp)) /* abortable */ { snprintf(OUTPUT,CF_BUFSIZE*2,"Shell command pipe %s\n",actiontxt); CfLog(cferror,OUTPUT,"ferror"); break; } print = false; for (sp = line; *sp != '\0'; sp++) { if (! isspace((int)*sp)) { print = true; break; } } switch (*line) { case '+': Verbose("Activated classes: %s\n",line+1); CheckClass(line+1,command); AddMultipleClasses(line+1); break; case '-': Verbose("Deactivated classes: %s\n",line+1); CheckClass(line+1,command); NegateCompoundClass(line+1,&VNEGHEAP); break; case '=': content[0] = '\0'; sscanf(line+1,"%[^=]=%[^\n]",name,content); Verbose("Defined Macro: %s, Value: %s\n",name,content); AddMacroValue(CONTEXTID,name,content); break; default: if (print) { snprintf(OUTPUT,CF_BUFSIZE,"%s: %s\n",actiontxt,line); CfLog(cferror,OUTPUT,""); } } } cfpclose(pp); return true; }
int SensibleFile(char *nodename,char *path,struct Image *ip) { int i, suspicious = true; struct stat statbuf; unsigned char *sp, newname[CF_BUFSIZE],vbuff[CF_BUFSIZE]; if (strlen(nodename) < 1) { snprintf(OUTPUT,CF_BUFSIZE,"Empty (null) filename detected in %s\n",path); CfLog(cferror,OUTPUT,""); return true; } if (IsItemIn(SUSPICIOUSLIST,nodename)) { struct stat statbuf; if (stat(nodename,&statbuf) != -1) { if (S_ISREG(statbuf.st_mode)) { snprintf(OUTPUT,CF_BUFSIZE,"Suspicious file %s found in %s\n",nodename,path); CfLog(cferror,OUTPUT,""); return false; } } } if (strcmp(nodename,"...") == 0) { Verbose("Possible DFS/FS cell node detected in %s...\n",path); return true; } for (i = 0; VSKIPFILES[i] != NULL; i++) { if (strcmp(nodename,VSKIPFILES[i]) == 0) { Debug("Filename %s/%s is classified as ignorable\n",path,nodename); return false; } } if ((strcmp("[",nodename) == 0) && (strcmp("/usr/bin",path) == 0)) { if (VSYSTEMHARDCLASS == linuxx) { return true; } } suspicious = true; for (sp = nodename; *sp != '\0'; sp++) { if ((*sp > 31) && (*sp < 127)) { suspicious = false; break; } } strcpy(vbuff,path); AddSlash(vbuff); strcat(vbuff,nodename); if (suspicious && NONALPHAFILES) { snprintf(OUTPUT,CF_BUFSIZE,"Suspicious filename %s in %s has no alphanumeric content (security)",CanonifyName(nodename),path); CfLog(cfsilent,OUTPUT,""); strcpy(newname,vbuff); for (sp = newname+strlen(path); *sp != '\0'; sp++) { if ((*sp > 126) || (*sp < 33)) { *sp = 50 + (*sp / 50); /* Create a visible ASCII interpretation */ } } strcat(newname,".cf-nonalpha"); snprintf(OUTPUT,CF_BUFSIZE,"Renaming file %s to %s",vbuff,newname); CfLog(cfsilent,OUTPUT,""); if (rename(vbuff,newname) == -1) { CfLog(cfverbose,"Rename failed - foreign filesystem?\n","rename"); } if (chmod(newname,0644) == -1) { CfLog(cfverbose,"Mode change failed - foreign filesystem?\n","chmod"); } return false; } if (strstr(nodename,".") && (EXTENSIONLIST != NULL)) { if (cflstat(vbuff,&statbuf,ip) == -1) { snprintf(OUTPUT,CF_BUFSIZE,"Couldn't examine %s - foreign filesystem?\n",vbuff); CfLog(cfverbose,OUTPUT,"lstat"); return true; } if (S_ISDIR(statbuf.st_mode)) { if (strcmp(nodename,"...") == 0) { Verbose("Hidden directory ... found in %s\n",path); return true; } for (sp = nodename+strlen(nodename)-1; *sp != '.'; sp--) { } if ((char *)sp != nodename) /* Don't get .dir */ { sp++; /* Find file extension, look for known plain files */ if ((strlen(sp) > 0) && IsItemIn(EXTENSIONLIST,sp)) { snprintf(OUTPUT,CF_BUFSIZE,"Suspicious directory %s in %s looks like plain file with extension .%s",nodename,path,sp); CfLog(cfsilent,OUTPUT,""); return false; } } } } for (sp = nodename; *sp != '\0'; sp++) /* Check for files like ".. ." */ { if ((*sp != '.') && ! isspace(*sp)) { suspicious = false; return true; } } /* removed if (EXTENSIONLIST==NULL) mb */ if (cflstat(vbuff,&statbuf,ip) == -1) { snprintf(OUTPUT,CF_BUFSIZE,"Couldn't stat %s",vbuff); CfLog(cfverbose,OUTPUT,"lstat"); return true; } if (statbuf.st_size == 0 && ! (VERBOSE||INFORM)) /* No sense in warning about empty files */ { return false; } snprintf(OUTPUT,CF_BUFSIZE,"Suspicious looking file object \"%s\" masquerading as hidden file in %s\n",nodename,path); CfLog(cfsilent,OUTPUT,""); Debug("Filename looks suspicious\n"); if (S_ISLNK(statbuf.st_mode)) { snprintf(OUTPUT,CF_BUFSIZE," %s is a symbolic link\n",nodename); CfLog(cfsilent,OUTPUT,""); } else if (S_ISDIR(statbuf.st_mode)) { snprintf(OUTPUT,CF_BUFSIZE," %s is a directory\n",nodename); CfLog(cfsilent,OUTPUT,""); } snprintf(OUTPUT,CF_BUFSIZE,"[%s] has size %ld and full mode %o\n",nodename,(unsigned long)(statbuf.st_size),(unsigned int)(statbuf.st_mode)); CfLog(cfsilent,OUTPUT,""); return true; }
void CPrefsDlg::LoadPrefs() { CString strBuff; CString strPrefab = g_strAppPath; AddSlash(strPrefab); strPrefab += "Prefabs\\"; m_nMouse = AfxGetApp()->GetProfileInt(PREF_SECTION, MOUSE_KEY, MOUSE_DEF); if (m_nMouse == 0) m_nMouseButtons = 2; else m_nMouseButtons = 3; m_nView = AfxGetApp()->GetProfileInt(PREF_SECTION, WINDOW_KEY, WINDOW_DEF); m_strQuake2 = AfxGetApp()->GetProfileString(PREF_SECTION, Q2_KEY, Q2_DEF); m_bRunQuake = AfxGetApp()->GetProfileInt(PREF_SECTION, RUNQ2_KEY, RUNQ2_DEF); m_bTextureLock = AfxGetApp()->GetProfileInt(PREF_SECTION, TLOCK_KEY, TLOCK_DEF); m_bRotateLock = AfxGetApp()->GetProfileInt(PREF_SECTION, RLOCK_KEY, TLOCK_DEF); m_strLastProject = AfxGetApp()->GetProfileString(PREF_SECTION, LASTPROJ_KEY, ""); m_strLastMap = AfxGetApp()->GetProfileString(PREF_SECTION, LASTMAP_KEY, ""); m_bLoadLast = AfxGetApp()->GetProfileInt(PREF_SECTION, LOADLAST_KEY, LOADLAST_DEF); m_bRunBefore = AfxGetApp()->GetProfileInt(INTERNAL_SECTION, RUN_KEY, RUN_DEF); //m_b3Dfx = AfxGetApp()->GetProfileInt(PREF_SECTION, _3DFX_KEY, 0); m_bFace = AfxGetApp()->GetProfileInt(PREF_SECTION, FACE_KEY, 1); m_bInternalBSP = AfxGetApp()->GetProfileInt(PREF_SECTION, BSP_KEY, 1); m_bRightClick = AfxGetApp()->GetProfileInt(PREF_SECTION, RCLICK_KEY, 1); m_bVertex = AfxGetApp()->GetProfileInt(PREF_SECTION, VERTEX_KEY, 1); m_bAutoSave = AfxGetApp()->GetProfileInt(PREF_SECTION, AUTOSAVE_KEY, 1); m_bPAK = AfxGetApp()->GetProfileInt(PREF_SECTION, PAK_KEY, 1); m_bNewApplyHandling = AfxGetApp()->GetProfileInt(PREF_SECTION, NEWAPPLY_KEY, 0); m_bLoadLastMap = AfxGetApp()->GetProfileInt(PREF_SECTION, LOADLASTMAP_KEY, 0); m_bGatewayHack = AfxGetApp()->GetProfileInt(PREF_SECTION, HACK_KEY, 0); m_bTextureWindow = AfxGetApp()->GetProfileInt(PREF_SECTION, TEXTURE_KEY, 1); m_bCleanTiny = AfxGetApp()->GetProfileInt(PREF_SECTION, TINYBRUSH_KEY, 0); strBuff = AfxGetApp()->GetProfileString(PREF_SECTION, TINYSIZE_KEY, "0.5"); m_fTinySize = atof(strBuff); m_nAutoSave = AfxGetApp()->GetProfileInt(PREF_SECTION, AUTOSAVETIME_KEY, 5); m_strAutoSave.Format("%i", m_nAutoSave); m_bSnapShots = AfxGetApp()->GetProfileInt(PREF_SECTION, SNAPSHOT_KEY, 1); m_numSnapShots = AfxGetApp()->GetProfileInt(PREF_SECTION, NUMSNAPSHOT_KEY, 10); m_strPAKFile = AfxGetApp()->GetProfileString(PREF_SECTION, PAKFILE_KEY, PAKFILE_DEF); m_nStatusSize = AfxGetApp()->GetProfileInt(PREF_SECTION, STATUS_KEY, 10); m_nMoveSpeed = AfxGetApp()->GetProfileInt(PREF_SECTION, MOVESPEED_KEY, 400); m_nAngleSpeed = AfxGetApp()->GetProfileInt(PREF_SECTION, ANGLESPEED_KEY, 300); m_bSetGame = AfxGetApp()->GetProfileInt(PREF_SECTION, SETGAME_KEY, 0); m_bCamXYUpdate = AfxGetApp()->GetProfileInt(PREF_SECTION, CAMXYUPDATE_KEY, 1); m_bNewLightDraw = AfxGetApp()->GetProfileInt(PREF_SECTION, LIGHTDRAW_KEY, 1); m_bCubicClipping = AfxGetApp()->GetProfileInt(PREF_SECTION, CUBICCLIP_KEY, 1); m_nCubicScale = AfxGetApp()->GetProfileInt(PREF_SECTION, CUBICSCALE_KEY, 13); m_bALTEdge = AfxGetApp()->GetProfileInt(PREF_SECTION, ALTEDGE_KEY, 0); m_bTextureBar = AfxGetApp()->GetProfileInt(PREF_SECTION, TEXTUREBAR_KEY, 0); m_strWhatGame = AfxGetApp()->GetProfileString(PREF_SECTION, WHATGAME_KEY, "Quake3"); m_bFaceColors = AfxGetApp()->GetProfileInt(PREF_SECTION, FACECOLORS_KEY, 0); m_bQE4Painting = AfxGetApp()->GetProfileInt(PREF_SECTION, QE4PAINT_KEY, 1); m_bSnapTToGrid = AfxGetApp()->GetProfileInt(PREF_SECTION, SNAPT_KEY, 0); m_bXZVis = AfxGetApp()->GetProfileInt(PREF_SECTION, XZVIS_KEY, 0); m_bYZVis = AfxGetApp()->GetProfileInt(PREF_SECTION, YZVIS_KEY, 0); m_bZVis = AfxGetApp()->GetProfileInt(PREF_SECTION, ZVIS_KEY, 1); m_bSizePaint = AfxGetApp()->GetProfileInt(PREF_SECTION, SIZEPAINT_KEY, 0); m_bDLLEntities = AfxGetApp()->GetProfileInt(PREF_SECTION, DLLENTITIES_KEY, 0); m_bWideToolbar = AfxGetApp()->GetProfileInt(PREF_SECTION, WIDETOOLBAR_KEY, 0); m_bNoClamp = AfxGetApp()->GetProfileInt(PREF_SECTION, NOCLAMP_KEY, 0); m_strPrefabPath = AfxGetApp()->GetProfileString(PREF_SECTION, PREFAB_KEY, strPrefab); m_strUserPath = AfxGetApp()->GetProfileString(PREF_SECTION, USERINI_KEY, ""); m_nRotation = AfxGetApp()->GetProfileInt(PREF_SECTION, ROTATION_KEY, 45); m_bSGIOpenGL = AfxGetApp()->GetProfileInt(PREF_SECTION, SGIOPENGL_KEY, 0); m_bBuggyICD = AfxGetApp()->GetProfileInt(PREF_SECTION, BUGGYICD_KEY, 0); m_bHiColorTextures = AfxGetApp()->GetProfileInt(PREF_SECTION, HICOLOR_KEY, 1); m_bChaseMouse = AfxGetApp()->GetProfileInt(PREF_SECTION, CHASEMOUSE_KEY, 1); m_nEntityShowState = AfxGetApp()->GetProfileInt(PREF_SECTION, ENTITYSHOW_KEY, 0); m_nTextureScale = AfxGetApp()->GetProfileInt(PREF_SECTION, TEXTURESCALE_KEY, 50); m_bTextureScrollbar = AfxGetApp()->GetProfileInt(PREF_SECTION, TEXTURESCROLLBAR_KEY, TRUE); m_bDisplayLists = AfxGetApp()->GetProfileInt(PREF_SECTION, DISPLAYLISTS_KEY, TRUE); m_bUseShaders = AfxGetApp()->GetProfileInt(PREF_SECTION, SHADERS_KEY, FALSE); m_bSwitchClip = AfxGetApp()->GetProfileInt(PREF_SECTION, SWITCHCLIP_KEY, TRUE); m_bSelectWholeEntities = AfxGetApp()->GetProfileInt(PREF_SECTION, SELWHOLEENTS_KEY, TRUE); m_nTextureQuality = AfxGetApp()->GetProfileInt(PREF_SECTION, TEXTUREQUALITY_KEY, 6); m_bShowShaders = AfxGetApp()->GetProfileInt(PREF_SECTION, SHOWSHADERS_KEY, TRUE); m_bShaderTest = AfxGetApp()->GetProfileInt(PREF_SECTION, SHADERTEST_KEY, TRUE); if (m_bRunBefore == FALSE) { SetGamePrefs(); } }
/* =========== QE_LoadProject FIXME: the BuildShortPathName calls should be removed, it would get much more cleaner I don't have time to modify something so deep in the system, but this lead to a bug when loading .md3 see Win_ent.cpp AssignModel =========== */ qboolean QE_LoadProject (char *projectfile) { char *data; Sys_Printf ("QE_LoadProject (%s)\n", projectfile); if ( LoadFileNoCrash (projectfile, (void **)&data) == -1) return false; g_strProject = projectfile; CString strData = data; free(data); CString strQ2Path = g_PrefsDlg.m_strQuake2; CString strQ2File; ExtractPath_and_Filename(g_PrefsDlg.m_strQuake2, strQ2Path, strQ2File); AddSlash(strQ2Path); char* pBuff = new char[1024]; //BuildShortPathName(strQ2Path, pBuff, 1024); strcpy_s(pBuff, 1024,strQ2Path); // Jonathan: strcpy_s replaces BuildShortPathName FindReplace(strData, "__Q2PATH", pBuff); //BuildShortPathName(g_strAppPath, pBuff, 1024); strcpy_s(pBuff, 1024,g_strAppPath); // Jonathan: strcpy_s replaces BuildShortPathName FindReplace(strData, "__QERPATH", pBuff); char* pFile; if (GetFullPathName(projectfile, 1024, pBuff, &pFile)) { g_PrefsDlg.m_strLastProject = pBuff; //BuildShortPathName(g_PrefsDlg.m_strLastProject, pBuff, 1024); g_PrefsDlg.m_strLastProject = pBuff; g_PrefsDlg.SavePrefs(); ExtractPath_and_Filename(pBuff, strQ2Path, strQ2File); int nLen = strQ2Path.GetLength(); if (nLen > 0) { if (strQ2Path[nLen - 1] == '\\') strQ2Path.SetAt(nLen-1,'\0'); char* pBuffer = strQ2Path.GetBufferSetLength(_MAX_PATH + 1); int n = strQ2Path.ReverseFind('\\'); if (n >=0 ) pBuffer[n + 1] = '\0'; strQ2Path.ReleaseBuffer(); FindReplace(strData, "__QEPROJPATH", strQ2Path); } } StartTokenParsing (strData.GetBuffer(0)); g_qeglobals.d_project_entity = Entity_Parse (true); if (!g_qeglobals.d_project_entity) Error ("Couldn't parse project file: %s", projectfile); // add a version checking to avoid people loading later versions of the project file and bitching against me int ver = IntForKey( g_qeglobals.d_project_entity, "version" ); if (ver != 0) { char strMsg[1024]; sprintf( strMsg, "This is a version %d project file. This build only supports <=0 project files.\n" "Please choose another project file or upgrade your version of Radiant.", ver ); MessageBox( NULL, strMsg, "Can't load project file", MB_ICONERROR | MB_OK ); return false; } for (int i = 0; i < g_nPathFixupCount; i++) { char *pPath = ValueForKey (g_qeglobals.d_project_entity, g_pPathFixups[i]); if (pPath[0] != '\\' && pPath[0] != '/') { if (GetFullPathName(pPath, 1024, pBuff, &pFile)) { SetKeyValue(g_qeglobals.d_project_entity, g_pPathFixups[i], pBuff); } } } delete []pBuff; // set here some default project settings you need if ( strlen( ValueForKey( g_qeglobals.d_project_entity, "brush_primit" ) ) == 0 ) { SetKeyValue( g_qeglobals.d_project_entity, "brush_primit", "0" ); } g_qeglobals.m_bBrushPrimitMode = IntForKey( g_qeglobals.d_project_entity, "brush_primit" ); // usefull for the log file and debuggin f****d up configurations from users: // output the basic information of the .qe4 project file Sys_Printf("basepath : %s\n", ValueForKey( g_qeglobals.d_project_entity, "basepath") ); Sys_Printf("mapspath : %s\n", ValueForKey( g_qeglobals.d_project_entity, "mapspath") ); // the rsh command code is probably broken in these builds .. I would need ppl that actually use it .. // Sys_Printf("rshcmd : %s\n", ValueForKey( g_qeglobals.d_project_entity, "rshcmd" ) ); // Sys_Printf("remotebasepath : %s\n", ValueForKey( g_qeglobals.d_project_entity, "remotebasepath" ) ); Sys_Printf("entitypath : %s\n", ValueForKey( g_qeglobals.d_project_entity, "entitypath" ) ); Sys_Printf("texturepath : %s\n", ValueForKey( g_qeglobals.d_project_entity, "texturepath" ) ); Eclass_InitForSourceDirectory (ValueForKey (g_qeglobals.d_project_entity, "entitypath")); FillClassList(); // list in entity window Map_New(); FillTextureMenu(); FillBSPMenu(); return true; }
int FS_ReadFile( const char *qpath, void **buffer ) { CString strPath = ValueForKey(g_qeglobals.d_project_entity, "basepath"); AddSlash(strPath); strPath += qpath; return LoadFile(strPath, buffer); }
void QE_InitVFS( void ){ // VFS initialization ----------------------- // we will call vfsInitDirectory, giving the directories to look in (for files in pk3's and for standalone files) // we need to call in order, the mod ones first, then the base ones .. they will be searched in this order // *nix systems have a dual filesystem in ~/.q3a, which is searched first .. so we need to add that too Str directory,prefabs; // TTimo: let's leave this to HL mode for now if ( g_pGameDescription->mGameFile == "hl.game" ) { // Hydra: we search the "gametools" path first so that we can provide editor // specific pk3's wads and misc files for use by the editor. // the relevant map compiler tools will NOT use this directory, so this helps // to ensure that editor files are not used/required in release versions of maps // it also helps keep your editor files all in once place, with the editor modules, // plugins, scripts and config files. // it also helps when testing maps, as you'll know your files won't/can't be used // by the game engine itself. // <gametools> directory = g_pGameDescription->mGameToolsPath; vfsInitDirectory( directory.GetBuffer() ); } // NOTE TTimo about the mymkdir calls .. this is a bit dirty, but a safe thing on *nix // if we have a mod dir if ( *ValueForKey( g_qeglobals.d_project_entity, "gamename" ) != '\0' ) { #if defined ( __linux__ ) || defined ( __APPLE__ ) // ~/.<gameprefix>/<fs_game> directory = g_qeglobals.m_strHomeGame.GetBuffer(); Q_mkdir( directory.GetBuffer(), 0775 ); directory += ValueForKey( g_qeglobals.d_project_entity, "gamename" ); Q_mkdir( directory.GetBuffer(), 0775 ); vfsInitDirectory( directory.GetBuffer() ); AddSlash( directory ); prefabs = directory; // also create the maps dir, it will be used as prompt for load/save directory += "/maps"; Q_mkdir( directory, 0775 ); // and the prefabs dir prefabs += "/prefabs"; Q_mkdir( prefabs, 0775 ); #endif // <fs_basepath>/<fs_game> directory = g_pGameDescription->mEnginePath; directory += ValueForKey( g_qeglobals.d_project_entity, "gamename" ); Q_mkdir( directory.GetBuffer(), 0775 ); vfsInitDirectory( directory.GetBuffer() ); AddSlash( directory ); prefabs = directory; // also create the maps dir, it will be used as prompt for load/save directory += "/maps"; Q_mkdir( directory.GetBuffer(), 0775 ); // and the prefabs dir prefabs += "/prefabs"; Q_mkdir( prefabs, 0775 ); } #if defined ( __linux__ ) || defined ( __APPLE__ ) // ~/.<gameprefix>/<fs_main> directory = g_qeglobals.m_strHomeGame.GetBuffer(); directory += g_pGameDescription->mBaseGame; vfsInitDirectory( directory.GetBuffer() ); #endif // <fs_basepath>/<fs_main> directory = g_pGameDescription->mEnginePath; directory += g_pGameDescription->mBaseGame; vfsInitDirectory( directory.GetBuffer() ); }
int CompressPath(char *dest,char *src) { char *sp; char node[CF_BUFSIZE]; int nodelen; int rootlen; Debug2("CompressPath(%s,%s)\n",dest,src); memset(dest,0,CF_BUFSIZE); rootlen = RootDirLength(src); strncpy(dest,src,rootlen); for (sp = src+rootlen; *sp != '\0'; sp++) { if (IsFileSep(*sp)) { continue; } for (nodelen = 0; sp[nodelen] != '\0' && !IsFileSep(sp[nodelen]); nodelen++) { if (nodelen > CF_MAXLINKSIZE) { CfLog(cferror,"Link in path suspiciously large",""); return false; } } strncpy(node, sp, nodelen); node[nodelen] = '\0'; sp += nodelen - 1; if (strcmp(node,".") == 0) { continue; } if (strcmp(node,"..") == 0) { if (!ChopLastNode(dest)) { Debug("cfengine: used .. beyond top of filesystem!\n"); return false; } continue; } else { AddSlash(dest); } if (BufferOverflow(dest,node)) { return false; } strcat(dest,node); } return true; }
int PakLoadAnyFile(const char *filename, void **bufferptr) { char cWork[WORK_LEN]; if (g_bPK3) { PK3FileInfo *pInfo; Str strKey; // need to lookup the file without the base/texture path on it Str strBase(g_strBasePath); AddSlash(strBase); __ConvertDOSToUnixName(cWork, strBase); Str strFile(filename); __ConvertDOSToUnixName(strFile, strFile); strFile.MakeLower(); strlwr(cWork); FindReplace(strFile, cWork, ""); PK3FileInfo infoFind; infoFind.m_pName = __StrDup(strFile.GetBuffer()); PK3List *pList = g_PK3Files.Find(&infoFind); if (pList) { pInfo = pList->Ptr(); memcpy(pInfo->m_zFile, &pInfo->m_zInfo, sizeof(unz_s)); if (unzOpenCurrentFile(pInfo->m_zFile) == UNZ_OK) { void *buffer = __qblockmalloc(pInfo->m_lSize+1); int n = unzReadCurrentFile(pInfo->m_zFile , buffer, pInfo->m_lSize); *bufferptr = buffer; unzCloseCurrentFile(pInfo->m_zFile); return n; } } #ifdef LOG_PAKFAIL sprintf(cWork, "PAK failed on %s\n", filename); g_LogFile.Log(cWork); #endif return -1; } for (int i = 0; i < dirsize; i++) { if(!stricmp(filename, pakdirptr[i].name)) { if (fseek(pakfile[m_nPAKIndex], pakdirptr[i].offset, SEEK_SET) >= 0) { void *buffer = __qmalloc (pakdirptr[i].size+1); ((char *)buffer)[pakdirptr[i].size] = 0; if (fread(buffer, 1, pakdirptr[i].size, pakfile[m_nPAKIndex]) == pakdirptr[i].size) { *bufferptr = buffer; return pakdirptr[i].size; } } } } #ifdef LOG_PAKFAIL sprintf(cWork, "PAK failed on %s\n", filename); g_LogFile.Log(cWork); #endif return -1; }
int ExpandLinks(char *dest, char *from, int level) { char *sp, buff[CF_BUFSIZE]; char node[CF_MAXLINKSIZE]; struct stat statbuf; int lastnode = false; memset(dest,0,CF_BUFSIZE); Debug2("ExpandLinks(%s,%d)\n",from,level); if (level >= CF_MAXLINKLEVEL) { CfLog(cferror, "Too many levels of symbolic links to evaluate " "absolute path\n",""); return false; } for (sp = from; *sp != '\0'; sp++) { if (*sp == '/') { continue; } sscanf(sp,"%[^/]",node); sp += strlen(node); if (*sp == '\0') { lastnode = true; } if (strcmp(node,".") == 0) { continue; } if (strcmp(node,"..") == 0) { if (! ChopLastNode(g_linkto)) { Debug("cfagent: used .. beyond top of filesystem!\n"); return false; } continue; } else { strcat(dest,"/"); } strcat(dest,node); /* File doesn't exist so we can stop here */ if (lstat(dest,&statbuf) == -1) { snprintf(g_output, CF_BUFSIZE*2, "Can't stat %s in ExpandLinks\n", dest); CfLog(cferror,g_output,"stat"); return false; } if (S_ISLNK(statbuf.st_mode)) { memset(buff,0,CF_BUFSIZE); if (readlink(dest,buff,CF_BUFSIZE-1) == -1) { snprintf(g_output, CF_BUFSIZE*2, "Expand links can't stat %s\n", dest); CfLog(cferror,g_output,"readlink"); return false; } else { if (buff[0] == '.') { ChopLastNode(dest); AddSlash(dest); if (BufferOverflow(dest,buff)) { return false; } strcat(dest,buff); } else if (buff[0] == '/') { strcpy(dest,buff); DeleteSlash(dest); if (strcmp(dest,from) == 0) { Debug2("No links to be expanded\n"); return true; } if (!lastnode && !ExpandLinks(buff,dest,level+1)) { return false; } } else { ChopLastNode(dest); AddSlash(dest); strcat(dest,buff); DeleteSlash(dest); if (strcmp(dest,from) == 0) { Debug2("No links to be expanded\n"); return true; } memset(buff,0,CF_BUFSIZE); if (!lastnode && !ExpandLinks(buff,dest,level+1)) { return false; } } } } } return true; }
void CheckBspProcess( void ) { char outputpath[1024]; char temppath[512]; DWORD exitcode; char* out; BOOL ret; if ( !bsp_process ) return; ret = GetExitCodeProcess( bsp_process, &exitcode ); if ( !ret ) Error( "GetExitCodeProcess failed" ); if ( exitcode == STILL_ACTIVE ) return; bsp_process = 0; GetTempPath( 512, temppath ); sprintf( outputpath, "%sjunk.txt", temppath ); LoadFile( outputpath, ( void** )&out ); Sys_Printf( "%s", out ); Sys_Printf( "\ncompleted.\n" ); free( out ); CTime tEnd = CTime::GetCurrentTime(); CTimeSpan tElapsed = tEnd - g_tBegin; CString strElapsed; strElapsed.Format( "Run time was %i hours, %i minutes and %i seconds", tElapsed.GetHours(), tElapsed.GetMinutes(), tElapsed.GetSeconds() ); Sys_Printf( strElapsed.GetBuffer( 0 ) ); Sys_Beep(); Pointfile_Check(); // run game if no PointFile and pref is set //++timo needs to stop after BSP if leaked .. does run through vis and light instead .. if ( g_PrefsDlg.m_bRunQuake == TRUE && !g_qeglobals.d_pointfile_display_list ) { char cCurDir[1024]; GetCurrentDirectory( 1024, cCurDir ); CString strExePath = "../../qio.exe"; //= g_PrefsDlg.m_strQuake2; CString strOrgPath; CString strOrgFile; ExtractPath_and_Filename( currentmap, strOrgPath, strOrgFile ); if ( g_PrefsDlg.m_bSetGame == TRUE ) // run in place with set game.. don't copy map { CString strBasePath = ValueForKey( g_qeglobals.d_project_entity, "basepath" ); strExePath += " +set game "; strExePath += strBasePath; WinExec( strExePath, SW_SHOW ); } else { CString strCopyPath = strExePath; char* pBuffer = strCopyPath.GetBufferSetLength( _MAX_PATH + 1 ); pBuffer[strCopyPath.ReverseFind( '\\' ) + 1] = '\0'; strCopyPath.ReleaseBuffer(); SetCurrentDirectory( strCopyPath ); CString strOrgPath; CString strOrgFile; ExtractPath_and_Filename( currentmap, strOrgPath, strOrgFile ); AddSlash( strCopyPath ); FindReplace( strOrgFile, ".map", ".bsp" ); //++timo modified for Quake3 !! strCopyPath += "baseq3\\maps\\"; strCopyPath += strOrgFile; AddSlash( strOrgPath ); strOrgPath += strOrgFile; bool bRun = ( strOrgPath.CompareNoCase( strCopyPath ) == 0 ); if ( !bRun ) bRun = ( CopyFile( strOrgPath, strCopyPath, FALSE ) == TRUE ); if ( bRun ) { FindReplace( strOrgFile, ".bsp", "" ); strExePath += " +map "; strExePath += strOrgFile; WinExec( strExePath, SW_SHOW ); } } SetCurrentDirectory( cCurDir ); } }
void LinkChildren(char *path,char type,struct stat *rootstat,uid_t uid,gid_t gid, struct Item *inclusions,struct Item *exclusions,struct Item *copy, short nofile,struct Link *ptr) { char *sp; char lastlink[CF_BUFSIZE],server[CF_BUFSIZE]; char from[CF_BUFSIZE],to[CF_BUFSIZE]; char relpath[CF_BUFSIZE]; char odir[CF_BUFSIZE]; DIR *dirh; struct dirent *dirp; struct stat statbuf; int matched = false; int (*linkfiles)(char *from, char *to, struct Item *inclusions, struct Item *exclusions, struct Item *copy, short int nofile, struct Link *ptr); Debug("LinkChildren(%s)\n",path); if (! S_ISDIR(rootstat->st_mode)) { snprintf(g_output,CF_BUFSIZE*2, "File %s is not a directory: it has no children to link!\n", path); CfLog(cferror,g_output,""); return; } Verbose("Linking the children of %s\n",path); for (sp = path+strlen(path); sp != path-1; sp--) { if (*(sp-1) == '/') { relpath[0] = '\0'; sscanf(sp,"%[^/]%s", lastlink,relpath); if (MatchAFileSystem(server,lastlink)) { strcpy(odir,server); if (BufferOverflow(odir,relpath)) { FatalError("culprit: LinkChildren()"); } strcat(odir,relpath); if ((dirh = opendir(odir)) == NULL) { snprintf(g_output,CF_BUFSIZE*2, "Can't open directory %s\n",path); CfLog(cferror,g_output,"opendir"); return; } for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) { if (!SensibleFile(dirp->d_name,odir,NULL)) { continue; } strcpy(from,path); AddSlash(from); if (BufferOverflow(from,dirp->d_name)) { FatalError("culprit: LinkChildren()"); } strcat(from,dirp->d_name); strcpy(to,odir); AddSlash(to); if (BufferOverflow(to,dirp->d_name)) { FatalError("culprit: LinkChildren()"); } strcat(to,dirp->d_name); Debug2("LinkChild from = %s to = %s\n",from,to); if (stat(to,&statbuf) == -1) { continue; } else { switch (type) { case 's': linkfiles = LinkFiles; break; case 'r': linkfiles = RelativeLink; break; case 'a': linkfiles = AbsoluteLink; break; case 'h': linkfiles = HardLinkFiles; break; default: snprintf(g_output,CF_BUFSIZE*2, "Internal error, link type was [%c]\n",type); CfLog(cferror,g_output,""); continue; } matched = (*linkfiles)(from,to,inclusions, exclusions,copy,nofile,ptr); if (matched && !g_dontdo) { chown(from,uid,gid); } } } if (matched) return; } } } snprintf(g_output,CF_BUFSIZE*2, "Couldn't link the children of %s to anything because no\n",path); CfLog(cferror,g_output,""); snprintf(g_output, CF_BUFSIZE*2, "file system was found to " "mirror it in the defined binservers list.\n"); CfLog(cferror,g_output,""); }
/** * @TODO fix the dangerous path lengths */ int CompressPath(char *dest, const char *src) { char node[CF_BUFSIZE]; int nodelen; int rootlen; memset(dest, 0, CF_BUFSIZE); rootlen = RootDirLength(src); memcpy(dest, src, rootlen); for (const char *sp = src + rootlen; *sp != '\0'; sp++) { if (IsFileSep(*sp)) { continue; } for (nodelen = 0; (sp[nodelen] != '\0') && (!IsFileSep(sp[nodelen])); nodelen++) { if (nodelen > CF_MAXLINKSIZE) { Log(LOG_LEVEL_ERR, "Link in path suspiciously large"); return false; } } strncpy(node, sp, nodelen); node[nodelen] = '\0'; sp += nodelen - 1; if (strcmp(node, ".") == 0) { continue; } if (strcmp(node, "..") == 0) { if (!ChopLastNode(dest)) { Log(LOG_LEVEL_DEBUG, "used .. beyond top of filesystem!"); return false; } continue; } AddSlash(dest); /* TODO use dest_size parameter instead of CF_BUFSIZE. */ size_t ret = strlcat(dest, node, CF_BUFSIZE); if (ret >= CF_BUFSIZE) { Log(LOG_LEVEL_ERR, "Internal limit reached in CompressPath()," " path too long: '%s' + '%s'", dest, node); return false; } } return true; }
int RecursiveLink(struct Link *lp,char *from,char *to,int maxrecurse) { struct stat statbuf; DIR *dirh; struct dirent *dirp; char newfrom[CF_BUFSIZE]; char newto[CF_BUFSIZE]; void *bug_check; int (*linkfiles)(char *from, char *to, struct Item *inclusions, struct Item *exclusions, struct Item *copy, short int nofile, struct Link *ptr); /* reached depth limit */ if (maxrecurse == 0) { Debug2("MAXRECURSE ran out, quitting at level %s with " "endlist = %d\n", to, lp->next); return false; } if (IgnoreFile(to,"",lp->ignores)) { Verbose("%s: Ignoring directory %s\n",g_vprefix,from); return false; } /* Check for root dir */ if (strlen(to) == 0) { to = "/"; } bug_check = lp->next; if ((dirh = opendir(to)) == NULL) { snprintf(g_output,CF_BUFSIZE*2,"Can't open directory [%s]\n",to); CfLog(cferror,g_output,"opendir"); return false; } if (lp->next != bug_check) { printf("%s: solaris BSD compat bug: opendir wrecked " "the heap memory!!", g_vprefix); printf("%s: in copy to %s, using workaround...\n",g_vprefix,from); lp->next = bug_check; } for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) { if (!SensibleFile(dirp->d_name,to,NULL)) { continue; } if (IgnoreFile(to,dirp->d_name,lp->ignores)) { continue; } /* Assemble pathname */ strcpy(newfrom,from); AddSlash(newfrom); strcpy(newto,to); AddSlash(newto); if (BufferOverflow(newfrom,dirp->d_name)) { closedir(dirh); return true; } strcat(newfrom,dirp->d_name); if (BufferOverflow(newto,dirp->d_name)) { closedir(dirh); return true; } strcat(newto,dirp->d_name); if (g_travlinks) { if (stat(newto,&statbuf) == -1) { snprintf(g_output,CF_BUFSIZE*2,"Can't stat %s\n",newto); CfLog(cfverbose,g_output,""); continue; } } else { if (lstat(newto,&statbuf) == -1) { snprintf(g_output,CF_BUFSIZE*2,"Can't stat %s\n",newto); CfLog(cfverbose,g_output,""); memset(g_vbuff,0,CF_BUFSIZE); if (readlink(newto,g_vbuff,CF_BUFSIZE-1) != -1) { Verbose("File is link to -> %s\n",g_vbuff); } continue; } } if (!FileObjectFilter(newto,&statbuf,lp->filters,links)) { Debug("Skipping filtered file %s\n",newto); continue; } if (S_ISDIR(statbuf.st_mode)) { RecursiveLink(lp,newfrom,newto,maxrecurse-1); } else { switch (lp->type) { case 's': linkfiles = LinkFiles; break; case 'r': linkfiles = RelativeLink; break; case 'a': linkfiles = AbsoluteLink; break; case 'h': linkfiles = HardLinkFiles; break; default: printf("cfagent: internal error, link type was [%c]\n",lp->type); continue; } (*linkfiles)(newfrom,newto,lp->inclusions,lp->exclusions, lp->copy,lp->nofile,lp); } } closedir(dirh); return true; }
void plFileUtils::ConcatFileName(wchar_t* path, const wchar_t* fileName) { AddSlash(path); wcscat(path, fileName); }
int LinkChildFiles(char *from,char *to,char type, struct Item *inclusions, struct Item *exclusions, struct Item *copy, short nofile, struct Link *ptr) { DIR *dirh; struct dirent *dirp; char pcwdto[CF_BUFSIZE],pcwdfrom[CF_BUFSIZE]; struct stat statbuf; int (*linkfiles)(char *from, char *to, struct Item *inclusions, struct Item *exclusions, struct Item *copy, short int nofile, struct Link *ptr); Debug("LinkChildFiles(%s,%s)\n",from,to); if (stat(to,&statbuf) == -1) { /* no error warning, since the higher level routine uses this */ return(false); } if ((dirh = opendir(to)) == NULL) { snprintf(g_output,CF_BUFSIZE*2,"Can't open directory %s\n",to); CfLog(cferror,g_output,"opendir"); return false; } for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) { if (!SensibleFile(dirp->d_name,to,NULL)) { continue; } /* Assemble pathnames */ strcpy(pcwdto,to); AddSlash(pcwdto); if (BufferOverflow(pcwdto,dirp->d_name)) { FatalError("Can't build filename in LinkChildFiles"); } strcat(pcwdto,dirp->d_name); strcpy(pcwdfrom,from); AddSlash(pcwdfrom); if (BufferOverflow(pcwdfrom,dirp->d_name)) { FatalError("Can't build filename in LinkChildFiles"); } strcat(pcwdfrom,dirp->d_name); switch (type) { case 's': linkfiles = LinkFiles; break; case 'r': linkfiles = RelativeLink; break; case 'a': linkfiles = AbsoluteLink; break; case 'h': linkfiles = HardLinkFiles; break; default: printf("Internal error, link type was [%c]\n",type); continue; } (*linkfiles)(pcwdfrom,pcwdto,inclusions,exclusions,copy,nofile,ptr); } closedir(dirh); return true; }
void LocateFilePromiserGroup(EvalContext *ctx, char *wildpath, Promise *pp, void (*fnptr) (EvalContext *ctx, char *path, Promise *ptr)) { Item *path, *ip, *remainder = NULL; char pbuffer[CF_BUFSIZE]; struct stat statbuf; int count = 0, lastnode = false, expandregex = false; uid_t agentuid = getuid(); int create = PromiseGetConstraintAsBoolean(ctx, "create", pp); char *pathtype = ConstraintGetRvalValue(ctx, "pathtype", pp, RVAL_TYPE_SCALAR); /* Do a search for promiser objects matching wildpath */ if ((!IsPathRegex(wildpath)) || (pathtype && (strcmp(pathtype, "literal") == 0))) { Log(LOG_LEVEL_VERBOSE, "Using literal pathtype for '%s'", wildpath); (*fnptr) (ctx, wildpath, pp); return; } else { Log(LOG_LEVEL_VERBOSE, "Using regex pathtype for '%s' (see pathtype)", wildpath); } pbuffer[0] = '\0'; path = SplitString(wildpath, '/'); // require forward slash in regex on all platforms for (ip = path; ip != NULL; ip = ip->next) { if ((ip->name == NULL) || (strlen(ip->name) == 0)) { continue; } if (ip->next == NULL) { lastnode = true; } /* No need to chdir as in recursive descent, since we know about the path here */ if (IsRegex(ip->name)) { remainder = ip->next; expandregex = true; break; } else { expandregex = false; } if (!JoinPath(pbuffer, ip->name)) { Log(LOG_LEVEL_ERR, "Buffer has limited size in LocateFilePromiserGroup"); return; } if (stat(pbuffer, &statbuf) != -1) { if ((S_ISDIR(statbuf.st_mode)) && ((statbuf.st_uid) != agentuid) && ((statbuf.st_uid) != 0)) { Log(LOG_LEVEL_INFO, "Directory '%s' in search path '%s' is controlled by another user (uid %ju) - trusting its content is potentially risky (possible race condition)", pbuffer, wildpath, (uintmax_t)statbuf.st_uid); PromiseRef(LOG_LEVEL_INFO, pp); } } } if (expandregex) /* Expand one regex link and hand down */ { char nextbuffer[CF_BUFSIZE], nextbufferOrig[CF_BUFSIZE], regex[CF_BUFSIZE]; const struct dirent *dirp; Dir *dirh; memset(regex, 0, CF_BUFSIZE); strncpy(regex, ip->name, CF_BUFSIZE - 1); if ((dirh = DirOpen(pbuffer)) == NULL) { // Could be a dummy directory to be created so this is not an error. Log(LOG_LEVEL_VERBOSE, "Using best-effort expanded (but non-existent) file base path '%s'", wildpath); (*fnptr) (ctx, wildpath, pp); DeleteItemList(path); return; } else { count = 0; for (dirp = DirRead(dirh); dirp != NULL; dirp = DirRead(dirh)) { if (!ConsiderLocalFile(dirp->d_name, pbuffer)) { continue; } if ((!lastnode) && (!S_ISDIR(statbuf.st_mode))) { Log(LOG_LEVEL_DEBUG, "Skipping non-directory '%s'", dirp->d_name); continue; } if (FullTextMatch(regex, dirp->d_name)) { Log(LOG_LEVEL_DEBUG, "Link '%s' matched regex '%s'", dirp->d_name, regex); } else { continue; } count++; strncpy(nextbuffer, pbuffer, CF_BUFSIZE - 1); AddSlash(nextbuffer); strcat(nextbuffer, dirp->d_name); for (ip = remainder; ip != NULL; ip = ip->next) { AddSlash(nextbuffer); strcat(nextbuffer, ip->name); } /* The next level might still contain regexs, so go again as long as expansion is not nullpotent */ if ((!lastnode) && (strcmp(nextbuffer, wildpath) != 0)) { LocateFilePromiserGroup(ctx, nextbuffer, pp, fnptr); } else { Promise *pcopy; Log(LOG_LEVEL_VERBOSE, "Using expanded file base path '%s'", nextbuffer); /* Now need to recompute any back references to get the complete path */ snprintf(nextbufferOrig, sizeof(nextbufferOrig), "%s", nextbuffer); MapNameForward(nextbuffer); if (!FullTextMatch(pp->promiser, nextbuffer)) { Log(LOG_LEVEL_DEBUG, "Error recomputing references for '%s' in '%s'", pp->promiser, nextbuffer); } /* If there were back references there could still be match.x vars to expand */ pcopy = ExpandDeRefPromise(ctx, ScopeGetCurrent()->scope, pp); (*fnptr) (ctx, nextbufferOrig, pcopy); PromiseDestroy(pcopy); } } DirClose(dirh); } } else { Log(LOG_LEVEL_VERBOSE, "Using file base path '%s'", pbuffer); (*fnptr) (ctx, pbuffer, pp); } if (count == 0) { Log(LOG_LEVEL_VERBOSE, "No promiser file objects matched as regular expression '%s'", wildpath); if (create) { (*fnptr)(ctx, pp->promiser, pp); } } DeleteItemList(path); }
int ExpandLinks(char *dest, const char *from, int level) { char buff[CF_BUFSIZE]; char node[CF_MAXLINKSIZE]; struct stat statbuf; int lastnode = false; memset(dest, 0, CF_BUFSIZE); if (level >= CF_MAXLINKLEVEL) { Log(LOG_LEVEL_ERR, "Too many levels of symbolic links to evaluate absolute path"); return false; } const char *sp = from; while (*sp != '\0') { if (*sp == FILE_SEPARATOR) { sp++; continue; } sscanf(sp, "%[^/]", node); sp += strlen(node); if (*sp == '\0') { lastnode = true; } if (strcmp(node, ".") == 0) { continue; } if (strcmp(node, "..") == 0) { continue; } else { strcat(dest, "/"); } strcat(dest, node); if (lstat(dest, &statbuf) == -1) /* File doesn't exist so we can stop here */ { Log(LOG_LEVEL_ERR, "Can't stat '%s' in ExpandLinks. (lstat: %s)", dest, GetErrorStr()); return false; } if (S_ISLNK(statbuf.st_mode)) { memset(buff, 0, CF_BUFSIZE); if (readlink(dest, buff, CF_BUFSIZE - 1) == -1) { Log(LOG_LEVEL_ERR, "Expand links can't stat '%s'. (readlink: %s)", dest, GetErrorStr()); return false; } else { if (buff[0] == '.') { ChopLastNode(dest); AddSlash(dest); /* TODO pass and use parameter dest_size. */ size_t ret = strlcat(dest, buff, CF_BUFSIZE); if (ret >= CF_BUFSIZE) { Log(LOG_LEVEL_ERR, "Internal limit reached in ExpandLinks()," " path too long: '%s' + '%s'", dest, buff); return false; } } else if (IsAbsoluteFileName(buff)) { strcpy(dest, buff); DeleteSlash(dest); if (strcmp(dest, from) == 0) { Log(LOG_LEVEL_DEBUG, "No links to be expanded"); return true; } if ((!lastnode) && (!ExpandLinks(buff, dest, level + 1))) { return false; } } else { ChopLastNode(dest); AddSlash(dest); /* TODO use param dest_size. */ size_t ret = strlcat(dest, buff, CF_BUFSIZE); if (ret >= CF_BUFSIZE) { Log(LOG_LEVEL_ERR, "Internal limit reached in ExpandLinks end," " path too long: '%s' + '%s'", dest, buff); return false; } DeleteSlash(dest); if (strcmp(dest, from) == 0) { Log(LOG_LEVEL_DEBUG, "No links to be expanded"); return true; } memset(buff, 0, CF_BUFSIZE); if ((!lastnode) && (!ExpandLinks(buff, dest, level + 1))) { return false; } } } } } return true; }
int DoRecursiveEditFiles(char *name,int level,struct Edit *ptr,struct stat *sb) { DIR *dirh; struct dirent *dirp; char pcwd[CF_BUFSIZE]; struct stat statbuf; int goback; if (level == -1) { return false; } Debug("RecursiveEditFiles(%s)\n",name); if (!DirPush(name,sb)) { return false; } if ((dirh = opendir(".")) == NULL) { return true; } for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) { if (!SensibleFile(dirp->d_name,name,NULL)) { continue; } if (IgnoreFile(name,dirp->d_name,ptr->ignores)) { continue; } strcpy(pcwd,name); /* Assemble pathname */ AddSlash(pcwd); if (BufferOverflow(pcwd,dirp->d_name)) { return true; } strcat(pcwd,dirp->d_name); if (!FileObjectFilter(pcwd,&statbuf,ptr->filters,editfiles)) { Verbose("Skipping filtered file %s\n",pcwd); continue; } if (TRAVLINKS) { if (lstat(dirp->d_name,&statbuf) == -1) { snprintf(OUTPUT,CF_BUFSIZE*2,"Can't stat %s\n",pcwd); CfLog(cferror,OUTPUT,"stat"); continue; } if (S_ISLNK(statbuf.st_mode) && (statbuf.st_mode != getuid())) { snprintf(OUTPUT,CF_BUFSIZE,"File %s is an untrusted link. cfagent will not follow it with a destructive operation (tidy)",pcwd); continue; } if (stat(dirp->d_name,&statbuf) == -1) { snprintf(OUTPUT,CF_BUFSIZE*2,"RecursiveCheck was working on %s when this happened:\n",pcwd); CfLog(cferror,OUTPUT,"stat"); continue; } } else { if (lstat(dirp->d_name,&statbuf) == -1) { snprintf(OUTPUT,CF_BUFSIZE*2,"RecursiveCheck was working in %s when this happened:\n",pcwd); CfLog(cferror,OUTPUT,"lstat"); continue; } } if (S_ISDIR(statbuf.st_mode)) { if (IsMountedFileSystem(&statbuf,pcwd,level)) { continue; } else { if ((ptr->recurse > 1) || (ptr->recurse == CF_INF_RECURSE)) { goback = DoRecursiveEditFiles(pcwd,level-1,ptr,&statbuf); DirPop(goback,name,sb); } else { WrapDoEditFile(ptr,pcwd); } } } else { WrapDoEditFile(ptr,pcwd); } } closedir(dirh); return true; }
void Map_Snapshot(){ CString strMsg; // I hope the modified flag is kept correctly up to date if ( !modified ) { return; } // we need to do the following // 1. make sure the snapshot directory exists (create it if it doesn't) // 2. find out what the lastest save is based on number // 3. inc that and save the map CString strOrgPath, strOrgFile; ExtractPath_and_Filename( currentmap, strOrgPath, strOrgFile ); AddSlash( strOrgPath ); strOrgPath += "snapshots"; bool bGo = true; struct stat Stat; if ( stat( strOrgPath, &Stat ) == -1 ) { #ifdef _WIN32 bGo = ( _mkdir( strOrgPath ) != -1 ); #endif #if defined ( __linux__ ) || defined ( __APPLE__ ) bGo = ( mkdir( strOrgPath,0755 ) != -1 ); #endif } AddSlash( strOrgPath ); if ( bGo ) { int nCount = 0; long lSize = 0; CString strNewPath; strNewPath = strOrgPath; strNewPath += strOrgFile; // QB - snapshots now follow the format: <mapname>.<snapnum>.<ext> // **NOTE** atm snapshots must end with a .map (or .xmap) ext (this is why they were broken) CString strOldEXT = "map"; //default to .map const char* type = strrchr( strOrgFile.GetBuffer(),'.' ); if ( type != NULL ) { strOldEXT = ++type; }; // get the ext for later. StripExtension(strNewPath); // then strip it from the new path // CString strFile; while ( bGo ) { char buf[PATH_MAX]; //sprintf( buf, "%s.%i", strNewPath.GetBuffer(), nCount ); // snapshot will now end with a known ext. sprintf( buf, "%s.%i.%s", strNewPath.GetBuffer(), nCount, strOldEXT.GetBuffer() ); strFile = buf; bGo = DoesFileExist( strFile, lSize ); nCount++; } // strFile has the next available slot Map_SaveFile( strFile, false ); // it is still a modified map (we enter this only if this is a modified map) Sys_SetTitle( currentmap ); Sys_MarkMapModified(); if ( lSize > 12 * 1024 * 1024 ) { // total size of saves > 4 mb Sys_Printf( "The snapshot files in %s total more than 4 megabytes. You might consider cleaning up.", strOrgPath.GetBuffer() ); } } else { strMsg.Format( "Snapshot save failed.. unabled to create directory\n%s", strOrgPath.GetBuffer() ); gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg ); } strOrgPath = ""; strOrgFile = ""; }
void CPrefsDlg::LoadPrefs() { CString strBuff; CString strPrefab = g_strAppPath; AddSlash(strPrefab); strPrefab += "Prefabs\\"; m_nMouseButtons = 3; m_bTextureLock = GetCvarInt( TLOCK_KEY, TLOCK_DEF ); m_bRotateLock = GetCvarInt( RLOCK_KEY, TLOCK_DEF ); m_strLastProject = GetCvarString( LASTPROJ_KEY, "" ); m_strLastMap = GetCvarString( LASTMAP_KEY, "" ); m_bLoadLast = GetCvarInt( LOADLAST_KEY, LOADLAST_DEF ); m_bRunBefore = GetCvarInt( RUN_KEY, RUN_DEF ); m_bFace = GetCvarInt( FACE_KEY, 1 ); m_bRightClick = GetCvarInt( RCLICK_KEY, 1 ); m_bVertex = GetCvarInt( VERTEX_KEY, 1 ); m_bAutoSave = GetCvarInt( AUTOSAVE_KEY, 1 ); m_bNewApplyHandling = GetCvarInt( NEWAPPLY_KEY, 0 ); m_bLoadLastMap = GetCvarInt( LOADLASTMAP_KEY, 0 ); m_bGatewayHack = GetCvarInt( HACK_KEY, 0 ); m_bTextureWindow = GetCvarInt( TEXTURE_KEY, 0 ); m_bCleanTiny = GetCvarInt( TINYBRUSH_KEY, 0 ); strBuff = GetCvarString( TINYSIZE_KEY, "0.5" ); m_fTinySize = atof(strBuff ); m_nAutoSave = GetCvarInt( AUTOSAVETIME_KEY, 5 ); if ( m_nAutoSave <= 0 ) { m_nAutoSave = 1; } m_strAutoSave.Format("%i", m_nAutoSave ); m_bSnapShots = GetCvarInt( SNAPSHOT_KEY, 0 ); m_nStatusSize = GetCvarInt( STATUS_KEY, 10 ); m_nMoveSpeed = GetCvarInt( MOVESPEED_KEY, 400 ); m_nAngleSpeed = GetCvarInt( ANGLESPEED_KEY, 300 ); m_bCamXYUpdate = GetCvarInt( CAMXYUPDATE_KEY, 1 ); m_bNewLightDraw = GetCvarInt( LIGHTDRAW_KEY, 1 ); m_bCubicClipping = ( GetCvarInt( CUBICCLIP_KEY, 1) != 0 ); m_nCubicScale = GetCvarInt( CUBICSCALE_KEY, 13 ); m_bALTEdge = GetCvarInt( ALTEDGE_KEY, 0 ); m_bQE4Painting = GetCvarInt( QE4PAINT_KEY, 1 ); m_bSnapTToGrid = GetCvarInt( SNAPT_KEY, 0 ); m_bXZVis = GetCvarInt( XZVIS_KEY, 0 ); m_bYZVis = GetCvarInt( YZVIS_KEY, 0 ); m_bZVis = GetCvarInt( ZVIS_KEY, 1 ); m_bSizePaint = GetCvarInt( SIZEPAINT_KEY, 0 ); m_bWideToolbar = GetCvarInt( WIDETOOLBAR_KEY, 1 ); m_bNoClamp = GetCvarInt( NOCLAMP_KEY, 0 ); m_nRotation = GetCvarInt( ROTATION_KEY, 45 ); m_bHiColorTextures = GetCvarInt( HICOLOR_KEY, 1 ); m_bChaseMouse = GetCvarInt( CHASEMOUSE_KEY, 1 ); m_nEntityShowState = GetCvarInt( ENTITYSHOW_KEY, 0 ); m_nTextureScale = GetCvarInt( TEXTURESCALE_KEY, 50 ); m_bTextureScrollbar = GetCvarInt( TEXTURESCROLLBAR_KEY, TRUE ); m_bDisplayLists = GetCvarInt( DISPLAYLISTS_KEY, TRUE ); m_bSwitchClip = GetCvarInt( SWITCHCLIP_KEY, TRUE ); m_bSelectWholeEntities = GetCvarInt( SELWHOLEENTS_KEY, TRUE ); m_nTextureQuality = GetCvarInt( TEXTUREQUALITY_KEY, 6 ); m_bGLLighting = GetCvarInt( GLLIGHTING_KEY, FALSE ); m_bNoStipple = GetCvarInt( NOSTIPPLE_KEY, 0 ); m_nUndoLevels = GetCvarInt( UNDOLEVELS_KEY, 63 ); m_strMaps = GetCvarString( MAPS_KEY, "" ); m_strModels = GetCvarString( MODELS_KEY, "" ); m_bNoStipple = GetCvarInt( NEWMAPFORMAT_KEY, 1 ); if ( m_bRunBefore == FALSE ) { SetGamePrefs(); } }
// reads all pak files from a dir void InitDirectory(const char* directory, ArchiveModules& archiveModules) { int j; g_numForbiddenDirs = 0; StringTokeniser st(GlobalRadiant().getGameDescriptionKeyValue("forbidden_paths"), " "); for(j = 0; j < VFS_MAXDIRS; ++j) { const char *t = st.getToken(); if(string_empty(t)) break; strncpy(g_strForbiddenDirs[g_numForbiddenDirs], t, PATH_MAX); g_strForbiddenDirs[g_numForbiddenDirs][PATH_MAX] = '\0'; ++g_numForbiddenDirs; } for(j = 0; j < g_numForbiddenDirs; ++j) { char* dbuf = g_strdup(directory); if(*dbuf && dbuf[strlen(dbuf)-1] == '/') dbuf[strlen(dbuf)-1] = 0; const char *p = strrchr(dbuf, '/'); p = (p ? (p+1) : dbuf); if(matchpattern(p, g_strForbiddenDirs[j], TRUE)) { g_free(dbuf); break; } g_free(dbuf); } if(j < g_numForbiddenDirs) { printf("Directory %s matched by forbidden dirs, removed\n", directory); return; } if (g_numDirs == VFS_MAXDIRS) return; strncpy(g_strDirs[g_numDirs], directory, PATH_MAX); g_strDirs[g_numDirs][PATH_MAX] = '\0'; FixDOSName (g_strDirs[g_numDirs]); AddSlash (g_strDirs[g_numDirs]); const char* path = g_strDirs[g_numDirs]; g_numDirs++; { archive_entry_t entry; entry.name = path; entry.archive = OpenArchive(path); entry.is_pakfile = false; g_archives.push_back(entry); } if (g_bUsePak) { GDir* dir = g_dir_open (path, 0, 0); if (dir != 0) { globalOutputStream() << "vfs directory: " << path << "\n"; const char* ignore_prefix = ""; const char* override_prefix = ""; { // See if we are in "sp" or "mp" mapping mode const char* gamemode = gamemode_get(); if (strcmp (gamemode, "sp") == 0) { ignore_prefix = "mp_"; override_prefix = "sp_"; } else if (strcmp (gamemode, "mp") == 0) { ignore_prefix = "sp_"; override_prefix = "mp_"; } } Archives archives; Archives archivesOverride; for(;;) { const char* name = g_dir_read_name(dir); if(name == 0) break; for(j = 0; j < g_numForbiddenDirs; ++j) { const char *p = strrchr(name, '/'); p = (p ? (p+1) : name); if(matchpattern(p, g_strForbiddenDirs[j], TRUE)) break; } if(j < g_numForbiddenDirs) continue; const char *ext = strrchr (name, '.'); if(ext && !string_compare_nocase_upper(ext, ".pk3dir")) { if (g_numDirs == VFS_MAXDIRS) continue; snprintf(g_strDirs[g_numDirs], PATH_MAX, "%s%s/", path, name); g_strDirs[g_numDirs][PATH_MAX] = '\0'; FixDOSName (g_strDirs[g_numDirs]); AddSlash (g_strDirs[g_numDirs]); g_numDirs++; { archive_entry_t entry; entry.name = g_strDirs[g_numDirs-1]; entry.archive = OpenArchive(g_strDirs[g_numDirs-1]); entry.is_pakfile = false; g_archives.push_back(entry); } } if ((ext == 0) || *(++ext) == '\0' || GetArchiveTable(archiveModules, ext) == 0) continue; // using the same kludge as in engine to ensure consistency if(!string_empty(ignore_prefix) && strncmp(name, ignore_prefix, strlen(ignore_prefix)) == 0) { continue; } if(!string_empty(override_prefix) && strncmp(name, override_prefix, strlen(override_prefix)) == 0) { archivesOverride.insert(name); continue; } archives.insert(name); } g_dir_close (dir); // add the entries to the vfs for(Archives::iterator i = archivesOverride.begin(); i != archivesOverride.end(); ++i) { char filename[PATH_MAX]; strcpy(filename, path); strcat(filename, (*i).c_str()); InitPakFile(archiveModules, filename); } for(Archives::iterator i = archives.begin(); i != archives.end(); ++i) { char filename[PATH_MAX]; strcpy(filename, path); strcat(filename, (*i).c_str()); InitPakFile(archiveModules, filename); } } else { globalErrorStream() << "vfs directory not found: " << path << "\n"; } } }