forked from Ariescyn/EldenRing-Save-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_layer.py
70 lines (55 loc) · 2.02 KB
/
os_layer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import platform
import sys
import subprocess
import shutil
import re
# main variables, directories and settings
config_path = "./data/config.json"
savedir = "./data/save-files/"
app_title = "Elden Ring Save Manager"
backupdir = "./data/backup/"
update_dir = "./data/updates/"
temp_dir = "./data/temp/"
post_update_file = "./data/post.update"
version = "v1.72"
v_num = 1.72 # Used for checking version for update
video_url = "https://youtu.be/LQxmFuq3dfg"
custom_search_tutorial_url = "https://youtu.be/li-ZiMXBmRk"
background_img = "./data/background.png"
icon_file = "./data/icon.ico"
bk_p = (-140, 20) # Background image position
is_windows = any(platform.win32_ver()) or hasattr(sys, "getwindowsversion")
def open_folder_standard_exporer(path):
"""Note: os.startfile is only avaiable on Win platform"""
if platform.system() == "Windows":
os.startfile(path.replace("/", "\\"))
else:
subprocess.Popen(["xdg-open", path])
def open_textfile_in_editor(path):
if is_windows:
subprocess.run(f"notepad {path}", shell=True, capture_output=True, text=True)
else:
subprocess.Popen(["xdg-open", path])
def force_close_process(process):
if is_windows:
comm = f"taskkill /IM {process} -F"
subprocess.run(comm, shell=True, capture_output=True, text=True)
else:
comm = f"pkill {process}"
os.system(comm)
def copy_folder(src, dest):
"""
if is_windows:
cmd = f"Xcopy {src} {dest} /E /H /C /I /Y".format(gamedir,savedir,lst_box_choice)
subprocess.run(comm, shell=True , capture_output=True, text=True)
else:
shutil.copytree(src, dest, dirs_exist_ok=True)
"""
shutil.copytree(src, dest, dirs_exist_ok=True)
def copy_file(src, dst):
shutil.copy(src, dst)
def delete_folder(folder):
if folder is None or not isinstance(folder, str) or len(folder) < 5:
raise Exception("UNSAFE FOLDER DELETE OPERATION. QUIT")
shutil.rmtree(folder)