Changeset 869 for trunk/Modules/Export
- Timestamp:
- Feb 6, 2016, 2:15:49 PM (9 years ago)
- Location:
- trunk/Modules/Export
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Export/Export.php
r866 r869 731 731 'LEFT JOIN `Export` ON `Export`.`Id` = `ExportTask`.`Export` WHERE '. 732 732 '((`Export`.`OutputType` = 9) OR (`Export`.`OutputType` = 10)) AND '. 733 '(`TimeFinish` IS NULL) OR (`Export` ='.$TaskId.') ORDER BY ` Progress` DESC'); // `Export`='.$Export->Id733 '(`TimeFinish` IS NULL) OR (`Export` ='.$TaskId.') ORDER BY `TimeQueued`'); // `Export`='.$Export->Id 734 734 while($Task = $DbResult->fetch_assoc()) 735 735 { -
trunk/Modules/Export/ProcessTask.php
r867 r869 8 8 include_once('Export.php'); 9 9 include_once('ExportOutput.php'); 10 11 class Task extends Model 12 { 13 var $Id; 14 15 function SetProgress($Progress) 16 { 17 $this->System->Database->query('UPDATE `ExportTask` SET `Progress`='.$Progress.' WHERE `Id`='.$this->Id); 18 } 19 } 20 21 class TaskExport extends Task 22 { 23 function DeleteOldFiles($deldir) 24 { 25 if(file_exists($deldir.'/')) 26 { 27 $Dir = opendir($deldir.'/') ; 28 while(($File = readdir($Dir)) !== false) 29 { 30 if(($File != '..') and ($File != '.') and (!is_dir($File))) unlink($deldir.'/'.$File); 31 } 32 closedir($Dir); 33 } 34 } 35 36 function rcopy($src, $dst) 37 { 38 if (file_exists($dst)) $this->DeleteOldFiles($dst); 39 if (is_dir($src)) { 40 if (!file_exists($dst)) mkdir($dst, 0777, true); 41 $files = scandir($src); 42 foreach ($files as $file) 43 if ($file != "." and $file != ".." and (!is_dir($src.'/'.$file))) $this->rcopy($src.'/'.$file, $dst.'/'.$file); 44 } 45 else if (file_exists($src)) copy($src, $dst); 46 } 47 48 function GetWinZPatch($patch) 49 { 50 //TMP="Z:\\a\\www\\wowpreklad\\tmp\\Export\\${EXPORTID}\\" 51 $patch = str_replace(DIRECTORY_SEPARATOR, '\\', $patch); 52 $patch = 'Z:'.$patch; 53 return $patch; 54 } 55 56 function MPQPack($packdir) 57 { 58 if(file_exists($packdir.DIRECTORY_SEPARATOR)) 59 { 60 $Dir = opendir($packdir.DIRECTORY_SEPARATOR); 61 while(($File = readdir($Dir)) !== false) 62 { 63 if(($File != '..') and ($File != '.')) { 64 $File = str_replace('/', DIRECTORY_SEPARATOR, $File); 65 $InDir = ''; 66 if (strpos($packdir, 'dbc') !== false) { 67 $InDir = 'DBFilesClient\\'; 68 if (DIRECTORY_SEPARATOR == '/') // linux 69 $InDir = 'DBFilesClient\\\\'; 70 } 71 if (strpos($packdir.$File, 'luaGlobal') !== false) { 72 $InDir = 'Interface\\FrameXML\\'; 73 if (DIRECTORY_SEPARATOR == '/') // linux 74 $InDir = 'Interface\\\\FrameXML\\\\'; 75 } 76 if (strpos($packdir.$File, 'luaGlue') !== false) { 77 $InDir = 'Interface\\GlueXML\\'; 78 if (DIRECTORY_SEPARATOR == '/') // linux 79 $InDir = 'Interface\\\\GlueXML\\\\'; 80 } 81 82 if (DIRECTORY_SEPARATOR == '/') // linux 83 echo exec('wine cmd /C mpq.exe "'.$this->GetWinZPatch($packdir.DIRECTORY_SEPARATOR. 84 '..'.DIRECTORY_SEPARATOR).'patch-5.MPQ" '.$InDir.basename($File).' "'. 85 $this->GetWinZPatch($packdir.DIRECTORY_SEPARATOR).$File.'" '); 86 87 if (DIRECTORY_SEPARATOR == '\\') // windows 88 echo exec('mpq.exe "'.$packdir.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR. 89 'patch-5.MPQ" '.$InDir.basename($File).' "'.$packdir.DIRECTORY_SEPARATOR.$File.'" '); 90 91 echo "\n"; 92 } 93 } 94 closedir($Dir); 95 } 96 } 97 98 function ExportDBC($Task) 99 { 100 $Export = new Export($this->System); 101 $Export->Id = $Task['ExportId']; 102 $Export->Init(); 103 104 echo(StrFTime("%d/%m/%Y %H:%M:%S", time()).': Generování DBC souborů pro export '.$Export->Id.'.. '."\n"); 105 $this->SetProgress(10); 106 107 echo('Mazání starých souborů...'."\n"); 108 109 // Delete old files 110 $this->DeleteOldFiles($Export->TempDir.'dbc'); 111 if(file_exists($Export->TempDir.'CzWoW_DBC.zip')) unlink($Export->TempDir.'CzWoW_DBC.zip'); 112 113 $this->SetProgress(20); 114 if(function_exists('gzcompress')) 115 { 116 $Export->ExportToDBC(); 117 echo('Komprese...'."\n"); 118 exec('zip -r -j '.$Export->TempDir.'CzWoW_DBC.zip '.$Export->TempDir.'dbc/'); 119 $this->SetProgress(80); 120 } else echo('Funkce pro tvorbu Zip souboru není podporována!'."\n"); 121 } 122 123 function ExportEXE($Task) 124 { 125 $Export = new ExportAddon($this->System); 126 $Export->Id = $Task['ExportId']; 127 $Export->Init(); 128 $Export->LoadFilters(); 129 130 echo(StrFTime("%d/%m/%Y %H:%M:%S", time()).': Generování EXE souboru pro export '.$Export->Id.'.. '."\n"); 131 $nsifile = 'install.nsi'; 132 133 // Delete old files 134 $this->SetProgress(1); 135 echo('Delete old files...'."\n"); 136 $this->DeleteOldFiles($Export->TempDir.'dbc'); 137 $this->DeleteOldFiles($Export->TempDir.'lua'); 138 $this->DeleteOldFiles($Export->TempDir.'CzWoW'); 139 140 // copy need files 141 $this->SetProgress(5); 142 echo('Copy files...'."\n"); 143 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/patch-5.MPQ', $Export->TempDir.'patch-5.MPQ'); 144 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/'.$nsifile, $Export->TempDir.$nsifile); 145 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/WowLua.exe', $Export->TempDir.'WowLua.exe'); 146 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/CzWoW/', $Export->TempDir.'CzWoW/'); 147 $this->rcopy('files/WoW.ico', $Export->TempDir.'WoW.ico'); 148 $this->rcopy('files/Fonts/', $Export->TempDir.'Fonts/'); 149 150 $this->SetProgress(10); 151 echo('Export lua...'."\n"); 152 $Export->ExportToLua(); 153 $this->SetProgress(15); 154 echo('Export CzWoW...'."\n"); 155 $Export->MakeAddon(); 156 $this->SetProgress(30); 157 echo('Export dbc...'."\n"); 158 $Export->ExportToDBC(); 159 160 echo('Create readme...'."\n"); 161 $this->SetProgress(60); 162 $File = new FileStream(); 163 $File->CreateFile($Export->TempDir.'ReadMe.htm'); 164 $File->WriteLine($Export->GetReadme()); 165 unset($File); 166 167 echo('Packing files...'."\n"); 168 $this->SetProgress(70); 169 $workdir = str_replace('/',DIRECTORY_SEPARATOR, $Export->TempDir); 170 $this->MPQPack($workdir.'lua'); 171 $this->SetProgress(80); 172 $this->MPQPack($workdir.'dbc'); 173 174 $this->SetProgress(90); 175 echo('Creating instalator...'."\n"); 176 if (DIRECTORY_SEPARATOR == '/') // linux 177 echo exec('makensis '.$workdir.$nsifile); 178 179 if (DIRECTORY_SEPARATOR == '\\') // windows 180 echo exec('"'.$workdir.$nsifile.'" '); //"c:\Program Files (x86)\NSIS\makensisw.exe" /Xscriptcmd 181 } 182 183 function Run() 184 { 185 global $Config; 186 187 while(1) 188 { 189 $DbResult = $this->Database->query('SELECT `ExportTask`.`Id`, `ExportTask`.`Export`, '. 190 '`Export`.`Id` AS `ExportId`, `Export`.`OutputType` AS `ExportOutput` FROM `ExportTask` '. 191 'LEFT JOIN `Export` ON `Export`.`Id` = `ExportTask`.`Export` WHERE '. 192 '(`ExportTask`.`TimeFinish` IS NULL) ORDER BY `TimeQueued`'); 193 while($Task = $DbResult->fetch_assoc()) 194 { 195 $this->Id = $Task['Id']; 196 if($Task['ExportId'] != '') 197 { 198 try 199 { 200 $this->SetProgress(0); 201 $this->Database->update('ExportTask', '`Id`='.$this->Id, array('TimeStart' => 'NOW()')); 202 203 if($Task['ExportOutput'] == 9) 204 { 205 $this->ExportDBC($Task); 206 } else 207 if($Task['ExportOutput'] == 10) 208 { 209 $this->ExportEXE($Task); 210 } else echo('Unknown export output type '.$Task['ExportOutput']."\n"); 211 212 $this->SetProgress(100); 213 $this->Database->update('ExportTask', '`Id`='.$this->Id, array('TimeFinish' => 'NOW()')); 214 echo ("\n"."Hotovo"."\n"); 215 } catch (Exception $E) 216 { 217 echo 'Caught exception: ', $E->getMessage(), "\n"; 218 } 219 } else 220 { 221 $this->Database->query('DELETE FROM `ExportTask` WHERE `Id`='.$this->Id); 222 echo('Export '.$Task['Export'].' nenalezen. Jeho úloha smazána.'."\n"); 223 } 224 } 225 sleep($Config['ExportTaskProcessPeriod']); 226 } 227 } 228 } 10 229 11 230 //LoadCommandLineParameters(); … … 14 233 $System->Run(); 15 234 16 function SetProgress($Export, $Progress) 17 { 18 global $System; 19 20 $System->Database->query('UPDATE `ExportTask` SET `Progress`='.$Progress.' WHERE `Export`='.$Export->Id); 21 } 22 23 function DeleteOldFiles($deldir) 24 { 25 if(file_exists($deldir.'/')) 26 { 27 $Dir = opendir($deldir.'/') ; 28 while(($File = readdir($Dir)) !== false) 29 { 30 if(($File != '..') and ($File != '.') and (!is_dir("$File"))) unlink($deldir.'/'.$File); 31 } 32 closedir($Dir); 33 } 34 } 35 36 function rcopy($src, $dst) 37 { 38 // echo $src.' '.$dst."\n"; 39 if (file_exists($dst)) DeleteOldFiles($dst); 40 if (is_dir($src)) { 41 if (!file_exists($dst)) mkdir($dst, 0777, true); 42 $files = scandir($src); 43 foreach ($files as $file) 44 if ($file != "." && $file != ".." and (!is_dir("$src/$file"))) rcopy("$src/$file", "$dst/$file"); 45 } 46 else if (file_exists($src)) copy($src, $dst); 47 } 48 49 function GetWinZPatch($patch) 50 { 51 //TMP="Z:\\a\\www\\wowpreklad\\tmp\\Export\\${EXPORTID}\\" 52 $patch = str_replace(DIRECTORY_SEPARATOR,'\\', $patch); 53 $patch = 'Z:'.$patch; 54 return $patch; 55 } 56 57 function MPQPack($packdir) 58 { 59 if(file_exists($packdir.DIRECTORY_SEPARATOR)) 60 { 61 $Dir = opendir($packdir.DIRECTORY_SEPARATOR) ; 62 while(($File = readdir($Dir)) !== false) 63 { 64 if(($File != '..') and ($File != '.')) { 65 $File = str_replace('/',DIRECTORY_SEPARATOR,$File); 66 $InDir = ''; 67 if (strpos($packdir,'dbc') !== false) { 68 $InDir = 'DBFilesClient\\'; 69 if (DIRECTORY_SEPARATOR == '/') // linux 70 $InDir = 'DBFilesClient\\\\'; 71 } 72 if (strpos($packdir.$File,'luaGlobal') !== false) { 73 $InDir = 'Interface\\FrameXML\\'; 74 if (DIRECTORY_SEPARATOR == '/') // linux 75 $InDir = 'Interface\\\\FrameXML\\\\'; 76 } 77 if (strpos($packdir.$File,'luaGlue') !== false) { 78 $InDir = 'Interface\\GlueXML\\'; 79 if (DIRECTORY_SEPARATOR == '/') // linux 80 $InDir = 'Interface\\\\GlueXML\\\\'; 81 } 82 83 if (DIRECTORY_SEPARATOR == '/') // linux 84 echo exec('wine cmd /C mpq.exe "'.GetWinZPatch($packdir.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR).'patch-5.MPQ" '.$InDir.basename($File).' "'.GetWinZPatch($packdir.DIRECTORY_SEPARATOR).$File.'" '); 85 86 if (DIRECTORY_SEPARATOR == '\\') // windows 87 echo exec('mpq.exe "'.$packdir.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'patch-5.MPQ" '.$InDir.basename($File).' "'.$packdir.DIRECTORY_SEPARATOR.$File.'" '); 88 89 echo "\n"; 90 } 91 } 92 closedir($Dir); 93 } 94 } 95 96 while(1) 97 { 98 // DBC files 99 $DbResult = $System->Database->query('SELECT `ExportTask`.`Id`, `ExportTask`.`Export`, `Export`.`Id` AS `ExportId` FROM `ExportTask`'. 100 ' LEFT JOIN `Export` ON `Export`.`Id` = `ExportTask`.`Export` WHERE (`Export`.`OutputType` = 9) '. 101 ' AND (`ExportTask`.`TimeFinish` IS NULL)'); 102 while($DbRow = $DbResult->fetch_assoc()) 103 { 104 echo(StrFTime("%d/%m/%Y %H:%M:%S", time()).': Generování DBC souborů pro export '.$DbRow['ExportId'].'.. '."\n"); 105 if($DbRow['ExportId'] != '') 106 { 107 try 108 { 109 $System->Database->update('ExportTask', '`Id`='.$DbRow['Id'], array('TimeStart' => 'NOW()')); 110 111 $Export = new Export($System); 112 $Export->Id = $DbRow['ExportId']; 113 $Export->Init(); 114 115 SetProgress($Export, 10); 116 117 echo('Mazání starých souborů...'."\n"); 118 119 // Delete old files 120 DeleteOldFiles($Export->TempDir.'dbc'); 121 if(file_exists($Export->TempDir.'CzWoW_DBC.zip')) unlink($Export->TempDir.'CzWoW_DBC.zip'); 122 123 SetProgress($Export, 20); 124 if(function_exists('gzcompress')) 125 { 126 $Export->ExportToDBC(); 127 echo('Komprese...'."\n"); 128 exec('zip -r -j '.$Export->TempDir.'CzWoW_DBC.zip '.$Export->TempDir.'dbc/'); 129 echo('Hotovo'."\n"); 130 SetProgress($Export, 80); 131 } else echo('Funkce pro tvorbu Zip souboru není podporována!'."\n"); 132 $System->Database->query('UPDATE `ExportTask` SET `TimeFinish`=NOW() WHERE `Export`='.$Export->Id); 133 } catch (Exception $e) 134 { 135 echo 'Caught exception: ', $e->getMessage(), "\n"; 136 } 137 SetProgress($Export, 100); 138 } else 139 { 140 $System->Database->query('DELETE FROM `ExportTask` WHERE `Export`='.$DbRow['Export']); 141 echo('Export '.$DbRow['Export'].' nenalezen. Jeho úloha smazána.'."\n"); 142 } 143 } 144 145 // EXE files 146 $DbResult = $System->Database->query('SELECT `ExportTask`.`Id`, `ExportTask`.`Export`, `Export`.`Id` AS `ExportId` FROM `ExportTask`'. 147 ' LEFT JOIN `Export` ON `Export`.`Id` = `ExportTask`.`Export` WHERE (`Export`.`OutputType` = 10) '. 148 ' AND (`ExportTask`.`TimeFinish` IS NULL)'); 149 while($DbRow = $DbResult->fetch_assoc()) 150 { 151 echo(StrFTime("%d/%m/%Y %H:%M:%S", time()).': Generování EXE souboru pro export '.$DbRow['ExportId'].'.. '."\n"); 152 if($DbRow['ExportId'] != '') 153 { 154 try 155 { 156 $System->Database->update('ExportTask', '`Id`='.$DbRow['Id'], array('TimeStart' => 'NOW()')); 157 // echo shell_exec('"'.dirname(__FILE__).'./client_cz_export.sh" '.$DbRow['ExportId'].''); 158 159 160 $Export = new ExportAddon($System); 161 $Export->Id = $DbRow['ExportId']; 162 $Export->Init(); 163 $Export->LoadFilters(); 164 165 $nsifile = 'install.nsi'; 166 167 // Delete old files 168 SetProgress($Export, 1); 169 echo('Delete old files...'."\n"); 170 DeleteOldFiles($Export->TempDir.'dbc'); 171 DeleteOldFiles($Export->TempDir.'lua'); 172 DeleteOldFiles($Export->TempDir.'CzWoW'); 173 174 //copy need files 175 SetProgress($Export, 5); 176 echo('Copy files...'."\n"); 177 rcopy('files/'.$Export->ClientVersion['Version'].'/patch-5.MPQ', $Export->TempDir.'patch-5.MPQ'); 178 rcopy('files/'.$Export->ClientVersion['Version'].'/'.$nsifile, $Export->TempDir.$nsifile); 179 rcopy('files/'.$Export->ClientVersion['Version'].'/WowLua.exe', $Export->TempDir.'WowLua.exe'); 180 rcopy('files/'.$Export->ClientVersion['Version'].'/CzWoW/', $Export->TempDir.'CzWoW/'); 181 rcopy('files/WoW.ico', $Export->TempDir.'WoW.ico'); 182 rcopy('files/Fonts/', $Export->TempDir.'Fonts/'); 183 184 SetProgress($Export, 10); 185 echo('Export lua...'."\n"); 186 $Export->ExportToLua(); 187 SetProgress($Export, 15); 188 echo('Export CzWoW...'."\n"); 189 $Export->MakeAddon(); 190 SetProgress($Export, 30); 191 echo('Export dbc...'."\n"); 192 $Export->ExportToDBC(); 193 194 echo('Create readme...'."\n"); 195 SetProgress($Export, 60); 196 $File = new FileStream(); 197 $File->CreateFile($Export->TempDir.'ReadMe.htm'); 198 $File->WriteLine($Export->GetReadme()); 199 unset($File); 200 201 echo('Packing files...'."\n"); 202 SetProgress($Export, 70); 203 $workdir = str_replace('/',DIRECTORY_SEPARATOR, $Export->TempDir); 204 MPQPack($workdir.'lua'); 205 SetProgress($Export, 80); 206 MPQPack($workdir.'dbc'); 207 208 SetProgress($Export, 90); 209 echo('Creating instalator...'."\n"); 210 if (DIRECTORY_SEPARATOR == '/') // linux 211 echo exec('makensis '.$workdir.$nsifile); 212 213 if (DIRECTORY_SEPARATOR == '\\') // windows 214 echo exec('"'.$workdir.$nsifile.'" '); //"c:\Program Files (x86)\NSIS\makensisw.exe" /Xscriptcmd 215 216 SetProgress($Export, 100); 217 echo ("\n"."Hotovo"."\n"); 218 $System->Database->query('UPDATE `ExportTask` SET `TimeFinish`=NOW() WHERE `Export`='.$DbRow['Export']); 219 } catch (Exception $e) 220 { 221 echo 'Caught exception: ', $e->getMessage(), "\n"; 222 } 223 } else 224 { 225 $System->Database->query('DELETE FROM `ExportTask` WHERE `Export`='.$DbRow['Export']); 226 echo('Export '.$DbRow['Export'].' nenalezen. Jeho úloha smazána.'."\n"); 227 } 228 } 229 sleep($Config['ExportTaskProcessPeriod']); 230 } 231 232 // WriteLog('Generování dbc úloh', LOG_TYPE_DOWNLOAD); 235 $Task = new TaskExport($System); 236 $Task->Run();
Note:
See TracChangeset
for help on using the changeset viewer.