Fix Backslash in config cauded path reading failure
This commit is contained in:
parent
b590b17225
commit
9a788e5484
30
Setup.py
30
Setup.py
@ -65,6 +65,13 @@ def save_env_file(env_data):
|
|||||||
|
|
||||||
def load_current_config():
|
def load_current_config():
|
||||||
"""Extract settings from existing config.py if it exists"""
|
"""Extract settings from existing config.py if it exists"""
|
||||||
|
# 新增一個幫助函數來標準化路徑
|
||||||
|
def normalize_path(path):
|
||||||
|
"""Convert backslashes to forward slashes in paths"""
|
||||||
|
if path:
|
||||||
|
return path.replace("\\", "/")
|
||||||
|
return path
|
||||||
|
|
||||||
config_data = {
|
config_data = {
|
||||||
"OPENAI_API_BASE_URL": "",
|
"OPENAI_API_BASE_URL": "",
|
||||||
"LLM_MODEL": "deepseek/deepseek-chat-v3-0324",
|
"LLM_MODEL": "deepseek/deepseek-chat-v3-0324",
|
||||||
@ -72,7 +79,7 @@ def load_current_config():
|
|||||||
"exa": {
|
"exa": {
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
"use_smithery": False,
|
"use_smithery": False,
|
||||||
"server_path": f"C:/Users/{CURRENT_USERNAME}/AppData/Roaming/npm/exa-mcp-server"
|
"server_path": normalize_path(f"C:/Users/{CURRENT_USERNAME}/AppData/Roaming/npm/exa-mcp-server")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ENABLE_CHAT_LOGGING": True,
|
"ENABLE_CHAT_LOGGING": True,
|
||||||
@ -81,7 +88,7 @@ def load_current_config():
|
|||||||
"WINDOW_TITLE": "Last War-Survival Game",
|
"WINDOW_TITLE": "Last War-Survival Game",
|
||||||
"ENABLE_SCHEDULED_RESTART": True,
|
"ENABLE_SCHEDULED_RESTART": True,
|
||||||
"RESTART_INTERVAL_MINUTES": 60,
|
"RESTART_INTERVAL_MINUTES": 60,
|
||||||
"GAME_EXECUTABLE_PATH": fr"C:\Users\{CURRENT_USERNAME}\AppData\Local\TheLastWar\Launch.exe",
|
"GAME_EXECUTABLE_PATH": normalize_path(fr"C:\Users\{CURRENT_USERNAME}\AppData\Local\TheLastWar\Launch.exe"),
|
||||||
"GAME_WINDOW_X": 50,
|
"GAME_WINDOW_X": 50,
|
||||||
"GAME_WINDOW_Y": 30,
|
"GAME_WINDOW_Y": 30,
|
||||||
"GAME_WINDOW_WIDTH": 600,
|
"GAME_WINDOW_WIDTH": 600,
|
||||||
@ -217,6 +224,12 @@ def generate_config_file(config_data, env_data):
|
|||||||
shutil.copy2("config.py", backup_path)
|
shutil.copy2("config.py", backup_path)
|
||||||
print(f"Created backup of existing config at {backup_path}")
|
print(f"Created backup of existing config at {backup_path}")
|
||||||
|
|
||||||
|
def normalize_path(path):
|
||||||
|
"""Convert backslashes to forward slashes in paths"""
|
||||||
|
if path:
|
||||||
|
return path.replace("\\", "/")
|
||||||
|
return path
|
||||||
|
|
||||||
# Helper function to ensure absolute path
|
# Helper function to ensure absolute path
|
||||||
def ensure_absolute_path(path):
|
def ensure_absolute_path(path):
|
||||||
if not os.path.isabs(path):
|
if not os.path.isabs(path):
|
||||||
@ -955,7 +968,9 @@ class WolfChatSetup(tk.Tk):
|
|||||||
initialdir=os.path.expanduser("~")
|
initialdir=os.path.expanduser("~")
|
||||||
)
|
)
|
||||||
if file_path:
|
if file_path:
|
||||||
self.exa_path_var.set(file_path)
|
# 標準化路徑格式(將反斜線改為正斜線)
|
||||||
|
normalized_path = file_path.replace("\\", "/")
|
||||||
|
self.exa_path_var.set(normalized_path)
|
||||||
|
|
||||||
def browse_chroma_dir(self):
|
def browse_chroma_dir(self):
|
||||||
"""Browse for Chroma data directory"""
|
"""Browse for Chroma data directory"""
|
||||||
@ -964,8 +979,9 @@ class WolfChatSetup(tk.Tk):
|
|||||||
initialdir=os.path.dirname(DEFAULT_CHROMA_DATA_PATH)
|
initialdir=os.path.dirname(DEFAULT_CHROMA_DATA_PATH)
|
||||||
)
|
)
|
||||||
if dir_path:
|
if dir_path:
|
||||||
# Always store as absolute path
|
# 標準化路徑格式(將反斜線改為正斜線)
|
||||||
self.chroma_dir_var.set(os.path.abspath(dir_path))
|
normalized_path = os.path.abspath(dir_path).replace("\\", "/")
|
||||||
|
self.chroma_dir_var.set(normalized_path)
|
||||||
|
|
||||||
def browse_game_path(self):
|
def browse_game_path(self):
|
||||||
"""Browse for game executable"""
|
"""Browse for game executable"""
|
||||||
@ -975,7 +991,9 @@ class WolfChatSetup(tk.Tk):
|
|||||||
initialdir=os.path.expanduser("~")
|
initialdir=os.path.expanduser("~")
|
||||||
)
|
)
|
||||||
if file_path:
|
if file_path:
|
||||||
self.game_path_var.set(file_path)
|
# 標準化路徑格式(將反斜線改為正斜線)
|
||||||
|
normalized_path = file_path.replace("\\", "/")
|
||||||
|
self.game_path_var.set(normalized_path)
|
||||||
|
|
||||||
def update_servers_list(self):
|
def update_servers_list(self):
|
||||||
"""Update the servers listbox with current servers"""
|
"""Update the servers listbox with current servers"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user