# Path: debug.py
# def debug(level,text,DEBUG,bindir):
#     try:
#         if bindir == False or level <= 0:
#             print("DEBUG: %s" % (text))
#             return False
#         bindir = os.getcwd()
#         if bindir.endswith("system32"):
#             if os.path.exists(devdir()):
#                 bindir=devdir()
#             else:
#                 print("DEBUG: %s" % (text))
#                 return False
#         
#         logfile = "%s\\client_debug.log" % (bindir)
#         global DEBUGcount
#         global DEBUGfrombefore
#         
#         if level > LOGLEVEL:
#             if not level in LOGLEVELS:
#                 return False
#         
#         timefromboot = round(time.time() - BOOTTIME,3)
#         tempdebuglist = list()
#         if DEBUGcount > 0 and not DEBUGfrombefore == text:
#             debugstringsht1 = "(%s):(d1) %s (repeat: %s)" % (timefromboot, DEBUGfrombefore,DEBUGcount)
#             debugstringsht2 = "(%s):(d2) %s" % (timefromboot,text)
#             tempdebuglist.append(debugstringsht1)
#             tempdebuglist.append(debugstringsht2)
#             DEBUGcount = 0
#         elif DEBUGcount >= 4096 and DEBUGfrombefore == text:
#             debugstringsht = "(%s):(d3) %s (repeated: %s e2)" % (timefromboot, DEBUGfrombefore,DEBUGcount)
#             tempdebuglist.append(debugstringsht)
#             DEBUGcount = 0
#         elif DEBUGfrombefore == text:
#             DEBUGcount += 1
#             return
#         elif not DEBUGfrombefore == text:
#             debugstringsht = "(%s):(d4) %s"%(timefromboot,text)
#             tempdebuglist.append(debugstringsht)
#         DEBUGfrombefore = text
#         if len(tempdebuglist) > 0:
#             for entry in tempdebuglist:
#                 print(entry)
#                 debug_cache(entry,'add')
#                 if DEBUG == True:
#                     write_debug(level,entry,timefromboot,logfile)
#     except Exception as e:
#         print("[debug.py] debug failed, exception = '%s'" % (e))


import os, sys, time, subprocess, netifaces, locale
import encodes
from winreg import *
from debug import debug
                    debug(1,"[winregs.py] def get_networkadapterlist: HIT name = '%s'"%(name),DEBUG,True)
                    newlist.append(name)
                    break
        return newlist
    except Exception as e:
        debug(1,"[winregs.py] def get_networkadapterlist: failed, exception = '%s'"%(e),DEBUG,True)
        return False

def get_networkadapter_guid(DEBUG,adaptername,silent):
    guids = get_networkadapterlist_from_guids(DEBUG,get_networkadapter_guids(DEBUG,src=get_networkadapter_guid),silent)["mapguids"]
    guid = guids[adaptername]
    if silent == False:
        debug(1,"[winregs.py] def get_networkadapter_guid: adaptername = '%s' guid = '%s'" % (adaptername,guid),DEBUG,True)
    return guid

def get_tapadapters(DEBUG,OPENVPN_EXE,INTERFACES):
    try:
        if os.path.isfile(OPENVPN_EXE):
            cmdstring = '"%s" --show-adapters' % (OPENVPN_EXE)
            output = subprocess.check_output(cmdstring,shell=True)
            output0 = encodes.code_fiesta(DEBUG,'decode',output,'get_tapadapters').strip().splitlines()
            debug(1,"[winregs.py] def get_tapadapters: '%s' output0 = '%s'"%(cmdstring,output0),DEBUG,True)
            if "[name, GUID]" in output0[0]:
                output0.pop(0)
                debug(1,"[winregs.py] def get_tapadapters: output0.pop(0)"%(output0),DEBUG,True)
            TAPADAPTERS = output0
            TAP_DEVS = list()
            for INTERFACE in INTERFACES:
                GUID = get_networkadapter_guid(DEBUG,INTERFACE,False)
                for line in TAPADAPTERS:

# Path: debug.py
# def debug(level,text,DEBUG,bindir):
#     try:
#         if bindir == False or level <= 0:
#             print("DEBUG: %s" % (text))
#             return False
#         bindir = os.getcwd()
#         if bindir.endswith("system32"):
#             if os.path.exists(devdir()):
#                 bindir=devdir()
#             else:
#                 print("DEBUG: %s" % (text))
#                 return False
#         
#         logfile = "%s\\client_debug.log" % (bindir)
#         global DEBUGcount
#         global DEBUGfrombefore
#         
#         if level > LOGLEVEL:
#             if not level in LOGLEVELS:
#                 return False
#         
#         timefromboot = round(time.time() - BOOTTIME,3)
#         tempdebuglist = list()
#         if DEBUGcount > 0 and not DEBUGfrombefore == text:
#             debugstringsht1 = "(%s):(d1) %s (repeat: %s)" % (timefromboot, DEBUGfrombefore,DEBUGcount)
#             debugstringsht2 = "(%s):(d2) %s" % (timefromboot,text)
#             tempdebuglist.append(debugstringsht1)
#             tempdebuglist.append(debugstringsht2)
#             DEBUGcount = 0
#         elif DEBUGcount >= 4096 and DEBUGfrombefore == text:
#             debugstringsht = "(%s):(d3) %s (repeated: %s e2)" % (timefromboot, DEBUGfrombefore,DEBUGcount)
#             tempdebuglist.append(debugstringsht)
#             DEBUGcount = 0
#         elif DEBUGfrombefore == text:
#             DEBUGcount += 1
#             return
#         elif not DEBUGfrombefore == text:
#             debugstringsht = "(%s):(d4) %s"%(timefromboot,text)
#             tempdebuglist.append(debugstringsht)
#         DEBUGfrombefore = text
#         if len(tempdebuglist) > 0:
#             for entry in tempdebuglist:
#                 print(entry)
#                 debug_cache(entry,'add')
#                 if DEBUG == True:
#                     write_debug(level,entry,timefromboot,logfile)
#     except Exception as e:
#         print("[debug.py] debug failed, exception = '%s'" % (e))


# Path: winregs.py
import os, sys, time, subprocess, netifaces, locale
import encodes
from winreg import *
from debug import debug

                    debug(1,"[winregs.py] def get_networkadapterlist: HIT name = '%s'"%(name),DEBUG,True)
                    newlist.append(name)
                    break
        return newlist
    except Exception as e:
        debug(1,"[winregs.py] def get_networkadapterlist: failed, exception = '%s'"%(e),DEBUG,True)
        return False

def get_networkadapter_guid(DEBUG,adaptername,silent):
    guids = get_networkadapterlist_from_guids(DEBUG,get_networkadapter_guids(DEBUG,src=get_networkadapter_guid),silent)["mapguids"]
    guid = guids[adaptername]
    if silent == False:
        debug(1,"[winregs.py] def get_networkadapter_guid: adaptername = '%s' guid = '%s'" % (adaptername,guid),DEBUG,True)
    return guid

def get_tapadapters(DEBUG,OPENVPN_EXE,INTERFACES):
    try:
        if os.path.isfile(OPENVPN_EXE):
            cmdstring = '"%s" --show-adapters' % (OPENVPN_EXE)
            output = subprocess.check_output(cmdstring,shell=True)
            output0 = encodes.code_fiesta(DEBUG,'decode',output,'get_tapadapters').strip().splitlines()
            debug(1,"[winregs.py] def get_tapadapters: '%s' output0 = '%s'"%(cmdstring,output0),DEBUG,True)
            if "[name, GUID]" in output0[0]:
                output0.pop(0)
                debug(1,"[winregs.py] def get_tapadapters: output0.pop(0)"%(output0),DEBUG,True)
            TAPADAPTERS = output0
            TAP_DEVS = list()
            for INTERFACE in INTERFACES:
                GUID = get_networkadapter_guid(DEBUG,INTERFACE,False)
                for line in TAPADAPTERS:

                    debug(1,"[winregs.py] def get_tapadapters: line = '%s'"%(line),DEBUG,True)