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

#include <C4Config.h>

Collaboration diagram for C4Config:
[legend]

Public Member Functions

 C4Config ()
 
 ~C4Config ()
 
const char * GetSubkeyPath (const char *strSubkey)
 
void Default ()
 
bool Save ()
 
bool Load (const char *szConfigFile=nullptr)
 
bool Init ()
 
bool Registered ()
 
const char * AtExePath (const char *szFilename)
 
const char * AtTempPath (const char *szFilename)
 
const char * AtTempUpdatePath (const char *szFilename)
 
const char * AtNetworkPath (const char *szFilename)
 
const char * AtScreenshotPath (const char *szFilename)
 
const char * AtUserDataPath (const char *szFilename)
 
const char * AtUserDataRelativePath (const char *szFilename)
 
const char * AtSystemDataPath (const char *szFilename)
 
const char * AtSystemDataRelativePath (const char *szFilename)
 
const char * AtRelativePath (const char *szFilename)
 
const char * GetRegistrationData (const char *strField)
 
void ForceRelativePath (StdStrBuf *sFilename)
 
void CompileFunc (StdCompiler *pComp)
 
bool IsCorrupted ()
 
bool RemoveModule (const char *szPath, char *szModules)
 
bool IsModule (const char *szPath, char *szModules)
 
bool AddModule (const char *szPath, char *szModules)
 
void GetConfigFileName (StdStrBuf &filename, const char *szConfigFile)
 
void CleanupTempUpdateFolder ()
 
const char * MakeTempUpdateFolder ()
 

Static Public Member Functions

static void ExpandEnvironmentVariables (char *strPath, size_t iMaxLen)
 

Public Attributes

C4ConfigGeneral General
 
C4ConfigDeveloper Developer
 
C4ConfigGraphics Graphics
 
C4ConfigSound Sound
 
C4ConfigNetwork Network
 
C4ConfigLobby Lobby
 
C4ConfigIRC IRC
 
C4ConfigGamepad Gamepads [C4ConfigMaxGamepads]
 
C4ConfigControls Controls
 
C4ConfigStartup Startup
 
C4ConfigSecurity Security
 
bool fConfigLoaded
 
StdStrBuf ConfigFilename
 

Detailed Description

Definition at line 245 of file C4Config.h.

Constructor & Destructor Documentation

C4Config::C4Config ( )
default

Definition at line 273 of file C4Config.cpp.

References Default().

274 {
275  Default();
276 }
void Default()
Definition: C4Config.cpp:283

Here is the call graph for this function:

C4Config::~C4Config ( )
default

Definition at line 278 of file C4Config.cpp.

References fConfigLoaded.

279 {
280  fConfigLoaded = false;
281 }
bool fConfigLoaded
Definition: C4Config.h:262

Member Function Documentation

bool C4Config::AddModule ( const char *  szPath,
char *  szModules 
)

Definition at line 771 of file C4Config.cpp.

References SAddModule().

772 {
773  return SAddModule(szModules,szPath);
774 }
bool SAddModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:557

Here is the call graph for this function:

const char * C4Config::AtExePath ( const char *  szFilename)

Definition at line 519 of file C4Config.cpp.

References _MAX_PATH, C4ConfigGeneral::ExePath, General, StdStrBuf::getData(), SAppend(), and SCopy().

520 {
521  SCopy(General.ExePath.getData(),AtPathFilename,_MAX_PATH);
522  SAppend(szFilename,AtPathFilename,_MAX_PATH);
523  return AtPathFilename;
524 }
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
C4ConfigGeneral General
Definition: C4Config.h:251
#define _MAX_PATH
StdCopyStrBuf ExePath
Definition: C4Config.h:52

Here is the call graph for this function:

const char * C4Config::AtNetworkPath ( const char *  szFilename)

Definition at line 547 of file C4Config.cpp.

References _MAX_PATH, General, Network, SAppend(), SCopy(), C4ConfigGeneral::UserDataPath, and C4ConfigNetwork::WorkPath.

Referenced by C4Network2::CreateDynamic(), C4Network2ResList::CreateNetworkFolder(), and C4Network2ResList::FindTempResFileName().

548 {
549  SCopy(General.UserDataPath,AtPathFilename,_MAX_PATH);
550  SAppend(Network.WorkPath,AtPathFilename,_MAX_PATH);
551  SAppend(szFilename,AtPathFilename,_MAX_PATH);
552  return AtPathFilename;
553 }
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
C4ConfigGeneral General
Definition: C4Config.h:251
#define _MAX_PATH
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:54
C4ConfigNetwork Network
Definition: C4Config.h:255
char WorkPath[CFG_MaxString+1]
Definition: C4Config.h:145

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::AtRelativePath ( const char *  szFilename)

Definition at line 656 of file C4Config.cpp.

References General, GetRelativePathS(), C4ConfigGeneral::SystemDataPath, and C4ConfigGeneral::UserDataPath.

Referenced by C4ComponentHost::CopyFilePathFromGroup(), C4DefList::GetByPath(), C4Language::GetPackGroups(), C4GameLobby::MainDlg::OnClientAddPlayer(), C4StartupPlrPropertiesDlg::OnClosed(), C4StartupMainDlg::OnPlayerSelContextAdd(), C4StartupMainDlg::OnShown(), C4Shader::Refresh(), C4Game::ReloadFile(), C4Player::Save(), C4Network2Res::SetByFile(), C4Network2Res::SetByGroup(), and C4GameSave::WriteDescDefinitions().

657 {
658  const char *szPath = GetRelativePathS(szFilename, General.UserDataPath);
659  if (szPath == szFilename)
660  return GetRelativePathS(szFilename, General.SystemDataPath);
661  return szPath;
662 }
C4ConfigGeneral General
Definition: C4Config.h:251
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:54
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:211

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::AtScreenshotPath ( const char *  szFilename)

Definition at line 555 of file C4Config.cpp.

References _MAX_PATH, AppendBackslash(), CreatePath(), DirectorySeparator, General, SAppend(), SCopy(), C4ConfigGeneral::ScreenshotPath, SLen(), and C4ConfigGeneral::UserDataPath.

Referenced by C4GraphicsSystem::SaveScreenshot().

556 {
557  int len;
558  SCopy(General.ScreenshotPath,AtPathFilename,_MAX_PATH);
559  if ((len = SLen(AtPathFilename)))
560  if (AtPathFilename[len-1] == DirectorySeparator)
561  AtPathFilename[len-1] = '\0';
562  if (!CreatePath(AtPathFilename))
563  {
564  SCopy(General.UserDataPath,AtPathFilename,_MAX_PATH);
565  }
566  AppendBackslash(AtPathFilename);
567  SAppend(szFilename,AtPathFilename,_MAX_PATH);
568  return AtPathFilename;
569 }
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
C4ConfigGeneral General
Definition: C4Config.h:251
#define _MAX_PATH
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
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:54
#define DirectorySeparator

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::AtSystemDataPath ( const char *  szFilename)

Definition at line 533 of file C4Config.cpp.

References _MAX_PATH, General, SAppend(), SCopy(), and C4ConfigGeneral::SystemDataPath.

Referenced by C4MusicSystem::Init().

534 {
535  SCopy(General.SystemDataPath, AtPathFilename, _MAX_PATH);
536  SAppend(szFilename, AtPathFilename, _MAX_PATH);
537  return AtPathFilename;
538 }
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
C4ConfigGeneral General
Definition: C4Config.h:251
#define _MAX_PATH
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::AtSystemDataRelativePath ( const char *  szFilename)

Definition at line 650 of file C4Config.cpp.

References General, GetRelativePathS(), and C4ConfigGeneral::SystemDataPath.

651 {
652  // Specified file is located in SystemDataPath: return relative path
653  return GetRelativePathS(szFilename, General.SystemDataPath);
654 }
C4ConfigGeneral General
Definition: C4Config.h:251
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:211

Here is the call graph for this function:

const char * C4Config::AtTempPath ( const char *  szFilename)

Definition at line 540 of file C4Config.cpp.

References _MAX_PATH, General, StdStrBuf::getData(), SAppend(), SCopy(), and C4ConfigGeneral::TempPath.

Referenced by C4ControlJoinPlayer::C4ControlJoinPlayer(), C4ControlReInitScenario::C4ControlReInitScenario(), C4StartupNetDlg::DoOK(), C4ScenarioSection::EnsureTempStore(), C4MusicFile::ExtractFile(), MakeTempUpdateFolder(), C4MusicFileSDL::Play(), C4PlayerInfoList::RecreatePlayerFiles(), C4MusicFile::RemTempFile(), C4PlayerList::Save(), C4PXSSystem::Save(), C4Player::Save(), C4Landscape::P::SaveDiffInternal(), C4Game::SaveGameTitle(), C4Landscape::P::SaveInternal(), C4Landscape::SaveMap(), C4Landscape::SaveTextures(), and C4ControlJoinPlayer::Strip().

541 {
542  SCopy(General.TempPath.getData(),AtPathFilename,_MAX_PATH);
543  SAppend(szFilename,AtPathFilename,_MAX_PATH);
544  return AtPathFilename;
545 }
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
C4ConfigGeneral General
Definition: C4Config.h:251
#define _MAX_PATH
StdCopyStrBuf TempPath
Definition: C4Config.h:53

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::AtTempUpdatePath ( const char *  szFilename)

Definition at line 825 of file C4Config.cpp.

References _MAX_PATH, AppendBackslash(), General, SAppend(), SCopy(), and C4ConfigGeneral::TempUpdatePath.

826 {
827  SCopy(General.TempUpdatePath,AtPathFilename,_MAX_PATH-1);
828  AppendBackslash(AtPathFilename);
829  SAppend(szFilename,AtPathFilename,_MAX_PATH);
830  return AtPathFilename;
831 }
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
C4ConfigGeneral General
Definition: C4Config.h:251
#define _MAX_PATH
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:257
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:57

Here is the call graph for this function:

const char * C4Config::AtUserDataPath ( const char *  szFilename)

Definition at line 526 of file C4Config.cpp.

References _MAX_PATH, General, SAppend(), SCopy(), and C4ConfigGeneral::UserDataPath.

Referenced by C4MainMenu::ActivateSavegame(), C4StartupPlrSelDlg::CheckPlayerName(), C4MusicSystem::Init(), C4Player::Init(), C4StartupPlrSelDlg::PlayerListItem::Load(), C4MusicSystem::LoadMoreMusic(), C4StartupPlrPropertiesDlg::OnClosed(), OpenExtraLogs(), OpenLog(), C4MessageInput::ProcessCommand(), C4Game::QuickSave(), C4Record::Start(), and C4StartupPlrSelDlg::PlayerListItem::UpdateCore().

527 {
528  SCopy(General.UserDataPath, AtPathFilename, _MAX_PATH);
529  SAppend(szFilename, AtPathFilename, _MAX_PATH);
530  return AtPathFilename;
531 }
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
C4ConfigGeneral General
Definition: C4Config.h:251
#define _MAX_PATH
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:54

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::AtUserDataRelativePath ( const char *  szFilename)

Definition at line 644 of file C4Config.cpp.

References General, GetRelativePathS(), and C4ConfigGeneral::UserDataPath.

Referenced by C4GraphicsSystem::SaveScreenshot().

645 {
646  // Specified file is located in UserDataPath: return relative path
647  return GetRelativePathS(szFilename, General.UserDataPath);
648 }
C4ConfigGeneral General
Definition: C4Config.h:251
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:54
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:211

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Config::CleanupTempUpdateFolder ( )

Definition at line 804 of file C4Config.cpp.

References EraseItem(), General, and C4ConfigGeneral::TempUpdatePath.

Referenced by C4Application::DoInit().

805 {
806  // Get rid of update path present from before update
807  if (*General.TempUpdatePath)
808  {
810  *General.TempUpdatePath = '\0';
811  }
812 }
C4ConfigGeneral General
Definition: C4Config.h:251
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:57
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Config::CompileFunc ( StdCompiler pComp)

Definition at line 755 of file C4Config.cpp.

References C4ConfigMaxGamepads, Controls, Developer, FormatString(), Gamepads, General, Graphics, IRC, Lobby, mkNamingAdapt(), Network, Security, Sound, Startup, and StdCompiler::Value().

756 {
757  pComp->Value(mkNamingAdapt(General, "General" ));
758  pComp->Value(mkNamingAdapt(Controls, "Controls" ));
759  for (int i=0; i<C4ConfigMaxGamepads; ++i)
760  pComp->Value(mkNamingAdapt(Gamepads[i], FormatString("Gamepad%d", i).getData()));
761  pComp->Value(mkNamingAdapt(Graphics, "Graphics" ));
762  pComp->Value(mkNamingAdapt(Sound, "Sound" ));
763  pComp->Value(mkNamingAdapt(Network, "Network" ));
764  pComp->Value(mkNamingAdapt(Lobby, "Lobby" ));
765  pComp->Value(mkNamingAdapt(IRC, "IRC" ));
766  pComp->Value(mkNamingAdapt(Developer, "Developer" ));
767  pComp->Value(mkNamingAdapt(Startup, "Startup" ));
768  pComp->Value(mkNamingAdapt(Security, "Security" ));
769 }
C4ConfigStartup Startup
Definition: C4Config.h:260
C4ConfigGeneral General
Definition: C4Config.h:251
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4ConfigGraphics Graphics
Definition: C4Config.h:253
C4ConfigLobby Lobby
Definition: C4Config.h:256
C4ConfigIRC IRC
Definition: C4Config.h:257
C4ConfigNetwork Network
Definition: C4Config.h:255
C4ConfigDeveloper Developer
Definition: C4Config.h:252
void Value(const T &rStruct)
Definition: StdCompiler.h:161
C4ConfigControls Controls
Definition: C4Config.h:259
C4ConfigSecurity Security
Definition: C4Config.h:261
C4ConfigGamepad Gamepads[C4ConfigMaxGamepads]
Definition: C4Config.h:258
C4ConfigSound Sound
Definition: C4Config.h:254
const int C4ConfigMaxGamepads
Definition: C4Config.h:213
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

void C4Config::Default ( )

Definition at line 283 of file C4Config.cpp.

References StdCompiler::Compile(), and fConfigLoaded.

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

284 {
285  // force default values
286  StdCompilerNull Comp; Comp.Compile(*this);
287  fConfigLoaded=false;
288 }
void Compile(T &&rStruct)
Definition: StdCompiler.h:173
bool fConfigLoaded
Definition: C4Config.h:262

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Config::ExpandEnvironmentVariables ( char *  strPath,
size_t  iMaxLen 
)
static

Definition at line 786 of file C4Config.cpp.

References _MAX_PATH, StdStrBuf::getData(), StdStrBuf::getLength(), GetWideChar(), SCopy(), SLen(), and SSearch().

Referenced by C4ConfigGeneral::DeterminePaths().

787 {
788 #ifdef _WIN32
789  wchar_t buf[_MAX_PATH + 1];
790  ExpandEnvironmentStringsW(GetWideChar(strPath), buf, _MAX_PATH);
791  SCopy(StdStrBuf(buf).getData(), strPath, iMaxLen);
792 #else // __linux__ or __APPLE___
793  StdStrBuf home(getenv("HOME"));
794  char* rest;
795  if (home && (rest = const_cast<char *>(SSearch(strPath, "$HOME"))) && (std::strlen(strPath) - 5 + home.getLength() <= iMaxLen))
796  {
797  // String replace... there might be a more elegant way to do this.
798  memmove(rest + home.getLength() - SLen("$HOME"), rest, SLen(rest) + 1);
799  strncpy(rest - SLen("$HOME"), home.getData(), home.getLength());
800  }
801 #endif
802 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:363
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:74

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Config::ForceRelativePath ( StdStrBuf sFilename)

Definition at line 664 of file C4Config.cpp.

References StdStrBuf::Copy(), General, GetC4Filename(), StdStrBuf::getData(), GetRelativePathS(), IsGlobalPath(), C4ConfigGeneral::SystemDataPath, and StdStrBuf::Take().

665 {
666  assert(sFilename);
667  // Specified file is located in SystemDataPath?
668  const char *szRelative = GetRelativePathS(sFilename->getData(), General.SystemDataPath);
669  if (szRelative != sFilename->getData())
670  {
671  // return relative path
672  StdStrBuf sTemp; sTemp.Copy(szRelative);
673  sFilename->Take(std::move(sTemp));
674  }
675  else
676  {
677  // not in ExePath: Is it a global path?
678  if (IsGlobalPath(sFilename->getData()))
679  {
680  // then shorten it (e.g. C:\Temp\Missions.ocf\Goldmine.ocs to Missions.ocf\Goldmine.ocs)
681  StdStrBuf sTemp; sTemp.Copy(GetC4Filename(sFilename->getData()));
682  sFilename->Take(std::move(sTemp));
683  }
684  }
685 }
const char * getData() const
Definition: StdBuf.h:442
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:227
C4ConfigGeneral General
Definition: C4Config.h:251
const char * GetC4Filename(const char *szPath)
Definition: StdFile.cpp:71
void Take(char *pnData)
Definition: StdBuf.h:457
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
void Copy()
Definition: StdBuf.h:467
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:211

Here is the call graph for this function:

void C4Config::GetConfigFileName ( StdStrBuf filename,
const char *  szConfigFile 
)

Definition at line 290 of file C4Config.cpp.

References StdStrBuf::Copy(), and StdStrBuf::Ref().

Referenced by Load(), and Save().

291 {
292  if (szConfigFile)
293  {
294  // Config filename is specified
295  filename.Ref(szConfigFile);
296  }
297  else
298  {
299  // Config filename from home
300  StdStrBuf home(getenv("HOME"));
301  if (home) { home += "/"; }
302  filename.Copy(home);
303 #ifdef __APPLE__
304  filename += "Library/Preferences/" C4ENGINEID ".config";
305 #else
306  filename += ".clonk/" C4ENGINENICK "/config";
307 #endif
308  }
309 }
void Ref(const char *pnData)
Definition: StdBuf.h:455
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4Config::GetRegistrationData ( const char *  strField)
inline

Definition at line 281 of file C4Config.h.

Referenced by C4ClientPlayerInfos::C4ClientPlayerInfos(), C4StartupOptionsDlg::C4StartupOptionsDlg(), C4StartupOptionsDlg::SaveConfig(), and C4ClientCore::SetLocal().

281 { return ""; }

Here is the caller graph for this function:

const char * C4Config::GetSubkeyPath ( const char *  strSubkey)

Definition at line 713 of file C4Config.cpp.

References sprintf.

Referenced by ConsoleDlgProc(), DialogWinProc(), C4ViewportWindow::Init(), C4GUI::DialogWindow::Init(), C4Game::PreInit(), PropertyDlgProc(), ToolsDlgProc(), and ViewportWinProc().

714 {
715  static char key[1024 + 1];
716 #ifdef _WIN32
717  sprintf(key, R"(Software\%s\%s\%s)", C4CFG_Company, C4ENGINENAME, strSubkey);
718 #else
719  sprintf(key, "%s", strSubkey);
720 #endif
721  return key;
722 }
#define sprintf
Definition: Standard.h:164

Here is the caller graph for this function:

bool C4Config::Init ( )

Definition at line 708 of file C4Config.cpp.

Referenced by C4Application::DoInit().

709 {
710  return true;
711 }

Here is the caller graph for this function:

bool C4Config::IsCorrupted ( )
inline

Definition at line 284 of file C4Config.h.

References C4ConfigGeneral::ConfigResetSafety, C4ConfigGeneral::ConfigResetSafetyVal, and C4ConfigGraphics::ResX.

Referenced by C4Application::DoInit().

C4ConfigGeneral General
Definition: C4Config.h:251
C4ConfigGraphics Graphics
Definition: C4Config.h:253
int32_t ConfigResetSafety
Definition: C4Config.h:50
int32_t ResX
Definition: C4Config.h:103

Here is the caller graph for this function:

bool C4Config::IsModule ( const char *  szPath,
char *  szModules 
)

Definition at line 776 of file C4Config.cpp.

References SIsModule().

777 {
778  return SIsModule(szModules,szPath);
779 }
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:541

Here is the call graph for this function:

bool C4Config::Load ( const char *  szConfigFile = nullptr)

Definition at line 311 of file C4Config.cpp.

References C4NetStdPortDiscovery, C4NetStdPortRefServer, StdStrBuf::Clear(), StdCompiler::Compile(), Config, ConfigFilename, StdStrBuf::Copy(), CreatePath(), C4ConfigGeneral::DefaultLanguage(), C4ConfigGeneral::DeterminePaths(), fConfigLoaded, General, GetConfigFileName(), StdStrBuf::getData(), StdStrBuf::isNull(), StdStrBuf::LoadFromFile(), Log(), LogF(), StdCompiler::Exception::Msg, Network, C4ConfigNetwork::Nick, C4ConfigNetwork::PortDiscovery, C4ConfigNetwork::PortRefServer, C4ConfigNetwork::PortTCP, C4ConfigNetwork::PortUDP, StdStrBuf::Ref(), SEqual(), and StdCompilerINIRead::setInput().

Referenced by C4Application::DoInit().

312 {
313  try
314  {
315 #ifdef _WIN32
316  // Windows: Default load from registry, if no explicit config file is specified
317  if (!szConfigFile)
318  {
319  StdCompilerConfigRead CfgRead(HKEY_CURRENT_USER, "Software\\" C4CFG_Company "\\" C4ENGINENAME);
320  CfgRead.Compile(*this);
321  }
322  else
323 #endif
324  {
325  // Nonwindows or explicit config file: Determine filename to load config from
326  StdStrBuf filename;
327  GetConfigFileName(filename, szConfigFile);
328 
329  // Load config file into buf
330  StdStrBuf buf;
331  buf.LoadFromFile(filename.getData());
332 
333  if (buf.isNull())
334  {
335  // Config file not present?
336 #ifdef __linux__
337  if (!szConfigFile)
338  {
339  StdStrBuf filename(getenv("HOME"));
340  if (filename) { filename += "/"; }
341  filename += ".clonk/" C4ENGINENICK;
342  CreatePath(filename.getData());
343  }
344 #endif
345  // Buggy StdCompiler crashes when compiling a Null-StdStrBuf
346  buf.Ref(" ");
347  }
348 
349  // Read config from buffer
350  StdCompilerINIRead IniRead;
351  IniRead.setInput(buf);
352  IniRead.Compile(*this);
353  }
354  }
355  catch (StdCompiler::Exception *pExc)
356  {
357  // Configuration file syntax error?
358  LogF("Error loading configuration: %s"/*LoadResStr("IDS_ERR_CONFREAD") - restbl not yet loaded*/, pExc->Msg.getData());
359  delete pExc;
360  return false;
361  }
362 
363  // Config postinit
365 #ifdef HAVE_WINSOCK
366  // Setup WS manually, so c4group doesn't depend on C4NetIO
367  WSADATA wsadata;
368  bool fWinSock = !WSAStartup(WINSOCK_VERSION, &wsadata);
369 #endif
370  if (SEqual(Network.Nick.getData(), "Unknown"))
371  {
372  char LocalName[25+1]; *LocalName = 0;
373  gethostname(LocalName, 25);
374  if (*LocalName) Network.Nick.Copy(LocalName);
375  }
376 #ifdef HAVE_WINSOCK
377  if (fWinSock) WSACleanup();
378 #endif
380  // Warning against invalid ports
382  {
383  Log("Warning: Network TCP port and reference server port both set to same value - increasing reference server port!");
386  }
388  {
389  Log("Warning: Network UDP port and LAN game discovery port both set to same value - increasing discovery port!");
392  }
393  // Empty nick already defaults to GetRegistrationData("Nick") or
394  // Network.LocalName at relevant places.
395  fConfigLoaded = true;
396  if (szConfigFile) ConfigFilename.Copy(szConfigFile); else ConfigFilename.Clear();
397  return true;
398 }
const char * getData() const
Definition: StdBuf.h:442
void DefaultLanguage()
Definition: C4Config.cpp:687
C4Config Config
Definition: C4Config.cpp:833
int32_t PortDiscovery
Definition: C4Config.h:153
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
void Clear()
Definition: StdBuf.h:466
C4ConfigGeneral General
Definition: C4Config.h:251
int32_t PortRefServer
Definition: C4Config.h:153
void setInput(const InT &In)
Definition: StdCompiler.h:630
void DeterminePaths()
Definition: C4Config.cpp:430
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
ValidatedStdCopyStrBuf< C4InVal::VAL_NameAllowEmpty > Nick
Definition: C4Config.h:156
void Compile(T &&rStruct)
Definition: StdCompiler.h:173
bool LoadFromFile(const char *szFile)
Definition: StdBuf.cpp:73
const int16_t C4NetStdPortRefServer
Definition: C4Network2.h:32
StdStrBuf ConfigFilename
Definition: C4Config.h:263
const int16_t C4NetStdPortDiscovery
Definition: C4Network2.h:31
C4ConfigNetwork Network
Definition: C4Config.h:255
void Ref(const char *pnData)
Definition: StdBuf.h:455
bool isNull() const
Definition: StdBuf.h:441
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
bool fConfigLoaded
Definition: C4Config.h:262
void GetConfigFileName(StdStrBuf &filename, const char *szConfigFile)
Definition: C4Config.cpp:290
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
void Copy()
Definition: StdBuf.h:467
int32_t PortTCP
Definition: C4Config.h:153
int32_t PortUDP
Definition: C4Config.h:153

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::MakeTempUpdateFolder ( )

Definition at line 814 of file C4Config.cpp.

References AtTempPath(), StdStrBuf::Copy(), CreatePath(), General, StdStrBuf::getData(), MakeTempFilename(), SCopy(), and C4ConfigGeneral::TempUpdatePath.

815 {
816  // just pick a temp name
817  StdStrBuf sTempName;
818  sTempName.Copy(AtTempPath("update"));
819  MakeTempFilename(&sTempName);
820  SCopy(sTempName.getData(), General.TempUpdatePath);
822  return General.TempUpdatePath;
823 }
const char * getData() const
Definition: StdBuf.h:442
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
C4ConfigGeneral General
Definition: C4Config.h:251
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:57
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

bool C4Config::Registered ( )

Definition at line 702 of file C4Config.cpp.

703 {
704  // Dummy function: to be overloaded in C4Config
705  return true;
706 }
bool C4Config::RemoveModule ( const char *  szPath,
char *  szModules 
)

Definition at line 781 of file C4Config.cpp.

References SRemoveModule().

782 {
783  return SRemoveModule(szModules,szPath);
784 }
bool SRemoveModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:582

Here is the call graph for this function:

bool C4Config::Save ( )

Definition at line 400 of file C4Config.cpp.

References ConfigFilename, StdCompiler::Decompile(), GetConfigFileName(), StdStrBuf::getData(), StdStrBuf::getLength(), LoadResStr(), LogF(), and StdCompiler::Exception::Msg.

Referenced by C4Game::DoGameOver(), C4Application::DoInit(), C4Application::Quit(), and C4StartupOptionsDlg::SaveConfig().

401 {
402  try
403  {
404 #ifdef _WIN32
405  if (!ConfigFilename.getLength())
406  {
407  // Windows: Default save to registry, if it wasn't loaded from file
408  StdCompilerConfigWrite CfgWrite(HKEY_CURRENT_USER, "Software\\" C4CFG_Company "\\" C4ENGINENAME);
409  CfgWrite.Decompile(*this);
410  }
411  else
412 #endif
413  {
414  StdStrBuf filename;
416  StdCompilerINIWrite IniWrite;
417  IniWrite.Decompile(*this);
418  IniWrite.getOutput().SaveToFile(filename.getData());
419  }
420  }
421  catch (StdCompiler::Exception *pExc)
422  {
423  LogF(LoadResStr("IDS_ERR_CONFSAVE"), pExc->Msg.getData());
424  delete pExc;
425  return false;
426  }
427  return true;
428 }
const char * getData() const
Definition: StdBuf.h:442
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdStrBuf ConfigFilename
Definition: C4Config.h:263
size_t getLength() const
Definition: StdBuf.h:445
void GetConfigFileName(StdStrBuf &filename, const char *szConfigFile)
Definition: C4Config.cpp:290
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
void Decompile(const T &rStruct)
Definition: StdCompiler.h:178

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

StdStrBuf C4Config::ConfigFilename

Definition at line 263 of file C4Config.h.

Referenced by Load(), and Save().

bool C4Config::fConfigLoaded

Definition at line 262 of file C4Config.h.

Referenced by Default(), Load(), C4Application::Quit(), and ~C4Config().

C4ConfigGamepad C4Config::Gamepads[C4ConfigMaxGamepads]

Definition at line 258 of file C4Config.h.

Referenced by CompileFunc().

C4ConfigGeneral C4Config::General

Definition at line 251 of file C4Config.h.

Referenced by C4Landscape::_SetPix2(), C4MainMenu::ActivateDisplay(), C4MainMenu::ActivateNewPlayer(), C4LSectors::Add(), C4Viewport::AdjustPosition(), C4Object::AssignRemoval(), AtExePath(), AtNetworkPath(), AtRelativePath(), AtScreenshotPath(), AtSystemDataPath(), AtSystemDataRelativePath(), AtTempPath(), AtTempUpdatePath(), AtUserDataPath(), AtUserDataRelativePath(), C4PortraitSelDlg::C4PortraitSelDlg(), C4StartupOptionsDlg::C4StartupOptionsDlg(), C4ScenarioListLoader::Scenario::CanOpen(), C4MassMover::Cease(), C4Playback::Check(), C4MCOverlay::CheckMask(), C4StartupPlrSelDlg::CheckPlayerName(), CleanupTempUpdateFolder(), C4Playback::Clear(), CompileFunc(), C4MassMoverSet::Create(), C4MapFolderData::CreateGUIElements(), C4ConfigGeneral::CreateSaveFolder(), C4GameControl::DbgRec(), C4PXS::Deactivate(), C4AulExec::DirectExec(), C4Application::DoInit(), C4ScenarioListLoader::SubFolder::DoLoadContents(), C4Landscape::P::DoScan(), C4UpperBoard::Draw(), C4Game::DropFile(), C4Game::ExecObjects(), C4PXS::Execute(), C4Game::Execute(), C4Object::Execute(), C4Playback::ExecuteControl(), C4PlayerControl::ExecuteControlPacket(), C4Landscape::P::ExecuteScan(), ForceRelativePath(), C4Game::GetTranslatedString(), C4Reloc::Init(), C4Landscape::Init(), C4Game::Init(), C4Player::InitControl(), C4Game::InitDefs(), C4StartupGraphics::InitFonts(), C4GraphicsResource::InitFonts(), C4Game::InitGame(), C4Game::InitScriptEngine(), C4StartupScenSelDlg::KeyCheat2(), C4DefList::Load(), C4ScenarioListLoader::Entry::Load(), Load(), C4MapFolderData::Load(), C4Game::LoadAdditionalSystemGroup(), C4ScenarioListLoader::Scenario::LoadCustomPre(), MakeTempUpdateFolder(), C4MainMenu::MenuCommand(), C4StartupPlrSelDlg::PlayerListItem::MoveFilename(), C4Game::NewObject(), C4StartupNetDlg::OnBtnRecord(), C4GameOptionButtons::OnBtnRecord(), C4StartupPlrPropertiesDlg::OnClosed(), C4StartupPlrSelDlg::OnDelBtnConfirm(), C4StartupMainDlg::OnPlayerSelContextAdd(), C4StartupMainDlg::OnPlayerSelContextAddPlr(), C4StartupMainDlg::OnPlayerSelContextRemove(), C4StartupMainDlg::OnPlayerSelContextRemovePlr(), C4StartupMainDlg::OnShown(), C4Playback::Open(), C4Game::OpenScenario(), C4Application::ParseCommandLine(), C4Application::PreInit(), C4MessageInput::ProcessCommand(), C4Network2HTTPClient::Query(), C4Game::QuickSave(), RecordRandom(), C4Game::ReloadDef(), C4Game::ReloadFile(), C4LSectors::Remove(), C4GameControl::RequestRuntimeRecord(), RestartApplication(), C4Shape::Rotate(), C4GameSave::SaveDesc(), C4ScenarioSection::ScenarioLoad(), C4Network2Res::SetByCore(), C4Application::SetGameFont(), C4ClientCore::SetLocal(), C4Object::SetOCF(), C4ScenarioListLoader::Entry::SetTitleInGroup(), C4Record::Start(), C4Record::Stop(), C4LSectors::Update(), C4Game::UpdateLanguage(), C4Object::UpdateOCF(), and C4StartupMainDlg::UpdateParticipants().

C4ConfigLobby C4Config::Lobby
C4ConfigSecurity C4Config::Security

Definition at line 261 of file C4Config.h.

Referenced by CompileFunc().


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