Skip to content

Commit 331109b

Browse files
On branch main
Your branch is ahead of 'origin/main' by 3 commits. (use "git push" to publish your local commits) Changes to be committed: new file: .gitignore new file: .vscode/c_cpp_properties.json new file: .vscode/settings.json new file: .vscode/tasks.json new file: onion.py new file: release/main.exe new file: release/openal32.dll new file: release/sfml-audio-2.dll new file: release/sfml-audio-d-2.dll new file: release/sfml-graphics-2.dll new file: release/sfml-graphics-d-2.dll new file: release/sfml-network-2.dll new file: release/sfml-network-d-2.dll new file: release/sfml-system-2.dll new file: release/sfml-system-d-2.dll new file: release/sfml-window-2.dll new file: release/sfml-window-d-2.dll new file: release_pack.zip new file: src/custom_headers/grid.cpp new file: src/custom_headers/grid.hpp new file: src/custom_headers/randoms.cpp new file: src/custom_headers/randoms.hpp new file: src/custom_headers/utils.cpp new file: src/custom_headers/utils.hpp new file: src/exec/main.exe new file: src/exec/openal32.dll new file: src/exec/sfml-audio-2.dll new file: src/exec/sfml-audio-d-2.dll new file: src/exec/sfml-graphics-2.dll new file: src/exec/sfml-graphics-d-2.dll new file: src/exec/sfml-network-2.dll new file: src/exec/sfml-network-d-2.dll new file: src/exec/sfml-system-2.dll new file: src/exec/sfml-system-d-2.dll new file: src/exec/sfml-window-2.dll new file: src/exec/sfml-window-d-2.dll new file: src/main.cpp new file: src_pack.zip
1 parent 8b9f209 commit 331109b

38 files changed

+570
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.obj
2+
*.pdb
3+
*.ilk

.vscode/c_cpp_properties.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
// "D:/ProgramsAndApps/SFML-2.6.1/include/SFML/",
8+
"D:/ProgramsAndApps/SFML-2.6.1/include/"
9+
],
10+
"defines": [
11+
"_DEBUG",
12+
"UNICODE",
13+
"_UNICODE"
14+
],
15+
"windowsSdkVersion": "10.0.22621.0",
16+
"compilerPath": "cl.exe",
17+
"cStandard": "c17",
18+
"cppStandard": "c++17",
19+
"intelliSenseMode": "windows-msvc-x64"
20+
}
21+
],
22+
"version": 4
23+
}

.vscode/settings.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"files.associations": {
3+
"*.COBOL*": "cobol",
4+
"*.COB*": "cobol",
5+
"*.COBCOPY*": "cobol",
6+
"*.COPYBOOK*": "cobol",
7+
"*.COPY*": "cobol",
8+
"*.PL1*": "pl1",
9+
"*.PLI*": "pl1",
10+
"*.INC*": "pl1",
11+
"*.INCLUDE*": "pl1",
12+
"*.JCL*": "jcl",
13+
"*.ASM*": "hlasm",
14+
"*.ASSEMBLE*": "hlasm",
15+
"*.HLASM*": "hlasm",
16+
"*.HLA*": "hlasm",
17+
"*.EXEC*": "rexx",
18+
"*.REXX*": "rexx",
19+
"*.REXXINC*": "rexx",
20+
"*.copyasm": "hlasm",
21+
"*.macasm": "hlasm",
22+
"*.bms": "hlasm",
23+
"*.rex": "rexx",
24+
"*.rexx": "rexx",
25+
"*.rmd": "markdown",
26+
"random": "cpp",
27+
"vector": "cpp",
28+
"iostream": "cpp"
29+
}
30+
}

.vscode/tasks.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "cppbuild",
6+
"label": "C/C++: cl.exe build active file",
7+
"command": "cl.exe",
8+
"args": [
9+
"/Zi",
10+
"/EHsc",
11+
"/nologo",
12+
// "/Fd${workspaceFolder}\\intermediate\\",
13+
"/I\"D:/ProgramsAndApps/SFML-2.6.1/include\"",
14+
// "/I\"${workspaceFolder}/src/custom_headers\"",
15+
"/Fo${workspaceFolder}\\src\\obj\\",
16+
"${file}",
17+
"${workspaceFolder}/src/custom_headers/grid.cpp",
18+
"${workspaceFolder}/src/custom_headers/randoms.cpp",
19+
"${workspaceFolder}/src/custom_headers/utils.cpp",
20+
"/link",
21+
// "/ILK:${workspaceFolder}\\intermediate\\${fileBasenameNoExtension}.ilk",
22+
"/MACHINE:X86",
23+
// "/OUT:${workspaceFolder}\\output\\${fileBasenameNoExtension}.exe",
24+
"/LIBPATH:\"D:/ProgramsAndApps/SFML-2.6.1/lib\"",
25+
"sfml-system.lib",
26+
"sfml-window.lib",
27+
"sfml-graphics.lib",
28+
"sfml-network.lib",
29+
"sfml-audio.lib"
30+
],
31+
"options": {
32+
"cwd": "${fileDirname}"
33+
},
34+
"problemMatcher": [
35+
"$msCompile"
36+
],
37+
"group": {
38+
"kind": "build",
39+
"isDefault": true
40+
},
41+
"detail": "compiler: cl.exe"
42+
}
43+
]
44+
}

onion.py

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import argparse
2+
import subprocess
3+
import shutil
4+
import os
5+
import glob
6+
7+
output_exe_name = "main.exe"
8+
9+
workspace_folder = os.getcwd()
10+
11+
release_folder = os.path.join(workspace_folder, "release")
12+
src_folder = os.path.join(workspace_folder, "src")
13+
14+
release_exe_path = os.path.join(release_folder, output_exe_name)
15+
16+
exec_folder = os.path.join(src_folder, "exec")
17+
custom_headers_folder = os.path.join(src_folder, "custom_headers")
18+
obj_folder = os.path.join(src_folder, "obj")
19+
main_cpp_file_path = os.path.join(src_folder, "main.cpp")
20+
21+
src_exe_path = os.path.join(exec_folder, output_exe_name)
22+
custom_header_cpp_file_paths = glob.glob(os.path.join(custom_headers_folder, "*.cpp"))
23+
24+
def run_command(command):
25+
causes = [
26+
"Memory runtime error in C++.",
27+
"Null pointer error in C++.",
28+
"Stack overflow error in C++.",
29+
"The required sfml dlls are missing. They should be in the same folder as main.exe.",
30+
"Not enough memory available for the program to run.",
31+
"Include file or some other path related error."
32+
]
33+
try:
34+
result = subprocess.run(command, capture_output=True, text=True, check=True, shell=True)
35+
print(' '.join(command), "executed with code", result.returncode)
36+
print(result.stdout)
37+
except subprocess.CalledProcessError as e:
38+
if(e != None): print(f"Error Happened: {e}")
39+
if(e.stdout != None and e.stdout != ""): print(f"Output: {e.stdout}")
40+
if(e.stderr != None and e.stderr != ""): print(f"Error: {e.stderr}")
41+
print(f"Something went wrong, probable causes:")
42+
for cause in causes:
43+
print("\t"+cause)
44+
45+
def make_debug_build():
46+
custom_header_cpp_file_paths_str = " ".join(custom_header_cpp_file_paths)
47+
custom_header_cpp_file_paths_str_formatted = custom_header_cpp_file_paths_str.replace("\\", "/")
48+
main_cpp_file_path_formatted = main_cpp_file_path.replace("\\", "/")
49+
obj_folder_formatted = obj_folder.replace("\\", "/") + '/'
50+
exec_folder_formatted = exec_folder.replace("\\", "/") + '/'
51+
52+
print("Making Debug Build...")
53+
command = [
54+
"""cmd /c chcp 65001>nul""",
55+
"""&& cd src """,
56+
f"""&& cl.exe /Zi /EHsc /nologo /ID:/ProgramsAndApps/SFML-2.6.1/include /Fo{obj_folder_formatted} {main_cpp_file_path_formatted} {custom_header_cpp_file_paths_str_formatted} /Fe{exec_folder_formatted} /Fd{exec_folder_formatted} /link /MACHINE:X86 /LIBPATH:"D:/ProgramsAndApps/SFML-2.6.1/lib" sfml-system.lib sfml-window.lib sfml-graphics.lib sfml-network.lib sfml-audio.lib"""
57+
]
58+
run_command(command)
59+
60+
def copy_file(src_path, release_path, filename):
61+
try:
62+
shutil.copy(src_path, release_path)
63+
print(f"Copied {filename} to the {release_path}")
64+
except FileNotFoundError as e:
65+
print(f"Error copying {filename}: {e}")
66+
except Exception as e:
67+
print(f"Unexpected error: {e}")
68+
69+
def check_then_build_src_exe():
70+
if not os.path.isfile(src_exe_path):
71+
print(f"{output_exe_name} does not exist in src folder, running build...")
72+
make_debug_build()
73+
else:
74+
print(f"Latest {output_exe_name} found in src folder")
75+
76+
def make_release_build():
77+
print("Making Release Build...")
78+
79+
if os.path.isfile(release_exe_path):
80+
isOverwrite = ""
81+
while(isOverwrite != "y" and isOverwrite != "n"):
82+
print(f"{output_exe_name} already exists in release folder. Overwrite? (Y/N): ", end="")
83+
isOverwrite = input()
84+
isOverwrite.lower()
85+
if(isOverwrite == "y"):
86+
check_then_build_src_exe()
87+
print("Overwriting...")
88+
copy_file(src_exe_path, release_exe_path, output_exe_name)
89+
break
90+
elif(isOverwrite == "n"):
91+
print("Exiting...")
92+
break
93+
else:
94+
print("Invalid Option.")
95+
else:
96+
print(f"{output_exe_name} does not exist in release folder, checking src...")
97+
check_then_build_src_exe()
98+
print("Copying...")
99+
copy_file(src_exe_path, release_exe_path, output_exe_name)
100+
101+
def run_release_program():
102+
print("Running Release Build Program...")
103+
release_exe_path = os.path.join(release_folder, output_exe_name)
104+
command = [
105+
f"cmd /c chcp 65001>nul && {release_exe_path}"
106+
]
107+
if not os.path.isfile(release_exe_path):
108+
print("Release build not found. Building new release...")
109+
make_release_build()
110+
run_command(command)
111+
112+
def run_debug_program():
113+
print("Running Debug Build Program...")
114+
src_exe_path = os.path.join(exec_folder, output_exe_name)
115+
command = [
116+
f"cmd /c chcp 65001>nul && {src_exe_path}"
117+
]
118+
if not os.path.isfile(src_exe_path):
119+
print("Debug build not found. Building new debug...")
120+
make_debug_build()
121+
run_command(command)
122+
123+
def pack_to_zip(folder_path, output_zip):
124+
if not os.path.exists(folder_path):
125+
print(f"The folder {folder_path} does not exist.")
126+
return
127+
128+
shutil.make_archive(output_zip, 'zip', folder_path)
129+
print(f"Folder '{folder_path}' has been compressed to '{output_zip}.zip'")
130+
131+
def pack_release():
132+
output_zip = 'release_pack'
133+
pack_to_zip(release_folder, output_zip)
134+
135+
def pack_debug():
136+
output_zip = 'src_pack'
137+
pack_to_zip(src_folder, output_zip)
138+
139+
140+
def main():
141+
parser = argparse.ArgumentParser(description="Build and Run Utility")
142+
143+
action_choices = ['make', 'run', 'pack']
144+
build_type_choices = ['debug', 'release']
145+
parser.add_argument("action", choices=action_choices,
146+
help="Action: 'make', 'run' or 'pack'")
147+
parser.add_argument("build_type", choices=build_type_choices,
148+
help="Build type: 'debug' or 'release'")
149+
150+
args = parser.parse_args()
151+
152+
if args.action == 'make':
153+
if args.build_type == 'debug':
154+
make_debug_build()
155+
elif args.build_type == 'release':
156+
make_release_build()
157+
elif args.action == 'run':
158+
if args.build_type == 'debug':
159+
run_debug_program()
160+
elif args.build_type == 'release':
161+
run_release_program()
162+
elif args.action == 'pack':
163+
if args.build_type == 'debug':
164+
pack_debug()
165+
elif args.build_type == 'release':
166+
pack_release()
167+
168+
if __name__ == "__main__":
169+
main()

release/main.exe

827 KB
Binary file not shown.

release/openal32.dll

616 KB
Binary file not shown.

release/sfml-audio-2.dll

1.05 MB
Binary file not shown.

release/sfml-audio-d-2.dll

1.53 MB
Binary file not shown.

release/sfml-graphics-2.dll

742 KB
Binary file not shown.

0 commit comments

Comments
 (0)