Skip to content

Commit

Permalink
Merge pull request #696 from Guovin/dev
Browse files Browse the repository at this point in the history
chore:tkinter config
  • Loading branch information
Guovin authored Dec 17, 2024
2 parents a113832 + c6c5b19 commit e833486
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 38 deletions.
11 changes: 7 additions & 4 deletions tkinter_ui/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import utils.constants as constants
from utils.config import config
from utils.tools import resource_path


class DefaultUI:
Expand Down Expand Up @@ -438,12 +439,14 @@ def update_ipv_type(self, event):
config.set("Settings", "ipv_type", self.ipv_type_combo.get())

def edit_whitelist_file(self):
if os.path.exists(constants.whitelist_path):
os.system(f'notepad.exe {constants.whitelist_path}')
path = resource_path(constants.whitelist_path)
if os.path.exists(path):
os.system(f'notepad.exe {path}')

def edit_blacklist_file(self):
if os.path.exists(constants.blacklist_path):
os.system(f'notepad.exe {constants.blacklist_path}')
path = resource_path(constants.blacklist_path)
if os.path.exists(path):
os.system(f'notepad.exe {path}')

def change_entry_state(self, state):
for entry in [
Expand Down
6 changes: 4 additions & 2 deletions tkinter_ui/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import utils.constants as constants
from utils.config import config
from utils.tools import resource_path


class SubscribeUI:
Expand Down Expand Up @@ -51,8 +52,9 @@ def update_open_subscribe(self):
config.set("Settings", "open_subscribe", str(self.open_subscribe_var.get()))

def edit_subscribe_file(self):
if os.path.exists(constants.subscribe_path):
os.system(f'notepad.exe {constants.subscribe_path}')
path = resource_path(constants.subscribe_path)
if os.path.exists(path):
os.system(f'notepad.exe {path}')

def change_entry_state(self, state):
for entry in [
Expand Down
1 change: 1 addition & 0 deletions tkinter_ui/tkinter_ui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ a = Analysis(
('../config/config.ini', 'config'),
('../config/demo.txt', 'config'),
('../config/whitelist.txt', 'config'),
('../config/blacklist.txt', 'config'),
('../config/subscribe.txt', 'config'),
('../config/rtp', 'config/rtp'),
('../updates/hotel/cache.pkl', 'updates/hotel'),
Expand Down
39 changes: 7 additions & 32 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,43 +339,18 @@ def copy(self):
"""
Copy config files to current directory
"""
user_source_file = resource_path(
self.config.get("Settings", "source_file", fallback="config/demo.txt")
)
user_config_path = resource_path("config/user_config.ini")
default_config_path = resource_path("config/config.ini")
user_config_file = (
user_config_path
if os.path.exists(user_config_path)
else default_config_path
)
dest_folder = os.path.join(os.getcwd(), "config")
files_to_copy = [user_source_file, user_config_file]
try:
if os.path.exists(dest_folder):
if not os.path.isdir(dest_folder):
os.remove(dest_folder)
src_dir = resource_path("config")
if os.path.exists(src_dir):
if not os.path.exists(dest_folder):
os.makedirs(dest_folder, exist_ok=True)
else:
os.makedirs(dest_folder, exist_ok=True)
for src_file in files_to_copy:
dest_path = os.path.join(dest_folder, os.path.basename(src_file))
if os.path.abspath(src_file) == os.path.abspath(
dest_path
) or os.path.exists(dest_path):
continue
shutil.copy(src_file, dest_folder)
src_rtp_dir = resource_path("config/rtp")
dest_rtp_dir = os.path.join(dest_folder, "rtp")
if os.path.exists(src_rtp_dir):
if not os.path.exists(dest_rtp_dir):
os.makedirs(dest_rtp_dir, exist_ok=True)

for root, _, files in os.walk(src_rtp_dir):

for root, _, files in os.walk(src_dir):
for file in files:
src_file_path = os.path.join(root, file)
relative_path = os.path.relpath(src_file_path, src_rtp_dir)
dest_file_path = os.path.join(dest_rtp_dir, relative_path)
relative_path = os.path.relpath(src_file_path, src_dir)
dest_file_path = os.path.join(dest_folder, relative_path)

dest_file_dir = os.path.dirname(dest_file_path)
if not os.path.exists(dest_file_dir):
Expand Down

0 comments on commit e833486

Please sign in to comment.