Skip to content

Commit

Permalink
Merge pull request #158 from xmoto/fixes
Browse files Browse the repository at this point in the history
Hotfix for 0.6.2
  • Loading branch information
Nikekson committed Mar 5, 2023
2 parents 57772c8 + 984e79b commit 747c3e1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
32 changes: 17 additions & 15 deletions src/db/xmDatabase.cpp
Expand Up @@ -96,7 +96,7 @@ void xmDatabase::preInitForProfileLoading(const std::string &i_dbFileUTF8) {

void xmDatabase::backupXmDb(const std::string &dbFile) {
std::ostringstream backupName;
backupName << "xm.v" << m_openingVersion << "." << iso8601Date() << ".db";
backupName << "xm.v" << m_openingVersion << "." << currentDateTime() << ".db";

std::string outputPath;
if (!XMFS::copyFile(FDT_DATA,
Expand Down Expand Up @@ -150,21 +150,23 @@ bool xmDatabase::init(const std::string &i_dbFileUTF8,
}

if (m_openingVersion < XMDB_VERSION) {
LogInfo("Backing up XmDb");

try {
backupXmDb(i_dbFileUTF8);
} catch (Exception &e) {
LogError("Failed to backup database:");
LogError(e.getMsg().c_str());
LogError("Bailing out..");

if (m_db != NULL) {
sqlite3_close(m_db);
m_db = NULL;
}
if (m_openingVersion != 0) {
LogInfo("Backing up XmDb");

try {
backupXmDb(i_dbFileUTF8);
} catch (Exception &e) {
LogError("Failed to backup database:");
LogError(e.getMsg().c_str());
LogError("Bailing out..");

return false;
if (m_db != NULL) {
sqlite3_close(m_db);
m_db = NULL;
}

return false;
}
}

LogInfo(
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/Time.cpp
Expand Up @@ -7,3 +7,10 @@ std::string iso8601Date() {
std::strftime(datetime, sizeof(datetime), "%Y-%m-%dT%H:%M:%SZ", std::localtime(&t));
return std::string(datetime);
}

std::string currentDateTime() {
std::time_t t = std::time(nullptr);
char datetime[sizeof("1970-01-01_00-00-00")];
std::strftime(datetime, sizeof(datetime), "%Y-%m-%d_%H-%M-%S", std::localtime(&t));
return std::string(datetime);
}
3 changes: 3 additions & 0 deletions src/helpers/Time.h
Expand Up @@ -5,4 +5,7 @@

std::string iso8601Date();

// Safe for use in file paths
std::string currentDateTime();

#endif // __XMOTO_TIME_H__
2 changes: 1 addition & 1 deletion src/xmoto/GameInit.cpp
Expand Up @@ -128,7 +128,7 @@ int main(int nNumArgs, char **ppcArgs) {
snprintf(cBuf,
1024,
"Fatal exception occurred: %s\n"
"Consult the logs/latest.log file for more information about what\n"
"Consult the logs/xmoto.log file for more information about what\n"
"might has occurred.\n",
e.getMsg().c_str());
MessageBox(NULL, cBuf, "X-Moto Error", MB_OK | MB_ICONERROR);
Expand Down

0 comments on commit 747c3e1

Please sign in to comment.