Skip to content

Commit

Permalink
fixed import error, bumped to version 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenNingia committed Aug 2, 2017
1 parent 564318c commit 9e4cbc0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<manifest package="org.openningia.mushapp" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.4" android:versionCode="104" android:installLocation="auto">
<manifest package="org.openningia.mushapp" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.5" android:versionCode="105" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="MushApp" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="MushApp" android:screenOrientation="portrait" android:launchMode="singleTop">
<intent-filter>
Expand Down
46 changes: 37 additions & 9 deletions src/sqlcharactermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,34 +282,62 @@ bool SqlCharacterModel::importAll()
inPath.append("/org.openningia.mushapp/ie");

QDir inDir{inPath};
if ( !inDir.exists() )
if ( !inDir.exists() ) {
qWarning("import/export directory does not exists");
return false;
}

auto files = inDir.entryInfoList(QStringList() << "*.json", QDir::Files, QDir::Name);
if ( files.empty() )
if ( files.empty() ) {
qWarning("import/export directory is empty");
return false;
}

auto importFrom = files.last();

qDebug() << "import from: " << importFrom.absoluteFilePath();

QFile reader(importFrom.absoluteFilePath());
if ( reader.open(QFile::ReadOnly) ) {
auto doc = QJsonDocument::fromJson(reader.readAll());

if ( !doc.isArray() )
if ( !doc.isArray() ) {
qWarning("loaded document is not an array of characters");
return false;
}

QJsonArray lst{doc.array()};
for(auto c: lst) {
if ( c.isObject() ) {
auto o = c.toObject();
QJsonDocument d{o};
importCharacter(o["name"].toString(), d.toBinaryData());

qDebug() << "found " << lst.count() << " characters";

auto import_from_json_object = [&](QJsonObject o) {
QJsonDocument d{o};
if ( !importCharacter(o["name"].toString(), d.toBinaryData()) ) {
qWarning() << "Failed to import " << o["name"].toString();
}
};

auto import_from_json_array = [&](QJsonArray lst) {
for(auto c: lst) {
if ( c.isObject() )
import_from_json_object(c.toObject());
else
qWarning("expected a json object");
}
};

for(auto c: lst) {
if ( c.isObject() )
import_from_json_object(c.toObject());
else if ( c.isArray() )
import_from_json_array(c.toArray());
else
qWarning("expected a json object or a json array");
}

return true;
}

qWarning("Could not read from import file");

return false;
}

0 comments on commit 9e4cbc0

Please sign in to comment.