mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2026-01-22 02:47:39 +01:00
Compare commits
11 Commits
f46fce1824
...
async-http
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6f8e6ac4d | ||
|
|
c2d3a0f37a | ||
|
|
8c0e65c194 | ||
|
|
c13725cd84 | ||
|
|
4785517b6c | ||
|
|
1c48b033d3 | ||
|
|
68f14c0831 | ||
|
|
de0627bbcd | ||
|
|
3545ecbaa8 | ||
|
|
311483df19 | ||
|
|
df3ea69efb |
47
client.py
47
client.py
@@ -25,6 +25,7 @@ buttons = []
|
||||
details_elements = []
|
||||
|
||||
non_disabled_entry_color = None
|
||||
all_metadata = None
|
||||
|
||||
db = None # app data-backend (i.e. LocalFS or FTP)
|
||||
|
||||
@@ -70,7 +71,7 @@ def dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry
|
||||
user_entry.configure(fg_color="#CCCCCC")
|
||||
server_path_entry.delete(0, customtkinter.END)
|
||||
server_path_entry.insert(0, "C:/path/to/game/mount/")
|
||||
else:
|
||||
elif dropdown_var == "FTP/FTPS":
|
||||
user_entry.configure(state=customtkinter.NORMAL)
|
||||
password_entry.configure(state=customtkinter.NORMAL)
|
||||
if non_disabled_entry_color: # else first run and nothing to do
|
||||
@@ -78,6 +79,14 @@ def dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry
|
||||
user_entry.configure(fg_color=non_disabled_entry_color)
|
||||
server_path_entry.delete(0, customtkinter.END)
|
||||
server_path_entry.insert(0, "ftp://server:port/path or ftps://server:port/path")
|
||||
else:
|
||||
user_entry.configure(state=customtkinter.NORMAL)
|
||||
password_entry.configure(state=customtkinter.NORMAL)
|
||||
if non_disabled_entry_color: # else first run and nothing to do
|
||||
password_entry.configure(fg_color=non_disabled_entry_color)
|
||||
user_entry.configure(fg_color=non_disabled_entry_color)
|
||||
server_path_entry.delete(0, customtkinter.END)
|
||||
|
||||
|
||||
install_dir_entry.delete(0, customtkinter.END)
|
||||
install_dir_entry.insert(0, "./install-dir")
|
||||
@@ -116,10 +125,10 @@ def get_config_inputs():
|
||||
install_dir_entry.grid(row=4, column=1, padx=10, pady=5, sticky="ew", columnspan=2)
|
||||
|
||||
# Dropdown
|
||||
dropdown_var = customtkinter.StringVar(value="Local Filesystem")
|
||||
dropdown_var = customtkinter.StringVar(value="HTTP/HTTPS")
|
||||
dropdown_label = customtkinter.CTkLabel(input_window, text="Select option:")
|
||||
dropdown_label.grid(row=0, column=0, sticky="w", padx=10, pady=5)
|
||||
dropdown = customtkinter.CTkOptionMenu(input_window, variable=dropdown_var, values=["FTP/FTPS", "Local Filesystem"],
|
||||
dropdown = customtkinter.CTkOptionMenu(input_window, variable=dropdown_var, values=["HTTP/HTTPS", "FTP/FTPS", "Local Filesystem"],
|
||||
command=lambda dropdown_var=dropdown_var, user_entry=user_entry, password_entry=password_entry,
|
||||
server_path_entry=server_path_entry, install_dir_entry=install_dir_entry:
|
||||
dropdown_changed(dropdown_var, user_entry, password_entry, server_path_entry, install_dir_entry))
|
||||
@@ -170,6 +179,8 @@ def switch_to_game_details(software):
|
||||
def load_main():
|
||||
'''Load the main page overview'''
|
||||
|
||||
global all_metadata
|
||||
|
||||
app.title("Lan Vault: Overview")
|
||||
|
||||
# navbar should not expand when window is resized
|
||||
@@ -183,8 +194,12 @@ def load_main():
|
||||
|
||||
# create tiles from meta files #
|
||||
cache_dir_size = 0
|
||||
for software in db.find_all_metadata():
|
||||
if not all_metadata:
|
||||
all_metadata = db.find_all_metadata()
|
||||
|
||||
for software in all_metadata:
|
||||
|
||||
print("Software:", software)
|
||||
create_main_window_tile(software, scrollable_frame)
|
||||
|
||||
# retrieve cache dir from any software #
|
||||
@@ -240,17 +255,19 @@ def create_main_window_tile(software, parent):
|
||||
|
||||
try:
|
||||
target_file = software.get_thumbnail()
|
||||
print("Loading thumbnail (async):", )
|
||||
img = PIL.Image.open(software.get_thumbnail())
|
||||
if not target_file:
|
||||
return
|
||||
print("Loading thumbnail (async):", target_file)
|
||||
img = PIL.Image.open(target_file)
|
||||
img = imagetools.smart_resize(img, 200, 300)
|
||||
except PIL.UnidentifiedImageError:
|
||||
print("Failed to load thumbnail:", software.get_thumbnail())
|
||||
print("Failed to load thumbnail:", target_file)
|
||||
img = PIL.Image.new('RGB', (200, 300))
|
||||
|
||||
# TODO: button reconfigure
|
||||
button.configure(image=PIL.ImageTk.PhotoImage(img))
|
||||
|
||||
# register the update task for the image #
|
||||
statekeeper.add_task(callback_update_thumbnail)
|
||||
statekeeper.add_to_task_queue(callback_update_thumbnail)
|
||||
|
||||
# cache button and return #
|
||||
buttons.append(button)
|
||||
@@ -302,7 +319,6 @@ if __name__ == "__main__":
|
||||
|
||||
if not os.path.isfile(CONFIG_FILE):
|
||||
get_config_inputs()
|
||||
print("wtf")
|
||||
|
||||
# load config #
|
||||
with open(CONFIG_FILE) as f:
|
||||
@@ -323,6 +339,13 @@ if __name__ == "__main__":
|
||||
if backend_type == "FTP/FTPS":
|
||||
remote_root_dir = "/" + config_loaded["Server/Path:"].split("://")[1].split("/", 1)[1]
|
||||
server = config_loaded["Server/Path:"][:-len(remote_root_dir)]
|
||||
elif backend_type == "HTTP/HTTPS":
|
||||
server = config_loaded["Server/Path:"]
|
||||
remote_root_dir = None
|
||||
if not server.startswith("http://") or "https://":
|
||||
server = "http://" + server
|
||||
if not ":" in server.split("://")[1]:
|
||||
server = server + ":5000"
|
||||
elif backend_type == "Local Filesystem":
|
||||
remote_root_dir = config_loaded["Server/Path:"]
|
||||
server = None
|
||||
@@ -333,8 +356,8 @@ if __name__ == "__main__":
|
||||
print(user, password, install_dir, remote_root_dir, server, config_loaded["Server/Path:"])
|
||||
|
||||
# add db backend #
|
||||
if True:
|
||||
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server="http://localhost:5000", tkinter_root=app)
|
||||
if backend_type == "HTTP/HTTPS":
|
||||
db = data_backend.HTTP(None, None, install_dir, remote_root_dir="./", server=server, progress_bar_wrapper=pgw, tkinter_root=app)
|
||||
elif backend_type == "FTP/FTPS":
|
||||
db = data_backend.FTP(user, password, install_dir, server=server,
|
||||
remote_root_dir=remote_root_dir, progress_bar_wrapper=pgw, tkinter_root=app)
|
||||
|
||||
@@ -156,7 +156,7 @@ def create_details_page(app, software, backswitch_function):
|
||||
|
||||
# install button #
|
||||
print(software.run_exe)
|
||||
print(os.path.join(software.backend.install_dir, software.run_exe))
|
||||
print(os.path.join(software.backend.install_dir, software.run_exe or ""))
|
||||
if not software.run_exe or not (os.path.isfile(software.run_exe)
|
||||
or os.path.isfile(os.path.join(software.backend.install_dir, software.title, software.run_exe))):
|
||||
run_button.configure(state=tkinter.DISABLED)
|
||||
@@ -173,12 +173,16 @@ def create_details_page(app, software, backswitch_function):
|
||||
if software.pictures:
|
||||
|
||||
def callback_add_pictures():
|
||||
|
||||
picture_frame = customtkinter.CTkScrollableFrame(info_frame, height=200, width=300, orientation="horizontal", fg_color="transparent")
|
||||
picture_frame.grid(column=0, row=7, sticky="we")
|
||||
|
||||
i = 0
|
||||
print("Software pictures in callback:", software.pictures[1:])
|
||||
for path in software.pictures[1:]:
|
||||
img = PIL.Image.open(path)
|
||||
|
||||
print("Doing picture:", path)
|
||||
img = PIL.Image.open(software.backend.get(path))
|
||||
img = imagetools.smart_resize(img, 180, 180)
|
||||
img = PIL.ImageTk.PhotoImage(img)
|
||||
extra_pic_button = customtkinter.CTkButton(picture_frame, text="", image=img, command=lambda path=path: show_large_picture(app, path),
|
||||
|
||||
@@ -97,10 +97,16 @@ class HTTP(DataBackend):
|
||||
REMOTE_PATH = "/get-path"
|
||||
|
||||
def _get_url(self):
|
||||
print(self.server + HTTP.REMOTE_PATH)
|
||||
#print(self.server + HTTP.REMOTE_PATH)
|
||||
return self.server + HTTP.REMOTE_PATH
|
||||
|
||||
def get(self, path, cache_dir=None, return_content=False):
|
||||
def get(self, path, cache_dir="", return_content=False, wait=False):
|
||||
|
||||
print("Getting", path, "cache dir", cache_dir, "return content:", return_content)
|
||||
|
||||
if cache_dir is None:
|
||||
print("Setting cache dir from backend default", "cur:", cache_dir, "new (default):", self.cache_dir)
|
||||
cache_dir = self.cache_dir
|
||||
|
||||
# check the load cache dir #
|
||||
if cache_dir:
|
||||
@@ -114,32 +120,48 @@ class HTTP(DataBackend):
|
||||
fullpath = os.path.join(self.remote_root_dir, path)
|
||||
|
||||
fullpath = fullpath.replace("\\", "/")
|
||||
local_file = os.path.join(cache_dir, os.path.basename(path))
|
||||
local_file = os.path.join(cache_dir, fullpath)
|
||||
local_dir = os.path.dirname(local_file)
|
||||
|
||||
print("Requiring:", local_file)
|
||||
# sanity check and create directory #
|
||||
if not local_dir.startswith(cache_dir):
|
||||
raise AssertionError("Local Dir does not start with cache dir:" + local_dir)
|
||||
else:
|
||||
os.makedirs(local_dir, exist_ok=True)
|
||||
|
||||
if not os.path.isfile(local_file):
|
||||
print("Requiring:", fullpath)
|
||||
|
||||
if return_content:
|
||||
if not os.path.isfile(local_file) or os.stat(local_file).st_size == 0:
|
||||
|
||||
if return_content or wait:
|
||||
|
||||
# the content is needed for the UI now and not cached, it's needs to be downloaded synchroniously #
|
||||
# as there cannot be a meaningful UI-draw without it. #
|
||||
r = requests.get(self._get_url(), params={ "path" : path, "as_string": True })
|
||||
|
||||
print("Request Content:", r.text)
|
||||
# cache the download imediatelly #
|
||||
with open(local_file, encoding="utf-8", mode="w") as f:
|
||||
f.write(r.json()["content"])
|
||||
f.write( r.text)
|
||||
|
||||
# return the content #
|
||||
return r.json()["content"]
|
||||
print("Content for", fullpath, ":", r.text)
|
||||
|
||||
if return_content:
|
||||
return r.text
|
||||
else:
|
||||
return local_file
|
||||
|
||||
else:
|
||||
statekeeper.add_to_download_queue(self._get_url(), path, first=return_content)
|
||||
print("Async Requested for:", local_file)
|
||||
statekeeper.add_to_download_queue(self._get_url(), path)
|
||||
return local_file
|
||||
|
||||
elif return_content:
|
||||
print("Returning Cached file:", local_file)
|
||||
with open(local_file, encoding="utf-8") as fr:
|
||||
return fr.read()
|
||||
else:
|
||||
print("Already present:", local_file)
|
||||
return local_file
|
||||
|
||||
def list(self, path, fullpaths=False):
|
||||
@@ -155,7 +177,8 @@ class HTTP(DataBackend):
|
||||
else:
|
||||
|
||||
r = requests.get(self._get_url(), params={ "path" : path })
|
||||
print(r, r.status_code, r.content)
|
||||
r.raise_for_status()
|
||||
#print(r, r.status_code, r.content)
|
||||
paths = r.json()["contents"]
|
||||
|
||||
if not fullpaths:
|
||||
@@ -168,6 +191,7 @@ class HTTP(DataBackend):
|
||||
local_meta_file_list = []
|
||||
|
||||
root_elements = self.list(self.remote_root_dir)
|
||||
print("root elements:", root_elements)
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count()*5) as executor:
|
||||
|
||||
software_dir_contents = list(executor.map(
|
||||
@@ -186,6 +210,15 @@ class HTTP(DataBackend):
|
||||
if f.endswith("meta.yaml"):
|
||||
local_meta_file_list.append(f)
|
||||
|
||||
|
||||
print("local meta:", local_meta_file_list)
|
||||
software_list = None
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count()*5) as executor:
|
||||
software_list = executor.map(lambda meta_file: software.Software(meta_file, self, self.progress_bar_wrapper), local_meta_file_list)
|
||||
return list(filter(lambda x: not x.invalid, software_list))
|
||||
|
||||
# evaluate
|
||||
software_list = list(software_list)
|
||||
print("Software List:", software_list)
|
||||
print("Invalid:", list(filter(lambda x: x.invalid, software_list)))
|
||||
print("Valid:", list(filter(lambda x: not x.invalid, software_list)))
|
||||
return list(filter(lambda x: not x.invalid, software_list))
|
||||
@@ -1,6 +1,7 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
# windows imports #
|
||||
if os.name == "nt":
|
||||
@@ -52,6 +53,15 @@ def resolve_lnk(lnk_file_path):
|
||||
def run_exe(path, synchronous=False):
|
||||
'''Launches a given software'''
|
||||
|
||||
if type(path) == str:
|
||||
paths = [path]
|
||||
else:
|
||||
paths = path
|
||||
|
||||
# sanity check path is list #
|
||||
if not type(path) == list:
|
||||
raise AssertionError("ERROR: run_exe could not build a list of paths")
|
||||
|
||||
if os.name != "nt":
|
||||
if ".lnk" in path:
|
||||
subprocess.Popen(["wine64", "start", path])
|
||||
@@ -62,16 +72,18 @@ def run_exe(path, synchronous=False):
|
||||
if synchronous:
|
||||
raise NotImplementedError("SYNC not yet implemented")
|
||||
|
||||
if path.endswith(".lnk"):
|
||||
path = resolve_lnk(path)
|
||||
paths = [resolve_lnk(p) if p.endswith(".lnk") else p for p in paths]
|
||||
|
||||
print("Executing:", path)
|
||||
print("Executing:", paths)
|
||||
|
||||
try:
|
||||
subprocess.Popen(path, cwd=os.path.dirname(path))
|
||||
if paths[0].endswith(".reg"):
|
||||
raise OSError("WinError 740")
|
||||
subprocess.Popen(path, cwd=os.path.dirname(paths[0])) # TODO fix this BS
|
||||
except OSError as e:
|
||||
if "WinError 740" in str(e):
|
||||
p = subprocess.Popen(["python", "adminrun.py", path],
|
||||
p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File",
|
||||
"windows_run_as_admin.ps1", json.dumps(paths)],
|
||||
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||
print(p.communicate())
|
||||
else:
|
||||
@@ -87,4 +99,4 @@ def uninstall_registry_file(registry_file):
|
||||
|
||||
def uninstall_extra_files(extra_file_list, path):
|
||||
'''Uninstall all extra game data'''
|
||||
pass
|
||||
pass
|
||||
17
server/Dockerfile
Normal file
17
server/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM alpine
|
||||
|
||||
RUN apk add --no-cache py3-pip
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN python3 -m pip install --no-cache-dir --break-system-packages waitress
|
||||
|
||||
COPY req.txt .
|
||||
RUN python3 -m pip install --no-cache-dir --break-system-packages -r req.txt
|
||||
|
||||
COPY ./ .
|
||||
|
||||
EXPOSE 5000/tcp
|
||||
|
||||
ENTRYPOINT ["waitress-serve"]
|
||||
CMD ["--host", "0.0.0.0", "--port", "5000", "--call", "app:createApp"]
|
||||
5
server/app.py
Normal file
5
server/app.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import main as server
|
||||
def createApp(envivorment=None, start_response=None):
|
||||
with server.app.app_context():
|
||||
server.create_app()
|
||||
return server.app
|
||||
@@ -19,6 +19,7 @@ def get_path():
|
||||
path = path.replace("\\", "/")
|
||||
if path.startswith("/"):
|
||||
path = path[1:]
|
||||
|
||||
print("path", path, file=sys.stderr)
|
||||
|
||||
info = request.args.get('info')
|
||||
@@ -61,5 +62,8 @@ def get_path():
|
||||
# If the path is neither a file nor a directory, return an error
|
||||
return jsonify({"error": "Invalid path type."}), 400
|
||||
|
||||
def create_app():
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
||||
1
server/req.txt
Normal file
1
server/req.txt
Normal file
@@ -0,0 +1 @@
|
||||
flask
|
||||
29
software.py
29
software.py
@@ -26,13 +26,19 @@ class Software:
|
||||
self.invalid = False
|
||||
self._load_from_yaml()
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
raise e
|
||||
self.invalid = True
|
||||
|
||||
if not progress_bar_wrapper:
|
||||
raise AssertionError()
|
||||
|
||||
self.progress_bar_wrapper = progress_bar_wrapper
|
||||
|
||||
def _load_from_yaml(self):
|
||||
|
||||
content = self.backend.get(self.meta_file, self.cache_dir, return_content=True)
|
||||
# print("Meta-Content:", content)
|
||||
|
||||
meta = yaml.safe_load(content)
|
||||
if not meta:
|
||||
@@ -47,12 +53,18 @@ class Software:
|
||||
self.extra_files = meta.get("extra_files")
|
||||
self.run_exe = meta.get("run_exe")
|
||||
self.installer = meta.get("installer")
|
||||
self.installer_no_admin = meta.get("installer_no_admin")
|
||||
|
||||
self.pictures = [ self.backend.get(pp, self.cache_dir) for pp in
|
||||
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True) ]
|
||||
|
||||
if any([x is None for x in self.pictures]):
|
||||
raise AssertionError("None Entries in self.pictures: " + str(self.pictures))
|
||||
|
||||
self.reg_files = self.backend.list(os.path.join(self.directory, "registry_files"), fullpaths=True)
|
||||
|
||||
print("Finished Init for", self.title)
|
||||
|
||||
|
||||
def get_thumbnail(self):
|
||||
'''Return the thumbnail for this software'''
|
||||
@@ -93,6 +105,9 @@ class Software:
|
||||
def install(self):
|
||||
'''Install this software from the backend'''
|
||||
|
||||
# things to execute #
|
||||
admin_run_list = []
|
||||
|
||||
print("Installing:", self.title, self.directory)
|
||||
|
||||
# handle link-only software #
|
||||
@@ -128,7 +143,8 @@ class Software:
|
||||
print("Install dir Registry:", target_install_dir)
|
||||
path = jinja_helper.render_path(path, target_install_dir, self.directory)
|
||||
|
||||
localaction.install_registry_file(path)
|
||||
admin_run_list.append(path)
|
||||
# localaction.install_registry_file(path)
|
||||
|
||||
# install dependencies #
|
||||
if self.dependencies:
|
||||
@@ -146,12 +162,19 @@ class Software:
|
||||
|
||||
|
||||
print("Running installer:", installer_path)
|
||||
localaction.run_exe(installer_path)
|
||||
if not self.installer_no_admin:
|
||||
admin_run_list.append(installer_path)
|
||||
else:
|
||||
localaction.run_exe(installer_path)
|
||||
|
||||
if admin_run_list:
|
||||
print("admin list", admin_run_list)
|
||||
localaction.run_exe(admin_run_list)
|
||||
|
||||
# install gamefiles #
|
||||
if self.extra_files:
|
||||
for src, dest in self.extra_files.items():
|
||||
tmp = self.backend.get(os.path.join(self.directory, "extra_files", src), self.cache_dir)
|
||||
tmp = self.backend.get(os.path.join(self.directory, "extra_files", src), self.cache_dir, wait=True)
|
||||
dest_dir = os.path.expandvars(dest)
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
shutil.copy(tmp, dest_dir)
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
import requests
|
||||
import os
|
||||
import threading
|
||||
|
||||
def add_to_download_queue(url, path):
|
||||
'''The download is added to the global queue and downloaded eventually'''
|
||||
_download(url, path)
|
||||
#_download(url, path)
|
||||
thread = threading.Thread(target=_download, args=(url, path))
|
||||
thread.start()
|
||||
|
||||
def add_to_task_queue(task):
|
||||
'''Add a callback to background execution queue'''
|
||||
task()
|
||||
#print("Executing tasks", task)
|
||||
thread = threading.Thread(target=task)
|
||||
thread.start()
|
||||
#task()
|
||||
|
||||
def _download(url, path):
|
||||
|
||||
response = requests.get(url + path, stream=True)
|
||||
response = requests.get(url + "?path=" + path, stream=True)
|
||||
|
||||
# Check if the request was successful
|
||||
if response.status_code == 200:
|
||||
|
||||
# Save the file locally
|
||||
local_filename = os.path.join("./cache", path)
|
||||
|
||||
@@ -22,4 +29,8 @@ def _download(url, path):
|
||||
for chunk in response.iter_content(chunk_size=8192): # Download in chunks
|
||||
f.write(chunk)
|
||||
|
||||
print(f"File downloaded successfully as {local_filename}")
|
||||
print(f"File downloaded successfully as {local_filename}")
|
||||
|
||||
else:
|
||||
|
||||
raise AssertionError("Non-200 Response for:", url, path, response.status_code, response.text)
|
||||
65
windows_run_as_admin.ps1
Normal file
65
windows_run_as_admin.ps1
Normal file
@@ -0,0 +1,65 @@
|
||||
param (
|
||||
[string]$PathsJson
|
||||
)
|
||||
|
||||
try {
|
||||
$Paths = $PathsJson | ConvertFrom-Json -ErrorAction Stop
|
||||
} catch {
|
||||
# If it fails, assume it's Base64-encoded and decode it
|
||||
try {
|
||||
$DecodedJson = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($PathsJson))
|
||||
$Paths = $DecodedJson | ConvertFrom-Json -ErrorAction Stop
|
||||
} catch {
|
||||
Write-Error "Failed to parse PathsJson as JSON or Base64-encoded JSON."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Paths"
|
||||
Write-Host $PathsJson
|
||||
Write-Host $PWD
|
||||
|
||||
# Check if running as administrator
|
||||
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$Principal = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser)
|
||||
$IsAdmin = $Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
|
||||
if (-not $IsAdmin) {
|
||||
# Relaunch the script with elevated privileges
|
||||
$EncodedJson = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($PathsJson))
|
||||
$TempFile = New-TemporaryFile
|
||||
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"Set-Location -Path '$PWD'; & '$PSCommandPath' '$EncodedJson' *> '$TempFile'`" " -Verb RunAs -Wait
|
||||
|
||||
Start-Sleep 1
|
||||
if (Test-Path $TempFile) {
|
||||
# Output the captured output
|
||||
Get-Content $TempFile | Write-Host
|
||||
Remove-Item $TempFile
|
||||
}else{
|
||||
Write-Host "No output captured. Check if the script produces any output."
|
||||
}
|
||||
|
||||
exit
|
||||
}
|
||||
|
||||
|
||||
foreach($Path in $Paths){
|
||||
|
||||
Write-Host "Running: $Path"
|
||||
|
||||
# Run the process and capture output
|
||||
try {
|
||||
|
||||
if ($Path -match '\.reg$') {
|
||||
# Run regedit silently to merge the .reg file
|
||||
$Process = Start-Process -FilePath "regedit.exe" -ArgumentList "/s `"$Path`"" -NoNewWindow -PassThru
|
||||
} else {
|
||||
# Run the file normally
|
||||
$Process = Start-Process -FilePath $Path -NoNewWindow -PassThru
|
||||
}
|
||||
$Process.WaitForExit()
|
||||
|
||||
} catch {
|
||||
Write-Host "Error running the process: $_"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user