|
|
发表于 2025-11-4 08:38:23
|
显示全部楼层
class Config {
/ e; U; h, a* E/ H7 U v. b( _public:% r2 N- c) I! ]( I- b0 w2 R3 C
static std::string GetSharePath() {5 u: H3 l2 }% _1 s$ t
// 优先检查 share 目录& }$ d* R$ k b# F) M' ~* t* n
if (DirectoryExists("./share/")) {
, w8 u$ F3 `3 g* C! T& o return "./share/";$ @/ l% W- w* B' r/ q
}
" O) W3 g8 D7 n4 ~' A2 y9 u // 如果 share 目录不存在,使用当前目录' G2 ]2 s3 f8 S* \/ U0 Q8 v. }! H
return "./";% v x3 X" t% P& ~" U) F+ ]4 D
} i: T8 y I# Z. _
/ k) T7 x, D: Z0 h; @
static std::string GetItemetcPath() {
0 H0 j2 n) s( M/ o0 Y' b, [ return GetSharePath() + "itemetc.csv";6 O x0 m& {1 x6 U4 H
}2 g$ f8 I4 n6 `( Z8 F) f3 S
; d- Z4 y) p, N' O; X# W; L# f/ A static std::string GetItemarmorPath() {; y6 }) V/ n9 J" o
return GetSharePath() + "itemarmor.csv";
4 g5 e# D5 M6 e }) h' w+ `2 O& F
1 `+ B; @* k: b s8 B) L9 X: R
static std::string GetItemweaponPath() {& ~0 X6 N" W$ o" }! `: B" y( t
return GetSharePath() + "itemweapon.csv";
l1 T/ e3 V9 c# r }
/ n6 Y: J5 |) m, j$ _ V1 j
/ B3 k5 D0 w7 \6 C, l( v1 x: ?% Q* z static std::string GetSkillnamePath() {
2 ^/ c# K% R% U, I return GetSharePath() + "skillname.csv";7 Z8 `: G9 X# t) E
}
, ]6 N5 G; S/ Q
8 o" }9 n. P) J1 Rprivate:
0 R% z6 Y* V/ i& ? static bool DirectoryExists(const std::string& path) {) ^$ r. |6 _* p% U N* G1 C
// 实现目录存在性检查
+ B) }5 R; n+ d struct stat info;
4 D7 ]6 r8 U; \+ F$ }. P3 M: j return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);& C, \/ o8 Y1 `/ @
}+ V9 h; {1 h, Q% J
}; |
|