Repacker implemented

This commit is contained in:
2020-12-28 21:34:07 +01:00
parent c1860a090a
commit bbe7b5849a
9 changed files with 168 additions and 23 deletions
+28
View File
@@ -1,4 +1,5 @@
<?php
require_once "libraries/utils.php";
// todo: make it work correctly on mac & linux (case sensitivity on deletion)
class optimizer
{
@@ -254,4 +255,31 @@ class optimizer
if (file_exists($file)) unlink($file);
}
}
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;
}
}
+1 -12
View File
@@ -17,7 +17,7 @@ class utils
{
if (is_dir($file))
{
recursive_zip_map($zip, $root, $file);
self::recursive_zip_map($zip, $root, $file);
}
else
{
@@ -26,15 +26,4 @@ class utils
}
}
}
// $folder = $my_db[$beatmap_id];
// $name = basename($folder) . ".osz";
// echo "Zipping " . $name;
// $path = $collection_location . "/" . $name;
// $zip = new ZipArchive;
// $zip->open($path, ZipArchive::CREATE);
// echo ".";
// recursive_zip_map($zip, $fol
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

+7
View File
@@ -45,6 +45,13 @@ if ($display == "main")
redirect("./");
}
if (isset($_GET["repack"]) && !empty($_GET["key"]))
{
$key = $_GET["key"];
$dl = @optimizer::repack($lib, $key);
redirect("./" . $dl);
}
if (isset($_GET["blacken"]))
{
@optimizer::blacken_backgrounds($lib);
+63 -7
View File
@@ -1,29 +1,85 @@
var xmlhttp = new XMLHttpRequest();
var page = 1;
var url = "./splitter.php?format=json&page=" + page.toString();
var url = "./splitter.php?format=json&page=";
updateBrowser();
xmlhttp.onreadystatechange = function() {
// done & success
if (this.readyState == 4 && this.status == 200) {
var result = JSON.parse(this.responseText);
alert(result);
changeBrowser(result);
}
};
xmlhttp.open("GET", url, true);
function requestPage(uri) {
xmlhttp.open("GET", uri, true);
xmlhttp.send();
}
function updateBrowser() {
requestPage(url + page.toString());
}
function prevPage() {
page -= 1;
if (page < 0) page = 0;
updateBrowser();
}
function nextPage() {
page += 1;
updateBrowser();
}
function changeBrowser(mapsets)
{
var browser = document.getElementById("browser");
var output = "";
var output = "<div>Page " + page.toString() + "</div>";
var template = "<div class=\"map\"><p class=\"map-title\">{{ MAP_TITLE }}</p></div>";
for (var beatmap of mapsets.entries)
var mapsetTemplate = `{{ MAIN_BROWSER_TEMPLATE_MAPSET }}`;
var template = `{{ MAIN_BROWSER_TEMPLATE_DIFFICULTY }}`;
for (var mapsetKey of Object.keys(mapsets))
{
output += template.replaceAll(/\{\{ MAP_TITLE \}\}/g, beatmap.Metadata.Title);
var mapset = mapsets[mapsetKey];
var subOutput = "";
var summary = true;
for (var beatmapKey of Object.keys(mapset.difficulties))
{
var beatmap = mapset.difficulties[beatmapKey];
if (beatmap.Metadata && beatmap.Metadata.Title)
{
var path = mapset.path.toString() + "/" + beatmap.background.toString();
path = encodeURI(path);
path = path.replaceAll(/\+/g, "%2b");
line = template;
line = line.replaceAll(/\{\{ MAP_TITLE \}\}/g, beatmap.Metadata.Title);
line = line.replaceAll(/\{\{ MAP_ARTIST \}\}/g, beatmap.Metadata.Artist);
line = line.replaceAll(/\{\{ MAP_MAPPER \}\}/g, beatmap.Metadata.Creator);
line = line.replaceAll(/\{\{ MAP_DIFFICULTY \}\}/g, beatmap.Metadata.Version);
line = line.replaceAll(/\{\{ MAP_IMAGE \}\}/g, "./proxy.php?path=" + path);
if (summary)
{
summary = false;
line = "<summary>" + line + "</summary>";
}
subOutput += line;
}
}
var uriSafeKey = mapset.key;
uriSafeKey = encodeURI(uriSafeKey);
uriSafeKey = uriSafeKey.replaceAll(/\+/g, "%2b");
subOutput = mapsetTemplate.replaceAll(/\{\{ MAP_DIFFICULTIES \}\}/g, subOutput);
subOutput = subOutput.replaceAll(/\{\{ MAPSET_KEY \}\}/g, uriSafeKey);
output += subOutput;
}
browser.innerHTML = output;
@@ -0,0 +1,11 @@
<div class="map">
<div class="map-image">
<img src="\{\{ MAP_IMAGE \}\}" />
</div>
<div class="map-details">
<p class="map-title">\{\{ MAP_TITLE \}\}</p>
<p class="map-artist">\{\{ MAP_ARTIST \}\}</p>
<p class="map-mapper">\{\{ MAP_MAPPER \}\}</p>
<p class="map-difficulty">\{\{ MAP_DIFFICULTY \}\}</p>
</div>
</div>
@@ -0,0 +1,6 @@
<div class="mapset-div">
<details class="mapset">
\{\{ MAP_DIFFICULTIES \}\}
</details>
<a href="./?repack&key=\{\{ MAPSET_KEY \}\}">REPACK</a>
</div>
+3 -1
View File
@@ -15,7 +15,9 @@
<div class="options">{{ MAIN_OPTIONS }}</div>
</div>
<div class="main-item">
<h2>Browser</h2>
<h2 id="a">Browser</h2>
<a onclick="prevPage()">[ Previous ]</a> &nbsp;
<a onclick="nextPage()">[ Next ]</a>
<div id="browser" class="browser">
<!-- todo JS -->
</div>
+47 -1
View File
@@ -11,9 +11,10 @@ html {
margin: 5px 0;
padding: 10px;
}
a:link, a:hover, a:active, a:visited {
a, a:link, a:hover, a:active, a:visited {
color: HotPink;
text-decoration: inherit;
cursor:pointer;
}
.small-background {
max-height: 100px;
@@ -65,3 +66,48 @@ a:link, a:hover, a:active, a:visited {
margin: 5px;
padding: 5px;
}
.map {
border: 1px solid white;
padding: 10px;
margin: 5px;
}
.map p {
margin: 0;
padding: 0;
}
.map-title {
font-weight: bold;
}
.map-artist, .map-mapper {
display: inline-block;
}
.map-artist::after {
content: ' /';
}
.map-mapper::before {
content: '/ ';
}
.map>div {
display: inline-block;
}
.map-image img {
max-height: 64px;
max-width: 64px;
}
.map-details {
display: inline-block;
vertical-align: top;
margin-left: 10px;
}
details.mapset summary::-webkit-details-marker {
display:none;
}
.mapset[open] .map {
background-color: #333333;
}
.mapset[open] summary .map {
background-color: #444444;
}