package cn.net.caoyao.cpzshandset.common.config;

import java.io.File;
import java.util.Map;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import cn.net.caoyao.cpzshandset.common.util.CacheGet;
import cn.net.caoyao.cpzshandset.common.util.CachePut;
import cn.net.caoyao.cpzshandset.common.util.GetSdcardPath;

public class SDCardConfig {

	public static final String ROOTDIR = "cn.net.caoyao.cpzshandset";
	
	private static final String CACHE_SDCONFIG="sdConfig";
	private static final String CACHE_ROOT_PATH="CpzsCommonHandset";

	/**
	 * 获取外置SD卡路径List
	 * @return
	 */
	public static Map<String, String> getSDList() {
		
		//return GetSdcardPath.getSDList();
		return GetSdcardPath.getExternalStorageDirectory();
	}
	
	/**
	 * 保存外置SD卡的路径
	 * @param context 上下文对象
	 * @param sdPath SD卡路径
	 */
	public static void saveSDPath(Context context,String sdPath) {
		if (TextUtils.isEmpty(sdPath)) {
			sdPath=GetSdcardPath.getSDCardPath();
		}
		CachePut cacheP = new CachePut();
		cacheP.putCacheStringG(context, CACHE_SDCONFIG, "sdPath", sdPath);
//		CachePut.putCache(context, CACHE_SDCONFIG, "sdPath", sdPath);
	}
	
	/**
	 * 获取SD卡路径
	 * 
	 * @param context
	 * @return
	 */
	public static String getSDcardPath(Context context) {

//		String path = Environment.getExternalStorageDirectory().toString();
//		String path= CacheGet.getCacheString(context, CACHE_SDCONFIG, "sdPath");//modify at 
		CacheGet cacheG = new CacheGet();
		String path = cacheG.getCacheStringG(context, CACHE_SDCONFIG, "sdPath");
		if (TextUtils.isEmpty(path)) {
			path=GetSdcardPath.getSDCardPath();
		}
		return path;
	}

	/**
	 * 获取sd卡路径
	 *
	 * @return
	 */
	public static String getSDPathForLog() {
		String sdDir = "";
		boolean sdCardExist = Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
		if (sdCardExist) {
			sdDir = Environment.getExternalStorageDirectory()
					+ "/"+CACHE_ROOT_PATH+"/cashLog/";// 获取跟目录
		} else {
			//cn.net.caoyao.cpzshandset
			sdDir = "/data/data"+ROOTDIR+"/cashLog/";
		}

		File file = new File(sdDir);
		if (!file.exists()) {
			file.mkdirs();
		}
		return sdDir;
	}
	/**
	 * 获取启动页路径
	 * @param context
	 * @return
	 */
	public static String getStartSavePath(Context context) {
		
		return getSDcardPath(context) + "/" + ROOTDIR + "/flush";
	}

	/**
	 * 获取缓存路径
	 * 
	 * @param context
	 * @return
	 */
	public static String getCachePath(Context context) {

		return getSDcardPath(context) + "/" + ROOTDIR + "/cache";
	}
	
	/**
	 * 获取缓存路径
	 * 
	 * @param context
	 * @return
	 */
	public static String getBasePath(Context context) {

		return getSDcardPath(context) + "/" + ROOTDIR;
	}
	/**
	 * 获取缓存文件路径
	 * 
	 * @param context
	 * @return
	 */
	public static String getFileCachePath(Context context) {

		return getSDcardPath(context) + "/" + ROOTDIR + "/files";
	}
	
	/**
	 * 获取缓存路径
	 * 
	 * @param context
	 * @return
	 */
	public static String getImageCachePath(Context context) {
		return getSDcardPath(context) + "/" + ROOTDIR + "/cache/image";
	}
}
