Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -32,13 +32,12 @@ def compile_and_zip():
|
|
32 |
cs_filename = f"script_{timestamp}.cs"
|
33 |
exe_filename = f"script_{timestamp}.exe"
|
34 |
rar_filename = f"output_{timestamp}.rar"
|
35 |
-
|
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 +66,34 @@ class Program
|
|
67 |
}
|
68 |
}
|
69 |
""")
|
70 |
-
|
71 |
-
# Compile with mcs
|
72 |
compile_cmd = [
|
73 |
"mcs",
|
74 |
-
|
75 |
-
|
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,13 +101,14 @@ 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
|
113 |
|
|
|
114 |
def get_current_rar():
|
115 |
"""Get the current RAR file or create one if none exists"""
|
116 |
files = list(Path(UPLOAD_FOLDER).glob('*.rar'))
|
|
|
32 |
cs_filename = f"script_{timestamp}.cs"
|
33 |
exe_filename = f"script_{timestamp}.exe"
|
34 |
rar_filename = f"output_{timestamp}.rar"
|
35 |
+
|
|
|
36 |
# Full paths
|
37 |
cs_path = os.path.join(COMPILE_FOLDER, cs_filename)
|
38 |
exe_path = os.path.join(COMPILE_FOLDER, exe_filename)
|
39 |
rar_path = os.path.join(UPLOAD_FOLDER, rar_filename)
|
40 |
+
|
41 |
# Write C# source with assembly attributes
|
42 |
with open(cs_path, 'w') as f:
|
43 |
f.write("""
|
|
|
66 |
}
|
67 |
}
|
68 |
""")
|
69 |
+
|
70 |
+
# Compile with mcs
|
71 |
compile_cmd = [
|
72 |
"mcs",
|
73 |
+
'-optimize+',
|
74 |
+
'-out:' + exe_path,
|
|
|
|
|
75 |
cs_path
|
76 |
]
|
77 |
+
|
78 |
compile_result = subprocess.run(compile_cmd, capture_output=True, text=True)
|
79 |
if compile_result.returncode != 0:
|
80 |
print(f"Compile error: {compile_result.stderr}")
|
81 |
return None
|
82 |
+
|
83 |
# Create RAR using 7zip
|
84 |
rar_cmd = ['/usr/bin/7z', 'a', rar_path, exe_path]
|
85 |
rar_result = subprocess.run(rar_cmd, capture_output=True, text=True)
|
86 |
if rar_result.returncode != 0:
|
87 |
print(f"RAR error: {rar_result.stderr}")
|
88 |
return None
|
89 |
+
|
90 |
# Cleanup temporary files
|
91 |
try:
|
92 |
os.remove(cs_path)
|
93 |
os.remove(exe_path)
|
94 |
except Exception as e:
|
95 |
print(f"Cleanup error: {e}")
|
96 |
+
|
97 |
# Remove old RAR files
|
98 |
for old_file in Path(UPLOAD_FOLDER).glob('*.rar'):
|
99 |
if old_file != Path(rar_path):
|
|
|
101 |
os.remove(old_file)
|
102 |
except:
|
103 |
pass
|
104 |
+
|
105 |
return rar_path
|
106 |
+
|
107 |
except Exception as e:
|
108 |
print(f"Error: {str(e)}")
|
109 |
return None
|
110 |
|
111 |
+
|
112 |
def get_current_rar():
|
113 |
"""Get the current RAR file or create one if none exists"""
|
114 |
files = list(Path(UPLOAD_FOLDER).glob('*.rar'))
|