Skip to content

Commit

Permalink
More of 3503: pass lasterror to Message directly, not via globals
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Oct 25, 2017
1 parent 2c364ae commit 13d4615
Show file tree
Hide file tree
Showing 42 changed files with 329 additions and 252 deletions.
4 changes: 2 additions & 2 deletions far/PluginA.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ class oem_plugin_factory: public native_plugin_factory
auto Module = std::make_unique<oem_plugin_module>(filename); auto Module = std::make_unique<oem_plugin_module>(filename);
if (!Module->m_Module) if (!Module->m_Module)
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();


Message(MSG_WARNING | MSG_ERRORTYPE | MSG_NOPLUGINS, Message(MSG_WARNING | MSG_NOPLUGINS, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MPlgLoadPluginError), msg(lng::MPlgLoadPluginError),
Expand Down
4 changes: 4 additions & 0 deletions far/changelog
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,7 @@
drkns 26.10.2017 00:01:39 +0100 - build 5075

1. Продолжение 3503: передача состояния LastError / LastNtStatus в Message напрямую, а не через глобальные пременные.

drkns 25.10.2017 22:37:34 +0100 - build 5074 drkns 25.10.2017 22:37:34 +0100 - build 5074


1. Группы сортировки работают только в режимах по имени и расширению, как раньше. 1. Группы сортировки работают только в режимах по имени и расширению, как раньше.
Expand Down
8 changes: 5 additions & 3 deletions far/cmdline.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1281,15 +1281,17 @@ bool CommandLine::IntChDir(const string& CmdLine,int ClosePanel,bool Selent)
} }
else else
{ {
Global->CatchError();
if (!Selent) if (!Selent)
Message(MSG_WARNING | MSG_ERRORTYPE, {
const auto ErrorState = error_state::fetch();

Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
strExpandedDir strExpandedDir
}, },
{ lng::MOk }); { lng::MOk });

}
return false; return false;
} }


Expand Down
85 changes: 45 additions & 40 deletions far/copy.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ COPY_CODES ShellCopy::CopyFileTree(const string& Dest)
&& !IsSlash(strDest.back()) && !IsSlash(strDest.back())
&& !os::fs::exists(strDest)) && !os::fs::exists(strDest))
{ {
switch (Message(FMSG_WARNING, switch (Message(MSG_WARNING,
msg(lng::MWarning), msg(lng::MWarning),
{ {
strDest, strDest,
Expand Down Expand Up @@ -1426,8 +1426,9 @@ COPY_CODES ShellCopy::CopyFileTree(const string& Dest)
auto Exists_2 = Exists_1; auto Exists_2 = Exists_1;
while ( !Exists_2 && SkipMode != 2) while ( !Exists_2 && SkipMode != 2)
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();
const auto Result = OperationFailed(strDestDriveRoot, lng::MError, L"");
const auto Result = OperationFailed(ErrorState, strDestDriveRoot, lng::MError, L"");
if (Result == operation::retry) if (Result == operation::retry)
{ {
continue; continue;
Expand Down Expand Up @@ -1978,8 +1979,9 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
} }
else else
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();
int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE,
int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCopyCannotRenameFolder), msg(lng::MCopyCannotRenameFolder),
Expand Down Expand Up @@ -2031,8 +2033,8 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
SrcData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && Flags & FCOPY_COPYSYMLINKCONTENTS? L""s : Src, SrcData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && Flags & FCOPY_COPYSYMLINKCONTENTS? L""s : Src,
strDestPath, Flags & FCOPY_COPYSECURITY? &SecAttr : nullptr)) strDestPath, Flags & FCOPY_COPYSECURITY? &SecAttr : nullptr))
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();
const int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE, const int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCopyCannotCreateFolder), msg(lng::MCopyCannotCreateFolder),
Expand Down Expand Up @@ -2100,8 +2102,8 @@ COPY_CODES ShellCopy::ShellCopyOneFile(


while (!ShellSetAttr(strDestPath,SetAttr)) while (!ShellSetAttr(strDestPath,SetAttr))
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();
const int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE, const int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCopyCannotChangeFolderAttr), msg(lng::MCopyCannotChangeFolderAttr),
Expand Down Expand Up @@ -2136,8 +2138,8 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
{ {
while (!ShellSetAttr(strDestPath,SetAttr)) while (!ShellSetAttr(strDestPath,SetAttr))
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();
const int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE, const int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCopyCannotChangeFolderAttr), msg(lng::MCopyCannotChangeFolderAttr),
Expand Down Expand Up @@ -2256,6 +2258,8 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
{ {
for (;;) for (;;)
{ {
error_state ErrorState;

if (!(Flags&FCOPY_COPYTONUL) && Rename) if (!(Flags&FCOPY_COPYTONUL) && Rename)
{ {
int AskDelete; int AskDelete;
Expand Down Expand Up @@ -2300,16 +2304,13 @@ COPY_CODES ShellCopy::ShellCopyOneFile(


if (!FileMoved) if (!FileMoved)
{ {
int MoveLastError=GetLastError(); ErrorState = error_state::fetch();


if (NWFS_Attr) if (NWFS_Attr)
os::fs::set_file_attributes(strSrcFullName,SrcData.dwFileAttributes); os::fs::set_file_attributes(strSrcFullName,SrcData.dwFileAttributes);


if (MoveLastError==ERROR_NOT_SAME_DEVICE) if (ErrorState.Win32Error == ERROR_NOT_SAME_DEVICE)
return COPY_FAILURE; return COPY_FAILURE;

SetLastError(MoveLastError);
Global->CatchError();
} }
else else
{ {
Expand All @@ -2334,7 +2335,7 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
do do
{ {
DWORD Attr=INVALID_FILE_ATTRIBUTES; DWORD Attr=INVALID_FILE_ATTRIBUTES;
CopyCode=ShellCopyFile(Src,SrcData,strDestPath,Attr,Append); CopyCode = ShellCopyFile(Src, SrcData, strDestPath, Attr, Append, ErrorState);
} }
while (CopyCode==COPY_RETRY); while (CopyCode==COPY_RETRY);


Expand Down Expand Up @@ -2382,7 +2383,7 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
int CopyCode; int CopyCode;
do do
{ {
CopyCode=ShellCopyFile(Src,SrcData,strDestPath,DestAttr,Append); CopyCode = ShellCopyFile(Src, SrcData, strDestPath, DestAttr, Append, ErrorState);
} }
while (CopyCode==COPY_RETRY); while (CopyCode==COPY_RETRY);


Expand Down Expand Up @@ -2438,10 +2439,10 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
//if (GetLastError() == ERROR_ACCESS_DENIED) //if (GetLastError() == ERROR_ACCESS_DENIED)
{ {
SetLastError(ERROR_ENCRYPTION_FAILED); SetLastError(ERROR_ENCRYPTION_FAILED);
ErrorState = error_state::fetch();
} }
Global->CatchError();


MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE, MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(MsgMCannot), msg(MsgMCannot),
Expand Down Expand Up @@ -2478,8 +2479,10 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
MsgCode=SkipMode; MsgCode=SkipMode;
else else
{ {
Global->CatchError(); if (!ErrorState.engaged())
MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE, ErrorState = error_state::fetch();

MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(MsgMCannot), msg(MsgMCannot),
Expand Down Expand Up @@ -2614,13 +2617,16 @@ int ShellCopy::DeleteAfterMove(const string& Name,DWORD Attr)


while ((Attr&FILE_ATTRIBUTE_DIRECTORY)?!os::fs::remove_directory(FullName):!os::fs::delete_file(FullName)) while ((Attr&FILE_ATTRIBUTE_DIRECTORY)?!os::fs::remove_directory(FullName):!os::fs::delete_file(FullName))
{ {
Global->CatchError();
operation MsgCode; operation MsgCode;


if (SkipDeleteMode!=-1) if (SkipDeleteMode!=-1)
MsgCode = static_cast<operation>(SkipDeleteMode); MsgCode = static_cast<operation>(SkipDeleteMode);
else else
MsgCode=OperationFailed(FullName, lng::MError, msg(lng::MCannotDeleteFile)); {
const auto ErrorState = error_state::fetch();

MsgCode = OperationFailed(ErrorState, FullName, lng::MError, msg(lng::MCannotDeleteFile));
}


switch (MsgCode) switch (MsgCode)
{ {
Expand All @@ -2645,7 +2651,7 @@ int ShellCopy::DeleteAfterMove(const string& Name,DWORD Attr)




int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcData, int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcData,
string &strDestName,DWORD &DestAttr,int Append) string &strDestName,DWORD &DestAttr,int Append, error_state& ErrorState)
{ {
if ((Flags&FCOPY_LINK)) if ((Flags&FCOPY_LINK))
{ {
Expand Down Expand Up @@ -2859,8 +2865,9 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
size_t BytesRead; size_t BytesRead;
while (!SrcFile.Read(CopyBuffer.get(), SrcFile.GetChunkSize(), BytesRead)) while (!SrcFile.Read(CopyBuffer.get(), SrcFile.GetChunkSize(), BytesRead))
{ {
Global->CatchError(); ErrorState = error_state::fetch();
const int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE,
const int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCopyReadError), msg(lng::MCopyReadError),
Expand All @@ -2870,7 +2877,6 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
if (!MsgCode) if (!MsgCode)
continue; continue;


DWORD LastError=GetLastError();
SrcFile.Close(); SrcFile.Close();


if (!(Flags&FCOPY_COPYTONUL)) if (!(Flags&FCOPY_COPYTONUL))
Expand All @@ -2891,8 +2897,6 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
} }


CP->SetProgressValue(0,0); CP->SetProgressValue(0,0);
SetLastError(LastError);
Global->CatchError();
CP->m_Bytes.CurrCopied = 0; // Сбросить текущий прогресс CP->m_Bytes.CurrCopied = 0; // Сбросить текущий прогресс
return COPY_FAILURE; return COPY_FAILURE;
} }
Expand All @@ -2907,11 +2911,11 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
DestFile.SetPointer(SrcFile.GetChunkOffset() + (Append? AppendPos : 0), nullptr, FILE_BEGIN); DestFile.SetPointer(SrcFile.GetChunkOffset() + (Append? AppendPos : 0), nullptr, FILE_BEGIN);
while (!DestFile.Write(CopyBuffer.get(), BytesRead)) while (!DestFile.Write(CopyBuffer.get(), BytesRead))
{ {
DWORD LastError=GetLastError(); ErrorState = error_state::fetch();
Global->CatchError();
int Split=FALSE,SplitCancelled=FALSE,SplitSkipped=FALSE; int Split=FALSE,SplitCancelled=FALSE,SplitSkipped=FALSE;


if ((LastError==ERROR_DISK_FULL || LastError==ERROR_HANDLE_DISK_FULL) && if ((ErrorState.Win32Error == ERROR_DISK_FULL || ErrorState.Win32Error == ERROR_HANDLE_DISK_FULL) &&
strDestName.size() > 1 && strDestName[1]==L':') strDestName.size() > 1 && strDestName[1]==L':')
{ {
const auto strDriveRoot = GetPathRoot(strDestName); const auto strDriveRoot = GetPathRoot(strDestName);
Expand All @@ -2924,7 +2928,7 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
SrcFile.SetPointer(FreeSize-BytesRead,nullptr,FILE_CURRENT)) SrcFile.SetPointer(FreeSize-BytesRead,nullptr,FILE_CURRENT))
{ {
DestFile.Close(); DestFile.Close();
int MsgCode=Message(MSG_WARNING | MSG_ERRORTYPE, int MsgCode=Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
strDestName strDestName
Expand Down Expand Up @@ -3027,7 +3031,7 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
else else
{ {
if (!SplitCancelled && !SplitSkipped && if (!SplitCancelled && !SplitSkipped &&
Message(MSG_WARNING | MSG_ERRORTYPE, Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCopyWriteError), msg(lng::MCopyWriteError),
Expand Down Expand Up @@ -3055,7 +3059,6 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
} }


CP->SetProgressValue(0,0); CP->SetProgressValue(0,0);
SetLastError(LastError);


if (SplitSkipped) if (SplitSkipped)
return COPY_SKIPPED; return COPY_SKIPPED;
Expand Down Expand Up @@ -3541,8 +3544,9 @@ bool ShellCopy::GetSecurity(const string& FileName, os::fs::security_descriptor&
if (SkipSecurityErrors) if (SkipSecurityErrors)
return true; return true;


Global->CatchError(); const auto ErrorState = error_state::fetch();
switch (Message(MSG_WARNING | MSG_ERRORTYPE,
switch (Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCannotGetSecurity), msg(lng::MCannotGetSecurity),
Expand Down Expand Up @@ -3570,8 +3574,9 @@ bool ShellCopy::SetSecurity(const string& FileName, const os::fs::security_descr
if (SkipSecurityErrors) if (SkipSecurityErrors)
return true; return true;


Global->CatchError(); const auto ErrorState = error_state::fetch();
switch (Message(MSG_WARNING | MSG_ERRORTYPE,
switch (Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(lng::MCannotSetSecurity), msg(lng::MCannotSetSecurity),
Expand Down
4 changes: 3 additions & 1 deletion far/copy.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Dialog;
class copy_progress; class copy_progress;
class FileFilter; class FileFilter;


struct error_state;

enum COPY_CODES: int; enum COPY_CODES: int;
enum ReparsePointTypes: int; enum ReparsePointTypes: int;
enum class panel_mode; enum class panel_mode;
Expand All @@ -57,7 +59,7 @@ class ShellCopy: noncopyable
COPY_CODES CopyFileTree(const string& Dest); COPY_CODES CopyFileTree(const string& Dest);
COPY_CODES ShellCopyOneFile(const string& Src, const os::fs::find_data &SrcData, string &strDest, int KeepPathPos, int Rename); COPY_CODES ShellCopyOneFile(const string& Src, const os::fs::find_data &SrcData, string &strDest, int KeepPathPos, int Rename);
COPY_CODES CheckStreams(const string& Src,const string& DestPath); COPY_CODES CheckStreams(const string& Src,const string& DestPath);
int ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcData, string &strDestName,DWORD &DestAttr,int Append); int ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcData, string &strDestName,DWORD &DestAttr,int Append, error_state& ErrorState);
int ShellSystemCopy(const string& SrcName,const string& DestName,const os::fs::find_data &SrcData); int ShellSystemCopy(const string& SrcName,const string& DestName,const os::fs::find_data &SrcData);
int DeleteAfterMove(const string& Name,DWORD Attr); int DeleteAfterMove(const string& Name,DWORD Attr);
bool AskOverwrite(const os::fs::find_data &SrcData,const string& SrcName,const string& DestName, DWORD DestAttr,int SameName,int Rename,int AskAppend, int &Append,string &strNewName,int &RetCode); bool AskOverwrite(const os::fs::find_data &SrcData,const string& SrcName,const string& DestName, DWORD DestAttr,int SameName,int Rename,int AskAppend, int &Append,string &strNewName,int &RetCode);
Expand Down
15 changes: 9 additions & 6 deletions far/delete.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -986,8 +986,9 @@ DEL_RESULT ShellDelete::ShellRemoveFile(const string& Name, bool Wipe, int Total
MsgCode = static_cast<operation>(m_SkipMode); MsgCode = static_cast<operation>(m_SkipMode);
else else
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();
MsgCode = OperationFailed(strFullName, lng::MError, msg(recycle_bin ? lng::MCannotRecycleFile : lng::MCannotDeleteFile));
MsgCode = OperationFailed(ErrorState, strFullName, lng::MError, msg(recycle_bin ? lng::MCannotRecycleFile : lng::MCannotDeleteFile));
} }


switch (static_cast<operation>(MsgCode)) switch (static_cast<operation>(MsgCode))
Expand Down Expand Up @@ -1051,8 +1052,9 @@ DEL_RESULT ShellDelete::ERemoveDirectory(const string& Name,DIRDELTYPE Type)
} }
else else
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();
MsgCode = OperationFailed(Name, lng::MError, msg(recycle_bin? lng::MCannotRecycleFolder : lng::MCannotDeleteFolder));
MsgCode = OperationFailed(ErrorState, Name, lng::MError, msg(recycle_bin? lng::MCannotRecycleFolder : lng::MCannotDeleteFolder));
} }


switch (MsgCode) switch (MsgCode)
Expand Down Expand Up @@ -1136,11 +1138,12 @@ bool ShellDelete::RemoveToRecycleBin(const string& Name, bool dir, DEL_RESULT& r
DWORD dwe = GetLastError(); // probably bad path to recycle bin DWORD dwe = GetLastError(); // probably bad path to recycle bin
if (ERROR_BAD_PATHNAME == dwe || ERROR_FILE_NOT_FOUND == dwe || (dir && ERROR_PATH_NOT_FOUND==dwe)) if (ERROR_BAD_PATHNAME == dwe || ERROR_FILE_NOT_FOUND == dwe || (dir && ERROR_PATH_NOT_FOUND==dwe))
{ {
Global->CatchError(); const auto ErrorState = error_state::fetch();

string qName(strFullName); string qName(strFullName);
QuoteOuterSpace(qName); QuoteOuterSpace(qName);


int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE, int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
msg(dir? lng::MCannotRecycleFolder : lng::MCannotRecycleFile), msg(dir? lng::MCannotRecycleFolder : lng::MCannotRecycleFile),
Expand Down
10 changes: 5 additions & 5 deletions far/dirmix.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ int TestFolder(const string& Path)
return TSTFLD_NOTEMPTY; return TSTFLD_NOTEMPTY;
} }


Global->CatchError(); const auto ErrorState = error_state::fetch();
const auto LastError = Global->CaughtError().Win32Error; const auto LastError = ErrorState.Win32Error;
if (LastError == ERROR_FILE_NOT_FOUND || LastError == ERROR_NO_MORE_FILES) if (LastError == ERROR_FILE_NOT_FOUND || LastError == ERROR_NO_MORE_FILES)
return TSTFLD_EMPTY; return TSTFLD_EMPTY;


Expand Down Expand Up @@ -190,15 +190,15 @@ bool CheckShortcutFolder(string& pTestPath, bool TryClosest, bool Silent)
if (!Result) if (!Result)
{ {
SetLastError(ERROR_PATH_NOT_FOUND); SetLastError(ERROR_PATH_NOT_FOUND);
Global->CatchError(); const auto ErrorState = error_state::fetch();


string strTarget = pTestPath; string strTarget = pTestPath;
TruncPathStr(strTarget, ScrX-16); TruncPathStr(strTarget, ScrX-16);


if (!TryClosest) if (!TryClosest)
{ {
if (!Silent) if (!Silent)
Message(MSG_WARNING | MSG_ERRORTYPE, Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
strTarget strTarget
Expand All @@ -207,7 +207,7 @@ bool CheckShortcutFolder(string& pTestPath, bool TryClosest, bool Silent)
} }
else // попытка найти! else // попытка найти!
{ {
if (Silent || Message(MSG_WARNING | MSG_ERRORTYPE, if (Silent || Message(MSG_WARNING, ErrorState,
msg(lng::MError), msg(lng::MError),
{ {
strTarget, strTarget,
Expand Down
Loading

0 comments on commit 13d4615

Please sign in to comment.