Skip to content

Commit 4fda196

Browse files
committed
error+clearing handling
1 parent 9cadd62 commit 4fda196

1 file changed

Lines changed: 134 additions & 109 deletions

File tree

FT_Builder.py

Lines changed: 134 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def get_valid_description_directory():
163163
if not DescriptionDir:
164164
# User left it empty or canceled, skip
165165
print("Description directory selection skipped.")
166-
return None, None, None, None # Return None for all values
166+
return "", "", "", "" # Return None for all values
167167

168168
# Check if DescriptionDir is a valid directory
169169
if os.path.isdir(DescriptionDir):
@@ -182,6 +182,27 @@ def get_valid_description_directory():
182182

183183

184184

185+
def delete_files_in_directory(directory_path):
186+
try:
187+
# Check if the directory exists
188+
if os.path.exists(directory_path):
189+
# Iterate over all files and subdirectories in the directory
190+
for root, dirs, files in os.walk(directory_path, topdown=False):
191+
for file_name in files:
192+
file_path = os.path.join(root, file_name)
193+
os.remove(file_path) # Delete the file
194+
for dir_name in dirs:
195+
dir_path = os.path.join(root, dir_name)
196+
shutil.rmtree(dir_path) # Delete the subdirectory and its contents
197+
shutil.rmtree(directory_path)
198+
print(f"generated custom folder deleted")
199+
else:
200+
print(f"no custom folder found")
201+
except Exception as e:
202+
print(f"An error occurred while deleting the files in the custom folder, error: {e}")
203+
204+
205+
185206

186207

187208

@@ -226,118 +247,122 @@ def main():
226247

227248

228249

250+
try:
251+
#creates the funky subfolders
252+
target_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher', 'data', 'DiffFiles'))
253+
os.makedirs(target_dir, exist_ok=True)
254+
255+
256+
#location of the hdiff builds
257+
hdiffz = os.path.join(os.path.dirname(__file__), 'hdiff', 'hdiffz.exe')
258+
hpatchz = os.path.join(os.path.dirname(__file__), 'hdiff', 'hpatchz.exe')
259+
260+
#location of the diff files
261+
NameFBXDiffFile = NameCustomAvatarDir + 'Diff'
262+
NameMetaDiffFile = NameCustomAvatarDir + 'Meta' + 'Diff'
263+
FBXDiffFile = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher', 'data', 'DiffFiles', NameFBXDiffFile+".hdiff"))
264+
MetaDiffFile = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher', 'data', 'DiffFiles', NameMetaDiffFile+".hdiff"))
265+
266+
#creates the FBXDiffFile
267+
if subprocess.run([hdiffz, '-f', OriginalFBX, FaceTrackedFBX, FBXDiffFile]).returncode != 0:
268+
print("Error occurred during creation of the diff file.")
269+
input("Press Enter to continue...")
270+
271+
#creates the MetaFBXDiffFile
272+
if subprocess.run([hdiffz, '-f', OriginalFBX+".meta", FaceTrackedFBX+".meta", MetaDiffFile]).returncode != 0:
273+
print("Error occurred during creation of the meta diff file.")
274+
input("Press Enter to continue...")
275+
276+
#location of the og script and the destination script
277+
OriginalScript = os.path.abspath(os.path.join(__file__, '..', 'PythonPatcher.py'))
278+
destination_path = os.path.abspath(os.path.join(os.path.dirname(__file__),"! "+ NameCustomAvatarDir + "Patcher.py"))
279+
280+
print("OriginalScript:", OriginalScript)
281+
print("destination_path:", destination_path)
282+
283+
shutil.copy(OriginalScript, destination_path)
284+
285+
#modifying the script with the input files (makes sure it's using the right formating)
286+
modify_python_patcher_script(
287+
get_assets_relative_path(OriginalFBX).replace("\\", "/"),
288+
get_assets_relative_path(OriginalFBX+".meta").replace("\\", "/"),
289+
NameFBXDiffFile,
290+
NameMetaDiffFile,
291+
os.path.basename(FaceTrackedFBX).replace("\\", "/"),
292+
NameCustomAvatarDir
293+
)
229294

230-
#creates the funky subfolders
231-
target_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher', 'data', 'DiffFiles'))
232-
os.makedirs(target_dir, exist_ok=True)
233-
234-
235-
#location of the hdiff builds
236-
hdiffz = os.path.join(os.path.dirname(__file__), 'hdiff', 'hdiffz.exe')
237-
hpatchz = os.path.join(os.path.dirname(__file__), 'hdiff', 'hpatchz.exe')
238-
239-
#location of the diff files
240-
NameFBXDiffFile = NameCustomAvatarDir + 'Diff'
241-
NameMetaDiffFile = NameCustomAvatarDir + 'Meta' + 'Diff'
242-
FBXDiffFile = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher', 'data', 'DiffFiles', NameFBXDiffFile+".hdiff"))
243-
MetaDiffFile = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher', 'data', 'DiffFiles', NameMetaDiffFile+".hdiff"))
244-
245-
#creates the FBXDiffFile
246-
if subprocess.run([hdiffz, '-f', OriginalFBX, FaceTrackedFBX, FBXDiffFile]).returncode != 0:
247-
print("Error occurred during creation of the diff file.")
248-
input("Press Enter to continue...")
249-
250-
#creates the MetaFBXDiffFile
251-
if subprocess.run([hdiffz, '-f', OriginalFBX+".meta", FaceTrackedFBX+".meta", MetaDiffFile]).returncode != 0:
252-
print("Error occurred during creation of the meta diff file.")
253-
input("Press Enter to continue...")
254-
255-
#location of the og script and the destination script
256-
OriginalScript = os.path.abspath(os.path.join(__file__, '..', 'PythonPatcher.py'))
257-
destination_path = os.path.abspath(os.path.join(os.path.dirname(__file__),"! "+ NameCustomAvatarDir + "Patcher.py"))
258-
259-
print("OriginalScript:", OriginalScript)
260-
print("destination_path:", destination_path)
261-
262-
shutil.copy(OriginalScript, destination_path)
263-
264-
#modifying the script with the input files (makes sure it's using the right formating)
265-
modify_python_patcher_script(
266-
get_assets_relative_path(OriginalFBX).replace("\\", "/"),
267-
get_assets_relative_path(OriginalFBX+".meta").replace("\\", "/"),
268-
NameFBXDiffFile,
269-
NameMetaDiffFile,
270-
os.path.basename(FaceTrackedFBX).replace("\\", "/"),
271-
NameCustomAvatarDir
272-
)
273-
274-
275-
#build the patcher
276-
buildDestination = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher'))
277-
PyInstaller.__main__.run([
278-
"! "+NameCustomAvatarDir+"Patcher.py",
279-
'--onedir',
280-
'--distpath', buildDestination,
281-
'--icon='+ os.path.abspath(os.path.join(os.path.dirname(__file__), 'YourCoolIcon.ico'))
282-
])
283-
284-
285-
#moving patcher files over
286-
source_dir = os.path.join(buildDestination, "! "+NameCustomAvatarDir+"Patcher")
287-
file_names = os.listdir(source_dir)
288-
289-
for file_name in file_names:
290-
shutil.move(os.path.join(source_dir, file_name), buildDestination)
291-
292-
#moving evrything that can be under the data folder
293-
294-
files_to_exclude = [
295-
"! "+NameCustomAvatarDir+"Patcher.exe",
296-
"base_library.zip",
297-
NameFBXDiffFile+".hdiff",
298-
NameMetaDiffFile+".hdiff"
299-
]
300-
301-
dll_names_to_exclude = ["python"]
302295

303-
for root, _, files in os.walk(buildDestination):
304-
for file_name in files:
305-
source_path = os.path.join(root, file_name)
306-
destination_path = ""
307-
308-
if file_name in files_to_exclude:
309-
continue
310-
311-
is_dll_with_python = any(name in file_name.lower() for name in dll_names_to_exclude)
312-
if is_dll_with_python:
313-
continue
314-
else:
315-
destination_path = os.path.join(buildDestination, 'data', file_name)
316-
317-
shutil.move(source_path, destination_path)
318-
319-
shutil.copy(hpatchz, os.path.join(buildDestination, 'data', 'hpatchz.exe'))
320-
shutil.copy(os.path.join(hpatchz, '..', 'License.txt'), os.path.join(buildDestination, 'data', 'License.txt'))
321-
os.rmdir(source_dir)
322-
print("Files moved to the 'data' folder.")
323-
324-
if DescriptionDir != '':
325-
#remplacing descriptions and readme placeholders
326-
DirPatcher = os.path.join('Assets', NameCustomDir, NameCustomAvatarDir, 'patcher')
327-
DirPrefab = os.path.join('Assets', NameCustomDir, NameCustomAvatarDir, 'prefab')
328-
329-
replace_placeholders_in_files_in_directory(
330-
DescriptionDir,
331-
NameCustomAvatarDir,
332-
CreatorName,
333-
BoothPage,
334-
PackageName,
335-
DirPatcher,
336-
DirPrefab,
337-
)
296+
#build the patcher
297+
buildDestination = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir, NameCustomAvatarDir, 'patcher'))
298+
PyInstaller.__main__.run([
299+
"! "+NameCustomAvatarDir+"Patcher.py",
300+
'--onedir',
301+
'--distpath', buildDestination,
302+
'--icon='+ os.path.abspath(os.path.join(os.path.dirname(__file__), 'YourCoolIcon.ico'))
303+
])
338304

339305

340-
print_ascii_Ready()
306+
#moving patcher files over
307+
source_dir = os.path.join(buildDestination, "! "+NameCustomAvatarDir+"Patcher")
308+
file_names = os.listdir(source_dir)
309+
310+
for file_name in file_names:
311+
shutil.move(os.path.join(source_dir, file_name), buildDestination)
312+
313+
#moving evrything that can be under the data folder
314+
315+
files_to_exclude = [
316+
"! "+NameCustomAvatarDir+"Patcher.exe",
317+
"base_library.zip",
318+
NameFBXDiffFile+".hdiff",
319+
NameMetaDiffFile+".hdiff"
320+
]
321+
322+
dll_names_to_exclude = ["python"]
323+
324+
for root, _, files in os.walk(buildDestination):
325+
for file_name in files:
326+
source_path = os.path.join(root, file_name)
327+
destination_path = ""
328+
329+
if file_name in files_to_exclude:
330+
continue
331+
332+
is_dll_with_python = any(name in file_name.lower() for name in dll_names_to_exclude)
333+
if is_dll_with_python:
334+
continue
335+
else:
336+
destination_path = os.path.join(buildDestination, 'data', file_name)
337+
338+
shutil.move(source_path, destination_path)
339+
340+
shutil.copy(hpatchz, os.path.join(buildDestination, 'data', 'hpatchz.exe'))
341+
shutil.copy(os.path.join(hpatchz, '..', 'License.txt'), os.path.join(buildDestination, 'data', 'License.txt'))
342+
os.rmdir(source_dir)
343+
print("Files moved to the 'data' folder.")
344+
345+
if DescriptionDir != '':
346+
#remplacing descriptions and readme placeholders
347+
DirPatcher = os.path.join('Assets', NameCustomDir, NameCustomAvatarDir, 'patcher')
348+
DirPrefab = os.path.join('Assets', NameCustomDir, NameCustomAvatarDir, 'prefab')
349+
350+
replace_placeholders_in_files_in_directory(
351+
DescriptionDir,
352+
NameCustomAvatarDir,
353+
CreatorName,
354+
BoothPage,
355+
PackageName,
356+
DirPatcher,
357+
DirPrefab,
358+
)
359+
360+
361+
print_ascii_Ready()
362+
except Exception as e:
363+
CustomDir = os.path.abspath(os.path.join(os.path.dirname(__file__), NameCustomDir))
364+
delete_files_in_directory(CustomDir)
365+
print("An error occurred while copying the file:", str(e))
341366

342367

343368
if __name__ == "__main__":

0 commit comments

Comments
 (0)