Repacker implemented

This commit is contained in:
2020-12-28 21:34:07 +01:00
parent c1860a090a
commit bbe7b5849a
9 changed files with 168 additions and 23 deletions
+28
View File
@@ -1,4 +1,5 @@
<?php
require_once "libraries/utils.php";
// todo: make it work correctly on mac & linux (case sensitivity on deletion)
class optimizer
{
@@ -254,4 +255,31 @@ class optimizer
if (file_exists($file)) unlink($file);
}
}
public static function repack(osu_library $library, string $key) : string
{
$path = $library->get_library()[$key]["path"] ?? "";
if (!file_exists($path)) return "";
$name = "session/osz/" . basename($path) . ".osz";
if (file_exists($name)) return $name;
$zip = new ZipArchive;
try
{
$zip->open($name, ZipArchive::CREATE);
utils::recursive_zip_map($zip, $path, $path);
}
catch (Exception $e)
{
return "";
}
finally
{
$zip->close();
}
return $name;
}
}