source: trunk/Modules/Export/ProcessTask.php@ 735

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