Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- chdir(dirname(__FILE__));
- define("OUTDIR", "~~~");
- define("INDIR", "~~~");
- define("DELETEDAYS", "30");
- define("FORMAT", "gif");
- mysql_pconnect("localhost", "~~~", "~~~");
- mysql_select_db("sourcemod");
- $res = mysql_query("SELECT * FROM sprays WHERE datediff(NOW(), firstdate) < ".DELETEDAYS." or (date > 0 and datediff(NOW(), date) < ".DELETEDAYS.")");
- chdir(OUTDIR);
- $done = array();
- $cmd = "";
- echo "There were ".mysql_num_rows($res)." files found to be processed.";
- while($row = mysql_fetch_assoc($res)){
- $out = '';
- echo "Processing: " . $row['filename']." \n";
- if(!file_exists(INDIR."/{$row['filename']}.dat"))
- {
- echo "\t File does not exist in ". INDIR . "... Skipping. \n";
- continue;
- }
- $done[$row['filename']] = true;
- if(file_exists(OUTDIR."/{$row['filename']}.".FORMAT))
- {
- echo "\t File exists in ". OUTDIR . "... Skipping. \n";
- continue;
- }
- if(!copy(INDIR."/{$row['filename']}.dat", OUTDIR."/{$row['filename']}.vtf"))
- {
- echo "\t File failed to copy... Skipping. \n";
- continue;
- }
- exec("/usr/local/bin/vtfconv ".escapeshellarg($row['filename']).".vtf", $out);
- $output = implode("\n", $out);
- if(strpos($output, "Could not open file...exiting") !== false)
- {
- echo "\t VTFConv could not open the file... Skipping. \n";
- continue;
- }
- $derp = 0;
- $src = array();
- while(file_exists(OUTDIR."/{$row['filename']}.vtf.{$derp}.png")){
- $src[]="{$row['filename']}.vtf.{$derp}.png";
- $derp ++;
- }
- if($derp < 1){
- echo "Failed to convert ".OUTDIR."/{$row['filename']}.vtf\n";
- continue;
- }
- exec("convert -delay 25 -loop 0 -set dispose background ".implode(" ", $src)." {$row['filename']}.gif");
- echo "\t Saved {$derp} frame(s) to ".OUTDIR."/{$row['filename']}.".FORMAT."\n";
- }
- $files = array_merge(array(), (array)glob(OUTDIR."/*.png", GLOB_MARK));
- foreach($files as $file){
- unlink($file);
- }
- $files = glob(OUTDIR."/*.".FORMAT, GLOB_MARK);
- foreach($files as $file){
- $fid = str_replace(".".FORMAT, "", substr($file, strrpos($file, "/")+1));
- if(!array_key_exists($fid, $done)){
- unlink($file);
- @unlink(INDIR."/{$fid}.dat");
- @unlink(OUTDIR."/{$fid}.vtf");
- @unlink(INDIR."/{$fid}.dat.ztmp");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement