Skip to content

Commit

Permalink
Panel.RememberLogicalDrives is more usable now, delayed deletion of t…
Browse files Browse the repository at this point in the history
…mp files launched from plugin panels, refactoring
  • Loading branch information
alabuzhev committed Apr 17, 2017
1 parent 558dfe7 commit 9cd2103
Show file tree
Hide file tree
Showing 37 changed files with 302 additions and 257 deletions.
10 changes: 5 additions & 5 deletions far/PluginA.cpp
Expand Up @@ -538,7 +538,7 @@ static PanelMode* ConvertPanelModesA(const oldfar::PanelMode *pnmA, size_t iCoun
auto Result = std::make_unique<PanelMode[]>(iCount);
const auto SrcRange = make_range(pnmA, iCount);
auto DstRange = make_range(Result.get(), iCount);
for (auto i: zip(SrcRange, DstRange))
for (const auto& i: zip(SrcRange, DstRange))
{
const auto& Src = std::get<0>(i);
auto& Dest = std::get<1>(i);
Expand Down Expand Up @@ -672,7 +672,7 @@ static PluginPanelItem* ConvertAnsiPanelItemsToUnicode(const range<oldfar::Plugi
{
auto Result = std::make_unique<PluginPanelItem[]>(PanelItemA.size());
auto DstRange = make_range(Result.get(), PanelItemA.size());
for(auto i: zip(PanelItemA, DstRange))
for(const auto& i: zip(PanelItemA, DstRange))
{
const auto& Src = std::get<0>(i);
auto& Dst = std::get<1>(i);
Expand Down Expand Up @@ -902,7 +902,7 @@ static void AnsiVBufToUnicode(CHAR_INFO* VBufA, FAR_CHAR_INFO* VBuf, size_t Size
const auto SrcRange = make_range(VBufA, Size);
auto DstRange = make_range(VBuf, Size);

for (auto i: zip(SrcRange, DstRange))
for (const auto& i: zip(SrcRange, DstRange))
{
const auto& Src = std::get<0>(i);
auto& Dst = std::get<1>(i);
Expand Down Expand Up @@ -3304,15 +3304,15 @@ static int WINAPI FarDialogExA(intptr_t PluginNumber, int X1, int Y1, int X2, in
std::vector<oldfar::FarDialogItem> diA(ItemsRange.size());

// to save DIF_SETCOLOR state
for (auto i: zip(diA, ItemsRange))
for (const auto& i: zip(diA, ItemsRange))
{
std::get<0>(i).Flags = std::get<1>(i).Flags;
}

std::vector<FarDialogItem> di(ItemsRange.size());
std::vector<FarList> l(ItemsRange.size());

for (auto i: zip(ItemsRange, di, l))
for (const auto& i: zip(ItemsRange, di, l))
{
std::apply(AnsiDialogItemToUnicode, i);
}
Expand Down
8 changes: 8 additions & 0 deletions far/changelog
@@ -1,3 +1,11 @@
drkns 17.04.2017 22:16:12 +0000 - build 4936

1. Panel.RememberLogicalDrives теперь, наверное, можно пользоваться - сохранённый список дисков будет обновлён при необходимости.

2. При запуске с плагиновых панелей удаление временного файла производится после закрытия панели, а не сразу.

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

drkns 12.04.2017 18:58:51 +0000 - build 4935

1. Продолжение 4934.
Expand Down
8 changes: 3 additions & 5 deletions far/cmdline.cpp
Expand Up @@ -1169,12 +1169,10 @@ bool CommandLine::ProcessOSCommands(const string& CmdLine, const std::function<v

if (CmdLine.size() > 1 && CmdLine[1] == L':' && (CmdLine.size() == 2 || CmdLine.find_first_not_of(L' ', 2) == string::npos))
{
wchar_t NewDir[] = { Upper(CmdLine[0]), L':', 0, 0 };

if (!FarChDir(NewDir))
const auto DriveLetter = Upper(CmdLine[0]);
if (!FarChDir(os::fs::get_drive(DriveLetter)))
{
NewDir[2] = L'\\';
FarChDir(NewDir);
FarChDir(os::fs::get_root_directory(DriveLetter));
}
SetPanel->ChangeDirToCurrent();
return true;
Expand Down
23 changes: 13 additions & 10 deletions far/common/enum_substrings.hpp
Expand Up @@ -45,7 +45,7 @@ namespace detail
auto Begin(char_type* Container) { return Container; }

template<class container>
bool IsEnd(const container& Container, decltype(std::cbegin(Container)) Iterator) { return Iterator == Container.cend(); }
bool IsEnd(const container& Container, decltype(std::cbegin(Container)) Iterator) { return Iterator == std::cend(Container); }
template<class char_type>
bool IsEnd(const char_type* Container, const char_type* Iterator) { return Iterator != Container && !*Iterator && !*(Iterator - 1); }
}
Expand All @@ -54,28 +54,29 @@ namespace detail
// Stops on double \0 or if end of container is reached.

template<class provider>
class enum_substrings_t: public enumerator<enum_substrings_t<provider>, range<decltype(&*detail::Begin(std::declval<std::decay_t<provider>>()))>>
class enum_substrings_t: public enumerator<enum_substrings_t<provider>, range<decltype(&*detail::Begin(std::declval<std::decay_t<const provider>>()))>>
{
IMPLEMENTS_ENUMERATOR(enum_substrings_t);
public:
NONCOPYABLE(enum_substrings_t);
MOVABLE(enum_substrings_t);

explicit enum_substrings_t(const provider& Provider): m_Provider(&Provider), m_Offset() {}
enum_substrings_t(const provider&&) = delete;
enum_substrings_t(const provider& Provider): m_Provider(&Provider), m_Offset() {}

private:
bool get(size_t Index, typename enum_substrings_t<provider>::value_type& Value)
bool get(size_t Index, typename enum_substrings_t::value_type& Value)
{
const auto Begin = detail::Begin(*m_Provider) + (Index? m_Offset : 0);
const auto Begin = detail::Begin(static_cast<std::decay_t<const provider>>(*m_Provider)) + (Index? m_Offset : 0);
auto End = Begin;
bool IsEnd;
for (; (IsEnd = detail::IsEnd(*m_Provider, End)) == false && *End; ++End)
for (; (IsEnd = detail::IsEnd(static_cast<std::decay_t<const provider>>(*m_Provider), End)) == false && *End; ++End)
;
if (End == Begin)
return false;

const auto Ptr = &*Begin;
Value = typename enum_substrings_t<provider>::value_type(Ptr, Ptr + (End - Begin));
Value = typename enum_substrings_t::value_type(Ptr, Ptr + (End - Begin));
m_Offset += Value.size() + (IsEnd? 0 : 1);
return true;
}
Expand All @@ -85,10 +86,12 @@ class enum_substrings_t: public enumerator<enum_substrings_t<provider>, range<de
};

template<class T>
auto enum_substrings(T&& Provider)
void enum_substrings(const T&& Provider) = delete;

template<class T>
auto enum_substrings(const T& Provider)
{
static_assert(std::is_lvalue_reference<T>::value);
return enum_substrings_t<std::remove_reference_t<T>>(Provider);
return enum_substrings_t<T>(Provider);
}

#endif // ENUM_SUBSTRINGS_HPP_AD490DED_6C5F_4C74_82ED_F858919C4277
4 changes: 2 additions & 2 deletions far/config.cpp
Expand Up @@ -1029,7 +1029,7 @@ static void ResetViewModes(const range<PanelViewSettings*>& Modes, int Index = -

if (Index < 0)
{
for (auto i : zip(InitialModes, Modes))
for (const auto& i: zip(InitialModes, Modes))
std::apply(InitMode, i);
}
else
Expand Down Expand Up @@ -2088,7 +2088,7 @@ void Options::Load(const std::vector<std::pair<string, string>>& Overridden)
};
static_assert(std::size(GuidOptions) == std::size(DefaultKnownGuids));

for(auto i: zip(DefaultKnownGuids, GuidOptions))
for(const auto& i: zip(DefaultKnownGuids, GuidOptions))
{
auto& a = std::get<0>(i);
auto& b = std::get<1>(i);
Expand Down
10 changes: 5 additions & 5 deletions far/config.hpp
Expand Up @@ -111,7 +111,7 @@ class Option
virtual string toString() const = 0;
virtual bool TryParse(const string& value) = 0;
virtual string ExInfo() const = 0;
virtual string GetType() const = 0;
virtual const wchar_t* GetType() const = 0;
virtual bool IsDefault(const any& Default) const = 0;
virtual void SetDefault(const any& Default) = 0;
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) = 0;
Expand Down Expand Up @@ -197,7 +197,7 @@ class BoolOption: public detail::OptionImpl<bool, BoolOption>

virtual string toString() const override { return Get() ? L"true"s : L"false"s; }
virtual bool TryParse(const string& value) override;
virtual string GetType() const override { return L"boolean"s; }
virtual const wchar_t* GetType() const override { return L"boolean"; }
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand All @@ -212,7 +212,7 @@ class Bool3Option: public detail::OptionImpl<long long, Bool3Option>

virtual string toString() const override { const auto v = Get(); return v == BSTATE_CHECKED? L"true"s : v == BSTATE_UNCHECKED? L"false"s : L"other"s; }
virtual bool TryParse(const string& value) override;
virtual string GetType() const override { return L"3-state"s; }
virtual const wchar_t* GetType() const override { return L"3-state"; }
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand All @@ -228,7 +228,7 @@ class IntOption: public detail::OptionImpl<long long, IntOption>
virtual string toString() const override { return str(Get()); }
virtual bool TryParse(const string& value) override;
virtual string ExInfo() const override;
virtual string GetType() const override { return L"integer"s; }
virtual const wchar_t* GetType() const override { return L"integer"; }
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand All @@ -250,7 +250,7 @@ class StringOption: public detail::OptionImpl<string, StringOption>

virtual string toString() const override { return Get(); }
virtual bool TryParse(const string& value) override { Set(value); return true; }
virtual string GetType() const override { return L"string"s; }
virtual const wchar_t* GetType() const override { return L"string"; }
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand Down
13 changes: 7 additions & 6 deletions far/cvtname.cpp
Expand Up @@ -42,6 +42,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "strmix.hpp"
#include "elevation.hpp"
#include "local.hpp"
#include "drivemix.hpp"

static void MixToFullPath(string& strPath)
{
Expand Down Expand Up @@ -150,7 +151,7 @@ static void MixToFullPath(const string& stPath, string& Dest, const string& stCu
}
else
{
const string DriveVar{L'=', stPath[0], L':'};
const auto DriveVar = L'=' + os::fs::get_drive(stPath[0]);
const auto strValue(os::env::get_variable(DriveVar));

if (!strValue.empty())
Expand Down Expand Up @@ -260,14 +261,14 @@ static string TryConvertVolumeGuidToDrivePath(const string& Path, const wchar_t
else
{
string strVolumeGuid;
const auto Strings = os::GetLogicalDriveStrings();
const auto ItemIterator = std::find_if(ALL_CONST_RANGE(Strings), [&](const auto& item)
const auto Enumerator = os::fs::enum_drives(os::fs::get_logical_drives());
const auto ItemIterator = std::find_if(ALL_CONST_RANGE(Enumerator), [&](const auto& i)
{
return os::GetVolumeNameForVolumeMountPoint(item, strVolumeGuid) && Path.compare(0, DirectoryOffset, strVolumeGuid.data(), DirectoryOffset) == 0;
return os::GetVolumeNameForVolumeMountPoint(os::fs::get_drive(i), strVolumeGuid) && Path.compare(0, DirectoryOffset, strVolumeGuid.data(), DirectoryOffset) == 0;
});
if (ItemIterator != Strings.cend())
if (ItemIterator != Enumerator.cend())
{
Result.replace(0, DirectoryOffset, *ItemIterator);
Result.replace(0, DirectoryOffset, os::fs::get_drive(*ItemIterator));
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions far/delete.cpp
Expand Up @@ -1188,3 +1188,14 @@ bool DeleteFileWithFolder(const string& FileName)
}
return Result;
}

delayed_deleter::delayed_deleter(const string& pathToDelete):
m_pathToDelete(pathToDelete)
{
}

delayed_deleter::~delayed_deleter()
{
DeleteFileWithFolder(m_pathToDelete);
}

10 changes: 10 additions & 0 deletions far/delete.hpp
Expand Up @@ -61,4 +61,14 @@ class ShellDelete: noncopyable
void DeleteDirTree(const string& Dir);
bool DeleteFileWithFolder(const string& FileName);

class delayed_deleter: noncopyable
{
public:
delayed_deleter(const string& pathToDelete);
~delayed_deleter();

private:
string m_pathToDelete;
};

#endif // DELETE_HPP_835E1D6F_E70E_4AF7_8D20_1668C007B16C
6 changes: 3 additions & 3 deletions far/dialog.cpp
Expand Up @@ -262,7 +262,7 @@ static size_t ConvertItemEx2(const DialogItemEx *ItemEx, FarGetDialogItem *Item)

void ItemsToItemsEx(const range<const FarDialogItem*>& Items, const range<DialogItemEx*>& ItemsEx, bool Short)
{
for (auto i: zip(Items, ItemsEx))
for (const auto& i: zip(Items, ItemsEx))
{
const auto& Item = std::get<0>(i);
auto& ItemEx = std::get<1>(i);
Expand Down Expand Up @@ -350,9 +350,9 @@ void Dialog::Construct(const range<DialogItemEx*>& SrcItems)
Items.assign(ALL_CONST_RANGE(SrcItems));

// Items[i].Auto.Owner points to SrcItems, we need to update:
for (auto i: zip(Items, SrcItems))
for (const auto& i: zip(Items, SrcItems))
{
for (auto j : zip(std::get<0>(i).Auto, std::get<1>(i).Auto))
for (const auto& j : zip(std::get<0>(i).Auto, std::get<1>(i).Auto))
{
const auto SrcItemIterator = std::find_if(ALL_CONST_RANGE(SrcItems), [&](const auto& SrcItem)
{
Expand Down
4 changes: 1 addition & 3 deletions far/dirmix.cpp
Expand Up @@ -77,9 +77,7 @@ bool FarChDir(const string& NewDir, bool ChangeDir)

if (!rc && GetLastError() == ERROR_PATH_NOT_FOUND)
{
os::drives_set NetworkDrives;
AddSavedNetworkDisks(NetworkDrives);
IsNetworkDrive = os::is_standard_drive_letter(Drive[1]) && NetworkDrives[os::get_drive_number(Drive[1])];
IsNetworkDrive = os::fs::is_standard_drive_letter(Drive[1]) && GetSavedNetworkDrives()[os::fs::get_drive_number(Drive[1])];
}
}
else
Expand Down

0 comments on commit 9cd2103

Please sign in to comment.