Skip to content

Commit 7af2588

Browse files
Merge pull request #16 from cataclysmic-dev/patch-2
2 parents d180067 + 7f8e274 commit 7af2588

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

robloxpyc/climaker.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import sys
44

55
import os
6+
7+
from platform import uname
8+
69
if not (os.path.dirname(os.path.abspath(__file__)).startswith(sys.path[-1])):
710
from loader import loader
811
from textcompiler import *
@@ -153,15 +156,48 @@ def w():
153156
elif sys.argv[1] == "cd":
154157
# Duplicate the cwd directory, the original will be renamed to -compiled and the new one will be renamed to the original. For the new one, go through every lua descendant file in the current directory and delete it and create a new file with the same name but .py
155158
confirm = input(warn("Are you sure? This will duplicate the current directory and compile the files in the new directory.\n\nType 'yes' to continue."))
156-
if confirm == "yes":
159+
if confirm == "yes" and uname().system == "Windows":
160+
# check if cwd/default.project.json exists, if it does, then use that as the default project file
161+
#if os.path.exists(os.getcwd()+"/default.project.json"):
162+
# formatdefaultproj(os.getcwd()+"/default.project.json")
163+
# rename directory to -compiled
164+
path_name = os.getcwd()
165+
#os.rename(path_name, path_name+"-compiled")
166+
# duplicate the directory, remove the -compiled from the end
167+
shutil.copytree(path_name, path_name + "-compiled")
168+
# now we have 2 identical directories, one with -compiled and one without. for the one without, go through every lua descendant file in the current directory and delete it and create a new file with the same name but .py
169+
path = os.getcwd()
170+
171+
for r, d, f in os.walk(backwordreplace(path, "-compiled", "", 1)):
172+
for file in f:
173+
if '.lua' in file:
174+
luafilecontents = ""
175+
with open(os.path.join(r, file), "r") as f:
176+
luafilecontents = f.read()
177+
178+
os.remove(os.path.join(r, file))
179+
180+
# create new file with same name but .py and write the lua file contents to it
181+
open(os.path.join(r, file.replace(".lua", basefile)), "x").close()
182+
# write the old file contents as a C++ comment
183+
open(os.path.join(r, file.replace(".lua", basefile)), "w").write("\"\"\"\n"+luafilecontents+"\n\"\"\"")
184+
185+
print(colortext.green("Converted "+os.path.join(r, file)+" to "+file.replace(".lua", basefile)))
186+
# create a .rpyc file in the non -compiled directory
187+
open(os.path.join(backwordreplace(path, "-compiled", "", 1), ".rpyc"), "x").close()
188+
# set cwd to not -compiled
189+
os.chdir(backwordreplace(path, "-compiled", "", 1))
190+
print(info("Completed! You may need to modify the default.package.json or any other equivalent file to make it use the -compiled directory rather than the original."))
191+
elif confirm == "yes":
192+
# note by CataclysmicDev -> i left this old code here just to make sure its stable on unix but you can delete it and see if the above code works on unix too
157193
path = os.path.join(os.getcwd(), "src")
158194
# check if cwd/default.project.json exists, if it does, then use that as the default project file
159195
#if os.path.exists(os.getcwd()+"/default.project.json"):
160196
# formatdefaultproj(os.getcwd()+"/default.project.json")
161197
# rename directory to -compiled
162-
os.rename(path, path+"-compiled")
198+
os.rename(path_name, path_name+"-compiled")
163199
# duplicate the directory, remove the -compiled from the end
164-
shutil.copytree(path+"-compiled", path)
200+
shutil.copytree(path_name + "-compiled", path_name)
165201
# now we have 2 identical directories, one with -compiled and one without. for the one without, go through every lua descendant file in the current directory and delete it and create a new file with the same name but .py
166202
path = os.getcwd()
167203

@@ -197,4 +233,4 @@ def w():
197233
except KeyboardInterrupt:
198234
print(colortext.red("Aborted!"))
199235
sys.exit(0)
200-
return w
236+
return w

0 commit comments

Comments
 (0)