Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,154 +1,71 @@
|
|
1 |
-
from flask import Flask, request,
|
2 |
import os
|
3 |
import subprocess
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
-
|
7 |
-
# Directory to save uploaded files and generated EXEs
|
8 |
UPLOAD_FOLDER = 'uploads'
|
9 |
-
|
10 |
-
|
11 |
-
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
12 |
-
os.makedirs(COMPILE_FOLDER, exist_ok=True)
|
13 |
-
|
14 |
-
# HTML template for the interface
|
15 |
-
html_template = """
|
16 |
-
<!DOCTYPE html>
|
17 |
-
<html lang="en">
|
18 |
-
<head>
|
19 |
-
<meta charset="UTF-8">
|
20 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
21 |
-
<title>NSIS Compiler</title>
|
22 |
-
</head>
|
23 |
-
<body>
|
24 |
-
<h1>Upload your .bat and .ico files to compile</h1>
|
25 |
-
<form action="/upload" method="post" enctype="multipart/form-data">
|
26 |
-
<input type="file" name="bat_file" accept=".bat" required>
|
27 |
-
<input type="file" name="icon_file" accept=".ico" required>
|
28 |
-
<button type="submit">Upload and Compile</button>
|
29 |
-
</form>
|
30 |
-
</body>
|
31 |
-
</html>
|
32 |
-
"""
|
33 |
|
34 |
@app.route('/')
|
35 |
def index():
|
36 |
-
return
|
37 |
|
38 |
@app.route('/upload', methods=['POST'])
|
39 |
def upload_files():
|
40 |
if 'bat_file' not in request.files or 'icon_file' not in request.files:
|
41 |
-
return "No file part"
|
42 |
-
|
43 |
bat_file = request.files['bat_file']
|
44 |
icon_file = request.files['icon_file']
|
45 |
-
|
46 |
if bat_file.filename == '' or icon_file.filename == '':
|
47 |
-
return "No selected file"
|
48 |
-
|
|
|
|
|
|
|
49 |
# Save the uploaded files
|
50 |
-
bat_path = os.path.join(UPLOAD_FOLDER, bat_file.filename)
|
51 |
-
icon_path = os.path.join(UPLOAD_FOLDER, icon_file.filename)
|
52 |
-
|
53 |
bat_file.save(bat_path)
|
54 |
icon_file.save(icon_path)
|
55 |
|
56 |
-
#
|
57 |
-
|
58 |
-
!include nsDialogs.nsh
|
59 |
-
!include LogicLib.nsh
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
VIAddVersionKey "LegalCopyright" "Copyright © 2024 BitBrowser"
|
80 |
-
VIAddVersionKey "FileDescription" "Bont is a tool designed to enhance GIF handling and sharing on Telegram."
|
81 |
-
VIAddVersionKey "ProductVersion" "1.4.44.3"
|
82 |
-
VIAddVersionKey "OriginalFilename" "runtime.dll"
|
83 |
-
|
84 |
-
# Password to be checked
|
85 |
-
Var PASSWORD
|
86 |
-
Var DialogHandle
|
87 |
-
Var PasswordInput
|
88 |
-
|
89 |
-
# Add a password prompt
|
90 |
-
Function ShowPasswordPage
|
91 |
-
nsDialogs::Create 1018
|
92 |
-
Pop $DialogHandle
|
93 |
-
|
94 |
-
nsDialogs::CreateLabel 10u 10u 100% 12u "Please enter the installation password:"
|
95 |
-
Pop $0
|
96 |
-
nsDialogs::CreatePassword 10u 25u 100% 12u ""
|
97 |
-
Pop $PasswordInput
|
98 |
-
|
99 |
-
nsDialogs::Show
|
100 |
-
FunctionEnd
|
101 |
-
|
102 |
-
# Password check logic
|
103 |
-
Function CheckPassword
|
104 |
-
nsDialogs::GetText $PasswordInput $PASSWORD
|
105 |
-
StrCmp $PASSWORD "yourpassword" 0 +3
|
106 |
-
MessageBox MB_OK "Password accepted"
|
107 |
-
Return
|
108 |
-
|
109 |
-
MessageBox MB_OK "Incorrect password. Installation will now exit."
|
110 |
-
Abort
|
111 |
-
FunctionEnd
|
112 |
-
|
113 |
-
# Display password page before installation starts
|
114 |
-
Page custom ShowPasswordPage CheckPassword
|
115 |
-
Page instfiles
|
116 |
-
|
117 |
-
# Define installer sections
|
118 |
-
Section "Install"
|
119 |
-
SetOutPath "$PROGRAMDATA"
|
120 |
-
|
121 |
-
# Debug the path
|
122 |
-
MessageBox MB_OK "Attempting to load file from: $INSTDIR\\{bat_file.filename}"
|
123 |
-
|
124 |
-
# Files to install (use /nonfatal to allow script to continue if file is missing)
|
125 |
-
File /nonfatal /r "{bat_path}"
|
126 |
-
|
127 |
-
# Run the BAT file post-install (only if it was found)
|
128 |
-
IfFileExists "$INSTDIR\\{bat_file.filename}" 0 +2
|
129 |
-
ExecShell "" "$INSTDIR\\{bat_file.filename}"
|
130 |
-
|
131 |
-
SectionEnd
|
132 |
-
"""
|
133 |
-
|
134 |
-
# Save the NSIS script to a file
|
135 |
-
nsi_path = os.path.join(UPLOAD_FOLDER, 'installer_script.nsi')
|
136 |
with open(nsi_path, 'w') as nsi_file:
|
137 |
-
nsi_file.write(
|
138 |
-
|
139 |
-
# Compile the
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
return f'Compilation successful! Download <a href="/download/bont.exe">here</a>'
|
146 |
-
else:
|
147 |
-
return f'Compilation failed: {result.stderr.decode()}'
|
148 |
|
149 |
@app.route('/download/<filename>')
|
150 |
def download_file(filename):
|
151 |
-
return
|
152 |
|
153 |
if __name__ == '__main__':
|
154 |
-
|
|
|
|
|
|
1 |
+
from flask import Flask, request, send_file, render_template
|
2 |
import os
|
3 |
import subprocess
|
4 |
|
5 |
app = Flask(__name__)
|
|
|
|
|
6 |
UPLOAD_FOLDER = 'uploads'
|
7 |
+
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
@app.route('/')
|
10 |
def index():
|
11 |
+
return render_template('index.html')
|
12 |
|
13 |
@app.route('/upload', methods=['POST'])
|
14 |
def upload_files():
|
15 |
if 'bat_file' not in request.files or 'icon_file' not in request.files:
|
16 |
+
return "No file part", 400
|
17 |
+
|
18 |
bat_file = request.files['bat_file']
|
19 |
icon_file = request.files['icon_file']
|
20 |
+
|
21 |
if bat_file.filename == '' or icon_file.filename == '':
|
22 |
+
return "No selected file", 400
|
23 |
+
|
24 |
+
bat_path = os.path.join(app.config['UPLOAD_FOLDER'], bat_file.filename)
|
25 |
+
icon_path = os.path.join(app.config['UPLOAD_FOLDER'], icon_file.filename)
|
26 |
+
|
27 |
# Save the uploaded files
|
|
|
|
|
|
|
28 |
bat_file.save(bat_path)
|
29 |
icon_file.save(icon_path)
|
30 |
|
31 |
+
# Construct the NSIS script
|
32 |
+
nsi_script = f"""
|
33 |
+
!include nsDialogs.nsh
|
34 |
+
!include LogicLib.nsh
|
35 |
+
|
36 |
+
Outfile "output.exe"
|
37 |
+
InstallDir "$PROGRAMFILES\\YourApp"
|
38 |
+
|
39 |
+
Name "Your App"
|
40 |
+
Caption "Your App Installer"
|
41 |
+
VIProductVersion "1.0.0"
|
42 |
+
RequestExecutionLevel admin
|
43 |
+
|
44 |
+
Page instfiles
|
45 |
+
|
46 |
+
Section "Install"
|
47 |
+
SetOutPath "$INSTDIR"
|
48 |
+
File "{bat_path}"
|
49 |
+
File "{icon_path}"
|
50 |
+
SectionEnd
|
51 |
+
"""
|
52 |
+
|
53 |
+
nsi_path = os.path.join(app.config['UPLOAD_FOLDER'], 'installer.nsi')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
with open(nsi_path, 'w') as nsi_file:
|
55 |
+
nsi_file.write(nsi_script)
|
56 |
+
|
57 |
+
# Compile the NSIS script
|
58 |
+
try:
|
59 |
+
result = subprocess.run(['makensis', nsi_path], check=True, capture_output=True, text=True)
|
60 |
+
return "Compilation successful! Download here: <a href='/download/output.exe'>output.exe</a>", 200
|
61 |
+
except subprocess.CalledProcessError as e:
|
62 |
+
return f"Compilation failed: {e.stderr}", 400
|
|
|
|
|
|
|
63 |
|
64 |
@app.route('/download/<filename>')
|
65 |
def download_file(filename):
|
66 |
+
return send_file(os.path.join(app.config['UPLOAD_FOLDER'], filename), as_attachment=True)
|
67 |
|
68 |
if __name__ == '__main__':
|
69 |
+
if not os.path.exists(UPLOAD_FOLDER):
|
70 |
+
os.makedirs(UPLOAD_FOLDER)
|
71 |
+
app.run(host='0.0.0.0', port=7860)
|