package com.tjzhxx.union.public_store;

import android.os.Environment;

import java.io.File;

public class AppDataFile {

    private File sdcard = Environment.getExternalStorageDirectory();
    private File mAppFile;
	private static AppDataFile mAppDataFile;
	private static final String FILE_ROOT_PATH="logisticsmanage";

	/**
	 * 图片
	 */
	public static final String FILE_PICTURE="Picture";
	
	public static String rootFileName=null;
	
	public AppDataFile(String rootFileName) {
        if(sdcard==null){
            sdcard= Environment.getDataDirectory();
        }
        File rootFile=new File(sdcard,FILE_ROOT_PATH);
        if(!rootFile.exists()){
            rootFile.mkdirs();
        }

        mAppFile=new File(rootFile,rootFileName);
        if(!mAppFile.exists()){
            mAppFile.mkdirs();
        }

		makFile(mAppFile,rootFileName);
	}
	
	public static void init(String rootFileName ){
		if(mAppDataFile ==null){
			mAppDataFile =new AppDataFile(rootFileName);
		}
	}
	
	private void makFile(File appFile, String rootFileName){
		makChildFile(appFile,FILE_PICTURE);
	}

    private File makChildFile(File appFile, String filename){
        File file=new File(appFile,filename);
        if(!file.exists()){
            file.mkdirs();
        }
        return file;
    }

    public static File getAppFile(){
        return mAppDataFile.mAppFile;
    }

	/**
	 * 获取图片目录
	 * @return
	 */
	public static File getPictureFile(){
		File file=new File(getAppFile(),FILE_PICTURE);
		if(!file.exists()){
			file.mkdirs();
		}
		return file;
	}

}
