in Squiggly/ane/WinDLLHunspellANE/HunspellNativeExtension/HunspellNativeExtension.cpp [54:132]
FREObject initHunspellObject(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){
const uint8_t *locale = 0;
const uint8_t *dictionaryPath = 0;
uint32_t len = -1;
FREObject retObj=0;
Hunspell * hunspellObject;
BOOL fRunTimeLinkSuccess = FALSE;
//get first argument
if(FREGetObjectAsUTF8(argv[1], &len, &dictionaryPath) != FRE_OK)
return retObj;
len = 0;
//get second argument
if(FREGetObjectAsUTF8(argv[0], &len, &locale) != FRE_OK)
return retObj;
//check in cache and return if already present
if(!(Hunspell_cache.find(std::string((char *)locale))==Hunspell_cache.end()))
{
FRENewObjectFromInt32(HUNSPELL_INIT_SUCCESS, &retObj);
return retObj;
}
U16Char_t * dic_path_U16= EncConv::convCharStrToU16Str((char *)dictionaryPath, "UTF-8");
U16Char_t *locale_U16= EncConv::convCharStrToU16Str((char *)locale, "UTF-8");
std::wstring aff_file= std::wstring((wchar_t *)dic_path_U16)+std::wstring(L"\\Dictionaries\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L"\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L".aff");
std::wstring dic_file= std::wstring((wchar_t *)dic_path_U16)+std::wstring(L"\\Dictionaries\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L"\\")+std::wstring((wchar_t *)locale_U16)+std::wstring(L".dic");
std::wstring lib_file= std::wstring((wchar_t *)dic_path_U16)+std::wstring(L"\\libhunspell.dll");
EncConv::releaseU16Str(dic_path_U16);
EncConv::releaseU16Str(locale_U16);
//creating OS specific aff,dic file paths refer: DanishOS Issue of CS6 AHP
std::string aff_file_U8= makeString(aff_file.c_str());
std::string dic_file_U8= makeString(dic_file.c_str());
//make the file url's
std::string lib_file_U8= std::string((char *)dictionaryPath)+std::string("\\libhunspell.dll");
//check for file is present
if( (FileExists(aff_file) && FileExists(dic_file) && FileExists(lib_file)) == false )
{
FRENewObjectFromInt32(RESOURCE_FILES_MISSING, &retObj);
return retObj;
}
LPCTSTR lib_file_lpstring= (wchar_t *)lib_file.c_str();
//make a new hunspell object
hinstLib = LoadLibrary(lib_file_lpstring);
if (hinstLib != NULL)
{
HUNSPELL_INIT initAdd = (HUNSPELL_INIT) GetProcAddress(hinstLib, "hunspell_initialize");
// If the function address is valid, call the function.
if (NULL != initAdd)
{
fRunTimeLinkSuccess = TRUE;
hunspellObject = (initAdd) ((char *)aff_file_U8.c_str(), (char *)dic_file_U8.c_str());
}
}
//add to hunspell cache
if(Hunspell_cache.find(std::string((char *)locale))==Hunspell_cache.end())
Hunspell_cache[std::string((char *)locale)]= hunspellObject;
if(hunspellObject)
{
FRENewObjectFromInt32(HUNSPELL_INIT_SUCCESS, &retObj);
}
else
{
FRENewObjectFromInt32(HUNSPELL_INIT_FAIL, &retObj);
}
return retObj;
}