Skip to content

Commit 360834e

Browse files
[Minor] Improving the way to read .shp file names from INI (#1852)
> 改进从 INI 中读取 `.shp` 文件名的方式 The original processing method would check if there is a file extension. If not, it would automatically add the `.shp` extension to read. This is a good safeguard, but there are two problems: > 原先的处理方式会检查是否有后缀名,如果没有,那么会自动补上 `.shp` 后缀来读取,这是一个不错的保障手段,但是存在两个问题: 1. It only strictly checks for lowercase `.shp`, meaning that `RING1.SHP` would be considered as *having **no** extension*, so it would automatically add to become `RING1.SHP.shp` for reading. > 只严格检查小写 `.shp`,也就是说 `RING1.SHP` 会被视为 **没有** 后缀,因此自动补充为 `RING1.SHP.shp` 来读取, 2. It does not strictly check whether it is an extension, meaning that `.shp.RING2` would be considered as *having **an** extension*, so it would not add, and actually try to read a file named `.shp.RING2`, rather than `.shp.RING2.shp`. > 不严格检查是否为后缀,也就是说 `.shp.RING2` 会被视为 **已有** 后缀,不会补充,并真的去读取名为 `.shp.RING2` 的文件,而不是 `.shp.RING2.shp`。 Now, some improvements have been made so that uppercase `.SHP` is ***not*** considered as *having **no** extension*, and at the same time, cases where `.shp` is not at the end are ***no longer*** considered as *having **an** extension*. > 现在对它们进行了一些改进,使得大写 `.SHP` **不会** 被视为 **没有** 后缀,同时 **不再** 将 `.shp` 不在末尾的情况视为 **已有** 后缀。 Expected effect of the current changes (`PDFXLOC` (red) as the original incorrect effect, `RING1` (blue) as the expected correct effect): > 当前更改的预期效果(`PDFXLOC`(红)作为原始的错误效果,`RING1`(蓝)作为预期的正确效果): <img width="736" height="613" alt="RING1 SHP" src="https://github.com/user-attachments/assets/470f5dd2-8290-45bc-8966-2ce436ebe20b" /> <img width="736" height="613" alt="RING2 shp A" src="https://github.com/user-attachments/assets/fb54ce79-d725-4306-bc97-59ad72e8e2af" /> - [x] Test has passed. > 测试通过。
1 parent 5d943fd commit 360834e

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ This page lists all the individual contributions to the project by their author.
485485
- **E1 Elite** - TileSet 255 and above bridge repair fix
486486
- **AutoGavy** - interceptor logic, Warhead critical hit logic
487487
- **Chasheen (Chasheenburg)** - CN docs help for Build#24
488+
- **Noble Fish** - some minor improvements and fixes, established Community Chinese docs, took over and completely rewrite the Official Chinese docs during Build#46
488489
- **tomsons26** - all-around help, assistance and guidance in reverse-engineering, YR binary mappings
489490
- **CCHyper** - all-around help, current project logo, assistance and guidance in reverse-engineering, YR binary mappings, custom locomotors example implementation
490491
- **AlexB** - Original FlyingStrings implementation

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ Phobos fixes:
673673
- Fixed `AltNextScenario` not taking effect (by FlyStar)
674674
- Fixed `DefaultDisguise` showing wrong house colors for different players (by NetsuNegi & Ollerus)
675675
- `600 The shield of the attached object is broken` bug fix for the triggered event (by FlyStar)
676+
- Fixed a read bug when setting the SHP file name in INI (By Noble_Fish)
676677
677678
Fixes / interactions with other extensions:
678679
- Weapons fired by EMPulse superweapons *(Ares feature)* now fully respect the firing building's FLH (by Starkku)

src/Utilities/Constructs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ bool TheaterSpecificSHP::Read(INI_EX& parser, const char* pSection, const char*
261261
GeneralUtils::ApplyTheaterSuffixToString(pValue);
262262

263263
std::string Result = pValue;
264-
if (!strstr(pValue, ".shp"))
264+
if (Result.size() < 4 || !std::equal(Result.end() - 4, Result.end(), ".shp", [](char input, char expected) { return std::tolower(input) == expected; }))
265265
Result += ".shp";
266266

267267
if (auto const pImage = FileSystem::LoadSHPFile(Result.c_str()))

src/Utilities/TemplateDef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ namespace detail
335335
auto const pValue = parser.value();
336336
std::string Result = pValue;
337337

338-
if (!strstr(pValue, ".shp"))
338+
if (Result.size() < 4 || !std::equal(Result.end() - 4, Result.end(), ".shp", [](char input, char expected) { return std::tolower(input) == expected; }))
339339
Result += ".shp";
340340

341341
if (auto const pImage = FileSystem::LoadSHPFile(Result.c_str()))

0 commit comments

Comments
 (0)