1
0
Fork 0

DBG: don't clear data before loading from JSON

This commit is contained in:
mrexodia 2016-10-08 01:36:26 +02:00
parent 862ccbfb2d
commit 2743bb12e0
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
11 changed files with 24 additions and 29 deletions

View File

@ -294,7 +294,6 @@ void TraceRecordManager::saveToDb(JSON root)
void TraceRecordManager::loadFromDb(JSON root)
{
clear();
EXCLUSIVE_ACQUIRE(LockTraceRecord);
// get the root object
const JSON tracerecord = json_object_get(root, "tracerecord");

View File

@ -48,7 +48,7 @@ void BookmarkCacheSave(JSON Root)
void BookmarkCacheLoad(JSON Root)
{
bookmarks.CacheLoad(Root);
bookmarks.CacheLoad(Root, false, "auto"); //legacy support
bookmarks.CacheLoad(Root, "auto"); //legacy support
}
bool BookmarkEnum(BOOKMARKSINFO* List, size_t* Size)

View File

@ -688,9 +688,6 @@ void BpCacheLoad(JSON Root)
{
EXCLUSIVE_ACQUIRE(LockBreakpoints);
// Remove all existing elements
breakpoints.clear();
// Get a handle to the root object -> breakpoints subtree
const JSON jsonBreakpoints = json_object_get(Root, "breakpoints");
@ -736,7 +733,7 @@ void BpCacheLoad(JSON Root)
{
key = BpGetDLLBpAddr(breakpoint.mod);
}
breakpoints.insert(std::make_pair(BreakpointKey(breakpoint.type, key), breakpoint));
breakpoints[BreakpointKey(breakpoint.type, key)] = breakpoint;
}
}

View File

@ -75,7 +75,7 @@ void CommentCacheSave(JSON Root)
void CommentCacheLoad(JSON Root)
{
comments.CacheLoad(Root);
comments.CacheLoad(Root, false, "auto"); //legacy support
comments.CacheLoad(Root, "auto"); //legacy support
}
bool CommentEnum(COMMENTSINFO* List, size_t* Size)

View File

@ -35,11 +35,12 @@ char dbbasepath[deflen];
*/
char dbpath[deflen];
void DbSave(DbLoadSaveType saveType)
void DbSave(DbLoadSaveType saveType, const char* dbfile, bool disablecompression)
{
EXCLUSIVE_ACQUIRE(LockDatabase);
dputs(QT_TRANSLATE_NOOP("DBG", "Saving database..."));
auto file = dbfile ? dbfile : dbpath;
dprintf(QT_TRANSLATE_NOOP("DBG", "Saving database to %s\n"), file);
DWORD ticks = GetTickCount();
JSON root = json_object();
@ -103,7 +104,7 @@ void DbSave(DbLoadSaveType saveType)
json_decref(pluginRoot);
}
auto wdbpath = StringUtils::Utf8ToUtf16(dbpath);
auto wdbpath = StringUtils::Utf8ToUtf16(file);
CopyFileW(wdbpath.c_str(), (wdbpath + L".bak").c_str(), FALSE); //make a backup
if(json_object_size(root))
{
@ -112,7 +113,7 @@ void DbSave(DbLoadSaveType saveType)
if(jsonText)
{
// Dump JSON to disk (overwrite any old files)
if(!FileHelper::WriteAllText(dbpath, jsonText))
if(!FileHelper::WriteAllText(file, jsonText))
{
dputs(QT_TRANSLATE_NOOP("DBG", "\nFailed to write database file!"));
json_free(jsonText);
@ -123,7 +124,7 @@ void DbSave(DbLoadSaveType saveType)
json_free(jsonText);
}
if(!settingboolget("Engine", "DisableDatabaseCompression"))
if(!disablecompression && !settingboolget("Engine", "DisableDatabaseCompression"))
LZ4_compress_fileW(wdbpath.c_str(), wdbpath.c_str());
}
else //remove database when nothing is in there
@ -133,22 +134,23 @@ void DbSave(DbLoadSaveType saveType)
json_decref(root); //free root
}
void DbLoad(DbLoadSaveType loadType)
void DbLoad(DbLoadSaveType loadType, const char* dbfile)
{
EXCLUSIVE_ACQUIRE(LockDatabase);
auto file = dbfile ? dbfile : dbpath;
// If the file doesn't exist, there is no DB to load
if(!FileExists(dbpath))
if(!FileExists(file))
return;
if(loadType == DbLoadSaveType::CommandLine)
dputs(QT_TRANSLATE_NOOP("DBG", "Loading commandline..."));
else
dputs(QT_TRANSLATE_NOOP("DBG", "Loading database..."));
dprintf(QT_TRANSLATE_NOOP("DBG", "Loading database from %s\n"), file);
DWORD ticks = GetTickCount();
// Multi-byte (UTF8) file path converted to UTF16
WString databasePathW = StringUtils::Utf8ToUtf16(dbpath);
WString databasePathW = StringUtils::Utf8ToUtf16(file);
// Decompress the file if compression was enabled
bool useCompression = !settingboolget("Engine", "DisableDatabaseCompression");
@ -167,7 +169,7 @@ void DbLoad(DbLoadSaveType loadType)
// Read the database file
String databaseText;
if(!FileHelper::ReadAllText(dbpath, databaseText))
if(!FileHelper::ReadAllText(file, databaseText))
{
dputs(QT_TRANSLATE_NOOP("DBG", "\nFailed to read database file!"));
return;
@ -257,10 +259,13 @@ void DbClear()
LabelClear();
BookmarkClear();
FunctionClear();
ArgumentClear();
LoopClear();
XrefClear();
EncodeMapClear();
TraceRecord.clear();
BpClear();
WatchClear();
PatchClear();
GuiSetDebuggeeNotes("");
}

View File

@ -10,8 +10,8 @@ enum class DbLoadSaveType
All
};
void DbSave(DbLoadSaveType saveType);
void DbLoad(DbLoadSaveType loadType);
void DbSave(DbLoadSaveType saveType, const char* dbfile = nullptr, bool disablecompression = false);
void DbLoad(DbLoadSaveType loadType, const char* dbfile = nullptr);
void DbClose();
void DbClear();
void DbSetPath(const char* Directory, const char* ModulePath);

View File

@ -143,7 +143,7 @@ void FunctionCacheSave(JSON Root)
void FunctionCacheLoad(JSON Root)
{
functions.CacheLoad(Root);
functions.CacheLoad(Root, false, "auto"); //legacy support
functions.CacheLoad(Root, "auto"); //legacy support
}
bool FunctionEnum(FUNCTIONSINFO* List, size_t* Size)

View File

@ -85,7 +85,7 @@ void LabelCacheSave(JSON Root)
void LabelCacheLoad(JSON Root)
{
labels.CacheLoad(Root);
labels.CacheLoad(Root, false, "auto"); //legacy support
labels.CacheLoad(Root, "auto"); //legacy support
}
bool LabelEnum(LABELSINFO* List, size_t* Size)

View File

@ -208,13 +208,10 @@ void LoopCacheLoad(JSON Root)
continue;
// Insert into global list
loops.insert(std::make_pair(DepthModuleRange(loopInfo.depth, ModuleRange(ModHashFromName(loopInfo.mod), Range(loopInfo.start, loopInfo.end))), loopInfo));
loops[DepthModuleRange(loopInfo.depth, ModuleRange(ModHashFromName(loopInfo.mod), Range(loopInfo.start, loopInfo.end)))] = loopInfo;
}
};
// Remove existing entries
loops.clear();
const JSON jsonLoops = json_object_get(Root, "loops");
const JSON jsonAutoLoops = json_object_get(Root, "autoloops");

View File

@ -184,10 +184,8 @@ public:
json_decref(jsonValues);
}
void CacheLoad(JSON root, bool clear = true, const char* keyprefix = nullptr)
void CacheLoad(JSON root, const char* keyprefix = nullptr)
{
if(clear)
Clear();
EXCLUSIVE_ACQUIRE(TLock);
auto jsonValues = json_object_get(root, keyprefix ? (keyprefix + String(jsonKey())).c_str() : jsonKey());
if(!jsonValues)

View File

@ -359,7 +359,6 @@ void WatchCacheSave(JSON root)
void WatchCacheLoad(JSON root)
{
WatchClear();
EXCLUSIVE_ACQUIRE(LockWatch);
JSON watchroot = json_object_get(root, "watch");
if(!watchroot)