Fix packaging names
This commit is contained in:
parent
85df574d3c
commit
e5fa49ad53
24 changed files with 24 additions and 24 deletions
6
unrenapk/README.md
Normal file
6
unrenapk/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
## RenPy-Android-Unpack
|
||||
A simple Python script for unpacking Ren'Py based .apk and .obb files to ready to use Ren'Py SDK's Project
|
||||
|
||||
### How to use
|
||||
* Put some .apk & .obb files in folder
|
||||
* `rendroid-unpack` (It unpacks all .apk and .obb files in the directory where it is located)
|
0
unrenapk/__init__.py
Normal file
0
unrenapk/__init__.py
Normal file
6
unrenapk/__main__.py
Executable file
6
unrenapk/__main__.py
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from . import application
|
||||
|
||||
if __name__ == '__main__':
|
||||
application.launch()
|
98
unrenapk/actions.py
Executable file
98
unrenapk/actions.py
Executable file
|
@ -0,0 +1,98 @@
|
|||
from zipfile import ZipFile, BadZipFile
|
||||
from PIL import Image
|
||||
import shutil
|
||||
import os
|
||||
|
||||
from .printer import Printer
|
||||
|
||||
|
||||
class Extract:
|
||||
|
||||
def __init__(self, output: str):
|
||||
self.output = output
|
||||
|
||||
@staticmethod
|
||||
def folder(zip_ref: ZipFile, path: str, dest: str):
|
||||
for content in zip_ref.namelist():
|
||||
if content.split('/')[0] == path:
|
||||
zip_ref.extract(content, dest)
|
||||
|
||||
@staticmethod
|
||||
def icon(directory: str):
|
||||
icons = []
|
||||
for folder, folders, files in os.walk(directory):
|
||||
for file in os.listdir(folder):
|
||||
if os.path.splitext(file)[1] == ".png":
|
||||
image = Image.open(f"{folder}/{file}")
|
||||
if image.size[0] == 432 and image.size[1] == 432:
|
||||
icons.append(f"{folder}/{file}")
|
||||
if len(icons) == 0:
|
||||
raise KeyError
|
||||
return icons
|
||||
|
||||
def assets(self, file: str):
|
||||
try:
|
||||
with ZipFile(file, 'r') as zip_ref:
|
||||
self.folder(zip_ref, 'assets', self.output)
|
||||
if os.path.splitext(file)[1] == '.apk':
|
||||
try:
|
||||
# ~Ren'Py 8, 7
|
||||
self.folder(zip_ref, 'res', os.path.join(self.output, 'assets'))
|
||||
for icon in self.icon(os.path.join(self.output, 'assets/res')):
|
||||
os.rename(icon, os.path.join(self.output, "assets", os.path.split(icon)[1]))
|
||||
except KeyError:
|
||||
try:
|
||||
# ~Ren'Py 6
|
||||
zip_ref.extract('res/drawable/icon.png', os.path.join(self.output, 'assets'))
|
||||
os.rename(os.path.join(self.output, 'assets/res/drawable/icon.png'),
|
||||
os.path.join(self.output, 'assets/icon.png'))
|
||||
except KeyError:
|
||||
Printer.warn("Icon not found. Maybe it is not supported apk?")
|
||||
except BadZipFile:
|
||||
Printer.err("Cant extract .apk file!")
|
||||
|
||||
|
||||
class Rename:
|
||||
|
||||
def __init__(self, output):
|
||||
self.output = output
|
||||
|
||||
def files(self, directory: str):
|
||||
for dir_ in os.walk(os.path.join(self.output, directory)):
|
||||
for file in dir_[2]:
|
||||
path = f'{dir_[0]}/{file}'
|
||||
folder = '/'.join(path.split('/')[:len(path.split('/')) - 1])
|
||||
newname = f'{path.split("/").pop().replace("x-", "")}'
|
||||
os.rename(path, f'{folder}/{newname}')
|
||||
|
||||
def dirs(self, directory: str):
|
||||
dirs = []
|
||||
for dir_ in os.walk(os.path.join(self.output, directory)):
|
||||
dirs.append(dir_[0])
|
||||
dirs.reverse()
|
||||
dirs.pop()
|
||||
for dir__ in dirs:
|
||||
folder = '/'.join(dir__.split('/')[:len(dir__.split('/')) - 1])
|
||||
newname = f'{dir__.split("/").pop().replace("x-", "")}'
|
||||
os.rename(dir__, f'{folder}/{newname}')
|
||||
|
||||
|
||||
class Actions:
|
||||
|
||||
def __init__(self, output: str):
|
||||
self.output = output
|
||||
|
||||
def extract(self) -> Extract:
|
||||
return Extract(self.output)
|
||||
|
||||
def rename(self) -> Rename:
|
||||
return Rename(self.output)
|
||||
|
||||
def clean(self, names: list, ignore: bool):
|
||||
for name in names:
|
||||
name = os.path.join(self.output, name)
|
||||
try:
|
||||
shutil.rmtree(name)
|
||||
except FileNotFoundError:
|
||||
if not ignore:
|
||||
Printer.warn(f"Path {name} not found!")
|
51
unrenapk/application.py
Normal file
51
unrenapk/application.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python3
|
||||
import colorama
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
|
||||
from .printer import Printer
|
||||
from .actions import Actions
|
||||
|
||||
|
||||
def args_init():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='unrenapk',
|
||||
description='Extract Ren\'Py .apk and .obb files into Ren\'Py SDK\'s project'
|
||||
)
|
||||
parser.add_argument('path')
|
||||
parser.add_argument('-o', '--output')
|
||||
return parser.parse_args()
|
||||
|
||||
def launch():
|
||||
if sys.platform == "win32":
|
||||
colorama.init()
|
||||
args = args_init()
|
||||
if args.output:
|
||||
output = args.output
|
||||
else:
|
||||
output = ''
|
||||
actions = Actions(output)
|
||||
printer = Printer()
|
||||
|
||||
filename = args.path
|
||||
if os.path.splitext(filename)[1] == '.apk' or os.path.splitext(filename)[1] == '.obb':
|
||||
actions.clean(['assets'], True)
|
||||
|
||||
printer.info(f'Extracting assets from {filename}... ')
|
||||
actions.extract().assets(filename)
|
||||
|
||||
printer.info('Renaming game assets... ')
|
||||
actions.rename().files('assets')
|
||||
actions.rename().dirs('assets')
|
||||
|
||||
printer.info('Removing unneeded files... ')
|
||||
if os.path.splitext(filename)[1] == '.apk':
|
||||
actions.clean(['assets/renpy', 'assets/res'], False)
|
||||
actions.clean(['assets/dexopt'], True)
|
||||
|
||||
printer.info('Renaming directory... ')
|
||||
actions.clean([os.path.splitext(filename)[0]], True)
|
||||
os.rename(os.path.join(output, 'assets'), os.path.splitext(filename)[0])
|
||||
else:
|
||||
Printer.err("It's not an .apk or .obb file!")
|
14
unrenapk/printer.py
Normal file
14
unrenapk/printer.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
class Printer:
|
||||
|
||||
@staticmethod
|
||||
def info(msg: str):
|
||||
print(f"\033[100m[INFO] {msg}\033[49m")
|
||||
|
||||
@staticmethod
|
||||
def warn(msg: str):
|
||||
print(f"\033[93m[WARN]\033[0m {msg}\033[49m")
|
||||
|
||||
@staticmethod
|
||||
def err(msg: str):
|
||||
print(f"\033[31m[ERROR]\033[0m {msg} Exiting...\033[49m")
|
||||
exit()
|
Loading…
Add table
Add a link
Reference in a new issue