|
| 1 | +/* |
| 2 | + * Copyright (C) 2022 moacirrf |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +package com.mrf.javadecompiler.openapi; |
| 18 | + |
| 19 | +import com.machinezoo.noexception.Exceptions; |
| 20 | +import com.mrf.javadecompiler.constants.Constants; |
| 21 | +import com.mrf.javadecompiler.exception.ExceptionHandler; |
| 22 | +import java.nio.file.Files; |
| 23 | +import java.nio.file.Path; |
| 24 | +import org.openide.modules.ModuleInstall; |
| 25 | + |
| 26 | +public class Installer extends ModuleInstall { |
| 27 | + |
| 28 | + @Override |
| 29 | + public boolean closing() { |
| 30 | + this.clearTempFolder(Path.of(Constants.TEMP_DIR_PLUGIN)); |
| 31 | + return super.closing(); |
| 32 | + } |
| 33 | + /** |
| 34 | + * Will remove recursivelly all decompiled classes, when close Netbeans. |
| 35 | + * |
| 36 | + * @param path |
| 37 | + */ |
| 38 | + private void clearTempFolder(Path path) { |
| 39 | + Exceptions.wrap(ex -> ExceptionHandler.handleException(ex)).run(() -> { |
| 40 | + if (Files.isDirectory(path) && Files.list(path).count() > 0) { |
| 41 | + Files.list(path).forEach(it -> this.clearTempFolder(it)); |
| 42 | + } |
| 43 | + Files.deleteIfExists(path); |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments