Skip to content
Permalink
Browse files

refactoring

  • Loading branch information...
alabuzhev committed Jun 22, 2017
1 parent ab6492b commit 56d2e1160f7c9912e9baa9f2857d629e92a35ffc
@@ -457,7 +457,7 @@ static DWORD OldKeyToKey(DWORD dOldKey)

if (CleanKey>0x80 && CleanKey<0x100)
{
char OemChar = static_cast<char>(CleanKey);
const auto OemChar = static_cast<char>(CleanKey);
wchar_t WideChar = 0;
if (encoding::oem::get_chars(&OemChar, 1, &WideChar, 1))
dOldKey = (dOldKey^CleanKey) | WideChar;
@@ -483,7 +483,7 @@ static DWORD KeyToOldKey(DWORD dKey)

if (CleanKey>0x80 && CleanKey<0x10000)
{
wchar_t WideChar = static_cast<wchar_t>(CleanKey);
const auto WideChar = static_cast<wchar_t>(CleanKey);
char OemChar = 0;
if (encoding::oem::get_bytes(&WideChar, 1, &OemChar, 1))
dKey = (dKey^CleanKey) | OemChar;
@@ -4708,15 +4708,17 @@ static int WINAPI FarViewerControlA(int Command, void* Param) noexcept

const auto vspA = static_cast<oldfar::ViewerSetPosition*>(Param);
ViewerSetPosition vsp={sizeof(ViewerSetPosition)};
vsp.Flags = 0;

if (vspA->Flags&oldfar::VSP_NOREDRAW) vsp.Flags|=VSP_NOREDRAW;

if (vspA->Flags&oldfar::VSP_PERCENT) vsp.Flags|=VSP_PERCENT;

if (vspA->Flags&oldfar::VSP_RELATIVE) vsp.Flags|=VSP_RELATIVE;
static const std::pair<oldfar::VIEWER_SETPOS_FLAGS, VIEWER_SETPOS_FLAGS> PluginFlagsMap[] =
{
OLDFAR_TO_FAR_MAP(VSP_NOREDRAW),
OLDFAR_TO_FAR_MAP(VSP_PERCENT),
OLDFAR_TO_FAR_MAP(VSP_RELATIVE),
OLDFAR_TO_FAR_MAP(VSP_NORETNEWPOS),
};

if (vspA->Flags&oldfar::VSP_NORETNEWPOS) vsp.Flags|=VSP_NORETNEWPOS;
vsp.Flags = VSP_NONE;
FirstFlagsToSecond(vspA->Flags, vsp.Flags, PluginFlagsMap);

vsp.StartPos = vspA->StartPos;
vsp.LeftPos = vspA->LeftPos;
@@ -4809,10 +4811,10 @@ static int WINAPI FarCharTableA(int Command, char *Buffer, int BufferSize) noexc
encoding::oem::get_bytes(sTableName, TableSet->TableName);
std::unique_ptr<wchar_t[]> us(AnsiToUnicodeBin(reinterpret_cast<char*>(TableSet->DecodeTable), std::size(TableSet->DecodeTable), nCP));

CharLowerBuff(us.get(), static_cast<DWORD>(std::size(TableSet->DecodeTable)));
lower(us.get(), std::size(TableSet->DecodeTable));
encoding::get_bytes(nCP, us.get(), std::size(TableSet->DecodeTable), reinterpret_cast<char*>(TableSet->LowerTable), std::size(TableSet->DecodeTable));

CharUpperBuff(us.get(), static_cast<DWORD>(std::size(TableSet->DecodeTable)));
upper(us.get(), std::size(TableSet->DecodeTable));
encoding::get_bytes(nCP, us.get(), std::size(TableSet->DecodeTable), reinterpret_cast<char*>(TableSet->UpperTable), std::size(TableSet->DecodeTable));

MultiByteRecode(static_cast<UINT>(nCP), CP_OEMCP, reinterpret_cast<char *>(TableSet->DecodeTable), std::size(TableSet->DecodeTable));
@@ -4837,19 +4839,16 @@ char* WINAPI XlatA(
{
try
{
DWORD NewFlags = 0;

if (Flags&oldfar::XLAT_SWITCHKEYBLAYOUT)
NewFlags |= XLAT_SWITCHKEYBLAYOUT;

if (Flags&oldfar::XLAT_SWITCHKEYBBEEP)
NewFlags |= XLAT_SWITCHKEYBBEEP;

if (Flags&oldfar::XLAT_USEKEYBLAYOUTNAME)
NewFlags |= XLAT_USEKEYBLAYOUTNAME;
static const std::pair<oldfar::XLATMODE, XLAT_FLAGS> PluginFlagsMap[] =
{
OLDFAR_TO_FAR_MAP(XLAT_SWITCHKEYBLAYOUT),
OLDFAR_TO_FAR_MAP(XLAT_SWITCHKEYBBEEP),
OLDFAR_TO_FAR_MAP(XLAT_USEKEYBLAYOUTNAME),
OLDFAR_TO_FAR_MAP(XLAT_CONVERTALLCMDLINE),
};

if (Flags&oldfar::XLAT_CONVERTALLCMDLINE)
NewFlags |= XLAT_CONVERTALLCMDLINE;
auto NewFlags = XLAT_NONE;
FirstFlagsToSecond(Flags, NewFlags, PluginFlagsMap);

const auto strLine = encoding::oem::get_chars(Line);
// XLat expects null-terminated string
@@ -1,3 +1,7 @@
drkns 22.06.2017 23:26:01 +0000 - build 4977

1. Рефакторинг.

drkns 21.06.2017 07:30:17 +0000 - build 4976

1. В некоторых случаях плагин мог вызвать исключение в меню со включенным фильтром.
@@ -254,21 +254,11 @@ bool CommandLine::ProcessKey(const Manager::Key& Key)
m_CurCmdStr = CmdStr.GetString();
}

string strStr;
if (LocalKey() == KEY_CTRLE || LocalKey() == KEY_RCTRLE)
{
Global->CtrlObject->CmdHistory->GetPrev(strStr);
}
else
{
Global->CtrlObject->CmdHistory->GetNext(strStr);
}

{
SCOPED_ACTION(SetAutocomplete)(&CmdStr);
SetString(Global->CtrlObject->CmdHistory->IsOnTop()? m_CurCmdStr : strStr, true);
}

SCOPED_ACTION(SetAutocomplete)(&CmdStr);
const auto strStr = LocalKey() == KEY_CTRLE || LocalKey() == KEY_RCTRLE?
Global->CtrlObject->CmdHistory->GetPrev() :
Global->CtrlObject->CmdHistory->GetNext();
SetString(Global->CtrlObject->CmdHistory->IsOnTop()? m_CurCmdStr : strStr, true);
}
return true;

@@ -1425,7 +1425,7 @@ static bool ParseIntValue(const string& sValue, long long& iValue)


template<class base_type, class derived>
bool detail::OptionImpl<base_type, derived>::ReceiveValue(GeneralConfig* Storage, const string& KeyName, const string& ValueName, const any& Default)
bool detail::OptionImpl<base_type, derived>::ReceiveValue(const GeneralConfig* Storage, const string& KeyName, const string& ValueName, const any& Default)
{
base_type CfgValue;
const auto Result = Storage->GetValue(KeyName, ValueName, CfgValue, any_cast<base_type>(Default));
@@ -133,7 +133,7 @@ class Option
friend class Options;

virtual bool StoreValue(GeneralConfig* Storage, const string& KeyName, const string& ValueName, bool always) const = 0;
virtual bool ReceiveValue(GeneralConfig* Storage, const string& KeyName, const string& ValueName, const any& Default) = 0;
virtual bool ReceiveValue(const GeneralConfig* Storage, const string& KeyName, const string& ValueName, const any& Default) = 0;

void MakeUnchanged() { m_Value.forget(); }

@@ -171,7 +171,7 @@ namespace detail
virtual bool IsDefault(const any& Default) const override { return Get() == any_cast<base_type>(Default); }
virtual void SetDefault(const any& Default) override { Set(any_cast<base_type>(Default)); }

virtual bool ReceiveValue(GeneralConfig* Storage, const string& KeyName, const string& ValueName, const any& Default) override;
virtual bool ReceiveValue(const GeneralConfig* Storage, const string& KeyName, const string& ValueName, const any& Default) override;
virtual bool StoreValue(GeneralConfig* Storage, const string& KeyName, const string& ValueName, bool always) const override;

//operator const base_type&() const { return Get(); }
@@ -198,25 +198,25 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb
return SetValueT(Key, Name, Value);
}

virtual bool GetValue(const string& Key, const string& Name, bool& Value, bool Default) override
virtual bool GetValue(const string& Key, const string& Name, bool& Value, bool Default) const override
{
long long Data = Default;
const auto Result = GetValue(Key, Name, Data, Data);
Value = Data != 0;
return Result;
}

virtual bool GetValue(const string& Key, const string& Name, long long& Value, long long Default) override
virtual bool GetValue(const string& Key, const string& Name, long long& Value, long long Default) const override
{
return GetValueT<column_type::integer>(Key, Name, Value, Default, &SQLiteStmt::GetColInt64);
}

virtual bool GetValue(const string& Key, const string& Name, string& Value, const wchar_t* Default) override
virtual bool GetValue(const string& Key, const string& Name, string& Value, const wchar_t* Default) const override
{
return GetValueT<column_type::string>(Key, Name, Value, Default, &SQLiteStmt::GetColText);
}

virtual bool GetValue(const string& Key, const string& Name, string& Value, const string& Default) override
virtual bool GetValue(const string& Key, const string& Name, string& Value, const string& Default) const override
{
return GetValueT<column_type::string>(Key, Name, Value, Default, &SQLiteStmt::GetColText);
}
@@ -226,17 +226,17 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb
return ExecuteStatement(stmtDelValue, Key, Name);
}

virtual bool EnumValues(const string& Key, DWORD Index, string &Name, string &Value) override
virtual bool EnumValues(const string& Key, DWORD Index, string &Name, string &Value) const override
{
return EnumValuesT(Key, Index, Name, Value, &SQLiteStmt::GetColText);
}

virtual bool EnumValues(const string& Key, DWORD Index, string &Name, long long& Value) override
virtual bool EnumValues(const string& Key, DWORD Index, string &Name, long long& Value) const override
{
return EnumValuesT(Key, Index, Name, Value, &SQLiteStmt::GetColInt64);
}

virtual void Export(representation_destination& Representation) override
virtual void Export(representation_destination& Representation) const override
{
auto& root = CreateChild(Representation.GetRoot(), GetKeyName());

@@ -312,7 +312,7 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb
virtual const char* GetKeyName() const = 0;

template<column_type TypeId, class getter_t, class T, class DT>
bool GetValueT(const string& Key, const string& Name, T& Value, const DT& Default, getter_t Getter)
bool GetValueT(const string& Key, const string& Name, T& Value, const DT& Default, getter_t Getter) const
{
const auto Stmt = AutoStatement(stmtGetValue);
if (!Stmt->Bind(Key, Name).Step() || Stmt->GetColType(0) != TypeId)
@@ -335,7 +335,7 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb
}

template<class T, class getter_t>
bool EnumValuesT(const string& Key, DWORD Index, string& Name, T& Value, getter_t Getter)
bool EnumValuesT(const string& Key, DWORD Index, string& Name, T& Value, getter_t Getter) const
{
auto Stmt = AutoStatement(stmtEnumValues);
if (Index == 0)
@@ -453,7 +453,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
return Key;
}

virtual key FindByName(const key& Root, const string& Name) override
virtual key FindByName(const key& Root, const string& Name) const override
{
const auto Stmt = AutoStatement(stmtFindKey);
if (!Stmt->Bind(Root.get(), Name).Step())
@@ -487,17 +487,17 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
return SetValueT(Root, Name, Value);
}

virtual bool GetValue(const key& Root, const string& Name, unsigned long long& Value) override
virtual bool GetValue(const key& Root, const string& Name, unsigned long long& Value) const override
{
return GetValueT(Root, Name, Value, &SQLiteStmt::GetColInt64);
}

virtual bool GetValue(const key& Root, const string& Name, string &Value) override
virtual bool GetValue(const key& Root, const string& Name, string &Value) const override
{
return GetValueT(Root, Name, Value, &SQLiteStmt::GetColText);
}

virtual bool GetValue(const key& Root, const string& Name, writable_blob_view& Value) override
virtual bool GetValue(const key& Root, const string& Name, writable_blob_view& Value) const override
{
return GetValueT(Root, Name, Value, &SQLiteStmt::GetColBlob);
}
@@ -513,7 +513,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
return ExecuteStatement(stmtDelValue, Root.get(), Name);
}

virtual bool EnumKeys(const key& Root, DWORD Index, string& Name) override
virtual bool EnumKeys(const key& Root, DWORD Index, string& Name) const override
{
auto Stmt = AutoStatement(stmtEnumKeys);
if (Index == 0)
@@ -527,7 +527,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
return true;
}

virtual bool EnumValues(const key& Root, DWORD Index, string& Name, int& Type) override
virtual bool EnumValues(const key& Root, DWORD Index, string& Name, int& Type) const override
{
auto Stmt = AutoStatement(stmtEnumValues);
if (Index == 0)
@@ -542,18 +542,18 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
return true;
}

virtual void SerializeBlob(const char* Name, const void* Blob, size_t Size, tinyxml::XMLElement& e)
virtual void SerializeBlob(const char* Name, const void* Blob, size_t Size, tinyxml::XMLElement& e) const
{
e.SetAttribute("type", "hex");
e.SetAttribute("value", BlobToHexString(Blob, Size).data());
}

virtual void Export(representation_destination& Representation) override
virtual void Export(representation_destination& Representation) const override
{
Export(Representation, root_key(), CreateChild(Representation.GetRoot(), "hierarchicalconfig"));
}

virtual std::vector<char> DeserializeBlob(const char* Name, const char* Type, const char* Value, const tinyxml::XMLElement& e)
virtual std::vector<char> DeserializeBlob(const char* Name, const char* Type, const char* Value, const tinyxml::XMLElement& e) const
{
return HexStringToBlob(Value);
}
@@ -567,7 +567,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
}
}

void Export(representation_destination& Representation, const key& Key, tinyxml::XMLElement& XmlKey)
void Export(representation_destination& Representation, const key& Key, tinyxml::XMLElement& XmlKey) const
{
{
const auto Stmt = AutoStatement(stmtEnumValues);
@@ -672,7 +672,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb
}

template<class T, class getter_t>
bool GetValueT(const key& Root, const string& Name, T& Value, getter_t Getter)
bool GetValueT(const key& Root, const string& Name, T& Value, getter_t Getter) const
{
const auto Stmt = AutoStatement(stmtGetValue);
if (!Stmt->Bind(Root.get(), Name).Step())
@@ -721,7 +721,7 @@ class HighlightHierarchicalConfigDb: public HierarchicalConfigDb
using HierarchicalConfigDb::HierarchicalConfigDb;

private:
virtual void SerializeBlob(const char* Name, const void* Blob, size_t Size, tinyxml::XMLElement& e) override
virtual void SerializeBlob(const char* Name, const void* Blob, size_t Size, tinyxml::XMLElement& e) const override
{
static const char* ColorKeys[] =
{
@@ -745,7 +745,7 @@ class HighlightHierarchicalConfigDb: public HierarchicalConfigDb
}
}

virtual std::vector<char> DeserializeBlob(const char* Name, const char* Type, const char* Value, const tinyxml::XMLElement& e) override
virtual std::vector<char> DeserializeBlob(const char* Name, const char* Type, const char* Value, const tinyxml::XMLElement& e) const override
{
if(!strcmp(Type, "color"))
{
@@ -807,7 +807,7 @@ class ColorsConfigDb: public ColorsConfig, public SQLiteDb
return b;
}

virtual bool GetValue(const string& Name, FarColor& Value) override
virtual bool GetValue(const string& Name, FarColor& Value) const override
{
const auto Stmt = AutoStatement(stmtGetValue);
if (!Stmt->Bind(Name).Step())
@@ -820,7 +820,7 @@ class ColorsConfigDb: public ColorsConfig, public SQLiteDb
return true;
}

virtual void Export(representation_destination& Representation) override
virtual void Export(representation_destination& Representation) const override
{
auto& root = CreateChild(Representation.GetRoot(), "colors");

@@ -1020,7 +1020,7 @@ class AssociationsConfigDb: public AssociationsConfig, public SQLiteDb
return ExecuteStatement(stmtDelType, id);
}

virtual void Export(representation_destination& Representation) override
virtual void Export(representation_destination& Representation) const override
{
auto& root = CreateChild(Representation.GetRoot(), "associations");

@@ -1200,7 +1200,7 @@ class PluginsCacheConfigDb: public PluginsCacheConfig, public SQLiteDb
}

virtual void Import(const representation_source&) override {}
virtual void Export(representation_destination&) override {}
virtual void Export(representation_destination&) const override {}

virtual unsigned long long CreateCache(const string& CacheName) override
{
@@ -1518,7 +1518,7 @@ class PluginsHotkeysConfigDb: public PluginsHotkeysConfig, public SQLiteDb
return ExecuteStatement(stmtDelHotkey, PluginKey, GuidToStr(MenuGuid), as_underlying_type(HotKeyType));
}

virtual void Export(representation_destination& Representation) override
virtual void Export(representation_destination& Representation) const override
{
auto& root = CreateChild(Representation.GetRoot(), "pluginhotkeys");

@@ -2104,7 +2104,7 @@ class HistoryConfigDb: public HistoryConfigCustom
// TODO: log
// TODO: implementation
virtual void Import(const representation_source&) override {}
virtual void Export(representation_destination&) override {}
virtual void Export(representation_destination&) const override {}
};

class HistoryConfigMemory: public HistoryConfigCustom
@@ -2117,7 +2117,7 @@ class HistoryConfigMemory: public HistoryConfigCustom

private:
virtual void Import(const representation_source&) override {}
virtual void Export(representation_destination&) override {}
virtual void Export(representation_destination&) const override {}
};

static const std::wregex& uuid_regex()
Oops, something went wrong.

0 comments on commit 56d2e11

Please sign in to comment.
You can’t perform that action at this time.