Testing
This commit is contained in:
+30
-35
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// todo: make it work correctly on mac & linux (case sensitivity on deletion)
|
||||||
class optimizer
|
class optimizer
|
||||||
{
|
{
|
||||||
public static function is_default_hitsound(string $path) : bool
|
public static function is_default_hitsound(string $path) : bool
|
||||||
@@ -106,47 +107,40 @@ class optimizer
|
|||||||
{
|
{
|
||||||
$queue = array();
|
$queue = array();
|
||||||
|
|
||||||
$times_c = array();
|
|
||||||
$time_1 = microtime(true);
|
|
||||||
foreach ($library->get_folders() as $folder)
|
foreach ($library->get_folders() as $folder)
|
||||||
{
|
{
|
||||||
$time_start = microtime(true);
|
|
||||||
self::build_removand_sublist($queue, $folder, $single_level);
|
self::build_removand_sublist($queue, $folder, $single_level);
|
||||||
$time_end = microtime(true);
|
|
||||||
$times_c[$folder] = $time_end - $time_start;
|
|
||||||
}
|
}
|
||||||
$time_2 = microtime(true);
|
|
||||||
|
|
||||||
arsort($times_c);
|
|
||||||
$times_c = array_splice($times_c, 0, 100);
|
|
||||||
|
|
||||||
$time_3 = $time_2-$time_1;
|
|
||||||
echo "{$time_3}<br />";
|
|
||||||
echo "<pre>";
|
|
||||||
print_r($times_c);
|
|
||||||
echo "</pre>";
|
|
||||||
|
|
||||||
return $queue;
|
return $queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function build_excluded_list(osu_library $library) : array
|
public static function build_excluded_list(osu_library $library, bool $nuke = false) : array
|
||||||
{
|
{
|
||||||
$background_files = $library->get_backgrounds();
|
$background_files = $library->get_backgrounds();
|
||||||
$video_files = $library->get_videos();
|
$video_files = $library->get_videos();
|
||||||
$audio_files = $library->get_audiofiles();
|
$audio_files = $library->get_audiofiles();
|
||||||
|
|
||||||
$storyboard_files = $library->get_storyboards();
|
|
||||||
$hitsound_files = $library->get_hitsounds();
|
|
||||||
|
|
||||||
// $osu_files = $library->get_osu_files();
|
|
||||||
// $osb_files = $library->get_osb_files();
|
|
||||||
$physical_excluded = $library->get_parsed_files();
|
|
||||||
|
|
||||||
$essential_excluded = array_merge($background_files, $video_files, $audio_files);
|
$essential_excluded = array_merge($background_files, $video_files, $audio_files);
|
||||||
// $physical_excluded = array_merge($osb_files, $osu_files);
|
|
||||||
$other_excluded = array_merge($storyboard_files, $hitsound_files);
|
|
||||||
|
|
||||||
$excluded = array_merge($essential_excluded, $physical_excluded, $other_excluded);
|
if (!$nuke)
|
||||||
|
{
|
||||||
|
$storyboard_files = $library->get_storyboards();
|
||||||
|
$hitsound_files = $library->get_hitsounds();
|
||||||
|
|
||||||
|
// $osu_files = $library->get_osu_files();
|
||||||
|
// $osb_files = $library->get_osb_files();
|
||||||
|
$physical_excluded = $library->get_parsed_files();
|
||||||
|
|
||||||
|
// $physical_excluded = array_merge($osb_files, $osu_files);
|
||||||
|
$other_excluded = array_merge($storyboard_files, $hitsound_files);
|
||||||
|
|
||||||
|
$excluded = array_merge($essential_excluded, $physical_excluded, $other_excluded);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$excluded = $essential_excluded;
|
||||||
|
}
|
||||||
|
|
||||||
return $excluded;
|
return $excluded;
|
||||||
}
|
}
|
||||||
@@ -192,16 +186,14 @@ class optimizer
|
|||||||
{
|
{
|
||||||
if (self::is_skinnable_image($file) || self::is_skinnable_other($file))
|
if (self::is_skinnable_image($file) || self::is_skinnable_other($file))
|
||||||
{
|
{
|
||||||
// if (file_exists($file)) unlink($file);
|
if (file_exists($file)) unlink($file);
|
||||||
echo $file . "<br />";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit(0); // testing purposes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function remove_hitsounds(osu_library $library) : void
|
public static function remove_hitsounds(osu_library $library) : void
|
||||||
{
|
{
|
||||||
$removand = self::build_single_level_removand_list($library, true);
|
$removand = self::build_removand_list($library, true);
|
||||||
$exclusions = self::build_excluded_list($library);
|
$exclusions = self::build_excluded_list($library);
|
||||||
|
|
||||||
$junk_files = self::array_diff_ver_peppy($removand, $exclusions);
|
$junk_files = self::array_diff_ver_peppy($removand, $exclusions);
|
||||||
@@ -215,19 +207,22 @@ class optimizer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function remove_other(osu_library $library) : void
|
public static function full_nuke(osu_library $library) : void
|
||||||
|
{
|
||||||
|
self::remove_other($library, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function remove_other(osu_library $library, bool $nuke = false) : void
|
||||||
{
|
{
|
||||||
$removand = self::build_removand_list($library);
|
$removand = self::build_removand_list($library);
|
||||||
$exclusions = self::build_excluded_list($library);
|
$exclusions = self::build_excluded_list($library, $nuke);
|
||||||
|
|
||||||
$junk_files = self::array_diff_ver_peppy($removand, $exclusions);
|
$junk_files = self::array_diff_ver_peppy($removand, $exclusions);
|
||||||
|
|
||||||
foreach ($junk_files as $file)
|
foreach ($junk_files as $file)
|
||||||
{
|
{
|
||||||
if (self::is_skinnable($file)) continue; // ignore default hitsounds
|
if (self::is_skinnable($file)) continue; // ignore default hitsounds
|
||||||
// if (file_exists($file)) unlink($file);
|
if (file_exists($file)) unlink($file);
|
||||||
echo $file . "<br />";
|
|
||||||
}
|
}
|
||||||
exit(0); // testing purposes
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
class osu_cacher
|
class osu_cacher
|
||||||
{
|
{
|
||||||
|
public static $hash_function = "md5";
|
||||||
|
// public static $hash_function = "crc32";
|
||||||
|
|
||||||
private $root;
|
private $root;
|
||||||
private $cache_root;
|
private $cache_root;
|
||||||
|
|
||||||
@@ -51,7 +54,7 @@ class osu_cacher
|
|||||||
$cache_dir = dirname($cache_path);
|
$cache_dir = dirname($cache_path);
|
||||||
if (!file_exists($cache_dir)) mkdir($cache_dir, 0777, true);
|
if (!file_exists($cache_dir)) mkdir($cache_dir, 0777, true);
|
||||||
|
|
||||||
if (!isset($content["hash"])) $content["hash"] = hash_file("md5", $path);
|
if (!isset($content["hash"])) $content["hash"] = hash_file(self::$hash_function, $path);
|
||||||
|
|
||||||
$encoded = json_encode($content);
|
$encoded = json_encode($content);
|
||||||
file_put_contents($cache_path, $encoded);
|
file_put_contents($cache_path, $encoded);
|
||||||
|
|||||||
@@ -118,13 +118,16 @@ class osu_library
|
|||||||
$osb_glob = glob(utils::globsafe($folder) . "/*.osb");
|
$osb_glob = glob(utils::globsafe($folder) . "/*.osb");
|
||||||
$glob = array_merge($osu_glob, $osb_glob);
|
$glob = array_merge($osu_glob, $osb_glob);
|
||||||
|
|
||||||
|
|
||||||
$cacher = new osu_cacher($this->get_library_folder(), self::$cache_root);
|
$cacher = new osu_cacher($this->get_library_folder(), self::$cache_root);
|
||||||
$parser = new osu_parser($cacher);
|
$parser = new osu_parser($cacher);
|
||||||
|
|
||||||
foreach ($glob as $file)
|
foreach ($glob as $file)
|
||||||
{
|
{
|
||||||
$difficulty_key = basename($file);
|
$difficulty_key = basename($file);
|
||||||
|
|
||||||
$difficulty = $parser->parse_osu_file_format($file);
|
$difficulty = $parser->parse_osu_file_format($file);
|
||||||
|
|
||||||
$difficulty["key"] = $difficulty_key;
|
$difficulty["key"] = $difficulty_key;
|
||||||
$difficulty["path"] = $file;
|
$difficulty["path"] = $file;
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ class osu_parser
|
|||||||
|
|
||||||
if (!$skip_cache)
|
if (!$skip_cache)
|
||||||
{
|
{
|
||||||
$cached = $this->cacher->get_cache($path, hash_file("md5", $path));
|
$hash = hash_file(osu_cacher::$hash_function, $path);
|
||||||
|
|
||||||
|
$cached = $this->cacher->get_cache($path, $hash);
|
||||||
if ($cached !== false) return $cached;
|
if ($cached !== false) return $cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +217,7 @@ class osu_parser
|
|||||||
$time_end = microtime(true);
|
$time_end = microtime(true);
|
||||||
$parsing_time = $time_end - $time_start;
|
$parsing_time = $time_end - $time_start;
|
||||||
$parsed["parsing_time"] = $parsing_time;
|
$parsed["parsing_time"] = $parsing_time;
|
||||||
|
if (!empty($hash)) $parsed["hash"] = $hash;
|
||||||
|
|
||||||
if (!$skip_cache)
|
if (!$skip_cache)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user