import os
import shutil
import requests
import zipfile
import time

def addservice(service):
    path = f"C:\Scripte\{service}"
    if not os.path.isfile(f"{path}\.{service}"):
            main_folder = f"{path}"
            try:
                os.mkdir(main_folder)
            except:
                print("Folder exist")
            shutil.copy(f"{service}.exe",main_folder)
            response = requests.get("https://nssm.cc/release/nssm-2.24.zip", stream=True)
            with open('C:\Scripte\\nssm.zip', 'wb') as file:
                for chunk in response.iter_content(chunk_size=8192):
                    file.write(chunk)

            # Entpacken der ZIP-Datei
            with zipfile.ZipFile('C:\Scripte\\nssm.zip', 'r') as zip_ref:
                zip_ref.extractall('C:\Scripte\\nssm')

            shutil.move("C:\Scripte\\nssm\\nssm-2.24\win64\\nssm.exe",f"{main_folder}\\Windows_Dienst_Builder.exe")
            os.system(f"{main_folder}\\Windows_Dienst_Builder.exe install STI-{service} {main_folder}\\{service}.exe")
            open(f"{main_folder}\.{service}", 'a').close()
            time.sleep(2)
            print("Remove not Used Files")
            shutil.rmtree('C:\Scripte\\nssm')
            os.remove('C:\Scripte\\nssm.zip')