OpenClonk
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 *directory, const char *language_title)
 
void DeterminePaths ()
 
void CompileFunc (StdCompiler *compiler)
 

Static Public Member Functions

static int GetLanguageSequence (const char *source, char *target)
 

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
 
StdStrBuf ModsFolder
 
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 ModsDataPath [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_LEN]
 

Detailed Description

Definition at line 31 of file C4Config.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ConfigResetSafetyVal 

Definition at line 34 of file C4Config.h.

34 { ConfigResetSafetyVal = 42 };
@ ConfigResetSafetyVal
Definition: C4Config.h:34

Member Function Documentation

◆ CompileFunc()

void C4ConfigGeneral::CompileFunc ( StdCompiler compiler)

Definition at line 45 of file C4Config.cpp.

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

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

Here is the call graph for this function:

◆ CreateSaveFolder()

bool C4ConfigGeneral::CreateSaveFolder ( const char *  directory,
const char *  language_title 
)

Definition at line 636 of file C4Config.cpp.

637 {
638  // Create directory if needed
639  if (!CreatePath(directory))
640  {
641  return false;
642  }
643  // Create title component if needed
644  char language[3]; SCopy(Config.General.Language, language, 2);
645  StdStrBuf title_file; title_file.Format("%s%c%s", directory, DirectorySeparator, C4CFN_WriteTitle);
646  StdStrBuf title_data; title_data.Format("%s:%s", language, language_title);
647 
648  CStdFile file;
649  if (!FileExists(title_file.getData()))
650  {
651  if (!file.Create(title_file.getData()) || !file.WriteString(title_data.getData()) || !file.Close())
652  {
653  return false;
654  }
655  }
656  // Save folder seems okay
657  return true;
658 }
#define C4CFN_WriteTitle
Definition: C4Components.h:83
C4Config Config
Definition: C4Config.cpp:930
#define DirectorySeparator
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:656
bool FileExists(const char *szFileName)
C4ConfigGeneral General
Definition: C4Config.h:255
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:151
bool Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:49
bool WriteString(const char *szStr)
Definition: CStdFile.cpp:264
const char * getData() const
Definition: StdBuf.h:442
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DefaultLanguage()

void C4ConfigGeneral::DefaultLanguage ( )

Definition at line 774 of file C4Config.cpp.

775 {
776  // No language defined: default to German or English by system language
777  if (!Language[0])
778  {
779  if (IsGermanSystem())
780  {
781  SCopy("DE - Deutsch", Language);
782  }
783  else
784  {
785  SCopy("US - English", Language);
786  }
787  }
788  // No fallback sequence defined: use primary language list
789  if (!LanguageEx[0])
790  {
792  }
793 }
bool IsGermanSystem()
Definition: C4AppMac.mm:193
static int GetLanguageSequence(const char *source, char *target)
Definition: C4Config.cpp:817

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

Referenced by C4Config::Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeterminePaths()

void C4ConfigGeneral::DeterminePaths ( )

Definition at line 469 of file C4Config.cpp.

470 {
471 #ifdef _WIN32
472  // Exe path
473  wchar_t apath[CFG_MaxString];
474  if (GetModuleFileNameW(nullptr, apath, CFG_MaxString))
475  {
476  ExePath = StdStrBuf(apath);
480  }
481 
482  // Temp path
483  GetTempPathW(CFG_MaxString,apath);
484  TempPath = StdStrBuf(apath);
485  if (TempPath[0])
486  {
488  }
489 #elif defined(PROC_SELF_EXE)
490  ExePath.SetLength(1024);
491  ssize_t l = readlink(PROC_SELF_EXE, ExePath.getMData(), 1024);
492  if (l < -1)
493  {
494  ExePath.Ref(".");
495  }
496  else
497  {
498  ExePath.SetLength(l);
501  }
502  const char * t = getenv("TMPDIR");
503  if (t)
504  {
505  TempPath = t;
507  }
508  else
509  {
510  TempPath = "/tmp/";
511  }
512 #else
513  // Mac: Just use the working directory as ExePath.
516  TempPath = "/tmp/";
517 #endif
518 
519  // Find system-wide data path
520 #if defined(_WIN32)
521  // Use ExePath: on windows, everything is installed to one directory
523 #elif defined(__APPLE__)
524  SCopy(::Application.GetGameDataPath().c_str(), SystemDataPath);
525 #elif defined(WITH_AUTOMATIC_UPDATE) && defined(WITH_APPDIR_INSTALLATION)
526  // AppDir: layout like normal unix installation, but relative to executable.
527  auto str = FormatString("%s%s", ExePath.getMData(), OC_SYSTEM_DATA_DIR);
528  SCopy(str.getMData(), SystemDataPath);
529 #elif defined(WITH_AUTOMATIC_UPDATE)
530  // WITH_AUTOMATIC_UPDATE builds are our tarball releases and
531  // development snapshots, i.e. where the game data is at the
532  // same location as the executable.
534 #elif defined(OC_SYSTEM_DATA_DIR)
535  SCopy(OC_SYSTEM_DATA_DIR, SystemDataPath);
536 #else
537 #error Please define OC_SYSTEM_DATA_DIR!
538 #endif
540 
541  // Find user-specific data path
542  if (ConfigUserPath[0])
543  {
545  }
546  else
547  {
548 #if defined(_WIN32)
549  SCopy(R"(%APPDATA%\)" C4ENGINENAME, UserDataPath);
550 #elif defined(__APPLE__)
551  SCopy("$HOME/Library/Application Support/" C4ENGINENAME, UserDataPath);
552 #else
553  SCopy("$HOME/.clonk/" C4ENGINENICK, UserDataPath);
554 #endif
555  }
558 
559  // Screenshot path
561  if (ScreenshotFolder.getLength() + std::strlen(ScreenshotPath) + 1 <= CFG_MaxString)
562  {
565  }
566  // Mods path
568  if (ModsFolder.getLength() + std::strlen(ModsDataPath) + 1 <= CFG_MaxString)
569  {
572  }
573  // Create user path if it doesn't already exist
575 }
@ CFG_MaxString
Definition: C4Config.h:28
C4Application Application
Definition: C4Globals.cpp:44
ptrdiff_t ssize_t
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:263
size_t SLen(const char *sptr)
Definition: Standard.h:74
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
bool TruncatePath(char *szPath)
Definition: StdFile.cpp:237
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:186
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:254
const char * GetWorkingDirectory()
Definition: StdFile.cpp:627
StdCopyStrBuf ExePath
Definition: C4Config.h:54
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:58
StdCopyStrBuf TempPath
Definition: C4Config.h:55
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
char ScreenshotPath[CFG_MaxString+1]
Definition: C4Config.h:59
static void ExpandEnvironmentVariables(char *path, size_t max_length)
Definition: C4Config.cpp:883
void SetLength(size_t iLength)
Definition: StdBuf.h:509
void Ref(const char *pnData)
Definition: StdBuf.h:455
char * getMData()
Definition: StdBuf.h:443
void AppendBackslash()
Definition: StdBuf.cpp:248
size_t getLength() const
Definition: StdBuf.h:445

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

Referenced by C4Config::Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLanguageSequence()

int C4ConfigGeneral::GetLanguageSequence ( const char *  source,
char *  target 
)
static

Definition at line 817 of file C4Config.cpp.

818 {
819  // Copy a condensed list of language codes from the source list to the target string,
820  // skipping any whitespace or long language descriptions. Language sequences are
821  // comma separated.
822  int count = 0;
823  char language[2 + 1];
824  for (int i = 0; SCopySegment(source, i, language, ',', 2, true); i++)
825  {
826  if (language[0])
827  {
828  if (target[0]) SAppendChar(',', target);
829  SAppend(language, target);
830  count++;
831  }
832  }
833  return count;
834 }
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:279
void SAppendChar(char cChar, char *szStr)
Definition: Standard.cpp:271

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

Referenced by DefaultLanguage().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ AlwaysDebug

int32_t C4ConfigGeneral::AlwaysDebug

Definition at line 40 of file C4Config.h.

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

◆ ConfigResetSafety

int32_t C4ConfigGeneral::ConfigResetSafety

Definition at line 52 of file C4Config.h.

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

◆ ConfigUserPath

char C4ConfigGeneral::ConfigUserPath[CFG_MaxString+1]

Definition at line 44 of file C4Config.h.

Referenced by CompileFunc(), and DeterminePaths().

◆ DebugRec

◆ DebugRecExternalFile

char C4ConfigGeneral::DebugRecExternalFile[_MAX_PATH_LEN]

◆ DebugRecWrite

int32_t C4ConfigGeneral::DebugRecWrite

Definition at line 64 of file C4Config.h.

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

◆ DefRec

int32_t C4ConfigGeneral::DefRec

◆ ExePath

◆ FirstStart

bool C4ConfigGeneral::FirstStart

Definition at line 62 of file C4Config.h.

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

◆ FPS

int32_t C4ConfigGeneral::FPS

◆ GamepadEnabled

bool C4ConfigGeneral::GamepadEnabled

Definition at line 61 of file C4Config.h.

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

◆ Language

char C4ConfigGeneral::Language[CFG_MaxString+1]

◆ LanguageEx

◆ MissionAccess

◆ MMTimer

int32_t C4ConfigGeneral::MMTimer

Definition at line 50 of file C4Config.h.

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

◆ ModsDataPath

char C4ConfigGeneral::ModsDataPath[CFG_MaxString+1]

◆ ModsFolder

StdStrBuf C4ConfigGeneral::ModsFolder

Definition at line 46 of file C4Config.h.

Referenced by CompileFunc(), and DeterminePaths().

◆ Name

char C4ConfigGeneral::Name[CFG_MaxString+1]

Definition at line 36 of file C4Config.h.

Referenced by CompileFunc().

◆ OpenScenarioInGameMode

int32_t C4ConfigGeneral::OpenScenarioInGameMode

Definition at line 41 of file C4Config.h.

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

◆ Participants

◆ RXFontName

char C4ConfigGeneral::RXFontName[CFG_MaxString+1]

◆ RXFontSize

int32_t C4ConfigGeneral::RXFontSize

◆ ScreenshotFolder

StdStrBuf C4ConfigGeneral::ScreenshotFolder

Definition at line 45 of file C4Config.h.

Referenced by CompileFunc(), and DeterminePaths().

◆ ScreenshotPath

char C4ConfigGeneral::ScreenshotPath[CFG_MaxString+1]

Definition at line 59 of file C4Config.h.

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

◆ ScrollSmooth

int32_t C4ConfigGeneral::ScrollSmooth

Definition at line 51 of file C4Config.h.

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

◆ SystemDataPath

◆ TempPath

StdCopyStrBuf C4ConfigGeneral::TempPath

Definition at line 55 of file C4Config.h.

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

◆ TempUpdatePath

char C4ConfigGeneral::TempUpdatePath[CFG_MaxString+1]

◆ UserDataPath


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