Skip to content

Now extracts files with forbidden symbols in name#2

Open
Kistras wants to merge 2 commits intolokkju:masterfrom
Kistras:master
Open

Now extracts files with forbidden symbols in name#2
Kistras wants to merge 2 commits intolokkju:masterfrom
Kistras:master

Conversation

@Kistras
Copy link
Copy Markdown

@Kistras Kistras commented Oct 2, 2021

Creates "?Datalist" files and alike
Fixes? #1
Now opens Star trek online files

Creates "?Datalist" files and alike
@Kistras Kistras changed the title Now works properly Now extracts files with forbidden symbols in name Oct 2, 2021
@lokkju
Copy link
Copy Markdown
Owner

lokkju commented Jan 22, 2022

I've been distracted, but this is a good catch. That said, I'd like to see it log and report the original filename to the user; or, if possible, escape any special filename chars. One of the goal is to be able to rebuild the hogg, for which we'd need the full filename

@Kistras
Copy link
Copy Markdown
Author

Kistras commented Nov 30, 2022

I'd like to see it log and report the original filename to the user; or, if possible, escape any special filename chars. One of the goal is to be able to rebuild the hogg, for which we'd need the full filename

I'm probably way too late for that, but I done that now. It's a bit clunky, but should work.
You can rebuild the name by using the following example code:

fn = "i'2:3**4.,m2?/s?><q%|help|+asd%2"
forbiddensymb = ["%", ":", "*", "?", ">", "<", "|", "+"] # "%" has to go first, otherwise you might replace it in wrong places
print(fn) # i'2:3**4.,m2?/s?><q%|help|+asd%2

# Encoding
for k, sym in enumerate(forbiddensymb):
    fn = fn.replace(sym, f"%{k}")
print(fn) # i'2%13%2%24.,m2%3/s%3%4%5q%0%6help%6%7asd%02

# Decoding
# It has to go in reversed order, otherwise "%" will get replaced way too soon, breaking filename as a result.
# I'm using reversed(list(enumerate(k))) to iterate through list backwards while still receiving correct item indexes.
for k, sym in reversed(list(enumerate(forbiddensymb))):
    fn = fn.replace(f"%{k}", sym)

print(fn) # i'2:3**4.,m2?/s?><q%|help|+asd%2

Note that forbiddensymb list is expected to be the same when you both encode and decode, otherwise some errors might arise.
probably should've changed the name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants