Skip to content

Commit

Permalink
Partial Unicode filename support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbui78 committed Oct 7, 2024
1 parent 167b6ce commit 6f275ec
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Cinema 4D/appdir_common/plugins/DazToC4D/DazToC4D.pyp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DZBRIDGE_VERSION_MAJOR = 2024
DZBRIDGE_VERSION_MINOR = 2
DZBRIDGE_VERSION_REVISION = 2
DZBRIDGE_VERSION_BUILD = 10
DZBRIDGE_VERSION_REVISION = 3
DZBRIDGE_VERSION_BUILD = 20
DZBRIDGE_VERSION_STRING = "v%s.%s.%s.%s" % (DZBRIDGE_VERSION_MAJOR, DZBRIDGE_VERSION_MINOR, DZBRIDGE_VERSION_REVISION, DZBRIDGE_VERSION_BUILD)
##
## DazToC4D
Expand Down
2 changes: 1 addition & 1 deletion Cinema 4D/appdir_common/plugins/DazToC4D/lib/DtuLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def load_dtu(self):
if file.endswith(".dtu"):
dtu = os.path.join(self.import_dir, file)
break
with open(dtu, "r") as data:
with open(dtu, "r", encoding="utf-8") as data:
self.dtu_dict = json.load(data)

def get_dtu_dict(self):
Expand Down
30 changes: 21 additions & 9 deletions DazStudioPlugin/DzC4DAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ QString FindC4DPyExe(QString sC4DExecutablePath)
return sC4DPyExe;
}

bool GenerateExporterBatchFile(QString batchFilePath, QString sExecutablePath, QString sCommandArgs)
bool GenerateExporterBatchFile(QString batchFilePath, QString sExecutablePath, QString sCommandArgs, QString sCWD)
{
QString sBatchFileFolder = QFileInfo(batchFilePath).dir().path().replace("\\", "/");
QDir().mkdir(sBatchFileFolder);

// 4. Generate manual batch file to launch exporter scripts
QString sBatchString = QString("\"%1\"").arg(sExecutablePath);

QString sBatchString = QString("\
chcp 65001\n\n\
cd /d \"%1\"\n\n\
\"%2\"\
").arg(sCWD).arg(sExecutablePath);
foreach(QString arg, sCommandArgs.split(";"))
{
if (arg.contains(" "))
Expand All @@ -80,7 +85,7 @@ bool GenerateExporterBatchFile(QString batchFilePath, QString sExecutablePath, Q
QFile batchFileOut(batchFilePath);
bool bResult = batchFileOut.open(QIODevice::WriteOnly | QIODevice::OpenModeFlag::Truncate);
if (bResult) {
batchFileOut.write(sBatchString.toAscii().constData());
batchFileOut.write(sBatchString.toUtf8().constData());
batchFileOut.close();
}
else {
Expand Down Expand Up @@ -156,8 +161,11 @@ DzError DzC4DExporter::write(const QString& filename, const DzFileIOSettings* op

//////////////////////////////////////////////////////////////////////////////////////////

QString sC4DLogPath = sIntermediatePath + "/" + "create_c4d_file.log";
QString sScriptPath = sIntermediateScriptsPath + "/" + "create_c4d_file.py";
//QString sC4DLogPath = sIntermediatePath + "/" + "create_c4d_file.log";
//QString sScriptPath = sIntermediateScriptsPath + "/" + "create_c4d_file.py";
//QString sCommandArgs = QString("%1;%2").arg(sScriptPath).arg(pC4DAction->m_sDestinationFBX);
QString sC4DLogPath = QString(".") + "/" + "create_c4d_file.log";
QString sScriptPath = QString("./Scripts") + "/" + "create_c4d_file.py";
QString sCommandArgs = QString("%1;%2").arg(sScriptPath).arg(pC4DAction->m_sDestinationFBX);
#if WIN32
QString batchFilePath = sIntermediatePath + "/" + "create_c4d_file.bat";
Expand All @@ -174,7 +182,7 @@ DzError DzC4DExporter::write(const QString& filename, const DzFileIOSettings* op
exportProgress.cancel();
return DZ_OPERATION_FAILED_ERROR;
}
GenerateExporterBatchFile(batchFilePath, sC4DPyExecutable, sCommandArgs);
GenerateExporterBatchFile(batchFilePath, sC4DPyExecutable, sCommandArgs, sIntermediatePath);

bool result = pC4DAction->executeC4DScripts(sC4DPyExecutable, sCommandArgs, 120);

Expand All @@ -188,7 +196,9 @@ DzError DzC4DExporter::write(const QString& filename, const DzFileIOSettings* op
tr("Export from Daz Studio complete."), QMessageBox::Ok);

#ifdef WIN32
ShellExecuteA(NULL, "open", sC4DOutputPath.toLocal8Bit().data(), NULL, NULL, SW_SHOWDEFAULT);
// ShellExecuteA(NULL, "open", sC4DOutputPath.toLocal8Bit().data(), NULL, NULL, SW_SHOWDEFAULT);
std::wstring wcsC4DOutputPath(reinterpret_cast<const wchar_t*>(sC4DOutputPath.utf16()));
ShellExecuteW(NULL, L"open", wcsC4DOutputPath.c_str(), NULL, NULL, SW_SHOWDEFAULT);
#elif defined(__APPLE__)
QStringList args;
args << "-e";
Expand All @@ -214,7 +224,9 @@ DzError DzC4DExporter::write(const QString& filename, const DzFileIOSettings* op
sErrorString += QString("Please check log files at : %1\n").arg(pC4DAction->m_sDestinationPath);
QMessageBox::critical(0, "Cinema 4D Exporter", tr(sErrorString.toLocal8Bit()), QMessageBox::Ok);
#ifdef WIN32
ShellExecuteA(NULL, "open", pC4DAction->m_sDestinationPath.toLocal8Bit().data(), NULL, NULL, SW_SHOWDEFAULT);
// ShellExecuteA(NULL, "open", pC4DAction->m_sDestinationPath.toLocal8Bit().data(), NULL, NULL, SW_SHOWDEFAULT);
std::wstring wcsDestinationPath(reinterpret_cast<const wchar_t*>(pC4DAction->m_sDestinationPath.utf16()));
ShellExecuteW(NULL, L"open", wcsDestinationPath.c_str(), NULL, NULL, SW_SHOWDEFAULT);
#elif defined(__APPLE__)
QStringList args;
args << "-e";
Expand Down Expand Up @@ -694,7 +706,7 @@ Do you want to Abort the operation now?");
//#ifdef __APPLE__
// if (m_nC4DExitCode != 0 && m_nC4DExitCode != 120)
#//else
if (m_nC4DExitCode != 1)
if (m_nC4DExitCode != 0)
//#endif
{
//if (m_nMayaExitCode == m_nPythonExceptionExitCode) {
Expand Down
8 changes: 5 additions & 3 deletions DazStudioPlugin/Resources/Scripts/create_c4d_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _add_to_log(message):
logfile = g_logfile

print(str(message))
with open(logfile, "a") as file:
with open(logfile, "a", encoding="utf-8") as file:
file.write(str(message) + "\n")


Expand All @@ -40,17 +40,20 @@ def _main(argv):
_print_usage()
return

fbx_path = line.replace("\\","/").strip()
fbx_path = line.strip()
fbx_path = os.path.abspath(fbx_path).replace("\\", "/")
if (not os.path.exists(fbx_path)):
_add_to_log("ERROR: main(): fbx file not found: " + str(fbx_path))
raise Exception("FBX file not found: " + str(fbx_path))
_add_to_log("DEBUG: fbx_path=" + fbx_path)

if ("B_FIG" in fbx_path):
json_path = fbx_path.replace("B_FIG.fbx", "FIG.dtu")
elif ("B_ENV" in fbx_path):
json_path = fbx_path.replace("B_ENV.fbx", "ENV.dtu")
else:
json_path = fbx_path.replace(".fbx", ".dtu")
_add_to_log("DEBUG: json_path=" + json_path)

custom_importer = CustomImports.CustomImports()
os.chdir(Definitions.EXPORT_DIR)
Expand Down Expand Up @@ -88,4 +91,3 @@ def _main(argv):
_add_to_log("Starting script... DEBUG: sys.argv=" + str(sys.argv))
_main(sys.argv[1:])
print("script completed.")
exit(0)
Binary file modified DazStudioPlugin/Resources/c4dplugin.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions DazStudioPlugin/real_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#define PRODUCT_VERSION_STRING "2024 version 2.2"
#define VER_MAJOR 2024
#define VER_MINOR 2
#define VER_REV 2
#define VER_BUILD 10
#define VER_REV 3
#define VER_BUILD 20

#define TOSTRING(x) #x
#define VERSION_STRING TOSTRING(VER_MAJOR) "." TOSTRING(VER_MINOR) "." TOSTRING(VER_REV) "." TOSTRING(VER_BUILD)

0 comments on commit 6f275ec

Please sign in to comment.