|
|
发表于 2025-11-4 08:38:23
|
显示全部楼层
class Config {6 ?9 f* M# E( |% o9 X! v2 T
public:
2 d/ l5 u+ I L7 m+ J static std::string GetSharePath() {4 t* @6 u3 V% w& N
// 优先检查 share 目录$ U% _: i) z7 d& P
if (DirectoryExists("./share/")) {
" Q. S$ Z0 g3 U return "./share/";5 o4 b) E! _. p: \
}, G+ R1 ~/ H( v& c# d' e
// 如果 share 目录不存在,使用当前目录
$ N; R E% \% O return "./";) e ?- V6 k8 _- M" }7 N ~
}. \+ R/ V( H; x, a! F1 U* x
( @6 N9 H+ x1 n# t% s
static std::string GetItemetcPath() {
- A. e; C4 h/ f* H8 t return GetSharePath() + "itemetc.csv";) e7 S- D, ~0 I0 |9 B
}; A3 w$ g- ~* Q" X
1 h! |. B. \5 k- m2 n* t static std::string GetItemarmorPath() {+ J+ a0 G" I" j$ r1 s
return GetSharePath() + "itemarmor.csv";
/ A# o& ], w. \8 }7 |$ m }
0 D/ j0 h1 G" D& ^/ c) Y
7 e- C* H* b t% E3 N4 K6 s! a static std::string GetItemweaponPath() {6 n! h( j q7 t, e" C* R
return GetSharePath() + "itemweapon.csv";, @) H# u& n' m0 k3 y$ S/ d
}
" g" E, e: F& \' }3 j0 ]+ z7 F7 K
7 o" B4 F% x% Y( a static std::string GetSkillnamePath() {
; D0 R. g G4 E+ [# h return GetSharePath() + "skillname.csv";
8 n% s% v# b' [- z7 @8 T }+ p- _& N& Z$ o; D
\5 v- e6 A) J1 ^, R: u) o
private:
" P+ l) R' Y$ F2 j( \# Y+ [ static bool DirectoryExists(const std::string& path) {
* L3 \$ C G+ @; \: M/ j // 实现目录存在性检查3 x6 K: ~9 v. Y. b& m. \6 W$ W; m
struct stat info;- `1 D! ]; g# c: g1 D' \! i
return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);. {# g B& b5 [) q% P4 W4 |
}
/ o0 A* g4 L" c& b6 u# `}; |
|