Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- date_default_timezone_set("Europe/Berlin");
- /**
- * Krom 2014
- *
- * License: Do whatever the fuck you want to do with it. Credits would be nice.
- *
- * TODO:
- * - log installed files, so re-installation can be prevented
- * - EXE installer: poll for supported flags and create custom options
- *
- * v1.1 - 19.10.2015
- * + added support for installing "people" and "data" folders.
- * ~ forced target folder names to be uppercase for "Runtime" and "People"
- * ~ forced target folder name to be lowercase for "data"
- */
- class DAZ3D_Installer {
- /* private, do not change */
- private $_found_installs;
- private $_internal_ignore;
- private $_logfile;
- /* you can/have to change these, after creating an instance */
- public $source_dir; // where to search for installables?
- public $install_dir; // where to install to?
- public $unzip_dir; // if I need to unzip, where can I do so? (only 1 zip at a time)
- public $log_dir; // where can I write my logfile to?
- public $ignore_dirs; // are there dirs I should ignore (see constructor)
- public $installed_file; // not working yet. log installed stuff here
- public $create_target_subdirs; // should I install everything to it's own directory? (Note: sometimes name guessing does not work that good, depends on folder structure)
- public $skip_existing_dirs; // if I should install to own dirs, should I skip those that already exist?
- public $bInstallOne; // for testing: should I install 1 package per category only?
- // --------------------------------------------------------------------- //
- public function __construct() {
- $this->_internal_ignore = array();
- $this->_found_installs = array();
- $this->_logfile = strftime("%Y%m%d%H%M%S_install.log");
- $this->source_dir = '';
- $this->install_dir = '';
- $this->unzip_dir = '';
- $this->log_dir = '';
- $this->installed_file = '';
- $this->ignore_dirs = array();
- $this->create_target_subdirs = true;
- $this->skip_existing_dirs = false;
- // install only one package per category (for testing)
- $this->bInstallOne = true;
- // these are pretty much static.
- // we don't want documents, and readmes
- // we do not process copying to program files dir.
- // we need to ignore MAC installers
- $this->ignore_dirs = array(
- 'documents',
- 'program files',
- 'readme',
- 'mac'
- );
- }
- // --------------------------------------------------------------------- //
- public function install() {
- // check settings
- if (!is_dir($this->source_dir))
- $this->_log2file("Source dir is not a dir?! >>".$this->source_dir."<<\n", true, true);
- if (!is_dir($this->install_dir))
- $this->_log2file("Install dir is not a dir?! >>".$this->install_dir."<<\n", true, true);
- if (!is_dir($this->unzip_dir))
- $this->_log2file("Unzip dir is not a dir?! >>".$this->unzip_dir."<<\n", true, true);
- if (!is_dir($this->log_dir))
- $this->_log2file("Log dir is not a dir?! >>".$this->log_dir."<<\n", true, true);
- $this->_log2file("Starting installation");
- $this->_log2file(" 1. Scanning for installables");
- $this->_scanDir($this->source_dir, $this->_found_installs);
- $stats = $this->getStats($this->_found_installs);
- $this->_log2file(" EXE: ".$stats['exe']);
- $this->_log2file(" ZIP: ".$stats['zip']);
- $this->_log2file(" Copy Content: ".$stats['content']);
- $this->_log2file(" Copy Runtime: ".$stats['runtime']);
- $this->_log2file(" Copy Other: ".$stats['other']);
- $this->_log2file(" Total: ".$stats['total']);
- $this->_log2file(" --------------------------");
- if (empty($this->_found_installs)) {
- $this->_log2file("Nothing to install found. Aborting.");
- return true;
- }
- echo "--------------------------\n";
- echo "Found these:\n";
- print_r($stats);
- echo "--------------------------\n";
- do {
- if (PHP_OS == 'WINNT') {
- echo "Do you wish to continue? (y/n): ";
- $k = stream_get_line(STDIN, 1024, PHP_EOL);
- } else $k = readline("Do you wish to continue? (y/n): ");
- } while ($k != 'y' && $k != 'j' && $k != 'n');
- if ($k == 'n') {
- $this->_log2file("User abort.");
- return true;
- }
- $this->_log2file(" 2. Installing...");
- // EXE
- if ($stats['exe'] > 0) {
- do {
- if (PHP_OS == 'WINNT') {
- echo "Install ".$stats['exe']." exe files? (y/n): ";
- $k = stream_get_line(STDIN, 1024, PHP_EOL);
- } else $k = readline("Install ".$stats['exe']." exe files? (y/n): ");
- } while ($k != 'y' && $k != 'j' && $k != 'n');
- if ($k == 'y' || $k == 'j')
- $this->_install_EXE($this->_found_installs);
- else $this->_log2file(" Skipping EXE files\n ------------------------");
- }
- // ZIP
- if ($stats['zip'] > 0) {
- do {
- if (PHP_OS == 'WINNT') {
- echo "Install ".$stats['zip']." zip files? (y/n): ";
- $k = stream_get_line(STDIN, 1024, PHP_EOL);
- } else $k = readline("Install ".$stats['zip']." zip files? (y/n): ");
- } while ($k != 'y' && $k != 'j' && $k != 'n');
- if ($k == 'y' || $k == 'j')
- $this->_install_ZIP($this->_found_installs);
- else $this->_log2file(" Skipping ZIP files\n ------------------------");
- }
- // CONTENT
- // considering installing this and runtime first, as there might be dependencies
- // on the exe files - had that with genesis 2, where the genesis2 wasn't an installable
- // but a dependency for installables - which in turn did not install.
- if ($stats['content'] > 0) {
- do {
- if (PHP_OS == 'WINNT') {
- echo "Copy ".$stats['content']." Content folders? (y/n): ";
- $k = stream_get_line(STDIN, 1024, PHP_EOL);
- } else $k = readline("Copy ".$stats['content']." Content folders? (y/n): ");
- } while ($k != 'y' && $k != 'j' && $k != 'n');
- if ($k == 'y' || $k == 'j')
- $this->_install_CONTENT($this->_found_installs);
- else $this->_log2file(" Skipping CONTENT folders\n ------------------------");
- }
- // RUNTIME
- if ($stats['runtime'] > 0) {
- do {
- if (PHP_OS == 'WINNT') {
- echo "Copy ".$stats['runtime']." Runtime folders? (y/n): ";
- $k = stream_get_line(STDIN, 1024, PHP_EOL);
- } else $k = readline("Copy ".$stats['runtime']." Runtime folders? (y/n): ");
- } while ($k != 'y' && $k != 'j' && $k != 'n');
- if ($k == 'y' || $k == 'j')
- $this->_install_RUNTIME($this->_found_installs);
- else $this->_log2file(" Skipping RUNTIME folders\n ------------------------");
- }
- // OTHER
- if ($stats['other'] > 0) {
- do {
- if (PHP_OS == 'WINNT') {
- echo "Copy ".$stats['runtime']." other folders? (y/n): ";
- $k = stream_get_line(STDIN, 1024, PHP_EOL);
- } else $k = readline("Copy ".$stats['runtime']." other folders? (y/n): ");
- } while ($k != 'y' && $k != 'j' && $k != 'n');
- if ($k == 'y' || $k == 'j')
- $this->_install_OTHER($this->_found_installs);
- else $this->_log2file(" Skipping other folders\n ------------------------");
- }
- echo "\n *** Installation completed ***\n";
- echo "Have a nice day! :)\n";
- $this->_log2file("Installation completed!");
- return true;
- }
- // --------------------------------------------------------------------- //
- private function _install_EXE($data) {
- $stats = $this->getStats($data);
- $this->_log2file(" Installing ".$stats['exe']." EXE files");
- // ------------------------------------------------------------------
- $cnt = 1;
- foreach($data as $fk => $fv) {
- if ($fv['type'] != 'exe') continue;
- $name = str_ireplace(".exe", "", basename($fv['path']));
- echo " Installing [".($cnt)."/".$stats['exe']."]: ".$name."\n";
- $this->_log2file(" [".($cnt)."/".$stats['exe']."] installing: ".$name);
- $cnt++;
- // if ($cnt < 77) continue;
- if ($this->create_target_subdirs) {
- if (is_dir($this->install_dir . $name.DIRECTORY_SEPARATOR)) {
- if ($this->skip_existing_dirs == true) {
- $this->_log2file(" target dir exists. Skipping.");
- continue;
- }
- } else if (!mkdir($this->install_dir . $name.DIRECTORY_SEPARATOR))
- die("Failed to create subdir: ".($this->install_dir . $name.DIRECTORY_SEPARATOR)."\n");
- chmod($this->install_dir . $name.DIRECTORY_SEPARATOR, 0777);
- $dst_dir = $this->install_dir . $name.DIRECTORY_SEPARATOR;
- } else $dst_dir = $this->install_dir . DIRECTORY_SEPARATOR;
- // 4 ways
- // could make that smarter by polling the exe for its options
- // with --help option.
- // still strange problems with "creating folder" on option3+4 "unattended" instead of "win32"
- // - as for the same problem with #1 or #2, adding a trailing slash fixed this. have to test #3+#4.
- // at least option #1 is not really unattended - it is, but only for very new installers (those "wide" ones)
- // 1.
- $options_1 = ' --mode unattended --unattendedmodeui minimal --accept_license yes --create_uninstaller no --create_startmenu_shortcuts no --installdir_content "'.$dst_dir.'"';
- $options_2 = ' --mode unattended --unattendedmodeui minimal --Uninstaller 0 --installpath "'.$dst_dir.'"';
- $options_3 = ' --mode win32 --uninstaller 0 --chosenpath "'.$dst_dir.'" --pathselection specify --prefix "'.$dst_dir.'"';
- $options_4 = ' --mode win32 --Uninstaller 0 --installpath "'.$dst_dir.'" --prefix "'.$dst_dir.'"';
- $error = false;
- echo " ".basename($fv['path'])."\n";
- $this->_log2file(" ".$fv['path']." $options_1");
- echo " trying method #1\n";
- // yeah not nice, I know. call me a lazy ass. :)
- $bar = popen('"'.$fv['path'].'"' . $options_1 . ' 2>&1', 'r');
- $read = fread($bar, 2048);
- pclose($bar);
- if (stripos($read, "error") !== false) {
- echo " trying method #2\n";
- $bar = popen('"'.$fv['path'].'"' . $options_2 . ' 2>&1', 'r');
- $read = fread($bar, 2048);
- pclose($bar);
- if (stripos($read, "error") !== false) {
- echo " trying method #3\n";
- $bar = popen('"'.$fv['path'].'"' . $options_3 . ' 2>&1', 'r');
- $read = fread($bar, 2048);
- pclose($bar);
- if (stripos($read, "error") !== false) {
- echo " trying method #4\n";
- $bar = popen('"'.$fv['path'].'"' . $options_4 . ' 2>&1', 'r');
- $read = fread($bar, 2048);
- pclose($bar);
- if (stripos($read, "error") !== false) {
- echo " Failed to install\n";
- $this->_log2file(" failed to install");
- $error = true;
- $bar = popen('"'.$fv['path'].'" 2>&1', 'r');
- $read = fread($bar, 2048);
- pclose($bar);
- } else echo " success method #4: $read\n";
- } else echo " success method #3: $read\n";
- } else echo " success method #2: $read\n";
- } else echo " success method #1: $read\n";
- if ($this->bInstallOne) break;
- }
- // ------------------------------------------------------------------
- $this->_log2file(" done installing exe files");
- $this->_log2file(" ------------------------");
- }
- // --------------------------------------------------------------------- //
- private function _install_ZIP() {
- $stats = $this->getStats($this->_found_installs);
- $this->_log2file(" Installing ".$stats['zip']." ZIP files");
- // ------------------------------------------------------------------
- $cnt = 1;
- foreach($this->_found_installs as $fk => $fv) {
- if ($fv['type'] != 'zip') continue;
- $foo = explode(DIRECTORY_SEPARATOR, $fv['path']);
- echo " Processing ZIP [".($cnt)."/".$stats['zip']."]: ".$foo[sizeof($foo)-2]." - ".basename($fv['path'])."\n";
- $this->_log2file(" [".($cnt)."/".$stats['zip']."] process ZIP: ".$foo[sizeof($foo)-2]." - ".basename($fv['path']));
- echo " unzipping\n";
- $this->_log2file(" unzipping");
- // unzip to temp dir
- $tmpdir = $this->unzip_dir . DIRECTORY_SEPARATOR . str_ireplace(".zip", "", basename($fv['path'])) . DIRECTORY_SEPARATOR;
- if (!mkdir($tmpdir)) return false;
- if (!$this->_unzip($fv['path'], $tmpdir)) {
- self::_s_delTree($tmpdir);
- return false;
- }
- // scan temp dir
- echo " scanning\n";
- $this->_log2file(" scanning");
- $found_installs = array();
- $this->_scanDir($tmpdir, $found_installs);
- $stats_zip = $this->getStats($found_installs);
- $this->_log2file(" EXE: ".$stats_zip['exe']);
- $this->_log2file(" ZIP: ".$stats_zip['zip']);
- $this->_log2file(" Copy Content: ".$stats_zip['content']);
- $this->_log2file(" Copy Runtime: ".$stats_zip['runtime']);
- $this->_log2file(" Copy Other: ".$stats_zip['other']);
- $this->_log2file(" Total: ".$stats_zip['total']);
- $this->_log2file(" --------------------------");
- if (empty($found_installs)) {
- $this->_log2file("Nothing to install found.");
- self::_s_delTree($tmpdir);
- return false;
- }
- // install using scanned method
- echo " installing\n";
- $this->_log2file(" installing");
- if ($stats_zip['exe'] > 0) {
- $this->_install_EXE($found_installs);
- }
- /*
- // allow recursion?
- if ($stats_zip['zip'] > 0) {
- $this->_install_ZIP($found_installs);
- }
- */
- if ($stats_zip['content'] > 0) {
- $this->_install_CONTENT($found_installs);
- }
- if ($stats_zip['runtime'] > 0) {
- $this->_install_RUNTIME($found_installs);
- }
- if ($stats_zip['other'] > 0) {
- $this->_install_OTHER($found_installs);
- }
- // proceed as usual
- // delete temp dir
- self::_s_delTree($tmpdir);
- $cnt++;
- if ($this->bInstallOne) break;
- }
- // ------------------------------------------------------------------
- $this->_log2file(" done installing zip files");
- $this->_log2file(" ------------------------");
- }
- // --------------------------------------------------------------------- //
- private function _install_CONTENT($data) {
- $stats = $this->getStats($data);
- $this->_log2file(" Copying ".$stats['content']." Content folders");
- // ------------------------------------------------------------------
- $cnt = 1;
- foreach($data as $fk => $fv) {
- if ($fv['type'] != 'copy_content') continue;
- $foo = explode(DIRECTORY_SEPARATOR, $fv['path']);
- echo " Copying [".($cnt)."/".$stats['content']."]: ".$foo[sizeof($foo)-2]."\n";
- $this->_log2file(" [".($cnt)."/".$stats['content']."] copying: ".$foo[sizeof($foo)-2]);
- $cnt++;
- if ($this->create_target_subdirs) {
- if (is_dir($this->install_dir . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR)) {
- if ($this->skip_existing_dirs == true) {
- $this->_log2file(" target dir exists. Skipping.");
- continue;
- }
- } else if (!mkdir($this->install_dir . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR))
- die("Failed to create subdir: ".($this->install_dir . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR)."\n");
- chmod($this->install_dir . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR, 0777);
- $dst_dir = $this->install_dir . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR;
- } else $dst_dir = $this->install_dir;
- $this->_recurse_copy($fv['path'], $dst_dir);
- if ($this->bInstallOne) break;
- }
- // ------------------------------------------------------------------
- $this->_log2file(" done copying content folders");
- $this->_log2file(" ------------------------");
- }
- // --------------------------------------------------------------------- //
- private function _install_OTHER($data) {
- $stats = $this->getStats($data);
- $this->_log2file(" Copying ".$stats['other']." other folders");
- // ------------------------------------------------------------------
- $cnt = 1;
- foreach($data as $fk => $fv) {
- if ($fv['type'] != 'copy_other') continue;
- $foo = explode(DIRECTORY_SEPARATOR, $fv['path']);
- $path_add = ((isset($fv['dir'])) ? $fv['dir'] . DIRECTORY_SEPARATOR : '');
- echo " Copying [".($cnt)."/".$stats['other']."]: ".$foo[sizeof($foo)-2]."\n";
- $this->_log2file(" [".($cnt)."/".$stats['other']."] copying: ".$foo[sizeof($foo)-2]);
- $cnt++;
- if ($this->create_target_subdirs) {
- if (is_dir($this->install_dir . $path_add . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR)) {
- if ($this->skip_existing_dirs == true) {
- $this->_log2file(" target dir exists. Skipping.");
- continue;
- }
- } else if (!mkdir($this->install_dir . $path_add . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR))
- die("Failed to create subdir: ".($this->install_dir . $path_add . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR)."\n");
- chmod($this->install_dir . $path_add . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR, 0777);
- $dst_dir = $this->install_dir . $path_add . $foo[sizeof($foo)-2].DIRECTORY_SEPARATOR;
- } else $dst_dir = $this->install_dir . $path_add;
- $this->_recurse_copy($fv['path'], $dst_dir);
- if ($this->bInstallOne) break;
- }
- // ------------------------------------------------------------------
- $this->_log2file(" done copying content folders");
- $this->_log2file(" ------------------------");
- }
- // --------------------------------------------------------------------- //
- private function _install_RUNTIME($data) {
- $stats = $this->getStats($data);
- $this->_log2file(" Copying ".$stats['runtime']." Runtime folders");
- // ------------------------------------------------------------------
- $cnt = 1;
- foreach($data as $fk => $fv) {
- if ($fv['type'] != 'copy_runtime') continue;
- $foo = explode(DIRECTORY_SEPARATOR, $fv['path']);
- echo " Copying [".($cnt)."/".$stats['runtime']."]: ".$foo[sizeof($foo)-3]."\n";
- $this->_log2file(" [".($cnt)."/".$stats['runtime']."] copying: ".$foo[sizeof($foo)-3]."\n");
- $cnt++;
- if ($this->create_target_subdirs) {
- if (is_dir($this->install_dir . $foo[sizeof($foo)-3].DIRECTORY_SEPARATOR)) {
- if ($this->skip_existing_dirs == true) {
- $this->_log2file(" target dir exists. Skipping.");
- continue;
- }
- } else if (!mkdir($this->install_dir . $foo[sizeof($foo)-3].DIRECTORY_SEPARATOR))
- die("Failed to create subdir: ".($this->install_dir . $foo[sizeof($foo)-3].DIRECTORY_SEPARATOR)."\n");
- chmod($this->install_dir . $foo[sizeof($foo)-3].DIRECTORY_SEPARATOR, 0777);
- $dst_dir = $this->install_dir . $foo[sizeof($foo)-3].DIRECTORY_SEPARATOR;
- } else $dst_dir = $this->install_dir;
- $this->_recurse_copy($fv['path'], $dst_dir . 'runtime' . DIRECTORY_SEPARATOR );
- if ($this->bInstallOne) break;
- }
- // ------------------------------------------------------------------
- $this->_log2file(" done copying runtime folders");
- $this->_log2file(" ------------------------");
- }
- // --------------------------------------------------------------------- //
- private function _scanDir($_dir, &$found) {
- if (!is_dir($_dir)) return false;
- $files = scandir($_dir);
- if (empty($files)) return false;
- foreach($files as $k => $v) {
- if ($v[0] == '.') continue;
- $ext = substr($v, strrpos($v, '.')+1);
- if ($ext == 'exe') {
- $found[] = array('type' => 'exe', 'path' => $_dir . $v);
- } else if ($ext == 'zip') {
- // moah complicated, as we don't know: a) what's in the zip, b) if it has been unpacked already
- // check for b)
- if (is_dir($_dir . substr($v, 0, -4) . DIRECTORY_SEPARATOR))
- continue;
- // check for a)
- if ($this->_scanZip($_dir . $v)) {
- $found[] = array('type' => 'zip', 'path' => $_dir . $v);
- } else {
- echo "__unusable ZIP: ". $_dir . $v . "\n";
- }
- } else if (is_dir($_dir . $v . '/')) {
- // Content has higher priority, as it can contain a runtime folder
- if (strtolower($v) == 'content') {
- $found[] = array('type' => 'copy_content', 'path' => $_dir . $v . DIRECTORY_SEPARATOR);
- } else if (strtolower($v) == 'runtime') {
- $found[] = array('type' => 'copy_runtime', 'path' => $_dir . $v . DIRECTORY_SEPARATOR);
- } else if (strtolower($v) == 'people') {
- $found[] = array('type' => 'copy_other', 'path' => $_dir . $v . DIRECTORY_SEPARATOR, 'dir' => 'People');
- } else if (strtolower($v) == 'data') {
- $found[] = array('type' => 'copy_other', 'path' => $_dir . $v . DIRECTORY_SEPARATOR, 'dir' => 'data');
- } else {
- if (!in_array(strtolower($v), $this->ignore_dirs))
- $this->_scanDir($_dir . $v . DIRECTORY_SEPARATOR, $found);
- }
- }
- }
- }
- // --------------------------------------------------------------------- //
- private function _scanZip($zipfile) {
- if (!is_file($zipfile)) return false;
- $_internal_ignore = array();
- $_found_something = false;
- $zip = new ZipArchive();
- if ($zip->open($zipfile)) {
- for ($i=0; $i<$zip->numFiles;$i++) {
- $filename = $zip->statIndex($i);
- $filename = $filename['name'];
- if (stripos(strtolower($filename), '.exe') !== false) {
- #echo "______ZIP: found exe: ".$filename."\n";
- $_found_something = true;
- continue;
- }
- if (!empty($_internal_ignore)) {
- foreach($_internal_ignore as $ik => $iv) {
- if (strpos($filename, $iv) !== false) {
- #echo "______ZIP: ignore ".$filename."\n";
- continue(2);
- }
- }
- }
- if (stripos(strtolower($filename), 'content') !== false) {
- #echo "______ZIP: found content: ".$filename." - ".dirname($filename.'/').'/'."\n";
- $add = dirname($filename);
- if ($add == '.') $add = (($filename[0] === 'C') ? 'C' : 'c') . 'ontent'.DIRECTORY_SEPARATOR;
- $_internal_ignore[] = $add;
- $_found_something = true;
- } else if (stripos(strtolower($filename), 'runtime') !== false) {
- #echo "______ZIP: found runtime: ".$filename."\n";
- $add = dirname($filename);
- if ($add == '.') $add = (($filename[0] === 'R') ? 'R' : 'R') . 'untime'.DIRECTORY_SEPARATOR; // force uppercase
- $_internal_ignore[] = $add;
- $_found_something = true;
- } else if (stripos(strtolower($filename), 'people') !== false) {
- #echo "______ZIP: found people: ".$filename."\n";
- $add = dirname($filename);
- if ($add == '.') $add = (($filename[0] === 'P') ? 'P' : 'P') . 'eople'.DIRECTORY_SEPARATOR; // force uppercase
- $_internal_ignore[] = $add;
- $_found_something = true;
- } else if (stripos(strtolower($filename), 'data') !== false) {
- #echo "______ZIP: found data: ".$filename."\n";
- $add = dirname($filename);
- if ($add == '.') $add = (($filename[0] === 'D') ? 'd' : 'd') . 'ata'.DIRECTORY_SEPARATOR; // force lowercase
- $_internal_ignore[] = $add;
- $_found_something = true;
- } else {
- #echo "__found unknown folder: ".dirname($filename)."\n";
- }
- }
- $zip->close();
- }
- return $_found_something;
- }
- // --------------------------------------------------------------------- //
- private function _unzip($zipfile, $target) {
- if (!is_file($zipfile)) return false;
- if (!is_dir($target)) return false;
- $zip = new ZipArchive();
- if ($zip->open($zipfile)) {
- $zip->extractTo($target);
- $zip->close();
- }
- return true;
- }
- // --------------------------------------------------------------------- //
- public function getStats($data) {
- $stats = array(
- 'exe' => 0,
- 'zip' => 0,
- 'runtime' => 0,
- 'content' => 0,
- 'other' => 0,
- 'total' => 0
- );
- if (empty($data) || !is_array($data)) return $stats;
- foreach($data as $k => $v) {
- switch($v['type']) {
- case 'exe' : $stats['exe']++; break;
- case 'zip' : $stats['zip']++; break;
- case 'copy_content' : $stats['content']++; break;
- case 'copy_runtime' : $stats['runtime']++; break;
- case 'copy_other' : $stats['other']++; break;
- default: break;
- }
- }
- $stats['total'] = array_sum($stats);
- return $stats;
- }
- // --------------------------------------------------------------------- //
- private function _log2file($str, $timestamp = true, $fatal = false) {
- if (($fh = fopen($this->log_dir . DIRECTORY_SEPARATOR . $this->_logfile, 'ab+'))) {
- fwrite($fh, (($timestamp) ? '['.strftime("%d.%m.%Y-%H:%M:%S").']' : '') . $str . "\n");
- if ($fatal) fwrite($fh, (($timestamp) ? '['.strftime("%d.%m.%Y-%H:%M:%S").']' : '') ."Exiting due to fatal error.\n");
- fclose($fh);
- if ($fatal) die($str."\n");
- } else die("Failed to write to log ".$this->log_dir . $this->_logfile."\n");
- if ($fatal) exit;
- }
- // --------------------------------------------------------------------- //
- private function _recurse_copy($src,$dst) {
- $dir = opendir($src);
- @mkdir($dst);
- while(false !== ( $file = readdir($dir)) ) {
- if (( $file != '.' ) && ( $file != '..' )) {
- if ( is_dir($src . DIRECTORY_SEPARATOR . $file) ) {
- $this->_recurse_copy($src . DIRECTORY_SEPARATOR . $file,$dst . DIRECTORY_SEPARATOR . $file);
- }
- else {
- copy($src . DIRECTORY_SEPARATOR . $file,$dst . DIRECTORY_SEPARATOR . $file);
- }
- }
- }
- closedir($dir);
- }
- // --------------------------------------------------------------------- //
- private static function _s_delTree($dir) {
- if ($dir == '/' || !strlen($dir)) die("FATAL. delTree called without dir or with root: ".$dir."\n");
- $files = array_diff(scandir($dir), array('.','..'));
- foreach ($files as $file) {
- (is_dir("$dir/$file")) ? self::_s_delTree("$dir/$file") : unlink("$dir/$file");
- }
- return rmdir($dir);
- }
- // --------------------------------------------------------------------- //
- }
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- $daz_installer = new DAZ3D_Installer();
- // Windows:
- /* remove "#" in front of the next three lines. add "#" in front of the three linux lines */
- #$daz_installer->source_dir = "C:\\content_4_install\\";
- #$daz_installer->install_dir = "C:\\extracted\\";
- #$daz_installer->unzip_dir = 'C:\\temp\\';
- // Linux
- $daz_installer->source_dir = "/media/MyDrive/content_4_install/";
- $daz_installer->install_dir = "/media/MyDrive/extracted/";
- $daz_installer->unzip_dir = '/media/MyDrive/_temp/';
- $daz_installer->log_dir = dirname(__FILE__). DIRECTORY_SEPARATOR;
- $daz_installer->installed_file = dirname(__FILE__). DIRECTORY_SEPARATOR . 'installed.txt';
- ///////////////////////////////////////////////////////////////////////////////
- $daz_installer->create_target_subdirs = false;
- $daz_installer->skip_existing_dirs = false;
- $daz_installer->bInstallOne = false;
- ///////////////////////////////////////////////////////////////////////////////
- $daz_installer->install();
- ///////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- ?>
Advertisement
Add Comment
Please, Sign In to add comment