delete and rename files

This commit is contained in:
2026-03-10 04:27:42 +05:00
parent 800f0fa15a
commit 0136b7b9f2
5 changed files with 321 additions and 5 deletions

View File

@@ -501,6 +501,40 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
}
}
fun renameFile(file: IsoFile, newName: String) {
viewModelScope.launch {
val oldPath = file.path
val newPath = "${oldPath.substringBeforeLast("/")}/$newName"
// Check if new file already exists
val checkResult = RootManager.executeCommand("test -f \"$newPath\" && echo exists")
if (checkResult.output.trim() == "exists") {
_uiState.update { it.copy(errorMessage = "File already exists: $newName") }
return@launch
}
val result = RootManager.executeCommand("mv \"$oldPath\" \"$newPath\"")
if (result.success) {
_uiState.update { it.copy(successMessage = "Renamed to $newName") }
loadFiles()
} else {
_uiState.update { it.copy(errorMessage = "Failed to rename file") }
}
}
}
fun deleteFile(file: IsoFile) {
viewModelScope.launch {
val result = RootManager.executeCommand("rm -f \"${file.path}\"")
if (result.success) {
_uiState.update { it.copy(successMessage = "Deleted ${file.name}") }
loadFiles()
} else {
_uiState.update { it.copy(errorMessage = "Failed to delete file") }
}
}
}
fun clearError() {
_uiState.update { it.copy(errorMessage = null) }
}