|
|
发表于 2025-11-4 08:38:23
|
显示全部楼层
class Config {: ~) }- p# L j) w1 d
public:
, o$ P5 \5 J& m' S) |8 ?7 z8 [ static std::string GetSharePath() {
: V% | f. w5 n6 H7 E // 优先检查 share 目录
{3 J! a2 _2 ? if (DirectoryExists("./share/")) {
3 j& Z$ A. N7 ] return "./share/";
$ l% R7 X$ U9 F5 g7 a }5 t1 t- G& U& g
// 如果 share 目录不存在,使用当前目录
/ N S# v/ w8 e9 ^ return "./";
$ ?) }/ S& @3 A5 ~% ?8 } }
) c1 W& m% o: v, u2 D " G2 f( B0 p8 i0 @( e& ?% d% p
static std::string GetItemetcPath() {: J8 Y4 U6 h5 z3 L k( s
return GetSharePath() + "itemetc.csv";. k5 l# s, J2 K- m5 h/ e
}
" N9 w6 ~* `# Q3 I t1 x & x! r/ T/ x- B1 ]) \' `
static std::string GetItemarmorPath() {7 o& l1 L. G2 v9 `) {/ X# h
return GetSharePath() + "itemarmor.csv";' U( J3 c9 P* y2 ^) l5 L1 k& P; h
}
, l/ N: E1 @% Q/ {6 r2 `9 c6 }- L& g
6 p, J2 e2 x. k# ^2 k static std::string GetItemweaponPath() {2 w- j' M* q E7 ^
return GetSharePath() + "itemweapon.csv";* w7 P. P9 H9 H/ r7 p
}
( _; H0 O) [# x7 G! y
$ H9 ]" M, k5 f4 o9 V static std::string GetSkillnamePath() {
& b/ D+ N' L, k return GetSharePath() + "skillname.csv";
* @4 \4 E7 I4 k/ @* h4 x0 Z+ k; o }8 {2 c$ E; o2 b
. ]4 w; c3 d/ `4 w F$ x o: r! O
private:
" n. C4 t2 B' m8 Z static bool DirectoryExists(const std::string& path) {" U, Y# d! f2 k) {, r$ P1 v
// 实现目录存在性检查9 C7 q' X, p; P q
struct stat info;
1 w9 h. F% V( k) l3 Q3 ^% u+ e) u! z( d. R return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);
5 h6 C7 q" p! {! s7 K( H/ C: O/ _8 P }
2 C& i6 M- l+ ~8 w f: R}; |
|