From 8d885a5a6720c4b1d1ca2f8e19389314d1201cfc Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Fri, 5 Jul 2024 18:09:24 +0200 Subject: [PATCH] Setup/WIN * fix paths for WIN ... and try to not use slashes in the future... * fixes #430 --- includes/utilities.php | 5 +-- setup/tools/CLISetup.class.php | 17 ++++------ setup/tools/filegen/simpleimg.ss.php | 48 +++++++++++++++------------- setup/tools/setupScript.class.php | 13 ++++---- 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/includes/utilities.php b/includes/utilities.php index 99b5a621..3a96e592 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -343,8 +343,9 @@ abstract class CLI $path .= ($path ? DIRECTORY_SEPARATOR : '').trim($fileOrPath); - // remove quotes (from erronous user input) - $path = str_replace(['"', "'"], ['', ''], $path); + // remove double quotes (from erronous user input), single quotes are + // valid chars for filenames and removing those mutilates several wow icons + $path = str_replace('"', '', $path); if (!$path) // empty strings given. (faulty dbc data?) return ''; diff --git a/setup/tools/CLISetup.class.php b/setup/tools/CLISetup.class.php index 35167219..0f83cba9 100644 --- a/setup/tools/CLISetup.class.php +++ b/setup/tools/CLISetup.class.php @@ -204,7 +204,7 @@ class CLISetup // alternative data source (no quotes, use forward slash) if (isset(self::$opts['datasrc'])) - self::$srcDir = CLI::nicePath(self::$opts['datasrc']); + self::$srcDir = CLI::nicePath('', self::$opts['datasrc']); if (!self::setLocales()) CLI::write('No valid locale specified. Check your config or --locales parameter, if used', CLI::LOG_ERROR); @@ -475,15 +475,12 @@ class CLISetup $setupDirs = glob('setup/*'); foreach ($setupDirs as $sd) { - if (mb_substr(self::$srcDir, -1) == '/') - self::$srcDir = mb_substr(self::$srcDir, 0, -1); - - if (mb_substr($sd, -1) == '/') + if (mb_substr($sd, -1) == DIRECTORY_SEPARATOR) $sd = mb_substr($sd, 0, -1); if (Util::lower($sd) == Util::lower(self::$srcDir)) { - self::$srcDir = $sd.'/'; + self::$srcDir = $sd.DIRECTORY_SEPARATOR; break; } } @@ -495,7 +492,7 @@ class CLISetup foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST) as $path) { - $_ = str_replace('\\', '/', $path->getPathname()); + $_ = CLI::nicePath($path->getPathname()); self::$mpqFiles[strtolower($_)] = $_; } @@ -521,7 +518,7 @@ class CLISetup $_ = strtolower(CLI::nicePath($file)); // remove trailing slash - if (mb_substr($_, -1, 1) == '/') + if (mb_substr($_, -1, 1) == DIRECTORY_SEPARATOR) $_ = mb_substr($_, 0, -1); if (isset(self::$mpqFiles[$_])) @@ -569,7 +566,7 @@ class CLISetup continue; if ($xp) // if in subDir add trailing slash - $xp .= '/'; + $xp .= DIRECTORY_SEPARATOR; $path = sprintf($pathPattern, $xp); if (self::fileExists($path)) @@ -599,7 +596,7 @@ class CLISetup continue; if ($xp) - $xp .= '/'; + $xp .= DIRECTORY_SEPARATOR; $gsFile = sprintf(self::GLOBALSTRINGS_LUA, self::$srcDir, $xp); if (self::fileExists($gsFile)) diff --git a/setup/tools/filegen/simpleimg.ss.php b/setup/tools/filegen/simpleimg.ss.php index a8743b50..2eace248 100644 --- a/setup/tools/filegen/simpleimg.ss.php +++ b/setup/tools/filegen/simpleimg.ss.php @@ -34,20 +34,20 @@ CLISetup::registerSetup("build", new class extends SetupScript ); private $genSteps = array( - // srcPath, realPath, localized, [pattern, isIcon, tileSize, localized], [[dest, ext, srcSize, destSize, borderOffset]] - 0 => ['Icons/', null, false, ['/.*\.(blp|png)$', true, 0], self::ICON_DIRS, ], - 1 => ['Spellbook/', null, false, ['/UI-Glyph-Rune-?\d+.(blp|png)$', false, 0], [['static/images/wow/Interface/Spellbook/', 'png', 0, 0, 0]]], - 2 => ['PaperDoll/', null, false, ['/UI-(Backpack|PaperDoll)-.*\.(blp|png)$', true, 0], self::ICON_DIRS, ], - 3 => ['GLUES/CHARACTERCREATE/', null, false, ['/UI-CharacterCreate-Races.(blp|png)', true, 64], self::ICON_DIRS, ], - 4 => ['GLUES/CHARACTERCREATE/', null, false, ['/UI-CharacterCreate-CLASSES.(blp|png)', true, 64], self::ICON_DIRS, ], - 5 => ['GLUES/CHARACTERCREATE/', null, false, ['/UI-CharacterCreate-Factions.(blp|png)', true, 64], self::ICON_DIRS, ], - // 6 => ['Minimap/' , null, false, ['/OBJECTICONS.(BLP|png)', true, 32], [['static/images/wow/icons/tiny/', 'gif', 0, 16, 2]]], - 7 => ['FlavorImages/', null, false, ['/.*\.(blp|png)$', false, 0], [['static/images/wow/Interface/FlavorImages/', 'png', 0, 0, 0]]], - 8 => ['Pictures/', null, false, ['/.*\.(blp|png)$', false, 0], [['static/images/wow/Interface/Pictures/', 'png', 0, 0, 0]]], - 9 => ['PvPRankBadges/', null, false, ['/.*\.(blp|png)$', false, 0], [['static/images/wow/Interface/PvPRankBadges/', 'png', 0, 0, 0]]], - 10 => ['Calendar/Holidays/', null, false, ['/.*(start|[ayhs])\.(blp|png)$', true, 0], self::ICON_DIRS, ], - 11 => ['GLUES/LOADINGSCREENS/', null, false, ['/lo.*\.(blp|png)$', false, 0], [['cache/loadingscreens/', 'png', 0, 0, 0]]], - 12 => ['PVPFrame/', null, false, ['/PVP-(ArenaPoints|Currency).*\.(blp|png)$', true, 0], self::ICON_DIRS, ] + // srcPath, realPath, localized, [pattern, isIcon, tileSize], [[dest, ext, srcSize, destSize, borderOffset]] + 0 => ['Icons/', null, false, ['.*\.(blp|png)$', true, 0], self::ICON_DIRS, ], + 1 => ['Spellbook/', null, false, ['UI-Glyph-Rune-?\d+.(blp|png)$', false, 0], [['static/images/wow/Interface/Spellbook/', 'png', 0, 0, 0]]], + 2 => ['PaperDoll/', null, false, ['UI-(Backpack|PaperDoll)-.*\.(blp|png)$', true, 0], self::ICON_DIRS, ], + 3 => ['GLUES/CHARACTERCREATE/', null, false, ['UI-CharacterCreate-Races\.(blp|png)', true, 64], self::ICON_DIRS, ], + 4 => ['GLUES/CHARACTERCREATE/', null, false, ['UI-CharacterCreate-CLASSES\.(blp|png)', true, 64], self::ICON_DIRS, ], + 5 => ['GLUES/CHARACTERCREATE/', null, false, ['UI-CharacterCreate-Factions\.(blp|png)', true, 64], self::ICON_DIRS, ], + // 6 => ['Minimap/' , null, false, ['OBJECTICONS.(BLP|png)', true, 32], [['static/images/wow/icons/tiny/', 'gif', 0, 16, 2]]], + 7 => ['FlavorImages/', null, false, ['.*\.(blp|png)$', false, 0], [['static/images/wow/Interface/FlavorImages/', 'png', 0, 0, 0]]], + 8 => ['Pictures/', null, false, ['.*\.(blp|png)$', false, 0], [['static/images/wow/Interface/Pictures/', 'png', 0, 0, 0]]], + 9 => ['PvPRankBadges/', null, false, ['.*\.(blp|png)$', false, 0], [['static/images/wow/Interface/PvPRankBadges/', 'png', 0, 0, 0]]], + 10 => ['Calendar/Holidays/', null, false, ['.*(start|[ayhs])\.(blp|png)$', true, 0], self::ICON_DIRS, ], + 11 => ['GLUES/LOADINGSCREENS/', null, false, ['lo.*\.(blp|png)$', false, 0], [['cache/loadingscreens/', 'png', 0, 0, 0]]], + 12 => ['PVPFrame/', null, false, ['PVP-(ArenaPoints|Currency).*\.(blp|png)$', true, 0], self::ICON_DIRS, ] ); // textures are composed of 64x64 icons @@ -148,10 +148,14 @@ CLISetup::registerSetup("build", new class extends SetupScript if (!$groups) // by default do not generate loadingscreens $groups = [0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 12]; - // removed unused generators + // removed unused generators and reset realPaths (in case of retry from failed attempt) foreach ($this->genSteps as $idx => $_) + { if (!in_array($idx, $groups)) unset($this->genSteps[$idx]); + else + $this->genSteps[$idx][self::$GEN_IDX_SRC_REAL] = null; + } if (!$this->checkSourceDirs()) { @@ -164,9 +168,9 @@ CLISetup::registerSetup("build", new class extends SetupScript $allPaths = []; foreach ($this->genSteps as $i => [, $path, , [$pattern, $isIcon, $tileSize], $outInfo]) { - $search = $path.$pattern; + $search = CLI::nicePath('', $path); if ($pattern) - $search = '/'.str_replace('/', '\\/', $search).'/i'; + $search = '/'.strtr($search, ['\\' => '\\\\', '/' => '\\/']).$pattern.'/i'; $files = CLISetup::filesInPath($search, !!$pattern); $allPaths = array_merge($allPaths, array_map(function ($x) { return substr($x, 0, -4); }, $files)); @@ -186,7 +190,7 @@ CLISetup::registerSetup("build", new class extends SetupScript ini_set('max_execution_time', $this->maxExecTime); $src = null; - $na = explode('/', $f); + $na = explode(DIRECTORY_SEPARATOR, $f); $img = explode('.', array_pop($na)); array_pop($img); // there are a hand full of images with multiple file endings or random dots in the name $img = implode('.', $img); @@ -214,7 +218,7 @@ CLISetup::registerSetup("build", new class extends SetupScript foreach ($row as $x => $name) { $j++; - $outFile = $dest.($isIcon ? strtolower($name) : $name).'.'.$ext; + $outFile = CLI::nicePath(($isIcon ? strtolower($name) : $name).'.'.$ext, $dest); $this->status = ' - '.str_pad($j.'/'.$nFiles, 12).str_pad('('.number_format($j * 100 / $nFiles, 2).'%)', 9); @@ -287,7 +291,7 @@ CLISetup::registerSetup("build", new class extends SetupScript { $j++; $this->status = ' - '.str_pad($j.'/'.$nFiles, 12).str_pad('('.number_format($j * 100 / $nFiles, 2).'%)', 9); - $outFile = $dest.($isIcon ? strtolower($img) : $img).'.'.$ext; + $outFile = CLI::nicePath(($isIcon ? strtolower($img) : $img).'.'.$ext, $dest); if (!CLISetup::getOpt('force') && file_exists($outFile)) { @@ -341,7 +345,7 @@ CLISetup::registerSetup("build", new class extends SetupScript if ($itemIcons = DB::Aowow()->selectCol('SELECT `inventoryIcon1` FROM dbc_itemdisplayinfo WHERE `inventoryIcon1` <> ""')) foreach ($itemIcons as $icon) - $dbcEntries[] = strtolower($this->genSteps[0][self::$GEN_IDX_SRC_REAL].'/'.$icon); + $dbcEntries[] = strtolower($this->genSteps[0][self::$GEN_IDX_SRC_REAL].DIRECTORY_SEPARATOR.$icon); } if (in_array(1, $gens)) // generates glyphs @@ -353,7 +357,7 @@ CLISetup::registerSetup("build", new class extends SetupScript if (in_array(10, $gens)) // generates holiday icons if ($eventIcons = DB::Aowow()->selectCol('SELECT `textureString` FROM dbc_holidays WHERE `textureString` <> ""')) foreach ($eventIcons as $icon) - $dbcEntries[] = strtolower($this->genSteps[10][self::$GEN_IDX_SRC_REAL].'/'.$icon.'start'); + $dbcEntries[] = strtolower($this->genSteps[10][self::$GEN_IDX_SRC_REAL].DIRECTORY_SEPARATOR.$icon.'start'); // case-insensitive array_unique *vomits silently into a corner* $dbcEntries = array_intersect_key($dbcEntries, array_unique($dbcEntries)); diff --git a/setup/tools/setupScript.class.php b/setup/tools/setupScript.class.php index 57d43e54..a58dd71a 100644 --- a/setup/tools/setupScript.class.php +++ b/setup/tools/setupScript.class.php @@ -171,7 +171,7 @@ trait TrImageProcessor if ($p = CLISetup::filesInPathLocalized($path, $this->success, $localized)) { $foundCache[$subDir] = $p; - $this->genSteps[$i][self::$GEN_IDX_SRC_REAL] = $p; // pvp v7.3+ - make $realPaths areferene + $this->genSteps[$i][self::$GEN_IDX_SRC_REAL] = $p; // php v8.2+ - make GEN_IDX_SRC_REAL a const } else $this->success = false; @@ -192,10 +192,9 @@ trait TrImageProcessor continue; $foundCache[$subDir] = true; - if (!$realPaths) { - CLI::write(CLI::red('MISSING').' - '.str_pad($subDir, 14).' @ '.sprintf($this->imgPath, '['.implode('/,', $locList).'/]').$subDir); + CLI::write(CLI::red('MISSING').' - '.str_pad($subDir, $outTblLen).' @ '.sprintf($this->imgPath, '['.implode('/,', $locList).'/]').$subDir); $this->success = false; } else if ($localized) @@ -203,13 +202,13 @@ trait TrImageProcessor $foundLoc = []; foreach (CLISetup::$expectedPaths as $xp => $lId) if (in_array($lId, array_keys(CLISetup::$locales))) - if (isset($realPaths[$lId]) && ($n = stripos($realPaths[$lId], '/'.$xp.'/'))) + if (isset($realPaths[$lId]) && ($n = stripos($realPaths[$lId], DIRECTORY_SEPARATOR.$xp.DIRECTORY_SEPARATOR))) $foundLoc[$lId] = substr($realPaths[$lId], $n + 1, 4); if ($diff = array_diff_key(CLISetup::$locales, $foundLoc)) { $buff = []; - foreach ($diff as $d) + foreach ($diff as $d => $_) $buff[] = CLI::red(Util::$localeStrings[$d]); foreach ($foundLoc as $str) $buff[] = CLI::green($str); @@ -227,7 +226,7 @@ trait TrImageProcessor // if not localized directly return result foreach ($this->genSteps as $i => [$subDir, $realPaths, $localized, , ]) - if (!$localized) + if (!$localized && $realPaths) $this->genSteps[$i][self::$GEN_IDX_SRC_REAL] = reset($realPaths); return $this->success; @@ -466,7 +465,7 @@ abstract class SetupScript $dirs[] = $dir; else foreach (CLISetup::$locales as $str) - $dirs[] = $dir . $str . '/'; + $dirs[] = $dir . $str . DIRECTORY_SEPARATOR; foreach ($dirs as $d) {