Skip to content

Commit 3c8c22b

Browse files
committed
Some performance improvements
1 parent a2ce712 commit 3c8c22b

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

main.pyw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import tkinter as tk, subprocess, shutil, custom_ui, tktooltip, strings
1+
import tkinter as tk, shutil, custom_ui, tktooltip, strings
22
from tkinter import ttk, filedialog
33
from dialogs import separator_wizard, customize_shortcut, about, change_language, change_theme
44
from utils import preferences
@@ -10,7 +10,7 @@ window.configure(padx = preferences.get_scaled_value(14), pady = preferences.get
1010

1111
shortcut_type = tk.StringVar(value = "file")
1212

13-
subprocess.call(f"rmdir /q /s \"{preferences.working_folder}\\separators\"", shell = True)
13+
shutil.rmtree(preferences.working_folder + "\\separators")
1414
shutil.copytree(preferences.internal + "separators", preferences.working_folder + "\\separators")
1515

1616

utils/shortcut.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import random, win32com.client, subprocess, ctypes, os, strings
1+
import random, win32com.client, ctypes, os, strings, shutil
22
import os, ctypes
33
from utils import preferences
44

55

66
def create_separator_shortcut(icon: str):
77
delete_remnants()
8-
98
random_number = random.randint(1000000000, 9999999999)
109

11-
subprocess.call(f"md \"{preferences.working_folder}\\shortcuts\\", shell = True)
10+
if not os.path.exists(preferences.working_folder + "\\shortcuts"):
11+
os.mkdir(preferences.working_folder + "\\shortcuts")
12+
1213
open(preferences.working_folder + f"\\shortcuts\\separator_shortcut_{random_number}.vbs", "w", encoding = "utf8").write("")
1314

1415
shell = win32com.client.Dispatch("WScript.Shell")
@@ -30,7 +31,9 @@ def create_file_shortcut(file_path, name: str, icon_path: str, icon_index: int =
3031
file_name = path_list[len(path_list) - 1]
3132
random_number_2 = str(random.randint(1000, 9999))
3233

33-
subprocess.call(f"md \"{preferences.working_folder}\\shortcuts\\", shell = True)
34+
if not os.path.exists(preferences.working_folder + "\\shortcuts"):
35+
os.mkdir(preferences.working_folder + "\\shortcuts")
36+
3437
open(preferences.working_folder + f"\\shortcuts\\file_shortcut_{random_number}.bat", "w", encoding = "utf8").write(f"chcp 65001 > nul\ncd \"{(file_path + random_number_2).replace(file_name + random_number_2, '')}\"\n\"{file_path}\"")
3538
open(preferences.working_folder + f"\\shortcuts\\file_shortcut_{random_number}.vbs", "w", encoding = "utf8").write(preferences.script_template_2.replace("(command)", f"\"\"{preferences.working_folder}\\shortcuts\\file_shortcut_{random_number}.bat\"\""))
3639

@@ -52,7 +55,9 @@ def create_folder_shortcut(folder_path: str, name: str, icon_path: str, icon_ind
5255
random_number = random.randint(1000000000, 9999999999)
5356
folder_path = folder_path.replace('/', '\\')
5457

55-
subprocess.call(f"md \"{preferences.working_folder}\\shortcuts\\", shell = True)
58+
if not os.path.exists(preferences.working_folder + "\\shortcuts"):
59+
os.mkdir(preferences.working_folder + "\\shortcuts")
60+
5661
open(preferences.working_folder + f"\\shortcuts\\folder_shortcut_{random_number}.bat", "w", encoding = "utf8").write(f"chcp 65001 > nul\nexplorer \"{folder_path}\"")
5762
open(preferences.working_folder + f"\\shortcuts\\folder_shortcut_{random_number}.vbs", "w", encoding = "utf8").write(preferences.script_template_2.replace("(command)", f"\"\"{preferences.working_folder}\\shortcuts\\folder_shortcut_{random_number}.bat\"\""))
5863

@@ -69,12 +74,13 @@ def create_folder_shortcut(folder_path: str, name: str, icon_path: str, icon_ind
6974

7075

7176
def delete_remnants():
72-
subprocess.call(f"rmdir /q /s \"{preferences.working_folder}\\shortcut\"", shell = True)
73-
subprocess.call(f"mkdir \"{preferences.working_folder}\\shortcut\"", shell = True)
77+
if not os.path.exists(preferences.working_folder + "\\shortcut"):
78+
shutil.rmtree(preferences.working_folder + "\\shortcut")
79+
os.mkdir(preferences.working_folder + "\\shortcut")
7480

7581

7682
def post_create_shortcut():
77-
subprocess.call(f"explorer \"{preferences.working_folder}shortcut\"", shell = True)
83+
os.startfile(preferences.working_folder + "shortcut")
7884

7985
ctypes.windll.user32.MessageBoxW(
8086
None,
@@ -85,7 +91,7 @@ def post_create_shortcut():
8591

8692

8793
def get_folder_icon(folder_path: str) -> str:
88-
folder_config = subprocess.getoutput(f"type \"{folder_path}\\desktop.ini\"").split("\n")
94+
folder_config = open(folder_path + "\\desktop.ini", "r").read().split("\n")
8995
folder_icon = ("C:\\Windows\\System32\\shell32.dll", 4)
9096

9197
for line in folder_config:

0 commit comments

Comments
 (0)