Skip to content

Commit 6a39f16

Browse files
committed
hotfix for old database
1 parent 6cb658a commit 6a39f16

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

source/gameanalytics/GADevice.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ namespace gameanalytics
225225
{
226226
if (_platform)
227227
{
228-
_writablepath = _platform->getPersistentPath() + "/" + state::GAState::getGameKey();
229-
if(!std::filesystem::exists(_writablepath))
230-
{
231-
std::filesystem::create_directory(_writablepath);
232-
}
228+
_writablepath = _platform->getPersistentPath();
233229
}
234230
}
235231
}

source/gameanalytics/GAStore.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,36 @@ namespace gameanalytics
207207
return sqlDatabase;
208208
}
209209

210+
bool GAStore::fixOldDatabase()
211+
{
212+
std::string oldPath = device::GADevice::getWritablePath() + "/ga.sqlite3";
213+
std::string newPath = device::GADevice::getWritablePath() + "/" + state::GAState::getGameKey() + "/ga.sqlite3";
214+
if(std::filesystem::exists(oldPath))
215+
{
216+
std::filesystem::rename(oldPath, newPath);
217+
return true;
218+
}
219+
220+
return false;
221+
}
222+
210223
bool GAStore::ensureDatabase(bool dropDatabase, std::string const& key)
211224
{
212225
// lazy creation of db path
213226
if(getInstance().dbPath.empty())
214227
{
215-
std::string path = device::GADevice::getWritablePath();
216-
path += utilities::printString("/%s/ga.sqlite3", key.c_str());
228+
std::string dir = device::GADevice::getWritablePath() + "/" + key;
229+
if(!std::filesystem::exists(dir))
230+
{
231+
std::filesystem::create_directory(dir);
232+
}
217233

234+
std::string path = dir + "/ga.sqlite3";
218235
getInstance().dbPath = path;
219236
}
220237

221238
const std::string dbPath = getInstance().dbPath;
239+
const bool shouldFixDb = getInstance().fixOldDatabase();
222240

223241
// Open database
224242
if (sqlite3_open(dbPath.c_str(), &getInstance().sqlDatabase) != SQLITE_OK)
@@ -232,7 +250,7 @@ namespace gameanalytics
232250
getInstance().dbReady = true;
233251
logging::GALogger::i("Database opened: %s", dbPath.c_str());
234252
}
235-
253+
236254
if (dropDatabase)
237255
{
238256
logging::GALogger::d("Drop tables");
@@ -242,6 +260,13 @@ namespace gameanalytics
242260
GAStore::executeQuerySync("DROP TABLE ga_progression");
243261
GAStore::executeQuerySync("VACUUM");
244262
}
263+
else if(shouldFixDb)
264+
{
265+
GAStore::executeQuerySync("DROP TABLE ga_events");
266+
GAStore::executeQuerySync("DROP TABLE ga_progression");
267+
GAStore::executeQuerySync("DROP TABLE ga_session");
268+
GAStore::executeQuerySync("VACUUM");
269+
}
245270

246271
// Create statements
247272
constexpr const char* sql_ga_events = "CREATE TABLE IF NOT EXISTS ga_events(status CHAR(50) NOT NULL, category CHAR(50) NOT NULL, session_id CHAR(50) NOT NULL, client_ts CHAR(50) NOT NULL, event TEXT NOT NULL);";

source/gameanalytics/GAStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace gameanalytics
5050

5151
static GAStore& getInstance();
5252

53+
bool fixOldDatabase();
5354
bool trimEventTable();
5455

5556
// set when calling "ensureDatabase"

source/gameanalytics/GameAnalytics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ namespace gameanalytics
356356
{
357357
return;
358358
}
359-
360-
359+
361360
threading::GAThreading::performTaskOnGAThread([gameKey, gameSecret]()
362361
{
363362
if (isSdkReady(true, false))

source/gameanalytics/Platform/GADevicePlatform.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,3 @@ namespace gameanalytics
4949
return std::make_unique<GADevicePlatform>();
5050
}
5151
}
52-
53-

0 commit comments

Comments
 (0)