<?php
$domtree = new DOMDocument('1.0', 'utf-8');
$domtree->formatOutput = true;
$xmlRoot = $domtree->createElement('Autoupdate');
$xmlRoot = $domtree->appendChild($xmlRoot);$xsinamespace = 'http://www.w3.org/2001/XMLSchema-instance';
$xsdnamespace = 'http://www.w3.org/2001/XMLSchema';
$xmlRoot->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', $xsinamespace);
$xmlRoot->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsd', $xsdnamespace);
listFolderFiles('gameupdate');
$domtree->save("gameupdate/version.xml");
echo("Ok rồi nha !");
function listFolderFiles($dir){
	global $domtree, $xmlRoot;
		$ffs = scandir($dir);
		foreach($ffs as $ff){
			if($ff == 'version.xml')
			{				
				break;
			}
			if($ff != '.' && $ff != '..'){
				if(is_dir($dir.'/'.$ff))
				{
					$ffssub = scandir($dir.'/'.$ff);
					listFolderFiles($dir.'/'.$ff);
				}
				else
				{
					$md5file = md5_file($dir."/".$ff);
					$md5file = strtoupper($md5file);
					$sizefile = filesize($dir."/".$ff);
					$item = $domtree->createElement("Item");
					$xmlRoot->appendChild($item);

					$path =$domtree->createElement("Path");					
					$str =str_replace("gameupdate/","",$dir.'/'.$ff);
					$nPath = str_replace("/","\\",$str);
					$path->appendChild($domtree->createTextNode($nPath));
					$item->appendChild($path);
										
					$link =$domtree->createElement("Link");					
					$str =str_replace("gameupdate/","",$dir.'/'.$ff);
					$nLink = str_replace("/","/",$str);
					$link->appendChild($domtree->createTextNode($nLink));					
					$item->appendChild($link);
					
					$hash =$domtree->createElement("Hash");
					$hash->appendChild($domtree->createTextNode($md5file));
					$item->appendChild($hash);
					
					$size =$domtree->createElement("Size");
					$size->appendChild($domtree->createTextNode($sizefile));
					$item->appendChild($size);
				}
			}
		}
}
?>