File existence safety

This commit is contained in:
2020-12-26 16:55:08 +01:00
parent bf60071b83
commit 78032e1583
3 changed files with 27 additions and 13 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ class optimizer
unlink($file); unlink($file);
} }
foreach ($library->get_storyboard_files() as $file) foreach ($library->get_osb_files() as $file)
{ {
unlink($file); unlink($file);
} }
@@ -118,7 +118,7 @@ class optimizer
$vid = $library->get_videos(); $vid = $library->get_videos();
$sb = $library->get_storyboards(); $sb = $library->get_storyboards();
$a = $library->get_audiofiles(); $a = $library->get_audiofiles();
$sbf = $library->get_storyboard_files(); $sbf = $library->get_osb_files();
$osf = $library->get_osu_files(); $osf = $library->get_osu_files();
$excluded = array_merge($bg, $vid, $sb, $a, $sbf, $osf); $excluded = array_merge($bg, $vid, $sb, $a, $sbf, $osf);
+24 -11
View File
@@ -250,12 +250,15 @@ class osu_library
$folders = array(); $folders = array();
foreach ($db as $beatmapset) 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 public function get_backgrounds() : array
@@ -269,7 +272,8 @@ class osu_library
{ {
if (!empty($beatmap["background"])) 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"])) 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") 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; return $osu_files;
} }
public function get_storyboard_files() : array public function get_osb_files() : array
{ {
$db = $this->get_library(); $db = $this->get_library();
@@ -332,7 +340,10 @@ class osu_library
{ {
if (!empty($beatmap["format"]) && $beatmap["format"] == "storyboard") 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) 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) 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;
} }
} }
} }
+1
View File
@@ -9,6 +9,7 @@
require_once "libraries/osu_library.php"; require_once "libraries/osu_library.php";
require_once "libraries/optimizer.php"; require_once "libraries/optimizer.php";
require_once "libraries/utils.php"; require_once "libraries/utils.php";
require_once "libraries/template_engine.php";
require_once "temp/dump.php"; require_once "temp/dump.php";
$lib = new osu_library(); $lib = new osu_library();