From 78032e15839071ee0c75f3233d771dd28158ebc6 Mon Sep 17 00:00:00 2001 From: Thayol Date: Sat, 26 Dec 2020 16:55:08 +0100 Subject: [PATCH] File existence safety --- libraries/optimizer.php | 4 ++-- libraries/osu_library.php | 35 ++++++++++++++++++++++++----------- main.php | 1 + 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/libraries/optimizer.php b/libraries/optimizer.php index 3205b74..deeb7bf 100644 --- a/libraries/optimizer.php +++ b/libraries/optimizer.php @@ -38,7 +38,7 @@ class optimizer unlink($file); } - foreach ($library->get_storyboard_files() as $file) + foreach ($library->get_osb_files() as $file) { unlink($file); } @@ -118,7 +118,7 @@ class optimizer $vid = $library->get_videos(); $sb = $library->get_storyboards(); $a = $library->get_audiofiles(); - $sbf = $library->get_storyboard_files(); + $sbf = $library->get_osb_files(); $osf = $library->get_osu_files(); $excluded = array_merge($bg, $vid, $sb, $a, $sbf, $osf); diff --git a/libraries/osu_library.php b/libraries/osu_library.php index 213a8ef..a3856c9 100644 --- a/libraries/osu_library.php +++ b/libraries/osu_library.php @@ -250,12 +250,15 @@ class osu_library $folders = array(); foreach ($db as $beatmapset) { - $backgrounds[] = $beatmapset["path"]; + if (file_exists($beatmapset["path"])) + { + $folders[] = $beatmapset["path"]; + } } - $backgrounds = array_unique($backgrounds); + $folders = array_unique($folders); - return $backgrounds; + return $folders; } public function get_backgrounds() : array @@ -269,7 +272,8 @@ class osu_library { if (!empty($beatmap["background"])) { - $backgrounds[] = $beatmapset["path"] . "/" . $beatmap["background"]; + $path = $beatmapset["path"] . "/" . $beatmap["background"]; + if (file_exists($path)) $backgrounds[] = $path; } } } @@ -290,7 +294,8 @@ class osu_library { if (!empty($beatmap["video"])) { - $videos[] = $beatmapset["path"] . "/" . $beatmap["video"]; + $path = $beatmapset["path"] . "/" . $beatmap["video"]; + if (file_exists($path)) $videos[] = $path; } } } @@ -311,7 +316,10 @@ class osu_library { if (!empty($beatmap["format"]) && $beatmap["format"] != "storyboard") { - $osu_files[] = $beatmap["path"]; + if (file_exists($beatmap["path"])) + { + $osu_files[] = $beatmap["path"]; + } } } } @@ -321,7 +329,7 @@ class osu_library return $osu_files; } - public function get_storyboard_files() : array + public function get_osb_files() : array { $db = $this->get_library(); @@ -332,7 +340,10 @@ class osu_library { if (!empty($beatmap["format"]) && $beatmap["format"] == "storyboard") { - $storyboard_files[] = $beatmap["path"]; + if (file_exists($beatmap["path"])) + { + $storyboard_files[] = $beatmap["path"]; + } } } } @@ -353,7 +364,8 @@ class osu_library { foreach ($beatmap["storyboard"] ?? array() as $storyelement) { - $storyboards[] = $beatmapset["path"] . "/" . $storyelement; + $path = $beatmapset["path"] . "/" . $storyelement; + if (file_exists($path)) $storyboards[] = $path; } } } @@ -372,9 +384,10 @@ class osu_library { foreach($beatmapset["difficulties"] as $beatmap) { - if (!empty($beatmap["audio"])) + if (!empty($beatmap["General"]["AudioFilename"])) { - $audiofiles[] = $beatmapset["path"] . "/" . $beatmap["audio"]; + $path = $beatmapset["path"] . "/" . $beatmap["General"]["AudioFilename"]; + if (file_exists($path)) $audiofiles[] = $path; } } } diff --git a/main.php b/main.php index a824e68..5fb8ec9 100644 --- a/main.php +++ b/main.php @@ -9,6 +9,7 @@ require_once "libraries/osu_library.php"; require_once "libraries/optimizer.php"; require_once "libraries/utils.php"; +require_once "libraries/template_engine.php"; require_once "temp/dump.php"; $lib = new osu_library();