diff --git a/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/main/MainViewModel.kt b/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/main/MainViewModel.kt index bd3736d..5a67b3d 100644 --- a/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/main/MainViewModel.kt +++ b/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/main/MainViewModel.kt @@ -2,6 +2,7 @@ package com.github.capntrips.kernelflasher.ui.screens.main import android.annotation.SuppressLint import android.content.Context +import android.content.res.Resources import android.util.Log import android.widget.Toast import androidx.compose.runtime.MutableState @@ -9,6 +10,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.navigation.NavController +import com.github.capntrips.kernelflasher.R import com.github.capntrips.kernelflasher.common.PartitionUtil import com.github.capntrips.kernelflasher.common.types.backups.Backup import com.github.capntrips.kernelflasher.ui.screens.backups.BackupsViewModel @@ -48,6 +50,7 @@ class MainViewModel( private val _isRefreshing: MutableState = mutableStateOf(true) private var _error: String? = null private var _backups: MutableMap = mutableMapOf() + private val resources: Resources = context.resources val isRefreshing: Boolean get() = _isRefreshing.value @@ -142,9 +145,9 @@ class MainViewModel( val ramoops = File("/sdcard/Download/console-ramoops--$now.log") Shell.cmd("cp /sys/fs/pstore/console-ramoops-0 $ramoops").exec() if (ramoops.exists()) { - log(context, "Saved ramoops to $ramoops") + log(context, resources.getString(R.string.save_ramoops_success, ramoops)) } else { - log(context, "Failed to save $ramoops", shouldThrow = true) + log(context,resources.getString(R.string.save_ramoops_fail, ramoops), shouldThrow = true) } } } @@ -156,9 +159,9 @@ class MainViewModel( val dmesg = File("/sdcard/Download/dmesg--$now.log") Shell.cmd("dmesg > $dmesg").exec() if (dmesg.exists()) { - log(context, "Saved dmesg to $dmesg") + log(context, resources.getString(R.string.save_dmesg_success, dmesg)) } else { - log(context, "Failed to save $dmesg", shouldThrow = true) + log(context,resources.getString(R.string.save_dmesg_fail, dmesg), shouldThrow = true) } } } @@ -170,9 +173,9 @@ class MainViewModel( val logcat = File("/sdcard/Download/logcat--$now.log") Shell.cmd("logcat -d > $logcat").exec() if (logcat.exists()) { - log(context, "Saved logcat to $logcat") + log(context, resources.getString(R.string.save_logcat_success, logcat)) } else { - log(context, "Failed to save $logcat", shouldThrow = true) + log(context,resources.getString(R.string.save_logcat_fail, logcat), shouldThrow = true) } } } diff --git a/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt b/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt index a29a5de..bed2210 100644 --- a/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt +++ b/app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt @@ -2,6 +2,7 @@ package com.github.capntrips.kernelflasher.ui.screens.slot import android.annotation.SuppressLint import android.content.Context +import android.content.res.Resources import android.net.Uri import android.provider.OpenableColumns import android.util.Log @@ -15,6 +16,7 @@ import androidx.compose.runtime.snapshots.SnapshotStateMap import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.navigation.NavController +import com.github.capntrips.kernelflasher.R import com.github.capntrips.kernelflasher.common.PartitionUtil import com.github.capntrips.kernelflasher.common.extensions.ByteArray.toHex import com.github.capntrips.kernelflasher.common.extensions.ExtendedFile.inputStream @@ -65,6 +67,7 @@ class SlotViewModel( private val hashAlgorithm: String = "SHA-256" private var inInit = true private var _error: String? = null + private val resources: Resources = context.resources val sha1: String get() = _sha1!! @@ -120,12 +123,12 @@ class SlotViewModel( when (Shell.cmd("$magiskboot cpio ramdisk.cpio test").exec().code) { 0 -> _sha1 = Shell.cmd("$magiskboot sha1 $boot").exec().out.firstOrNull() 1 -> _sha1 = Shell.cmd("$magiskboot cpio ramdisk.cpio sha1").exec().out.firstOrNull() - else -> log(context, "Invalid ramdisk in boot.img", shouldThrow = true) + else -> log(context, resources.getString(R.string.invalid_ramdisk), shouldThrow = true) } } else if (kernel.exists()) { _sha1 = Shell.cmd("$magiskboot sha1 $boot").exec().out.firstOrNull() } else { - log(context, "Invalid boot.img, no ramdisk or kernel found", shouldThrow = true) + log(context, resources.getString(R.string.invalid_boot), shouldThrow = true) } Shell.cmd("$magiskboot cleanup").exec() @@ -218,11 +221,11 @@ class SlotViewModel( launch { val now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd--HH-mm")) val logName = if (navController.currentDestination!!.route!!.contains("ak3")) { - "ak3" + resources.getString(R.string.log_ak3) } else if (navController.currentDestination!!.route!!.endsWith("/backup")) { - "backup" + resources.getString(R.string.log_backup) } else { - "flash" + resources.getString(R.string.log_flash) } val log = File("/sdcard/Download/$logName-log--$now.log") if (navController.currentDestination!!.route!!.contains("ak3")) { @@ -231,9 +234,9 @@ class SlotViewModel( log.writeText(flashOutput.joinToString("\n")) } if (log.exists()) { - log(context, "Saved $logName log to $log") + log(context, resources.getString(R.string.save_log_success, logName, log)) } else { - log(context, "Failed to save $log", shouldThrow = true) + log(context, resources.getString(R.string.save_log_fail, log), shouldThrow = true) } } } @@ -353,21 +356,21 @@ class SlotViewModel( val externalDir = fileSystemManager.getFile("/sdcard/KernelFlasher") if (!externalDir.exists()) { if (!externalDir.mkdir()) { - log(context, "Failed to create KernelFlasher dir on /sdcard", shouldThrow = true) + log(context, resources.getString(R.string.create_kf_dir_fail), shouldThrow = true) } } val backupsDir = externalDir.getChildFile("backups") if (!backupsDir.exists()) { if (!backupsDir.mkdir()) { - log(context, "Failed to create backups dir", shouldThrow = true) + log(context, resources.getString(R.string.create_backups_dir_fail), shouldThrow = true) } } val backupDir = backupsDir.getChildFile(now) if (backupDir.exists()) { - log(context, "Backup $now already exists", shouldThrow = true) + log(context, resources.getString(R.string.backup_exists, now), shouldThrow = true) } else { if (!backupDir.mkdir()) { - log(context, "Failed to create backup dir", shouldThrow = true) + log(context, resources.getString(R.string.create_backup_dir_fail), shouldThrow = true) } } return backupDir @@ -389,7 +392,7 @@ class SlotViewModel( addMessage("Saving backup $now") val hashes = backupPartitions(context, backupDir) if (hashes == null) { - log(context, "No partitions saved", shouldThrow = true) + log(context, resources.getString(R.string.no_partitions_saved), shouldThrow = true) } val jsonFile = backupDir.getChildFile("backup.json") val backup = Backup(now, "raw", currentKernelVersion!!, sha1, null, hashes, hashAlgorithm) @@ -423,7 +426,7 @@ class SlotViewModel( callback.invoke() } } else { - log(context, "AK3 zip is missing", shouldThrow = true) + log(context, resources.getString(R.string.ak3_zip_missing), shouldThrow = true) } } } @@ -443,7 +446,7 @@ class SlotViewModel( val zipFile = ZipFile(zip) zipFile.use { z -> if (z.getEntry("anykernel.sh") == null) { - log(context, "Invalid AK3 zip", shouldThrow = true) + log(context, resources.getString(R.string.ak3_zip_invalid), shouldThrow = true) } withContext (Dispatchers.Main) { callback?.invoke() @@ -454,7 +457,7 @@ class SlotViewModel( throw e } } else { - log(context, "Failed to save zip", shouldThrow = true) + log(context, resources.getString(R.string.save_zip_fail), shouldThrow = true) } } @@ -467,7 +470,7 @@ class SlotViewModel( val backupsDir = fileSystemManager.getFile("$externalDir/backups") val backupDir = backupsDir.getChildFile(currentBackup) if (!backupDir.exists()) { - log(context, "Backup $currentBackup does not exists", shouldThrow = true) + log(context, resources.getString(R.string.backup_not_exist, currentBackup), shouldThrow = true) } val source = backupDir.getChildFile(flashFilename!!) val zip = File(context.filesDir, flashFilename!!) @@ -509,14 +512,14 @@ class SlotViewModel( val flashScript = File(files, "flash_ak3.sh") val result = Shell.Builder.create().setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_REDIRECT_STDERR).build().newJob().add("F=$files Z=\"$zip\" /system/bin/sh $flashScript").to(flashOutput).exec() if (result.isSuccess) { - log(context, "Kernel flashed successfully") + log(context, resources.getString(R.string.flash_success)) _wasFlashSuccess.value = true } else { - log(context, "Failed to flash zip", shouldThrow = false) + log(context, resources.getString(R.string.flash_fail), shouldThrow = false) } clearTmp(context) } else { - log(context, "AK3 zip is missing", shouldThrow = true) + log(context, resources.getString(R.string.ak3_zip_missing), shouldThrow = true) } } catch (e: Exception) { clearFlash(context) @@ -569,7 +572,7 @@ class SlotViewModel( PartitionUtil.flashBlockDevice(image, blockDevice, hashAlgorithm) } } else { - log(context, "Partition $partitionName was not found", shouldThrow = true) + log(context, resources.getString(R.string.partition_not_found, partitionName), shouldThrow = true) } addMessage("Flashed $flashFilename to $partitionName") addMessage("Cleaning up ...") @@ -577,7 +580,7 @@ class SlotViewModel( addMessage("Done.") _wasFlashSuccess.value = true } else { - log(context, "Partition image is missing", shouldThrow = true) + log(context, resources.getString(R.string.partition_image_missing), shouldThrow = true) } } catch (e: Exception) { clearFlash(context) diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml new file mode 100644 index 0000000..deef21f --- /dev/null +++ b/app/src/main/res/values-pl/strings.xml @@ -0,0 +1,89 @@ + + + Kernel Flasher + Wymagane uprawnienia Superużytkownika + Usługa Superużytkownika została odłączona + Urządzenie + Model + Kompilacja + Nazwa jądra + Wersja jądra + Przyrostek slotu + Slot + Slot A + Slot B + Boot SHA1 + Vendor DLKM + Istnieje + Nie znaleziono + Zamontowany + Niezamontowany + Wybierz + Kopie zapasowe + Zapisz ramoops + Zapisz dmesg + Zapisz logcat + Wstecz + Utwórz kopię zapasową + Aktualizacje + Sflashuj + Sflashuj archiwum AK3 + Sflashuj obraz partycji + Przywróć + Sprawdź wersję jądra + Zamontuj Vendor DLKM + Odmontuj Vendor DLKM + Migruj + Zmapuj Vendor DLKM + Odmapuj Vendor DLKM + Nie znaleziono kopii zapasowych + Usuń + Dodaj + Adres URL + Wersja + Data publikacji + Ostatnia aktualizacja + Lista zmian + Sprawdź aktualizacje + Pobierz + Uruchom ponownie + Miękki restart + Uruchom ponownie do trybu Recovery + Uruchom ponownie do trybu Bootloader + Uruchom ponownie do trybu Download + Uruchom ponownie do trybu EDL + Zapisz dziennik AK3 + Zapisz dziennik Flashowania + Zapisz dziennik kopii zapasowej + Zapisz dziennik przywracania + Zapisz archiwum AK3 jako kopię zapasową + Typ kopii zapasowej + Sumy kontrolne + Wybór partycji niedostępny dla kopii zapasowych starszego formatu + Sflashowano pomyślnie + Błąd podczas flashowania + Wadliwy ramdisk w boot.img + Wadliwy boot.img, nie znaleziono ramdisku lub jądra + Zapisano dziennik %1$s do %2$s + Nie udało się zapisać dziennika %1$s + AK3 + Kopii zapasowej + Flashowania + Nie udało się utworzyć katalogu KernelFlasher w /sdcard + Nie udało się utworzyć katalogu kopii zapasowych + Nie udało się utworzyć katalogu kopii zapasowej + Kopia zapasowa %1$s już istnieje + Brak zapisanych partycji + Archiwum AK3 nie istnieje + Wadliwe archiwum AK3 + Nie udało się zapisać archiwum + Kopia zpasowa %1$s nie istnieje + Nie znaleziono partycji %1$s + Obraz partycji nie istnieje + Zapisano ramoops w %1$s + Nie udało się zapisać pliku %1$s + Zapisano dmesg w %1$s + Nie udało się zapisać pliku %1$s + Zapisano logcat w %1$s + Nie udało się zapisać pliku %1$s + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58788cf..0725fa5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,5 +59,31 @@ Backup Type Hashes Partition selection unavailable for legacy backups + Kernel flashed successfully + Failed to flash zip + Invalid ramdisk in boot.img + Invalid boot.img, no ramdisk or kernel found + Saved %1$s log to %2$s + Failed to save %1$s log + AK3 + backup + flash + Failed to create KernelFlasher dir on /sdcard + Failed to create backups dir + Failed to create backup dir + Backup %1$s already exists + No partitions saved + AK3 zip is missing + Invalid AK3 zip + Failed to save zip + Backup %1$s does not exists + Partition %1$s was not found + Partition image is missing + Saved ramoops to %1$s + Failed to save %1$s + Saved dmesg to %1$s + Failed to save %1$s + Saved logcat to %1$s + Failed to save %1$s \ No newline at end of file