OSDN Git Service

実行ファイル名を変更。
[tpi/lychee.git] / src / common / library / library.h
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \r
5   This library is free software; you can redistribute it and/or modify it under\r
6   the terms of the GNU Lesser General Public License as published by the Free\r
7   Software Foundation; either version 2.1 of the License, or (at your option)\r
8   any later version.\r
9 \r
10   This library is distributed in the hope that it will be useful, but WITHOUT\r
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License\r
13   for more details.\r
14 \r
15   You should have received a copy of the GNU Lesser General Public License along\r
16   with this library; if not, write to the Free Software Foundation, Inc.,\r
17   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
18 \r
19   $Id$\r
20 *******************************************************************************/\r
21 \r
22 //******************************************************************************\r
23 //    Includes\r
24 //******************************************************************************\r
25 \r
26 #include "../header/plugin.h"\r
27 #include <wx/file.h>\r
28 \r
29 //******************************************************************************\r
30 //    Functions\r
31 //******************************************************************************\r
32 \r
33 wxString MakeCommandLineSend(const wxString & szCommandLine, TPI_SWITCHES * swInfo = NULL, const wxArrayString & asFiles = wxArrayString(), const wxString & szResponceFileName = wxEmptyString);\r
34 wxString MakeResponceFile(const wxArrayString & asFiles, bool bQuote, bool bUnicode = false);\r
35 wxString MB2String(const char * sz);\r
36 wxString UTF82String(const char * sz);\r
37 wxString WC2String(const wchar_t * sz);\r
38 \r
39 inline void RemoveCwdFromSearchPath(void)\r
40 {\r
41 #ifdef __WINDOWS__\r
42         static void * p = (void *) ::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "SetDllDirectoryW");\r
43         if (p != NULL)\r
44         {\r
45                 ((int (__stdcall *)(const wchar_t *)) p)(L"");\r
46         }\r
47 #endif\r
48 }\r
49 \r
50 #ifdef __WINDOWS__\r
51 inline wxDateTime FileTimeToWxDateTime(FILETIME * pft)\r
52 {\r
53         FILETIME ftLocal;\r
54         SYSTEMTIME st;\r
55         if (! ::FileTimeToLocalFileTime(pft, & ftLocal) || ! ::FileTimeToSystemTime(& ftLocal, & st))\r
56         {\r
57                 return (time_t) 0;\r
58         }\r
59         wxDateTime dt(st.wDay, wxDateTime::Month(st.wMonth - 1), st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);\r
60         return dt;\r
61 }\r
62 #endif\r
63 \r
64 #ifdef MYUSE_LIBPATH\r
65 wxString g_szLibPath;\r
66 \r
67 #ifdef __WINDOWS__\r
68 BOOL WINAPI DllMain(HINSTANCE hLib, DWORD dwReason, void *)\r
69 {\r
70         if (dwReason == DLL_PROCESS_ATTACH)\r
71         {\r
72                 wchar_t szName[1024];\r
73                 ::GetModuleFileName(hLib, szName, sizeof(szName) - 1);\r
74                 g_szLibPath = wxFileName(WC2String(szName)).GetPath(true);\r
75         }\r
76         return TRUE;\r
77 }\r
78 #else\r
79 #include <dlfcn.h>\r
80 // GCC4.7ではg_szLibPathへの代入で不正終了してしまうので、myMakeXMLNameの初回に呼ぶように変更。\r
81 //__attribute__((constructor))\r
82 void inline on_load(void)\r
83 {\r
84         Dl_info dl;\r
85         dladdr((void *) on_load, & dl);\r
86         g_szLibPath = wxFileName(UTF82String(dl.dli_fname)).GetPath(true);\r
87 }\r
88 #endif\r
89 \r
90 wxString myMakeXMLName(const wxString & szFile)\r
91 {\r
92 #ifdef __LINUX__\r
93         if (g_szLibPath.IsEmpty())\r
94         {\r
95                 // 初回はライブラリが存在するディレクトリを取得。\r
96                 on_load();\r
97         }\r
98 #endif\r
99         return g_szLibPath + szFile + wxT(".xml");\r
100 }\r
101 #endif\r