Open Side Menu Go to the Top
Register
Bodog Notes Exporter - Python Script Bodog Notes Exporter - Python Script

10-13-2011 , 03:11 PM
The problem:

Bodog thought it would be a great idea to store player notes in the windows registry. However their implementation is wacked, and the problem is realized when you want to backup/move your notes. If you export the notes registry entry, everything gets exported to a .reg file just fine. However, when you go to (re)import that registry file, only players with one line of notes are imported. All players with more than one line of notes are not added to the registry, meaning a large portion of your notes are not imported.* (see my original solution here, and identification of the problem here)

*The reason for this is because bodog uses a pair of LF + CR characters to represent hard returns. This character combination will export from the registry, but not import back into the registry (NH MSFT). However these character combinations can be imported to the registry if converted to hex first.

The solution:

To import your multi-line notes in their entirety, they need to be first converted into a hex string that ends up looking something like this :
Code:
"playerA"=hex(1):12, 00, 0D, 00, 6C, 00
This single line represents every line of notes taken for playerA, and is readable by the registry. So now we just need a script to convert all of the notes into this format, and spit out a .reg file that you can import on any computer without loosing any data. That is exactly what this script does, but I also included the ability to export Bodog game settings to a separate file (these entries do not need to be converted to hex).


Usage:
Just make a few edits below, save as .py file, run the script, and then double click on the .reg file(s) created to import.

There are currently 5 constants that need to be edited to use this script:
1) USERNAME - This is your Bodog Username.
2) NOTES_OUTPUT_FILE - This the name of the .reg file you want to save your notes to. (Folder must already exist)
3) SETTINGS_OUTPUT_FILE - This is the name of the .reg file you want to save your Bodog settings to. (Folder must already exist)
4) EXPORT_NOTES - 1 = export notes when script is executed. 0 = Do not export.
5) EXPORT_SETTINGS - 1 = export settings when script is executed. 0 = Do not export.

Code:
from _winreg import *
import shlex, subprocess

###########################################
##CONSTANTS
###########################################

#Edit these
USERNAME             = "XXXXXXXX"
NOTES_OUTPUT_FILE    = "bodog_notes.reg"
SETTINGS_OUTPUT_FILE = "bodog_settings.reg"
EXPORT_NOTES         = 1
EXPORT_SETTINGS      = 1

#Don't edit below here
ROOT_KEY             = "HKEY_CURRENT_USER"
NOTES_OPEN_KEY       = HKEY_CURRENT_USER
NOTES_HEX_PREFIX     = "hex(1):"
BODOG_ROOT           = "Software\\Bodog Poker\\Game\\"
NOTES_ROOT           = BODOG_ROOT + "Notes\\"  + USERNAME
NOTES_OUTPUT_HEADER  = "Windows Registry Editor Version 5.00\n\n"
NOTES_OUTPUT_KEY     = "["+ROOT_KEY + NOTES_ROOT + "]\n"
SETTINGS_PATH        = BODOG_ROOT + "Settings"

##########################################
##Functions
##########################################

#split string into n length pieces
def split_len(seq, length):
    return [seq[i:i+length] for i in range(0, len(seq), length)]

#format a string into a registry readable hex entry
def value_to_hex(subkey):

    #convert each character to hex and seperate with 00 (no idea why the registry does this)
    out = NOTES_HEX_PREFIX + ",00,".join(split_len(subkey.encode("hex"), 2))

    #if output is not empty, append 00
    if len(out) > len(NOTES_HEX_PREFIX): out += ",00"
    return out

#return the formatted entry to be written to file
def output_pair(tup):
    return '"' + tup[0] + '"=' + value_to_hex(tup[1])

#export notes to file
def export_notes():
    #open key & output file
    masterKey = OpenKey(NOTES_OPEN_KEY, NOTES_ROOT + "\\")
    f = open(NOTES_OUTPUT_FILE, 'w')

    #write header to file
    f.write(NOTES_OUTPUT_HEADER + NOTES_OUTPUT_KEY)

    try:
        x = 0
        while (x >=0):
            f.write(output_pair(EnumValue(masterKey, x)) + "\n")
            x +=1 
    except EnvironmentError:

        #close key & output file
        CloseKey(masterKey)
        f.close()
        print "Notes Successfully Exported"

#export settings to file
def export_settings():
    #Edit these
    subprocess.Popen("REGEDIT /E " + SETTINGS_OUTPUT_FILE + " \"" + ROOT_KEY + "\\" + SETTINGS_PATH + "\"")
    print "Settings Successfully Exported"
    
##########################################
##Main
##########################################
    
if EXPORT_NOTES: export_notes() 
if EXPORT_SETTINGS: export_settings()

Notes:

This script was recently hacked together (and I blow at python), so I welcome any input, suggestions, fixes, or bug reports. I expect to continue to polish this script, and update as necessary. Also, I realize an AHK script would be helpful to a much wider audience (and I would actually prefer AHK) but I'm really annoyed with AHK right now and python is much quicker to implement something like this. If anybody wants to help convert this to AHK, let me know.

Disclaimer:


This script has barely been tested, and there is some risk in using it. Exporting notes is not a problem, but when importing notes (and settings), you will be overwriting everything in your existing registry. If there is a problem with the script or .reg file, it is conceivable that you could lose all of your notes on the system you are importing to. Furthermore, it's possible human error could cause some loss of data (for example, if you export notes from an old bodog install, and import into a current bodog install). For this reason, I take no responsibility and assume no liability for any harm this script may cause. I suggest importing notes to a temporary install on another machine or VM to make sure it is working properly before importing over newer data.
Bodog Notes Exporter - Python Script Quote
10-14-2011 , 11:18 AM
Python >>> AHK

I would love to see the hundreds of lines of this code in AHK...

I suggest you make a GUI and offer an executable version of your script. I have no clue how many know how to execute a .py script.

I use http://www.wxpython.org/ for GUI

and pyinstaller to make executables
Bodog Notes Exporter - Python Script Quote

      
m