Najeebsk

TOTAL-COMMANDS-DB.py

Apr 18th, 2026
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 46.37 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. NAJEEB TOTAL CMD COMMANDS V7.2 ULTIMATE - PATH EXECUTOR EDITION
  4. ✅ Fixed: Initialization Order Error
  5. ✅ Features: Edit Before Run | Copy | Browse Path | Execute from Any Directory
  6. ✅ Compatible: Windows 7 32-bit | Python 3.7.9 | BY NAJEEB SHAH KHAN
  7. """
  8.  
  9. import tkinter as tk
  10. from tkinter import ttk, messagebox, simpledialog, filedialog
  11. import subprocess
  12. import os
  13. import json
  14. import threading
  15. import ctypes
  16. import time
  17. import queue
  18. import sys
  19.  
  20. # Try import pyperclip for clipboard (optional fallback included)
  21. try:
  22.     import pyperclip
  23.     HAS_PYPERCLIP = True
  24. except ImportError:
  25.     HAS_PYPERCLIP = False
  26.  
  27. # 🔧 ADD THIS HERE 👇
  28. SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
  29. os.chdir(SCRIPT_DIR)
  30. print(f"[✅ FIXED] Script running from: {SCRIPT_DIR}")
  31. # --- Configuration ---
  32. FILE_NAME = "TOTAL-COMMANDS.db"
  33. FAV_FILE = "TOTAL-COMMANDS.json"
  34. CONFIG_FILE = "TOTAL-COMMANDS-CONFIG.json"
  35. VERSION = "7.2-FIXED"
  36.  
  37. # --- Safety List (Dangerous Commands) ---
  38. DANGEROUS_KEYWORDS = ["format", "del /s", "rmdir /s", "fdisk", "diskpart", "shutdown /r"]
  39.  
  40. # --- Quick Access Paths ---
  41. QUICK_PATHS = {
  42.     "C:": "C:\\",
  43.     "D:": "D:\\",
  44.     "Desktop": os.path.join(os.path.expanduser("~"), "Desktop"),
  45.     "Documents": os.path.join(os.path.expanduser("~"), "Documents"),
  46.     "Downloads": os.path.join(os.path.expanduser("~"), "Downloads"),
  47.     "Temp": os.getenv("TEMP", "C:\\Windows\\Temp"),
  48.     "System32": "C:\\Windows\\System32",
  49.     "Program Files": "C:\\Program Files",
  50. }
  51.  
  52.  
  53. # ============================================================================
  54. # ✅ ALL HELPER FUNCTIONS DEFINED FIRST (Before Class)
  55. # ============================================================================
  56.  
  57. def safe_clipboard_copy(text, root=None):
  58.     """Safely copy text to clipboard with fallback"""
  59.     if HAS_PYPERCLIP:
  60.         try:
  61.             pyperclip.copy(text)
  62.             return True
  63.         except:
  64.             pass
  65.     if root:
  66.         try:
  67.             root.clipboard_clear()
  68.             root.clipboard_append(text)
  69.             root.update()
  70.             return True
  71.         except:
  72.             pass
  73.     return False
  74.  
  75.  
  76. def validate_directory(path):
  77.     """Check if path is a valid directory"""
  78.     try:
  79.         return os.path.isdir(path)
  80.     except:
  81.         return False
  82.  
  83.  
  84. # ============================================================================
  85. # ✅ MAIN CLASS - METHODS IN LOGICAL ORDER
  86. # ============================================================================
  87.  
  88. class GodModeV7:
  89.    
  90.     # ==================== INITIALIZATION ====================
  91.     def __init__(self, root):
  92.         self.root = root
  93.         self.root.title(f"NAJEEB CMD COMMANDS RUNNER PRO MAX V{VERSION} | WIN7-32BIT-OPTIMIZED")
  94.         self.root.geometry("1250x750")
  95.         self.root.configure(bg="#1e1e1e")
  96.        
  97.         # Thread Safety Queue
  98.         self.log_queue = queue.Queue()
  99.        
  100.         # Data Structures
  101.         self.commands = {}
  102.         self.favorites = set()
  103.         self.config = {"geometry": "1250x750", "theme": "dark", "work_dir": ""}
  104.        
  105.         # Working Directory
  106.         #self.work_dir = tk.StringVar(value=os.getcwd())
  107.         self.work_dir = tk.StringVar(value=SCRIPT_DIR)
  108.        
  109.         # UI Elements (Initialize as None)
  110.         self.cat_listbox = None
  111.         self.cmd_listbox = None
  112.         self.console = None
  113.         self.notebook = None
  114.         self.path_entry = None
  115.         self.path_executor_entry = None
  116.         self.executor_cmd = None
  117.         self.executor_path_lbl = None
  118.         self.file_listbox = None
  119.         self.context_menu = None
  120.         self.search_var = None
  121.         self.path_var = None
  122.         self.path_status = None
  123.         self.status_var = None
  124.         self.sys_info_text = None
  125.         self.cpu_lbl = None
  126.         self.ram_lbl = None
  127.         self.proc_list = None
  128.        
  129.         # Load Config & Favorites FIRST (No UI needed)
  130.         self.load_config()
  131.         self.load_favorites()
  132.        
  133.         # Create UI SECOND
  134.         self.create_main_layout()
  135.         self.create_menu()
  136.        
  137.         # Load Commands THIRD (Now UI exists)
  138.         self.load_commands()
  139.        
  140.         # Start Monitor Loop
  141.         self.update_monitor()
  142.         self.process_log_queue()
  143.        
  144.         # Handle Close
  145.         self.root.protocol("WM_DELETE_WINDOW", self.on_close)
  146.        
  147.         # Log startup
  148.         self.log(f"NAJEEB CLI PRO MAX V{VERSION} Started!\n")
  149.  
  150.     # ==================== UI CREATION ====================
  151.    
  152.     def create_main_layout(self):
  153.         """Create main notebook and tabs"""
  154.         self.notebook = ttk.Notebook(self.root)
  155.         self.notebook.pack(fill="both", expand=True, padx=5, pady=5)
  156.        
  157.         # Tab 1: Command Center
  158.         self.tab_cmd = tk.Frame(self.notebook, bg="#1e1e1e")
  159.         self.notebook.add(self.tab_cmd, text="🚀 Command Center")
  160.         self.setup_command_tab()
  161.        
  162.         # Tab 2: System & Network
  163.         self.tab_sys = tk.Frame(self.notebook, bg="#1e1e1e")
  164.         self.notebook.add(self.tab_sys, text="🖥️ System & Network")
  165.         self.setup_system_tab()
  166.        
  167.         # Tab 3: Process Manager
  168.         self.tab_proc = tk.Frame(self.notebook, bg="#1e1e1e")
  169.         self.notebook.add(self.tab_proc, text="⚙️ Process Manager")
  170.         self.setup_process_tab()
  171.        
  172.         # Tab 4: Path Executor (NEW!)
  173.         self.tab_path = tk.Frame(self.notebook, bg="#1e1e1e")
  174.         self.notebook.add(self.tab_path, text="📁 Path Executor")
  175.         self.setup_path_tab()
  176.  
  177.     def setup_command_tab(self):
  178.         """Setup Command Center tab with path selector"""
  179.         # === PATH SELECTOR BAR ===
  180.         path_frame = tk.Frame(self.tab_cmd, bg="#252526")
  181.         path_frame.pack(fill="x", padx=5, pady=3)
  182.        
  183.         tk.Label(path_frame, text="📍 Work Dir:", bg="#252526", fg="#00ff00", font=("Consolas", 9)).pack(side="left", padx=5)
  184.        
  185.         self.path_entry = tk.Entry(path_frame, textvariable=self.work_dir, width=60, bg="#333", fg="white", insertbackground="white", font=("Consolas", 9))
  186.         self.path_entry.pack(side="left", padx=5)
  187.         self.path_entry.bind("<Return>", lambda e: self.validate_path())
  188.        
  189.         btn_browse = tk.Button(path_frame, text="🗂️ Browse", command=self.browse_path,
  190.                               bg="#007acc", fg="white", relief="flat", padx=8, pady=2, cursor="hand2")
  191.         btn_browse.pack(side="left", padx=2)
  192.        
  193.         self.path_var = tk.StringVar(value="Quick Paths ▼")
  194.         path_menu = tk.OptionMenu(path_frame, self.path_var, "Quick Paths ▼", *list(QUICK_PATHS.keys()), command=self.set_quick_path)
  195.         path_menu.config(bg="#2d2d2d", fg="white", activebackground="#007acc", activeforeground="white", relief="flat", cursor="hand2")
  196.         path_menu.pack(side="left", padx=5)
  197.        
  198.         tk.Button(path_frame, text="🔄 Reset", command=self.reset_path,
  199.                  bg="#555", fg="white", relief="flat", padx=8, pady=2, cursor="hand2").pack(side="left", padx=2)
  200.        
  201.         self.path_status = tk.Label(path_frame, text="✓ Valid", fg="lime", bg="#252526", font=("Consolas", 8))
  202.         self.path_status.pack(side="right", padx=10)
  203.        
  204.         # === TOP FRAME (Search & Actions) ===
  205.         top_frame = tk.Frame(self.tab_cmd, bg="#2d2d2d")
  206.         top_frame.pack(fill="x", padx=5, pady=5)
  207.        
  208.         self.search_var = tk.StringVar()
  209.         # ✅ FIX: Use lambda to avoid early binding issues
  210.         self.search_var.trace_add("write", lambda *args: self.search_command())
  211.        
  212.         tk.Entry(top_frame, textvariable=self.search_var, width=40, bg="#333", fg="white", insertbackground="white").pack(side="left", padx=5)
  213.        
  214.         btn_style = {"bg": "#007acc", "fg": "white", "relief": "flat", "padx": 10, "pady": 5, "cursor": "hand2"}
  215.        
  216.         tk.Button(top_frame, text="▶ Run", command=self.run_selected, **btn_style).pack(side="left", padx=2)
  217.         tk.Button(top_frame, text="✏️ Edit+Run", command=self.edit_and_run, **btn_style).pack(side="left", padx=2)
  218.         tk.Button(top_frame, text="⚡ Admin", command=self.run_admin_selected, **btn_style).pack(side="left", padx=2)
  219.         tk.Button(top_frame, text="⭐ Fav", command=self.toggle_fav, **btn_style).pack(side="left", padx=2)
  220.         tk.Button(top_frame, text="➕ Add", command=self.add_command, **btn_style).pack(side="left", padx=2)
  221.         tk.Button(top_frame, text="🗑️ Del", command=self.delete_command, **btn_style).pack(side="left", padx=2)
  222.         tk.Button(top_frame, text="📋 Batch", command=self.run_batch, **btn_style).pack(side="left", padx=2)
  223.  
  224.         # === MIDDLE SPLIT (Categories & List) ===
  225.         mid_pane = tk.PanedWindow(self.tab_cmd, orient="horizontal", bg="#1e1e1e")
  226.         mid_pane.pack(fill="both", expand=True, padx=5, pady=5)
  227.        
  228.         # Left: Categories
  229.         self.cat_listbox = tk.Listbox(mid_pane, bg="#252526", fg="#00ff00", selectbackground="#007acc", selectforeground="white", cursor="hand2")
  230.         mid_pane.add(self.cat_listbox, width=200)
  231.         self.cat_listbox.bind("<<ListboxSelect>>", self.on_category_select)
  232.        
  233.         # Right: Commands List
  234.         self.cmd_listbox = tk.Listbox(mid_pane, bg="#1e1e1e", fg="white", selectbackground="#007acc", selectforeground="white", font=("Consolas", 10), exportselection=False)
  235.         mid_pane.add(self.cmd_listbox)
  236.         self.cmd_listbox.bind("<Double-Button-1>", lambda e: self.edit_and_run())
  237.         self.cmd_listbox.bind("<Control-Button-1>", self.multi_select)
  238.         self.cmd_listbox.bind("<Button-3>", self.show_context_menu)
  239.        
  240.         # Context Menu
  241.         self._create_context_menu()
  242.        
  243.         # === BOTTOM: Console ===
  244.         console_frame = tk.Frame(self.tab_cmd, bg="black")
  245.         console_frame.pack(fill="x", padx=5, pady=5)
  246.        
  247.         self.console = tk.Text(console_frame, height=10, bg="black", fg="#00ff00", font=("Consolas", 9))
  248.         self.console.pack(side="left", fill="both", expand=True)
  249.        
  250.         scroll = tk.Scrollbar(console_frame, command=self.console.yview)
  251.         scroll.pack(side="right", fill="y")
  252.         self.console.config(yscrollcommand=scroll.set)
  253.        
  254.         con_ctrl = tk.Frame(self.tab_cmd, bg="#1e1e1e")
  255.         con_ctrl.pack(fill="x", padx=5)
  256.         tk.Button(con_ctrl, text="Clear Log", command=lambda: self.console.delete(1.0, tk.END), cursor="hand2").pack(side="left")
  257.         tk.Button(con_ctrl, text="Save Log", command=self.save_log, cursor="hand2").pack(side="left", padx=5)
  258.         tk.Button(con_ctrl, text="📋 Copy Log", command=self.copy_console, cursor="hand2").pack(side="left", padx=5)
  259.        
  260.         # Status Bar
  261.         self.status_var = tk.StringVar()
  262.         self.status_var.set("Ready | Work Dir: " + self.work_dir.get()[:40] + "...")
  263.         tk.Label(self.tab_cmd, textvariable=self.status_var, bg="#007acc", fg="white", anchor="w").pack(fill="x", side="bottom")
  264.  
  265.     def _create_context_menu(self):
  266.         """Create right-click context menu for command list"""
  267.         self.context_menu = tk.Menu(self.root, tearoff=0, bg="#2d2d2d", fg="white", activebackground="#007acc", activeforeground="white")
  268.         self.context_menu.add_command(label="✏️ Edit Command", command=self.edit_selected_command)
  269.         self.context_menu.add_command(label="📋 Copy to Clipboard", command=self.copy_selected_command)
  270.         self.context_menu.add_separator()
  271.         self.context_menu.add_command(label="▶ Run Normal", command=self.run_selected)
  272.         self.context_menu.add_command(label="⚡ Run as Admin", command=self.run_admin_selected)
  273.         self.context_menu.add_separator()
  274.         self.context_menu.add_command(label="⭐ Toggle Favorite", command=self.toggle_fav)
  275.         self.context_menu.add_command(label="🗑️ Delete Command", command=self.delete_command)
  276.  
  277.     def setup_path_tab(self):
  278.         """Setup Path Executor tab"""
  279.         # Path Input Section
  280.         path_input_frame = tk.LabelFrame(self.tab_path, text="📁 Select Execution Directory", bg="#2d2d2d", fg="white")
  281.         path_input_frame.pack(fill="x", padx=10, pady=10)
  282.        
  283.         tk.Label(path_input_frame, text="Directory Path:", bg="#2d2d2d", fg="#00ff00").grid(row=0, column=0, padx=5, pady=5, sticky="w")
  284.        
  285.         self.path_executor_entry = tk.Entry(path_input_frame, width=70, bg="#333", fg="white", insertbackground="white", font=("Consolas", 10))
  286.         self.path_executor_entry.grid(row=0, column=1, padx=5, pady=5)
  287.         self.path_executor_entry.insert(0, os.getcwd())
  288.        
  289.         tk.Button(path_input_frame, text="🗂️ Browse", command=self.browse_executor_path,
  290.                  bg="#007acc", fg="white", relief="flat", padx=15, cursor="hand2").grid(row=0, column=2, padx=5, pady=5)
  291.         tk.Button(path_input_frame, text="✓ Validate", command=self.validate_executor_path,
  292.                  bg="#28a745", fg="white", relief="flat", padx=10, cursor="hand2").grid(row=0, column=3, padx=5, pady=5)
  293.        
  294.         # Quick Paths Grid
  295.         quick_frame = tk.LabelFrame(self.tab_path, text="⚡ Quick Access Paths", bg="#2d2d2d", fg="white")
  296.         quick_frame.pack(fill="x", padx=10, pady=10)
  297.        
  298.         row, col = 0, 0
  299.         for name, path in QUICK_PATHS.items():
  300.             tk.Button(quick_frame, text=f"📁 {name}", command=lambda p=path: self.set_executor_path(p),
  301.                      bg="#3a3a3a", fg="cyan", relief="flat", padx=10, pady=3, cursor="hand2").grid(row=row, column=col, padx=3, pady=3)
  302.             col += 1
  303.             if col > 3:
  304.                 col = 0
  305.                 row += 1
  306.        
  307.         # Command Input Section
  308.         cmd_frame = tk.LabelFrame(self.tab_path, text="▶ Enter Command to Execute", bg="#2d2d2d", fg="white")
  309.         cmd_frame.pack(fill="both", expand=True, padx=10, pady=10)
  310.        
  311.         tk.Label(cmd_frame, text="Command:", bg="#2d2d2d", fg="#00ff00").pack(anchor="w", padx=5, pady=2)
  312.        
  313.         self.executor_cmd = tk.Text(cmd_frame, height=4, bg="#1e1e1e", fg="white", font=("Consolas", 10), insertbackground="white")
  314.         self.executor_cmd.pack(fill="x", padx=5, pady=5)
  315.        
  316.         exec_ctrl = tk.Frame(cmd_frame, bg="#2d2d2d")
  317.         exec_ctrl.pack(fill="x", padx=5, pady=5)
  318.        
  319.         tk.Button(exec_ctrl, text="▶ Run in Selected Dir", command=self.run_executor_command,
  320.                  bg="#007acc", fg="white", relief="flat", padx=20, pady=5, cursor="hand2").pack(side="left", padx=5)
  321.         tk.Button(exec_ctrl, text="⚡ Run as Admin", command=lambda: self.run_executor_command(admin=True),
  322.                  bg="#dc3545", fg="white", relief="flat", padx=20, pady=5, cursor="hand2").pack(side="left", padx=5)
  323.         tk.Button(exec_ctrl, text="📋 Copy Command", command=self.copy_executor_command,
  324.                  bg="#555", fg="white", relief="flat", padx=15, pady=5, cursor="hand2").pack(side="left", padx=5)
  325.         tk.Button(exec_ctrl, text="🗑️ Clear", command=lambda: self.executor_cmd.delete(1.0, tk.END),
  326.                  bg="#555", fg="white", relief="flat", padx=15, pady=5, cursor="hand2").pack(side="right", padx=5)
  327.        
  328.         tk.Label(cmd_frame, text="📊 Current Directory:", bg="#2d2d2d", fg="yellow").pack(anchor="w", padx=5, pady=2)
  329.         self.executor_path_lbl = tk.Label(cmd_frame, text=os.getcwd(), bg="#1e1e1e", fg="lime", font=("Consolas", 9), anchor="w")
  330.         self.executor_path_lbl.pack(fill="x", padx=5, pady=2)
  331.        
  332.         list_frame = tk.Frame(cmd_frame, bg="#2d2d2d")
  333.         list_frame.pack(fill="both", expand=True, padx=5, pady=10)
  334.        
  335.         tk.Label(list_frame, text="📄 Files in Directory:", bg="#2d2d2d", fg="cyan").pack(anchor="w")
  336.        
  337.         self.file_listbox = tk.Listbox(list_frame, bg="#1e1e1e", fg="white", font=("Consolas", 9))
  338.         self.file_listbox.pack(fill="both", expand=True, pady=5)
  339.        
  340.         tk.Button(list_frame, text="🔄 Refresh File List", command=self.refresh_file_list,
  341.                  bg="#555", fg="white", relief="flat", cursor="hand2").pack(pady=5)
  342.  
  343.     def setup_system_tab(self):
  344.         """Setup System & Network tab"""
  345.         info_frame = tk.LabelFrame(self.tab_sys, text="System Information", bg="#2d2d2d", fg="white")
  346.         info_frame.pack(fill="x", padx=10, pady=10)
  347.        
  348.         self.sys_info_text = tk.Text(info_frame, height=8, bg="#1e1e1e", fg="cyan")
  349.         self.sys_info_text.pack(fill="x", padx=5, pady=5)
  350.         self.refresh_sys_info()
  351.        
  352.         net_frame = tk.LabelFrame(self.tab_sys, text="Network Tools", bg="#2d2d2d", fg="white")
  353.         net_frame.pack(fill="both", expand=True, padx=10, pady=10)
  354.        
  355.         tk.Button(net_frame, text="📡 Get IP Config", command=self.get_ip_config, cursor="hand2").pack(side="left", padx=10, pady=10)
  356.         tk.Button(net_frame, text="📶 Ping Google", command=self.ping_google, cursor="hand2").pack(side="left", padx=10, pady=10)
  357.         tk.Button(net_frame, text="🌐 Flush DNS", command=self.flush_dns, cursor="hand2").pack(side="left", padx=10, pady=10)
  358.         tk.Button(net_frame, text="📋 Copy Output", command=self.copy_last_output, cursor="hand2").pack(side="left", padx=10, pady=10)
  359.        
  360.         self.cpu_lbl = tk.Label(self.tab_sys, text="CPU: 0%", fg="lime", bg="#1e1e1e", font=("Arial", 12, "bold"))
  361.         self.cpu_lbl.pack(side="left", padx=20)
  362.         self.ram_lbl = tk.Label(self.tab_sys, text="RAM: 0%", fg="yellow", bg="#1e1e1e", font=("Arial", 12, "bold"))
  363.         self.ram_lbl.pack(side="left", padx=20)
  364.  
  365.     def setup_process_tab(self):
  366.         """Setup Process Manager tab"""
  367.         tk.Label(self.tab_proc, text="Running Processes (Top 50)", bg="#2d2d2d", fg="white").pack(pady=5)
  368.        
  369.         self.proc_list = ttk.Treeview(self.tab_proc, columns=("Name", "PID", "CPU"), show="headings")
  370.         self.proc_list.heading("Name", text="Process Name")
  371.         self.proc_list.heading("PID", text="PID")
  372.         self.proc_list.heading("CPU", text="CPU %")
  373.         self.proc_list.pack(fill="both", expand=True, padx=10, pady=5)
  374.        
  375.         tk.Button(self.tab_proc, text="🔄 Refresh List", command=self.refresh_processes, cursor="hand2").pack(pady=5)
  376.         tk.Button(self.tab_proc, text="💀 Kill Selected", command=self.kill_process, bg="#cc3333", fg="white", cursor="hand2").pack(pady=5)
  377.  
  378.     def create_menu(self):
  379.         """Create main menu bar"""
  380.         menubar = tk.Menu(self.root)
  381.         self.root.config(menu=menubar)
  382.        
  383.         file_menu = tk.Menu(menubar, tearoff=0)
  384.         menubar.add_cascade(label="File", menu=file_menu)
  385.         file_menu.add_command(label="Export Commands", command=self.export_commands)
  386.         file_menu.add_command(label="Import Commands", command=self.import_commands)
  387.         file_menu.add_separator()
  388.         file_menu.add_command(label="Exit", command=self.on_close)
  389.        
  390.         edit_menu = tk.Menu(menubar, tearoff=0)
  391.         menubar.add_cascade(label="Edit", menu=edit_menu)
  392.         edit_menu.add_command(label="Edit Selected Command", command=self.edit_selected_command)
  393.         edit_menu.add_command(label="Copy Selected Command", command=self.copy_selected_command)
  394.        
  395.         path_menu = tk.Menu(menubar, tearoff=0)
  396.         menubar.add_cascade(label="Path", menu=path_menu)
  397.         path_menu.add_command(label="Set Working Directory", command=self.browse_path)
  398.         path_menu.add_command(label="Reset to Default", command=self.reset_path)
  399.         path_menu.add_separator()
  400.         for name, path in QUICK_PATHS.items():
  401.             path_menu.add_command(label=f"📁 {name}", command=lambda p=path: self.set_path(p))
  402.        
  403.         help_menu = tk.Menu(menubar, tearoff=0)
  404.         menubar.add_cascade(label="Help", menu=help_menu)
  405.         help_menu.add_command(label="About", command=self.show_about)
  406.         help_menu.add_command(label="Keyboard Shortcuts", command=self.show_shortcuts)
  407.  
  408.     # ==================== PATH MANAGEMENT ====================
  409.    
  410.     def browse_path(self):
  411.         """Browse and select folder for command execution"""
  412.         path = filedialog.askdirectory(title="Select Working Directory", initialdir=self.work_dir.get())
  413.         if path:
  414.             self.work_dir.set(path)
  415.             self.validate_path()
  416.             self.log(f"[PATH] Working directory: {path}\n")
  417.             self.update_status()
  418.  
  419.     def browse_executor_path(self):
  420.         """Browse path for Path Executor tab"""
  421.         path = filedialog.askdirectory(title="Select Execution Directory", initialdir=self.path_executor_entry.get())
  422.         if path:
  423.             self.path_executor_entry.delete(0, tk.END)
  424.             self.path_executor_entry.insert(0, path)
  425.             self.executor_path_lbl.config(text=path)
  426.             self.validate_executor_path()
  427.             self.refresh_file_list()
  428.  
  429.     def validate_path(self):
  430.         """Validate working directory path"""
  431.         path = self.work_dir.get().strip()
  432.         if validate_directory(path):
  433.             self.path_status.config(text="✓ Valid", fg="lime")
  434.             self.config["work_dir"] = path
  435.             self.save_config()
  436.             return True
  437.         else:
  438.             self.path_status.config(text="✗ Invalid", fg="red")
  439.             messagebox.showwarning("Invalid Path", f"Directory does not exist:\n{path}")
  440.             return False
  441.  
  442.     def validate_executor_path(self):
  443.         """Validate path in Path Executor tab"""
  444.         path = self.path_executor_entry.get().strip()
  445.         if validate_directory(path):
  446.             self.executor_path_lbl.config(text=path, fg="lime")
  447.             self.refresh_file_list()
  448.             self.log(f"[PATH-EXEC] Validated: {path}\n")
  449.             return True
  450.         else:
  451.             self.executor_path_lbl.config(text=path, fg="red")
  452.             messagebox.showwarning("Invalid Path", f"Directory does not exist:\n{path}")
  453.             return False
  454.  
  455.     def set_quick_path(self, selection):
  456.         """Set path from quick access dropdown"""
  457.         if selection and selection != "Quick Paths ▼" and selection in QUICK_PATHS:
  458.             path = QUICK_PATHS[selection]
  459.             self.work_dir.set(path)
  460.             self.validate_path()
  461.             self.log(f"[PATH] Quick path: {selection} → {path}\n")
  462.             self.path_var.set("Quick Paths ▼")
  463.             self.update_status()
  464.  
  465.     def set_path(self, path):
  466.         """Set working directory programmatically"""
  467.         self.work_dir.set(path)
  468.         self.validate_path()
  469.         self.update_status()
  470.  
  471.     def set_executor_path(self, path):
  472.         """Set path in Path Executor tab"""
  473.         self.path_executor_entry.delete(0, tk.END)
  474.         self.path_executor_entry.insert(0, path)
  475.         self.executor_path_lbl.config(text=path)
  476.         self.validate_executor_path()
  477.  
  478.     def reset_path(self):
  479.         """Reset working directory to default"""
  480.         default = os.getcwd()
  481.         self.work_dir.set(default)
  482.         self.validate_path()
  483.         self.log(f"[PATH] Reset to: {default}\n")
  484.         self.update_status()
  485.  
  486.     def update_status(self):
  487.         """Update status bar with current path"""
  488.         path = self.work_dir.get()
  489.         display = path if len(path) <= 50 else path[:47] + "..."
  490.         self.status_var.set(f"Ready | Work Dir: {display}")
  491.  
  492.     def refresh_file_list(self):
  493.         """List files in selected executor directory"""
  494.         self.file_listbox.delete(0, tk.END)
  495.         path = self.path_executor_entry.get().strip()
  496.         if not validate_directory(path):
  497.             self.file_listbox.insert(tk.END, "⚠️ Invalid directory")
  498.             return
  499.         try:
  500.             items = os.listdir(path)
  501.             for item in sorted(items):
  502.                 full_path = os.path.join(path, item)
  503.                 prefix = "📁 " if os.path.isdir(full_path) else "📄 "
  504.                 self.file_listbox.insert(tk.END, f"{prefix}{item}")
  505.         except PermissionError:
  506.             self.file_listbox.insert(tk.END, "⚠️ Access Denied")
  507.         except Exception as e:
  508.             self.file_listbox.insert(tk.END, f"Error: {e}")
  509.  
  510.     # ==================== PATH EXECUTOR ====================
  511.    
  512.     def run_executor_command(self, admin=False):
  513.         """Execute command from Path Executor tab"""
  514.         cmd = self.executor_cmd.get(1.0, tk.END).strip()
  515.         path = self.path_executor_entry.get().strip()
  516.        
  517.         if not cmd:
  518.             messagebox.showinfo("Info", "Please enter a command to execute.")
  519.             return
  520.         if not validate_directory(path):
  521.             if not messagebox.askyesno("Invalid Path", f"Directory does not exist:\n{path}\n\nRun anyway with default directory?"):
  522.                 return
  523.             path = None
  524.        
  525.         self.log(f"[EXEC-PATH] Directory: {path or 'DEFAULT'}\n")
  526.         self.log(f"[EXEC-CMD] {cmd}\n")
  527.        
  528.         if admin:
  529.             full_cmd = f'cd /d "{path}" && {cmd} && pause' if path else f'{cmd} && pause'
  530.             ctypes.windll.shell32.ShellExecuteW(None, "runas", "cmd.exe", f"/c {full_cmd}", None, 1)
  531.             self.log(f"[ADMIN] Launched in new window\n")
  532.         else:
  533.             self.run_thread(cmd, work_dir=path)
  534.  
  535.     def copy_executor_command(self):
  536.         """Copy command from Path Executor to clipboard"""
  537.         cmd = self.executor_cmd.get(1.0, tk.END).strip()
  538.         if cmd:
  539.             if safe_clipboard_copy(cmd, self.root):
  540.                 messagebox.showinfo("Copied", f"Command copied:\n{cmd}")
  541.             else:
  542.                 messagebox.showerror("Error", "Failed to copy to clipboard")
  543.  
  544.     # ==================== CONTEXT MENU & CLIPBOARD ====================
  545.    
  546.     def show_context_menu(self, event):
  547.         """Show right-click context menu"""
  548.         index = self.cmd_listbox.nearest(event.y)
  549.         self.cmd_listbox.selection_clear(0, tk.END)
  550.         self.cmd_listbox.selection_set(index)
  551.         self.cmd_listbox.activate(index)
  552.         try:
  553.             self.context_menu.tk_popup(event.x_root, event.y_root)
  554.         finally:
  555.             self.context_menu.grab_release()
  556.  
  557.     def edit_selected_command(self):
  558.         """Edit command in database"""
  559.         cmds = self.get_selected_commands_with_meta()
  560.         if not cmds:
  561.             messagebox.showinfo("Info", "Please select a command to edit.")
  562.             return
  563.         cat, original_cmd = cmds[0]
  564.         edited_cmd = simpledialog.askstring("✏️ Edit Command", f"Edit in '{cat}':", initialvalue=original_cmd, parent=self.root)
  565.         if edited_cmd and edited_cmd.strip():
  566.             edited_cmd = edited_cmd.strip()
  567.             if original_cmd in self.favorites and edited_cmd != original_cmd:
  568.                 self.favorites.remove(original_cmd)
  569.                 self.favorites.add(edited_cmd)
  570.                 self.save_favorites()
  571.             if cat in self.commands and original_cmd in self.commands[cat]:
  572.                 idx = self.commands[cat].index(original_cmd)
  573.                 self.commands[cat][idx] = edited_cmd
  574.                 self.save_commands()
  575.                 self.on_category_select()
  576.                 self.log(f"[EDITED] '{original_cmd}' → '{edited_cmd}'\n")
  577.                 messagebox.showinfo("Success", "Command updated!")
  578.  
  579.     def copy_selected_command(self):
  580.         """Copy selected command to clipboard"""
  581.         cmds = self.get_selected_commands()
  582.         if not cmds:
  583.             messagebox.showinfo("Info", "Please select a command to copy.")
  584.             return
  585.         cmd_text = cmds[0]
  586.         if safe_clipboard_copy(cmd_text, self.root):
  587.             self.log(f"[COPIED] '{cmd_text}'\n")
  588.             self.status_var.set(f"Copied: {cmd_text[:50]}...")
  589.             messagebox.showinfo("Copied!", cmd_text)
  590.         else:
  591.             messagebox.showerror("Error", "Failed to copy")
  592.  
  593.     def copy_console(self):
  594.         """Copy entire console to clipboard"""
  595.         if self.console is None: return
  596.         content = self.console.get(1.0, tk.END)
  597.         if safe_clipboard_copy(content, self.root):
  598.             messagebox.showinfo("Copied", "Console log copied!")
  599.         else:
  600.             messagebox.showerror("Error", "Failed to copy")
  601.  
  602.     def copy_last_output(self):
  603.         """Copy last output to clipboard"""
  604.         content = self.console.get(1.0, tk.END) if self.console else ""
  605.         if safe_clipboard_copy(content, self.root):
  606.             self.log("[COPIED] Output to clipboard\n")
  607.  
  608.     def edit_and_run(self):
  609.         """Edit command before running"""
  610.         cmds = self.get_selected_commands_with_meta()
  611.         if not cmds:
  612.             messagebox.showinfo("Info", "Please select a command.")
  613.             return
  614.         cat, original_cmd = cmds[0]
  615.         run_cmd = simpledialog.askstring("▶ Edit & Run", "Modify command:", initialvalue=original_cmd, parent=self.root)
  616.         if run_cmd is not None:
  617.             cmd_to_run = run_cmd.strip() if run_cmd.strip() else original_cmd
  618.             self.run_thread(cmd_to_run)
  619.  
  620.     # ==================== SELECTION HELPERS ====================
  621.    
  622.     def get_selected_commands_with_meta(self):
  623.         """Return (category, command) tuples for selected items"""
  624.         if self.cmd_listbox is None: return []
  625.         try:
  626.             indices = self.cmd_listbox.curselection()
  627.             if not indices:
  628.                 active = self.cmd_listbox.index(tk.ACTIVE)
  629.                 if active >= 0: indices = [active]
  630.                 else: return []
  631.             results = []
  632.             current_cat = None
  633.             if self.cat_listbox and self.cat_listbox.curselection():
  634.                 cat_idx = self.cat_listbox.curselection()[0]
  635.                 current_cat = self.cat_listbox.get(cat_idx)
  636.             for i in indices:
  637.                 val = self.cmd_listbox.get(i).strip()
  638.                 if val.startswith("⭐ "): val = val[3:]
  639.                 if current_cat:
  640.                     results.append((current_cat, val))
  641.                 else:
  642.                     for cat, cmds in self.commands.items():
  643.                         if val in cmds:
  644.                             results.append((cat, val))
  645.                             break
  646.             return results
  647.         except:
  648.             return []
  649.  
  650.     def get_selected_commands(self):
  651.         """Return command strings for selected items"""
  652.         if self.cmd_listbox is None: return []
  653.         try:
  654.             indices = self.cmd_listbox.curselection()
  655.             if not indices:
  656.                 active = self.cmd_listbox.index(tk.ACTIVE)
  657.                 if active >= 0: indices = [active]
  658.                 else: return []
  659.             cmds = []
  660.             for i in indices:
  661.                 val = self.cmd_listbox.get(i).strip()
  662.                 if val.startswith("⭐ "): val = val[3:]
  663.                 cmds.append(val)
  664.             return cmds
  665.         except:
  666.             return []
  667.  
  668.     # ==================== SEARCH FUNCTION (✅ DEFINED BEFORE USE) ====================
  669.    
  670.     def search_command(self):
  671.         """Filter commands based on search query - ✅ NOW PROPERLY DEFINED"""
  672.         if self.cmd_listbox is None:
  673.             return
  674.         query = self.search_var.get().lower()
  675.         self.cmd_listbox.delete(0, tk.END)
  676.        
  677.         if not query:
  678.             self.on_category_select()
  679.             return
  680.            
  681.         for cat, cmds in self.commands.items():
  682.             for cmd in cmds:
  683.                 if query in cmd.lower():
  684.                     prefix = "⭐ " if cmd in self.favorites else "   "
  685.                     self.cmd_listbox.insert(tk.END, f"{prefix}{cmd}")
  686.  
  687.     # ==================== COMMAND EXECUTION ====================
  688.    
  689.     def check_safety(self, cmd):
  690.         """Check for dangerous keywords"""
  691.         for key in DANGEROUS_KEYWORDS:
  692.             if key in cmd.lower():
  693.                 return messagebox.askyesno("⚠️ DANGER", f"Command contains '{key}'.\nRun anyway?", icon="warning")
  694.         return True
  695.  
  696.     def run_thread(self, cmd, is_admin=False, work_dir=None):
  697.         """Run command in background thread"""
  698.         def task():
  699.             try:
  700.                 if not self.check_safety(cmd):
  701.                     self.log_queue.put(f"[BLOCKED] Cancelled: {cmd}\n")
  702.                     return
  703.  
  704.                 exec_dir = work_dir if work_dir and validate_directory(work_dir) else self.work_dir.get()
  705.                 if not validate_directory(exec_dir):
  706.                     exec_dir = os.getcwd()
  707.                    
  708.                 timestamp = time.strftime("%H:%M:%S")
  709.                 self.log_queue.put(f"\n[{timestamp}] Dir: {exec_dir}\n[CMD] {cmd}\n{'='*60}\n")
  710.                
  711.                 if is_admin:
  712.                     full_cmd = f'cd /d "{exec_dir}" && {cmd} && pause'
  713.                     ctypes.windll.shell32.ShellExecuteW(None, "runas", "cmd.exe", f"/c {full_cmd}", None, 1)
  714.                     self.log_queue.put(f"[ADMIN] Launched\n")
  715.                 else:
  716.                     process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
  717.                                               text=True, encoding='oem', errors='ignore', cwd=exec_dir)
  718.                     for line in process.stdout:
  719.                         self.log_queue.put(line)
  720.                     process.wait()
  721.                     self.log_queue.put(f"\n[FINISHED] Exit: {process.returncode}\n")
  722.             except Exception as e:
  723.                 self.log_queue.put(f"[ERROR] {e}\n")
  724.        
  725.         threading.Thread(target=task, daemon=True).start()
  726.  
  727.     def run_selected(self):
  728.         """Run selected command(s)"""
  729.         cmds = self.get_selected_commands()
  730.         if not cmds:
  731.             messagebox.showinfo("Info", "Select a command to run.")
  732.             return
  733.         for cmd in cmds:
  734.             self.run_thread(cmd)
  735.  
  736.     def run_admin_selected(self):
  737.         """Run selected command as admin"""
  738.         cmds = self.get_selected_commands()
  739.         if not cmds:
  740.             messagebox.showinfo("Info", "Select a command.")
  741.             return
  742.         for cmd in cmds:
  743.             self.run_thread(cmd, is_admin=True)
  744.  
  745.     def run_batch(self):
  746.         """Run multiple commands"""
  747.         script = simpledialog.askstring("Batch Runner", "Commands (one per line):", parent=self.root)
  748.         if script:
  749.             for line in script.splitlines():
  750.                 if line.strip():
  751.                     self.run_thread(line.strip())
  752.  
  753.     def multi_select(self, event):
  754.         """Handle Ctrl+Click multi-select"""
  755.         pass
  756.  
  757.     def toggle_fav(self):
  758.         """Toggle favorite status"""
  759.         cmds = self.get_selected_commands()
  760.         if not cmds: return
  761.         cmd = cmds[0]
  762.         if cmd in self.favorites:
  763.             self.favorites.remove(cmd)
  764.         else:
  765.             self.favorites.add(cmd)
  766.         self.save_favorites()
  767.         self.on_category_select()
  768.  
  769.     def add_command(self):
  770.         """Add new command"""
  771.         cmd = simpledialog.askstring("Add Command", "Enter Command:", parent=self.root)
  772.         if cmd and cmd.strip():
  773.             cmd = cmd.strip()
  774.             cat = simpledialog.askstring("Category", "Enter Category:", parent=self.root) or "Custom"
  775.             if cat not in self.commands:
  776.                 self.commands[cat] = []
  777.                 if self.cat_listbox: self.cat_listbox.insert(tk.END, cat)
  778.             self.commands[cat].append(cmd)
  779.             self.save_commands()
  780.             self.on_category_select()
  781.  
  782.     def delete_command(self):
  783.         """Delete selected command"""
  784.         cmds = self.get_selected_commands()
  785.         if not cmds: return
  786.         cmd = cmds[0]
  787.         if messagebox.askyesno("Delete?", f"Delete:\n{cmd}"):
  788.             for c in self.commands:
  789.                 if cmd in self.commands[c]:
  790.                     self.commands[c].remove(cmd)
  791.             if cmd in self.favorites:
  792.                 self.favorites.remove(cmd)
  793.             self.save_commands()
  794.             self.save_favorites()
  795.             self.on_category_select()
  796.  
  797.     # ==================== DATA LOADING/SAVING ====================
  798.    
  799.     def load_commands(self):
  800.         """Load commands from database file"""
  801.         self.commands.clear()
  802.         if self.cat_listbox: self.cat_listbox.delete(0, tk.END)
  803.        
  804.         default_cats = []     #["System", "Network", "Files", "Custom"]
  805.        
  806.         if os.path.exists(FILE_NAME):
  807.             try:
  808.                 with open(FILE_NAME, "r", encoding="utf-8") as f:
  809.                     current_cat = "General"
  810.                     for line in f:
  811.                         line = line.strip()
  812.                         if line.startswith("[") and line.endswith("]"):
  813.                             current_cat = line[1:-1]
  814.                             if current_cat not in self.commands:
  815.                                 self.commands[current_cat] = []
  816.                         elif line:
  817.                             if current_cat not in self.commands:
  818.                                 self.commands[current_cat] = []
  819.                             self.commands[current_cat].append(line)
  820.             except Exception as e:
  821.                 self.log(f"Error loading DB: {e}\n")
  822.                 self.commands = {c: [] for c in default_cats}
  823.         else:
  824.             self.commands = {c: [] for c in default_cats}
  825.             self.save_commands()
  826.            
  827.         if self.cat_listbox:
  828.             for cat in sorted(self.commands.keys()):
  829.                 self.cat_listbox.insert(tk.END, cat)
  830.             if self.cat_listbox.size() > 0:
  831.                 self.cat_listbox.selection_set(0)
  832.                 self.on_category_select()
  833.  
  834.     def save_commands(self):
  835.         """Save commands to database file"""
  836.         try:
  837.             with open(FILE_NAME, "w", encoding="utf-8") as f:
  838.                 for cat, cmds in self.commands.items():
  839.                     f.write(f"[{cat}]\n")
  840.                     for cmd in cmds:
  841.                         f.write(f"{cmd}\n")
  842.         except Exception as e:
  843.             messagebox.showerror("Save Error", str(e))
  844.  
  845.     def on_category_select(self, event=None):
  846.         """Update command list when category changes"""
  847.         try:
  848.             if not self.cat_listbox or not self.cmd_listbox: return
  849.             idx = self.cat_listbox.curselection()[0]
  850.             cat = self.cat_listbox.get(idx)
  851.             self.cmd_listbox.delete(0, tk.END)
  852.             for cmd in self.commands.get(cat, []):
  853.                 prefix = "⭐ " if cmd in self.favorites else "   "
  854.                 self.cmd_listbox.insert(tk.END, f"{prefix}{cmd}")
  855.         except IndexError:
  856.             pass
  857.  
  858.     def load_favorites(self):
  859.         """Load favorites from JSON"""
  860.         if os.path.exists(FAV_FILE):
  861.             try:
  862.                 with open(FAV_FILE, "r") as f:
  863.                     self.favorites = set(json.load(f))
  864.             except:
  865.                 self.favorites = set()
  866.  
  867.     def save_favorites(self):
  868.         """Save favorites to JSON"""
  869.         try:
  870.             with open(FAV_FILE, "w") as f:
  871.                 json.dump(list(self.favorites), f)
  872.         except:
  873.             pass
  874.  
  875.     def load_config(self):
  876.         """Load config from JSON"""
  877.         if os.path.exists(CONFIG_FILE):
  878.             try:
  879.                 with open(CONFIG_FILE, "r") as f:
  880.                     self.config = json.load(f)
  881.                     if "geometry" in self.config:
  882.                         self.root.geometry(self.config["geometry"])
  883.                     if "work_dir" in self.config and validate_directory(self.config["work_dir"]):
  884.                         self.work_dir.set(self.config["work_dir"])
  885.             except:
  886.                 pass
  887.  
  888.     def save_config(self):
  889.         """Save config to JSON"""
  890.         self.config["geometry"] = self.root.geometry()
  891.         self.config["work_dir"] = self.work_dir.get()
  892.         try:
  893.             with open(CONFIG_FILE, "w") as f:
  894.                 json.dump(self.config, f)
  895.         except:
  896.             pass
  897.  
  898.     def export_commands(self):
  899.         """Export commands to JSON"""
  900.         file = filedialog.asksaveasfilename(defaultextension=".json", filetypes=[("JSON", "*.json")])
  901.         if file:
  902.             try:
  903.                 with open(file, "w", encoding="utf-8") as f:
  904.                     json.dump(self.commands, f, indent=4)
  905.                 messagebox.showinfo("Success", "Exported!")
  906.             except Exception as e:
  907.                 messagebox.showerror("Error", str(e))
  908.  
  909.     def import_commands(self):
  910.         """Import commands from JSON"""
  911.         file = filedialog.askopenfilename(filetypes=[("JSON", "*.json")])
  912.         if file:
  913.             try:
  914.                 with open(file, "r", encoding="utf-8") as f:
  915.                     data = json.load(f)
  916.                 count = 0
  917.                 for cat, cmds in data.items():
  918.                     if cat not in self.commands: self.commands[cat] = []
  919.                     for cmd in cmds:
  920.                         if cmd not in self.commands[cat]:
  921.                             self.commands[cat].append(cmd)
  922.                             count += 1
  923.                 self.save_commands()
  924.                 self.load_commands()
  925.                 messagebox.showinfo("Success", f"Imported {count} commands!")
  926.             except Exception as e:
  927.                 messagebox.showerror("Error", str(e))
  928.  
  929.     # ==================== SYSTEM MONITORING ====================
  930.    
  931.     def refresh_sys_info(self):
  932.         """Refresh system information display"""
  933.         try:
  934.             import psutil
  935.             info = f"OS: {os.name} | Python: {sys.version.split()[0]}\n"
  936.             info += f"Cores: {psutil.cpu_count(logical=False)} | Threads: {psutil.cpu_count(logical=True)}\n"
  937.             info += f"Boot: {time.ctime(psutil.boot_time())}"
  938.             self.sys_info_text.delete(1.0, tk.END)
  939.             self.sys_info_text.insert(tk.END, info)
  940.         except ImportError:
  941.             self.sys_info_text.insert(tk.END, "Install psutil: pip install psutil")
  942.         except Exception as e:
  943.             self.sys_info_text.insert(tk.END, f"Error: {e}")
  944.  
  945.     def update_monitor(self):
  946.         """Update CPU/RAM monitors"""
  947.         try:
  948.             import psutil
  949.             cpu = psutil.cpu_percent(interval=0.5)
  950.             ram = psutil.virtual_memory().percent
  951.             self.cpu_lbl.config(text=f"CPU: {cpu}%", fg="red" if cpu > 80 else "orange" if cpu > 50 else "lime")
  952.             self.ram_lbl.config(text=f"RAM: {ram}%", fg="red" if ram > 80 else "orange" if ram > 50 else "yellow")
  953.         except:
  954.             pass
  955.         self.root.after(2000, self.update_monitor)
  956.  
  957.     def refresh_processes(self):
  958.         """Refresh process list"""
  959.         for item in self.proc_list.get_children():
  960.             self.proc_list.delete(item)
  961.         try:
  962.             import psutil
  963.             procs = []
  964.             for p in psutil.process_iter(['pid', 'name', 'cpu_percent']):
  965.                 try:
  966.                     info = p.info
  967.                     if info['cpu_percent'] is None: info['cpu_percent'] = 0.0
  968.                     procs.append(info)
  969.                 except: pass
  970.             procs.sort(key=lambda x: x['cpu_percent'] or 0, reverse=True)
  971.             for p in procs[:50]:
  972.                 self.proc_list.insert("", "end", values=(p['name'] or "Unknown", p['pid'], f"{p['cpu_percent'] or 0:.1f}%"))
  973.         except ImportError:
  974.             messagebox.showinfo("Info", "Install psutil: pip install psutil")
  975.         except Exception as e:
  976.             messagebox.showerror("Error", str(e))
  977.  
  978.     def kill_process(self):
  979.         """Kill selected process"""
  980.         selected = self.proc_list.selection()
  981.         if not selected: return
  982.         item = self.proc_list.item(selected[0])
  983.         pid = item['values'][1]
  984.         if messagebox.askyesno("Kill?", f"Kill PID {pid}?"):
  985.             try:
  986.                 subprocess.call(f"taskkill /PID {pid} /F", shell=True)
  987.                 self.refresh_processes()
  988.             except Exception as e:
  989.                 messagebox.showerror("Error", str(e))
  990.  
  991.     def get_ip_config(self): self.run_thread("ipconfig /all")
  992.     def ping_google(self): self.run_thread("ping google.com -n 4")
  993.     def flush_dns(self): self.run_thread("ipconfig /flushdns")
  994.  
  995.     # ==================== UTILITIES ====================
  996.    
  997.     def log(self, message):
  998.         """Add message to log queue"""
  999.         self.log_queue.put(message)
  1000.  
  1001.     def process_log_queue(self):
  1002.         """Process log queue and update console"""
  1003.         try:
  1004.             while True:
  1005.                 msg = self.log_queue.get_nowait()
  1006.                 if self.console:
  1007.                     self.console.insert(tk.END, msg)
  1008.                     self.console.see(tk.END)
  1009.         except queue.Empty:
  1010.             pass
  1011.         self.root.after(100, self.process_log_queue)
  1012.  
  1013.     def save_log(self):
  1014.         """Save console log to file"""
  1015.         if not self.console: return
  1016.         file = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text", "*.txt")])
  1017.         if file:
  1018.             try:
  1019.                 with open(file, "w", encoding="utf-8") as f:
  1020.                     f.write(self.console.get(1.0, tk.END))
  1021.             except Exception as e:
  1022.                 messagebox.showerror("Error", str(e))
  1023.  
  1024.     def show_about(self):
  1025.         """Show about dialog"""
  1026.         messagebox.showinfo("About", f"NAJEEB CLI PRO MAX V{VERSION}\nWin7-32Bit | Python 3.7.9\n\nUse responsibly! ⚠️")
  1027.  
  1028.     def show_shortcuts(self):
  1029.         """Show keyboard shortcuts"""
  1030.         messagebox.showinfo("Shortcuts", "Ctrl+E: Edit | Ctrl+C: Copy | Ctrl+B: Browse Path | Enter: Run")
  1031.  
  1032.     def on_close(self):
  1033.         """Handle window close"""
  1034.         self.save_config()
  1035.         if messagebox.askyesno("Exit", "Save and exit?"):
  1036.             self.root.destroy()
  1037.  
  1038.  
  1039. # ==================== KEYBOARD SHORTCUTS ====================
  1040. def bind_shortcuts(app):
  1041.     app.root.bind("<Control-e>", lambda e: app.edit_selected_command())
  1042.     app.root.bind("<Control-c>", lambda e: app.copy_selected_command())
  1043.     app.root.bind("<Control-b>", lambda e: app.browse_path())
  1044.     app.root.bind("<Control-f>", lambda e: app.search_var.entrywidget.focus_set() if app.search_var else None)
  1045.     app.root.bind("<Return>", lambda e: app.run_selected())
  1046.  
  1047. # ==================== MAIN ENTRY POINT ====================
  1048. if __name__ == "__main__":
  1049.     # High DPI Fix
  1050.     try:
  1051.         ctypes.windll.shcore.SetProcessDpiAwareness(1)
  1052.     except:
  1053.         pass
  1054.    
  1055.     root = tk.Tk()
  1056.     try:
  1057.         root.iconbitmap(default='')
  1058.     except:
  1059.         pass
  1060.    
  1061.     app = GodModeV7(root)
  1062.     bind_shortcuts(app)
  1063.    
  1064.     app.log("✅ Ready | Right-click commands for options\n")
  1065.     app.log("💡 Use Path Executor tab for custom directories\n\n")
  1066.    
  1067.     root.mainloop()
  1068.  
Add Comment
Please, Sign In to add comment