All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.reandroid.apk.DexFileInputSource Maven / Gradle / Ivy

There is a newer version: 1.3.5
Show newest version
/*
 *  Copyright (C) 2022 github.com/REAndroid
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.reandroid.apk;

import com.reandroid.archive.InputSource;
import com.reandroid.archive.RenamedInputSource;

import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class DexFileInputSource extends RenamedInputSource implements Comparable{
    public DexFileInputSource(String name, InputSource inputSource){
        super(name, inputSource);
    }
    public int getDexNumber(){
        return InputSource.getDexNumber(getAlias());
    }
    @Override
    public int compareTo(DexFileInputSource source) {
        return Integer.compare(getDexNumber(), source.getDexNumber());
    }

    public static void sort(List sourceList){
        sourceList.sort(new Comparator() {
            @Override
            public int compare(DexFileInputSource s1, DexFileInputSource s2) {
                return s1.compareTo(s2);
            }
        });
    }

    public static void sortDexFiles(List fileList){
        fileList.sort(new Comparator() {
            @Override
            public int compare(File file1, File file2) {
                int i1 = InputSource.getDexNumber(file1.getName());
                int i2 = InputSource.getDexNumber(file2.getName());
                if(i1 == i2){
                    return 0;
                }
                if(i1 < 0 || i1 < i2){
                    return -1;
                }
                return 1;
            }
        });
    }
    public static List listDexFiles(File dir){
        List results = new ArrayList<>();
        if(!dir.isDirectory()){
            return results;
        }
        File[] files = dir.listFiles();
        if(files == null){
            return results;
        }
        for(File file : files){
            if(file.isFile() && isDexName(file.getName())){
                results.add(file);
            }
        }
        sortDexFiles(results);
        return results;
    }

    public static boolean isDexName(String name){
        return InputSource.getDexNumber(name)>=0;
    }
    static String getDexName(int i){
        if(i==0){
            return "classes.dex";
        }
        return "classes" + i + ".dex";
    }

    public static final String DEX_DIRECTORY_NAME = "dex";
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy