Optimizer settings gardening

This commit is contained in:
2021-01-06 19:30:33 +01:00
parent 05117f6836
commit 1fcb640029
5 changed files with 25 additions and 15 deletions
+1 -1
View File
@@ -293,7 +293,7 @@ class optimizer
public static function cleanup_dir(string $dir, bool $recursion = false) : void
{
$dir = rtrim(str_replace("\\", "/", $dir), "/");
$dir = utils::to_unix_slashes_without_trail($dir);
$glob = glob(utils::globsafe($dir) . "/*");
foreach ($glob as $file)
{
+7 -11
View File
@@ -8,36 +8,32 @@ class optimizer_settings
public function __construct(string $path)
{
$this->path = $path;
if (file_exists($path))
{
$this->load();
}
}
public function load()
public function load() : void
{
$raw = file_get_contents($this->path);
$json = json_decode($raw, true);
$json = utils::load_json($this->path);
$this->osu_path = $json["osu_path"] ?? "";
}
public function save()
public function save() : void
{
$json = array();
$json["osu_path"] = $this->osu_path;
$json = [ "osu_path" => $this->osu_path ];
$raw = json_encode($json);
file_put_contents($this->path, $raw);
file_put_contents($this->path, json_encode($json));
}
public function set_osu_path($path) : void
{
$sanitized = str_replace("\\", "/", $path);
$sanitized = rtrim($sanitized, "/");
if (file_exists($path))
{
$this->osu_path = $sanitized;
$this->osu_path = utils::to_unix_slashes_without_trail($path);
}
}
+1 -2
View File
@@ -24,8 +24,7 @@ class osu_library
public function scan_library(string $root) : void
{
$time_start = microtime(true); // measure scanning time
$root = str_ireplace("\\", "/", $root); // fuck windows backslash
$root = rtrim($root, "/"); // remove trailing slash(es)
$root = utils::to_unix_slashes_without_trail($root);
// giving a different library should always cause a full rescan
if ($this->get_osu_root() !== $root)
+1 -1
View File
@@ -34,7 +34,7 @@ class osu_parser
// fix backslash and double quotes
public static function fix_filename(string $filename) : string
{
return trim(str_replace("\\", "/", $filename), "\"");
return trim(utils::to_unix_slashes($filename), "\"");
}
public static function file_ver_peppy(string $path)// : array|bool // see you in php8
+15
View File
@@ -49,4 +49,19 @@ class utils
return json_decode($raw, true) ?? array();
}
public static function to_unix_slashes(string $path) : string
{
return str_replace("\\", "/", $path);
}
public static function remove_trailing_slashes(string $path) : string
{
return rtrim($path, "/");
}
public static function to_unix_slashes_without_trail(string $path) : string
{
return self::remove_trailing_slashes(self::to_unix_slashes($path));
}
}