Skip to content

Commit

Permalink
incorrect help displaying (actually hlf reading) when its language is…
Browse files Browse the repository at this point in the history
… different from the current one
  • Loading branch information
alabuzhev committed Oct 17, 2017
1 parent 5a97988 commit 4bab816
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 48 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
drkns 18.10.2017 00:47:15 +0100 - build 5067

1. С форума: некорректное отображение помощи (а на самом деле чтение - см. "четное количество багов"), если её язык не совпадает с текущим.

zg 16.10.2017 17:28:26 +0300 - build 5066

1. 0002760: Отдельные макрообласти для GRABBER, HMENU, DESKTOP.
Expand Down
7 changes: 3 additions & 4 deletions far/filelist.cpp
Expand Up @@ -5249,12 +5249,11 @@ void FileList::UpdateKeyBar()

bool FileList::PluginPanelHelp(const plugin_panel* hPlugin) const
{
string strPath, strFileName;
strPath = hPlugin->plugin()->GetModuleName();
auto strPath = hPlugin->plugin()->GetModuleName();
CutToSlash(strPath);
uintptr_t nCodePage = CP_OEMCP;
os::fs::file HelpFile;
if (!OpenLangFile(HelpFile, strPath,Global->HelpFileMask,Global->Opt->strHelpLanguage,strFileName, nCodePage))
const auto HelpFile = OpenLangFile(strPath, Global->HelpFileMask, Global->Opt->strHelpLanguage, nCodePage);
if (!HelpFile)
return false;

Help::create(Help::MakeLink(strPath, L"Contents"));
Expand Down
14 changes: 7 additions & 7 deletions far/help.cpp
Expand Up @@ -269,9 +269,8 @@ bool Help::ReadHelp(const string& Mask)
}

uintptr_t nCodePage = CP_OEMCP;
os::fs::file HelpFile;

if (!OpenLangFile(HelpFile, strPath,(Mask.empty()?Global->HelpFileMask:Mask),Global->Opt->strHelpLanguage,strFullHelpPathName, nCodePage))
const auto HelpFile = OpenLangFile(strPath, (Mask.empty()?Global->HelpFileMask:Mask), Global->Opt->strHelpLanguage, nCodePage);
if (!HelpFile)
{
ErrorHelp = true;

Expand All @@ -294,6 +293,8 @@ bool Help::ReadHelp(const string& Mask)
return false;
}

strFullHelpPathName = HelpFile.GetName();

string strReadStr;

if (GetOptionsParam(HelpFile,L"TabSize",strReadStr, nCodePage))
Expand Down Expand Up @@ -2007,7 +2008,6 @@ void Help::ReadDocumentsHelp(int TypeIndex)
StackData->CurX=StackData->CurY=0;
strCtrlColorChar.clear();
const wchar_t *PtrTitle = nullptr, *ContentsName = nullptr;
string strPath, strFullFileName;

switch (TypeIndex)
{
Expand All @@ -2030,11 +2030,11 @@ void Help::ReadDocumentsHelp(int TypeIndex)
{
std::for_each(CONST_RANGE(*Global->CtrlObject->Plugins, i)
{
strPath = i->GetModuleName();
auto strPath = i->GetModuleName();
CutToSlash(strPath);
uintptr_t nCodePage = CP_OEMCP;
os::fs::file HelpFile;
if (OpenLangFile(HelpFile,strPath,Global->HelpFileMask,Global->Opt->strHelpLanguage,strFullFileName, nCodePage))
const auto HelpFile = OpenLangFile(strPath, Global->HelpFileMask, Global->Opt->strHelpLanguage, nCodePage);
if (HelpFile)
{
string strEntryName, strSecondParam;

Expand Down
61 changes: 26 additions & 35 deletions far/language.cpp
Expand Up @@ -51,58 +51,47 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

static const wchar_t LangFileMask[] = L"*.lng";

bool OpenLangFile(os::fs::file& LangFile, const string& Path,const string& Mask,const string& Language, string &strFileName, uintptr_t &nCodePage, bool StrongLang,string *pstrLangName)
os::fs::file OpenLangFile(const string& Path,const string& Mask,const string& Language, uintptr_t &nCodePage, bool StrongLang,string *pstrLangName)
{
strFileName.clear();
string strEngFileName;
string strLangName;
os::fs::file EnglishFile;

auto PathWithSlash = Path;
AddEndSlash(PathWithSlash);

for (const auto& FindData: os::fs::enum_files(PathWithSlash + Mask))
{
strFileName = PathWithSlash + FindData.strFileName;
const auto CurrentFileName = PathWithSlash + FindData.strFileName;

if (!LangFile.Open(strFileName, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING))
{
strFileName.clear();
}
else

if (auto CurrentFile = os::fs::file(CurrentFileName, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING))
{
GetFileFormat(LangFile, nCodePage, nullptr, false);

if (GetLangParam(LangFile, L"Language", strLangName, nullptr, nCodePage) && equal_icase(strLangName, Language))
break;
GetFileFormat(CurrentFile, nCodePage, nullptr, false);

LangFile.Close();
string LanguageName;
if (GetLangParam(CurrentFile, L"Language", LanguageName, nullptr, nCodePage) && equal_icase(LanguageName, Language))
{
return CurrentFile;
}

if (StrongLang)
{
strFileName.clear();
strEngFileName.clear();
break;
return {};
}

if (equal_icase(strLangName, L"English"_sv))
strEngFileName = strFileName;
}
}

if (!LangFile)
{
if (!strEngFileName.empty())
strFileName = strEngFileName;

if (!strFileName.empty())
{
if (LangFile.Open(strFileName, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING) && pstrLangName)
if (equal_icase(LanguageName, L"English"_sv))
{
*pstrLangName = L"English";
EnglishFile = std::move(CurrentFile);
}
}
}

return LangFile? true : false;
if (!EnglishFile)
return {};

if (pstrLangName)
*pstrLangName = L"English";

return EnglishFile;
}


Expand Down Expand Up @@ -350,15 +339,17 @@ void language::load(const string& Path, int CountNeed)

uintptr_t nCodePage = CP_OEMCP;
string strLangName = Global->Opt->strLanguage;
os::fs::file LangFile;

auto Data = m_Data->create();

if (!OpenLangFile(LangFile, Path, LangFileMask, Global->Opt->strLanguage, Data->m_FileName, nCodePage, false, &strLangName))
const auto LangFile = OpenLangFile(Path, LangFileMask, Global->Opt->strLanguage, nCodePage, false, &strLangName);
if (!LangFile)
{
throw MAKE_FAR_EXCEPTION(L"Cannot find language data");
}

Data->m_FileName = LangFile.GetName();

GetFileString GetStr(LangFile, nCodePage);

if (CountNeed != -1)
Expand Down
2 changes: 1 addition & 1 deletion far/language.hpp
Expand Up @@ -97,7 +97,7 @@ class far_language final: private language, public singleton<far_language>
};


bool OpenLangFile(os::fs::file& LangFile, const string& Path, const string& Mask, const string& Language, string &strFileName, uintptr_t &nCodePage, bool StrongLang = false, string *pstrLangName = nullptr);
os::fs::file OpenLangFile(const string& Path, const string& Mask, const string& Language, uintptr_t &nCodePage, bool StrongLang = false, string *pstrLangName = nullptr);
bool GetLangParam(const os::fs::file& LangFile, const string& ParamName, string& strParam1, string *strParam2, UINT nCodePage);
bool SelectInterfaceLanguage();
bool SelectHelpLanguage();
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,5066)m4_dnl
m4_define(BUILD,5067)m4_dnl

0 comments on commit 4bab816

Please sign in to comment.