get_backgrounds() as $file) self::blacken_image($file); } public static function remove_videos(osu_library $library) { utils::array_delete_if_exists($library->get_videos()); } public static function remove_storyboards(osu_library $library) : void { // exclude vital files if they are used in the storyboard $vital = array_merge($library->get_backgrounds(), $library->get_audiofiles()); $sb_safe = array_diff($library->get_storyboards(), $vital); utils::array_delete_if_exists($sb_safe); utils::array_delete_if_exists($library->get_osb_files()); } private static function build_removand_sublist(array &$queue, string $folder, bool $single_level = false) { foreach (glob(utils::globsafe($folder) . "/*") as $file) { if (is_dir($file)) { if (!$single_level) self::build_removand_sublist($queue, $file, false); // recursion } else { $queue[] = $file; } } } public static function build_removand_list(osu_library $library, bool $single_level = false) : array { $queue = array(); foreach ($library->get_folders() as $folder) { self::build_removand_sublist($queue, $folder, $single_level); } return $queue; } public static function copy_unless_excluded(string $needle, array $value, array $excluded_list) { if (in_array($needle, $excluded_list)) { return array(); } else { return $value; } } public static function build_essential_list(osu_library $library, array $except = array()) : array { $bg = self::copy_unless_excluded("backgrounds", $library->get_backgrounds(), $except); $vid = self::copy_unless_excluded("videos", $library->get_videos(), $except); $aud = self::copy_unless_excluded("audio", $library->get_audiofiles(), $except); return array_merge($bg, $vid, $aud); } public static function build_physical_list(osu_library $library, array $except = array()) : array { if (in_array("osu", $except) || in_array("osb", $except)) { $osu_files = self::copy_unless_excluded("osu", $library->get_osu_files(), $except); $osb_files = self::copy_unless_excluded("osb", $library->get_osb_files(), $except); return array_merge($osu_files, $osb_files); } return self::copy_unless_excluded("parsed", $library->get_parsed_files(), $except); } public static function build_other_list(osu_library $library, array $except = array()) : array { $storyboards = self::copy_unless_excluded("storyboard", $library->get_storyboards(), $except); $hitsounds = self::copy_unless_excluded("hitsounds", $library->get_hitsounds(), $except); return array_merge($storyboards, $hitsounds); } public static function build_excluded_list(osu_library $library, array $except = array()) : array { $essential_excluded = self::build_essential_list($library, $except); $physical_excluded = self::build_physical_list($library, $except); $other_excluded = self::build_other_list($library, $except); return array_merge($essential_excluded, $physical_excluded, $other_excluded); } public static function cut_extension(string $path) : string { $directory = pathinfo($path, PATHINFO_DIRNAME) ?? ""; if (!empty($directory)) $directory .= "/"; // append slash if set return $directory . (pathinfo($path, PATHINFO_FILENAME) ?? ""); } // because peppy thinks file extensions are wildcards: // you can have image.mp3 in storyboards in jfif // and you can have ogg vorbis hitsounds in mysound.wav.png.whatever public static function array_diff_ver_peppy(array &$files, array &$exclusions) : array { // osu! is case insensitive $files_lowercase = array(); foreach ($files as $key => $value) { $files_lowercase[$key] = self::cut_extension(mb_strtolower($value)); } $exclusions_lowercase = array(); foreach ($exclusions as $key => $value) { $exclusions_lowercase[$key] = self::cut_extension(mb_strtolower($value)); } // return values from the original, but only the ones that did not get removed return array_intersect_key($files, array_diff($files_lowercase, $exclusions_lowercase)); } public static function get_junk_files(osu_library $library, $excluded = array()) : array { $removand = self::build_removand_list($library, true); $exclusions = self::build_excluded_list($library); return self::array_diff_ver_peppy($removand, $exclusions); } public static function remove_skins(osu_library $library) : void { $junk_files = self::get_junk_files($library); foreach ($junk_files as $key => $file) { if (self::is_skinnable_image($file) || self::is_skinnable_other($file)) { unset($junk_files[$key]); } } utils::array_delete_if_exists($junk_files); } public static function remove_hitsounds(osu_library $library) : void { $junk_files = self::get_junk_files($library, $exclusions); foreach ($junk_files as $key => $file) { if (self::is_skinnable_sound($file)) { unset($junk_files[$key]); } } utils::array_delete_if_exists($junk_files); $hitsounds_safe = $library->get_hitsounds(); $hitsounds_safe = array_diff($hitsounds_safe, $library->get_audiofiles()); utils::array_delete_if_exists($hitsounds_safe); } 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 { if ($nuke) { $excluded_arg = [ "videos", "osb", "storyboard", "hitsounds" ]; } else { $excluded_arg = array(); } $junk_files = self::get_junk_files($library, $excluded_arg); foreach ($junk_files as $key => $file) { if (!$nuke && self::is_skinnable($file)) continue; unset($junk_files[$key]); } utils::array_delete_if_exists($junk_files); } public static function repack_all(osu_library $library) : void { foreach ($library->get_library() as $key => $mapset) { self::repack($library, $mapset["key"]); } } 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; } public static function cleanup_dir(string $dir, bool $recursion = false) : void { $dir = utils::to_unix_slashes_without_trail($dir); $glob = glob(utils::globsafe($dir) . "/*"); foreach ($glob as $file) { if (is_dir($file) && $recursion) { self::cleanup_dir($file, true); @rmdir($file); } else { unlink($file); } } } }