11#!/usr/bin/python'
22
3+ # Created by Sooraj S
4+ # https://encryptext.sooraj.dev
5+ # Free for everyone. Forever.
6+
37from os import rename , remove , rmdir , makedirs , listdir , path , environ
48from shutil import rmtree
59import sys
@@ -118,18 +122,23 @@ def progress_bar(percent_done):
118122 update = input ("\n Are you updating or installing Encryptext? [(u)pdating/(i)nstalling] " )
119123
120124# Open the Encryptext.pyw file and read it into a variable
121- file = open (getTrueFilename ("Encryptext.pyw" ), "r" , encoding = "utf8" )
122- file = file .read ()
123- text = file
125+ with open (getTrueFilename ("Encryptext.pyw" ), "r" , encoding = "utf8" ) as file :
126+ text = file .read ()
127+
128+ # Add version number to the file
129+ file = text .split ("VERSION NUMBER HERE" )
130+ text = version .join (file )
131+
132+ # Change debug mode to False if it's True
133+ try :
134+ file = text .split ("debug = True" )
135+ text = "debug = False" .join (file )
136+ except : pass
124137
125138# Adds computed hash to file
126139hash_str = "INSERT COMPUTED HASH HERE"
127- file = text .split ("# HASH STRING HERE" )
128- hash_line = file [1 ].split ("'" )
129- hash_line [1 ] = hash_str
130- file [1 ] = "'" .join (hash_line )
131-
132- text = "" .join (file )
140+ file = text .split ("HASH STRING HERE" )
141+ text = hash_str .join (file )
133142
134143# Communicate to old program
135144return_attributes = ""
@@ -143,48 +152,29 @@ def progress_bar(percent_done):
143152 except :
144153 raise Exception ("Something went wrong! Please try again or file a crash report on GitHub." )
145154
146- # Find where the encryption key is stored in the file
147- file = text .split ("# ENCRYPTION KEY HERE" )
148-
149155if update == "i" :
150156 # Create a key and remove the b'' from the string
151157 key = F .generate_key ().decode ()
152158else :
153159 key = str (return_attributes [3 ].split ("'" )[1 ])
154160
155161# Add the key to the file
156- key_line = file [1 ]
157- key_line = key_line .split ("'" )
158- key_line [1 ] = key
159- key_line = "'" .join (key_line )
160- file [1 ] = key_line
161-
162- text = "" .join (file )
162+ file = text .split ("ENCRYPTION KEY HERE" )
163+ text = key .join (file )
163164
164165print ("Encryption key set!" )
165166
166167possible_characters = ascii_letters + digits
167168
168- # Find where the format item separator string is stored in the file
169- file = text .split ("# FORMAT ITEM SEPARATOR HERE" )
170-
171169if update == "i" :
172170 # Create a format item separator string
173171 format_item_separator = "" .join ([choice (possible_characters ) for i in range (randint (15 , 45 ))])
174172else :
175173 format_item_separator = str (return_attributes [0 ].split ("'" )[1 ])
176174
177175# Add the format item separator string to the file
178- key_line = file [1 ]
179- key_line = key_line .split ("'" )
180- key_line [1 ] = format_item_separator
181- key_line = "'" .join (key_line )
182- file [1 ] = key_line
183-
184- text = "" .join (file )
185-
186- # Find where the format separator string is stored in the file
187- file = text .split ("# FORMAT SEPARATOR HERE" )
176+ file = text .split ("FORMAT ITEM SEPARATOR HERE" )
177+ text = format_item_separator .join (file )
188178
189179if update == "i" :
190180 # Create a format separator string
@@ -193,16 +183,8 @@ def progress_bar(percent_done):
193183 format_separator = str (return_attributes [1 ].split ("'" )[1 ])
194184
195185# Add the format separator string to the file
196- key_line = file [1 ]
197- key_line = key_line .split ("'" )
198- key_line [1 ] = format_separator
199- key_line = "'" .join (key_line )
200- file [1 ] = key_line
201-
202- text = "" .join (file )
203-
204- # Find where the format string is stored in the file
205- file = text .split ("# FORMAT STRING HERE" )
186+ file = text .split ("FORMAT SEPARATOR HERE" )
187+ text = format_separator .join (file )
206188
207189if update == "i" :
208190 # Create a format string
@@ -211,13 +193,8 @@ def progress_bar(percent_done):
211193 format_string = str (return_attributes [2 ].split ("'" )[1 ])
212194
213195# Add the format string to the file
214- key_line = file [1 ]
215- key_line = key_line .split ("'" )
216- key_line [1 ] = format_string
217- key_line = "'" .join (key_line )
218- file [1 ] = key_line
219-
220- text = "" .join (file )
196+ file = text .split ("FORMAT STRING HERE" )
197+ text = format_string .join (file )
221198
222199print ("Format strings set!" )
223200
@@ -231,7 +208,6 @@ def progress_bar(percent_done):
231208 keep_settings = input ("\n Do you want to load your settings from an old version?\n NOTE: If you don't have an older version, it will create new settings by default [(y)es/(n)o] " )
232209
233210data = {
234- "version" : version ,
235211 "recentFilePaths" : [],
236212 "maxRecentFiles" : 5 ,
237213 "otherSettings" : {
@@ -256,7 +232,6 @@ def progress_bar(percent_done):
256232 file = json .load (file )
257233
258234 data = {
259- "version" : version ,
260235 "recentFilePaths" : file ["recentFilePaths" ],
261236 "maxRecentFiles" : file ["maxRecentFiles" ],
262237 "otherSettings" : {
@@ -318,7 +293,7 @@ def progress_bar(percent_done):
318293# Moves the exe out of the dist folder
319294rename (path .join (dir_path , "dist" , "encryptext.exe" ), path .join (dir_path , f"encryptext_v{ version } .exe" ))
320295
321- # Create desktop shortcut
296+ # Create desktop shortcut for Windows
322297# https://stackoverflow.com/a/69597224
323298try :
324299 from win32com .client import Dispatch
@@ -333,7 +308,7 @@ def progress_bar(percent_done):
333308except :
334309 print (f"Couldn't create Desktop shortcut!" )
335310
336- # Create Start Menu shortcut
311+ # Create Start Menu shortcut for Windows
337312try :
338313 # Create Start Menu folder for Encryptext
339314 makedirs (path .join (home_dir , "AppData" , "Roaming" , "Microsoft" , "Windows" , "Start Menu" , "Programs" , "Encryptext" ), exist_ok = True )
0 commit comments