Skip to content

Commit

Permalink
1. Рефакторинг.
Browse files Browse the repository at this point in the history
2. VS2015 warnings.
  • Loading branch information
alabuzhev committed Jan 8, 2015
1 parent d35ffae commit ec977cf
Show file tree
Hide file tree
Showing 44 changed files with 214 additions and 206 deletions.
8 changes: 7 additions & 1 deletion far/changelog
@@ -1,4 +1,10 @@
drkns 04.01.2015 19:27:27 +0200 - build 4233
drkns 08.01.2015 22:22:57 +0200 - build 4234

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

2. VS2015 warnings.

drkns 04.01.2015 19:27:27 +0200 - build 4233

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

Expand Down
5 changes: 5 additions & 0 deletions far/config.cpp
Expand Up @@ -3249,3 +3249,8 @@ int GetFarIniInt(const string& AppName, const string& KeyName, int Default)
{
return GetPrivateProfileInt(AppName.data(), KeyName.data(), Default, Global->g_strFarINI.data());
}

clock_t GetRedrawTimeout()
{
return Global->Opt->RedrawTimeout * CLOCKS_PER_SEC / 1000;
}
27 changes: 15 additions & 12 deletions far/config.hpp
Expand Up @@ -84,6 +84,7 @@ enum DIZUPDATETYPE

struct default_value;
struct column;
struct FARConfigItem;

class Option: noncopyable
{
Expand All @@ -96,8 +97,8 @@ class Option: noncopyable
virtual void fromString(const string& value) = 0;
virtual const string ExInfo() const = 0;
virtual const string typeToString() const = 0;
virtual bool IsDefault(const struct FARConfigItem* Holder) const = 0;
virtual void SetDefault(const struct FARConfigItem* Holder) = 0;
virtual bool IsDefault(const FARConfigItem* Holder) const = 0;
virtual void SetDefault(const FARConfigItem* Holder) = 0;
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) = 0;
virtual void Export(FarSettingsItem& To) const = 0;

Expand Down Expand Up @@ -136,8 +137,8 @@ class BoolOption:public Option
virtual void fromString(const string& value) override;
virtual const string ExInfo() const override { return string(); }
virtual const string typeToString() const override { return L"boolean"; }
virtual bool IsDefault(const struct FARConfigItem* Holder) const override;
virtual void SetDefault(const struct FARConfigItem* Holder) override;
virtual bool IsDefault(const FARConfigItem* Holder) const override;
virtual void SetDefault(const FARConfigItem* Holder) override;
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand All @@ -163,8 +164,8 @@ class Bool3Option:public Option
virtual void fromString(const string& value) override;
virtual const string ExInfo() const override { return string(); }
virtual const string typeToString() const override { return L"3-state"; }
virtual bool IsDefault(const struct FARConfigItem* Holder) const override;
virtual void SetDefault(const struct FARConfigItem* Holder) override;
virtual bool IsDefault(const FARConfigItem* Holder) const override;
virtual void SetDefault(const FARConfigItem* Holder) override;
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand Down Expand Up @@ -194,8 +195,8 @@ class IntOption:public Option
virtual void fromString(const string& value) override;
virtual const string ExInfo() const override;
virtual const string typeToString() const override { return L"integer"; }
virtual bool IsDefault(const struct FARConfigItem* Holder) const override;
virtual void SetDefault(const struct FARConfigItem* Holder) override;
virtual bool IsDefault(const FARConfigItem* Holder) const override;
virtual void SetDefault(const FARConfigItem* Holder) override;
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand Down Expand Up @@ -230,8 +231,8 @@ class StringOption:public Option
virtual void fromString(const string& value) override { Set(value); }
virtual const string ExInfo() const override { return string(); }
virtual const string typeToString() const override { return L"string"; }
virtual bool IsDefault(const struct FARConfigItem* Holder) const override;
virtual void SetDefault(const struct FARConfigItem* Holder) override;
virtual bool IsDefault(const FARConfigItem* Holder) const override;
virtual void SetDefault(const FARConfigItem* Holder) override;
virtual bool Edit(class DialogBuilder* Builder, int Width, int Param) override;
virtual void Export(FarSettingsItem& To) const override;

Expand Down Expand Up @@ -843,7 +844,7 @@ class Options: noncopyable
int ElevationMode;
int WindowMode;

const std::vector<struct PanelViewSettings>& ViewSettings;
const std::vector<PanelViewSettings>& ViewSettings;

class farconfig;

Expand Down Expand Up @@ -877,9 +878,11 @@ class Options: noncopyable

std::vector<farconfig> Config;
farconfig_mode CurrentConfig;
std::vector<struct PanelViewSettings> m_ViewSettings;
std::vector<PanelViewSettings> m_ViewSettings;
bool m_ViewSettingsChanged;
};

string GetFarIniString(const string& AppName, const string& KeyName, const string& Default);
int GetFarIniInt(const string& AppName, const string& KeyName, int Default);

clock_t GetRedrawTimeout();
3 changes: 1 addition & 2 deletions far/configdb.cpp
Expand Up @@ -2425,8 +2425,7 @@ bool Database::Import(const string& File)

if (doc.LoadFile(XmlFile.get()))
{
auto farconfig = doc.FirstChildElement("farconfig");
if (farconfig)
if (auto farconfig = doc.FirstChildElement("farconfig"))
{
const tinyxml::TiXmlHandle root(farconfig);

Expand Down
39 changes: 11 additions & 28 deletions far/copy.cpp
Expand Up @@ -218,11 +218,10 @@ class CopyProgress
bool IsCancelled;
FarColor Color;
int Percents;
DWORD LastWriteTime;
time_check TimeCheck;
FormatString strSrc,strDst;
string strTime;
LangString strFiles;
bool Timer();
void Flush();
void DrawNames();
void CreateScanBackground();
Expand All @@ -238,6 +237,7 @@ class CopyProgress

// BUGBUG
string strTotalCopySizeText;
time_check SecurityTimeCheck;
};

static void GetTimeText(DWORD Time,string &strTimeText)
Expand All @@ -250,23 +250,9 @@ static void GetTimeText(DWORD Time,string &strTimeText)
strTimeText = FormatString() << fmt::ExactWidth(2) << fmt::FillChar(L'0') << Hour << L":" << fmt::ExactWidth(2) << fmt::FillChar(L'0') << Min << L":" << fmt::ExactWidth(2) << fmt::FillChar(L'0') << Sec;
}

bool CopyProgress::Timer()
{
bool Result=false;
DWORD Time=GetTickCount();

if (!LastWriteTime||(Time-LastWriteTime>=(DWORD)Global->Opt->RedrawTimeout))
{
LastWriteTime=Time;
Result=true;
}

return Result;
}

void CopyProgress::Flush()
{
if (Timer())
if (TimeCheck)
{
if (!IsCancelled)
{
Expand Down Expand Up @@ -296,7 +282,8 @@ CopyProgress::CopyProgress(bool Move,bool Total,bool Time):
IsCancelled(false),
Color(ColorIndexToColor(COL_DIALOGTEXT)),
Percents(0),
LastWriteTime(0)
TimeCheck(time_check::immediate, GetRedrawTimeout()),
SecurityTimeCheck(time_check::immediate, GetRedrawTimeout())
{
}

Expand Down Expand Up @@ -480,7 +467,7 @@ void CopyProgress::SetProgress(bool TotalProgress,UINT64 CompletedSize,UINT64 To

if (m_Time&&(!Total||TotalProgress))
{
DWORD WorkTime=clock()-CopyStartTime;
auto WorkTime = clock() - CopyStartTime;
UINT64 SizeLeft=(OldTotalSize>OldCompletedSize)?(OldTotalSize-OldCompletedSize):0;
long CalcTime=OldCalcTime;

Expand All @@ -489,8 +476,8 @@ void CopyProgress::SetProgress(bool TotalProgress,UINT64 CompletedSize,UINT64 To
OldCalcTime=CalcTime=WorkTime-WaitUserTime;
}

WorkTime/=1000;
CalcTime/=1000;
WorkTime /= CLOCKS_PER_SEC;
CalcTime /= CLOCKS_PER_SEC;

if (!WorkTime)
{
Expand Down Expand Up @@ -3950,18 +3937,14 @@ bool ShellCopy::SetSecurity(const string& FileName, const api::FAR_SECURITY_DESC
return true;
}

BOOL ShellCopySecuryMsg(const CopyProgress* CP, const string& Name)
BOOL ShellCopySecuryMsg(CopyProgress* CP, const string& Name)
{
static DWORD PrepareSecuryStartTime=0;

DWORD CurTime=GetTickCount();
if (Name.empty() || ((CurTime - PrepareSecuryStartTime) > (DWORD)Global->Opt->RedrawTimeout))
if (Name.empty() || CP->SecurityTimeCheck)
{
static int Width=30;
int WidthTemp;
if (!Name.empty())
{
PrepareSecuryStartTime = CurTime; // Ïåðâûé ôàéë ðèñóåòñÿ âñåãäà
WidthTemp=std::max(static_cast<int>(Name.size()),30);
}
else
Expand Down Expand Up @@ -4116,7 +4099,7 @@ bool ShellCopy::CalcTotalSize()
{
DirInfoData Data = {};
CP->SetScanName(strSelName);
int __Ret=GetDirInfo(L"",strSelName, Data, -1, Filter, (Flags&FCOPY_COPYSYMLINKCONTENTS?GETDIRINFO_SCANSYMLINK:0)|(UseFilter?GETDIRINFO_USEFILTER:0));
int __Ret = GetDirInfo(L"", strSelName, Data, getdirinfo_infinite_delay, Filter, (Flags&FCOPY_COPYSYMLINKCONTENTS? GETDIRINFO_SCANSYMLINK : 0) | (UseFilter? GETDIRINFO_USEFILTER : 0));
FileSize = Data.FileSize;
if (__Ret <= 0)
{
Expand Down
24 changes: 24 additions & 0 deletions far/datetime.hpp
Expand Up @@ -94,3 +94,27 @@ bool Utc2Local(const FILETIME &ft, SYSTEMTIME &lst);
bool Local2Utc(const FILETIME &lft, SYSTEMTIME &st);
bool Utc2Local(const SYSTEMTIME &st, FILETIME &lft);
bool Local2Utc(const SYSTEMTIME &lst, FILETIME &ft);

class time_check: noncopyable
{
public:
enum time_check_mode { delayed, immediate };
time_check(time_check_mode Mode, clock_t Interval): m_Begin(Mode == delayed ? clock() : 0), m_Interval(Interval) {}

void reset(clock_t Value = clock()) { m_Begin = Value; }

operator bool()
{
const auto Current = clock();
if (m_Interval > 0 && Current - m_Begin > m_Interval)
{
reset(Current);
return true;
}
return false;
}

private:
clock_t m_Begin;
clock_t m_Interval;
};

0 comments on commit ec977cf

Please sign in to comment.