|
|
发表于 2025-11-4 08:38:23
|
显示全部楼层
class Config {
6 x- _+ W6 _7 k( X) Ppublic:
7 @3 }* w+ [/ H$ C3 T" G static std::string GetSharePath() {
6 U6 d8 `; h5 d- U2 s' h // 优先检查 share 目录
d' M1 e" j; s6 a# u& q$ I/ g4 v if (DirectoryExists("./share/")) {' B& K/ R) L) ~2 D6 f
return "./share/";
8 J# ~' r6 e/ K6 A' ^( k }
% J. |( k7 y& s8 u# a- \! L! \ // 如果 share 目录不存在,使用当前目录
1 G, I* {% a; C5 o5 O" L$ R: O1 A return "./";
6 h/ h! g- A9 `0 q }
+ |, k# b& Y! p! g$ L ; Y4 J, p3 q5 H7 Y& z
static std::string GetItemetcPath() {$ ]1 e: l& q, u/ L# c
return GetSharePath() + "itemetc.csv";
1 L' B( A4 U F7 Y1 n* i8 E }
/ Y& d$ S i. b + Q j5 y2 w* e) b9 q
static std::string GetItemarmorPath() {
- V* c; }& Z. l v return GetSharePath() + "itemarmor.csv";
* [: c6 M X( w4 q) c y }
* W: ]2 J) j: E2 ?* f) @ ( c X8 [: h( e8 z% r; A' I
static std::string GetItemweaponPath() {+ S& t& t4 ^$ K2 r* ^! b
return GetSharePath() + "itemweapon.csv";
2 F3 I+ O( |+ I }
# S8 j5 O2 t ~9 d4 g" d
% z) Y- U$ M* ^# q4 w' U4 h static std::string GetSkillnamePath() {8 _* b$ }: R/ `4 A3 z
return GetSharePath() + "skillname.csv";
4 i; g+ W% r) o3 B! W }$ S) T0 @" L M/ {7 y8 n
% I0 U* R# h7 ^
private:4 `$ S6 J0 W t, h' |2 ~9 n, g3 K
static bool DirectoryExists(const std::string& path) {
4 s. E7 w0 C- E // 实现目录存在性检查
$ Q @. @* [' a4 E, p8 ]* ] struct stat info;8 q. I( Q6 i: m! g( R
return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);
w, d8 s! i! q0 I8 u }
* B8 N# I) w: I4 Y! ?: R8 k7 n}; |
|