|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# updater(1-2to1-3).py, Copyright(c) 2021 Martin S. Merkli |
| 3 | +# version: 1.3 |
| 4 | +# |
| 5 | +# This program is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | + |
| 19 | +import os |
| 20 | +import sys |
| 21 | +import tkinter as tk |
| 22 | +from tkinter import messagebox |
| 23 | +from tkinter import filedialog |
| 24 | + |
| 25 | +location = os.getcwd() |
| 26 | +if location[-1] not in ['/', '\\']: |
| 27 | + location += '/' |
| 28 | + |
| 29 | +def select_location(): |
| 30 | + global location |
| 31 | + directory = filedialog.askdirectory() |
| 32 | + location = directory |
| 33 | + |
| 34 | +def main(): |
| 35 | +global location |
| 36 | +root = tk.Tk() |
| 37 | +root.title('Update - FileEncryption') |
| 38 | + button_a = tk.Button(root, text='Select directory of FileEncryption.py', command=select_location) |
| 39 | + label_b = tk.Label(root, text=location) |
| 40 | + pressed_c = tk.BooleanVar(False) |
| 41 | + button_c = tk.Button(root, text='Update', command=lambda: pressed_g.set(True)) |
| 42 | + button_a.grid(row=0, column=0) |
| 43 | + label_b.grid(row=1, column=0) |
| 44 | + button_c.grid(row=2, column=0) |
| 45 | + loop = True |
| 46 | + while loop: |
| 47 | + try: |
| 48 | + root.update() |
| 49 | + if location[-1] not in ['/', '\\']: |
| 50 | + location += '/' |
| 51 | + if os.path.exists(location + 'FileEncryption.py'): |
| 52 | + continue_available = True |
| 53 | + else: |
| 54 | + continue_available = False |
| 55 | + if continue_available: |
| 56 | + button_c.config(state=tk.NORMAL) |
| 57 | + else: |
| 58 | + button_c.config(state=tk.DISABLED) |
| 59 | + if pressed_c.get(): |
| 60 | + loop = False |
| 61 | + with open(location + 'FileEncryption.py', 'rb') as old_file: |
| 62 | + old_content = old_file.read() |
| 63 | + with open(location + 'FileEncryption.py', 'wb') as new_file: |
| 64 | + new_file.write(old_content.replace(b'os.urandom(64)', b'os.urandom(500)')) |
| 65 | + messagebox.showinfo('Success - FileEncryption', 'Install successful: delete this updater') |
| 66 | + label_b.config(text=location) |
| 67 | + except tk.TclError: |
| 68 | + sys.exit(0) |
| 69 | + |
| 70 | +if __name__ == '__main__': |
| 71 | + main() |
| 72 | + |
0 commit comments