Skip to content

Commit

Permalink
Bug fixes & improvements
Browse files Browse the repository at this point in the history
- Improved how the installer inserts values into the compilation file.
- Version number is back to being hard-coded as users can have multiple versions of Encryptext installed which can all show up as the latest version.
- Removed update menu option as updates can happen *automagically* when installing new versions.
- Added better checks when saving file to not cause any edge case errors.
- Installer now adds the version number when compiling the program.
- Shortened the `installer_creator.py` file by a few lines by removing redundant code.
- Closed #74
  • Loading branch information
WhenLifeHandsYouLemons committed Apr 10, 2024
1 parent 316ec2d commit 25b86ac
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 115 deletions.
65 changes: 22 additions & 43 deletions Encryptext.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ def getTrueFilename(filename):
base = abspath(".")
return join(base, filename)

debug = False
debug = True
version = "VERSION NUMBER HERE"

# ENCRYPTION KEY HERE
encrypt_key = b''# ENCRYPTION KEY HERE
hash_str = "HASH STRING HERE"
encrypt_key = b"ENCRYPTION KEY HERE"

# Uses random random-length strings of characters to determine where formatting starts and stops# FORMAT ITEM SEPARATOR HERE
format_item_separator = ''# FORMAT ITEM SEPARATOR HERE# FORMAT SEPARATOR HERE
format_separator = ''# FORMAT SEPARATOR HERE# FORMAT STRING HERE
format_string = ''# FORMAT STRING HERE

# HASH STRING HERE
hash_str = ''# HASH STRING HERE
# Uses random random-length strings of characters to determine where formatting starts and stops
format_item_separator = "FORMAT ITEM SEPARATOR HERE"
format_separator = "FORMAT SEPARATOR HERE"
format_string = "FORMAT STRING HERE"

def updateMode() -> tuple:
return (format_item_separator, format_separator, format_string, encrypt_key)
Expand Down Expand Up @@ -76,9 +74,10 @@ try:
settings[key] = False
elif value == "true":
settings[key] = True

version = f"{'.'.join(version.split('.')[0:-1])} (build {version.split('.')[-1]})"
except FileNotFoundError:
settings = {
"version": "'Encryptext Travel Mode'",
"recentFilePaths": [],
"maxRecentFiles": 0,
"otherSettings": {
Expand All @@ -95,7 +94,8 @@ except FileNotFoundError:
}
}

version = f"{'.'.join(settings['version'].split('.')[0:-1])} (build {settings['version'].split('.')[-1]})"
version = "'Encryptext Travel Mode'"

font_scale_factor = settings["otherSettings"]["fontScaleFactor"]

"""
Expand Down Expand Up @@ -365,8 +365,6 @@ root.iconbitmap(getTrueFilename("app_icon.ico"))
"""
Variables
"""
update_file_title = " DO NOT SAVE THIS FILE "

file_save_locations = []
file_extensions = []

Expand Down Expand Up @@ -445,10 +443,17 @@ def updateTags():
tags_used = textboxes[current_tab].tag_names()
i = 0

# Convert the tuple into a list to remove the "sel" tag
# The "sel" tag caused issues when saving if there was text selected
# Convert the tuple into a list to remove the "sel" and "current_line" tag
# These tags caused issues when saving
tags_used = list(tags_used)
tags_used.remove("sel")
try:
tags_used.remove("sel")
finally:
try:
# Throws an error if highlightActiveLine setting isn't on
tags_used.remove("current_line")
except ValueError: pass

for tag in tags_used:
indices = textboxes[current_tab].tag_ranges(tag)
for start, end in zip(indices[::2], indices[1::2]):
Expand Down Expand Up @@ -1010,11 +1015,6 @@ def editingMode(Event=None):
if current_tab == -1:
return None

# Don't allow the encryption key tab to be edited
tab_title = tab_panes.tab(tab_panes.tabs()[getCurrentTab()])["text"]
if tab_title == update_file_title:
return None

# Set the textbox to be writable
textboxes[current_tab].config(state=tk.NORMAL)

Expand Down Expand Up @@ -1076,25 +1076,6 @@ def selectWholeWord(direction, Event=None):
def openPreferences():
pref_window.__init__()

def updateMenu(Event=None):
current_tab = getCurrentTab()
if current_tab == -1:
addNewTab()

messagebox.showinfo("Update Encryptext", """1. Run the new version's installer\n2. When it asks whether you're installing or updating, choose updating.\n3. When it asks for the old enryption key and other strings, copy and paste the ones shown in the text editor here.\n\nClick 'Ok' to view the keys.\n\nDO NOT SAVE THE DOCUMENT WITH THE KEYS.""")

key = encrypt_key.decode()

# Change the title
tab_panes.tab(tab_panes.tabs()[getCurrentTab()], text=update_file_title)

# Add the needed strings to the box
textboxes[current_tab].delete("1.0", tk.END)
textboxes[current_tab].insert("1.0", f"Encryption Key: {key}\nFormat Item Separator: {format_item_separator}\nFormat Separator String: {format_separator}\nFormat String: {format_string}")

# Enter viewing mode so that the string can't be accidentally changed
viewingMode()

def aboutMenu(Event=None):
messagebox.showinfo("About Encryptext", f"Unlock a new level of security and versatility with Encryptext, the text editor designed for the modern user. Seamlessly blending essential features with modern encryption technology, Encryptext ensures your documents are safeguarded like never before.\n\nFree for everyone. Forever. ❤\n\nVersion {version}")

Expand Down Expand Up @@ -1556,8 +1537,6 @@ def createMenuBar():
textstylemenu.add_command(label="Bold", accelerator="Ctrl+B", command=changeToBold)
textstylemenu.add_command(label="Italic", accelerator="Ctrl+I", command=changeToItalic)

helpmenu.add_command(label="Update Encryptext", command=updateMenu)

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

Expand Down
1 change: 0 additions & 1 deletion Original Files/build_number.txt

This file was deleted.

1 change: 1 addition & 0 deletions builds/build_number.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
81 changes: 28 additions & 53 deletions encryptext_installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/python'

# Created by Sooraj S
# https://encryptext.sooraj.dev
# Free for everyone. Forever.

from os import rename, remove, rmdir, makedirs, listdir, path, environ
from shutil import rmtree
import sys
Expand Down Expand Up @@ -118,18 +122,23 @@ def progress_bar(percent_done):
update = input("\nAre you updating or installing Encryptext? [(u)pdating/(i)nstalling] ")

# Open the Encryptext.pyw file and read it into a variable
file = open(getTrueFilename("Encryptext.pyw"), "r", encoding="utf8")
file = file.read()
text = file
with open(getTrueFilename("Encryptext.pyw"), "r", encoding="utf8") as file:
text = file.read()

# Add version number to the file
file = text.split("VERSION NUMBER HERE")
text = version.join(file)

# Change debug mode to False if it's True
try:
file = text.split("debug = True")
text = "debug = False".join(file)
except: pass

# Adds computed hash to file
hash_str = "INSERT COMPUTED HASH HERE"
file = text.split("# HASH STRING HERE")
hash_line = file[1].split("'")
hash_line[1] = hash_str
file[1] = "'".join(hash_line)

text = "".join(file)
file = text.split("HASH STRING HERE")
text = hash_str.join(file)

# Communicate to old program
return_attributes = ""
Expand All @@ -143,48 +152,29 @@ def progress_bar(percent_done):
except:
raise Exception("Something went wrong! Please try again or file a crash report on GitHub.")

# Find where the encryption key is stored in the file
file = text.split("# ENCRYPTION KEY HERE")

if update == "i":
# Create a key and remove the b'' from the string
key = F.generate_key().decode()
else:
key = str(return_attributes[3].split("'")[1])

# Add the key to the file
key_line = file[1]
key_line = key_line.split("'")
key_line[1] = key
key_line = "'".join(key_line)
file[1] = key_line

text = "".join(file)
file = text.split("ENCRYPTION KEY HERE")
text = key.join(file)

print("Encryption key set!")

possible_characters = ascii_letters + digits

# Find where the format item separator string is stored in the file
file = text.split("# FORMAT ITEM SEPARATOR HERE")

if update == "i":
# Create a format item separator string
format_item_separator = "".join([choice(possible_characters) for i in range(randint(15, 45))])
else:
format_item_separator = str(return_attributes[0].split("'")[1])

# Add the format item separator string to the file
key_line = file[1]
key_line = key_line.split("'")
key_line[1] = format_item_separator
key_line = "'".join(key_line)
file[1] = key_line

text = "".join(file)

# Find where the format separator string is stored in the file
file = text.split("# FORMAT SEPARATOR HERE")
file = text.split("FORMAT ITEM SEPARATOR HERE")
text = format_item_separator.join(file)

if update == "i":
# Create a format separator string
Expand All @@ -193,16 +183,8 @@ def progress_bar(percent_done):
format_separator = str(return_attributes[1].split("'")[1])

# Add the format separator string to the file
key_line = file[1]
key_line = key_line.split("'")
key_line[1] = format_separator
key_line = "'".join(key_line)
file[1] = key_line

text = "".join(file)

# Find where the format string is stored in the file
file = text.split("# FORMAT STRING HERE")
file = text.split("FORMAT SEPARATOR HERE")
text = format_separator.join(file)

if update == "i":
# Create a format string
Expand All @@ -211,13 +193,8 @@ def progress_bar(percent_done):
format_string = str(return_attributes[2].split("'")[1])

# Add the format string to the file
key_line = file[1]
key_line = key_line.split("'")
key_line[1] = format_string
key_line = "'".join(key_line)
file[1] = key_line

text = "".join(file)
file = text.split("FORMAT STRING HERE")
text = format_string.join(file)

print("Format strings set!")

Expand All @@ -231,7 +208,6 @@ def progress_bar(percent_done):
keep_settings = input("\nDo you want to load your settings from an old version?\nNOTE: If you don't have an older version, it will create new settings by default [(y)es/(n)o] ")

data = {
"version": version,
"recentFilePaths": [],
"maxRecentFiles": 5,
"otherSettings": {
Expand All @@ -256,7 +232,6 @@ def progress_bar(percent_done):
file = json.load(file)

data = {
"version": version,
"recentFilePaths": file["recentFilePaths"],
"maxRecentFiles": file["maxRecentFiles"],
"otherSettings": {
Expand Down Expand Up @@ -318,7 +293,7 @@ def progress_bar(percent_done):
# Moves the exe out of the dist folder
rename(path.join(dir_path, "dist", "encryptext.exe"), path.join(dir_path, f"encryptext_v{version}.exe"))

# Create desktop shortcut
# Create desktop shortcut for Windows
# https://stackoverflow.com/a/69597224
try:
from win32com.client import Dispatch
Expand All @@ -333,7 +308,7 @@ def progress_bar(percent_done):
except:
print(f"Couldn't create Desktop shortcut!")

# Create Start Menu shortcut
# Create Start Menu shortcut for Windows
try:
# Create Start Menu folder for Encryptext
makedirs(path.join(home_dir, "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Encryptext"), exist_ok=True)
Expand Down
31 changes: 13 additions & 18 deletions installer_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import hashlib
import PyInstaller.__main__

version = "1.9.1"
version = "1.9.2"
testing = False

def update_build_number():
with open("Original Files/build_number.txt", "r") as file:
with open("builds/build_number.txt", "r") as file:
build_number = int(file.read().strip())
build_number += 1
with open("Original Files/build_number.txt", "w") as file:
with open("builds/build_number.txt", "w") as file:
file.write(str(build_number))
return build_number

Expand All @@ -27,30 +27,25 @@ def computeHash(input_string: str) -> str:
return hash_object.hexdigest()

def modifyInstallerFile(add: bool) -> None:
if add:
# Add the computed hash and version number
with open("encryptext_installer.py", "r+") as file:
installer_file = file.read()
with open("encryptext_installer.py", "r+") as file:
installer_file = file.read()

if add:
# Add the computed hash and version number
installer_parts = installer_file.split("INSERT COMPUTED HASH HERE")
installer_file = hash_str.join(installer_parts)
installer_parts = installer_file.split("INSERT VERSION NUMBER HERE")
installer_file = version.join(installer_parts)

file.seek(0)
file.write(installer_file)
file.truncate()
else:
# Remove the computed hash and version number
with open("encryptext_installer.py", "r+") as file:
installer_file = file.read()
else:
# Remove the computed hash and version number
installer_parts = installer_file.split(hash_str)
installer_file = "INSERT COMPUTED HASH HERE".join(installer_parts)
installer_parts = installer_file.split(version)
installer_file = "INSERT VERSION NUMBER HERE".join(installer_parts)

file.seek(0)
file.write(installer_file)
file.truncate()
file.seek(0)
file.write(installer_file)
file.truncate()

# Open the key.txt file and read in the key
with open("Original Files/key.txt", "r") as file:
Expand Down

0 comments on commit 25b86ac

Please sign in to comment.