anchor.diff:  					lager:info("Update csv Diff ~p~n~p", [{I#file_info.mtime,butil:sec(I#file_info.mtime)}, {Date,Lastmod}]),
   					case butil:sec(I#file_info.mtime) < Lastmod of
   						true ->
  -							update_csv();
  +							update_csv(Url);
   						false ->
   							uptodate
   					end;
   				_ ->
  -					update_csv()
  +					update_csv(Url)
   			end
   	end.
  -update_csv() ->
  -	case application:get_env(bkdcore,geoipv4) of
  -		undefined ->
  -			Url = "";
  -		{ok,Url} ->
  -			ok
  -	end,		
  -	case length(Url) > 0 of
  -		true ->
  -			{ok, "200", _, Body} = butil:http(Url),
  -			{ok,L} = zip:extract(Body,[memory]),
  -			{_,Csv} = butil:findtrue(fun({Name,_B}) -> 
  -										string:str(Name,".csv") > 0
  -									end,L),
  -			filelib:ensure_dir(butil:project_rootpath()++"/priv/geoip/"),
  -			file:write_file(butil:project_rootpath() ++ "/priv/geoip/geoip.csv",Csv);
  -		_ ->
  -			ok
  -	end.
  -
  -consci([HL|CL],L) ->
  -	H = butil:tobin(HL),
  -	put(c,undefined),
  -	case lists:member(HL,asia()) of
  -		true ->	put(c,asia);
  -		_ -> ok
  -	end,
  -	case lists:member(HL,europe()) of
  -		true ->	put(c,europe);
  -		_ -> ok
  -	end,	
  -	case lists:member(HL,america()) of
  -		true ->	put(c,america);
  -		_ -> ok
  -	end,
  -	case proplists:get_value(H,?LANGUAGES) of
  -		undefined -> Lang = [];
  -		Lang -> ok
  -	end,
  -	consci(CL,[#ci{country = H, continent = get(c),languages = Lang}|L]);
  -consci([], L) ->
  -	L.
  +update_csv(Url) ->
  +	filelib:ensure_dir(butil:project_rootpath()++"/priv/geoip/"),
  +	case butil:http("http://download.geonames.org/export/dump/countryInfo.txt") of
  +		{ok, "200", _, BodyCI} ->
  +			file:write_file(butil:project_rootpath() ++ "/priv/geoip/countryInfo.txt",BodyCI);
  +		_ ->
  +			ok
  +	end,
  +	{ok, "200", _, Body} = butil:http(Url),
  +	{ok,L} = zip:extract(Body,[memory]),
  +	[begin
  +		case filename:split(Name) of
  +			[_,"GeoIP2-Country-Blocks-IPv4.csv"] ->
  +				Fn = "geoip.csv";
  +			[_,"GeoIP2-Country-Blocks-IPv6.csv"] ->
  +				Fn = "ipv6.csv";
  +			_ ->
  +				Fn = undefined
  +		end,
  +		case Fn of
  +			undefined ->
  +				ok;
  +			_ ->
  +				file:write_file(butil:project_rootpath() ++ "/priv/geoip/"++Fn,Bin)
  +		end
  +	end || {Name,Bin} <- L].
  +
   
   find_ip({Min, Max, Country, _Left, _Right}, IP) when IP > Min, IP < Max ->
   	Country;
  
positive.code: code_change(_, State, _) ->
  	{ok, State}.
  init(_) ->
  	% filelib:ensure_dir(butil:project_rootpath()++"/priv/geoip/"),
  	C = ets:new(countries,[set,private,{keypos,#ci.country}]),
  	% [ets:insert(C,{Ctry}) || Ctry <- tuple_to_list(?COUNTRIES)],
  	% [ets:insert(C,{{langs, Ctry},L}) || {Ctry,L} <- ?LANGUAGES],
  	ets:insert(C,consci(europe(), [])),
  	ets:insert(C,consci(asia(), [])),
  	ets:insert(C,consci(america(), [])),
  	Loclangs = dict:from_list(loclangs()),
  	case filelib:is_dir(butil:project_rootpath()++"/priv/geoip/") of
  		true ->
  			self() ! {check_file,0};
  		_ ->
  			ok
  	end,
  	{ok, #gip{countries = C,loclangs = Loclangs}}.
  
  check_update_csv() ->
  	case application:get_env(bkdcore,geoipv4) of
  
negative.code: handle_cast({save_tree, T}, P) ->
  	lager:info("bkdweb_geoip saving geoip tree"),
  	gen_server:cast(access,{save_tree,T}),
  	butil:savetermfile(butil:project_rootpath()++"/priv/geoip/tree.bin", T),
  	{noreply, P#gip{tree = T}};
  handle_cast({print_info}, P) ->
  	io:format("treesize ~p~n", [tuple_size(P#gip.tree)]),
  	{noreply, P};
  handle_cast(_X, P) ->
  	{noreply, P}.
  