Loading app/src/main/java/foundation/e/drive/fileFilters/AppSettingsFileFilter.javadeleted 100644 → 0 +0 −27 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import java.io.File; import java.io.FileFilter; import java.util.Locale; /** * @author Vincent Bourgmayer * FileFilter for application Settings */ class AppSettingsFileFilter implements FileFilter { @Override public boolean accept(File pathname) { return pathname.isFile() || (pathname.isDirectory() && !pathname.getName().toLowerCase(Locale.ROOT).contains("cache")); } } app/src/main/java/foundation/e/drive/fileFilters/CrashlogsFileFilter.javadeleted 100644 → 0 +0 −56 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import androidx.annotation.NonNull; import java.io.File; import java.io.FileFilter; import foundation.e.drive.utils.ServiceExceptionHandler; /** * @Author Vincent Bourgmayer */ public class CrashlogsFileFilter implements FileFilter { private final static long max_timestamp_delta = 864000000; //10 days in ms (240*3600*1000) @Override public boolean accept(@NonNull File pathname) { String fileTimestamp = extractTimestamp(pathname.getName(), ServiceExceptionHandler.LOG_FILE_NAME_PREFIX, ServiceExceptionHandler.LOG_FILE_EXTENSION); long timestamp; try { timestamp = Long.parseLong(fileTimestamp); }catch (NumberFormatException e){ //Can't parse the extracted timestamp //This file has not the expected name. It must be removed return true; } //if current Date - file date >= max deta allowed return ((System.currentTimeMillis() - timestamp ) >= max_timestamp_delta); } /** * Extract the timestamp from the name of the file * UnitTested! * @param fileName Filename * @param prefix prefix to ignore * @param extension extension to ignore * @return the timestamp extracted from the name */ private String extractTimestamp(String fileName, @NonNull String prefix, @NonNull String extension){ return fileName.substring(prefix.length(), (fileName.length() - extension.length())); } } No newline at end of file app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.javadeleted 100644 → 0 +0 −40 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import androidx.annotation.NonNull; import java.io.FileFilter; /** * @author Vincent Bourgmayer */ public class FileFilterFactory { @NonNull public static FileFilter getFileFilter(@NonNull String category){ FileFilter filter; switch (category){ case "Rom settings": filter = new SettingsFileFilter(); break; case "Applications": filter = new AppSettingsFileFilter(); break; case "media": filter = new MediaFileFilter(); break; default: filter = new NoCacheFileFilter(); break; } return filter; } } app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.kt 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2024 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.drive.fileFilters; import foundation.e.drive.utils.AppConstants import foundation.e.drive.utils.FileUtils import java.io.File import java.io.FileFilter /** * @author Vincent Bourgmayer * @author Fahim Salam Chowdhury */ object FileFilterFactory { fun buildFileFilter(category: String?): FileFilter { return when (category) { "Rom settings" -> buildSettingsFilter() "Applications" -> buildAppSettingsFilter() "media" -> BasicFileFilter() else -> buildNoCacheFileFilter() } } private fun buildSettingsFilter(): FileFilter { return object : BasicFileFilter() { override fun accept(pathname: File?): Boolean { return super.accept(pathname) && pathname!!.isFile && (pathname.name.startsWith("settings_") && pathname.name.endsWith(".xml") || pathname.name == AppConstants.APPLICATIONS_LIST_FILE_NAME) } } } private fun buildAppSettingsFilter(): FileFilter { return object : BasicFileFilter() { override fun accept(pathname: File?): Boolean { return (super.accept(pathname) && (pathname!!.isFile || (pathname.isDirectory && !pathname.name.lowercase().contains("cache")))) } } } private fun buildNoCacheFileFilter(): FileFilter { return object : BasicFileFilter() { override fun accept(pathname: File?): Boolean { return super.accept(pathname) && !pathname!!.name.lowercase().contains("cache") } } } } private open class BasicFileFilter : FileFilter { override fun accept(pathname: File?): Boolean { return pathname != null && !pathname.isHidden && FileUtils.isNotPartFile(pathname) } } app/src/main/java/foundation/e/drive/fileFilters/MediaFileFilter.javadeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import java.io.File; import java.io.FileFilter; /** * @author Vincent Bourgmayer */ class MediaFileFilter implements FileFilter { /** * Only accept not hidden files: * Media should not be synced if they're hidden files * @param file File to check * @return true if file is accepted */ @Override public boolean accept(File file) { return !file.isHidden(); } } Loading
app/src/main/java/foundation/e/drive/fileFilters/AppSettingsFileFilter.javadeleted 100644 → 0 +0 −27 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import java.io.File; import java.io.FileFilter; import java.util.Locale; /** * @author Vincent Bourgmayer * FileFilter for application Settings */ class AppSettingsFileFilter implements FileFilter { @Override public boolean accept(File pathname) { return pathname.isFile() || (pathname.isDirectory() && !pathname.getName().toLowerCase(Locale.ROOT).contains("cache")); } }
app/src/main/java/foundation/e/drive/fileFilters/CrashlogsFileFilter.javadeleted 100644 → 0 +0 −56 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import androidx.annotation.NonNull; import java.io.File; import java.io.FileFilter; import foundation.e.drive.utils.ServiceExceptionHandler; /** * @Author Vincent Bourgmayer */ public class CrashlogsFileFilter implements FileFilter { private final static long max_timestamp_delta = 864000000; //10 days in ms (240*3600*1000) @Override public boolean accept(@NonNull File pathname) { String fileTimestamp = extractTimestamp(pathname.getName(), ServiceExceptionHandler.LOG_FILE_NAME_PREFIX, ServiceExceptionHandler.LOG_FILE_EXTENSION); long timestamp; try { timestamp = Long.parseLong(fileTimestamp); }catch (NumberFormatException e){ //Can't parse the extracted timestamp //This file has not the expected name. It must be removed return true; } //if current Date - file date >= max deta allowed return ((System.currentTimeMillis() - timestamp ) >= max_timestamp_delta); } /** * Extract the timestamp from the name of the file * UnitTested! * @param fileName Filename * @param prefix prefix to ignore * @param extension extension to ignore * @return the timestamp extracted from the name */ private String extractTimestamp(String fileName, @NonNull String prefix, @NonNull String extension){ return fileName.substring(prefix.length(), (fileName.length() - extension.length())); } } No newline at end of file
app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.javadeleted 100644 → 0 +0 −40 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import androidx.annotation.NonNull; import java.io.FileFilter; /** * @author Vincent Bourgmayer */ public class FileFilterFactory { @NonNull public static FileFilter getFileFilter(@NonNull String category){ FileFilter filter; switch (category){ case "Rom settings": filter = new SettingsFileFilter(); break; case "Applications": filter = new AppSettingsFileFilter(); break; case "media": filter = new MediaFileFilter(); break; default: filter = new NoCacheFileFilter(); break; } return filter; } }
app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.kt 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2024 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.drive.fileFilters; import foundation.e.drive.utils.AppConstants import foundation.e.drive.utils.FileUtils import java.io.File import java.io.FileFilter /** * @author Vincent Bourgmayer * @author Fahim Salam Chowdhury */ object FileFilterFactory { fun buildFileFilter(category: String?): FileFilter { return when (category) { "Rom settings" -> buildSettingsFilter() "Applications" -> buildAppSettingsFilter() "media" -> BasicFileFilter() else -> buildNoCacheFileFilter() } } private fun buildSettingsFilter(): FileFilter { return object : BasicFileFilter() { override fun accept(pathname: File?): Boolean { return super.accept(pathname) && pathname!!.isFile && (pathname.name.startsWith("settings_") && pathname.name.endsWith(".xml") || pathname.name == AppConstants.APPLICATIONS_LIST_FILE_NAME) } } } private fun buildAppSettingsFilter(): FileFilter { return object : BasicFileFilter() { override fun accept(pathname: File?): Boolean { return (super.accept(pathname) && (pathname!!.isFile || (pathname.isDirectory && !pathname.name.lowercase().contains("cache")))) } } } private fun buildNoCacheFileFilter(): FileFilter { return object : BasicFileFilter() { override fun accept(pathname: File?): Boolean { return super.accept(pathname) && !pathname!!.name.lowercase().contains("cache") } } } } private open class BasicFileFilter : FileFilter { override fun accept(pathname: File?): Boolean { return pathname != null && !pathname.isHidden && FileUtils.isNotPartFile(pathname) } }
app/src/main/java/foundation/e/drive/fileFilters/MediaFileFilter.javadeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line /* * Copyright © CLEUS SAS 2018-2019. * Copyright © ECORP SAS 2020. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html */ package foundation.e.drive.fileFilters; import java.io.File; import java.io.FileFilter; /** * @author Vincent Bourgmayer */ class MediaFileFilter implements FileFilter { /** * Only accept not hidden files: * Media should not be synced if they're hidden files * @param file File to check * @return true if file is accepted */ @Override public boolean accept(File file) { return !file.isHidden(); } }