import sys

debug = '0'
frequest = 'freenet_request'
finsert = 'freenet_insert'
fmailInterval = '900000'
#freenetdir = '\freenet'
helper = 'kfmclient exec'
java = 'java'
#javaw = 'NOjavaw'

if sys.platform == 'win32':
    from win32api import RegOpenKey, RegQueryValueEx, RegCloseKey
    from win32con import HKEY_LOCAL_MACHINE
    import string, os
    
    hkey = HKEY_LOCAL_MACHINE
    subkey = r'Software\Freenet'
    name = 'inspath'
    
    hkey = RegOpenKey(hkey, subkey)
    freenetdir = RegQueryValueEx(hkey, "instpath")[0]
    #print freenetdir
    RegCloseKey(hkey)    
    helper = 'start'
    '''
    if os.path.exists(r"c:\program files\freenet\flaunch.ini"):
        freenetdir = (r"c:\program files\freenet")
        freenetdir = os.path.normpath(freenetdir)
        flaunch = (r"c:\program files\freenet\flaunch.ini")
    else:
        if os.path.exists(r"c:\freenet\flaunch.ini"):
            flaunch = os.path.normpath(r"c:\freenet\flaunch.ini")
            freenetdir = (r"c:\freenet")
            freenetdir = os.path.normpath(freenetdir)
    '''
    finsert = os.path.join(freenetdir, 'finsert')
    frequest = os.path.join(freenetdir, 'frequest')
    flaunch = os.path.join(freenetdir, 'flaunch.ini')
    f = open("%s" % flaunch, "r")
    lines = f.readlines()
    
    for l in lines:
        if string.find(l, 'javaexec=') != -1:
            java = string.split(l, '=', 2)[1]
            java = string.strip(java)
            #print java
    
        if string.find(l, 'javaw=') != -1:
            javaw = string.split(l, '=', 2)[1]
            javaw = string.strip(javaw)
            #print javaw
    
        if string.find(l, 'frequest=') != -1:
            serverAddress = string.split(l, ' ', 2)[2]
            serverAddress = string.strip(serverAddress)
            #print serverAddress

# Commands to be executed by Java

#frequest=Freenet.client.RequestClient --serverAddress tcp/127.0.0.1:19114