<?php

class Icons {

	function __constructor(){}

	function saveIconSet($d){
 	 
		$dpFile = Config::get("private_system_path")."/config/users/".User::getIntance()->userInfo->username."_dp.txt";
		$dpStr = Util::readFile($dpFile);
	 	if($dpStr===false){
	 		Response::sendResponse(false, null, "icons", "user_icons_doesnot_exist");
	 	}
	 	
		$dp = DataSerializer::deserialize($dpStr);
	 	$dp->icons = $d;/*(object) array();
	 	$dp->icons->iconsFilename =  $d->iconsFilename;
	 	$dp->icons->desktopIconsFormat = $d->desktopIconsFormat;*/
	 	
	 	if(!Util::writeFile($dpFile,DataSerializer::serialize($dp))){
	 	 	Response::sendResponse(false, null, "icons", "user_icons_cannot_write");
	 	}
 	 	
		Response::sendOKResponse((object) array("success"=>true));
	}	 
	
	function getIconSet($d){
 	 
		$themeFile = "resources/icons/".$d->fileName;
 	 	if(!is_file($themeFile)){
 	 		Response::sendResponse(false, null, "icons", "icons_doesnot_exist");
		}
		
		$theme = WddxSerializer::deserialize(Util::readFile($themeFile));
 	 	
 	 	
		Response::sendOKResponse($theme);
	}	 
	function getAllIcons(){
	 	
	 	$ud = new UD();
	 	$ud->readOnlyFiles = true;
	 	
	 	$FaF = $ud->getFoldersAndFiles("resources/icons");
	 	if($FaF<0){
	 		Response::sendErrorResponse($ud->getErrorID($FaF), $ud->getErrorMsg($FaF));
		}
		Response::sendOKResponse($FaF);
	}

	function getIconImage($a){
		 
		$realPath = "resources/icons/image/".basename($a[0]);
		 
		readfile($realPath);
		 
		exit;
	}
}
?>