throw different exceptions at copy/move operations

This commit is contained in:
tibbi 2017-08-28 22:44:42 +02:00
parent 23401eb128
commit 4e0991dc50
22 changed files with 50 additions and 5 deletions

View file

@ -3,7 +3,7 @@ package com.simplemobiletools.commons.asynctasks
import android.os.AsyncTask
import android.support.v4.provider.DocumentFile
import android.support.v4.util.Pair
import android.util.Log
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.*
import java.io.*
@ -37,7 +37,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
copy(file, curFile)
} catch (e: Exception) {
Log.e(TAG, "copy $e")
activity.toast(e.localizedMessage)
return false
}
}
@ -65,7 +65,8 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
val document = activity.getFastDocument(destination) ?: return
document.createDirectory(destination.name)
} else if (!destination.mkdirs()) {
throw IOException("Could not create dir ${destination.absolutePath}")
val error = String.format(activity.getString(R.string.could_not_create_folder), destination.absolutePath)
throw IOException(error)
}
}
@ -94,7 +95,8 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
val directory = destination.parentFile
if (!directory.exists() && !directory.mkdirs()) {
throw IOException("Could not create dir ${directory.absolutePath}")
val error = String.format(activity.getString(R.string.could_not_create_folder), directory.absolutePath)
throw IOException(error)
}
var inputStream: InputStream? = null
@ -106,7 +108,8 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal
}
if (mDocument == null) {
throw IOException("Could not create destination document ${destination.parent}")
val error = String.format(activity.getString(R.string.could_not_create_file), destination.parent)
throw IOException(error)
}
val newDocument = mDocument!!.createFile(source.getMimeType(), destination.name)

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Some files could not be copied</string>
<string name="no_files_selected">No files selected</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Create new</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Některé soubory nemohly být zkopírovány</string>
<string name="no_files_selected">Žádné soubory vybrány</string>
<string name="saving">Ukládám&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Nový</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Einige Dateien konnten nicht kopiert werden</string>
<string name="no_files_selected">Keine Dateien ausgewählt</string>
<string name="saving">Speichere&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Neuer Ordner</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Algunos archivos no se pudieron copiar</string>
<string name="no_files_selected">No hay archivos seleccionados</string>
<string name="saving">Guardando&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Crear nueva</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Certains fichiers n\'ont pu être copiés</string>
<string name="no_files_selected">Aucun fichier sélectionné</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Créer nouveau</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Some files could not be copied</string>
<string name="no_files_selected">No files selected</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Create new</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Some files could not be copied</string>
<string name="no_files_selected">No files selected</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Create new</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Alcuni file non possono essere copiati</string>
<string name="no_files_selected">Nessun file selezionato</string>
<string name="saving">Salvataggio&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Crea nuovo</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">一部のファイルがコピーできませんでした</string>
<string name="no_files_selected">No files selected</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Create new</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">일부 파일을 복사 할 수 없음</string>
<string name="no_files_selected">파일이 선택되지 않음</string>
<string name="saving">저장중&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">새로 만들기</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Kai kurie failai negali bûti kopijuojami</string>
<string name="no_files_selected">Nepasirinkti failai</string>
<string name="saving">Iðsaugoma&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Kurti naujà</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Niektóre pliki nie mogą być skopiowane</string>
<string name="no_files_selected">Nie wybrano żadnych plików</string>
<string name="saving">Zapsisuję&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Utwórz nowy</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Alguns arquivos não foram copiados</string>
<string name="no_files_selected">Nenhum arquivo selecionado</string>
<string name="saving">Salvando&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Criar</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Alguns ficheiros não foram copiados</string>
<string name="no_files_selected">Nenhum ficheiro selecionado</string>
<string name="saving">A guardar&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Criar</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Некоторые файлы не могут быть скопированы</string>
<string name="no_files_selected">Файлы не выбраны</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Создать</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Nepodarilo sa skopírovať niektoré súbory</string>
<string name="no_files_selected">Niesú označené žiadne súbory</string>
<string name="saving">Ukladanie&#8230;</string>
<string name="could_not_create_folder">Nepodarilo sa vytvoriť priečinok %s</string>
<string name="could_not_create_file">Nepodarilo sa vytvoriť súbor %s</string>
<!-- Create new -->
<string name="create_new">Vytvoriť nový</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Några filer gick inte att kopiera</string>
<string name="no_files_selected">Inga filer markerade</string>
<string name="saving">Sparar&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Skapa ny</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Bazı dosyalar kopyalanamadı</string>
<string name="no_files_selected">No files selected</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Create new</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">无法复制相同文件</string>
<string name="no_files_selected">未选择文件</string>
<string name="saving">正在保存&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">新建</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">部分檔案無法被複製</string>
<string name="no_files_selected">未選擇檔案</string>
<string name="saving">儲存中&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">新增</string>

View file

@ -45,6 +45,8 @@
<string name="copying_success_partial">Some files could not be copied</string>
<string name="no_files_selected">No files selected</string>
<string name="saving">Saving&#8230;</string>
<string name="could_not_create_folder">Could not create folder %s</string>
<string name="could_not_create_file">Could not create file %s</string>
<!-- Create new -->
<string name="create_new">Create new</string>