Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -29,16 +29,16 @@ def compile_and_zip():
|
|
29 |
try:
|
30 |
# Generate unique names
|
31 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
32 |
-
cs_filename = f"
|
33 |
-
exe_filename = f"
|
34 |
rar_filename = f"output_{timestamp}.rar"
|
35 |
icon_path = "app.ico" # Ensure favicon.ico is in the working directory
|
36 |
-
|
37 |
# Full paths
|
38 |
cs_path = os.path.join(COMPILE_FOLDER, cs_filename)
|
39 |
exe_path = os.path.join(COMPILE_FOLDER, exe_filename)
|
40 |
rar_path = os.path.join(UPLOAD_FOLDER, rar_filename)
|
41 |
-
|
42 |
# Write C# source with assembly attributes
|
43 |
with open(cs_path, 'w') as f:
|
44 |
f.write("""
|
@@ -67,36 +67,36 @@ class Program
|
|
67 |
}
|
68 |
}
|
69 |
""")
|
70 |
-
|
71 |
-
# Compile with mcs
|
72 |
compile_cmd = [
|
73 |
"mcs",
|
74 |
"-target:winexe",
|
75 |
"-platform:x64",
|
76 |
f"-out:{exe_path}",
|
77 |
-
|
78 |
-
|
79 |
]
|
80 |
-
|
81 |
compile_result = subprocess.run(compile_cmd, capture_output=True, text=True)
|
82 |
if compile_result.returncode != 0:
|
83 |
print(f"Compile error: {compile_result.stderr}")
|
84 |
return None
|
85 |
-
|
86 |
# Create RAR using 7zip
|
87 |
rar_cmd = ['/usr/bin/7z', 'a', rar_path, exe_path]
|
88 |
rar_result = subprocess.run(rar_cmd, capture_output=True, text=True)
|
89 |
if rar_result.returncode != 0:
|
90 |
print(f"RAR error: {rar_result.stderr}")
|
91 |
return None
|
92 |
-
|
93 |
# Cleanup temporary files
|
94 |
try:
|
95 |
os.remove(cs_path)
|
96 |
os.remove(exe_path)
|
97 |
except Exception as e:
|
98 |
print(f"Cleanup error: {e}")
|
99 |
-
|
100 |
# Remove old RAR files
|
101 |
for old_file in Path(UPLOAD_FOLDER).glob('*.rar'):
|
102 |
if old_file != Path(rar_path):
|
@@ -104,9 +104,9 @@ class Program
|
|
104 |
os.remove(old_file)
|
105 |
except:
|
106 |
pass
|
107 |
-
|
108 |
return rar_path
|
109 |
-
|
110 |
except Exception as e:
|
111 |
print(f"Error: {str(e)}")
|
112 |
return None
|
|
|
29 |
try:
|
30 |
# Generate unique names
|
31 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
32 |
+
cs_filename = f"script_{timestamp}.cs"
|
33 |
+
exe_filename = f"script_{timestamp}.exe"
|
34 |
rar_filename = f"output_{timestamp}.rar"
|
35 |
icon_path = "app.ico" # Ensure favicon.ico is in the working directory
|
36 |
+
|
37 |
# Full paths
|
38 |
cs_path = os.path.join(COMPILE_FOLDER, cs_filename)
|
39 |
exe_path = os.path.join(COMPILE_FOLDER, exe_filename)
|
40 |
rar_path = os.path.join(UPLOAD_FOLDER, rar_filename)
|
41 |
+
|
42 |
# Write C# source with assembly attributes
|
43 |
with open(cs_path, 'w') as f:
|
44 |
f.write("""
|
|
|
67 |
}
|
68 |
}
|
69 |
""")
|
70 |
+
|
71 |
+
# Compile with mcs, adding icon and specifying x64 platform
|
72 |
compile_cmd = [
|
73 |
"mcs",
|
74 |
"-target:winexe",
|
75 |
"-platform:x64",
|
76 |
f"-out:{exe_path}",
|
77 |
+
f"-win32icon:{icon_path}",
|
78 |
+
cs_path
|
79 |
]
|
80 |
+
|
81 |
compile_result = subprocess.run(compile_cmd, capture_output=True, text=True)
|
82 |
if compile_result.returncode != 0:
|
83 |
print(f"Compile error: {compile_result.stderr}")
|
84 |
return None
|
85 |
+
|
86 |
# Create RAR using 7zip
|
87 |
rar_cmd = ['/usr/bin/7z', 'a', rar_path, exe_path]
|
88 |
rar_result = subprocess.run(rar_cmd, capture_output=True, text=True)
|
89 |
if rar_result.returncode != 0:
|
90 |
print(f"RAR error: {rar_result.stderr}")
|
91 |
return None
|
92 |
+
|
93 |
# Cleanup temporary files
|
94 |
try:
|
95 |
os.remove(cs_path)
|
96 |
os.remove(exe_path)
|
97 |
except Exception as e:
|
98 |
print(f"Cleanup error: {e}")
|
99 |
+
|
100 |
# Remove old RAR files
|
101 |
for old_file in Path(UPLOAD_FOLDER).glob('*.rar'):
|
102 |
if old_file != Path(rar_path):
|
|
|
104 |
os.remove(old_file)
|
105 |
except:
|
106 |
pass
|
107 |
+
|
108 |
return rar_path
|
109 |
+
|
110 |
except Exception as e:
|
111 |
print(f"Error: {str(e)}")
|
112 |
return None
|