|
|
class Config {& r) m& P. x. [( z
public:( k! X' ^ @: e q% D
static std::string GetSharePath() {
* o6 @' Z" A/ L- h H // 优先检查 share 目录
" A9 [2 b) I% y4 K& l2 V if (DirectoryExists("./share/")) {% c9 Q; t7 \5 n7 d
return "./share/";- t2 p' _2 Z1 K) O3 G0 t! A, I
}2 X* F2 p# Y- `/ ^
// 如果 share 目录不存在,使用当前目录
4 q& T; }- b" o3 [" `; d return "./";
3 r2 ]0 Q5 T L. W$ ?+ x4 \ }
% K$ U# K0 a7 b! n
. q5 b' E! D3 _9 Y, Z static std::string GetItemetcPath() {! J1 p& {" Z& u7 j! s
return GetSharePath() + "itemetc.csv";
! R0 w3 q4 q# q9 P' m. A* E, Y! _ }
. H) x% e5 O4 W- f' M# w, d/ r 8 W+ R; K$ j* q3 {4 @
static std::string GetItemarmorPath() {7 c" U: Z9 B& Y: a
return GetSharePath() + "itemarmor.csv";6 i: Q2 Y0 _; u; y. f; ?/ p
}
, N, d3 o. ?7 j' o' W& { % f9 t# ?% z ]9 Y! O
static std::string GetItemweaponPath() {, v' I+ \1 s2 ^
return GetSharePath() + "itemweapon.csv";
' @( y# M% r, n: Y4 O! s0 D }# S1 h8 W. x8 U- ~9 Q" Z
M( \* [, v7 H! i5 b
static std::string GetSkillnamePath() {
& P: c$ h( `; R \ return GetSharePath() + "skillname.csv";7 N, j8 Y3 ^" f. u
}8 y) [# T% r2 h6 m: `$ S
y* y! ?0 f8 T" q+ [private:- n8 `: t- p4 H
static bool DirectoryExists(const std::string& path) {7 o' j7 |3 u* T' ~$ k- E% Y
// 实现目录存在性检查
/ v" O* Y5 U( [. | k } struct stat info;, b( Z" X5 Q7 P+ T2 x1 {5 L7 b
return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);6 n+ b+ O) s% T1 A
}( W1 i6 l, e$ @) F5 S
}; |
|