Skip to content
Permalink
Browse files

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

2. "Починим" загрузку плагинов c нетрадиционным расположением зависимых dll.
3. Не закрываем quick search при потере фокуса, если OC новее, чем XP/2k3.
4. Рефакторинг.
  • Loading branch information...
alabuzhev committed Jan 22, 2015
1 parent 78cc6c8 commit 36c94f250c956cbca3ee1b593723742326a879b5
Showing with 157 additions and 119 deletions.
  1. +11 −1 far/changelog
  2. +9 −9 far/console.cpp
  3. +1 −1 far/cvtname.cpp
  4. +1 −1 far/datetime.cpp
  5. +1 −1 far/dlgedit.cpp
  6. +2 −2 far/drivemix.cpp
  7. +2 −2 far/elevation.cpp
  8. +2 −2 far/farexcpt.cpp
  9. +39 −8 far/farwinapi.cpp
  10. +43 −0 far/farwinapi.hpp
  11. +1 −1 far/flink.cpp
  12. +0 −23 far/imports.cpp
  13. +10 −43 far/imports.hpp
  14. +20 −10 far/panel.cpp
  15. +4 −4 far/plclass.cpp
  16. +9 −9 far/plclass.hpp
  17. +1 −1 far/plist.cpp
  18. +1 −1 far/vbuild.m4
@@ -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. Рефакторинг.

@@ -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),
@@ -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;
@@ -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;
}
@@ -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);

@@ -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);
});
@@ -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;
@@ -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)
@@ -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)
{
@@ -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)
{
@@ -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)
@@ -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;
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -1404,7 +1404,7 @@ BOOL FindStreamClose(HANDLE hFindStream)
{
BOOL Ret=FALSE;

if(Imports().FindFirstStreamW.exists())
if(Imports().FindFirstStreamW)
{
Ret=::FindClose(hFindStream);
}
@@ -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);
@@ -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());
@@ -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;
}
}
}
@@ -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;
};
}
}
@@ -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);
}
@@ -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"),
@@ -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
@@ -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__);\
Oops, something went wrong.

0 comments on commit 36c94f2

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