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 |
|
@@ -18,53 +18,52 @@ html_template = """
|
|
18 |
<head>
|
19 |
<meta charset="UTF-8">
|
20 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
21 |
-
<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 |
-
<pre>{{ logs }}</pre>
|
30 |
</body>
|
31 |
</html>
|
32 |
"""
|
33 |
|
34 |
@app.route('/')
|
35 |
def index():
|
36 |
-
return render_template_string(html_template
|
37 |
|
38 |
@app.route('/upload', methods=['POST'])
|
39 |
-
def
|
40 |
-
if '
|
41 |
return "No file part"
|
42 |
|
43 |
-
file = request.files['
|
44 |
|
45 |
if file.filename == '':
|
46 |
return "No selected file"
|
47 |
|
48 |
-
# Save the
|
49 |
-
|
50 |
-
file.save(
|
51 |
|
52 |
-
# Compile the
|
53 |
-
exe_name = file.filename.replace('.
|
54 |
exe_path = os.path.join(COMPILE_FOLDER, exe_name)
|
55 |
|
56 |
-
# Command to run
|
57 |
-
compile_command = f'
|
58 |
-
|
59 |
-
# Run the command and capture logs
|
60 |
-
result = subprocess.run(compile_command, shell=True, capture_output=True, text=True)
|
61 |
|
62 |
-
|
|
|
|
|
|
|
63 |
|
64 |
if result.returncode == 0:
|
65 |
-
return f'Compilation successful! Download <a href="/download/{exe_name}">here</a>'
|
66 |
else:
|
67 |
-
return f'Compilation failed: <pre>{
|
68 |
|
69 |
@app.route('/download/<filename>')
|
70 |
def download_file(filename):
|
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
+
# Directory to save uploaded NSI files and generated EXEs
|
8 |
UPLOAD_FOLDER = 'uploads'
|
9 |
COMPILE_FOLDER = 'compiled'
|
10 |
|
|
|
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 .nsi file to compile</h1>
|
25 |
<form action="/upload" method="post" enctype="multipart/form-data">
|
26 |
+
<input type="file" name="nsi_file" accept=".nsi" required>
|
27 |
<button type="submit">Upload and Compile</button>
|
28 |
</form>
|
|
|
29 |
</body>
|
30 |
</html>
|
31 |
"""
|
32 |
|
33 |
@app.route('/')
|
34 |
def index():
|
35 |
+
return render_template_string(html_template)
|
36 |
|
37 |
@app.route('/upload', methods=['POST'])
|
38 |
+
def upload_nsi():
|
39 |
+
if 'nsi_file' not in request.files:
|
40 |
return "No file part"
|
41 |
|
42 |
+
file = request.files['nsi_file']
|
43 |
|
44 |
if file.filename == '':
|
45 |
return "No selected file"
|
46 |
|
47 |
+
# Save the NSI file
|
48 |
+
nsi_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
49 |
+
file.save(nsi_path)
|
50 |
|
51 |
+
# Compile the NSI file using makensis
|
52 |
+
exe_name = file.filename.replace('.nsi', '.exe')
|
53 |
exe_path = os.path.join(COMPILE_FOLDER, exe_name)
|
54 |
|
55 |
+
# Command to run NSIS compiler
|
56 |
+
compile_command = f'makensis {nsi_path}'
|
|
|
|
|
|
|
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/{exe_name}">here</a><br><pre>{output}</pre>'
|
65 |
else:
|
66 |
+
return f'Compilation failed: <pre>{output}</pre>'
|
67 |
|
68 |
@app.route('/download/<filename>')
|
69 |
def download_file(filename):
|