File size: 2,095 Bytes
b1f0958
45a1acf
 
66f8fc1
45a1acf
 
b1f0958
66f8fc1
45a1acf
 
b1f0958
66f8fc1
45a1acf
52ab4b4
 
b1f0958
 
52ab4b4
 
b1f0958
52ab4b4
b1f0958
 
 
 
 
52ab4b4
 
 
 
b1f0958
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52ab4b4
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
from flask import Flask, request, send_file, render_template
import os
import subprocess

app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

@app.route('/')
def index():
    return render_template('index.html')

@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", 400

    bat_file = request.files['bat_file']
    icon_file = request.files['icon_file']

    if bat_file.filename == '' or icon_file.filename == '':
        return "No selected file", 400

    bat_path = os.path.join(app.config['UPLOAD_FOLDER'], bat_file.filename)
    icon_path = os.path.join(app.config['UPLOAD_FOLDER'], icon_file.filename)

    # Save the uploaded files
    bat_file.save(bat_path)
    icon_file.save(icon_path)

    # Construct the NSIS script
    nsi_script = f"""
    !include nsDialogs.nsh
    !include LogicLib.nsh

    Outfile "output.exe"
    InstallDir "$PROGRAMFILES\\YourApp"

    Name "Your App"
    Caption "Your App Installer"
    VIProductVersion "1.0.0"
    RequestExecutionLevel admin

    Page instfiles

    Section "Install"
        SetOutPath "$INSTDIR"
        File "{bat_path}"
        File "{icon_path}"
    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 "Compilation successful! Download here: <a href='/download/output.exe'>output.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)