Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rc2qt hex decoding, remove Python-style b'' from C++ output #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tools/rc2qt/rc2qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,11 @@ def output(self):
print(self.DialogExsDeclFooter)


def bytes_to_cpp_literal(b: bytes) -> str:
"""Converts bytes into a C++ hex-escaped string (without double-quotes)."""
return str(b)[2:-1]


class rcDialogInitList(object):
DialogInitItemFormat = """
mfc{0}->AddString(_T("{1}"));
Expand All @@ -847,9 +852,12 @@ def output(self, id, subId, mfc):
items = itemsForId[str(subId)]
if items:
for item in items:
# If odd number of hex-digits, pad with 0.
if len(item)%2:
item += "0"
print(self.DialogInitItemFormat.format(mfc, unhexlify(item)))

cpp_literal = bytes_to_cpp_literal(unhexlify(item))
print(self.DialogInitItemFormat.format(mfc, cpp_literal))

class myRcVisitor(rcVisitor):
def visitToolbar_statement(self, ctx):
Expand Down
6 changes: 6 additions & 0 deletions tools/rc2qt/run-rc2qt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
cd $(git rev-parse --show-toplevel)

python tools/rc2qt/rc2qt.py \
libs/famitracker/FamiTracker.rc \
> libs/famitracker/cqtmfc_famitracker.cpp