# 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: debug.py
# def devmode():
#     return getmode("DEVMODE")


import os, time, subprocess, sys, json
import shlex
import win32process
import release_version
import hashings
import signtool
import encodes
import platform
from datetime import datetime
from debug import debug
from debug import devmode
    debug(9,"[openvpn.py] def get_arch: ARCH = '%s'" % (ARCH),DEBUG,True)
    return ARCH

def os_platform(DEBUG):
    debug(9,"[openvpn.py] def os_platform()",DEBUG,True)
    true_platform = os.environ['PROCESSOR_ARCHITECTURE']
    try:
        true_platform = os.environ["PROCESSOR_ARCHITEW6432"]
    except KeyError:
        pass
        #true_platform not assigned to if this does not exist
    if true_platform in supported_platforms(DEBUG):
        debug(9,"[openvpn.py] def os_platform: true_platform = '%s'" % (true_platform),DEBUG,True)
        return true_platform
    else:
        debug(1,"[openvpn.py] def os_platform: true_platform = '%s' NOT SUPPORTED" % (true_platform),DEBUG,True)
        sys.exit()

def win_detect_openvpn(DEBUG,OPENVPN_EXE):
    # returns [ OPENVPN_DIR, OPENVPN_EXE ]
    try:
        debug(1,"[openvpn.py] def win_detect_openvpn()",DEBUG,True)
        if OPENVPN_EXE == False:
            debug(1,"[openvpn.py] def win_detect_openvpn: check programfiles",DEBUG,True)
            programfiles = [ "PROGRAMFILES", "PROGRAMFILES(x86)", "PROGRAMW6432" ]
            for getenv in programfiles:
                programfiles_dir = os.getenv(getenv)
                file = "%s\\OpenVPN\\bin\\openvpn.exe" % (programfiles_dir)
                if os.path.isfile(file):
                    debug(1,"[openvpn.py] def win_detect_openvpn: '%s'" % (file),DEBUG,True)

# 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: debug.py
# def devmode():
#     return getmode("DEVMODE")


# Path: openvpn.py
import os, time, subprocess, sys, json
import shlex
import win32process
import release_version
import hashings
import signtool
import encodes
import platform
from datetime import datetime
from debug import debug
from debug import devmode

    debug(9,"[openvpn.py] def get_arch: ARCH = '%s'" % (ARCH),DEBUG,True)
    return ARCH

def os_platform(DEBUG):
    debug(9,"[openvpn.py] def os_platform()",DEBUG,True)
    true_platform = os.environ['PROCESSOR_ARCHITECTURE']
    try:
        true_platform = os.environ["PROCESSOR_ARCHITEW6432"]
    except KeyError:
        pass
        #true_platform not assigned to if this does not exist
    if true_platform in supported_platforms(DEBUG):
        debug(9,"[openvpn.py] def os_platform: true_platform = '%s'" % (true_platform),DEBUG,True)
        return true_platform
    else:
        debug(1,"[openvpn.py] def os_platform: true_platform = '%s' NOT SUPPORTED" % (true_platform),DEBUG,True)
        sys.exit()

def win_detect_openvpn(DEBUG,OPENVPN_EXE):
    # returns [ OPENVPN_DIR, OPENVPN_EXE ]
    try:
        debug(1,"[openvpn.py] def win_detect_openvpn()",DEBUG,True)
        if OPENVPN_EXE == False:
            debug(1,"[openvpn.py] def win_detect_openvpn: check programfiles",DEBUG,True)
            programfiles = [ "PROGRAMFILES", "PROGRAMFILES(x86)", "PROGRAMW6432" ]
            for getenv in programfiles:
                programfiles_dir = os.getenv(getenv)
                file = "%s\\OpenVPN\\bin\\openvpn.exe" % (programfiles_dir)
                if os.path.isfile(file):
                    debug(1,"[openvpn.py] def win_detect_openvpn: '%s'" % (file),DEBUG,True)

                    OPENVPN_DIR = "%s\\OpenVPN\\bin" % (programfiles_dir)