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

Constructor & Destructor Documentation

C4Config::C4Config ( )

Definition at line 277 of file C4Config.cpp.

References Default().

278 {
279  Default();
280 }
void Default()
Definition: C4Config.cpp:287

Here is the call graph for this function:

C4Config::~C4Config ( )

Definition at line 282 of file C4Config.cpp.

References fConfigLoaded.

283 {
284  fConfigLoaded = false;
285 }
bool fConfigLoaded
Definition: C4Config.h:263

Member Function Documentation

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

Definition at line 775 of file C4Config.cpp.

References SAddModule().

776 {
777  return SAddModule(szModules,szPath);
778 }
bool SAddModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:527

Here is the call graph for this function:

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

Definition at line 523 of file C4Config.cpp.

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

524 {
525  SCopy(General.ExePath.getData(),AtPathFilename,_MAX_PATH);
526  SAppend(szFilename,AtPathFilename,_MAX_PATH);
527  return AtPathFilename;
528 }
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
C4ConfigGeneral General
Definition: C4Config.h:252
#define _MAX_PATH
StdCopyStrBuf ExePath
Definition: C4Config.h:53

Here is the call graph for this function:

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

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

552 {
553  SCopy(General.UserDataPath,AtPathFilename,_MAX_PATH);
554  SAppend(Network.WorkPath,AtPathFilename,_MAX_PATH);
555  SAppend(szFilename,AtPathFilename,_MAX_PATH);
556  return AtPathFilename;
557 }
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
C4ConfigGeneral General
Definition: C4Config.h:252
#define _MAX_PATH
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
C4ConfigNetwork Network
Definition: C4Config.h:256
char WorkPath[CFG_MaxString+1]
Definition: C4Config.h:146

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

661 {
662  const char *szPath = GetRelativePathS(szFilename, General.UserDataPath);
663  if (szPath == szFilename)
664  return GetRelativePathS(szFilename, General.SystemDataPath);
665  return szPath;
666 }
C4ConfigGeneral General
Definition: C4Config.h:252
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:221

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 559 of file C4Config.cpp.

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

Referenced by C4GraphicsSystem::SaveScreenshot().

560 {
561  int len;
562  SCopy(General.ScreenshotPath,AtPathFilename,_MAX_PATH);
563  if ((len = SLen(AtPathFilename)))
564  if (AtPathFilename[len-1] == DirectorySeparator)
565  AtPathFilename[len-1] = '\0';
566  if (!CreatePath(AtPathFilename))
567  {
568  SCopy(General.UserDataPath,AtPathFilename,_MAX_PATH);
569  }
570  AppendBackslash(AtPathFilename);
571  SAppend(szFilename,AtPathFilename,_MAX_PATH);
572  return AtPathFilename;
573 }
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
C4ConfigGeneral General
Definition: C4Config.h:252
#define _MAX_PATH
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
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
#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 537 of file C4Config.cpp.

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

Referenced by C4MusicSystem::Init().

538 {
539  SCopy(General.SystemDataPath, AtPathFilename, _MAX_PATH);
540  SAppend(szFilename, AtPathFilename, _MAX_PATH);
541  return AtPathFilename;
542 }
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
C4ConfigGeneral General
Definition: C4Config.h:252
#define _MAX_PATH
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56

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 654 of file C4Config.cpp.

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

655 {
656  // Specified file is located in SystemDataPath: return relative path
657  return GetRelativePathS(szFilename, General.SystemDataPath);
658 }
C4ConfigGeneral General
Definition: C4Config.h:252
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:221

Here is the call graph for this function:

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

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

545 {
546  SCopy(General.TempPath.getData(),AtPathFilename,_MAX_PATH);
547  SAppend(szFilename,AtPathFilename,_MAX_PATH);
548  return AtPathFilename;
549 }
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
C4ConfigGeneral General
Definition: C4Config.h:252
#define _MAX_PATH
StdCopyStrBuf TempPath
Definition: C4Config.h:54

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 829 of file C4Config.cpp.

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

830 {
831  SCopy(General.TempUpdatePath,AtPathFilename,_MAX_PATH-1);
832  AppendBackslash(AtPathFilename);
833  SAppend(szFilename,AtPathFilename,_MAX_PATH);
834  return AtPathFilename;
835 }
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
C4ConfigGeneral General
Definition: C4Config.h:252
#define _MAX_PATH
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:267
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:58

Here is the call graph for this function:

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

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

531 {
532  SCopy(General.UserDataPath, AtPathFilename, _MAX_PATH);
533  SAppend(szFilename, AtPathFilename, _MAX_PATH);
534  return AtPathFilename;
535 }
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
C4ConfigGeneral General
Definition: C4Config.h:252
#define _MAX_PATH
char UserDataPath[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::AtUserDataRelativePath ( const char *  szFilename)

Definition at line 648 of file C4Config.cpp.

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

Referenced by C4GraphicsSystem::SaveScreenshot().

649 {
650  // Specified file is located in UserDataPath: return relative path
651  return GetRelativePathS(szFilename, General.UserDataPath);
652 }
C4ConfigGeneral General
Definition: C4Config.h:252
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:221

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Config::CleanupTempUpdateFolder ( )

Definition at line 808 of file C4Config.cpp.

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

Referenced by C4Application::DoInit().

809 {
810  // Get rid of update path present from before update
811  if (*General.TempUpdatePath)
812  {
814  *General.TempUpdatePath = '\0';
815  }
816 }
C4ConfigGeneral General
Definition: C4Config.h:252
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:58
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:819

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Config::CompileFunc ( StdCompiler pComp)

Definition at line 759 of file C4Config.cpp.

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

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

Here is the call graph for this function:

void C4Config::Default ( )

Definition at line 287 of file C4Config.cpp.

References StdCompiler::Compile(), and fConfigLoaded.

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

288 {
289  // force default values
290  StdCompilerNull Comp; Comp.Compile(*this);
291  fConfigLoaded=false;
292 }
void Compile(T &&rStruct)
Definition: StdCompiler.h:183
bool fConfigLoaded
Definition: C4Config.h:263

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 790 of file C4Config.cpp.

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

Referenced by C4ConfigGeneral::DeterminePaths().

791 {
792 #ifdef _WIN32
793  wchar_t buf[_MAX_PATH + 1];
794  ExpandEnvironmentStringsW(GetWideChar(strPath), buf, _MAX_PATH);
795  SCopy(StdStrBuf(buf).getData(), strPath, iMaxLen);
796 #else // __linux__ or __APPLE___
797  StdStrBuf home(getenv("HOME"));
798  char* rest;
799  if (home && (rest = const_cast<char *>(SSearch(strPath, "$HOME"))) && (std::strlen(strPath) - 5 + home.getLength() <= iMaxLen))
800  {
801  // String replace... there might be a more elegant way to do this.
802  memmove(rest + home.getLength() - SLen("$HOME"), rest, SLen(rest) + 1);
803  strncpy(rest - SLen("$HOME"), home.getData(), home.getLength());
804  }
805 #endif
806 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
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:333
#define _MAX_PATH
size_t SLen(const char *sptr)
Definition: Standard.h:78

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Config::ForceRelativePath ( StdStrBuf sFilename)

Definition at line 668 of file C4Config.cpp.

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

669 {
670  assert(sFilename);
671  // Specified file is located in SystemDataPath?
672  const char *szRelative = GetRelativePathS(sFilename->getData(), General.SystemDataPath);
673  if (szRelative != sFilename->getData())
674  {
675  // return relative path
676  StdStrBuf sTemp; sTemp.Copy(szRelative);
677  sFilename->Take(std::move(sTemp));
678  }
679  else
680  {
681  // not in ExePath: Is it a global path?
682  if (IsGlobalPath(sFilename->getData()))
683  {
684  // then shorten it (e.g. C:\Temp\Missions.ocf\Goldmine.ocs to Missions.ocf\Goldmine.ocs)
685  StdStrBuf sTemp; sTemp.Copy(GetC4Filename(sFilename->getData()));
686  sFilename->Take(std::move(sTemp));
687  }
688  }
689 }
const char * getData() const
Definition: StdBuf.h:450
bool IsGlobalPath(const char *szPath)
Definition: StdFile.cpp:237
C4ConfigGeneral General
Definition: C4Config.h:252
const char * GetC4Filename(const char *szPath)
Definition: StdFile.cpp:81
void Take(char *pnData)
Definition: StdBuf.h:465
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
void Copy()
Definition: StdBuf.h:475
const char * GetRelativePathS(const char *strPath, const char *strRelativeTo)
Definition: StdFile.cpp:221

Here is the call graph for this function:

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

Definition at line 294 of file C4Config.cpp.

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

Referenced by Load(), and Save().

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

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

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

282 { return ""; }

Here is the caller graph for this function:

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

Definition at line 717 of file C4Config.cpp.

References sprintf.

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

718 {
719  static char key[1024 + 1];
720 #ifdef _WIN32
721  sprintf(key, "Software\\%s\\%s\\%s", C4CFG_Company, C4ENGINENAME, strSubkey);
722 #else
723  sprintf(key, "%s", strSubkey);
724 #endif
725  return key;
726 }
#define sprintf
Definition: Standard.h:171

Here is the caller graph for this function:

bool C4Config::Init ( )

Definition at line 712 of file C4Config.cpp.

Referenced by C4Application::DoInit().

713 {
714  return true;
715 }

Here is the caller graph for this function:

bool C4Config::IsCorrupted ( )
inline

Definition at line 285 of file C4Config.h.

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

Referenced by C4Application::DoInit().

C4ConfigGeneral General
Definition: C4Config.h:252
C4ConfigGraphics Graphics
Definition: C4Config.h:254
int32_t ConfigResetSafety
Definition: C4Config.h:51
int32_t ResX
Definition: C4Config.h:104

Here is the caller graph for this function:

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

Definition at line 780 of file C4Config.cpp.

References SIsModule().

781 {
782  return SIsModule(szModules,szPath);
783 }
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:511

Here is the call graph for this function:

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4Config::MakeTempUpdateFolder ( )

Definition at line 818 of file C4Config.cpp.

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

819 {
820  // just pick a temp name
821  StdStrBuf sTempName;
822  sTempName.Copy(AtTempPath("update"));
823  MakeTempFilename(&sTempName);
824  SCopy(sTempName.getData(), General.TempUpdatePath);
826  return General.TempUpdatePath;
827 }
const char * getData() const
Definition: StdBuf.h:450
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:642
C4ConfigGeneral General
Definition: C4Config.h:252
char TempUpdatePath[CFG_MaxString+1]
Definition: C4Config.h:58
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:544
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:333
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

bool C4Config::Registered ( )

Definition at line 706 of file C4Config.cpp.

707 {
708  // Dummy function: to be overloaded in C4Config
709  return true;
710 }
bool C4Config::RemoveModule ( const char *  szPath,
char *  szModules 
)

Definition at line 785 of file C4Config.cpp.

References SRemoveModule().

786 {
787  return SRemoveModule(szModules,szPath);
788 }
bool SRemoveModule(char *szList, const char *szModule, bool fCaseSensitive)
Definition: Standard.cpp:552

Here is the call graph for this function:

bool C4Config::Save ( )

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

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

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

Referenced by Load(), and Save().

bool C4Config::fConfigLoaded

Definition at line 263 of file C4Config.h.

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

C4ConfigGamepad C4Config::Gamepads[C4ConfigMaxGamepads]

Definition at line 259 of file C4Config.h.

Referenced by CompileFunc().

C4ConfigGeneral C4Config::General

Definition at line 252 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(), C4Reloc::Init(), C4Landscape::Init(), C4Game::Init(), C4Player::InitControl(), C4Game::InitDefs(), C4StartupGraphics::InitFonts(), C4GraphicsResource::InitFonts(), C4Game::InitGame(), C4Game::InitScriptEngine(), C4StartupScenSelDlg::KeyCheat2(), 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 262 of file C4Config.h.

Referenced by CompileFunc().


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