Skip to content

Commit

Permalink
fix: update YYCC dependency.
Browse files Browse the repository at this point in the history
- use YYCC to validate code page.
- fix build issue according to the changes of YYCC::StdPatch
- use YYCC to polyfill the contains function of C++ container.
- use YYCC utf8 style Win32 MoveFile and DeleteFile.
- fix include statement due to the changes of directory layout of YYCC.
- bump up version to 3.2
  • Loading branch information
yyc12345 committed Nov 4, 2024
1 parent 2138e46 commit 23d8fad
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 54 deletions.
8 changes: 4 additions & 4 deletions script/build.bat
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
@ECHO OFF
ECHO This script must be executed at the root of project. Press any key to continue...
PAUSE
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 3.0" -y "J:\YYCCommonplace\bin\msvc_install"
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 3.0" -y "J:\YYCCommonplace\bin\cpp17\msvc_install"
MSBuild src\vtobjplugin.sln -p:Configuration=Release -p:Platform=x86
python -m zipfile -c "E:\Virtools\Virtools Dev 3.0\InterfacePlugins\vtobjplugin_vt3.0.zip" "E:\Virtools\Virtools Dev 3.0\InterfacePlugins\vtobjplugin.dll" "E:\Virtools\Virtools Dev 3.0\InterfacePlugins\vtobjplugin.pdb"
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 3.5" -y "J:\YYCCommonplace\bin\msvc_install"
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 3.5" -y "J:\YYCCommonplace\bin\cpp17\msvc_install"
MSBuild src\vtobjplugin.sln -p:Configuration=Release -p:Platform=x86
python -m zipfile -c "E:\Virtools\Virtools Dev 3.5\InterfacePlugins\vtobjplugin_vt3.5.zip" "E:\Virtools\Virtools Dev 3.5\InterfacePlugins\vtobjplugin.dll" "E:\Virtools\Virtools Dev 3.5\InterfacePlugins\vtobjplugin.pdb"
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 4.0" -y "J:\YYCCommonplace\bin\msvc_install"
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 4.0" -y "J:\YYCCommonplace\bin\cpp17\msvc_install"
MSBuild src\vtobjplugin.sln -p:Configuration=Release -p:Platform=x86
python -m zipfile -c "E:\Virtools\Virtools Dev 4.0\InterfacePlugins\vtobjplugin_vt4.0.zip" "E:\Virtools\Virtools Dev 4.0\InterfacePlugins\vtobjplugin.dll" "E:\Virtools\Virtools Dev 4.0\InterfacePlugins\vtobjplugin.pdb"
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 5.0" -y "J:\YYCCommonplace\bin\msvc_install"
python "script\setup_env.py" -p "E:\Virtools\Virtools Dev 5.0" -y "J:\YYCCommonplace\bin\cpp17\msvc_install"
MSBuild src\vtobjplugin.sln -p:Configuration=Release -p:Platform=x86
python -m zipfile -c "E:\Virtools\Virtools Dev 5.0\InterfacePlugins\vtobjplugin_vt5.0.zip" "E:\Virtools\Virtools Dev 5.0\InterfacePlugins\vtobjplugin.dll" "E:\Virtools\Virtools Dev 5.0\InterfacePlugins\vtobjplugin.pdb"
ECHO Build Done.
2 changes: 1 addition & 1 deletion script/build_build_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main() -> None:
for ver in ('3.0', '3.5', '4.0', '5.0'):
vt_path: str = f'E:\Virtools\\Virtools Dev {ver}'
vt_interface_path: str = f'{vt_path}\InterfacePlugins'
writeline(f, f'python "script\\setup_env.py" -p "{vt_path}" -y "J:\\YYCCommonplace\\bin\\msvc_install"')
writeline(f, f'python "script\\setup_env.py" -p "{vt_path}" -y "J:\\YYCCommonplace\\bin\\cpp17\\msvc_install"')
writeline(f, f'MSBuild src\\vtobjplugin.sln -p:Configuration=Release -p:Platform=x86')
writeline(f, f'python -m zipfile -c "{vt_interface_path}\\vtobjplugin_vt{ver}.zip" "{vt_interface_path}\\vtobjplugin.dll" "{vt_interface_path}\\vtobjplugin.pdb"')

Expand Down
4 changes: 2 additions & 2 deletions src/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace vtobjplugin {
if (!YYCC::WinFctHelper::GetModuleFileName(NULL, u8_virtools_path))
u8_virtools_path.clear();
// get its parent folder and append with cfg file name
std::filesystem::path virtools_path(YYCC::FsPathPatch::FromUTF8Path(u8_virtools_path.c_str()));
return YYCC::FsPathPatch::ToUTF8Path(virtools_path.parent_path() / YYCC::FsPathPatch::FromUTF8Path(YYCC_U8("vtobjplugin.cfg")));
std::filesystem::path virtools_path(YYCC::StdPatch::ToStdPath(u8_virtools_path));
return YYCC::StdPatch::ToUTF8Path(virtools_path.parent_path() / YYCC::StdPatch::ToStdPath(YYCC_U8("vtobjplugin.cfg")));
}

#define INIT_HELPER(name) name(YYCC_U8( #name ), g_DefaultExportSetting.name)
Expand Down
12 changes: 6 additions & 6 deletions src/ExportLayoutWeaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace vtobjplugin {
// get material
CKMaterial* material = mesh->GetMaterial(i);
if (material == nullptr) continue;
if (file.m_MaterialMap.find(material) != file.m_MaterialMap.end()) continue;
if (YYCC::StdPatch::Contains(file.m_MaterialMap, material)) continue;

// get name
YYCC::yycc_u8string ckobj_name(GetCKObjectName(material));
Expand All @@ -247,19 +247,19 @@ namespace vtobjplugin {
// get texture and validate it.
CKTexture* texture = pair.first->GetTexture();
if (texture == nullptr) continue;
if (m_TextureMap.find(texture) != m_TextureMap.end()) continue;
if (YYCC::StdPatch::Contains(m_TextureMap, texture)) continue;
if (texture->GetSlotFileName(0) == nullptr) { // skip if no slot file name
m_Reporter.Write(texture, m_StringLoader.LoadStringU8(IDS_EXPLAYOUT_TEX_NO_SLOT_FNAME).c_str());
continue;
}

// fetch associated texture path from virtools with given encoding
std::filesystem::path texture_path(YYCC::FsPathPatch::FromUTF8Path(
YYCC::EncodingHelper::CharToUTF8(texture->GetSlotFileName(0), m_ExportSetting.GetCompositionEncoding()).c_str()
std::filesystem::path texture_path(YYCC::StdPatch::ToStdPath(
YYCC::EncodingHelper::CharToUTF8(texture->GetSlotFileName(0), m_ExportSetting.GetCompositionEncoding())
));
// extract stem and extension part from given path
YYCC::yycc_u8string filename_stem(YYCC::FsPathPatch::ToUTF8Path(texture_path.stem())),
filename_extension(YYCC::FsPathPatch::ToUTF8Path(texture_path.extension()));
YYCC::yycc_u8string filename_stem(YYCC::StdPatch::ToUTF8Path(texture_path.stem())),
filename_extension(YYCC::StdPatch::ToUTF8Path(texture_path.extension()));

// correct stem part of given file.
// because file name also need to be written in mtl file
Expand Down
2 changes: 1 addition & 1 deletion src/ExportSettingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace vtobjplugin {
// only check custom encoding when it is enabled
if (RADIOBTN_GETCHECK(m_CompositionEncoding_Custom)) {
YYCC::yycc_u8string custom_encoding_strl(Utilities::GetCWndText(&m_CustomEncoding));
if (custom_encoding_strl.empty() || !YYCC::ParserHelper::TryParse<UINT>(custom_encoding_strl, custom_encoding) || !Utilities::ValidateCodePage(custom_encoding)) {
if (custom_encoding_strl.empty() || !YYCC::ParserHelper::TryParse<UINT>(custom_encoding_strl, custom_encoding) || !YYCC::WinFctHelper::IsValidCodePage(custom_encoding)) {
MessageBoxW(m_hWnd, string_loader.LoadStringW(IDS_EXPSETDLG_ERR_INVALID_CP).c_str(), errmsg_title.c_str(), MB_OK + MB_ICONERROR);
return;
}
Expand Down
38 changes: 18 additions & 20 deletions src/ObjExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,42 +394,40 @@ namespace vtobjplugin {
m_Reporter.Write(m_StringLoader.LoadStringU8(IDS_OBJEXP_ERR_TEMP_DIR).c_str());
return;
}
std::filesystem::path temp_directory(YYCC::FsPathPatch::FromUTF8Path(u8_temp_directory.c_str()));
std::filesystem::path temp_directory(YYCC::StdPatch::ToStdPath(u8_temp_directory));

// iterate texture list
for (const auto& texture : m_ExportLayoutWeaver.GetTextureMap()) {
// build temporary file path
// get texture file name and replace its stem to our GUID
// because we want to keep its extension
// which Virtools rely on it to decide the file type it should output.
auto temp_file = temp_directory / YYCC::FsPathPatch::FromUTF8Path(YYCC_U8("fc57c274-7f05-4e89-bbf0-678ad31c6774")); // a random generated GUID for this app
temp_file.replace_extension(YYCC::FsPathPatch::FromUTF8Path(texture.second.c_str()).extension());
auto temp_file = temp_directory / YYCC::StdPatch::ToStdPath(YYCC_U8("fc57c274-7f05-4e89-bbf0-678ad31c6774")); // a random generated GUID for this app
temp_file.replace_extension(YYCC::StdPatch::ToStdPath(texture.second).extension());

// get temp file wchar style and ascii style
auto u8_temp_file = YYCC::FsPathPatch::ToUTF8Path(temp_file);
// get utf8 style and ascii type of temp file.
auto u8_temp_file = YYCC::StdPatch::ToUTF8Path(temp_file);
std::string acp_temp_file;
std::wstring w_temp_file;
if (!YYCC::EncodingHelper::UTF8ToChar(u8_temp_file, acp_temp_file, CP_ACP) ||
!YYCC::EncodingHelper::UTF8ToWchar(u8_temp_file, w_temp_file)) {
if (!YYCC::EncodingHelper::UTF8ToChar(u8_temp_file, acp_temp_file, CP_ACP)) {
m_Reporter.Format(m_StringLoader.LoadStringU8(IDS_OBJEXP_ERR_TEMP_TEX).c_str(), u8_temp_file.c_str());
continue;
}

// get destination file path and wchar style
// get utf8 destination file path
auto u8_dest_file = GetExportFilePath(texture.second);
std::wstring w_dest_file;
if (!YYCC::EncodingHelper::UTF8ToWchar(u8_dest_file, w_dest_file)) {
m_Reporter.Format(m_StringLoader.LoadStringU8(IDS_OBJEXP_ERR_TEX).c_str(), u8_dest_file.c_str());
continue;
}

// save it by virtools function
texture.first->SaveImage(const_cast<CKSTRING>(acp_temp_file.c_str()));

// use W style Windows function
// to move saved texture to destination.
DeleteFileW(w_dest_file.c_str());
MoveFileW(w_temp_file.c_str(), w_dest_file.c_str());
// use utf8 function (underlying function is Windows W function) to move it to destination.
// delete destination file first to make sure move can work.
YYCC::WinFctHelper::DeleteFile(u8_dest_file);
// move it and check result.
if (!YYCC::WinFctHelper::MoveFile(u8_temp_file, u8_dest_file)) {
m_Reporter.Format(m_StringLoader.LoadStringU8(IDS_OBJEXP_ERR_TEX).c_str(), u8_dest_file.c_str());
continue;
}

}
}

Expand Down Expand Up @@ -529,10 +527,10 @@ namespace vtobjplugin {
YYCC::yycc_u8string ObjExporter::GetExportFilePath(const YYCC::yycc_u8string_view& filename) {
// get export firectory
std::filesystem::path export_directory(
YYCC::FsPathPatch::FromUTF8Path(m_ExportSetting.m_ExportDirectory.c_str())
YYCC::StdPatch::ToStdPath(m_ExportSetting.m_ExportDirectory)
);
// get full path output
return YYCC::FsPathPatch::ToUTF8Path(export_directory / YYCC::FsPathPatch::FromUTF8Path(filename.data()));
return YYCC::StdPatch::ToUTF8Path(export_directory / YYCC::StdPatch::ToStdPath(filename));
}

#pragma endregion
Expand Down
5 changes: 0 additions & 5 deletions src/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ namespace vtobjplugin::Utilities {

#pragma endregion

bool ValidateCodePage(UINT code_page) {
CPINFOEXW cpinfo;
return GetCPInfoExW(code_page, 0, &cpinfo);
}

void SetCWndText(CWnd* ctl, const YYCC::yycc_u8string_view& val) {
ctl->SetWindowTextA(YYCC::EncodingHelper::UTF8ToChar(val, CP_ACP).c_str());
}
Expand Down
2 changes: 0 additions & 2 deletions src/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ namespace vtobjplugin::Utilities {
#define RADIOBTN_GETCHECK(instance) (instance.GetCheck() == BST_CHECKED)
#define RADIOBTN_SETCHECK(instance, stmt) (instance.SetCheck((stmt) ? BST_CHECKED : BST_UNCHECKED))

bool ValidateCodePage(UINT code_page);

void SetCWndText(CWnd* ctl, const YYCC::yycc_u8string_view& val);
YYCC::yycc_u8string GetCWndText(CWnd* ctl);

Expand Down
8 changes: 6 additions & 2 deletions src/stdafx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once

#pragma region Windows Virtools Stuff
#include <WinImportPrefix.hpp>
#include <YYCC/WinImportPrefix.hpp>

#include <SDKDDKVer.h>

Expand Down Expand Up @@ -42,10 +42,14 @@
#include "VEP_KeyboardShortcutManager.h"
#include "VEP_All.h"

#include <WinImportSuffix.hpp>
#include <YYCC/WinImportSuffix.hpp>
#pragma endregion

#pragma region YYCC Stuff
#include <YYCCommonplace.hpp>

#if YYCC_VERCMP_NE(YYCC_VER_MAJOR, YYCC_VER_MINOR, YYCC_VER_PATCH, 1, 3, 0)
#error "The version of provided YYCC library is not matched with we required. Please check your YYCC library installation."
#endif
#pragma endregion

2 changes: 1 addition & 1 deletion src/vtobjplugin.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ImportGroup Label="PropertySheets"/>
<PropertyGroup Label="UserMacros">
<VIRTOOLS_PATH>E:\Virtools\Virtools Dev 5.0</VIRTOOLS_PATH>
<YYCC_PATH>J:\YYCCommonplace\bin\msvc_install</YYCC_PATH>
<YYCC_PATH>J:\YYCCommonplace\bin\cpp17\msvc_install</YYCC_PATH>
</PropertyGroup>
<PropertyGroup/>
<ItemDefinitionGroup/>
Expand Down
20 changes: 10 additions & 10 deletions src/vtobjplugin.rc
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "yyc12345"
VALUE "FileDescription", "���� Virtools �� Wavefront OBJ ��������"
VALUE "FileVersion", "3.1.0.0"
VALUE "FileVersion", "3.2.0.0"
VALUE "InternalName", "vtobjplu.dll"
VALUE "LegalCopyright", "��Ȩ���� (C) 2020-2024 yyc12345"
VALUE "OriginalFilename", "vtobjplu.dll"
VALUE "ProductName", "vtobjplugin"
VALUE "ProductVersion", "3.1.0.0"
VALUE "ProductVersion", "3.2.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down Expand Up @@ -109,7 +109,7 @@ BEGIN
EDITTEXT IDC_EDIT3,230,383,107,14,ES_AUTOHSCROLL
CONTROL "������Ͳ����ļ���ʹ�� UTF8",IDC_CHECK11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,402,123,10
CONTROL "�ڽű��ļ���ʹ�� UTF8",IDC_CHECK12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,420,99,10
LTEXT "vtobjplugin - v3.1",IDC_STATIC,6,444,58,8
LTEXT "vtobjplugin - v3.2",IDC_STATIC,6,444,58,8
PUSHBUTTON "����ΪĬ��",IDC_BUTTON2,6,462,50,14
END

Expand Down Expand Up @@ -157,7 +157,7 @@ BEGIN
IDS_VTMENU_MENU_REPORT_BUG "�㱨����"
IDS_VTMENU_MENU_ABOUT "���� vtobjplugin"
IDS_VTMENU_ABOUT_TITLE "���� vtobjplugin"
IDS_VTMENU_ABOUT_BODY "vtobjplugin v3.1 - ������ Virtools �� Wavefront OBJ ��������\n���� GPL v3 ����֤��\n��Ŀ��ҳ: https://github.com/yyc12345/vtobjplugin"
IDS_VTMENU_ABOUT_BODY "vtobjplugin v3.2 - ������ Virtools �� Wavefront OBJ ��������\n���� GPL v3 ����֤��\n��Ŀ��ҳ: https://github.com/yyc12345/vtobjplugin"
IDS_VTMENU_SUCCESS_NOTE "Wavefront OBJ ������ɡ�"
IDS_EXPSETDLG_ERR_TITLE "����"
END
Expand All @@ -175,7 +175,7 @@ BEGIN
IDS_OBJEXP_ERR_BLD_SCRIPT "�޷����� Blender �ű��ļ�: ""%s""��"
IDS_OBJEXP_ERR_TEMP_DIR "�޷���ȡ Windows ��ʱ·��������޷�������ͼ��"
IDS_OBJEXP_ERR_TEMP_TEX "�޷���ȡ��ʱ��ͼĿ¼: ""%s""����������ͼ�ĸ��ơ�"
IDS_OBJEXP_ERR_TEX "�޷���ȡ��ͼĿ¼: ""%s""����������ͼ�ĸ��ơ�"
IDS_OBJEXP_ERR_TEX "�޷�������ͼ: ""%s""����������ͼ�ĸ��ơ�"
IDS_UNAME_RENAME "��������Ψһ�ԣ����� ""%s"" �ѱ�������Ϊ ""%s""��"
IDS_EXPLAYOUT_OBJ_NO_MESH "3D ���岻������������������"
IDS_EXPLAYOUT_MESH_NO_FACE "���������񲻺����κ��档����������"
Expand Down Expand Up @@ -261,12 +261,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "yyc12345"
VALUE "FileDescription", "Wavefront OBJ Exporter for Virtools."
VALUE "FileVersion", "3.1.0.0"
VALUE "FileVersion", "3.2.0.0"
VALUE "InternalName", "vtobjplu.dll"
VALUE "LegalCopyright", "Copyright (C) 2020-2024 yyc12345"
VALUE "OriginalFilename", "vtobjplu.dll"
VALUE "ProductName", "vtobjplugin"
VALUE "ProductVersion", "3.1.0.0"
VALUE "ProductVersion", "3.2.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down Expand Up @@ -332,7 +332,7 @@ BEGIN
CONTROL "Use UTF8 in Object and Material File",IDC_CHECK11,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,402,131,10
CONTROL "Use UTF8 in Script File",IDC_CHECK12,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,420,87,10
LTEXT "vtobjplugin - v3.1",IDC_STATIC,6,444,58,8
LTEXT "vtobjplugin - v3.2",IDC_STATIC,6,444,58,8
PUSHBUTTON "Reset",IDC_BUTTON2,6,462,50,14
END

Expand Down Expand Up @@ -380,7 +380,7 @@ BEGIN
IDS_VTMENU_MENU_REPORT_BUG "Report Bug"
IDS_VTMENU_MENU_ABOUT "About vtobjplugin"
IDS_VTMENU_ABOUT_TITLE "About vtobjplugin"
IDS_VTMENU_ABOUT_BODY "vtobjplugin v3.1 - A Wavefront OBJ Exporter for Virtools.\nUnder GPL v3 License.\nProject Home Page: https://github.com/yyc12345/vtobjplugin"
IDS_VTMENU_ABOUT_BODY "vtobjplugin v3.2 - A Wavefront OBJ Exporter for Virtools.\nUnder GPL v3 License.\nProject Home Page: https://github.com/yyc12345/vtobjplugin"
IDS_VTMENU_SUCCESS_NOTE "Wavefront OBJ Export Done."
IDS_EXPSETDLG_ERR_TITLE "Setting Error"
END
Expand All @@ -398,7 +398,7 @@ BEGIN
IDS_OBJEXP_ERR_BLD_SCRIPT "Fail to create Blender script file: ""%s""."
IDS_OBJEXP_ERR_TEMP_DIR "Fail to get Windows temp path, thus we can not copy texture."
IDS_OBJEXP_ERR_TEMP_TEX "Fail to get temporary texture path: ""%s"". Skip copying this texture."
IDS_OBJEXP_ERR_TEX "Fail to get texture path: ""%s"". Skip copying this texture."
IDS_OBJEXP_ERR_TEX "Fail to copy texture: ""%s"". Skip copying this texture."
IDS_UNAME_RENAME "Name ""%s"" was renamed to ""%s"" for unique name."
IDS_EXPLAYOUT_OBJ_NO_MESH "3D Object doesn't have mesh. Skip exporting."
IDS_EXPLAYOUT_MESH_NO_FACE
Expand Down

0 comments on commit 23d8fad

Please sign in to comment.