Created
August 27, 2024 22:54
-
-
Save NotStatilko/52ffceb81f8a72c10bc0286474767789 to your computer and use it in GitHub Desktop.
Fingerprint fix for Windows (v1.6)
This file contains hidden or 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 little module will update Fingerprints of local files | |
to v1.6. This is an important change in TGBOX Protocol. | |
[THIS IS FOR WINDOWS ONLY] | |
Please note that without updating fingerprints your Box | |
will have DUPLICATE files. For example, if you already | |
uploaded (e.g) "C:\\Users\\User\\file.txt" and you will | |
push it again, it will be NOT rejected but re-uploaded | |
as DIFFERENT (completely new) file!! | |
| TO FIX THIS YOU CAN | | |
1) Use this module within TGBOX-CLI. | |
Connect your Box to CLI and type | |
tgbox-cli python --execute FIX_1_6.py --non-interactive | |
2) Run this module directly as "python FIX_1_6.py" | |
3) If (for some reason) you don't want to use this module: | |
You can clear your LocalBox FILES and made a Deep Sync. | |
[This may take some time if You have many files] | |
Within TGBOX-CLI: | |
tgbox-cli file-remove --local-only | |
tgbox-cli box-sync --deep | |
Within Python: | |
... # Here should be all imports and DecryptedLocalBox in dlb | |
from tgbox.api.sync import sync_agen | |
ids = [dlbf.id for dlbf in sync_agen(dlb.files())] | |
tgbox.sync(dlb.delete_files(lbf_ids=ids)) | |
tgbox.sync(dlb.sync(deep=True)) | |
""" | |
try: | |
import tgbox | |
if tgbox.defaults.MINOR_VERSION != 6: | |
print( | |
'\nx You should run this script from v1.6 with latest commits!\n' | |
' Go to https://github/NonProjects/tgbox\n' | |
) | |
exit(1) | |
except ModuleNotFoundError: | |
print('\nx Can not find `tgbox` package. Check your env.\n') | |
exit(1) | |
from os import getenv | |
from pathlib import Path | |
if getenv('TGBOX_CLI_SK') and __name__ == '__main__': | |
print( | |
'\nx (CLI) Please run this script from the TGBOX-CLI. I.e:\n' | |
f'tgbox-cli python --execute {Path(__file__).name} --non-interactive\n' | |
) | |
exit(1) | |
if getenv('TGBOX_CLI_SK') and __name__ != '__main__': | |
if not Objects.dlb: | |
print('\nx Please connect your Box to CLI firstly!\n') | |
exit(1) | |
dlb = Objects.dlb | |
else: | |
lb_path = input('\n@ Path to your LocalBox file: ') | |
lb_pass = input('# Box phrase (INPUT VISIBLE): ') | |
# You can change here N, p, r or Salt or whole | |
# basekey making func if your setup is different. | |
basekey = tgbox.keys.make_basekey(lb_pass.encode()) | |
dlb = tgbox.sync(tgbox.api.local.get_localbox(basekey, lb_path)) | |
from tgbox.api.sync import sync_agen | |
for dlbf in sync_agen(dlb.files()): | |
fingerprint = tgbox.tools.make_file_fingerprint( | |
mainkey = dlb.mainkey, | |
file_path = (dlbf.file_path / dlbf.file_name) | |
) | |
if fingerprint == dlbf.fingerprint: | |
print( | |
f'% ID{dlbf.id} fingerprint is up to date ' | |
f'({fingerprint.hex()[:8]}...)! Skip...' | |
) | |
continue | |
sql_tuple = ( | |
'UPDATE FILES SET FINGERPRINT=? WHERE ID=?', | |
(fingerprint, dlbf.id) | |
) | |
tgbox.sync(dlb.tgbox_db.FILES.execute(sql_tuple, commit=False)) | |
print( | |
f'\n% ID{dlbf.id} FINGERPRINT({dlbf.fingerprint.hex()}) ->\n' | |
f' FINGERPRINT({fingerprint.hex()}) (FIX)' | |
) | |
tgbox.sync(dlb.tgbox_db.FILES.commit()) | |
tgbox.sync(dlb.done()) | |
print('\nv Updated all fingerprints. Done! :)\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment