OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ConfigGeneral Class Reference

#include <C4Config.h>

Collaboration diagram for C4ConfigGeneral:
[legend]

Public Types

enum  { ConfigResetSafetyVal = 42 }
 

Public Member Functions

void DefaultLanguage ()
 
bool CreateSaveFolder (const char *strDirectory, const char *strLanguageTitle)
 
void DeterminePaths ()
 
void CompileFunc (StdCompiler *pComp)
 

Static Public Member Functions

static int GetLanguageSequence (const char *strSource, char *strTarget)
 

Public Attributes

char Name [CFG_MaxString+1]
 
char Language [CFG_MaxString+1]
 
char LanguageEx [CFG_MaxString+1]
 
char Participants [CFG_MaxString+1]
 
int32_t AlwaysDebug
 
int32_t OpenScenarioInGameMode
 
char RXFontName [CFG_MaxString+1]
 
int32_t RXFontSize
 
char ConfigUserPath [CFG_MaxString+1]
 
StdStrBuf ScreenshotFolder
 
char MissionAccess [CFG_MaxString+1]
 
int32_t FPS
 
int32_t DefRec
 
int32_t MMTimer
 
int32_t ScrollSmooth
 
int32_t ConfigResetSafety
 
StdCopyStrBuf ExePath
 
StdCopyStrBuf TempPath
 
char UserDataPath [CFG_MaxString+1]
 
char SystemDataPath [CFG_MaxString+1]
 
char ScreenshotPath [CFG_MaxString+1]
 
char TempUpdatePath [CFG_MaxString+1]
 
bool GamepadEnabled
 
bool FirstStart
 
int32_t DebugRec
 
int32_t DebugRecWrite
 
char DebugRecExternalFile [_MAX_PATH+1]
 

Detailed Description

Definition at line 31 of file C4Config.h.

Member Enumeration Documentation

anonymous enum
Enumerator
ConfigResetSafetyVal 

Definition at line 34 of file C4Config.h.

Member Function Documentation

void C4ConfigGeneral::CompileFunc ( StdCompiler pComp)

Definition at line 52 of file C4Config.cpp.

References AlwaysDebug, C4DEFAULT_FONT_NAME, ConfigResetSafety, ConfigResetSafetyVal, ConfigUserPath, DefRec, FirstStart, FPS, GamepadEnabled, Language, LanguageEx, MissionAccess, mkNamingAdapt(), MMTimer, Name, OpenScenarioInGameMode, Participants, RXFontName, RXFontSize, s, ScreenshotFolder, ScrollSmooth, TempUpdatePath, and StdCompiler::Value().

53 {
54  // For those without the ability to intuitively guess what the falses and trues mean:
55  // its mkNamingAdapt(field, name, default, fPrefillDefault, fStoreDefault)
56  // where fStoreDefault writes out the value to the config even if it's the same as the default.
57 #define s mkStringAdaptM
58  pComp->Value(mkNamingAdapt(s(Name), "Name", "" ));
59  pComp->Value(mkNamingAdapt(s(Language), "Language", "", false, true));
60  pComp->Value(mkNamingAdapt(s(LanguageEx), "LanguageEx", "", false, true));
61  pComp->Value(mkNamingAdapt(s(Participants), "Participants", "" ));
62 
63  // deliberately not grandfathering UserPath setting, since it was written to config by default
64  pComp->Value(mkNamingAdapt(s(ConfigUserPath), "UserDataPath", "", false, true));
65  // assimilate old data
66  pComp->Value(mkNamingAdapt(s(Adopt.PlayerPath), "PlayerPath", ""));
67 
68  // temporary path only set during updates
69  pComp->Value(mkNamingAdapt(s(TempUpdatePath), "TempUpdatePath", ""));
70 
71  pComp->Value(mkNamingAdapt(s(MissionAccess), "MissionAccess", "", false, true));
72  pComp->Value(mkNamingAdapt(FPS, "FPS", 0 ));
73  pComp->Value(mkNamingAdapt(DefRec, "DefRec", 0 ));
74  pComp->Value(mkNamingAdapt(ScreenshotFolder, "ScreenshotFolder", "Screenshots", false, true));
75  pComp->Value(mkNamingAdapt(ScrollSmooth, "ScrollSmooth", 4 ));
76  pComp->Value(mkNamingAdapt(AlwaysDebug, "DebugMode", 0 ));
77  pComp->Value(mkNamingAdapt(OpenScenarioInGameMode, "OpenScenarioInGameMode", 0 ));
78 #ifdef _WIN32
79  pComp->Value(mkNamingAdapt(MMTimer, "MMTimer", 1 ));
80 #endif
81  pComp->Value(mkNamingAdapt(s(RXFontName), "FontName", C4DEFAULT_FONT_NAME, false, true));
82  pComp->Value(mkNamingAdapt(RXFontSize, "FontSize", 14, false, true));
83  pComp->Value(mkNamingAdapt(GamepadEnabled, "GamepadEnabled", true ));
84  pComp->Value(mkNamingAdapt(FirstStart, "FirstStart", true ));
85  pComp->Value(mkNamingAdapt(ConfigResetSafety, "ConfigResetSafety", static_cast<int32_t>(ConfigResetSafetyVal) ));
86 }
int32_t OpenScenarioInGameMode
Definition: C4Config.h:41
char MissionAccess[CFG_MaxString+1]
Definition: C4Config.h:46
int32_t FPS
Definition: C4Config.h:47
StdStrBuf ScreenshotFolder
Definition: C4Config.h:45
bool GamepadEnabled
Definition: C4Config.h:59
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
#define C4DEFAULT_FONT_NAME
Definition: C4Config.h:28
char ConfigUserPath[CFG_MaxString+1]
Definition: C4Config.h:44
char Participants[CFG_MaxString+1]
Definition: C4Config.h:39
int32_t ConfigResetSafety
Definition: C4Config.h:51
int32_t DefRec
Definition: C4Config.h:48
void Value(const T &rStruct)
Definition: StdCompiler.h:171
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
bool FirstStart
Definition: C4Config.h:60
char Language[CFG_MaxString+1]
Definition: C4Config.h:37
char Name[CFG_MaxString+1]
Definition: C4Config.h:36
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:58
char RXFontName[CFG_MaxString+1]
Definition: C4Config.h:42
int32_t RXFontSize
Definition: C4Config.h:43
int32_t MMTimer
Definition: C4Config.h:49
int32_t AlwaysDebug
Definition: C4Config.h:40
#define s
int32_t ScrollSmooth
Definition: C4Config.h:50

Here is the call graph for this function:

bool C4ConfigGeneral::CreateSaveFolder ( const char *  strDirectory,
const char *  strLanguageTitle 
)

Definition at line 576 of file C4Config.cpp.

References C4CFN_WriteTitle, CStdFile::Close(), Config, CStdFile::Create(), CreatePath(), DirectorySeparator, FileExists(), StdStrBuf::Format(), C4Config::General, StdStrBuf::getData(), Language, SCopy(), and CStdFile::WriteString().

Referenced by C4Game::QuickSave(), and C4Record::Start().

577 {
578  // Create directory if needed
579  if (!CreatePath(strDirectory))
580  return false;
581  // Create title component if needed
582  char lang[3]; SCopy(Config.General.Language, lang, 2);
583  StdStrBuf strTitleFile; strTitleFile.Format("%s%c%s", strDirectory, DirectorySeparator, C4CFN_WriteTitle);
584  StdStrBuf strTitleData; strTitleData.Format("%s:%s", lang, strLanguageTitle);
585  CStdFile hFile;
586  if (!FileExists(strTitleFile.getData()))
587  if (!hFile.Create(strTitleFile.getData()) || !hFile.WriteString(strTitleData.getData()) || !hFile.Close())
588  return false;
589  // Save folder seems okay
590  return true;
591 }
const char * getData() const
Definition: StdBuf.h:450
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:155
#define C4CFN_WriteTitle
Definition: C4Components.h:83
C4Config Config
Definition: C4Config.cpp:837
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:642
bool Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:53
C4ConfigGeneral General
Definition: C4Config.h:252
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
char Language[CFG_MaxString+1]
Definition: C4Config.h:37
bool FileExists(const char *szFilename)
Definition: StdFile.cpp:439
bool WriteString(const char *szStr)
Definition: CStdFile.cpp:268
#define DirectorySeparator

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ConfigGeneral::DefaultLanguage ( )

Definition at line 691 of file C4Config.cpp.

References GetLanguageSequence(), IsGermanSystem(), Language, LanguageEx, and SCopy().

Referenced by C4Config::Load().

692 {
693  // No language defined: default to German or English by system language
694  if (!Language[0])
695  {
696  if (IsGermanSystem())
697  SCopy("DE - Deutsch", Language);
698  else
699  SCopy("US - English", Language);
700  }
701  // No fallback sequence defined: use primary language list
702  if (!LanguageEx[0])
704 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
static int GetLanguageSequence(const char *strSource, char *strTarget)
Definition: C4Config.cpp:728
bool IsGermanSystem()
Definition: C4AppMac.mm:193
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
char Language[CFG_MaxString+1]
Definition: C4Config.h:37

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ConfigGeneral::DeterminePaths ( )

Definition at line 434 of file C4Config.cpp.

References AppendBackslash(), StdStrBuf::AppendBackslash(), Application, CFG_MaxString, ConfigUserPath, CreatePath(), ExePath, C4Config::ExpandEnvironmentVariables(), StdStrBuf::getData(), StdStrBuf::getLength(), StdStrBuf::getMData(), GetParentPath(), GetWorkingDirectory(), StdStrBuf::Ref(), SAppend(), SCopy(), ScreenshotFolder, ScreenshotPath, StdStrBuf::SetLength(), SLen(), SystemDataPath, TempPath, TruncatePath(), and UserDataPath.

Referenced by C4Config::Load().

435 {
436 #ifdef _WIN32
437  // Exe path
438  wchar_t apath[CFG_MaxString];
439  if (GetModuleFileNameW(nullptr,apath,CFG_MaxString))
440  {
441  ExePath = StdStrBuf(apath);
445  }
446  // Temp path
447  GetTempPathW(CFG_MaxString,apath);
448  TempPath = StdStrBuf(apath);
450 #elif defined(__linux__)
451  ExePath.SetLength(1024);
452  ssize_t l = readlink("/proc/self/exe", ExePath.getMData(), 1024);
453  if (l < -1)
454  {
455  ExePath.Ref(".");
456  }
457  else
458  {
459  ExePath.SetLength(l);
462  }
463  const char * t = getenv("TMPDIR");
464  if (t)
465  {
466  TempPath = t;
468  }
469  else
470  TempPath = "/tmp/";
471 #else
472  // Mac: Just use the working directory as ExePath.
475  TempPath = "/tmp/";
476 #endif
477 
478  // Find system-wide data path
479 #if defined(_WIN32)
480  // Use ExePath: on windows, everything is installed to one directory
482 #elif defined(__APPLE__)
483  SCopy(::Application.GetGameDataPath().c_str(),SystemDataPath);
484 #elif defined(WITH_AUTOMATIC_UPDATE)
485  // WITH_AUTOMATIC_UPDATE builds are our tarball releases and
486  // development snapshots, i.e. where the game data is at the
487  // same location as the executable.
489 #elif defined(OC_SYSTEM_DATA_DIR)
490  SCopy(OC_SYSTEM_DATA_DIR, SystemDataPath);
491 #else
492 #error Please define OC_SYSTEM_DATA_DIR!
493 #endif
495 
496  // Find user-specific data path
497  if (ConfigUserPath[0])
499  else
500 #if defined(_WIN32)
501  SCopy("%APPDATA%\\" C4ENGINENAME, UserDataPath);
502 #elif defined(__APPLE__)
503  SCopy("$HOME/Library/Application Support/" C4ENGINENAME, UserDataPath);
504 #else
505  SCopy("$HOME/.clonk/" C4ENGINENICK, UserDataPath);
506 #endif
509 
510  // Screenshot path
513  {
516  }
517  // Create user path if it doesn't already exist
519 }
const char * getData() const
Definition: StdBuf.h:450
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:642
StdStrBuf ScreenshotFolder
Definition: C4Config.h:45
char ScreenshotPath[CFG_MaxString+1]
Definition: C4Config.h:57
size_t SLen(const char *sptr)
Definition: Standard.h:78
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:267
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:199
char * getMData()
Definition: StdBuf.h:451
void AppendBackslash()
Definition: StdBuf.cpp:255
char ConfigUserPath[CFG_MaxString+1]
Definition: C4Config.h:44
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
ptrdiff_t ssize_t
const char * GetWorkingDirectory()
Definition: StdFile.cpp:613
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
static void ExpandEnvironmentVariables(char *strPath, size_t iMaxLen)
Definition: C4Config.cpp:790
void Ref(const char *pnData)
Definition: StdBuf.h:463
StdCopyStrBuf TempPath
Definition: C4Config.h:54
StdCopyStrBuf ExePath
Definition: C4Config.h:53
size_t getLength() const
Definition: StdBuf.h:453
void SetLength(size_t iLength)
Definition: StdBuf.h:517
bool TruncatePath(char *szPath)
Definition: StdFile.cpp:250
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

int C4ConfigGeneral::GetLanguageSequence ( const char *  strSource,
char *  strTarget 
)
static

Definition at line 728 of file C4Config.cpp.

References SAppend(), SAppendChar(), and SCopySegment().

Referenced by DefaultLanguage().

729 {
730  // Copy a condensed list of language codes from the source list to the target string,
731  // skipping any whitespace or long language descriptions. Language sequences are
732  // comma separated.
733  int iCount = 0;
734  char strLang[2 + 1];
735  for (int i = 0; SCopySegment(strSource, i, strLang, ',', 2, true); i++)
736  if (strLang[0])
737  {
738  if (strTarget[0]) SAppendChar(',', strTarget);
739  SAppend(strLang, strTarget);
740  iCount++;
741  }
742  return iCount;
743 }
void SAppendChar(char cChar, char *szStr)
Definition: Standard.cpp:235
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:243

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int32_t C4ConfigGeneral::AlwaysDebug

Definition at line 40 of file C4Config.h.

Referenced by CompileFunc(), and C4Game::Init().

int32_t C4ConfigGeneral::ConfigResetSafety

Definition at line 51 of file C4Config.h.

Referenced by CompileFunc(), and C4Config::IsCorrupted().

char C4ConfigGeneral::ConfigUserPath[CFG_MaxString+1]

Definition at line 44 of file C4Config.h.

Referenced by CompileFunc(), and DeterminePaths().

char C4ConfigGeneral::DebugRecExternalFile[_MAX_PATH+1]
int32_t C4ConfigGeneral::DebugRecWrite

Definition at line 63 of file C4Config.h.

Referenced by C4Playback::Check(), C4Playback::Open(), and C4Application::ParseCommandLine().

int32_t C4ConfigGeneral::DefRec
bool C4ConfigGeneral::FirstStart

Definition at line 60 of file C4Config.h.

Referenced by CompileFunc(), and C4StartupMainDlg::OnShown().

int32_t C4ConfigGeneral::FPS
bool C4ConfigGeneral::GamepadEnabled

Definition at line 59 of file C4Config.h.

Referenced by CompileFunc(), C4Application::DoInit(), and C4Player::InitControl().

char C4ConfigGeneral::Language[CFG_MaxString+1]
int32_t C4ConfigGeneral::MMTimer

Definition at line 49 of file C4Config.h.

Referenced by C4StartupOptionsDlg::C4StartupOptionsDlg(), and CompileFunc().

char C4ConfigGeneral::Name[CFG_MaxString+1]

Definition at line 36 of file C4Config.h.

Referenced by CompileFunc().

int32_t C4ConfigGeneral::OpenScenarioInGameMode

Definition at line 41 of file C4Config.h.

Referenced by CompileFunc(), and C4Application::ParseCommandLine().

char C4ConfigGeneral::RXFontName[CFG_MaxString+1]
int32_t C4ConfigGeneral::RXFontSize
StdStrBuf C4ConfigGeneral::ScreenshotFolder

Definition at line 45 of file C4Config.h.

Referenced by CompileFunc(), and DeterminePaths().

char C4ConfigGeneral::ScreenshotPath[CFG_MaxString+1]

Definition at line 57 of file C4Config.h.

Referenced by C4Config::AtScreenshotPath(), and DeterminePaths().

int32_t C4ConfigGeneral::ScrollSmooth

Definition at line 50 of file C4Config.h.

Referenced by C4Viewport::AdjustPosition(), and CompileFunc().

StdCopyStrBuf C4ConfigGeneral::TempPath

Definition at line 54 of file C4Config.h.

Referenced by C4Config::AtTempPath(), DeterminePaths(), and C4Application::DoInit().

char C4ConfigGeneral::TempUpdatePath[CFG_MaxString+1]

The documentation for this class was generated from the following files: