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 30 of file C4Config.h.

Member Enumeration Documentation

anonymous enum
Enumerator
ConfigResetSafetyVal 

Definition at line 33 of file C4Config.h.

Member Function Documentation

void C4ConfigGeneral::CompileFunc ( StdCompiler pComp)

Definition at line 48 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().

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

Here is the call graph for this function:

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

Definition at line 572 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().

573 {
574  // Create directory if needed
575  if (!CreatePath(strDirectory))
576  return false;
577  // Create title component if needed
578  char lang[3]; SCopy(Config.General.Language, lang, 2);
579  StdStrBuf strTitleFile; strTitleFile.Format("%s%c%s", strDirectory, DirectorySeparator, C4CFN_WriteTitle);
580  StdStrBuf strTitleData; strTitleData.Format("%s:%s", lang, strLanguageTitle);
581  CStdFile hFile;
582  if (!FileExists(strTitleFile.getData()))
583  if (!hFile.Create(strTitleFile.getData()) || !hFile.WriteString(strTitleData.getData()) || !hFile.Close())
584  return false;
585  // Save folder seems okay
586  return true;
587 }
const char * getData() const
Definition: StdBuf.h:442
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:151
#define C4CFN_WriteTitle
Definition: C4Components.h:83
C4Config Config
Definition: C4Config.cpp:833
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
bool Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:49
C4ConfigGeneral General
Definition: C4Config.h:251
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
char Language[CFG_MaxString+1]
Definition: C4Config.h:36
bool FileExists(const char *szFileName)
bool WriteString(const char *szStr)
Definition: CStdFile.cpp:264
#define DirectorySeparator

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ConfigGeneral::DefaultLanguage ( )

Definition at line 687 of file C4Config.cpp.

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

Referenced by C4Config::Load().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ConfigGeneral::DeterminePaths ( )

Definition at line 430 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().

431 {
432 #ifdef _WIN32
433  // Exe path
434  wchar_t apath[CFG_MaxString];
435  if (GetModuleFileNameW(nullptr,apath,CFG_MaxString))
436  {
437  ExePath = StdStrBuf(apath);
441  }
442  // Temp path
443  GetTempPathW(CFG_MaxString,apath);
444  TempPath = StdStrBuf(apath);
446 #elif defined(__linux__)
447  ExePath.SetLength(1024);
448  ssize_t l = readlink("/proc/self/exe", ExePath.getMData(), 1024);
449  if (l < -1)
450  {
451  ExePath.Ref(".");
452  }
453  else
454  {
455  ExePath.SetLength(l);
458  }
459  const char * t = getenv("TMPDIR");
460  if (t)
461  {
462  TempPath = t;
464  }
465  else
466  TempPath = "/tmp/";
467 #else
468  // Mac: Just use the working directory as ExePath.
471  TempPath = "/tmp/";
472 #endif
473 
474  // Find system-wide data path
475 #if defined(_WIN32)
476  // Use ExePath: on windows, everything is installed to one directory
478 #elif defined(__APPLE__)
479  SCopy(::Application.GetGameDataPath().c_str(),SystemDataPath);
480 #elif defined(WITH_AUTOMATIC_UPDATE)
481  // WITH_AUTOMATIC_UPDATE builds are our tarball releases and
482  // development snapshots, i.e. where the game data is at the
483  // same location as the executable.
485 #elif defined(OC_SYSTEM_DATA_DIR)
486  SCopy(OC_SYSTEM_DATA_DIR, SystemDataPath);
487 #else
488 #error Please define OC_SYSTEM_DATA_DIR!
489 #endif
491 
492  // Find user-specific data path
493  if (ConfigUserPath[0])
495  else
496 #if defined(_WIN32)
497  SCopy(R"(%APPDATA%\)" C4ENGINENAME, UserDataPath);
498 #elif defined(__APPLE__)
499  SCopy("$HOME/Library/Application Support/" C4ENGINENAME, UserDataPath);
500 #else
501  SCopy("$HOME/.clonk/" C4ENGINENICK, UserDataPath);
502 #endif
505 
506  // Screenshot path
509  {
512  }
513  // Create user path if it doesn't already exist
515 }
const char * getData() const
Definition: StdBuf.h:442
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
StdStrBuf ScreenshotFolder
Definition: C4Config.h:44
char ScreenshotPath[CFG_MaxString+1]
Definition: C4Config.h:56
size_t SLen(const char *sptr)
Definition: Standard.h:74
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:257
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
char * getMData()
Definition: StdBuf.h:443
void AppendBackslash()
Definition: StdBuf.cpp:248
char ConfigUserPath[CFG_MaxString+1]
Definition: C4Config.h:43
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:54
ptrdiff_t ssize_t
const char * GetWorkingDirectory()
Definition: StdFile.cpp:603
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
static void ExpandEnvironmentVariables(char *strPath, size_t iMaxLen)
Definition: C4Config.cpp:786
void Ref(const char *pnData)
Definition: StdBuf.h:455
StdCopyStrBuf TempPath
Definition: C4Config.h:53
StdCopyStrBuf ExePath
Definition: C4Config.h:52
size_t getLength() const
Definition: StdBuf.h:445
void SetLength(size_t iLength)
Definition: StdBuf.h:509
bool TruncatePath(char *szPath)
Definition: StdFile.cpp:240
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 724 of file C4Config.cpp.

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

Referenced by DefaultLanguage().

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

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 39 of file C4Config.h.

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

int32_t C4ConfigGeneral::ConfigResetSafety

Definition at line 50 of file C4Config.h.

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

char C4ConfigGeneral::ConfigUserPath[CFG_MaxString+1]

Definition at line 43 of file C4Config.h.

Referenced by CompileFunc(), and DeterminePaths().

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

Definition at line 62 of file C4Config.h.

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

int32_t C4ConfigGeneral::DefRec
bool C4ConfigGeneral::FirstStart

Definition at line 59 of file C4Config.h.

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

int32_t C4ConfigGeneral::FPS
bool C4ConfigGeneral::GamepadEnabled

Definition at line 58 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 48 of file C4Config.h.

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

char C4ConfigGeneral::Name[CFG_MaxString+1]

Definition at line 35 of file C4Config.h.

Referenced by CompileFunc().

int32_t C4ConfigGeneral::OpenScenarioInGameMode

Definition at line 40 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 44 of file C4Config.h.

Referenced by CompileFunc(), and DeterminePaths().

char C4ConfigGeneral::ScreenshotPath[CFG_MaxString+1]

Definition at line 56 of file C4Config.h.

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

int32_t C4ConfigGeneral::ScrollSmooth

Definition at line 49 of file C4Config.h.

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

StdCopyStrBuf C4ConfigGeneral::TempPath

Definition at line 53 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: