@@ -142,15 +142,15 @@ class SettingsViewModel(private val application: Application) : AndroidViewModel
142142 val imageIndexFile = File (application.filesDir, ImageIndexer .INDEX_FILENAME )
143143 val videoIndexFile = File (application.filesDir, VideoIndexer .INDEX_FILENAME )
144144 val hashFile = File (application.cacheDir, HASH_FILENAME )
145+ val filesToZip = listOf (imageIndexFile, videoIndexFile, hashFile)
145146 _isBackupLoading .value = true
146147
147148 viewModelScope.launch(Dispatchers .IO ){
148149 try {
149- val imageHash = hashFile(imageIndexFile)
150- val videoHash = hashFile(videoIndexFile)
151- hashFile.writeText(" $imageHash \n $videoHash " )
150+ val hashes: List <String > = listOf (imageIndexFile, videoIndexFile).filter { it.exists() }.map{hashFile(it)}
151+ hashFile.writeText(hashes.joinToString(" \n " ) )
152152
153- zipFiles(indexZipFile, listOf (imageIndexFile, videoIndexFile, hashFile) )
153+ zipFiles(indexZipFile, filesToZip )
154154 copyToUri(application, uri, indexZipFile)
155155 _event .emit(" Backup successful" )
156156 }catch (e: Exception ){
@@ -193,7 +193,7 @@ class SettingsViewModel(private val application: Application) : AndroidViewModel
193193 private suspend fun isValidBackupFile (extractedFiles : List <File >): Boolean {
194194 val hashFile = extractedFiles.find { it.name == HASH_FILENAME }? : return false
195195 val hashesFromFile: List <String > = hashFile.readLines()
196- if (hashesFromFile.size < 2 ) return false
196+ if (hashesFromFile.isEmpty()) return false // must have hash for at least 1 of image or video index file
197197
198198 val indexFiles = extractedFiles.filterNot{it.name == HASH_FILENAME }
199199 val indexHashes = indexFiles.map{hashFile(it)}
0 commit comments