|
|
发表于 2025-11-4 08:38:23
|
显示全部楼层
class Config {
: F7 H6 o7 p. W+ C7 t" Tpublic:
) U. i6 p/ K" T+ g1 w/ _& u static std::string GetSharePath() {
$ c! ?3 o5 h6 P* N6 @% t1 C // 优先检查 share 目录
4 g3 h& h6 u0 @; x6 m% [5 c if (DirectoryExists("./share/")) {
5 t, p6 {/ @4 L; Z' l) L return "./share/";0 h) N9 d# t6 m* F( v
}
( L3 N w; V, y! ]6 b0 I, s // 如果 share 目录不存在,使用当前目录' k; w- q0 K' I3 H( Q+ E
return "./";; \2 F( u# S+ f& f* ^) n
}
# E& b/ C% p- n, Z0 ?% P
* Q6 W0 X( E; O9 N static std::string GetItemetcPath() {+ |4 c& T9 G& |+ F
return GetSharePath() + "itemetc.csv";7 x0 S" g8 V6 S9 M2 z0 h, ?5 i) Y, T0 P
}
! R" Q( }1 N& ^2 v* S2 N
- v# X8 b: \# E+ n" y* @ ?& { static std::string GetItemarmorPath() {% A: T9 Y$ T* V: k4 }/ v5 l
return GetSharePath() + "itemarmor.csv";
: J! ~1 j: P4 ]& V( p; O. \) n0 t }
' r8 U& |% Y; }; \3 M: m& P5 e + ^9 \7 s! q6 x! J
static std::string GetItemweaponPath() {" {# s1 s7 e [, Y& Y( [" \
return GetSharePath() + "itemweapon.csv";
2 \' z$ E! n4 I8 B }
: m; k. g& @6 H& ` {" o) Z+ x; A0 j s% k8 b
static std::string GetSkillnamePath() {
0 z6 T5 d) D' ]8 S8 x3 l- a return GetSharePath() + "skillname.csv";. A* k3 |* a: M1 u8 E& ?6 T# t; ~
}6 R) I6 s+ N2 C! x+ ~
. l3 Y! J* g" r) R' V( U4 h8 b$ _
private:
+ q% J* Z# z7 r0 ~- m& b, ^ static bool DirectoryExists(const std::string& path) {
( ~" Y( C E- N5 Y // 实现目录存在性检查
3 m( e7 A9 j' ?3 X! ^ struct stat info;
$ b7 J' J9 H# u. _5 j return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFDIR);2 O4 u% Z6 A' Q3 v1 Y$ x4 L7 X
}3 K$ e$ P' f7 ]+ l$ P# W
}; |
|