diff --git a/Encryptext.pyw b/Encryptext.pyw index 5673811..29f1627 100644 --- a/Encryptext.pyw +++ b/Encryptext.pyw @@ -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) @@ -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": { @@ -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"] """ @@ -138,7 +138,7 @@ class CustomText(tk.Text): cmd = (self._orig,) + args result = self.tk.call(cmd) except tk._tkinter.TclError: - result = "" + result = "break" # generate an event if something was added or deleted, # or the cursor position changed @@ -176,37 +176,64 @@ class PreferenceWindow(tk.Toplevel): self.option_pady = 3 + # Title label + self.title = WrappedLabel(self.pref_window, text="Preferences", font=(settings["otherSettings"]["fontStyle"], int(round(18*font_scale_factor)))) + + self.title.pack(side="top", fill="x", anchor="nw", padx=5, pady=10) + ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=5, pady=5) + # Recent file number self.selected_recent_files = tk.IntVar(value=settings["maxRecentFiles"]) - self.title = WrappedLabel(self.pref_window, text="Preferences", font=(settings["otherSettings"]["fontStyle"], int(round(18*font_scale_factor)))) self.recent_file_label = WrappedLabel(self.pref_window, text="Number of recent files to store: ", anchor="nw", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) self.recent_file_val = ttk.Spinbox(self.recent_file_label, textvariable=self.selected_recent_files, from_=0, to=20, width=5, font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + self.recent_file_label.pack(side="top", anchor="w", fill="x", padx=5) + self.recent_file_val.pack(side="right", padx=20, pady=self.option_pady) + ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) + # Font style picker self.selected_font_style = tk.StringVar(value=settings["otherSettings"]["fontStyle"]) self.font_style_label = WrappedLabel(self.pref_window, text="Display font style: ", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) font_options = sorted(list(font.families())) self.font_style_val = ttk.Combobox(self.font_style_label, textvariable=self.selected_font_style, values=font_options, state="readonly", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + self.font_style_label.pack(side="top", fill="x", padx=5, anchor="nw") + self.font_style_val.pack(side="right", padx=20, pady=self.option_pady) + # Font size number self.selected_font_sf = tk.DoubleVar(value=settings["otherSettings"]["fontScaleFactor"]) self.font_sf_label = WrappedLabel(self.pref_window, text="Display font size scale factor: ", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) self.font_sf_val = ttk.Spinbox(self.font_sf_label, textvariable=self.selected_font_sf, from_=0.5, to=2, increment=0.05, width=5, font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + self.font_sf_label.pack(side="top", fill="x", padx=5, anchor="nw") + self.font_sf_val.pack(side="right", padx=20, pady=self.option_pady) + ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) + # Theme selector self.selected_theme = tk.StringVar(value=settings["otherSettings"]["theme"]) self.theme_label = WrappedLabel(self.pref_window, text="Theme: ", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) self.light_theme_val = ttk.Radiobutton(self.theme_label, text="Light", value="light", variable=self.selected_theme) self.dark_theme_val = ttk.Radiobutton(self.theme_label, text="Dark", value="dark", variable=self.selected_theme) + self.theme_label.pack(side="top", fill="x", padx=5, anchor="n") + self.dark_theme_val.pack(side="right", padx=20, pady=self.option_pady) + self.light_theme_val.pack(side="right", padx=20, pady=self.option_pady) + ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) + # Auto-save selector self.selected_auto_save = tk.StringVar(value=str(settings["otherSettings"]["autoSave"]).lower()) self.auto_save_val = ttk.Checkbutton(self.pref_window, text="Auto-save", variable=self.selected_auto_save, onvalue="true", offvalue="false") + self.auto_save_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) + # Auto-save interval number self.selected_auto_save_interval_val = tk.IntVar(value=settings["otherSettings"]["autoSaveInterval"]) - self.auto_save_interval_label = WrappedLabel(self.pref_window, text="Auto-save interval: ", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) - self.auto_save_interval_val = ttk.Spinbox(self.auto_save_interval_label, textvariable=self.selected_auto_save_interval_val, from_=1, to=300, increment=15, width=5, font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + self.auto_save_interval_label = WrappedLabel(self.pref_window, text="Auto-save interval (seconds): ", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + self.auto_save_interval_val = ttk.Spinbox(self.auto_save_interval_label, textvariable=self.selected_auto_save_interval_val, from_=1, to=600, increment=5, width=5, font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + + self.auto_save_interval_label.pack(side="top", fill="x", padx=5, anchor="nw") + self.auto_save_interval_val.pack(side="right", padx=20, pady=self.option_pady) + ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) # Language picker self.selected_language = tk.StringVar(value=settings["otherSettings"]["language"]) @@ -218,56 +245,39 @@ class PreferenceWindow(tk.Toplevel): lang_options = ["en_US"] self.language_val = ttk.Combobox(self.language_label, textvariable=self.selected_language, values=lang_options, state="readonly", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + self.language_label.pack(side="top", fill="x", padx=5, anchor="nw") + self.language_val.pack(side="right", padx=20, pady=self.option_pady) + ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) + # show checkboxes for other true/false options self.selected_show_line_no = tk.StringVar(value=str(settings["otherSettings"]["showLineNumbers"]).lower()) self.show_line_no_val = ttk.Checkbutton(self.pref_window, text="Show line numbers", variable=self.selected_show_line_no, onvalue="true", offvalue="false") + + self.show_line_no_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) + self.selected_wrap_line = tk.StringVar(value=str(settings["otherSettings"]["wrapLines"]).lower()) self.wrap_line_val = ttk.Checkbutton(self.pref_window, text="Wrap text", variable=self.selected_wrap_line, onvalue="true", offvalue="false") + + self.wrap_line_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) + self.selected_show_active_line = tk.StringVar(value=str(settings["otherSettings"]["highlightActiveLine"]).lower()) self.show_active_line_val = ttk.Checkbutton(self.pref_window, text="Highlight active line", variable=self.selected_show_active_line, onvalue="true", offvalue="false") + + self.show_active_line_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) + self.selected_close_all_tabs = tk.StringVar(value=str(settings["otherSettings"]["closeAllTabs"]).lower()) self.close_all_tabs_val = ttk.Checkbutton(self.pref_window, text="Close all tabs", variable=self.selected_close_all_tabs, onvalue="true", offvalue="false") - # Info text - self.info_text = WrappedLabel(self.pref_window, text="Reopen Encryptext to see changes after saving.", anchor="sw", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) + self.close_all_tabs_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) # Save button self.save_button = ttk.Button(self.pref_window, text="Save Preferences", command=self.savePreferences) - # Add all items to the display - self.title.pack(side="top", fill="x", anchor="nw", padx=5, pady=10) - ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=5, pady=5) - - self.recent_file_label.pack(side="top", anchor="w", fill="x", padx=5) - self.recent_file_val.pack(side="right", padx=20, pady=self.option_pady) - ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) - - self.font_style_label.pack(side="top", fill="x", padx=5, anchor="nw") - self.font_style_val.pack(side="right", padx=20, pady=self.option_pady) - self.font_sf_label.pack(side="top", fill="x", padx=5, anchor="nw") - self.font_sf_val.pack(side="right", padx=20, pady=self.option_pady) - ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) - - self.theme_label.pack(side="top", fill="x", padx=5, anchor="n") - self.dark_theme_val.pack(side="right", padx=20, pady=self.option_pady) - self.light_theme_val.pack(side="right", padx=20, pady=self.option_pady) - ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) - - self.auto_save_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) - self.auto_save_interval_label.pack(side="top", fill="x", padx=5, anchor="nw") - self.auto_save_interval_val.pack(side="right", padx=20, pady=self.option_pady) - ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) - - self.language_label.pack(side="top", fill="x", padx=5, anchor="nw") - self.language_val.pack(side="right", padx=20, pady=self.option_pady) - ttk.Separator(self.pref_window, orient="horizontal").pack(side="top", fill="x", padx=100, pady=10) + self.save_button.pack(side="bottom", anchor="e", pady=10, padx=10) - self.show_line_no_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) - self.wrap_line_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) - self.show_active_line_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) - self.close_all_tabs_val.pack(side="top", anchor="nw", padx=5, pady=self.option_pady) + # Info text + self.info_text = WrappedLabel(self.pref_window, text="Reopen Encryptext to see changes after saving.", anchor="sw", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor)))) - self.save_button.pack(side="bottom", anchor="e", pady=10, padx=10) self.info_text.pack(side="bottom", anchor="n", padx=5, pady=self.option_pady, fill="x") elif self.win_open: self.pref_window.focus() @@ -355,8 +365,6 @@ root.iconbitmap(getTrueFilename("app_icon.ico")) """ Variables """ -update_file_title = " DO NOT SAVE THIS FILE " - file_save_locations = [] file_extensions = [] @@ -434,6 +442,18 @@ def updateTags(): tags_used = textboxes[current_tab].tag_names() i = 0 + + # 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) + 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]): @@ -681,13 +701,15 @@ def openFile(Event=None, current=False, file_path=None): if len(recent_files) > settings["maxRecentFiles"]: recent_files.pop() createMenuBar() - if file_extensions[current_tab] == "md": - global preview_window - try: - preview_window.deiconify() - updatePreview() - except: - preview_window.__init__() + + # Open the preview window if a markdown file is opened + if file_extensions[current_tab] == "md": + global preview_window + try: + preview_window.deiconify() + updatePreview() + except: + preview_window.__init__() else: text = textboxes[current_tab].get("1.0", tk.END) textboxes[current_tab].delete("1.0", tk.END) @@ -738,6 +760,16 @@ def newFile(Event=None): updatePreview() +def autoSaveFile(): + # Save the file if there is a tab open + current_tab = getCurrentTab() + if current_tab != -1: + saveFile(auto_save=True) + + # Recursively run autoSaveFile until program is closed (sys.exit kills all processes) + # Delay time is in milliseconds + root.after(settings["otherSettings"]["autoSaveInterval"]*1000, autoSaveFile) + def saveFile(Event=None, auto_save=False): current_tab = getCurrentTab() if current_tab == -1: @@ -983,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) @@ -1008,27 +1035,46 @@ def deselectAll(Event=None): textboxes[current_tab].event_generate("<>") -def openPreferences(): - pref_window.__init__() +def deleteWholeWord(Event=None): + current_tab = getCurrentTab() + if current_tab == -1: + return None + + textboxes[current_tab].delete("insert-2c wordstart", "insert") + textboxes[current_tab].see("insert") -def updateMenu(Event=None): + return "break" + +def moveWholeWord(direction, Event=None): current_tab = getCurrentTab() if current_tab == -1: - addNewTab() + return None + + if direction == "Left": + textboxes[current_tab].mark_set("insert", "insert-2c wordstart") + elif direction == "Right": + textboxes[current_tab].mark_set("insert", "insert wordend") - 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.""") + textboxes[current_tab].see("insert") + + return "break" + +def selectWholeWord(direction, Event=None): + current_tab = getCurrentTab() + if current_tab == -1: + return None - key = encrypt_key.decode() + if direction == "Left": + textboxes[current_tab].tag_add("sel", "insert-2c wordstart", "insert") + elif direction == "Right": + textboxes[current_tab].tag_add("sel", "insert", "insert wordend") - # Change the title - tab_panes.tab(tab_panes.tabs()[getCurrentTab()], text=update_file_title) + textboxes[current_tab].see("insert") - # 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}") + return "break" - # Enter viewing mode so that the string can't be accidentally changed - viewingMode() +def openPreferences(): + pref_window.__init__() 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}") @@ -1250,7 +1296,7 @@ def addNewTab(Event=None): textboxes[-1].bindtags((bindtags[2], bindtags[0], bindtags[1], bindtags[3])) # Track document changes and update markdown preview - textboxes[-1].bind('<>', trackChanges) + textboxes[-1].bind('', trackChanges) if settings["otherSettings"]["showLineNumbers"] == True and settings["otherSettings"]["highlightActiveLine"] == True: textboxes[-1].bind("<>", updateHighlightAndNumbers) textboxes[-1].bind("", updateHighlightAndNumbers) @@ -1339,8 +1385,6 @@ def captureSpecialKeys(Event=None): cur_key = Event.keysym mod_key = Event.state - # print(Event, cur_key, mod_key) - # Run function based on what key was pressed if cur_key == "s": saveFile() @@ -1384,6 +1428,16 @@ def captureSpecialKeys(Event=None): paste() elif cur_key == "a": selectAll() + elif cur_key == "BackSpace" and mod_key == 4: + deleteWholeWord() + elif cur_key == "Left" and mod_key == 262148: + moveWholeWord(direction=cur_key) + elif cur_key == "Right" and mod_key == 262148: + moveWholeWord(direction=cur_key) + elif cur_key == "Left" and mod_key == 262149: + selectWholeWord(direction=cur_key) + elif cur_key == "Right" and mod_key == 262149: + selectWholeWord(direction=cur_key) return "break" @@ -1402,6 +1456,10 @@ addNewTab() # The preview window was the focused one before root.focus_force() +# Set the autosave to start working +if settings["otherSettings"]["autoSave"]: + autoSaveFile() + """ Menu Bar """ @@ -1479,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) diff --git a/Original Files/build_number.txt b/Original Files/build_number.txt deleted file mode 100644 index 2edeafb..0000000 --- a/Original Files/build_number.txt +++ /dev/null @@ -1 +0,0 @@ -20 \ No newline at end of file diff --git a/builds/build_number.txt b/builds/build_number.txt new file mode 100644 index 0000000..bf0d87a --- /dev/null +++ b/builds/build_number.txt @@ -0,0 +1 @@ +4 \ No newline at end of file diff --git a/builds/testing/encryptext_installer_v1.9.1.18_64bit.exe b/builds/release/encryptext_installer_v1.9.2_64bit.exe similarity index 99% rename from builds/testing/encryptext_installer_v1.9.1.18_64bit.exe rename to builds/release/encryptext_installer_v1.9.2_64bit.exe index d3f6ee0..924028f 100644 Binary files a/builds/testing/encryptext_installer_v1.9.1.18_64bit.exe and b/builds/release/encryptext_installer_v1.9.2_64bit.exe differ diff --git a/builds/testing/encryptext_installer_v1.9.1.20_64bit_release.exe b/builds/testing/encryptext_installer_v1.9.2.1_64bit.exe similarity index 99% rename from builds/testing/encryptext_installer_v1.9.1.20_64bit_release.exe rename to builds/testing/encryptext_installer_v1.9.2.1_64bit.exe index bbb4ca6..f75e8d4 100644 Binary files a/builds/testing/encryptext_installer_v1.9.1.20_64bit_release.exe and b/builds/testing/encryptext_installer_v1.9.2.1_64bit.exe differ diff --git a/builds/release/encryptext_installer_v1.9.1_64bit.exe b/builds/testing/encryptext_installer_v1.9.2.2_64bit.exe similarity index 99% rename from builds/release/encryptext_installer_v1.9.1_64bit.exe rename to builds/testing/encryptext_installer_v1.9.2.2_64bit.exe index bbb4ca6..4f8a085 100644 Binary files a/builds/release/encryptext_installer_v1.9.1_64bit.exe and b/builds/testing/encryptext_installer_v1.9.2.2_64bit.exe differ diff --git a/builds/testing/encryptext_installer_v1.9.1.19_64bit.exe b/builds/testing/encryptext_installer_v1.9.2.3_64bit.exe similarity index 99% rename from builds/testing/encryptext_installer_v1.9.1.19_64bit.exe rename to builds/testing/encryptext_installer_v1.9.2.3_64bit.exe index f5a1319..2ba7cc9 100644 Binary files a/builds/testing/encryptext_installer_v1.9.1.19_64bit.exe and b/builds/testing/encryptext_installer_v1.9.2.3_64bit.exe differ diff --git a/builds/testing/encryptext_installer_v1.9.2.4_64bit_release.exe b/builds/testing/encryptext_installer_v1.9.2.4_64bit_release.exe new file mode 100644 index 0000000..924028f Binary files /dev/null and b/builds/testing/encryptext_installer_v1.9.2.4_64bit_release.exe differ diff --git a/encryptext_installer.py b/encryptext_installer.py index d0d5421..1a06bb2 100644 --- a/encryptext_installer.py +++ b/encryptext_installer.py @@ -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 @@ -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 = "" @@ -143,9 +152,6 @@ 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() @@ -153,21 +159,13 @@ def progress_bar(percent_done): 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))]) @@ -175,16 +173,8 @@ def progress_bar(percent_done): 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 @@ -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 @@ -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!") @@ -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": { @@ -256,7 +232,6 @@ def progress_bar(percent_done): file = json.load(file) data = { - "version": version, "recentFilePaths": file["recentFilePaths"], "maxRecentFiles": file["maxRecentFiles"], "otherSettings": { @@ -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 @@ -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) diff --git a/installer_creator.py b/installer_creator.py index 7f1be4e..0d66b08 100644 --- a/installer_creator.py +++ b/installer_creator.py @@ -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 @@ -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: