FolderUtils.java 2.12 KB
package com.gimi.common.cinema.utils;

import android.text.TextUtils;
import android.util.Log;

import java.io.File;

/**
 * Created by 李攀 on 2015/6/2
 */
public class FolderUtils {
    public static String getClassPath(String moviePath, String localPath) {
        String cur = moviePath.replace(localPath, "");
        String className = cur.substring(0, cur.indexOf("/"));
        return localPath + className + "/";
    }

    public static String getMovieFolderPath(String moviePath, String localPath) {
        String classPath = getClassPath(moviePath, localPath);
        String cur = moviePath.replace(classPath, "");
        String className = cur.substring(0, cur.indexOf("/"));
        return classPath + className + "/";
    }


    public static String getClassPath(String moviePath, String ip, String folder) {
        String rootPath;
        if (!TextUtils.isEmpty(folder)) {
            rootPath = "/mnt/samba/" + ip + File.separator + folder;
        } else {
            rootPath = "/mnt/samba/" + ip;
        }
        if (TextUtils.isEmpty(moviePath)) {
            Log.d("wugian", "╟  moviePath is null");
            return null;
        }
        Log.d("wugian", "╟ " + rootPath);
        while (!new File(moviePath).getParent().equals(rootPath)) {
            if (new File(new File(moviePath).getParent() + "/TJ").exists()) {
                return new File(moviePath).getPath() + File.separator;
            }
            moviePath = new File(moviePath).getParent();
        }
        return null;
    }

    public static String getMovieFolderPath(String moviePath, String ip, String folder) {
        String classPath = getClassPath(moviePath, ip, folder);
        String replace = moviePath.replace(classPath, "");
        int i = replace.indexOf("/");
        return classPath + replace.substring(0, i + 1);
    }

    public static String getMovieFolderName(String moviePath, String ip, String folder) {
        String classPath = getClassPath(moviePath, ip, folder);
        String movieFolderPath = getMovieFolderPath(moviePath, ip, folder);
        return (movieFolderPath.replace(classPath, "")).replace("/", "");
    }
}