diff --git a/index.php b/index.php index bfd6e07..12c12b6 100644 --- a/index.php +++ b/index.php @@ -13,8 +13,5 @@ set_time_limit(298800); // the future ini_set('memory_limit', '1024M'); -// git does not like empty folders -if (!file_exists("session")) mkdir("session"); - // the entry point require "main.php"; \ No newline at end of file diff --git a/libraries/optimizer.php b/libraries/optimizer.php index 2573536..321c222 100644 --- a/libraries/optimizer.php +++ b/libraries/optimizer.php @@ -256,6 +256,14 @@ class optimizer } } + 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"] ?? ""; diff --git a/libraries/optimizer_settings.php b/libraries/optimizer_settings.php new file mode 100644 index 0000000..37af460 --- /dev/null +++ b/libraries/optimizer_settings.php @@ -0,0 +1,48 @@ +path = $path; + if (file_exists($path)) + { + $this->load(); + } + } + + public function load() + { + $raw = file_get_contents($this->path); + $json = json_decode($raw, true); + + $this->osu_path = $json["osu_folder"] ?? ""; + } + + public function save() + { + $json = array(); + $json["osu_path"] = $this->osu_path; + + $raw = json_encode($json); + file_put_contents($this->path); + } + + public function set_osu_path($path) : void + { + $sanitized = str_replace("\\", "/", $path); + $sanitized = rtrim($sanitized, "/"); + if (file_exists($path)) + { + $this->osu_path = $sanitized; + } + } + + public function get_osu_path() : string + { + return $this->osu_path; + } +} \ No newline at end of file diff --git a/libraries/osu_library.php b/libraries/osu_library.php index fe8973d..bfe4e78 100644 --- a/libraries/osu_library.php +++ b/libraries/osu_library.php @@ -178,7 +178,7 @@ class osu_library public function get_root() : string { - return $this->db["root"]; + return $this->db["root"] ?? ""; } public function set_root(string $root) : void diff --git a/macska.jpg b/macska.jpg deleted file mode 100644 index 4be5ef6..0000000 Binary files a/macska.jpg and /dev/null differ diff --git a/main.php b/main.php index 23600de..5a9dcf8 100644 --- a/main.php +++ b/main.php @@ -1,23 +1,46 @@ is_loaded()) +if (isset($_GET["settings"]) || empty($settings->get_osu_path())) +{ + // $display = "start"; +} +else if (!empty($_GET["notice"])) +{ + $display = "notice"; + $notice = $_GET["notice"]; +} +else if (!empty($_GET["warn"]) && !empty($_GET["forward"])) +{ + $display = "warn"; + $forward = $_GET["forward"]; + $warn = $_GET["warn"]; +} +else if ($lib->is_loaded()) { $display = "main"; } @@ -28,28 +51,39 @@ function redirect($path) exit(0); // TERMINATE CURRENT SCRIPT! } -$te = new template_engine(); -if ($display == "main") +if (!empty($settings->get_osu_path())) { if (isset($_GET["rescan"])) { - $lib->rescan_library(json_decode(file_get_contents("session/settings.json"), true)["osu_folder"]); + $lib->rescan_library($settings->get_osu_path()); $lib->save_db(); redirect("./"); } if (isset($_GET["scan"])) { - $lib->scan_library(json_decode(file_get_contents("session/settings.json"), true)["osu_folder"]); + $lib->scan_library($settings->get_osu_path()); $lib->save_db(); redirect("./"); } +} - if (isset($_GET["repack"]) && !empty($_GET["key"])) +$te = new template_engine(); +if ($display == "main") +{ + if (isset($_GET["repack"])) { - $key = $_GET["key"]; - $dl = @optimizer::repack($lib, $key); - redirect("./" . $dl); + if (!empty($_GET["key"])) + { + $key = $_GET["key"]; + $dl = @optimizer::repack($lib, $key); + redirect("./" . $dl); + } + else if (isset($_GET["all"])) + { + @optimizer::repack_all($lib); + redirect("./?notice=repack"); + } } if (isset($_GET["blacken"])) @@ -95,6 +129,7 @@ if ($display == "main") } $options = array( + [ "./?settings", "Settings", "Go back to the setup/settings screen." ], [ "./?scan", "Scan", "Only scan for changes." ], [ "./?rescan", "Force rescan", "Fully rescan the library. (cached)" ], [ "./?blacken", "Remove backgrounds", "Replace the background files with 1x1 black images." ], @@ -104,6 +139,7 @@ if ($display == "main") [ "./?nohit", "Remove custom hitsounds", "Does not remove storyboard elements." ], [ "./?purify", "Remove junk files", "Remove everything that isn't referenced in .osu or .osb files." ], [ "./?nuke", "NUKE", "Remove everything that isn't .osu or a referenced audio/background file. Note: old/bad maps might lose vital elements!" ], + [ "./?warn=repack&forward=" . urlencode("./?repack&all"), "Repack all", "Repack all maps to .osz files. Note: you should not share exported maps; always use official osu! links." ], [ "./splitter.php?page=1", "Explore", "TBD" ], ); @@ -136,14 +172,36 @@ if ($display == "main") ]); } - echo $te->get_html(); - // dump($lib, "lib"); } +else if ($display == "notice") +{ + $notice_upper = strtoupper($notice); + $te->set_block_template("CONTENT", "NOTICE_{$notice_upper}"); +} +else if ($display == "warn") +{ + $warn_upper = strtoupper($warn); + $te->set_block("WARN_FORWARD_LINK", $forward); + $te->set_block_template("CONTENT", "WARN_{$warn_upper}"); +} else if ($display == "start") { + if (!empty($_POST["osu_folder"])) + { + $settings->set_osu_path($_POST["osu_folder"]); + $settings->save(); + redirect("./?scan"); + } + $te->set_block_template("CONTENT", "SETTINGS"); + if (!empty($settings->get_osu_path())) + { + $te->set_block_template("SETTINGS_BACK", "SETTINGS_BACK_SOURCE"); + } } + +echo $te->get_html(); // foreach ($lib->get_library() as $mapset) diff --git a/splitter.php b/splitter.php index 45a808b..5b8fdc5 100644 --- a/splitter.php +++ b/splitter.php @@ -52,36 +52,16 @@ if ($format == "html") else $difftext = "difficulties"; echo $value["id"] . ": " . $firstdiff["Metadata"]["Artist"] . " - " . $firstdiff["Metadata"]["Title"] . " (" . $diffcount . " {$difftext})\n"; } - // $proc_times = array(); - // foreach ($library as $key => $set) - // { - // $tiempo = 0; - // foreach ($set["difficulties"] as $map) - // { - // $tiempo += $map["parsing_time"]; - // } - // $proc_times[$key] = $tiempo; - // } - - // arsort($proc_times); - - // foreach ($proc_times as $key => $tiempo) - // { - // $value = $library[$key]; - // $firstdiff = $value["difficulties"][array_key_first($value["difficulties"])]; - // $diffcount = 0; - // foreach ($value["difficulties"] as $diff) - // { - // if ($diff["format"] != "storyboard") - // { - // $diffcount++; - // } - // } - // echo str_pad(round($tiempo, 5), 7, "0") . "s " . $value["id"] . ": " . $firstdiff["Metadata"]["Artist"] . " - " . $firstdiff["Metadata"]["Title"] . " (" . $diffcount . " difficulties)\n"; - // } } else // default to json in every other case { + $response = array( + "page" => $page, + "maxpage" => $maxpage, + "pagesize" => $pagesize, + "mapsets" => $partial_library ?? array(), + ); + header('Content-Type: application/json'); - echo json_encode($partial_library); + echo json_encode($response); } \ No newline at end of file diff --git a/templates/main-browser-script.js b/templates/main-browser-script.js index 52c7c1e..b0a8eb0 100644 --- a/templates/main-browser-script.js +++ b/templates/main-browser-script.js @@ -1,5 +1,6 @@ var xmlhttp = new XMLHttpRequest(); var page = 1; +var maxpage = 1; var url = "./splitter.php?format=json&page="; updateBrowser(); @@ -34,17 +35,38 @@ function nextPage() { updateBrowser(); } -function changeBrowser(mapsets) +function firstPage() { + page = 1; + updateBrowser(); +} + +function lastPage() { + page = maxpage; + updateBrowser(); +} + +function changeBrowser(response) { var browser = document.getElementById("browser"); - var output = "
Page " + page.toString() + "
"; + if (!response.page) + { + return; + } + + if (response.maxpage) + { + maxpage = response.maxpage; + } + + var output = "
Page " + page.toString() + "/" + response.maxpage.toString() + "
"; var mapsetTemplate = `{{ MAIN_BROWSER_TEMPLATE_MAPSET }}`; var template = `{{ MAIN_BROWSER_TEMPLATE_DIFFICULTY }}`; - for (var mapsetKey of Object.keys(mapsets)) + + for (var mapsetKey of Object.keys(response.mapsets)) { - var mapset = mapsets[mapsetKey]; + var mapset = response.mapsets[mapsetKey]; var subOutput = ""; var summary = true; diff --git a/templates/main-browser-template-mapset.html b/templates/main-browser-template-mapset.html index 5c68140..0679eda 100644 --- a/templates/main-browser-template-mapset.html +++ b/templates/main-browser-template-mapset.html @@ -2,5 +2,5 @@
\{\{ MAP_DIFFICULTIES \}\}
- REPACK + ↑ [ REPACK ] ↑ \ No newline at end of file diff --git a/templates/main.html b/templates/main.html index 1f42bcc..bdcb652 100644 --- a/templates/main.html +++ b/templates/main.html @@ -16,8 +16,13 @@

Browser

- [ Previous ]   - [ Next ] +
+ [ << First ]   + [ < Previous ]   + [ Next > ]   + [ Last >> ]   +
+
diff --git a/templates/notice-repack.txt b/templates/notice-repack.txt new file mode 100644 index 0000000..9ffa775 --- /dev/null +++ b/templates/notice-repack.txt @@ -0,0 +1 @@ +Check your session/osz/ folder for the exported files. \ No newline at end of file diff --git a/templates/settings-back-source.html b/templates/settings-back-source.html new file mode 100644 index 0000000..c8d2d70 --- /dev/null +++ b/templates/settings-back-source.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/templates/settings.html b/templates/settings.html new file mode 100644 index 0000000..f653dea --- /dev/null +++ b/templates/settings.html @@ -0,0 +1,11 @@ +
+

SETTINGS

+
+ +
+

(Use a fully qualified real path preferably without symlinks. Relative paths are supported in theory, but try to use absolute paths.)

+ {{ SETTINGS_BACK }} + +
+
+
\ No newline at end of file diff --git a/templates/style.css b/templates/style.css index 82fd53f..ccac12b 100644 --- a/templates/style.css +++ b/templates/style.css @@ -110,4 +110,15 @@ details.mapset summary::-webkit-details-marker { .mapset[open] summary .map { background-color: #444444; +} +.warn h2 { + margin: 0; + text-align: center; +} +.warn { + max-width: 400px; + margin: auto; + margin-top: 30px; + border: 1px solid white; + padding: 10px; } \ No newline at end of file diff --git a/templates/warn-repack.html b/templates/warn-repack.html new file mode 100644 index 0000000..33e0d4c --- /dev/null +++ b/templates/warn-repack.html @@ -0,0 +1,6 @@ +
+

WARNING!

+

Repacking all beatmaps will take a LONG time. Are you sure you want to continue?

+

[ Yes ]    [ No ]

+

(The repacking will start after clicking the "yes" button. If you are unsure whether you clicked it, check your session/osz/ folder; there should be some .osz files already.)

+
\ No newline at end of file