From b6919bdd908f53db8d1c13abb6bf5bccdd053d21 Mon Sep 17 00:00:00 2001 From: Aurora Freir <37246948+CatAndDogSoup@users.noreply.github.com> Date: Fri, 10 Mar 2023 14:07:24 +0000 Subject: [PATCH 1/3] Adding support for namespaces and clashing names Adds a function to handle namespaces ( : ) and clashing names using full names ( | ) by replacing those characters with ones that Windows supports by default. --- release/scripts/mgear/core/skin.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/release/scripts/mgear/core/skin.py b/release/scripts/mgear/core/skin.py index 9fce7e62..e4b6b3f5 100644 --- a/release/scripts/mgear/core/skin.py +++ b/release/scripts/mgear/core/skin.py @@ -23,6 +23,9 @@ FILE_JSON_EXT = ".jSkin" PACK_EXT = ".gSkinPack" +NAMESPACE_REPLACER = "~" +CLASH_REPLACER = "!" + ###################################### # Skin getters ###################################### @@ -200,6 +203,17 @@ def collectData(skinCls, dataDic): # Skin export ###################################### +def clash_and_namespace_fixer(filepath, toFile=True): + # This is a gross approach, but it does work as Windows + # supports ! (or CLASH_REPLACER if changed) but not | + # Same with : Namespaces and NAMESPACE_REPLACER + if toFile: + filepath = filepath.replace(":", NAMESPACE_REPLACER).replace("|", CLASH_REPLACER) + else: + filepath = filepath.replace(NAMESPACE_REPLACER, ":").replace(CLASH_REPLACER, "|") + + return filepath + def exportSkin(filePath=None, objs=None, *args): if not objs: if pm.selected(): @@ -222,8 +236,7 @@ def exportSkin(filePath=None, objs=None, *args): filePath = pm.fileDialog2(fileMode=0, fileFilter=fileFilters) if filePath: - filePath = filePath[0] - + filePath = clash_and_namespace_fixer(filepath=filePath[0], toFile=True) else: return False @@ -317,7 +330,7 @@ def exportSkinPack(packPath=None, objs=None, use_json=False, *args): packDic["rootPath"], packName = os.path.split(packPath) for obj in objs: - fileName = obj.stripNamespace() + file_ext + fileName = clash_and_namespace_fixer(filePath=obj.stripNamespace(), toFile=True) + file_ext filePath = os.path.join(packDic["rootPath"], fileName) if exportSkin(filePath, [obj], use_json): packDic["packFiles"].append(fileName) @@ -448,7 +461,7 @@ def getObjsFromSkinFile(filePath=None, *args): def importSkin(filePath=None, *args): - + filePath = clash_and_namespace_fixer(filepath=filePath, toFile=False) if not filePath: f1 = 'mGear Skin (*{0} *{1})'.format(FILE_EXT, FILE_JSON_EXT) f2 = ";;gSkin Binary (*{0});;jSkin ASCII (*{1})".format( From ada232b4190ef690cc7575e7fb8556d960074020 Mon Sep 17 00:00:00 2001 From: Aurora Freir <37246948+CatAndDogSoup@users.noreply.github.com> Date: Mon, 13 Mar 2023 16:41:17 +0000 Subject: [PATCH 2/3] Fixing argument name, and issue with namespace export --- release/scripts/mgear/core/skin.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/release/scripts/mgear/core/skin.py b/release/scripts/mgear/core/skin.py index e4b6b3f5..1a4a1f8b 100644 --- a/release/scripts/mgear/core/skin.py +++ b/release/scripts/mgear/core/skin.py @@ -207,10 +207,15 @@ def clash_and_namespace_fixer(filepath, toFile=True): # This is a gross approach, but it does work as Windows # supports ! (or CLASH_REPLACER if changed) but not | # Same with : Namespaces and NAMESPACE_REPLACER + filedir = os.path.dirname(filepath) + if filedir: + filedir = filedir + "/" + filename = os.path.basename(filepath) + raw_name, extension = os.path.splitext(filename) if toFile: - filepath = filepath.replace(":", NAMESPACE_REPLACER).replace("|", CLASH_REPLACER) + filepath = filedir + raw_name.replace(":", NAMESPACE_REPLACER).replace("|", CLASH_REPLACER) + extension else: - filepath = filepath.replace(NAMESPACE_REPLACER, ":").replace(CLASH_REPLACER, "|") + filepath = filedir + raw_name.replace(NAMESPACE_REPLACER, ":").replace(CLASH_REPLACER, "|") + extension return filepath @@ -330,7 +335,7 @@ def exportSkinPack(packPath=None, objs=None, use_json=False, *args): packDic["rootPath"], packName = os.path.split(packPath) for obj in objs: - fileName = clash_and_namespace_fixer(filePath=obj.stripNamespace(), toFile=True) + file_ext + fileName = clash_and_namespace_fixer(filepath=obj.name(), toFile=True) + file_ext filePath = os.path.join(packDic["rootPath"], fileName) if exportSkin(filePath, [obj], use_json): packDic["packFiles"].append(fileName) @@ -461,7 +466,7 @@ def getObjsFromSkinFile(filePath=None, *args): def importSkin(filePath=None, *args): - filePath = clash_and_namespace_fixer(filepath=filePath, toFile=False) + filePath = clash_and_namespace_fixer(filepath=filePath, toFile=True) if not filePath: f1 = 'mGear Skin (*{0} *{1})'.format(FILE_EXT, FILE_JSON_EXT) f2 = ";;gSkin Binary (*{0});;jSkin ASCII (*{1})".format( @@ -570,7 +575,7 @@ def importSkinPack(filePath=None, *args): packDic = json.load(fp) for pFile in packDic["packFiles"]: filePath = os.path.join(os.path.split(filePath)[0], pFile) - importSkin(filePath, True) + importSkin(clash_and_namespace_fixer(filepath=filePath, toFile=True), True) ###################################### # Skin Copy From d8e733d59b992b28447e3ff57bd68a05bef767f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Gallo?= Date: Fri, 22 Sep 2023 00:02:37 -0600 Subject: [PATCH 3/3] Removes conflicting clash_and_namespace_fixer call in importSkin This call was causing problems when calling Import Skin from the UI --- release/scripts/mgear/core/skin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/release/scripts/mgear/core/skin.py b/release/scripts/mgear/core/skin.py index 1a4a1f8b..89af6105 100644 --- a/release/scripts/mgear/core/skin.py +++ b/release/scripts/mgear/core/skin.py @@ -466,7 +466,6 @@ def getObjsFromSkinFile(filePath=None, *args): def importSkin(filePath=None, *args): - filePath = clash_and_namespace_fixer(filepath=filePath, toFile=True) if not filePath: f1 = 'mGear Skin (*{0} *{1})'.format(FILE_EXT, FILE_JSON_EXT) f2 = ";;gSkin Binary (*{0});;jSkin ASCII (*{1})".format(