Skip to content

Commit

Permalink
<fix> fix _p extraction problem in python2
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymousException committed Jun 6, 2024
1 parent a523daf commit c2c60a4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
27 changes: 23 additions & 4 deletions src/call_game_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def is_64_bit():
return platform.architecture()[0] == '64bit'


def get_python_path(game_path):
game_dir = os.path.dirname(game_path) + '/'
def get_python_path_from_game_dir(game_dir):
lib_list_64 = ['windows-x86_64', 'py2-windows-x86_64', 'py3-windows-x86_64']
lib_list_86 = ['windows-i686', 'py2-windows-i686', 'py3-windows-i686']
python_path = None
Expand All @@ -30,8 +29,12 @@ def get_python_path(game_path):
return python_path


def is_python2(game_path):
python_dir = os.path.dirname(get_python_path(game_path))
def get_python_path_from_game_path(game_path):
game_dir = os.path.dirname(game_path) + '/'
return get_python_path_from_game_dir(game_dir)


def is_python2_with_python_dir(python_dir):
paths = os.walk(python_dir, topdown=False)
is_py2 = False
for path, dir_lst, file_lst in paths:
Expand All @@ -43,6 +46,22 @@ def is_python2(game_path):
return is_py2


def is_python2_from_game_dir(game_dir):
try:
python_dir = os.path.dirname(get_python_path_from_game_dir(game_dir))
except Exception:
return True
return is_python2_with_python_dir(python_dir)


def is_python2_from_game_path(game_path):
try:
python_dir = os.path.dirname(get_python_path_from_game_path(game_path))
except Exception:
return True
return is_python2_with_python_dir(python_dir)


def get_py_path(game_path):
base_name = os.path.splitext(game_path)[0]
return base_name + '.py'
Expand Down
2 changes: 1 addition & 1 deletion src/extraction_official_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from my_log import log_print
from editor_form import open_directory_and_select_file
from extraction_official import Ui_ExtractionOfficialDialog
from call_game_python import get_py_path, get_python_path
from call_game_python import get_py_path
import my_log


Expand Down
4 changes: 2 additions & 2 deletions src/pack_game_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from my_log import log_print
from editor_form import open_directory_and_select_file

from call_game_python import get_py_path, get_python_path
from call_game_python import get_py_path, get_python_path_from_game_path
from pack_game import Ui_PackGameDialog
import add_change_language_entrance_form
import my_log
Expand Down Expand Up @@ -411,7 +411,7 @@ def get_script_file_list(game_dir):
def pack_game_files(path, package_name, pack_list, is_show_directory):
dir = os.path.dirname(path)
game_dir = dir + '/game'
python_path = get_python_path(path)
python_path = get_python_path_from_game_path(path)
if python_path is None:
log_print(f'can not locate python.exe , please check {path}')
target_path = dir + '/game/' + package_name + '.rpa'
Expand Down
34 changes: 21 additions & 13 deletions src/renpy_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pathlib

from my_log import log_print
from call_game_python import is_python2_from_game_dir
from string_tool import remove_upprintable_chars, EncodeBracketContent, EncodeBrackets, replace_all_blank, \
replace_unescaped_quotes

Expand Down Expand Up @@ -70,7 +71,7 @@ def run(self):
log_print(msg)


def ExtractFromFile(p, is_open_filter, filter_length, is_skip_underline):
def ExtractFromFile(p, is_open_filter, filter_length, is_skip_underline, is_py2):
e = set()
f = io.open(p, 'r+', encoding='utf-8')
_read = f.read()
Expand Down Expand Up @@ -102,10 +103,15 @@ def ExtractFromFile(p, is_open_filter, filter_length, is_skip_underline):
continue

if is_in__p:
p_content = p_content + line_content
sep = '\n'
if is_py2:
sep = '\\n'
p_content = p_content + line_content + sep
if line_content.endswith('""")'):
p_content = p_content.strip()[6:-4]
p_content = p_content.rstrip('\n').replace('\n','\\n')
p_content = p_content.rstrip(sep)
if is_py2:
p_content = p_content.strip()[6:-4]
p_content = p_content.rstrip('\n').replace('\n', '\\n')
#log_print(p_content)
if filter_length != 9999:
log_print(f'Found _p() in {p}:{index+1}')
Expand Down Expand Up @@ -235,7 +241,7 @@ def CreateEmptyFileIfNotExsit(p):
open(target, 'w').close()


def GetExtractedSet(p, is_skip_underline):
def GetExtractedSet(p, is_skip_underline, is_py2):
if (p[len(p) - 1] != '/' and p[len(p) - 1] != '\\'):
p = p + '/'
e = set()
Expand All @@ -245,7 +251,7 @@ def GetExtractedSet(p, is_skip_underline):
i = os.path.join(path, file_name)
if (file_name.endswith("rpy") == False):
continue
extracted = ExtractFromFile(i, False, 9999, is_skip_underline)
extracted = ExtractFromFile(i, False, 9999, is_skip_underline, is_py2)
both = e & extracted
if len(both) > 0:
f = io.open(i, 'r', encoding='utf-8')
Expand All @@ -266,7 +272,7 @@ def GetExtractedSet(p, is_skip_underline):
return e


def WriteExtracted(p, extractedSet, is_open_filter, filter_length, is_gen_empty, is_skip_underline):
def WriteExtracted(p, extractedSet, is_open_filter, filter_length, is_gen_empty, is_skip_underline, is_py2):
if (p[len(p) - 1] != '/' and p[len(p) - 1] != '\\'):
p = p + '/'
index = p.rfind('tl\\')
Expand All @@ -293,7 +299,7 @@ def WriteExtracted(p, extractedSet, is_open_filter, filter_length, is_gen_empty,
log_print(target + " not exists skip!")
continue

e = ExtractFromFile(target, is_open_filter, filter_length, is_skip_underline)
e = ExtractFromFile(target, is_open_filter, filter_length, is_skip_underline, is_py2)
eDiff = e - extractedSet
if len(eDiff) > 0:
f = io.open(i, 'a+', encoding='utf-8')
Expand Down Expand Up @@ -360,8 +366,9 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, gl
pass
if (os.path.isfile(target) == False):
open(target, 'w').close()
e = ExtractFromFile(p, is_open_filter, filter_length, is_skip_underline)
extractedSet = ExtractFromFile(target, False, 9999, is_skip_underline)
is_py2 = is_python2_from_game_dir(targetDir.rstrip('/').rstrip('\\') + '/../../../')
e = ExtractFromFile(p, is_open_filter, filter_length, is_skip_underline, is_py2)
extractedSet = ExtractFromFile(target, False, 9999, is_skip_underline, is_py2)
eDiff = e - extractedSet
if len(eDiff) > 0:
f = io.open(target, 'a+', encoding='utf-8')
Expand Down Expand Up @@ -395,7 +402,8 @@ def ExtractWriteFile(p, tl_name, is_open_filter, filter_length, is_gen_empty, gl


def ExtractAllFilesInDir(dirName, is_open_filter, filter_length, is_gen_empty, is_skip_underline):
is_py2 = is_python2_from_game_dir(dirName + '/../../../')
CreateEmptyFileIfNotExsit(dirName)
ret = GetExtractedSet(dirName, is_skip_underline)
WriteExtracted(dirName, ret, is_open_filter, filter_length, is_gen_empty, is_skip_underline)
ret = GetExtractedSet(dirName, is_skip_underline)
ret = GetExtractedSet(dirName, is_skip_underline, is_py2)
WriteExtracted(dirName, ret, is_open_filter, filter_length, is_gen_empty, is_skip_underline, is_py2)
ret = GetExtractedSet(dirName, is_skip_underline, is_py2)

0 comments on commit c2c60a4

Please sign in to comment.