2015-06-30 02:54:59 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, assimp team
|
2015-06-30 02:54:59 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "assimp_view.h"
|
|
|
|
#include "richedit.h"
|
2017-06-01 14:21:23 +00:00
|
|
|
#include <commdlg.h>
|
2020-05-02 13:14:38 +00:00
|
|
|
#include <commoncontrols.h>
|
2015-06-30 02:54:59 +00:00
|
|
|
|
|
|
|
namespace AssimpView {
|
|
|
|
|
|
|
|
CLogWindow CLogWindow::s_cInstance;
|
|
|
|
|
|
|
|
extern HKEY g_hRegistry;
|
|
|
|
|
|
|
|
// header for the RTF log file
|
2020-05-02 13:14:38 +00:00
|
|
|
static const char *AI_VIEW_RTF_LOG_HEADER =
|
|
|
|
"{\\rtf1"
|
2015-06-30 02:54:59 +00:00
|
|
|
"\\ansi"
|
|
|
|
"\\deff0"
|
|
|
|
"{"
|
2020-05-02 13:14:38 +00:00
|
|
|
"\\fonttbl{\\f0 Courier New;}"
|
2015-06-30 02:54:59 +00:00
|
|
|
"}"
|
2020-05-02 13:14:38 +00:00
|
|
|
"{\\colortbl;"
|
|
|
|
"\\red255\\green0\\blue0;" // red for errors
|
|
|
|
"\\red255\\green120\\blue0;" // orange for warnings
|
|
|
|
"\\red0\\green150\\blue0;" // green for infos
|
|
|
|
"\\red0\\green0\\blue180;" // blue for debug messages
|
|
|
|
"\\red0\\green0\\blue0;" // black for everything else
|
|
|
|
"}}";
|
2015-06-30 02:54:59 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// Message procedure for the log window
|
|
|
|
//-------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
INT_PTR CALLBACK LogDialogProc(HWND hwndDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lParam) {
|
2015-06-30 02:54:59 +00:00
|
|
|
(void)lParam;
|
2020-05-02 13:14:38 +00:00
|
|
|
switch (uMsg) {
|
2015-06-30 02:54:59 +00:00
|
|
|
case WM_INITDIALOG:
|
|
|
|
return TRUE;
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
case WM_SIZE: {
|
2015-06-30 02:54:59 +00:00
|
|
|
int x = LOWORD(lParam);
|
|
|
|
int y = HIWORD(lParam);
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
SetWindowPos(GetDlgItem(hwndDlg, IDC_EDIT1), nullptr, 0, 0,
|
|
|
|
x - 10, y - 12, SWP_NOMOVE | SWP_NOZORDER);
|
2015-06-30 02:54:59 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2020-05-02 13:14:38 +00:00
|
|
|
}
|
2015-06-30 02:54:59 +00:00
|
|
|
case WM_CLOSE:
|
2020-05-02 13:14:38 +00:00
|
|
|
EndDialog(hwndDlg, 0);
|
2015-06-30 02:54:59 +00:00
|
|
|
|
|
|
|
CLogWindow::Instance().bIsVisible = false;
|
|
|
|
return TRUE;
|
2020-05-02 13:14:38 +00:00
|
|
|
};
|
2015-06-30 02:54:59 +00:00
|
|
|
return FALSE;
|
2020-05-02 13:14:38 +00:00
|
|
|
}
|
2015-06-30 02:54:59 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void CLogWindow::Init() {
|
|
|
|
this->hwnd = ::CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_LOGVIEW),
|
|
|
|
nullptr, &LogDialogProc);
|
2015-06-30 02:54:59 +00:00
|
|
|
|
2019-01-30 15:07:40 +00:00
|
|
|
if (!this->hwnd) {
|
2015-06-30 02:54:59 +00:00
|
|
|
CLogDisplay::Instance().AddEntry("[ERROR] Unable to create logger window",
|
2020-05-02 13:14:38 +00:00
|
|
|
D3DCOLOR_ARGB(0xFF, 0, 0xFF, 0));
|
2015-06-30 02:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup the log text
|
2020-05-02 13:14:38 +00:00
|
|
|
this->szText = AI_VIEW_RTF_LOG_HEADER;
|
|
|
|
;
|
2015-06-30 02:54:59 +00:00
|
|
|
this->szPlainText = "";
|
|
|
|
}
|
2019-01-30 15:07:40 +00:00
|
|
|
|
2015-06-30 02:54:59 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2019-01-30 15:07:40 +00:00
|
|
|
void CLogWindow::Show() {
|
|
|
|
if (this->hwnd) {
|
2020-05-02 13:14:38 +00:00
|
|
|
ShowWindow(this->hwnd, SW_SHOW);
|
2015-06-30 02:54:59 +00:00
|
|
|
this->bIsVisible = true;
|
|
|
|
|
|
|
|
// contents aren't updated while the logger isn't displayed
|
|
|
|
this->Update();
|
|
|
|
}
|
|
|
|
}
|
2019-01-30 15:07:40 +00:00
|
|
|
|
2015-06-30 02:54:59 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void CMyLogStream::write(const char *message) {
|
2015-06-30 02:54:59 +00:00
|
|
|
CLogWindow::Instance().WriteLine(message);
|
|
|
|
}
|
2019-01-30 15:07:40 +00:00
|
|
|
|
2015-06-30 02:54:59 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2019-01-30 15:07:40 +00:00
|
|
|
void CLogWindow::Clear() {
|
2020-05-02 13:14:38 +00:00
|
|
|
this->szText = AI_VIEW_RTF_LOG_HEADER;
|
|
|
|
;
|
2015-06-30 02:54:59 +00:00
|
|
|
this->szPlainText = "";
|
|
|
|
|
|
|
|
this->Update();
|
|
|
|
}
|
2019-01-30 15:07:40 +00:00
|
|
|
|
2015-06-30 02:54:59 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2019-01-30 15:07:40 +00:00
|
|
|
void CLogWindow::Update() {
|
|
|
|
if (this->bIsVisible) {
|
2015-06-30 02:54:59 +00:00
|
|
|
SETTEXTEX sInfo;
|
|
|
|
sInfo.flags = ST_DEFAULT;
|
|
|
|
sInfo.codepage = CP_ACP;
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
SendDlgItemMessage(this->hwnd, IDC_EDIT1,
|
|
|
|
EM_SETTEXTEX, (WPARAM)&sInfo, (LPARAM)this->szText.c_str());
|
2015-06-30 02:54:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-30 15:07:40 +00:00
|
|
|
|
2015-06-30 02:54:59 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2019-01-30 15:07:40 +00:00
|
|
|
void CLogWindow::Save() {
|
2015-06-30 02:54:59 +00:00
|
|
|
char szFileName[MAX_PATH];
|
|
|
|
|
|
|
|
DWORD dwTemp = MAX_PATH;
|
2020-05-02 13:14:38 +00:00
|
|
|
if (ERROR_SUCCESS != RegQueryValueEx(g_hRegistry, "LogDestination", nullptr, nullptr, (BYTE *)szFileName, &dwTemp)) {
|
2015-06-30 02:54:59 +00:00
|
|
|
// Key was not found. Use C:
|
2020-05-02 13:14:38 +00:00
|
|
|
strcpy(szFileName, "");
|
2019-01-30 15:07:40 +00:00
|
|
|
} else {
|
2015-06-30 02:54:59 +00:00
|
|
|
// need to remove the file name
|
2020-05-02 13:14:38 +00:00
|
|
|
char *sz = strrchr(szFileName, '\\');
|
2015-07-02 11:50:21 +00:00
|
|
|
if (!sz)
|
2020-05-02 13:14:38 +00:00
|
|
|
sz = strrchr(szFileName, '/');
|
2015-07-02 11:50:21 +00:00
|
|
|
if (sz)
|
|
|
|
*sz = 0;
|
2015-06-30 02:54:59 +00:00
|
|
|
}
|
|
|
|
OPENFILENAME sFilename1 = {
|
|
|
|
sizeof(OPENFILENAME),
|
2020-05-02 13:14:38 +00:00
|
|
|
g_hDlg, GetModuleHandle(nullptr),
|
2020-04-07 14:56:22 +00:00
|
|
|
"Log files\0*.txt", nullptr, 0, 1,
|
|
|
|
szFileName, MAX_PATH, nullptr, 0, nullptr,
|
2015-06-30 02:54:59 +00:00
|
|
|
"Save log to file",
|
|
|
|
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
|
2020-04-07 14:56:22 +00:00
|
|
|
0, 1, ".txt", 0, nullptr, nullptr
|
2015-06-30 02:54:59 +00:00
|
|
|
};
|
2020-05-02 13:14:38 +00:00
|
|
|
if (GetSaveFileName(&sFilename1) == 0) return;
|
2015-06-30 02:54:59 +00:00
|
|
|
|
|
|
|
// Now store the file in the registry
|
2020-05-02 13:14:38 +00:00
|
|
|
RegSetValueExA(g_hRegistry, "LogDestination", 0, REG_SZ, (const BYTE *)szFileName, MAX_PATH);
|
2015-06-30 02:54:59 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
FILE *pFile = fopen(szFileName, "wt");
|
|
|
|
fprintf(pFile, this->szPlainText.c_str());
|
2015-06-30 02:54:59 +00:00
|
|
|
fclose(pFile);
|
|
|
|
|
|
|
|
CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved",
|
2020-05-02 13:14:38 +00:00
|
|
|
D3DCOLOR_ARGB(0xFF, 0xFF, 0xFF, 0));
|
2015-06-30 02:54:59 +00:00
|
|
|
}
|
2019-01-30 15:07:40 +00:00
|
|
|
|
2015-06-30 02:54:59 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2020-05-02 13:14:38 +00:00
|
|
|
void CLogWindow::WriteLine(const char *message) {
|
2015-06-30 02:54:59 +00:00
|
|
|
this->szPlainText.append(message);
|
|
|
|
this->szPlainText.append("\r\n");
|
|
|
|
|
2019-01-30 15:07:40 +00:00
|
|
|
if (0 != this->szText.length()) {
|
2020-05-02 13:14:38 +00:00
|
|
|
this->szText.resize(this->szText.length() - 1);
|
2015-06-30 02:54:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
switch (message[0]) {
|
2015-06-30 02:54:59 +00:00
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
this->szText.append("{\\pard \\cf1 \\b \\fs18 ");
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
case 'W':
|
|
|
|
this->szText.append("{\\pard \\cf2 \\b \\fs18 ");
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
case 'I':
|
|
|
|
this->szText.append("{\\pard \\cf3 \\b \\fs18 ");
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
this->szText.append("{\\pard \\cf4 \\b \\fs18 ");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this->szText.append("{\\pard \\cf5 \\b \\fs18 ");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string _message = message;
|
2020-05-02 13:14:38 +00:00
|
|
|
for (unsigned int i = 0; i < _message.length(); ++i) {
|
2015-06-30 02:54:59 +00:00
|
|
|
if ('\\' == _message[i] ||
|
2020-05-02 13:14:38 +00:00
|
|
|
'}' == _message[i] ||
|
|
|
|
'{' == _message[i]) {
|
|
|
|
_message.insert(i++, "\\");
|
2015-06-30 02:54:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->szText.append(_message);
|
|
|
|
this->szText.append("\\par}}");
|
|
|
|
|
2019-01-30 15:07:40 +00:00
|
|
|
if (this->bIsVisible && this->bUpdate) {
|
2015-06-30 02:54:59 +00:00
|
|
|
SETTEXTEX sInfo;
|
|
|
|
sInfo.flags = ST_DEFAULT;
|
|
|
|
sInfo.codepage = CP_ACP;
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
SendDlgItemMessage(this->hwnd, IDC_EDIT1,
|
|
|
|
EM_SETTEXTEX, (WPARAM)&sInfo, (LPARAM)this->szText.c_str());
|
2015-06-30 02:54:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
} // namespace AssimpView
|