Normal scan option added

This commit is contained in:
2020-12-26 15:43:54 +01:00
parent 69375796a6
commit d32105e5c5
3 changed files with 51 additions and 4 deletions
+41 -2
View File
@@ -29,13 +29,21 @@ class osu_library
$this->set_root($root); // update db entry
$this->clear_library();
$glob = glob($this->get_library_folder() . "/*", GLOB_ONLYDIR);
$library = $this->get_library();
natsort($glob); // i like wasting your processing power
foreach($glob as $folder)
{
$this->scan_add_folder($folder);
$key = basename($folder);
if (isset($library[$key]))
{
$this->scan_check_folder($folder);
}
else
{
$this->scan_add_folder($folder);
}
}
$time_end = microtime(true);
@@ -54,6 +62,37 @@ class osu_library
unset($this->db["library"]);
}
private function scan_check_folder(string $folder) : void
{
$key = basename($folder);
$osu_glob = glob(utils::globsafe($folder) . "/*.osu");
$osb_glob = glob(utils::globsafe($folder) . "/*.osb");
$glob = array_merge($osu_glob, $osb_glob);
$cacher = new osu_cacher($this->get_library_folder(), self::$cache_root);
$changed = false;
if (count($osu_glob) < 1)
{
$changed = true;
}
foreach ($glob as $file)
{
if ($cacher->get_cache($file) === false)
{
$changed = true;
}
}
if ($changed)
{
unset($this->db["library"][$key]);
$this->scan_add_folder($folder);
}
}
private function scan_add_folder(string $folder) : void
{
$key = basename($folder);
+1 -1
View File
@@ -152,7 +152,7 @@ class osu_parser
unset($file); // remove the memory leak
// storyboards are overloaded with dupes (renumber to make json export to arrays)
$parsed["storyboard"] = array_values(array_unique($parsed["storyboard"]));
if (!empty($parsed["storyboard"])) $parsed["storyboard"] = array_values(array_unique($parsed["storyboard"]));
$time_end = microtime(true);
$parsing_time = $time_end - $time_start;
+9 -1
View File
@@ -27,6 +27,13 @@ function redirect($path)
}
if (isset($_GET["rescan"]))
{
$lib->rescan_library(json_decode(file_get_contents("session/settings.json"), true)["osu_folder"]);
$lib->save_db();
redirect("./");
}
if (isset($_GET["scan"]))
{
$lib->scan_library(json_decode(file_get_contents("session/settings.json"), true)["osu_folder"]);
$lib->save_db();
@@ -61,7 +68,8 @@ $start = file_get_contents("resources/start.html");
$start = str_replace("{{ STYLE }}", file_get_contents("resources/style.css"), $start);
echo $start;
dump($lib, "lib");
echo '<a href="./?rescan">[Rescan]</a> ';
echo '<a href="./?scan">[Scan]</a> ';
echo '<a href="./?rescan">[Force rescan]</a> ';
echo '<a href="./?blacken">[Blacken]</a> ';
echo '<a href="./?nosb">[NoSB]</a> ';
echo '<a href="./?novid">[Novid]</a> ';