Skip to content

Commit

Permalink
Merge pull request #1 from Lime-blur/1.0.5
Browse files Browse the repository at this point in the history
Added an additional parameter to reduce the .dff file dump
  • Loading branch information
Lime-blur authored Nov 22, 2023
2 parents 6822c16 + 49725fa commit 2d693b5
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 13 deletions.
4 changes: 2 additions & 2 deletions rwparser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.github.Lime-blur'
version = '1.0.4'
version = '1.0.5'

android {
namespace 'ru.limedev.rwparser'
Expand Down Expand Up @@ -50,7 +50,7 @@ afterEvaluate {
from components.release
groupId = 'com.github.Lime-blur'
artifactId = 'rwparser'
version = '1.0.4'
version = '1.0.5'
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions rwparser/src/main/cpp/modelparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ extern "C" jint Java_ru_limedev_rwparser_ModelParser_putDffDumpIntoFileNative(
JNIEnv* env,
jobject,
jstring jInFilePath,
jstring jOutFilePath
jstring jOutFilePath,
jboolean jIsDetailedDump
) {
HeaderInfo header{};
char *inFile = jniutils::to_char_ptr(env, jInFilePath);
Expand All @@ -26,7 +27,7 @@ extern "C" jint Java_ru_limedev_rwparser_ModelParser_putDffDumpIntoFileNative(
in.seekg(-12, ios::cur);
auto *clump = new Clump;
clump->read(in);
dump += clump->getDump(true);
dump += clump->getDump((bool) (jIsDetailedDump == JNI_TRUE));
delete clump;
}
}
Expand Down
15 changes: 12 additions & 3 deletions rwparser/src/main/java/ru/limedev/rwparser/ModelParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ class ModelParser {
* Parses the dff file and places the dump in the specified file.
* @param jInFilePath dff file
* @param jOutFilePath the file to place dff's dump
* @param jIsDetailedDump true - for a detailed dump, false - for a non-detailed dump. Default is false
* @return [ParseResult.SUCCESS] - if the operation was successful,
* [ParseResult.ERROR] - if a failure occurred.
*/
fun putDffDumpIntoFile(jInFilePath: String, jOutFilePath: String): ParseResult {
fun putDffDumpIntoFile(
jInFilePath: String,
jOutFilePath: String,
jIsDetailedDump: Boolean = false
): ParseResult {
return try {
val parseResult = putDffDumpIntoFileNative(jInFilePath, jOutFilePath)
val parseResult = putDffDumpIntoFileNative(jInFilePath, jOutFilePath, jIsDetailedDump)
if (parseResult == 0) ParseResult.SUCCESS else ParseResult.ERROR
} catch (e: Exception) {
ParseResult.ERROR
Expand All @@ -34,7 +39,11 @@ class ModelParser {
}
}

private external fun putDffDumpIntoFileNative(jInFilePath: String, jOutFilePath: String): Int
private external fun putDffDumpIntoFileNative(
jInFilePath: String,
jOutFilePath: String,
jIsDetailedDump: Boolean
): Int

private external fun putTxdDumpIntoFileNative(jInFilePath: String, jOutFilePath: String): Int

Expand Down
36 changes: 32 additions & 4 deletions sample/src/main/java/ru/limedev/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.io.File
class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
private var currentOperation: ParseOperation? = null

private var resultLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
Expand All @@ -23,7 +24,22 @@ class MainActivity : AppCompatActivity() {
val fileName = uri?.getName(this)
val fileExtension = uri?.getExtension(this)
val documentsFile = uri?.toInternalDocumentsFile(this, fileName)
parse(fileName, fileExtension, documentsFile)
when (currentOperation) {
ParseOperation.PARSE -> parse(
fileName = fileName,
fileExtension = fileExtension,
documentsFile = documentsFile,
detailed = true
)
ParseOperation.SHORT_PARSE -> parse(
fileName = fileName,
fileExtension = fileExtension,
documentsFile = documentsFile,
detailed = false
)
else -> Unit
}
currentOperation = null
documentsFile?.delete()
}
}
Expand All @@ -32,21 +48,33 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.button.setOnClickListener { handleOpeningFile() }
binding.button.setOnClickListener {
currentOperation = ParseOperation.PARSE
handleOpeningFile()
}
binding.button2.setOnClickListener {
currentOperation = ParseOperation.SHORT_PARSE
handleOpeningFile()
}
}

private fun handleOpeningFile() {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply { type = "*/*" }
resultLauncher.launch(intent)
}

private fun parse(fileName: String?, fileExtension: String?, documentsFile: File?) {
private fun parse(
fileName: String?,
fileExtension: String?,
documentsFile: File?,
detailed: Boolean
) {
if (fileName == null || fileExtension == null || documentsFile == null) return
val inFilePath = getInternalDocumentsFilePath(fileName) ?: return
val outFilePath = getInternalDocumentsFilePath("result.txt") ?: return
val modelParser = ModelParser()
val parseResult = when (fileExtension) {
".dff" -> modelParser.putDffDumpIntoFile(inFilePath, outFilePath)
".dff" -> modelParser.putDffDumpIntoFile(inFilePath, outFilePath, detailed)
".txd" -> modelParser.putTxdDumpIntoFile(inFilePath, outFilePath)
else -> ParseResult.ERROR
}
Expand Down
3 changes: 3 additions & 0 deletions sample/src/main/java/ru/limedev/sample/ParseOperation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package ru.limedev.sample

enum class ParseOperation { PARSE, SHORT_PARSE, CONVERT }
28 changes: 26 additions & 2 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,35 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Open file"
android:layout_marginEnd="8dp"
android:text="Parse"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/sample_text"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/sample_text"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sample_text" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Parse (short)"
app:layout_constraintBottom_toBottomOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button"
app:layout_constraintTop_toTopOf="@+id/button" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Сonvert"
app:layout_constraintEnd_toEndOf="@+id/button2"
app:layout_constraintStart_toStartOf="@+id/button"
app:layout_constraintTop_toBottomOf="@+id/button" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 2d693b5

Please sign in to comment.