| 1 |
#include "StrRsc.h" |
| 2 |
|
| 3 |
#include <algorithm> |
| 4 |
#include <vector> |
| 5 |
#include <array> |
| 6 |
#include <windows.h> |
| 7 |
#include <shlwapi.h> |
| 8 |
#if defined(_MSC_VER) |
| 9 |
#pragma comment(lib, "shlwapi.lib") |
| 10 |
#endif |
| 11 |
|
| 12 |
#include "../../Common/dummy.h" |
| 13 |
#include "../../Common/tstring.h" |
| 14 |
#include "../../Common/StrResource.h" |
| 15 |
|
| 16 |
#include "OptionDlg.h" |
| 17 |
#include "StrRscConsts.h" |
| 18 |
|
| 19 |
HINSTANCE g_hInstance; |
| 20 |
|
| 21 |
namespace Regnessem |
| 22 |
{ |
| 23 |
namespace AddIn |
| 24 |
{ |
| 25 |
namespace StrRsc |
| 26 |
{ |
| 27 |
StrRscMain g_strRscMain; |
| 28 |
|
| 29 |
StrRscMain::StrRscMain() |
| 30 |
{ |
| 31 |
SetPluginInfo(NMPI_APIVER , NMP_INFO_APIVER); |
| 32 |
SetPluginInfo(NMPI_MODULENAME , NMP_INFO_MODULENAME); |
| 33 |
SetPluginInfo(NMPI_TITLE , NMP_INFO_TITLE); |
| 34 |
SetPluginInfo(NMPI_DESCRIPTION , NMP_INFO_DESCRIPTION); |
| 35 |
SetPluginInfo(NMPI_AUTHOR , NMP_INFO_AUTHOR); |
| 36 |
SetPluginInfo(NMPI_COPYRIGHT , NMP_INFO_COPYRIGHT); |
| 37 |
SetPluginInfo(NMPI_PLUGINVER , NMP_INFO_PLUGINVER); |
| 38 |
} |
| 39 |
|
| 40 |
// úť |
| 41 |
void StrRscMain::DoInitialize() |
| 42 |
{ |
| 43 |
IniFiles.clear(); |
| 44 |
g_StrResource.reset(new StrResource(InitInfo)); |
| 45 |
Config.LoadFromFile(GetIniFileName()); |
| 46 |
|
| 47 |
// T[rXĚo^ |
| 48 |
CreateNsmService(NMS_ADDIN_STRRSC_GETLOCALSTR, StrRscService::DoGetLocalStr); |
| 49 |
CreateNsmService(NMS_ADDIN_STRRSC_SHOWOPTIONDIALOG, StrRscService::DoShowOptionDialog); |
| 50 |
|
| 51 |
ChangeLangEvent = CreateNsmEvent(NME_ADDIN_STRRSC_CHANGELANGUAGE); |
| 52 |
} |
| 53 |
|
| 54 |
// IvV_CAO\Ś |
| 55 |
INT_PTR StrRscMain::DoShowOptionDialog(HWND parent) |
| 56 |
{ |
| 57 |
OptionDlg dlg; |
| 58 |
dlg.Locale = Config.Locale; |
| 59 |
|
| 60 |
INT_PTR result = dlg.ShowOptionDialog(parent); |
| 61 |
|
| 62 |
if(result == IDOK && dlg.Locale != Config.Locale) |
| 63 |
{ |
| 64 |
Config.Locale = dlg.Locale; |
| 65 |
Config.SaveToFile(GetIniFileName()); |
| 66 |
// OnChangeLanguageCxgĘm |
| 67 |
NotifyEvent(ChangeLangEvent, 0, 0); |
| 68 |
} |
| 69 |
|
| 70 |
return result; |
| 71 |
} |
| 72 |
|
| 73 |
void StrRscMain::RegisterIniFile(const tstring &pluginName) |
| 74 |
{ |
| 75 |
std::array<TCHAR, MAX_PATH> exePath; |
| 76 |
GetModuleFileName(NULL, exePath.data(), std::tuple_size<decltype(exePath)>::value); |
| 77 |
|
| 78 |
const tstring filePath = ExtractFilePath(exePath.data()) |
| 79 |
+ TEXT("Plugins\\StrRsc\\Language\\") |
| 80 |
+ Config.Locale + TEXT('\\') |
| 81 |
+ pluginName + TEXT(".txt"); |
| 82 |
|
| 83 |
if(PathFileExists(filePath.c_str())) |
| 84 |
IniFiles.insert(std::make_pair(pluginName, filePath)); |
| 85 |
} |
| 86 |
|
| 87 |
// žęt@CŠçśńćž |
| 88 |
int StrRscMain::DoGetLocalStr(const NsmStrRsc &strRsc) |
| 89 |
{ |
| 90 |
if(!strRsc.lpDefaultStr || !strRsc.lpMessageTag || !strRsc.lpPluginName || !strRsc.lpSectionName) |
| 91 |
return 0; |
| 92 |
|
| 93 |
if(strRsc.nBufferSize < 1) |
| 94 |
return 0; |
| 95 |
|
| 96 |
const tstring pluginName = c2t(strRsc.lpPluginName); |
| 97 |
|
| 98 |
IniFilesTable::const_iterator it = IniFiles.find(pluginName); |
| 99 |
|
| 100 |
if(it == IniFiles.end()) |
| 101 |
{ |
| 102 |
RegisterIniFile(pluginName); |
| 103 |
it = IniFiles.find(pluginName); |
| 104 |
|
| 105 |
if(it == IniFiles.end()) |
| 106 |
{ |
| 107 |
StrToStrRsc(strRsc, c2t(strRsc.lpDefaultStr)); |
| 108 |
|
| 109 |
return 0; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
std::vector<TCHAR> buff(strRsc.nBufferSize); |
| 114 |
GetPrivateProfileString( |
| 115 |
c2t(strRsc.lpSectionName).c_str(), |
| 116 |
c2t(strRsc.lpMessageTag).c_str(), |
| 117 |
c2t(strRsc.lpDefaultStr).c_str(), |
| 118 |
&buff[0], static_cast<DWORD>(buff.size()), (*it).second.c_str()); |
| 119 |
|
| 120 |
if(!StrToStrRsc(strRsc, &buff[0])) |
| 121 |
return 0; |
| 122 |
|
| 123 |
return 1; |
| 124 |
} |
| 125 |
|
| 126 |
// String->StrRsc ĎˇÖ |
| 127 |
int StrRscMain::StrToStrRsc(const NsmStrRsc &strRsc, const tstring &source) |
| 128 |
{ |
| 129 |
if(!strRsc.lpBuffer) |
| 130 |
return 0; |
| 131 |
|
| 132 |
if(strRsc.nBufferSize < 1) |
| 133 |
return 0; |
| 134 |
|
| 135 |
std::string tmp = t2c(source); |
| 136 |
|
| 137 |
std::string::size_type len = std::min<std::string::size_type>(strRsc.nBufferSize - 1, tmp.size()); |
| 138 |
|
| 139 |
tmp.resize(len); |
| 140 |
|
| 141 |
strcpy_s(strRsc.lpBuffer, strRsc.nBufferSize, tmp.c_str()); |
| 142 |
|
| 143 |
return static_cast<int>(len); |
| 144 |
} |
| 145 |
|
| 146 |
// ---------------------------------------------------------------------------- |
| 147 |
|
| 148 |
// T[rXÖ |
| 149 |
|
| 150 |
LONG_PTR __stdcall StrRscService::DoShowOptionDialog(const WPARAM wParam, const LPARAM /* lParam */) |
| 151 |
{ |
| 152 |
return g_strRscMain.DoShowOptionDialog(reinterpret_cast<HWND>(wParam)); |
| 153 |
} |
| 154 |
|
| 155 |
LONG_PTR __stdcall StrRscService::DoGetLocalStr(const WPARAM wParam, const LPARAM /* lParam */) |
| 156 |
{ |
| 157 |
if(!wParam) |
| 158 |
return 0; |
| 159 |
|
| 160 |
return g_strRscMain.DoGetLocalStr(*reinterpret_cast<NsmStrRsc*>(wParam)); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/) |
| 167 |
{ |
| 168 |
g_hInstance = hinstDLL; |
| 169 |
|
| 170 |
switch(fdwReason) |
| 171 |
{ |
| 172 |
case DLL_PROCESS_ATTACH: |
| 173 |
break; |
| 174 |
case DLL_PROCESS_DETACH: |
| 175 |
break; |
| 176 |
case DLL_THREAD_ATTACH: |
| 177 |
break; |
| 178 |
case DLL_THREAD_DETACH: |
| 179 |
break; |
| 180 |
} |
| 181 |
|
| 182 |
return TRUE; |
| 183 |
} |
| 184 |
|
| 185 |
extern "C" |
| 186 |
{ |
| 187 |
// vOCÉÖˇéîńđÔˇ |
| 188 |
// |
| 189 |
// nInfoNo : ćžľ˝˘îńĚÔ |
| 190 |
// lpBuffer : îńđi[ˇéobt@ |
| 191 |
// nSize : obt@ĚTCY |
| 192 |
// |
| 193 |
// Return : ŔŰÉŤńžîńĚTCY |
| 194 |
// nInfoNo ŞłřČç 0 |
| 195 |
int WINAPI GetPluginInfo(const int nInfNo, LPSTR lpBuffer, const int nSize) |
| 196 |
{ |
| 197 |
if(!lpBuffer) |
| 198 |
return 0; |
| 199 |
|
| 200 |
if(nSize < 1) |
| 201 |
return 0; |
| 202 |
|
| 203 |
std::string result = t2c(Regnessem::AddIn::StrRsc::g_strRscMain.GetPluginInfo(nInfNo)); |
| 204 |
|
| 205 |
if(result.empty()) |
| 206 |
return 0; |
| 207 |
|
| 208 |
std::string::size_type len = std::min<std::string::size_type>(nSize-1, result.size()); |
| 209 |
|
| 210 |
result.resize(len); |
| 211 |
strcpy_s(lpBuffer, nSize, result.c_str()); |
| 212 |
|
| 213 |
return static_cast<int>(len); |
| 214 |
} |
| 215 |
|
| 216 |
// vOCĚúť |
| 217 |
// |
| 218 |
// lpPluginInitInfo : vOCúťîń |
| 219 |
// |
| 220 |
// Return : G[R[h |
| 221 |
int WINAPI Initialize(const Regnessem::PNsmPluginInitInfo lpNsmInitInfo) |
| 222 |
{ |
| 223 |
if(!lpNsmInitInfo) |
| 224 |
return Regnessem::NsmPluginState::InternalError; |
| 225 |
|
| 226 |
Regnessem::AddIn::StrRsc::g_strRscMain.Initialize(*lpNsmInitInfo); |
| 227 |
|
| 228 |
return Regnessem::NsmPluginState::AllRight; |
| 229 |
} |
| 230 |
|
| 231 |
// vOCĚIš |
| 232 |
// |
| 233 |
// Return : G[R[h |
| 234 |
int WINAPI Terminate() |
| 235 |
{ |
| 236 |
Regnessem::AddIn::StrRsc::g_strRscMain.Terminate(); |
| 237 |
|
| 238 |
return Regnessem::NsmPluginState::AllRight; |
| 239 |
} |
| 240 |
} |