bool CCourse::LoadCourseList () { CSPList list (128); if (!list.Load (param.common_course_dir, "courses.lst")) { Message ("could not load courses.lst"); return false; } CSPList paramlist (48); CourseList.resize(list.Count()); for (size_t i=0; i<list.Count(); i++) { const string& line1 = list.Line(i); CourseList[i].name = SPStrN (line1, "name", "noname"); CourseList[i].dir = SPStrN (line1, "dir", "nodir"); string desc = SPStrN (line1, "desc", ""); FT.AutoSizeN (2); vector<string> desclist = FT.MakeLineList (desc.c_str(), 335 * Winsys.scale - 16.0); size_t cnt = desclist.size(); if (cnt > MAX_DESCRIPTION_LINES) cnt = MAX_DESCRIPTION_LINES; CourseList[i].num_lines = cnt; for (size_t ll=0; ll<cnt; ll++) { CourseList[i].desc[ll] = desclist[ll]; } string coursepath = param.common_course_dir + SEP + CourseList[i].dir; if (DirExists (coursepath.c_str())) { // preview string previewfile = coursepath + SEP + "preview.png"; CourseList[i].preview = new TTexture(); if (!CourseList[i].preview->LoadMipmap(previewfile, 0)) { Message ("couldn't load previewfile"); // texid = Tex.TexID (NO_PREVIEW); } // params string paramfile = coursepath + SEP + "course.dim"; if (!paramlist.Load (paramfile)) { Message ("could not load course.dim"); } const string& line2 = paramlist.Line (0); CourseList[i].author = SPStrN (line2, "author", "unknown"); CourseList[i].size.x = SPFloatN (line2, "width", 100); CourseList[i].size.y = SPFloatN (line2, "length", 1000); CourseList[i].play_size.x = SPFloatN (line2, "play_width", 90); CourseList[i].play_size.y = SPFloatN (line2, "play_length", 900); CourseList[i].angle = SPFloatN (line2, "angle", 10); CourseList[i].scale = SPFloatN (line2, "scale", 10); CourseList[i].start.x = SPFloatN (line2, "startx", 50); CourseList[i].start.y = SPFloatN (line2, "starty", 5); CourseList[i].env = Env.GetEnvIdx (SPStrN (line2, "env", "etr")); CourseList[i].music_theme = Music.GetThemeIdx (SPStrN (line2, "theme", "normal")); CourseList[i].use_keyframe = SPBoolN (line2, "use_keyframe", false); CourseList[i].finish_brake = SPFloatN (line2, "finish_brake", 20); paramlist.Clear (); // the list is used several times } } list.MakeIndex (CourseIndex, "dir"); return true; }
TArray<FString> I_GetSteamPath() { TArray<FString> result; TArray<FString> SteamInstallFolders; // Linux and OS X actually allow the user to install to any location, so // we need to figure out on an app-by-app basis where the game is installed. // To do so, we read the virtual registry. #ifdef __APPLE__ const FString appSupportPath = M_GetMacAppSupportPath(); FString regPath = appSupportPath + "/Steam/config/config.vdf"; try { SteamInstallFolders = ParseSteamRegistry(regPath); } catch(class CDoomError &error) { // If we can't parse for some reason just pretend we can't find anything. return result; } SteamInstallFolders.Push(appSupportPath + "/Steam/SteamApps/common"); #else char* home = getenv("HOME"); if(home != NULL && *home != '\0') { FString regPath; regPath.Format("%s/.steam/config/config.vdf", home); // [BL] The config seems to have moved from the more modern .local to // .steam at some point. Not sure if it's just my setup so I guess we // can fall back on it? if(!FileExists(regPath)) regPath.Format("%s/.local/share/Steam/config/config.vdf", home); try { SteamInstallFolders = ParseSteamRegistry(regPath); } catch(class CDoomError &error) { // If we can't parse for some reason just pretend we can't find anything. return result; } regPath.Format("%s/.local/share/Steam/SteamApps/common", home); SteamInstallFolders.Push(regPath); } #endif for(unsigned int i = 0;i < SteamInstallFolders.Size();++i) { for(unsigned int app = 0;app < countof(AppInfo);++app) { struct stat st; FString candidate(SteamInstallFolders[i] + "/" + AppInfo[app].BasePath); if(DirExists(candidate)) result.Push(candidate); } } return result; }
void InitConfig (const char *arg0) { #if defined (OS_WIN32_MINGW) || defined (OS_WIN32_MSC) // the progdir is always the current dir param.config_dir = "config"; param.data_dir = "data"; param.configfile = param.config_dir + SEP + "options.txt"; printf("configfile: %s\n", param.configfile.c_str()); // XXX #else #if 0 char buff[256]; if (strcmp (arg0, "./etr") == 0) { // start from work directory char *s = getcwd (buff, 256); if (s==NULL) {}; } else { // start with full path strcpy (buff, arg0); if (strlen (buff) > 5) { buff[strlen(buff)-3] = 0; } } param.prog_dir = buff; #endif struct passwd *pwent = getpwuid (getuid ()); param.config_dir = pwent->pw_dir; param.config_dir += SEP; param.config_dir += CONFIG_DIR; // or: param.config_dir = param.prog_dir + SEP + "config"; if (!DirExists (param.config_dir.c_str())) mkdir (param.config_dir.c_str(), 0775); param.data_dir = ETR_DATA_DIR; param.data_dir += SEP; param.data_dir += "etr"; // param.data_dir = param.prog_dir + SEP + "data"; param.configfile = param.config_dir + SEP + "options"; #endif param.screenshot_dir = param.data_dir + SEP + "screenshots"; param.obj_dir = param.data_dir + SEP + "objects"; param.env_dir2 = param.data_dir + SEP + "env"; param.char_dir = param.data_dir + SEP + "char"; param.terr_dir = param.data_dir + SEP + "terrains"; param.tex_dir = param.data_dir + SEP + "textures"; param.common_course_dir = param.data_dir + SEP + "courses"; param.sounds_dir = param.data_dir + SEP + "sounds"; param.music_dir = param.data_dir + SEP + "music"; param.font_dir = param.data_dir + SEP + "fonts"; param.trans_dir = param.data_dir + SEP + "translations"; param.player_dir = param.data_dir + SEP + "players"; param.ui_snow = true; param.view_mode = FOLLOW; param.display_fps = false; param.show_hud = true; // XXX if (FileExists (param.configfile)) { printf(" configfile exist \n"); LoadConfigFile (); } else { printf(" configfile does not exist ! \n"); SetConfigDefaults (); SaveConfigFile (); } /*string playerfile = param.config_dir + SEP + PLAYER_FILE; if (FileExists (playerfile)) { } else { }*/ }
void CCAddPathStrings(char ***list, int *num, char *path, char *standard1, char *standard2) { int len, separator; char *newstr; /* Add the standard paths, derived from the install location */ if(standard1) { if(!CCStringListContains(*list, *num, standard1) && DirExists(standard1)) { AddString(list, num, standard1); } } if(standard2) { if(!CCStringListContains(*list, *num, standard2) && DirExists(standard2)) { AddString(list, num, standard2); } } /* Bail out if no main path */ if(!path) { return; } /* Attempt to discover the correct path separator to use */ #ifdef IL_WIN32_PLATFORM if(strchr(path, ';') != 0) { /* The path already uses ';', so that is probably the separator */ separator = ';'; } else { /* Deal with the ambiguity between ':' used as a separator and ':' used to specify a drive letter */ if(((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z')) && path[1] == ':') { /* The path is probably one directory, starting with a drive letter */ separator = ';'; } else { /* The path is probably Cygwin-like, using ':' to separate */ separator = ':'; } } #else separator = ':'; #endif /* Split the path into separate components */ while(*path != '\0') { if(*path == separator || *path == ' ' || *path == '\t' || *path == '\r' || *path == '\n') { ++path; continue; } len = 1; while(path[len] != '\0' && path[len] != separator) { ++len; } while(len > 0 && (path[len - 1] == ' ' || path[len - 1] == '\t' || path[len - 1] == '\r' || path[len - 1] == '\n')) { --len; } newstr = (char *)ILMalloc(len + 1); if(!newstr) { CCOutOfMemory(); } ILMemCpy(newstr, path, len); newstr[len] = '\0'; if(!CCStringListContains(*list, *num, newstr) && DirExists(newstr)) { AddString(list, num, newstr); } else { ILFree(newstr); } path += len; } }
/******************************************************************** CreateShare - create the file share on this computer ********************************************************************/ HRESULT CreateShare(SCA_SMBP* pssp) { if (!pssp || !(pssp->wzKey)) return E_INVALIDARG; HRESULT hr = S_OK; PACL pACL = NULL; SHARE_INFO_502 si; NET_API_STATUS s; DWORD dwParamErr = 0; BOOL fShareExists = SUCCEEDED(DoesShareExist(pssp->wzKey)); PSECURITY_DESCRIPTOR pSD = static_cast<PSECURITY_DESCRIPTOR>(MemAlloc(SECURITY_DESCRIPTOR_MIN_LENGTH, TRUE)); ExitOnNull(pSD, hr, E_OUTOFMEMORY, "Failed to allocate memory for security descriptor"); #pragma prefast(push) #pragma prefast(disable:25029) if (!::InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) #pragma prefast(pop) { ExitOnLastError(hr, "failed to initialize security descriptor"); } hr = AllocateAcl(pssp, &pACL); ExitOnFailure(hr, "Failed to allocate ACL for fileshare"); if (NULL == pACL) { WcaLog(LOGMSG_VERBOSE, "Ignoring NULL DACL."); } #pragma prefast(push) #pragma prefast(disable:25028) // We only call this when pACL isn't NULL, so this call is safe according to the docs // add the ACL to the security descriptor. else if (!::SetSecurityDescriptorDacl(pSD, TRUE, pACL, FALSE)) { ExitOnLastError(hr, "Failed to set security descriptor"); } #pragma prefast(pop) // all that is left is to create the share FillShareInfo(&si, pssp, pSD); // Fail if the directory doesn't exist if (!DirExists(pssp->wzDirectory, NULL)) ExitOnFailure1(hr = HRESULT_FROM_WIN32(ERROR_OBJECT_NOT_FOUND), "Can't create a file share on directory that doesn't exist: %ls.", pssp->wzDirectory); WcaLog(LOGMSG_VERBOSE, "Creating file share on directory \'%ls\' named \'%ls\'.", pssp->wzDirectory, pssp->wzKey); if (!fShareExists) { s = ::NetShareAdd(NULL, 502, (BYTE*) &si, &dwParamErr); WcaLog(LOGMSG_VERBOSE, "Adding a new file share."); } else { // The share exists. Write our new permissions over the top. s = ::NetShareSetInfo(NULL, pssp->wzKey, 502, (BYTE*) &si, &dwParamErr); WcaLog(LOGMSG_VERBOSE, "Setting permissions on existing share."); } if (NERR_Success != s) { hr = E_FAIL; if (!fShareExists && NERR_DuplicateShare == s) WcaLog(LOGMSG_VERBOSE, "Duplicate error when existence check failed."); // error codes listed above. ExitOnFailure1(hr, "Failed to create/modify file share: Err: %d", s); } LExit: if (pACL) { ::LocalFree(pACL); } ReleaseMem(pSD); return hr; }
void ReadStnInfo(bool loadCoverage) { StnRecType LStnRec; FILE *SiteFile; char LineBuff[128]; int StnID,x,y; int debug = FALSE; bool coverageDirExists = DirExists(coveragePath); bool coverageLoadFailed = false; float lat, lng, ht; if ((SiteFile = fopen(SiteInfoFName,"r")) == 0) { printf("ERROR OPENING %s\n",SiteInfoFName); return; } while (fgets(LineBuff,128,SiteFile) && // skip to radar site data (strncmp(LineBuff,"RADAR SITE DATA",15) != 0)) { if (debug) printf(LineBuff); } if (debug) printf(LineBuff); if (feof(SiteFile)) { fclose(SiteFile); printf("NO RADAR SITE DATA FOUND IN %s\n",SiteInfoFName); return; } while (fgets(LineBuff,128,SiteFile) && // read radar site data (strncmp(LineBuff,"END RADAR SITE DATA",19) != 0)) { if (sscanf(LineBuff,"%d %s %f %f %f %d",&StnID,LStnRec.Name,&lat, &lng,&ht,&LStnRec.Rdr) == 6) { // remove trailing '_' chars ht *= 0.001; // convert metres to km LStnRec.set(-lat, lng, ht); // siteinfo.txt file lat is +ve south, flip it to +ve north x = strlen(LStnRec.Name) - 1; // remove trailing '_' while (x && (LStnRec.Name[x] == '_')) { LStnRec.Name[x] = 0; x--; } LStnRec.safeFileName(LStnRec.fName); // make name suitable for use in file names if ((StnID <= LastStn) && (StnID > 0)) // put rec into array StnRec[StnID] = LStnRec; if (loadCoverage && coverageDirExists) { ReadCoverageData(StnID); coverageLoadFailed |= !StnRec[StnID].coverage; } StnRec[StnID].valid = true; } else if (debug) printf("ERROR READING %s\n",LineBuff); } if (debug) { for (x=0;x<LastStn;x++) { LStnRec = StnRec[x]; printf("%d %s %f %f %f %d\n",x,LStnRec.Name, LStnRec.Lat(),LStnRec.Lng(),LStnRec.Ht(),LStnRec.Rdr); } } if (coverageDirExists && coverageLoadFailed) { y = 0; printf("ReadStnInfo - Error loading coverage data for - \n"); for (x=0;x<LastStn;x++) { if (StnRec[x].valid && !StnRec[x].coverage) { printf("%8s(%02d) ",StnRec[x].Name,x); y++; if ((y % 6) == 0) printf("\n "); } } printf("\n"); } fclose(SiteFile); if (debug) printf("%s\n",LineBuff); }
int GetGraceSerializationPaths(int &OutputCount, char **List, int MaxCount) { OutputCount = 0; if (*List == NULL) return 1; //add local directory { char *LocalPath = new char[2]; strcpy_s(LocalPath, 2, "."); if (DirExists(LocalPath) && OutputCount<MaxCount) List[OutputCount++] = LocalPath; else delete LocalPath; } //add temp directory 1 { char *TempPath = new char[500]; DWORD ret = GetTempPath(500, TempPath); if (ret < MAX_PATH && ret != 0) { RemoveEndSlashes(TempPath); if (HaveStringInList(TempPath, List, OutputCount) == 0 && DirExists(TempPath) && OutputCount<MaxCount) List[OutputCount++] = TempPath; else delete[] TempPath; } else delete[] TempPath; } //add temp directory 2 { char *env_p; size_t len; errno_t err = _dupenv_s(&env_p, &len, "TMP"); if (err == 0 && len > 0) { RemoveEndSlashes(env_p); if (HaveStringInList(env_p, List, OutputCount) == 0 && DirExists(env_p) && OutputCount < MaxCount) { char *TempPath = new char[500]; strcpy_s(TempPath, 500, env_p); List[OutputCount++] = TempPath; } free(env_p); } } //add temp directory 3 { char *env_p; size_t len; errno_t err = _dupenv_s(&env_p, &len, "TEMP"); if (err == 0 && len > 0) { RemoveEndSlashes(env_p); if (HaveStringInList(env_p, List, OutputCount) == 0 && DirExists(env_p) && OutputCount < MaxCount) { char *TempPath = new char[500]; strcpy_s(TempPath, 500, env_p); List[OutputCount++] = TempPath; } free(env_p); } } //add temp directory 4 { char *env_p; size_t len; errno_t err = _dupenv_s(&env_p, &len, "USERPROFILE"); if (err == 0 && len > 0) { RemoveEndSlashes(env_p); if (HaveStringInList(env_p, List, OutputCount) == 0 && DirExists(env_p) && OutputCount < MaxCount) { char *TempPath = new char[500]; strcpy_s(TempPath, 500, env_p); List[OutputCount++] = TempPath; } free(env_p); } } //add temp directory 5 { char *env_p; size_t len; errno_t err = _dupenv_s(&env_p, &len, "%WINDIR%\temp"); if (err == 0 && len > 0) { RemoveEndSlashes(env_p); if (HaveStringInList(env_p, List, OutputCount) == 0 && DirExists(env_p) && OutputCount < MaxCount) { char *TempPath = new char[500]; strcpy_s(TempPath, 500, env_p); List[OutputCount++] = TempPath; } free(env_p); } } return 0; }
/** * Parse command line arguments, initialise g_options * @param argc - Number of arguments * @param argv - Array of argument strings */ void ParseArguments(int argc, char ** argv) { g_options.program = argv[0]; // program name g_options.verbosity = LOGDEBUG; // default log level // Set the main directory //if (getcwd(g_options.root_dir, sizeof(g_options.root_dir)) == NULL) // Fatal("Couldn't get current working directory - %s", strerror(errno)); clock_gettime(CLOCK_MONOTONIC, &(g_options.start_time)); // Start time g_options.auth_method = AUTH_NONE; // Don't use authentication g_options.auth_uri = ""; // g_options.auth_options = ""; g_options.experiment_dir = "."; for (int i = 1; i < argc; ++i) { if (argv[i][0] != '-') Fatal("Unexpected argv[%d] - %s", i, argv[i]); if (i+1 >= argc || argv[i+1][0] == '-') Fatal("No argument following switch %s", argv[i]); if (strlen(argv[i]) > 2) Fatal("Human readable switches are not supported."); char * end = NULL; switch (argv[i][1]) { // Set program verbosity case 'v': g_options.verbosity = strtol(argv[++i], &end, 10); break; // Enable/Disable pin test case 'p': g_options.enable_pin = !(strtol(argv[++i], &end, 10)); break; // Authentication URI and options case 'A': g_options.auth_uri = argv[++i]; break; case 'e': // Experiments directory g_options.experiment_dir = argv[++i]; break; default: Fatal("Unrecognised switch %s", argv[i]); break; } if (end != NULL && *end != '\0') Fatal("argv[%d] -%c requires an integer (got \"%s\" instead)", i-1, argv[i-1][0], argv[i]); } if (!DirExists(g_options.experiment_dir)) { Fatal("Experiment directory '%s' does not exist.", g_options.experiment_dir); } if (g_options.auth_uri[0] != '\0') { // Get the options part of the URI if it exists char * c = (char*)g_options.auth_uri; while (*(++c) != '\0' && *c != '#'); if (*(c++) == '#') { *(c-1) = '\0'; g_options.auth_options = c; } // Use the first part of the URI to identify the protocol: c = (char*)g_options.auth_uri; while (*(++c) != '\0' && *c != ':'); if (*c == '\0') // No ':' means no protocol; use plaintext file { g_options.auth_method = AUTH_SHADOW; } else if (*c == ':' && *(c+1) == '/' && *(c+2) == '/') { *c = '\0'; if (strcmp(g_options.auth_uri, "ldap") == 0 || strcmp(g_options.auth_uri, "ldaps") == 0) { *c = ':'; // LDAP URI's require the prodocol as part of the string g_options.auth_method = AUTH_LDAP; } else if (strcmp(g_options.auth_uri, "mysql") == 0) { g_options.auth_uri = c+3; // MySQL doesn't (just a hostname) g_options.auth_method = AUTH_MYSQL; } else { Fatal("Unsupported authentication method %s", g_options.auth_uri); } } } else { Log(LOGWARN, "No authentication method."); } Log(LOGDEBUG, "Verbosity: %d", g_options.verbosity); Log(LOGDEBUG, "Pin Module Enabled: %d", g_options.enable_pin); Log(LOGDEBUG, "Auth method: %d", g_options.auth_method); Log(LOGDEBUG, "Auth URI: %s", g_options.auth_uri); Log(LOGDEBUG, "Auth Options: %s", g_options.auth_options); //Log(LOGDEBUG, "Root directory: %s", g_options.root_dir); Log(LOGDEBUG, "Experiment directory: %s", g_options.experiment_dir); }
HRESULT ShellExec( __in LPCWSTR wzTarget, __in BOOL fUnelevated ) { HRESULT hr = S_OK; LPWSTR sczWorkingDirectory = NULL; // a reasonable working directory (not the system32 default from MSI) is the directory where the target lives hr = PathGetDirectory(wzTarget, &sczWorkingDirectory); ExitOnFailure(hr, "failed to get directory for target: %ls", wzTarget); if (!DirExists(sczWorkingDirectory, NULL)) { ReleaseNullStr(sczWorkingDirectory); } if (fUnelevated) { hr = ShelExecUnelevated(wzTarget, NULL, NULL, sczWorkingDirectory, SW_SHOWDEFAULT); ExitOnFailure(hr, "ShelExecUnelevated failed with target %ls", wzTarget); } else { HINSTANCE hinst = ::ShellExecuteW(NULL, NULL, wzTarget, NULL, sczWorkingDirectory, SW_SHOWDEFAULT); if (hinst <= HINSTANCE(32)) { LONG64 code = reinterpret_cast<LONG64>(hinst); switch (code) { case ERROR_FILE_NOT_FOUND: hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); break; case ERROR_PATH_NOT_FOUND: hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); break; case ERROR_BAD_FORMAT: hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); break; case SE_ERR_ASSOCINCOMPLETE: case SE_ERR_NOASSOC: hr = HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION); break; case SE_ERR_DDEBUSY: case SE_ERR_DDEFAIL: case SE_ERR_DDETIMEOUT: hr = HRESULT_FROM_WIN32(ERROR_DDE_FAIL); break; case SE_ERR_DLLNOTFOUND: hr = HRESULT_FROM_WIN32(ERROR_DLL_NOT_FOUND); break; case SE_ERR_OOM: hr = E_OUTOFMEMORY; break; case SE_ERR_ACCESSDENIED: hr = E_ACCESSDENIED; break; default: hr = E_FAIL; } ExitOnFailure(hr, "ShellExec failed with return code %llu.", code); } } LExit: ReleaseStr(sczWorkingDirectory); return hr; }
bool DirDelete(const iStringT& dname) { if ( !DirExists( dname ) ) return true; return ::RemoveDirectoryW(dname.CStr()) ? true : false; }