This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Segment auto export to apk, some extra metadata
- Loading branch information
Showing
4 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import common | ||
import os | ||
import os.path as ospath | ||
import pathlib | ||
import tempfile | ||
import getpass | ||
import math | ||
import time | ||
import hashlib | ||
|
||
def get_time(): | ||
""" | ||
Get the current UNIX timestamp | ||
""" | ||
|
||
return math.floor(time.time()) | ||
|
||
def get_hash(data): | ||
""" | ||
Compute the SHA1 hash of a utf8 string | ||
""" | ||
|
||
return hashlib.sha1(data.encode('utf-8')).hexdigest() | ||
|
||
def get_trace(): | ||
""" | ||
The user trace is the first two hex digits of the SHA1 hash of the user's | ||
username. This means there is only 256 possible values of the trace, so it's | ||
only really useful for confirming that some untampered segments might have | ||
been made by the same person, with a relatively high probability of error. | ||
It is meant so that someone can tell if some segments in a mod without a | ||
given creator name are by the same creator, and for tracking segments in | ||
general, while still trying to minimise privacy risk. | ||
""" | ||
|
||
username = getpass.getuser() | ||
|
||
result = get_hash(username)[:2] | ||
|
||
return result | ||
|
||
def prepare_folders(path): | ||
""" | ||
Make the folders for the file of the given name | ||
""" | ||
|
||
os.makedirs(pathlib.Path(path).parent, exist_ok = True) | ||
|
||
def find_apk(): | ||
""" | ||
Find the path to an APK | ||
""" | ||
|
||
# Search for templates.xml (how we find the APK) and set path | ||
path = "" | ||
|
||
### Try to find from APK Editor Studio ### | ||
|
||
try: | ||
# Get the search path | ||
search_path = tempfile.gettempdir() + "/apk-editor-studio/apk" | ||
|
||
# Enumerate files | ||
dirs = os.listdir(search_path) | ||
|
||
for d in dirs: | ||
cand = str(os.path.abspath(search_path + "/" + d + "/assets/templates.xml.mp3")) | ||
|
||
print("Trying the path:", cand) | ||
|
||
if ospath.exists(cand): | ||
path = str(pathlib.Path(cand).parent) | ||
break | ||
except FileNotFoundError: | ||
print("Smash Hit Tools: No APK Editor Studio folder found.") | ||
|
||
print("Final apk path:", path) | ||
|
||
return path |