|
|
发表于 2025-11-4 08:38:23
|
显示全部楼层
class Config {% Z: T+ h, q! u% I
public:! Z& k) b _! E
static std::string GetSharePath() {
1 u, X2 Q( _1 T5 c // 优先检查 share 目录. n( q, D5 Y1 i1 i- J6 y
if (DirectoryExists("./share/")) {
. k) J- b. Q6 H2 S7 u9 ^% _ return "./share/";0 m$ _ q$ }$ o$ v7 c3 Z
}0 z+ F+ D, a$ C h1 F4 V, X* g
// 如果 share 目录不存在,使用当前目录
7 R! B) x Y5 ~/ u return "./";' x7 \/ X8 y/ l$ ~, I
}0 A) L" ~2 X" E, @( b+ I
% \% S( C: M1 U
static std::string GetItemetcPath() {
) O% Y Q9 R) Q+ d5 K7 r; K. | return GetSharePath() + "itemetc.csv";
, H. Q1 s8 u% T& ^# V }' w( h3 G6 I8 y: Z' d
% p% ~5 }5 L e; v3 G% ] static std::string GetItemarmorPath() {
* m0 }+ \9 U ]) w( t+ F. U return GetSharePath() + "itemarmor.csv";. J L( ]% ~5 v3 }
}" G, o) o1 E( ?& n0 U E7 X$ C
) S H8 w/ g' E& e/ A( ~/ G1 w
static std::string GetItemweaponPath() {( F% G& a" u! a+ L, I' O5 z% P4 H
return GetSharePath() + "itemweapon.csv";0 z* H7 Y! _3 ]4 B) W
}
% `7 y" o- ^$ t" t. c: k5 a) d) Q/ O
- _- R$ y- G! A* I static std::string GetSkillnamePath() {2 P- V" ~0 t1 w: V
return GetSharePath() + "skillname.csv";# ~9 Y: Q1 U# z2 O
}
4 F" T' f6 d& b/ p! a' ]4 `+ ^ % T& M5 X' @" l- n4 d# h6 w
private:
* i% w8 Y7 H" \* W( F static bool DirectoryExists(const std::string& path) {& ]. i' A- h' L# U0 H, O @- g
// 实现目录存在性检查* \; D% y/ ]7 @/ @& ^# U, `8 ~ P, D
struct stat info;% p$ U7 x6 C! U8 L/ k% m
return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);( A6 y- L& Q+ O0 `6 r' e/ O
}' T$ Y# ?2 B( Y6 B2 \, U
}; |
|