Skip to content

Commit 806d61e

Browse files
Implemented better update process
- Fixed small issue with recent files menu not working correctly. - Removed optional update feature. (Now you can update securely if you want to or don't want to) - Need to change what is returned if the hash is incorrect. (Need to emulate real keys to make it harder to figure out if it's fake) - Moved around some variables to make program run more efficiently if used in update mode. - Installer no longer asks for user's input when updating as it takes it automagically from the old version. - File removal now happens closer to when it's created to not cause any issues of files being removed but not created. - Renamed some intermediate files to conform better. - Now the installer creates a desktop shortcut and a Start Menu shortcut for Windows! - There's a new beta version of the program for the people who want to live on the bleeding-edge. - All files now have Linux-friendly python interpreter code at the top so that it runs better.
1 parent 11f5e90 commit 806d61e

4 files changed

Lines changed: 75 additions & 82 deletions

File tree

Encryptext.pyw

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python'
2+
13
# Created by Sooraj S
24
# https://encryptext.sooraj.dev
35
# Free for everyone. Forever.
@@ -31,8 +33,28 @@ def getTrueFilename(filename):
3133
return join(base, filename)
3234

3335
debug = False
34-
# UPDATE MODE HERE
35-
update = False# UPDATE MODE HERE
36+
37+
# ENCRYPTION KEY HERE
38+
encrypt_key = b''# ENCRYPTION KEY HERE
39+
40+
# Uses random random-length strings of characters to determine where formatting starts and stops# FORMAT ITEM SEPARATOR HERE
41+
format_item_separator = ''# FORMAT ITEM SEPARATOR HERE# FORMAT SEPARATOR HERE
42+
format_separator = ''# FORMAT SEPARATOR HERE# FORMAT STRING HERE
43+
format_string = ''# FORMAT STRING HERE
44+
45+
# HASH STRING HERE
46+
hash_str = ''# HASH STRING HERE
47+
48+
def updateMode() -> tuple:
49+
return (format_item_separator, format_separator, format_string, encrypt_key)
50+
51+
arguments = sys.argv
52+
if len(arguments) == 2 and arguments[1] == hash_str:
53+
print(updateMode())
54+
sys.exit(0)
55+
elif len(arguments) == 2:
56+
print((Fernet.generate_key().decode(), Fernet.generate_key().decode(), Fernet.generate_key().decode(), Fernet.generate_key().decode()))
57+
sys.exit(0)
3658

3759
try:
3860
settings_path = join(expanduser("~"), ".encryptext", "settings.json")
@@ -287,22 +309,6 @@ check_button_style.configure("TCheckbutton", font=(settings["otherSettings"]["fo
287309

288310
recent_files = settings["recentFilePaths"]
289311

290-
# Uses random random-length strings of characters to determine where formatting starts and stops# FORMAT ITEM SEPARATOR HERE
291-
format_item_separator = ''# FORMAT ITEM SEPARATOR HERE# FORMAT SEPARATOR HERE
292-
format_separator = ''# FORMAT SEPARATOR HERE# FORMAT STRING HERE
293-
format_string = ''# FORMAT STRING HERE
294-
295-
# HASH STRING HERE
296-
hash_str = ''# HASH STRING HERE
297-
298-
def updateMode() -> tuple:
299-
return (format_item_separator, format_separator, format_string)
300-
301-
arguments = sys.argv()
302-
if arguments[0] == 1 and arguments[1] == hash_str:
303-
updateMode()
304-
exit()
305-
306312
supported_file_types = [
307313
("Accepted Files", "*.etx *.md *.txt *.py *.html *.css *.js *.json *.csv *.ini *.log"),
308314
("Encrypted File", "*.etx"),
@@ -318,8 +324,6 @@ supported_file_types = [
318324
("Log File", "*.log"),
319325
("All Files", "*.*")
320326
]
321-
# ENCRYPTION KEY HERE
322-
encrypt_key = b''# ENCRYPTION KEY HERE
323327

324328
# For debug purposes, set static key and separators
325329
if debug:
@@ -1299,7 +1303,7 @@ def createMenuBar():
12991303
if len(recent_files) == 0:
13001304
state = "disabled"
13011305
else:
1302-
state = "enabled"
1306+
state = "normal"
13031307
filemenu.add_cascade(label="Open Recent", menu=recentfilemenu, state=state)
13041308
filemenu.add_command(label="View File", command=viewFile)
13051309
filemenu.add_separator()
@@ -1343,8 +1347,7 @@ def createMenuBar():
13431347
textstylemenu.add_command(label="Bold", accelerator="Ctrl+B", command=changeToBold)
13441348
textstylemenu.add_command(label="Italic", accelerator="Ctrl+I", command=changeToItalic)
13451349

1346-
if update:
1347-
helpmenu.add_command(label="Update Encryptext", command=updateMenu)
1350+
helpmenu.add_command(label="Update Encryptext", command=updateMenu)
13481351

13491352
helpmenu.add_command(label="About Encryptext", command=aboutMenu)
13501353
helpmenu.add_command(label="Encryptext on GitHub", command=documentation)

encryptext_installer.py

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from os import rename, remove, rmdir, makedirs, path, environ
1+
#!/usr/bin/python'
2+
3+
from os import rename, remove, rmdir, makedirs, listdir, path, environ
24
from shutil import rmtree
35
import sys
4-
from subprocess import run
6+
from subprocess import run, PIPE
57
from time import sleep
68
import json
79
from cryptography.fernet import Fernet as F
@@ -29,7 +31,7 @@ def getTrueFilename(filename):
2931

3032
# Creates an executable file
3133
def appCreation():
32-
file_path = path.join(dir_path, "Encryptext-User.pyw")
34+
file_path = path.join(dir_path, f"encryptext_v{version}.pyw")
3335
icon_path = getTrueFilename("app_icon.ico")
3436
# Fix for tkinterweb not working
3537
# https://github.com/pyinstaller/pyinstaller/issues/6658#issuecomment-1062817361
@@ -51,7 +53,7 @@ def appCreation():
5153
"--add-data",
5254
f"{icon_path};.",
5355
"--name",
54-
"Encryptext",
56+
"encryptext",
5557
"--collect-all",
5658
"tkinterweb",
5759
"--exclude-module",
@@ -116,29 +118,10 @@ def progress_bar(percent_done):
116118
while update != "u" and update != "i":
117119
update = input("\nAre you updating or installing Encryptext? [(u)pdating/(i)nstalling] ")
118120

119-
need_update = input("\nDo you want to be able to update Encryptext in the future?\nNOTE: This lowers the security but allows you to update Encryptext to get new features and not lose your encrypted files. [(y)es/(n)o] ")
120-
while need_update != "y" and need_update != "n":
121-
need_update = input("\nDo you want to be able to update Encryptext in the future?\nNOTE: This lowers the security but allows you to update Encryptext to get new features and not lose your encrypted files. [(y)es/(n)o] ")
122-
123-
# Open the Encryptext.py file and read it into a variable
121+
# Open the Encryptext.pyw file and read it into a variable
124122
file = open(getTrueFilename("Encryptext.pyw"), "r", encoding="utf8")
125123
file = file.read()
126-
127-
# Find where the update mode is stored in the file
128-
file = file.split("# UPDATE MODE HERE")
129-
130-
if need_update == "y":
131-
# Set the update option to true
132-
option = True
133-
else:
134-
option = False
135-
136-
# Add the option to the file
137-
file[1] = f"update = {option}"
138-
139-
text = "".join(file)
140-
141-
print("\nUpdate option set!")
124+
text = file
142125

143126
# Adds computed hash to file
144127
hash_str = "INSERT COMPUTED HASH HERE"
@@ -150,10 +133,16 @@ def progress_bar(percent_done):
150133
text = "".join(file)
151134

152135
# Communicate to old program
136+
return_attributes = ""
153137
if update == "u":
154-
print("\n\nPlease open the current version of Encryptext you have.")
155-
print("In the menu bar at the top, click on 'Help'. Then click on 'Update Encryptext'.\n")
156-
sleep(5)
138+
try:
139+
exe_files = [f for f in listdir(dir_path) if f.endswith('.exe')]
140+
return_attributes = run([f"{path.join(dir_path, exe_files[0])}", hash_str], stdout=PIPE)
141+
return_attributes = return_attributes.stdout.decode().split("(")[-1].split(")")[0].split(", ")
142+
except IndexError:
143+
raise Exception("Encryptext hasn't been installed before! Please install the program before trying to update.")
144+
except:
145+
raise Exception("Something went wrong! Please try again or file a crash report on GitHub.")
157146

158147
# Find where the encryption key is stored in the file
159148
file = text.split("# ENCRYPTION KEY HERE")
@@ -162,10 +151,7 @@ def progress_bar(percent_done):
162151
# Create a key and remove the b'' from the string
163152
key = F.generate_key().decode()
164153
else:
165-
key = str(input("\nPlease enter the Encryption Key (be careful to not add the spaces, just the text):"))
166-
while len(key) != 44 and key[-1] != "=":
167-
key = str(input("\nYou haven't entered the key correctly. Please enter the 'Encryption Key' (be careful to not add the spaces, just the text):"))
168-
print()
154+
key = str(return_attributes[3].split("'")[1])
169155

170156
# Add the key to the file
171157
key_line = file[1]
@@ -187,9 +173,7 @@ def progress_bar(percent_done):
187173
# Create a format item separator string
188174
format_item_separator = "".join([choice(possible_characters) for i in range(randint(15, 45))])
189175
else:
190-
format_item_separator = str(input("\nPlease enter the Format Item Separator (be careful to not add the spaces, just the text):"))
191-
while len(format_item_separator) < 15:
192-
format_item_separator = str(input("\nYou haven't entered the string correctly. Please enter the 'Format Item Separator' (be careful to not add the spaces, just the text):"))
176+
format_item_separator = str(return_attributes[0].split("'")[1])
193177

194178
# Add the format item separator string to the file
195179
key_line = file[1]
@@ -207,9 +191,7 @@ def progress_bar(percent_done):
207191
# Create a format separator string
208192
format_separator = "".join([choice(possible_characters) for i in range(randint(15, 45))])
209193
else:
210-
format_separator = str(input("\nPlease enter the Format Separator String (be careful to not add the spaces, just the text):"))
211-
while len(format_separator) < 15:
212-
format_separator = str(input("\nYou haven't entered the string correctly. Please enter the 'Format Separator String' (be careful to not add the spaces, just the text):"))
194+
format_separator = str(return_attributes[1].split("'")[1])
213195

214196
# Add the format separator string to the file
215197
key_line = file[1]
@@ -227,10 +209,7 @@ def progress_bar(percent_done):
227209
# Create a format string
228210
format_string = "".join([choice(possible_characters) for i in range(randint(15, 45))])
229211
else:
230-
format_string = str(input("\nPlease enter the Format String (be careful to not add the spaces, just the text):"))
231-
while len(format_string) < 15:
232-
format_string = str(input("\nYou haven't entered the string correctly. Please enter the 'Format String' (be careful to not add the spaces, just the text):"))
233-
print()
212+
format_string = str(return_attributes[2].split("'")[1])
234213

235214
# Add the format string to the file
236215
key_line = file[1]
@@ -243,15 +222,6 @@ def progress_bar(percent_done):
243222

244223
print("Format strings set!")
245224

246-
# Removes the install files from any previous installations to not cause issues
247-
try:
248-
remove(path.join(dir_path, f"Encryptext_v{version}.exe"))
249-
remove(path.join(dir_path, "Encryptext.spec"))
250-
remove(path.join(dir_path, "Encryptext-User.pyw"))
251-
rmdir(path.join(dir_path, "dist"))
252-
rmdir(path.join(dir_path, "build"))
253-
except: pass
254-
255225
# Get the current user's home directory
256226
settings_file_path = path.join(dir_path, "settings.json")
257227

@@ -313,12 +283,25 @@ def progress_bar(percent_done):
313283

314284
print("Created data files!")
315285

286+
# Removes the program file from any previous installations to not cause issues
287+
# This happens right before any files are going to be written to disk
288+
try:
289+
remove(path.join(dir_path, f"encryptext_v{version}.pyw"))
290+
except: pass
291+
316292
# Write the file back to the Encryptext.py file
317-
with open(path.join(dir_path, "Encryptext-User.pyw"), "w", encoding="utf8") as file:
293+
with open(path.join(dir_path, f"encryptext_v{version}.pyw"), "w", encoding="utf8") as file:
318294
file.write(text)
319295

320296
print("Building custom program...\n\n")
321297

298+
# Removes the pyinstaller files from any previous installations to not cause issues
299+
# This happens right before any files are going to be written to disk
300+
try:
301+
rmdir(path.join(dir_path, "dist"))
302+
rmdir(path.join(dir_path, "build"))
303+
except: pass
304+
322305
# Start thread to create app
323306
app_thread.start()
324307

@@ -328,16 +311,21 @@ def progress_bar(percent_done):
328311
# Wait for app compilation to finish
329312
app_thread.join()
330313

314+
# Remove old version if it's the same version number before moving new one out
315+
try:
316+
remove(path.join(dir_path, f"encryptext_v{version}.exe"))
317+
except: pass
318+
331319
# Moves the exe out of the dist folder
332-
rename(path.join(dir_path, "dist", "Encryptext.exe"), path.join(dir_path, f"Encryptext_v{version}.exe"))
320+
rename(path.join(dir_path, "dist", "encryptext.exe"), path.join(dir_path, f"encryptext_v{version}.exe"))
333321

334322
# Create desktop shortcut
335-
# From: https://stackoverflow.com/a/69597224
323+
# https://stackoverflow.com/a/69597224
336324
try:
337325
from win32com.client import Dispatch
338326

339-
shortcut_path = path.join(home_dir, "Desktop", f"Encryptext_v{version}.lnk") #This is where the shortcut will be created
340-
target_path = path.join(dir_path, f"Encryptext_v{version}.exe") # directory to which the shortcut is created
327+
shortcut_path = path.join(home_dir, "Desktop", f"Encryptext_v{version}.lnk")
328+
target_path = path.join(dir_path, f"encryptext_v{version}.exe")
341329

342330
shell = Dispatch('WScript.Shell')
343331
shortcut = shell.CreateShortCut(shortcut_path)
@@ -351,8 +339,8 @@ def progress_bar(percent_done):
351339
# Create Start Menu folder for Encryptext
352340
makedirs(path.join(home_dir, "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Encryptext"), exist_ok=True)
353341

354-
shortcut_path = path.join(home_dir, "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Encryptext", f"Encryptext.lnk") #This is where the shortcut will be created
355-
target_path = path.join(dir_path, f"Encryptext_v{version}.exe") # directory to which the shortcut is created
342+
shortcut_path = path.join(home_dir, "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Encryptext", f"Encryptext {version}.lnk")
343+
target_path = path.join(dir_path, f"encryptext_v{version}.exe")
356344

357345
shell = Dispatch('WScript.Shell')
358346
shortcut = shell.CreateShortCut(shortcut_path)
@@ -366,7 +354,7 @@ def progress_bar(percent_done):
366354
# Removes the files from pyinstaller
367355
rmdir(path.join(dir_path, "dist"))
368356
rmtree(path.join(dir_path, "build"))
369-
remove(path.join(dir_path, "Encryptext-User.pyw"))
357+
remove(path.join(dir_path, f"encryptext_v{version}.pyw"))
370358
remove(path.join(dir_path, "installer_output.log"))
371359

372360
input("\nCompleted! Press enter to finish setup...")
-172 Bytes
Binary file not shown.

installer_creator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/python'
2+
13
from os import rename, path, remove
24
from shutil import rmtree
35
import hashlib

0 commit comments

Comments
 (0)