mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
Implement unpacking logic
This commit is contained in:
parent
97f2b2972c
commit
c2b8c152bc
2 changed files with 51 additions and 0 deletions
|
@ -623,3 +623,26 @@ function email_users($usernames, $subject, $body)
|
|||
}
|
||||
return $emailsSent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively deletes a directory and it's contents.
|
||||
* Adapted by Starbeamrainbowlabs
|
||||
* @param string $path The path to the directory to delete.
|
||||
* @param bool $delete_self Whether to delete the top-level directory. Set this to false to delete only a directory's contents
|
||||
* @source https://stackoverflow.com/questions/4490637/recursive-delete
|
||||
*/
|
||||
function delete_recursive($path, $delete_self = true) {
|
||||
$it = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($path),
|
||||
RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
foreach ($it as $file) {
|
||||
if (in_array($file->getBasename(), [".", ".."]))
|
||||
continue;
|
||||
if($file->isDir())
|
||||
rmdir($file->getPathname());
|
||||
else
|
||||
unlink($file->getPathname());
|
||||
}
|
||||
if($delete_self) rmdir($path);
|
||||
}
|
||||
|
|
28
core/07-unpack.php
Normal file
28
core/07-unpack.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
// If the extra data directory:
|
||||
// - doesn't exist already
|
||||
// - has an mtime before that of this file
|
||||
// ...extract it again
|
||||
if(!file_exists($paths->extra_data_directory) ||
|
||||
filemtime(__FILE__) > filemtime($paths->extra_data_directory)) {
|
||||
if(file_exists($paths->extra_data_directory))
|
||||
delete_recursive($paths->extra_data_directory, false);
|
||||
else
|
||||
mkdir($paths->extra_data_directory, 0700);
|
||||
touch($paths->extra_data_directory);
|
||||
|
||||
$temp_file = tmpfile();
|
||||
$source = fopen(__FILE__, "r");
|
||||
|
||||
fseek($source, __COMPILER_HALT_OFFSET__);
|
||||
stream_copy_to_stream($source, $temp_file);
|
||||
|
||||
$temp_filename = stream_get_meta_data($temp_file)["uri"];
|
||||
|
||||
$extractor = new ZipArchive();
|
||||
$extractor->open($temp_filename);
|
||||
$extractor->extractTo($paths->extra_data_directory);
|
||||
$extractor->close();
|
||||
fclose($temp_file);
|
||||
}
|
Loading…
Reference in a new issue