Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / misc / log_analyser / PlugInSelector.cpp
blob2845f5f8c79a7f9d8a0cc8bc715e1646e1d64160
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdafx.h"
21 #include "log_analyser.h"
22 #include "PlugInSelector.h"
24 using namespace std;
26 #ifdef _DEBUG
27 #define new DEBUG_NEW
28 #undef THIS_FILE
29 static char THIS_FILE[] = __FILE__;
30 #endif
32 /////////////////////////////////////////////////////////////////////////////
33 // CPlugInSelector dialog
36 CPlugInSelector::CPlugInSelector(CWnd* pParent /*=NULL*/)
37 : CDialog(CPlugInSelector::IDD, pParent)
39 //{{AFX_DATA_INIT(CPlugInSelector)
40 // NOTE: the ClassWizard will add member initialization here
41 //}}AFX_DATA_INIT
45 void CPlugInSelector::DoDataExchange(CDataExchange* pDX)
47 CDialog::DoDataExchange(pDX);
48 //{{AFX_DATA_MAP(CPlugInSelector)
49 DDX_Control(pDX, IDC_LIST1, m_PlugInListBox);
50 //}}AFX_DATA_MAP
54 BEGIN_MESSAGE_MAP(CPlugInSelector, CDialog)
55 //{{AFX_MSG_MAP(CPlugInSelector)
56 ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
60 /////////////////////////////////////////////////////////////////////////////
61 // CPlugInSelector message handlers
66 BOOL CPlugInSelector::OnInitDialog()
68 CDialog::OnInitDialog();
70 if ( m_PlugInListBox.GetCount() == 0 )
72 for (unsigned int i=0; i!=Dlls->size(); ++i )
74 m_PlugInListBox.InsertString( i, (*Dlls)[i] ); // not sorted
78 AnalyseFunc = NULL;
79 LibInst = NULL;
81 GetDlgItem( IDC_GROUP_INFO )->EnableWindow( ! Dlls->empty() );
82 GetDlgItem( IDOK )->EnableWindow( ! Dlls->empty() );
83 if ( ! Dlls->empty() )
85 m_PlugInListBox.SetCurSel( 0 );
86 OnSelchangeList1();
89 return TRUE;
93 std::string::size_type getLastSeparator (const string &filename)
95 string::size_type pos = filename.find_last_of ('/');
96 if (pos == string::npos)
98 pos = filename.find_last_of ('\\');
99 if (pos == string::npos)
101 pos = filename.find_last_of ('@');
104 return pos;
108 string getFilename (const string &filename)
110 string::size_type pos = getLastSeparator(filename);
111 if (pos != string::npos)
112 return filename.substr (pos + 1);
113 else
114 return filename;
121 void CPlugInSelector::OnSelchangeList1()
123 CString dllName;
124 m_PlugInListBox.GetText( m_PlugInListBox.GetCurSel(), dllName );
126 // Release previous DLL if any
127 if ( LibInst != NULL )
129 FreeLibrary( LibInst );
132 // Load DLL
133 LibInst = LoadLibrary( dllName );
134 if ( ! LibInst )
136 CString s;
137 TCHAR msg [300];
138 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
139 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), msg, 299, NULL );
140 s.Format(_T("Can't load %s: %s"), dllName, msg );
141 AfxMessageBox( s );
142 AnalyseFunc = NULL;
143 return;
146 // Display info
147 TInfoFunc infoFunc = (TInfoFunc)GetProcAddress( LibInst, "getInfoString" );
148 if ( ! infoFunc )
150 AfxMessageBox( _T("Can't find function getInfoString in dll") );
151 return;
153 GetDlgItem(IDC_GROUP_INFO)->SetWindowText(nlUtf8ToTStr(getFilename(NLMISC::tStrToUtf8(dllName))));
154 GetDlgItem(IDC_PLUGIN_INFO)->SetWindowText(nlUtf8ToTStr(infoFunc()));
156 // Prepare analyse func
157 AnalyseFunc = (TAnalyseFunc)GetProcAddress( LibInst, "doAnalyse" );
158 if ( ! AnalyseFunc )
160 AfxMessageBox( _T("Can't find function doAnalyse in dll") );
161 return;
164 GetDlgItem( IDOK )->EnableWindow( m_PlugInListBox.GetCurSel() != LB_ERR );
171 void CPlugInSelector::OnCancel()
173 AnalyseFunc = NULL;
175 // Release previous DLL if any
176 if ( LibInst != NULL )
178 FreeLibrary( LibInst );
179 LibInst = NULL;
182 CDialog::OnCancel();