Permalink
Browse files

Using time_point and duration for internal time representation instea…

…d of FILETIME and raw integers where possible; unified format for filter & highlight & sort group entries
  • Loading branch information...
alabuzhev committed Oct 19, 2017
1 parent 4bab816 commit 95623472dd8671113eaca0ee6e025107355e128d
Showing with 1,186 additions and 922 deletions.
  1. +8 −0 far/changelog
  2. +1 −0 far/common.hpp
  3. +1 −1 far/common/bytes_view.hpp
  4. +65 −0 far/common/chrono.hpp
  5. +34 −0 far/common/utility.hpp
  6. +21 −16 far/configdb.cpp
  7. +3 −3 far/configdb.hpp
  8. +8 −8 far/copy.cpp
  9. +8 −7 far/copy_progress.cpp
  10. +156 −168 far/datetime.cpp
  11. +14 −54 far/datetime.hpp
  12. +2 −2 far/dialog.cpp
  13. +1 −1 far/dialog.hpp
  14. +1 −2 far/disabled_warnings.hpp
  15. +1 −1 far/elevation.cpp
  16. +1 −1 far/execute.cpp
  17. +8 −2 far/far.vcxproj
  18. +9 −0 far/far.vcxproj.filters
  19. +1 −1 far/fileattr.cpp
  20. +1 −1 far/fileattr.hpp
  21. +1 −1 far/fileedit.cpp
  22. +245 −139 far/filefilter.cpp
  23. +4 −1 far/filefilter.hpp
  24. +212 −195 far/filefilterparams.cpp
  25. +29 −9 far/filefilterparams.hpp
  26. +53 −47 far/filelist.cpp
  27. +5 −5 far/filelist.hpp
  28. +1 −1 far/filesystemwatcher.cpp
  29. +2 −2 far/filesystemwatcher.hpp
  30. +6 −6 far/findfile.cpp
  31. +6 −4 far/headers.hpp
  32. +37 −141 far/hilight.cpp
  33. +1 −1 far/hilight.hpp
  34. +3 −3 far/history.cpp
  35. +3 −3 far/hook_wow64.cpp
  36. +5 −4 far/infolist.cpp
  37. +8 −10 far/macro.cpp
  38. +7 −0 far/main.cpp
  39. +1 −0 far/makefile_gcc
  40. +3 −2 far/makefile_vc
  41. +9 −8 far/mix.cpp
  42. +2 −2 far/panelmix.cpp
  43. +1 −1 far/panelmix.hpp
  44. +68 −0 far/platform.chrono.cpp
  45. +56 −0 far/platform.chrono.hpp
  46. +16 −16 far/platform.fs.cpp
  47. +7 −7 far/platform.fs.hpp
  48. +3 −2 far/platform.hpp
  49. +2 −1 far/plclass.cpp
  50. +1 −1 far/plugsettings.cpp
  51. +34 −34 far/setattr.cpp
  52. +3 −1 far/stddlg.cpp
  53. +2 −1 far/synchro.hpp
  54. +3 −3 far/syslog.cpp
  55. +1 −1 far/vbuild.m4
  56. +1 −1 far/vc_crt_fix_impl.cpp
  57. +1 −1 far/viewer.cpp
@@ -1,3 +1,11 @@
drkns 19.10.2017 01:07:23 +0100 - build 5068
1. Для внутреннего представления времени по возможности используются стандартные time_point и duration вместо FILETIME и голых чисел. Изменения масштабные, возможны баги.
2. Унифицирован формат фильтров и групп раскраски/сортировки, ибо слишком много копипасты.
В целях совместимости старый формат пока что поддерживается в обе стороны (и читается, и пишется).
Через некоторое время поддержка будет убрана.
drkns 18.10.2017 00:47:15 +0100 - build 5067
1. С форума: некорректное отображение помощи (а на самом деле чтение - см. "четное количество багов"), если её язык не совпадает с текущим.
@@ -60,6 +60,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "common/zip_view.hpp"
#include "common/bytes_view.hpp"
#include "common/singleton.hpp"
#include "common/chrono.hpp"
// TODO: clean up & split
@@ -41,7 +41,7 @@ class bytes_view: public range<const char*>
}
template<typename T>
explicit bytes_view(T& Object):
explicit bytes_view(const T& Object):
bytes_view(&Object, sizeof(Object))
{
static_assert(std::is_trivially_copyable<T>::value);
@@ -0,0 +1,65 @@
#ifndef CHRONO_HPP_D4A71D62_47D4_45B1_B667_84D6E1E31A14
#define CHRONO_HPP_D4A71D62_47D4_45B1_B667_84D6E1E31A14
#pragma once
/*
chrono.hpp
*/
/*
Copyright © 2017 Far Group
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
template<typename... tuple_types>
class split_duration: public std::tuple<tuple_types...>
{
public:
template<typename duration_type>
split_duration(duration_type Duration)
{
split<0, duration_type, tuple_types...>(Duration);
}
private:
template<size_t Index, typename duration_type>
void split(duration_type) const
{
}
template<size_t Index, typename duration_type, typename arg, typename... args>
void split(duration_type Duration)
{
const auto Value = std::chrono::duration_cast<arg>(Duration);
std::get<Index>(*this) = Value;
split<Index + 1, duration_type, args...>(Duration - Value);
}
};
namespace chrono
{
using days = std::chrono::duration<int, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
}
#endif // CHRONO_HPP_D4A71D62_47D4_45B1_B667_84D6E1E31A14
@@ -117,4 +117,38 @@ namespace enum_helpers
}
}
namespace detail
{
template<class... args>
struct overload_t;
template<typename arg>
struct overload_t<arg>: arg
{
using type = arg;
using arg::operator();
};
template<typename arg, typename... args>
struct overload_t<arg, args...>: arg, overload_t<args...>::type
{
using type = overload_t;
explicit overload_t(arg&& Arg, args&&... Args):
arg(FWD(Arg)),
args(FWD(Args))...
{
}
using arg::operator();
using overload_t<args...>::type::operator();
};
}
template<typename... args>
auto overload(args&&... Args)
{
return detail::overload_t<args...>(FWD(Args)...);
}
#endif // UTILITY_HPP_D8E934C7_BF30_4CEB_B80C_6E508DF7A1BC
@@ -680,7 +680,16 @@ class HierarchicalConfigDb: public async_delete_impl, public HierarchicalConfig,
if (!Stmt->Bind(Root.get(), Name).Step())
return false;
Value = std::invoke(Getter, Stmt, 0);
try
{
Value = std::invoke(Getter, Stmt, 0);
}
catch (const far_exception&)
{
// Blob assignment could fail if the size is incorrect
return false;
}
return true;
}
@@ -1609,11 +1618,6 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
}
private:
static unsigned long long DaysToUI64(int Days)
{
return Days * 24ull * 60ull * 60ull * 10000000ull;
}
os::thread WorkThread;
os::event StopEvent;
os::event AsyncDeleteAddDone;
@@ -1702,7 +1706,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
bool AddInternal(unsigned int TypeHistory, const string& HistoryName, const string &Name, int Type, bool Lock, const string &strGuid, const string &strFile, const string &strData) const
{
return ExecuteStatement(stmtAdd, TypeHistory, HistoryName, Type, Lock, Name, GetCurrentUTCTimeInUI64(), strGuid, strFile, strData);
return ExecuteStatement(stmtAdd, TypeHistory, HistoryName, Type, Lock, Name, nt_clock::now().time_since_epoch().count(), strGuid, strFile, strData);
}
bool DeleteInternal(unsigned long long id) const
@@ -1808,7 +1812,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
return DeleteInternal(id);
}
virtual bool Enum(DWORD index, unsigned int TypeHistory, const string_view& HistoryName, unsigned long long *id, string &Name, history_record_type* Type, bool *Lock, unsigned long long *Time, string &strGuid, string &strFile, string &strData, bool Reverse = false) override
virtual bool Enum(DWORD index, unsigned int TypeHistory, const string_view& HistoryName, unsigned long long& id, string& Name, history_record_type& Type, bool& Lock, time_point& Time, string& strGuid, string& strFile, string& strData, bool Reverse = false) override
{
WaitAllAsync();
auto Stmt = AutoStatement(Reverse? stmtEnumDesc : stmtEnum);
@@ -1819,11 +1823,11 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
if (!Stmt->Step())
return false;
*id = Stmt->GetColInt64(0);
id = Stmt->GetColInt64(0);
Name = Stmt->GetColText(1);
*Type = static_cast<history_record_type>(Stmt->GetColInt(2));
*Lock = Stmt->GetColInt(3) != 0;
*Time = Stmt->GetColInt64(4);
Type = static_cast<history_record_type>(Stmt->GetColInt(2));
Lock = Stmt->GetColInt(3) != 0;
Time = time_point(duration(Stmt->GetColInt64(4)));
strGuid = Stmt->GetColText(5);
strFile = Stmt->GetColText(6);
strData = Stmt->GetColText(7);
@@ -1855,7 +1859,8 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
virtual bool DeleteOldUnlocked(unsigned int TypeHistory, const string_view& HistoryName, int DaysToKeep, int MinimumEntries) override
{
WaitAllAsync();
const auto older = GetCurrentUTCTimeInUI64() - DaysToUI64(DaysToKeep);
const auto older = (nt_clock::now() - chrono::days(DaysToKeep)).time_since_epoch().count();
return ExecuteStatement(stmtDeleteOldUnlocked, TypeHistory, HistoryName, older, MinimumEntries);
}
@@ -1966,7 +1971,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
virtual unsigned long long SetEditorPos(const string_view& Name, int Line, int LinePos, int ScreenLine, int LeftPos, uintptr_t CodePage) override
{
WaitCommitAsync();
return ExecuteStatement(stmtSetEditorPos, Name, GetCurrentUTCTimeInUI64(), Line, LinePos, ScreenLine, LeftPos, CodePage)? LastInsertRowID() : 0;
return ExecuteStatement(stmtSetEditorPos, Name, nt_clock::now().time_since_epoch().count(), Line, LinePos, ScreenLine, LeftPos, CodePage)? LastInsertRowID() : 0;
}
virtual unsigned long long GetEditorPos(const string_view& Name, int *Line, int *LinePos, int *ScreenLine, int *LeftPos, uintptr_t *CodePage) override
@@ -2007,7 +2012,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
virtual unsigned long long SetViewerPos(const string_view& Name, long long FilePos, long long LeftPos, int Hex_Wrap, uintptr_t CodePage) override
{
WaitCommitAsync();
return ExecuteStatement(stmtSetViewerPos, Name, GetCurrentUTCTimeInUI64(), FilePos, LeftPos, Hex_Wrap, CodePage)? LastInsertRowID() : 0;
return ExecuteStatement(stmtSetViewerPos, Name, nt_clock::now().time_since_epoch().count(), FilePos, LeftPos, Hex_Wrap, CodePage)? LastInsertRowID() : 0;
}
virtual unsigned long long GetViewerPos(const string_view& Name, long long *FilePos, long long *LeftPos, int *Hex, uintptr_t *CodePage) override
@@ -2046,7 +2051,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb
virtual void DeleteOldPositions(int DaysToKeep, int MinimumEntries) override
{
WaitCommitAsync();
const auto older = GetCurrentUTCTimeInUI64() - DaysToUI64(DaysToKeep);
const auto older = (nt_clock::now() - chrono::days(DaysToKeep)).time_since_epoch().count();
ExecuteStatement(stmtDeleteOldEditor, older, MinimumEntries);
ExecuteStatement(stmtDeleteOldViewer, older, MinimumEntries);
}
@@ -288,7 +288,7 @@ class HistoryConfig: public representable, virtual public transactional
virtual ~HistoryConfig() override = default;
//command,view,edit,folder,dialog history
virtual bool Enum(DWORD index, unsigned int TypeHistory, const string_view& HistoryName, unsigned long long *id, string &strName, history_record_type* Type, bool *Lock, unsigned long long *Time, string &strGuid, string &strFile, string &strData, bool Reverse=false) = 0;
virtual bool Enum(DWORD index, unsigned int TypeHistory, const string_view& HistoryName, unsigned long long& id, string& strName, history_record_type& Type, bool& Lock, time_point& Time, string& strGuid, string& strFile, string& strData, bool Reverse = false) = 0;
virtual bool Delete(unsigned long long id) = 0;
virtual bool DeleteAndAddAsync(unsigned long long DeleteId, unsigned int TypeHistory, const string_view& HistoryName, const string_view& strName, int Type, bool Lock, string &strGuid, string &strFile, string &strData) = 0;
virtual bool DeleteOldUnlocked(unsigned int TypeHistory, const string_view& HistoryName, int DaysToKeep, int MinimumEntries) = 0;
@@ -321,7 +321,7 @@ class HistoryConfig: public representable, virtual public transactional
string Name;
history_record_type Type;
bool Lock;
unsigned long long Time;
time_point Time;
string Guid;
string File;
string Data;
@@ -333,7 +333,7 @@ class HistoryConfig: public representable, virtual public transactional
using value_type = enum_data;
return make_inline_enumerator<value_type>([this, HistoryType, &HistoryName, Reverse](size_t Index, value_type& Value)
{
return Enum(static_cast<DWORD>(Index), HistoryType, HistoryName, &Value.Id, Value.Name, &Value.Type, &Value.Lock, &Value.Time, Value.Guid, Value.File, Value.Data, Reverse);
return Enum(static_cast<DWORD>(Index), HistoryType, HistoryName, Value.Id, Value.Name, Value.Type, Value.Lock, Value.Time, Value.Guid, Value.File, Value.Data, Reverse);
});
}
@@ -3077,7 +3077,7 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
if (!(Flags&FCOPY_COPYTONUL))
{
DestFile.SetTime(nullptr, nullptr, &SrcData.ftLastWriteTime, nullptr);
DestFile.SetTime(nullptr, nullptr, &SrcData.LastWriteTime, nullptr);
if (CopySparse)
{
@@ -3100,7 +3100,7 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
{
if (DestFile.Open(strDestName,GENERIC_WRITE,FILE_SHARE_READ,nullptr,OPEN_EXISTING,flags_attrs))
{
DestFile.SetTime(nullptr, nullptr, &SrcData.ftLastWriteTime, nullptr);
DestFile.SetTime(nullptr, nullptr, &SrcData.LastWriteTime, nullptr);
DestFile.Close();
}
}
@@ -3348,29 +3348,29 @@ bool ShellCopy::AskOverwrite(const os::fs::find_data &SrcData,
if ((Flags&FCOPY_ONLYNEWERFILES))
{
// сравним время
if (DestData.ftLastWriteTime < SrcData.ftLastWriteTime)
if (DestData.LastWriteTime < SrcData.LastWriteTime)
MsgCode = 0;
else
MsgCode = 2;
}
else
{
unsigned long long SrcSize = SrcData.nFileSize;
FILETIME SrcLastWriteTime = SrcData.ftLastWriteTime;
auto SrcLastWriteTime = SrcData.LastWriteTime;
if (Flags&FCOPY_COPYSYMLINKCONTENTS && SrcData.dwFileAttributes&FILE_ATTRIBUTE_REPARSE_POINT)
{
os::fs::find_data FindData;
if (os::fs::get_find_data(ConvertNameToReal(SrcName), FindData))
{
SrcSize = FindData.nFileSize;
SrcLastWriteTime = FindData.ftLastWriteTime;
SrcLastWriteTime = FindData.LastWriteTime;
}
}
string strDateText, strTimeText;
ConvertDate(SrcLastWriteTime, strDateText, strTimeText, 8, FALSE, FALSE, TRUE);
const auto strSrcFileStr = format(Format, msg(lng::MCopySource), SrcSize, strDateText, strTimeText);
ConvertDate(DestData.ftLastWriteTime, strDateText, strTimeText, 8, FALSE, FALSE, TRUE);
ConvertDate(DestData.LastWriteTime, strDateText, strTimeText, 8, FALSE, FALSE, TRUE);
const auto strDestFileStr = format(Format, msg(lng::MCopyDest), DestData.nFileSize, strDateText, strTimeText);
WarnCopyDlgData[WDLG_SRCFILEBTN].Data = strSrcFileStr.data();
@@ -3464,9 +3464,9 @@ bool ShellCopy::AskOverwrite(const os::fs::find_data &SrcData,
}
string strDateText, strTimeText;
ConvertDate(SrcData.ftLastWriteTime,strDateText,strTimeText,8,FALSE,FALSE,TRUE);
ConvertDate(SrcData.LastWriteTime, strDateText, strTimeText, 8, FALSE, FALSE, TRUE);
const auto strSrcFileStr = format(Format, msg(lng::MCopySource), SrcData.nFileSize, strDateText, strTimeText);
ConvertDate(DestData.ftLastWriteTime,strDateText,strTimeText,8,FALSE,FALSE,TRUE);
ConvertDate(DestData.LastWriteTime, strDateText, strTimeText, 8, FALSE, FALSE, TRUE);
const auto strDestFileStr = format(Format, msg(lng::MCopyDest), DestData.nFileSize, strDateText, strTimeText);
WarnCopyDlgData[WDLG_SRCFILEBTN].Data=strSrcFileStr.data();
WarnCopyDlgData[WDLG_DSTFILEBTN].Data=strDestFileStr.data();
@@ -1,4 +1,4 @@
/*
/*
copy_progress.cpp
*/
/*
@@ -73,14 +73,14 @@ size_t copy_progress::GetCanvasWidth()
return 52;
}
static string GetTimeText(DWORD Seconds)
static string GetTimeText(std::chrono::seconds Seconds)
{
string Days, Time;
ConvertRelativeDate(UI64ToFileTime(Seconds * 1000ull * 10000ull), Days, Time);
ConvertDuration(Seconds, Days, Time);
if (Days != L"0")
{
// BUGBUG copy time > 4.166 days (100 hrs) will not be displayed correctly
const auto Hours = str(std::min(Seconds / 3600, 99ul));
const auto Hours = str(std::min(std::chrono::duration_cast<std::chrono::hours>(Seconds), 99h).count());
Time[0] = Hours[0];
Time[1] = Hours[1];
}
@@ -310,19 +310,20 @@ void copy_progress::UpdateTime(unsigned long long SizeDone, unsigned long long S
m_CalcTime = std::chrono::steady_clock::now() - m_CopyStartTime - WaitUserTime;
string tmp[3];
if (const auto CalcTime = std::chrono::duration_cast<std::chrono::seconds>(m_CalcTime).count())
const auto CalcTime = std::chrono::duration_cast<std::chrono::seconds>(m_CalcTime);
if (CalcTime != CalcTime.zero())
{
SizeDone -= m_Bytes.Skipped;
const auto CPS = SizeDone / CalcTime;
const auto CPS = SizeDone / CalcTime.count();
const auto strCalcTimeStr = GetTimeText(CalcTime);
if (m_SpeedUpdateCheck)
{
if (SizeToGo)
{
m_TimeLeft = GetTimeText(static_cast<DWORD>(CPS? SizeToGo / CPS:0));
m_TimeLeft = GetTimeText(std::chrono::seconds(CPS? SizeToGo / CPS : 0));
}
m_Speed = FileSizeToStr(CPS, 8, COLUMN_FLOATSIZE | COLUMN_COMMAS);
Oops, something went wrong.

0 comments on commit 9562347

Please sign in to comment.