mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	Move isValidZipFile to ZipHelper
This commit is contained in:
		| @@ -224,7 +224,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { | |||||||
|  |  | ||||||
|     private void importDatabase(final String filePath) { |     private void importDatabase(final String filePath) { | ||||||
|         // check if file is supported |         // check if file is supported | ||||||
|         if (!manager.isValidZipFile(filePath)) { |         if (!ZipHelper.isValidZipFile(filePath)) { | ||||||
|             Toast.makeText(getContext(), R.string.no_valid_zip_file, Toast.LENGTH_SHORT) |             Toast.makeText(getContext(), R.string.no_valid_zip_file, Toast.LENGTH_SHORT) | ||||||
|                 .show(); |                 .show(); | ||||||
|             return; |             return; | ||||||
|   | |||||||
| @@ -36,16 +36,6 @@ class ContentSettingsManager(private val fileLocator: NewPipeFileLocator) { | |||||||
|             } |             } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun isValidZipFile(filePath: String): Boolean { |  | ||||||
|         try { |  | ||||||
|             ZipFile(filePath).use { |  | ||||||
|                 return@isValidZipFile true |  | ||||||
|             } |  | ||||||
|         } catch (ioe: IOException) { |  | ||||||
|             return false |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Tries to create database directory if it does not exist. |      * Tries to create database directory if it does not exist. | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -4,7 +4,9 @@ import java.io.BufferedInputStream; | |||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.io.FileInputStream; | import java.io.FileInputStream; | ||||||
| import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||||
|  | import java.io.IOException; | ||||||
| import java.util.zip.ZipEntry; | import java.util.zip.ZipEntry; | ||||||
|  | import java.util.zip.ZipFile; | ||||||
| import java.util.zip.ZipInputStream; | import java.util.zip.ZipInputStream; | ||||||
| import java.util.zip.ZipOutputStream; | import java.util.zip.ZipOutputStream; | ||||||
|  |  | ||||||
| @@ -99,4 +101,12 @@ public final class ZipHelper { | |||||||
|             return found; |             return found; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static boolean isValidZipFile(final String filePath) { | ||||||
|  |         try (ZipFile ignored = new ZipFile(filePath)) { | ||||||
|  |             return true; | ||||||
|  |         } catch (final IOException ioe) { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 XiangRongLin
					XiangRongLin