void FGameConfigFile::CreateStandardAutoExec(const char *section, bool start) { if (!SetSection(section)) { FString path; #ifdef __APPLE__ char cpath[PATH_MAX]; FSRef folder; if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) && noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX)) { path << cpath << "/" GAME_DIR "/autoexec.cfg"; } #elif !defined(unix) path = "$PROGDIR/autoexec.cfg"; #else path = GetUserFile ("autoexec.cfg"); #endif SetSection (section, true); SetValueForKey ("Path", path.GetChars()); } if (start) { MoveSectionToStart(section); } }
FString M_GetCajunPath(const char *botfilename) { FString path; // Check first in ~/.config/zdoom/botfilename. path = GetUserFile(botfilename); if (!FileExists(path)) { // Then check in SHARE_DIR/botfilename. path = SHARE_DIR; path << botfilename; if (!FileExists(path)) { path = ""; } } return path; }
//VIZDOOM_CODE FString M_GetCajunPath(const char *botfilename) { FString path; // Then first run folder path = "./"; path << botfilename; if (!FileExists(path)) { // Then check executable folder path = progdir; path << botfilename; if (!FileExists(path)) { // Then check in ~/.config/zdoom/botfilename. path = GetUserFile(botfilename); if (!FileExists(path)) { path = ""; } } } return path; }
FString FGameConfigFile::GetConfigPath (bool tryProg) { char *pathval; FString path; pathval = Args->CheckValue ("-config"); if (pathval != NULL) return FString(pathval); #ifdef _WIN32 path = NULL; HRESULT hr; TCHAR uname[UNLEN+1]; DWORD unamelen = countof(uname); // Because people complained, try for a user-specific .ini in the program directory first. // If that is not writeable, use the one in the home directory instead. hr = GetUserName (uname, &unamelen); if (SUCCEEDED(hr) && uname[0] != 0) { // Is it valid for a user name to have slashes? // Check for them and substitute just in case. char *probe = uname; while (*probe != 0) { if (*probe == '\\' || *probe == '/') *probe = '_'; ++probe; } path = progdir; path += "zdoom-"; path += uname; path += ".ini"; if (tryProg) { if (!FileExists (path.GetChars())) { path = ""; } } else { // check if writeable FILE *checker = fopen (path.GetChars(), "a"); if (checker == NULL) { path = ""; } else { fclose (checker); } } } if (path.IsEmpty()) { if (Args->CheckParm ("-cdrom")) return CDROM_DIR "\\zdoom.ini"; path = progdir; path += "zdoom.ini"; } return path; #elif defined(__APPLE__) char cpath[PATH_MAX]; FSRef folder; if (noErr == FSFindFolder(kUserDomain, kPreferencesFolderType, kCreateFolder, &folder) && noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX)) { path = cpath; path += "/zdoom.ini"; return path; } // Ungh. return "zdoom.ini"; #else return GetUserFile ("zdoom.ini"); #endif }
FString M_GetConfigPath(bool for_reading) { return GetUserFile(GAMENAMELOWERCASE ".ini"); }
FString M_GetAutoexecPath() { return GetUserFile("autoexec.cfg"); }
FString M_GetConfigPath(bool for_reading) { return GetUserFile("zdoom.ini"); }
bool FCajunMaster::LoadBots () { FScanner sc; FString tmp; bool gotteam = false; bglobal.ForgetBots (); #ifndef unix tmp = progdir; tmp += "zcajun/" BOTFILENAME; if (!FileExists (tmp)) { DPrintf ("No " BOTFILENAME ", so no bots\n"); return false; } #else tmp = GetUserFile (BOTFILENAME); if (!FileExists (tmp)) { if (!FileExists (SHARE_DIR BOTFILENAME)) { DPrintf ("No " BOTFILENAME ", so no bots\n"); return false; } else sc.OpenFile (SHARE_DIR BOTFILENAME); } #endif else { sc.OpenFile (tmp); } while (sc.GetString ()) { if (!sc.Compare ("{")) { sc.ScriptError ("Unexpected token '%s'\n", sc.String); } botinfo_t *newinfo = new botinfo_t; bool gotclass = false; memset (newinfo, 0, sizeof(*newinfo)); newinfo->info = copystring ("\\autoaim\\0\\movebob\\.25"); for (;;) { sc.MustGetString (); if (sc.Compare ("}")) break; switch (sc.MatchString (BotConfigStrings)) { case BOTCFG_NAME: sc.MustGetString (); appendinfo (newinfo->info, "name"); appendinfo (newinfo->info, sc.String); newinfo->name = copystring (sc.String); break; case BOTCFG_AIMING: sc.MustGetNumber (); newinfo->skill.aiming = sc.Number; break; case BOTCFG_PERFECTION: sc.MustGetNumber (); newinfo->skill.perfection = sc.Number; break; case BOTCFG_REACTION: sc.MustGetNumber (); newinfo->skill.reaction = sc.Number; break; case BOTCFG_ISP: sc.MustGetNumber (); newinfo->skill.isp = sc.Number; break; case BOTCFG_TEAM: { char teamstr[16]; BYTE teamnum; sc.MustGetString (); if (IsNum (sc.String)) { teamnum = atoi (sc.String); if (!TeamLibrary.IsValidTeam (teamnum)) { teamnum = TEAM_NONE; } } else { teamnum = TEAM_NONE; for (unsigned int i = 0; i < Teams.Size(); ++i) { if (stricmp (Teams[i].GetName (), sc.String) == 0) { teamnum = i; break; } } } appendinfo (newinfo->info, "team"); mysnprintf (teamstr, countof(teamstr), "%d", teamnum); appendinfo (newinfo->info, teamstr); gotteam = true; break; } default: if (stricmp (sc.String, "playerclass") == 0) { gotclass = true; } appendinfo (newinfo->info, sc.String); sc.MustGetString (); appendinfo (newinfo->info, sc.String); break; } } if (!gotclass) { // Bots that don't specify a class get a random one appendinfo (newinfo->info, "playerclass"); appendinfo (newinfo->info, "random"); } if (!gotteam) { // Same for bot teams appendinfo (newinfo->info, "team"); appendinfo (newinfo->info, "255"); } newinfo->next = bglobal.botinfo; newinfo->lastteam = TEAM_NONE; bglobal.botinfo = newinfo; bglobal.loaded_bots++; } Printf ("%d bots read from %s\n", bglobal.loaded_bots, BOTFILENAME); return true; }