MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / ImportFileFromJson

Method ImportFileFromJson

Src/Database/Database.cpp:686–713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

684}
685
686bool CDatabaseFile::ImportFileFromJson(const QJsonObject &obj, QString &szFile)
687{
688 QString szErr;
689 QString szFileContent = obj["FileContent"].toString();
690 if(szFileContent.isEmpty()) {
691 qCritical(log) << "The file content is empty.";
692 return false;
693 }
694 szFile = obj["FileName"].toString();
695 if(szFile.isEmpty()) {
696 qCritical(log) << "The file name is empty.";
697 return false;
698 }
699 szFile = GetFile(szFile);
700 QFileInfo fi(szFile);
701 if(!fi.exists()) {
702 QFile f(szFile);
703 if(!f.open(QFile::WriteOnly | QFile::Text)) {
704 szErr = "Failed to open file: " + szFile
705 + "; Error: " + f.errorString();
706 qCritical(log) << szErr;
707 return false;
708 }
709 f.write(szFileContent.toStdString().c_str(), szFileContent.size());
710 f.close();
711 }
712 return true;
713}
714
715bool CDatabaseFile::ImportFileToDatabaseFromJson(const QJsonObject &obj, QString &szFile)
716{

Callers

nothing calls this directly

Calls 5

errorStringMethod · 0.80
writeMethod · 0.80
isEmptyMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected