source: trunk/Modules/Export/ProcessTask.php

Last change on this file was 900, checked in by chronos, 5 weeks ago
  • Fixed: More form input fields validation.
  • Modified: Code cleanup.
File size: 7.8 KB
Line 
1<?php
2
3ini_set('memory_limit', '100M');
4
5include_once(dirname(__FILE__).'/../../includes/Global.php');
6include_once(dirname(__FILE__).'/../../includes/zip.lib.php');
7
8include_once('Export.php');
9include_once('ExportOutput.php');
10
11class 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
21class 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 {
41 if (!file_exists($dst)) mkdir($dst, 0777, true);
42 $files = scandir($src);
43 foreach ($files as $file)
44 {
45 if (($file != ".") and ($file != "..") and (!is_dir($src.'/'.$file)))
46 $this->rcopy($src.'/'.$file, $dst.'/'.$file);
47 }
48 }
49 else if (file_exists($src)) copy($src, $dst);
50 }
51
52 function GetWinZPatch($patch)
53 {
54 //TMP="Z:\\a\\www\\wowpreklad\\tmp\\Export\\${EXPORTID}\\"
55 $patch = str_replace(DIRECTORY_SEPARATOR, '\\', $patch);
56 $patch = 'Z:'.$patch;
57 return $patch;
58 }
59
60 function MPQPack($packdir)
61 {
62 if (file_exists($packdir.DIRECTORY_SEPARATOR))
63 {
64 $Dir = opendir($packdir.DIRECTORY_SEPARATOR);
65 while (($File = readdir($Dir)) !== false)
66 {
67 if (($File != '..') and ($File != '.'))
68 {
69 $File = str_replace('/', DIRECTORY_SEPARATOR, $File);
70 $InDir = '';
71 if (strpos($packdir, 'dbc') !== false)
72 {
73 $InDir = 'DBFilesClient\\';
74 if (DIRECTORY_SEPARATOR == '/') // linux
75 $InDir = 'DBFilesClient\\\\';
76 }
77 if (strpos($packdir.$File, 'luaGlobal') !== false)
78 {
79 $InDir = 'Interface\\FrameXML\\';
80 if (DIRECTORY_SEPARATOR == '/') // linux
81 $InDir = 'Interface\\\\FrameXML\\\\';
82 }
83 if (strpos($packdir.$File, 'luaGlue') !== false)
84 {
85 $InDir = 'Interface\\GlueXML\\';
86 if (DIRECTORY_SEPARATOR == '/') // linux
87 $InDir = 'Interface\\\\GlueXML\\\\';
88 }
89
90 if (DIRECTORY_SEPARATOR == '/') // linux
91 {
92 echo(exec('wine mpq.exe "'.$this->GetWinZPatch($packdir.DIRECTORY_SEPARATOR.
93 '..'.DIRECTORY_SEPARATOR).'patch-5.MPQ" '.$InDir.basename($File).' "'.
94 $this->GetWinZPatch($packdir.DIRECTORY_SEPARATOR).$File.'" '));
95 } else
96 if (DIRECTORY_SEPARATOR == '\\') // windows
97 {
98 echo(exec('mpq.exe "'.$packdir.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.
99 'patch-5.MPQ" '.$InDir.basename($File).' "'.$packdir.DIRECTORY_SEPARATOR.$File.'" '));
100 }
101
102 echo("\n");
103 }
104 }
105 closedir($Dir);
106 }
107 }
108
109 function ExportDBC($Task)
110 {
111 $Export = new Export($this->System);
112 $Export->Id = $Task['ExportId'];
113 $Export->Init();
114
115 echo(date("j.n.Y H:i:s", time()).': Generování DBC souborů pro export '.$Export->Id.'.. '."\n");
116 $this->SetProgress(10);
117
118 echo('Mazání starých souborů...'."\n");
119
120 // Delete old files
121 $this->DeleteOldFiles($Export->TempDir.'dbc');
122 if (file_exists($Export->TempDir.'CzWoW_DBC.zip'))
123 {
124 unlink($Export->TempDir.'CzWoW_DBC.zip');
125 }
126
127 $this->SetProgress(20);
128 if (function_exists('gzcompress'))
129 {
130 echo(strip_tags($Export->ExportToDBC()));
131 echo('Komprese...'."\n");
132 $SourceDir = $Export->TempDir.'dbc/';
133 if (file_exists($SourceDir))
134 {
135 exec('zip -r -j '.$Export->TempDir.'CzWoW_DBC.zip '.$SourceDir);
136 } else echo('Directory doesn\'t exist '.$SourceDir);
137 $this->SetProgress(80);
138 } else echo('Funkce pro tvorbu Zip souboru není podporována!'."\n");
139 }
140
141 function ExportEXE($Task)
142 {
143 $Export = new ExportAddon($this->System);
144 $Export->Id = $Task['ExportId'];
145 $Export->Init();
146 $Export->LoadFilters();
147
148 echo(date("j.n.Y H:i:s", time()).': Generování EXE souboru pro export '.$Export->Id.'.. '."\n");
149 $nsifile = 'install.nsi';
150
151 // Delete old files
152 $this->SetProgress(1);
153 echo('Delete old files...'."\n");
154 $this->DeleteOldFiles($Export->TempDir.'dbc');
155 $this->DeleteOldFiles($Export->TempDir.'lua');
156 $this->DeleteOldFiles($Export->TempDir.'CzWoW');
157
158 // copy needed files
159 $this->SetProgress(5);
160 echo('Copy files...'."\n");
161 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/patch-5.MPQ', $Export->TempDir.'patch-5.MPQ');
162 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/'.$nsifile, $Export->TempDir.$nsifile);
163 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/WowLua.exe', $Export->TempDir.'WowLua.exe');
164 $this->rcopy('files/'.$Export->ClientVersion['Version'].'/CzWoW/', $Export->TempDir.'CzWoW/');
165 $this->rcopy('files/WoW.ico', $Export->TempDir.'WoW.ico');
166 $this->rcopy('files/Fonts/', $Export->TempDir.'Fonts/');
167
168 $this->SetProgress(10);
169 echo('Export lua...'."\n");
170 $Export->ExportToLua();
171 $this->SetProgress(15);
172 echo('Export CzWoW...'."\n");
173 $Export->MakeAddon();
174 $this->SetProgress(30);
175 echo('Export dbc...'."\n");
176 $Export->ExportToDBC();
177
178 echo('Create readme...'."\n");
179 $this->SetProgress(60);
180 $File = new FileStream();
181 $File->CreateFile($Export->TempDir.'ReadMe.htm');
182 $File->WriteLine($Export->GetReadme());
183 unset($File);
184
185 echo('Packing files...'."\n");
186 $this->SetProgress(70);
187 $workdir = str_replace('/', DIRECTORY_SEPARATOR, $Export->TempDir);
188 $this->MPQPack($workdir.'lua');
189 $this->SetProgress(80);
190 $this->MPQPack($workdir.'dbc');
191
192 $this->SetProgress(90);
193 echo('Creating instalator...'."\n");
194 if (DIRECTORY_SEPARATOR == '/') // linux
195 echo exec('makensis '.$workdir.$nsifile);
196
197 if (DIRECTORY_SEPARATOR == '\\') // windows
198 echo exec('"'.$workdir.$nsifile.'" '); //"c:\Program Files (x86)\NSIS\makensisw.exe" /Xscriptcmd
199 }
200
201 function Run()
202 {
203 global $Config;
204
205 while (1)
206 {
207 $DbResult = $this->Database->query('SELECT `ExportTask`.`Id`, `ExportTask`.`Export`, '.
208 '`Export`.`Id` AS `ExportId`, `Export`.`OutputType` AS `ExportOutput` FROM `ExportTask` '.
209 'LEFT JOIN `Export` ON `Export`.`Id` = `ExportTask`.`Export` WHERE '.
210 '(`ExportTask`.`TimeFinish` IS NULL) ORDER BY `TimeQueued`');
211 while ($Task = $DbResult->fetch_assoc())
212 {
213 $this->Id = $Task['Id'];
214 if ($Task['ExportId'] != '')
215 {
216 try
217 {
218 $this->SetProgress(0);
219 $this->Database->update('ExportTask', '`Id`='.$this->Id, array('TimeStart' => 'NOW()'));
220
221 if ($Task['ExportOutput'] == 9)
222 {
223 $this->ExportDBC($Task);
224 } else
225 if ($Task['ExportOutput'] == 10)
226 {
227 $this->ExportEXE($Task);
228 } else echo('Unknown export output type '.$Task['ExportOutput']."\n");
229
230 $this->SetProgress(100);
231 $this->Database->update('ExportTask', '`Id`='.$this->Id, array('TimeFinish' => 'NOW()'));
232 echo ("\n"."Hotovo"."\n");
233 } catch (Exception $E)
234 {
235 echo 'Caught exception: ', $E->getMessage(), "\n";
236 }
237 } else
238 {
239 $this->Database->query('DELETE FROM `ExportTask` WHERE `Id`='.$this->Id);
240 echo('Export '.$Task['Export'].' nenalezen. Jeho úloha smazána.'."\n");
241 }
242 }
243 sleep($Config['ExportTaskProcessPeriod']);
244 }
245 }
246}
247
248//LoadCommandLineParameters();
249$System = new Core();
250$System->DoNotShowPage = true;
251$System->Run();
252
253$Task = new TaskExport($System);
254$Task->Run();
Note: See TracBrowser for help on using the repository browser.