sigyllly commited on
Commit
aeacaf3
·
verified ·
1 Parent(s): 5d10efa

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -20
main.py CHANGED
@@ -29,16 +29,17 @@ 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"script_{timestamp}.cs"
33
- exe_filename = f"script_{timestamp}.exe"
34
- archive_filename = f"output_{timestamp}.7z" # Use .7z instead of .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
- archive_path = os.path.join(UPLOAD_FOLDER, archive_filename)
40
 
41
- # Write C# source
42
  with open(cs_path, 'w') as f:
43
  f.write("""
44
  using System;
@@ -67,12 +68,14 @@ class Program
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)
@@ -80,13 +83,11 @@ class Program
80
  print(f"Compile error: {compile_result.stderr}")
81
  return None
82
 
83
- # Create 7z archive using 7zip
84
- seven_zip_cmd = ["/usr/bin/7z", "a", archive_path, exe_path]
85
- print(f"Running command: {' '.join(seven_zip_cmd)}") # Debugging output
86
-
87
- seven_zip_result = subprocess.run(seven_zip_cmd, capture_output=True, text=True)
88
- if seven_zip_result.returncode != 0:
89
- print(f"7z error: {seven_zip_result.stderr}")
90
  return None
91
 
92
  # Cleanup temporary files
@@ -96,15 +97,15 @@ class Program
96
  except Exception as e:
97
  print(f"Cleanup error: {e}")
98
 
99
- # Remove old archive files
100
- for old_file in Path(UPLOAD_FOLDER).glob('*.7z'):
101
- if old_file != Path(archive_path):
102
  try:
103
  os.remove(old_file)
104
  except:
105
  pass
106
 
107
- return archive_path
108
 
109
  except Exception as e:
110
  print(f"Error: {str(e)}")
 
29
  try:
30
  # Generate unique names
31
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
32
+ cs_filename = f"run_{timestamp}.cs"
33
+ exe_filename = f"run_{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("""
45
  using System;
 
68
  }
69
  """)
70
 
71
+ # Compile with mcs using custom flags
72
  compile_cmd = [
73
  "mcs",
74
+ "-target:winexe",
75
+ "-platform:x64",
76
+ f"-out:{exe_path}",
77
+ cs_path,
78
+ f"-win32icon:{icon_path}"
79
  ]
80
 
81
  compile_result = subprocess.run(compile_cmd, capture_output=True, text=True)
 
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
 
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):
103
  try:
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)}")