Skip to content

Commit

Permalink
1. Показываем метки дисков из реестра при отсутствии физических.
Browse files Browse the repository at this point in the history
2. "Починим" загрузку плагинов c нетрадиционным расположением зависимых dll.
3. Не закрываем quick search при потере фокуса, если OC новее, чем XP/2k3.
4. Рефакторинг.
  • Loading branch information
alabuzhev committed Jan 22, 2015
1 parent 78cc6c8 commit 36c94f2
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 119 deletions.
12 changes: 11 additions & 1 deletion far/changelog
@@ -1,4 +1,14 @@
shmuel 22.01.2015 13:21:30 +0200 - build 4253
drkns 22.01.2015 23:13:47 +0200 - build 4254

1. Показываем метки дисков из реестра при отсутствии физических.

2. "Починим" загрузку плагинов c нетрадиционным расположением зависимых dll.

3. Не закрываем quick search при потере фокуса, если OC новее, чем XP/2k3.

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

shmuel 22.01.2015 13:21:30 +0200 - build 4253

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

Expand Down
18 changes: 9 additions & 9 deletions far/console.cpp
Expand Up @@ -817,19 +817,19 @@ class extendedconsole:public basicconsole
{
}

ImportedFunctions::module Module;
api::rtdl::module Module;

struct ModuleImports
{
ImportedFunctions::function_pointer<BOOL(WINAPI*)(FAR_CHAR_INFO* Buffer, COORD BufferSize, COORD BufferCoord, SMALL_RECT* ReadRegion)> pReadOutput;
ImportedFunctions::function_pointer<BOOL(WINAPI*)(const FAR_CHAR_INFO* Buffer, COORD BufferSize, COORD BufferCoord, SMALL_RECT* WriteRegion)> pWriteOutput;
ImportedFunctions::function_pointer<BOOL(WINAPI*)()> pCommit;
ImportedFunctions::function_pointer<BOOL(WINAPI*)(FarColor* Attributes) > pGetTextAttributes;
ImportedFunctions::function_pointer<BOOL(WINAPI*)(const FarColor* Attributes)> pSetTextAttributes;
ImportedFunctions::function_pointer<BOOL(WINAPI*)(const FarColor* Color, int Mode)> pClearExtraRegions;
ImportedFunctions::function_pointer<BOOL(WINAPI*)(FarColor* Color, BOOL Centered, BOOL AddTransparent)> pGetColorDialog;
api::rtdl::function_pointer<BOOL(WINAPI*)(FAR_CHAR_INFO* Buffer, COORD BufferSize, COORD BufferCoord, SMALL_RECT* ReadRegion)> pReadOutput;
api::rtdl::function_pointer<BOOL(WINAPI*)(const FAR_CHAR_INFO* Buffer, COORD BufferSize, COORD BufferCoord, SMALL_RECT* WriteRegion)> pWriteOutput;
api::rtdl::function_pointer<BOOL(WINAPI*)()> pCommit;
api::rtdl::function_pointer<BOOL(WINAPI*)(FarColor* Attributes) > pGetTextAttributes;
api::rtdl::function_pointer<BOOL(WINAPI*)(const FarColor* Attributes)> pSetTextAttributes;
api::rtdl::function_pointer<BOOL(WINAPI*)(const FarColor* Color, int Mode)> pClearExtraRegions;
api::rtdl::function_pointer<BOOL(WINAPI*)(FarColor* Color, BOOL Centered, BOOL AddTransparent)> pGetColorDialog;

ModuleImports(const ImportedFunctions::module& Module):
ModuleImports(const api::rtdl::module& Module):
#define INIT_IMPORT(name) p ## name(Module, #name)
INIT_IMPORT(ReadOutput),
INIT_IMPORT(WriteOutput),
Expand Down
2 changes: 1 addition & 1 deletion far/cvtname.cpp
Expand Up @@ -248,7 +248,7 @@ static string TryConvertVolumeGuidToDrivePath(const string& Path, const wchar_t
size_t DirectoryOffset;
if (ParsePath(Path, &DirectoryOffset) == PATH_VOLUMEGUID)
{
if (Imports().GetVolumePathNamesForVolumeNameW.exists())
if (Imports().GetVolumePathNamesForVolumeNameW)
{
wchar_t_ptr Buffer(api::NT_MAX_PATH);
DWORD RetSize;
Expand Down
2 changes: 1 addition & 1 deletion far/datetime.cpp
Expand Up @@ -751,7 +751,7 @@ bool Utc2Local(SYSTEMTIME &st, FILETIME &lft)

static inline bool local_to_utc(const SYSTEMTIME &lst, SYSTEMTIME &ust)
{
if (Imports().TzSpecificLocalTimeToSystemTime.exists())
if (Imports().TzSpecificLocalTimeToSystemTime)
{
return Imports().TzSpecificLocalTimeToSystemTime(nullptr, &lst, &ust) != FALSE;
}
Expand Down
2 changes: 1 addition & 1 deletion far/dlgedit.cpp
Expand Up @@ -332,7 +332,7 @@ void DlgEdit::SetString(const string& Str, bool disable_autocomplete, int pos)
if (disable_autocomplete && (acompl = lineEdit->GetAutocomplete()))
lineEdit->SetAutocomplete(false);

lineEdit->SetString(Str.data(),Str.size());
lineEdit->SetString(Str.data(), static_cast<int>(Str.size()));
if (pos >= 0)
lineEdit->SetCurPos(pos);

Expand Down
4 changes: 2 additions & 2 deletions far/drivemix.cpp
Expand Up @@ -61,8 +61,8 @@ DWORD FarGetLogicalDrives()

if (!Global->Opt->Policies.ShowHiddenDrives)
{
const HKEY Roots[] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER};
std::any_of(CONST_RANGE(Roots, i) -> bool
static const HKEY Roots[] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER};
std::any_of(CONST_RANGE(Roots, i)
{
return api::reg::GetValue(i, L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", L"NoDrives", NoDrives);
});
Expand Down
4 changes: 2 additions & 2 deletions far/elevation.cpp
Expand Up @@ -887,7 +887,7 @@ bool ElevationRequired(ELEVATION_MODE Mode, bool UseNtStatus)
bool Result = false;
if(Global && Global->Opt && Global->Opt->ElevationMode & Mode)
{
if(UseNtStatus && Imports().RtlGetLastNtStatus.exists())
if(UseNtStatus && Imports().RtlGetLastNtStatus)
{
NTSTATUS LastNtStatus = api::GetLastNtStatus();
Result = LastNtStatus == STATUS_ACCESS_DENIED || LastNtStatus == STATUS_PRIVILEGE_NOT_HELD;
Expand Down Expand Up @@ -933,7 +933,7 @@ class elevated:noncopyable
if (Pipe != INVALID_HANDLE_VALUE)
{
ULONG ServerProcessId;
if(!Imports().GetNamedPipeServerProcessId.exists() || (Imports().GetNamedPipeServerProcessId(Pipe, &ServerProcessId) && ServerProcessId == PID))
if(!Imports().GetNamedPipeServerProcessId || (Imports().GetNamedPipeServerProcessId(Pipe, &ServerProcessId) && ServerProcessId == PID))
{
HANDLE ParentProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, PID);
if(ParentProcess)
Expand Down
4 changes: 2 additions & 2 deletions far/farexcpt.cpp
Expand Up @@ -221,7 +221,7 @@ static bool ProcessSEHExceptionImpl(EXCEPTION_POINTERS *xp)

if (Global && Global->Opt->ExceptUsed && !Global->Opt->strExceptEventSvc.empty())
{
ImportedFunctions::module m(Global->Opt->strExceptEventSvc.data());
api::rtdl::module m(Global->Opt->strExceptEventSvc.data());

if (m)
{
Expand All @@ -236,7 +236,7 @@ static bool ProcessSEHExceptionImpl(EXCEPTION_POINTERS *xp)
DWORD SizeModuleName;
};

ImportedFunctions::function_pointer<BOOL(WINAPI*)(EXCEPTION_POINTERS* xp, const PLUGINRECORD* Module, const PluginStartupInfo* LocalStartupInfo, LPDWORD Result)> p(m, "ExceptionProc");
api::rtdl::function_pointer<BOOL(WINAPI*)(EXCEPTION_POINTERS* xp, const PLUGINRECORD* Module, const PluginStartupInfo* LocalStartupInfo, LPDWORD Result)> p(m, "ExceptionProc");

if (p)
{
Expand Down
47 changes: 39 additions & 8 deletions far/farwinapi.cpp
Expand Up @@ -705,7 +705,7 @@ int file_walker::GetPercent() const

NTSTATUS GetLastNtStatus()
{
return Imports().RtlGetLastNtStatus.exists()? Imports().RtlGetLastNtStatus() : STATUS_SUCCESS;
return Imports().RtlGetLastNtStatus? Imports().RtlGetLastNtStatus() : STATUS_SUCCESS;
}

BOOL DeleteFile(const string& FileName)
Expand Down Expand Up @@ -979,7 +979,7 @@ DWORD GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, string &strFileName)
FileName.reset(BufferSize);
if (hProcess)
{
if (Imports().QueryFullProcessImageNameW.exists() && !hModule)
if (Imports().QueryFullProcessImageNameW && !hModule)
{
DWORD sz = BufferSize;
Size = 0;
Expand Down Expand Up @@ -1259,7 +1259,7 @@ BOOL SetFileAttributes(const string& FileName,DWORD dwFileAttributes)

bool CreateSymbolicLinkInternal(const string& Object, const string& Target, DWORD dwFlags)
{
return Imports().CreateSymbolicLinkW.exists()?
return Imports().CreateSymbolicLinkW?
(Imports().CreateSymbolicLink(Object.data(), Target.data(), dwFlags) != FALSE) :
CreateReparsePoint(Target, Object, dwFlags&SYMBOLIC_LINK_FLAG_DIRECTORY?RP_SYMLINKDIR:RP_SYMLINKFILE);
}
Expand Down Expand Up @@ -1315,7 +1315,7 @@ BOOL CreateHardLink(const string& FileName, const string& ExistingFileName, LPSE
HANDLE FindFirstStream(const string& FileName,STREAM_INFO_LEVELS InfoLevel,LPVOID lpFindStreamData,DWORD dwFlags)
{
HANDLE Ret=INVALID_HANDLE_VALUE;
if(Imports().FindFirstStreamW.exists())
if(Imports().FindFirstStreamW)
{
Ret=Imports().FindFirstStreamW(NTPath(FileName).data(),InfoLevel,lpFindStreamData,dwFlags);
}
Expand Down Expand Up @@ -1374,7 +1374,7 @@ HANDLE FindFirstStream(const string& FileName,STREAM_INFO_LEVELS InfoLevel,LPVOI
BOOL FindNextStream(HANDLE hFindStream,LPVOID lpFindStreamData)
{
BOOL Ret=FALSE;
if(Imports().FindFirstStreamW.exists())
if(Imports().FindFirstStreamW)
{
Ret=Imports().FindNextStreamW(hFindStream,lpFindStreamData);
}
Expand Down Expand Up @@ -1404,7 +1404,7 @@ BOOL FindStreamClose(HANDLE hFindStream)
{
BOOL Ret=FALSE;

if(Imports().FindFirstStreamW.exists())
if(Imports().FindFirstStreamW)
{
Ret=::FindClose(hFindStream);
}
Expand Down Expand Up @@ -1530,7 +1530,7 @@ bool internalNtQueryGetFinalPathNameByHandle(HANDLE hFile, string& FinalFilePath

bool GetFinalPathNameByHandle(HANDLE hFile, string& FinalFilePath)
{
if (Imports().GetFinalPathNameByHandleW.exists())
if (Imports().GetFinalPathNameByHandleW)
{
wchar_t Buffer[MAX_PATH];
size_t Size = Imports().GetFinalPathNameByHandle(hFile, Buffer, ARRAYSIZE(Buffer), VOLUME_NAME_GUID);
Expand Down Expand Up @@ -1605,7 +1605,7 @@ bool GetVolumeNameForVolumeMountPoint(const string& VolumeMountPoint,string& Vol

void EnableLowFragmentationHeap()
{
if (Imports().HeapSetInformation.exists())
if (Imports().HeapSetInformation)
{
std::vector<HANDLE> Heaps(10);
DWORD ActualNumHeaps = ::GetProcessHeaps(static_cast<DWORD>(Heaps.size()), Heaps.data());
Expand Down Expand Up @@ -1983,4 +1983,35 @@ DWORD GetAppPathsRedirectionFlag()
return str;
}
}

namespace rtdl
{
module::~module()
{
if (m_loaded)
{
FreeLibrary(m_module);
}
}

HMODULE module::get_module() const
{
if (!m_module)
{
m_module = GetModuleHandle(m_name);
if (!m_module)
{
m_module = LoadLibrary(m_name);

if (!m_module && m_AlternativeLoad && IsAbsolutePath(m_name))
{
m_module = LoadLibraryEx(m_name, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
}
// TODO: log if nullptr
m_loaded = m_module != nullptr;
}
}
return m_module;
}
}
}
43 changes: 43 additions & 0 deletions far/farwinapi.hpp
Expand Up @@ -394,4 +394,47 @@ namespace api
string expand_strings(const wchar_t* str);
inline string expand_strings(const string& str) { return expand_strings(str.data()); }
}

// Run-Time Dynamic Linking
namespace rtdl
{
class module: noncopyable
{
public:
module(const wchar_t* name, bool AlternativeLoad = false):
m_name(name),
m_module(),
m_loaded(),
m_AlternativeLoad(AlternativeLoad)
{}
~module();

FARPROC GetProcAddress(const char* name) const { return ::GetProcAddress(get_module(), name); }
operator bool() const { return get_module() != nullptr; }

private:
HMODULE get_module() const;

const wchar_t* m_name;
mutable HMODULE m_module;
mutable bool m_loaded;
const bool m_AlternativeLoad;
};

template<typename T>
class function_pointer: noncopyable
{
public:
function_pointer(const module& Module, const char* Name):
m_module(Module),
m_pointer(reinterpret_cast<T>(m_module.GetProcAddress(Name)))
{}
operator T() const { return m_pointer; }
operator bool() const { return m_pointer != nullptr; }

private:
const module& m_module;
mutable T m_pointer;
};
}
}
2 changes: 1 addition & 1 deletion far/flink.cpp
Expand Up @@ -170,7 +170,7 @@ bool CreateReparsePoint(const string& Target, const string& Object,ReparsePointT
{
Type = api::fs::is_directory(Target)? RP_SYMLINKDIR : RP_SYMLINKFILE;
}
if (Imports().CreateSymbolicLinkW.exists() && !api::fs::exists(ObjectStatus))
if (Imports().CreateSymbolicLinkW && !api::fs::exists(ObjectStatus))
{
Result=api::CreateSymbolicLink(Object,Target,Type==RP_SYMLINKDIR?SYMBOLIC_LINK_FLAG_DIRECTORY:0);
}
Expand Down
23 changes: 0 additions & 23 deletions far/imports.cpp
Expand Up @@ -42,29 +42,6 @@ const ImportedFunctions& Imports()
return ifn;
}

ImportedFunctions::module::~module()
{
if (m_loaded)
{
FreeLibrary(m_module);
}
}

HMODULE ImportedFunctions::module::get_module() const
{
if (!m_module)
{
m_module = GetModuleHandle(m_name);
if (!m_module)
{
m_module = LoadLibrary(m_name);
// TODO: log if nullptr
m_loaded = m_module != nullptr;
}
}
return m_module;
}


ImportedFunctions::ImportedFunctions():
m_ntdll(L"ntdll"),
Expand Down
53 changes: 10 additions & 43 deletions far/imports.hpp
Expand Up @@ -35,47 +35,14 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class ImportedFunctions: noncopyable
{
public:
class module: noncopyable
{
public:
module(const wchar_t* name): m_name(name), m_module(), m_loaded() {}
~module();

FARPROC GetProcAddress(const char* name) const { return ::GetProcAddress(get_module(), name); }
operator bool() const { return get_module() != nullptr; }

private:
HMODULE get_module() const;

const wchar_t* m_name;
mutable HMODULE m_module;
mutable bool m_loaded;
};

template<typename T>
class function_pointer: noncopyable
{
public:
function_pointer(const module& Module, const char* Name):
m_module(Module),
m_pointer(reinterpret_cast<T>(m_module.GetProcAddress(Name))) {}
operator T() const { return m_pointer; }
bool exists() const { return m_pointer != nullptr; }

private:
const module& m_module;
mutable T m_pointer;
};

private:
template<typename T, class Y, T stub>
class unique_function_pointer: noncopyable
{
public:
unique_function_pointer(const module& Module): m_module(Module) {}
unique_function_pointer(const api::rtdl::module& Module): m_module(Module) {}
operator T() const { return get_pointer(); }
bool exists() const { return get_pointer() != stub; }
operator bool() const { return get_pointer() != stub; }

private:
T get_pointer() const
Expand All @@ -86,16 +53,16 @@ class ImportedFunctions: noncopyable
return pointer;
}

const module& m_module;
const api::rtdl::module& m_module;
};

const module m_ntdll;
const module m_kernel32;
const module m_shell32;
const module m_user32;
const module m_virtdisk;
const module m_rstrtmgr;
const module m_netapi32;
const api::rtdl::module m_ntdll;
const api::rtdl::module m_kernel32;
const api::rtdl::module m_shell32;
const api::rtdl::module m_user32;
const api::rtdl::module m_virtdisk;
const api::rtdl::module m_rstrtmgr;
const api::rtdl::module m_netapi32;

#define DECLARE_IMPORT_FUNCTION(RETTYPE, CALLTYPE, NAME, ...)\
private: static RETTYPE CALLTYPE stub_##NAME(__VA_ARGS__);\
Expand Down

0 comments on commit 36c94f2

Please sign in to comment.