Skip to content

Commit

Permalink
Improve storage initialization and error handling, refactoring
Browse files Browse the repository at this point in the history
Add checks to ensure that:

- The first storage path, i.e. the path of the designated user directory, is added to the storage successfully.
- The folder of the user directory is created successfully (or already exists).
- The default folders inside the user directory are created successfully (or already exist).

On failure, the client/server will quit immediately on launch. The client will quit with an error message popup showing the log messages of the failed storage initialization. Closes ddnet#3758, which presumably was caused by the user directory not being accessible. Closes ddnet#9165.

Refactoring:

- Consistently use the `log_` functions for logging.
- Extract functions in `CStorage` to improve readability.
- Add `enum class EInitializationType` for storage initialization.
  • Loading branch information
Robyt3 committed Jan 4, 2025
1 parent a30c3f7 commit 62c9ed4
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 142 deletions.
18 changes: 17 additions & 1 deletion src/engine/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4707,7 +4707,23 @@ int main(int argc, const char **argv)
delete pEngine;
});

IStorage *pStorage = CreateStorage(IStorage::STORAGETYPE_CLIENT, argc, argv);
IStorage *pStorage;
{
CMemoryLogger MemoryLogger;
MemoryLogger.SetParent(log_get_scope_logger());
{
CLogScope LogScope(&MemoryLogger);
pStorage = CreateStorage(IStorage::EInitializationType::CLIENT, argc, argv);
}
if(!pStorage)
{
log_error("client", "Failed to initialize the storage location (see details above)");
std::string Message = "Failed to initialize the storage location. See details below.\n\n" + MemoryLogger.ConcatenatedLines();
pClient->ShowMessageBox("Storage Error", Message.c_str());
PerformAllCleanup();
return -1;
}
}
pKernel->RegisterInterface(pStorage);

pFutureAssertionLogger->Set(CreateAssertionLogger(pStorage, GAME_NAME));
Expand Down
7 changes: 6 additions & 1 deletion src/engine/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ int main(int argc, const char **argv)
IEngine *pEngine = CreateEngine(GAME_NAME, pFutureConsoleLogger, 2 * std::thread::hardware_concurrency() + 2);
pKernel->RegisterInterface(pEngine);

IStorage *pStorage = CreateStorage(IStorage::STORAGETYPE_SERVER, argc, argv);
IStorage *pStorage = CreateStorage(IStorage::EInitializationType::SERVER, argc, argv);
if(!pStorage)
{
log_error("server", "failed to initialize storage");
return -1;
}
pKernel->RegisterInterface(pStorage);

pFutureAssertionLogger->Set(CreateAssertionLogger(pStorage, GAME_NAME));
Expand Down
Loading

0 comments on commit 62c9ed4

Please sign in to comment.