diff --git a/README.md b/README.md index e8f82d9..b846759 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,11 @@ Features: # Download: [![Latest](https://img.shields.io/github/v/tag/MBQbUtils/BulkStartStop?sort=date&label=&style=for-the-badge&color=424242)](https://github.com/MBQbUtils/BulkStartStop/releases/latest/download/BulkStartStop_portable.zip) ## Theme used: [forest-dark](https://github.com/rdbende/Forest-ttk-theme) with minor changes ## Main lib used: [WinJobster](https://github.com/SemperSolus0x3d/WinJobster) with minor changes + +# Multiple configs and rules lists +Path to config can be configured with `-c`/`--config` params on start +```cmd +BulkStartStop.exe --config path/to/config.json +``` + +Path to rules list file can be set with config. \ No newline at end of file diff --git a/WinJobster/WinJobsterLoader.py b/WinJobster/WinJobsterLoader.py index f872f03..c2acc6f 100644 --- a/WinJobster/WinJobsterLoader.py +++ b/WinJobster/WinJobsterLoader.py @@ -9,7 +9,6 @@ def load(self) -> c.WinDLL: dll_path = pathlib.Path(__file__).parent architecture = 64 if platform.architecture()[0] == '64bit' else 86 dll_path = str(dll_path.joinpath(f'WinJobster-x{architecture}.dll').absolute()) - print(dll_path) lib = c.WinDLL(dll_path) lib.StartProcess.restype = c.c_uint32 lib.StartProcess.errcheck = WinJobsterLoader._errcheck diff --git a/main.py b/main.py index f948032..5e1b3b0 100644 --- a/main.py +++ b/main.py @@ -3,10 +3,12 @@ import os.path import re import shlex +import sys import tkinter as tk import tkinter.filedialog import tkinter.ttk as ttk import winreg +import argparse from WinJobster import Process import jsons @@ -20,6 +22,7 @@ def __init__(self, filename: str = 'apps_to_manage.txt'): def load(self): try: + mkdir(self.filename) with open(self.filename, 'r', encoding='utf-8-sig') as file: self._paths = {path.strip() for path in file.readlines() if path} except OSError: @@ -46,6 +49,13 @@ def paths(self, value: set[str]): class Config: run_all_at_startup: bool = False kill_all_on_close: bool = False + rules_path: str = 'apps_to_manage.txt' + + +def mkdir(path): + dirname = os.path.dirname(path) + if dirname and not (os.path.exists(dirname) and os.path.isdir(dirname)): + os.mkdir(dirname) class ConfigStorage: @@ -55,6 +65,7 @@ def __init__(self, filename: str = 'config.json'): def load(self): try: + mkdir(self.filename) with open(self.filename, 'r', encoding='utf-8-sig') as file: self.config = jsons.loads(file.read(), Config) except OSError: @@ -125,10 +136,10 @@ def toggle(self): class Model: - def __init__(self): - self._paths_storage = PathsStorage() - self._config_storage = ConfigStorage() + def __init__(self, args): + self._config_storage = ConfigStorage(args.config) self._config_storage.load() + self._paths_storage = PathsStorage(self.settings.rules_path) self.paths: list = list(self._paths_storage.paths) self._processes = {path: ProcessModel(path) for path in self.paths} @@ -338,12 +349,12 @@ def set_kill_on_close(self, value: bool): class App(tk.Tk): - def __init__(self): + def __init__(self, args): super().__init__() self.title('Apps bulk start/stop') self.geometry('640x480') self.apply_theme() - model = Model() + model = Model(args) view = View(self) view.pack(fill=tk.X, padx=8, pady=8) controller = Controller(model, view) @@ -358,8 +369,15 @@ def apply_theme(self): style.theme_use('forest-dark') +def get_args(): + parser = argparse.ArgumentParser(add_help=False) + parser.add_argument('--config', '-c', default='config.json') + return parser.parse_args(sys.argv[1:]) + + def main(): - App().mainloop() + args = get_args() + App(args).mainloop() if __name__ == '__main__':