Update Picocrypt.py
This commit is contained in:
parent
62242034f7
commit
d6996ef9bb
|
@ -29,12 +29,17 @@ from tkinterdnd2 import TkinterDnD,DND_FILES
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import rmtree,copyfile,copytree
|
from shutil import rmtree,copyfile,copytree
|
||||||
|
from time import sleep
|
||||||
import sys
|
import sys
|
||||||
import tkinter
|
import tkinter
|
||||||
import tkinter.ttk
|
import tkinter.ttk
|
||||||
import tkinter.scrolledtext
|
import tkinter.scrolledtext
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import platform
|
import platform
|
||||||
|
try:
|
||||||
|
import winreg as wr
|
||||||
|
except:
|
||||||
|
pass
|
||||||
from creedsolo import RSCodec,ReedSolomonError
|
from creedsolo import RSCodec,ReedSolomonError
|
||||||
|
|
||||||
# Tk/Tcl is a little barbaric, so I'm disabling
|
# Tk/Tcl is a little barbaric, so I'm disabling
|
||||||
|
@ -288,16 +293,58 @@ def checkContextMenuBinded():
|
||||||
contextMenuMenuOff.set(1)
|
contextMenuMenuOff.set(1)
|
||||||
|
|
||||||
def bindContextMenu():
|
def bindContextMenu():
|
||||||
target = pathJoin(expanduser("~"),*"/AppData/Roaming/Microsoft/Windows/SendTo/Picocrypt.exe".split("/"))
|
tmp = Path(rootDir).parent.absolute()
|
||||||
force = messagebox.askyesno("Confirmation","Please select Picocrypt.exe in the next step.")
|
target = pathJoin(expanduser("~"),"Picocrypt")
|
||||||
if force:
|
vbs = pathJoin(target,"add_files.vbs")
|
||||||
tmp = filedialog.askopenfilename(
|
|
||||||
initialdir=expanduser("~")
|
if exists(target):
|
||||||
|
rmtree(target)
|
||||||
|
copytree(tmp,target)
|
||||||
|
|
||||||
|
keyVal = "Directory\\Shell\\Enc\\command"
|
||||||
|
try:
|
||||||
|
key = wr.OpenKey(
|
||||||
|
wr.HKEY_CLASSES_ROOT,
|
||||||
|
keyVal,
|
||||||
|
0,
|
||||||
|
wr.KEY_ALL_ACCESS
|
||||||
)
|
)
|
||||||
if not tmp:
|
except WindowsError:
|
||||||
return
|
key = wr.CreateKey(wr.HKEY_CLASSES_ROOT,keyVal)
|
||||||
copyfile(tmp,target)
|
|
||||||
checkContextMenuBinded()
|
regEntry = (r'wscript "{}" "%1"'.format(vbs))
|
||||||
|
wr.SetValueEx(key,"",0,wr.REG_SZ,regEntry)
|
||||||
|
wr.CloseKey(key)
|
||||||
|
|
||||||
|
keyVal = "*\\Shell\\Enc\\command"
|
||||||
|
try:
|
||||||
|
key = wr.OpenKey(
|
||||||
|
wr.HKEY_CLASSES_ROOT,
|
||||||
|
keyVal,
|
||||||
|
0,
|
||||||
|
wr.KEY_ALL_ACCESS
|
||||||
|
)
|
||||||
|
except WindowsError:
|
||||||
|
key = wr.CreateKey(wr.HKEY_CLASSES_ROOT,keyVal)
|
||||||
|
regEntry = (r'wscript "{}" "%1"'.format(vbs))
|
||||||
|
wr.SetValueEx(key,"",0,wr.REG_SZ,regEntry)
|
||||||
|
wr.CloseKey(key)
|
||||||
|
|
||||||
|
a = open(vbs,"rb")
|
||||||
|
b = a.read().decode("utf-8")
|
||||||
|
a.close()
|
||||||
|
b = b.replace("PICOCRYPT_PATH",target)
|
||||||
|
a = open(vbs,"wb")
|
||||||
|
a.write(b.encode("utf-8"))
|
||||||
|
a.close()
|
||||||
|
|
||||||
|
a = open(vbs.replace(".vbs",".bat"),"rb")
|
||||||
|
b = a.read().decode("utf-8")
|
||||||
|
a.close()
|
||||||
|
b = b.replace("PICOCRYPT_PATH",target)
|
||||||
|
a = open(vbs.replace(".vbs",".bat"),"wb")
|
||||||
|
a.write(b.encode("utf-8"))
|
||||||
|
a.close()
|
||||||
|
|
||||||
def unbindContextMenu():
|
def unbindContextMenu():
|
||||||
tmp = pathJoin(expanduser("~"),*"/AppData/Roaming/Microsoft/Windows/SendTo/Picocrypt.exe".split("/"))
|
tmp = pathJoin(expanduser("~"),*"/AppData/Roaming/Microsoft/Windows/SendTo/Picocrypt.exe".split("/"))
|
||||||
|
@ -1240,6 +1287,26 @@ def prepare():
|
||||||
system("sdelete64.exe /accepteula")
|
system("sdelete64.exe /accepteula")
|
||||||
checkContextMenuBinded()
|
checkContextMenuBinded()
|
||||||
|
|
||||||
|
def awaitFiles():
|
||||||
|
a = open(files,"rb")
|
||||||
|
b = a.read().decode("utf-8")
|
||||||
|
a.close()
|
||||||
|
while True:
|
||||||
|
sleep(5)
|
||||||
|
a = open(files,"rb")
|
||||||
|
c = a.read().decode("utf-8")
|
||||||
|
a.close()
|
||||||
|
if b==c:
|
||||||
|
b = c
|
||||||
|
break
|
||||||
|
|
||||||
|
a.close()
|
||||||
|
b = b.replace("\r\n"," ").replace('"',"")
|
||||||
|
remove(files)
|
||||||
|
remove(files.replace("files.txt","tmp.txt"))
|
||||||
|
inputSelected(b)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# Close window only if not encrypting or decrypting
|
# Close window only if not encrypting or decrypting
|
||||||
def onClose():
|
def onClose():
|
||||||
global outputFile
|
global outputFile
|
||||||
|
@ -1255,13 +1322,20 @@ if __name__=="__main__":
|
||||||
# Create Reed-Solomon header codec
|
# Create Reed-Solomon header codec
|
||||||
tmp = Thread(target=createRsc,daemon=True)
|
tmp = Thread(target=createRsc,daemon=True)
|
||||||
tmp.start()
|
tmp.start()
|
||||||
|
|
||||||
# Prepare application
|
# Prepare application
|
||||||
tmp = Thread(target=prepare,daemon=True)
|
tmp = Thread(target=prepare,daemon=True)
|
||||||
tmp.start()
|
tmp.start()
|
||||||
|
|
||||||
# Context menu select file
|
# Windows context menu
|
||||||
if len(sys.argv)>1:
|
if platform.system()=="Windows":
|
||||||
inputSelected("{"+sys.argv[1]+"}")
|
try:
|
||||||
|
files = pathJoin(Path(rootDir).parent.absolute(),"files.txt")
|
||||||
|
getsize(files)
|
||||||
|
tmp = Thread(target=awaitFiles,daemon=True)
|
||||||
|
tmp.start()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Start tkinter
|
# Start tkinter
|
||||||
tk.protocol("WM_DELETE_WINDOW",onClose)
|
tk.protocol("WM_DELETE_WINDOW",onClose)
|
||||||
|
|
Loading…
Reference in New Issue