Optimizer settings gardening
This commit is contained in:
@@ -293,7 +293,7 @@ class optimizer
|
|||||||
|
|
||||||
public static function cleanup_dir(string $dir, bool $recursion = false) : void
|
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) . "/*");
|
$glob = glob(utils::globsafe($dir) . "/*");
|
||||||
foreach ($glob as $file)
|
foreach ($glob as $file)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,36 +8,32 @@ class optimizer_settings
|
|||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
|
|
||||||
if (file_exists($path))
|
if (file_exists($path))
|
||||||
{
|
{
|
||||||
$this->load();
|
$this->load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load()
|
public function load() : void
|
||||||
{
|
{
|
||||||
$raw = file_get_contents($this->path);
|
$json = utils::load_json($this->path);
|
||||||
$json = json_decode($raw, true);
|
|
||||||
|
|
||||||
$this->osu_path = $json["osu_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, json_encode($json));
|
||||||
file_put_contents($this->path, $raw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_osu_path($path) : void
|
public function set_osu_path($path) : void
|
||||||
{
|
{
|
||||||
$sanitized = str_replace("\\", "/", $path);
|
|
||||||
$sanitized = rtrim($sanitized, "/");
|
|
||||||
if (file_exists($path))
|
if (file_exists($path))
|
||||||
{
|
{
|
||||||
$this->osu_path = $sanitized;
|
$this->osu_path = utils::to_unix_slashes_without_trail($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ class osu_library
|
|||||||
public function scan_library(string $root) : void
|
public function scan_library(string $root) : void
|
||||||
{
|
{
|
||||||
$time_start = microtime(true); // measure scanning time
|
$time_start = microtime(true); // measure scanning time
|
||||||
$root = str_ireplace("\\", "/", $root); // fuck windows backslash
|
$root = utils::to_unix_slashes_without_trail($root);
|
||||||
$root = rtrim($root, "/"); // remove trailing slash(es)
|
|
||||||
|
|
||||||
// giving a different library should always cause a full rescan
|
// giving a different library should always cause a full rescan
|
||||||
if ($this->get_osu_root() !== $root)
|
if ($this->get_osu_root() !== $root)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class osu_parser
|
|||||||
// fix backslash and double quotes
|
// fix backslash and double quotes
|
||||||
public static function fix_filename(string $filename) : string
|
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
|
public static function file_ver_peppy(string $path)// : array|bool // see you in php8
|
||||||
|
|||||||
@@ -49,4 +49,19 @@ class utils
|
|||||||
|
|
||||||
return json_decode($raw, true) ?? array();
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user