Skip to content
Permalink
Browse files

More of 3503: pass lasterror to Message directly, not via globals

  • Loading branch information...
alabuzhev committed Oct 25, 2017
1 parent 2c364ae commit 13d4615b0e90e8337d12c3b0fe3c91b0093db18d
@@ -207,9 +207,9 @@ class oem_plugin_factory: public native_plugin_factory
auto Module = std::make_unique<oem_plugin_module>(filename);
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::MPlgLoadPluginError),
@@ -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

1. Группы сортировки работают только в режимах по имени и расширению, как раньше.
@@ -1281,15 +1281,17 @@ bool CommandLine::IntChDir(const string& CmdLine,int ClosePanel,bool Selent)
}
else
{
Global->CatchError();
if (!Selent)
Message(MSG_WARNING | MSG_ERRORTYPE,
{
const auto ErrorState = error_state::fetch();

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

}
return false;
}

@@ -1398,7 +1398,7 @@ COPY_CODES ShellCopy::CopyFileTree(const string& Dest)
&& !IsSlash(strDest.back())
&& !os::fs::exists(strDest))
{
switch (Message(FMSG_WARNING,
switch (Message(MSG_WARNING,
msg(lng::MWarning),
{
strDest,
@@ -1426,8 +1426,9 @@ COPY_CODES ShellCopy::CopyFileTree(const string& Dest)
auto Exists_2 = Exists_1;
while ( !Exists_2 && SkipMode != 2)
{
Global->CatchError();
const auto Result = OperationFailed(strDestDriveRoot, lng::MError, L"");
const auto ErrorState = error_state::fetch();

const auto Result = OperationFailed(ErrorState, strDestDriveRoot, lng::MError, L"");
if (Result == operation::retry)
{
continue;
@@ -1978,8 +1979,9 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
}
else
{
Global->CatchError();
int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE,
const auto ErrorState = error_state::fetch();

int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(lng::MCopyCannotRenameFolder),
@@ -2031,8 +2033,8 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
SrcData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && Flags & FCOPY_COPYSYMLINKCONTENTS? L""s : Src,
strDestPath, Flags & FCOPY_COPYSECURITY? &SecAttr : nullptr))
{
Global->CatchError();
const int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE,
const auto ErrorState = error_state::fetch();
const int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(lng::MCopyCannotCreateFolder),
@@ -2100,8 +2102,8 @@ COPY_CODES ShellCopy::ShellCopyOneFile(

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

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

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

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

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

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

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

@@ -2438,10 +2439,10 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
//if (GetLastError() == ERROR_ACCESS_DENIED)
{
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(MsgMCannot),
@@ -2478,8 +2479,10 @@ COPY_CODES ShellCopy::ShellCopyOneFile(
MsgCode=SkipMode;
else
{
Global->CatchError();
MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE,
if (!ErrorState.engaged())
ErrorState = error_state::fetch();

MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(MsgMCannot),
@@ -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))
{
Global->CatchError();
operation MsgCode;

if (SkipDeleteMode!=-1)
MsgCode = static_cast<operation>(SkipDeleteMode);
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)
{
@@ -2645,7 +2651,7 @@ int ShellCopy::DeleteAfterMove(const string& Name,DWORD Attr)


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))
{
@@ -2859,8 +2865,9 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
size_t BytesRead;
while (!SrcFile.Read(CopyBuffer.get(), SrcFile.GetChunkSize(), BytesRead))
{
Global->CatchError();
const int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE,
ErrorState = error_state::fetch();

const int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(lng::MCopyReadError),
@@ -2870,7 +2877,6 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
if (!MsgCode)
continue;

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

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

CP->SetProgressValue(0,0);
SetLastError(LastError);
Global->CatchError();
CP->m_Bytes.CurrCopied = 0; // Сбросить текущий прогресс
return COPY_FAILURE;
}
@@ -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);
while (!DestFile.Write(CopyBuffer.get(), BytesRead))
{
DWORD LastError=GetLastError();
Global->CatchError();
ErrorState = error_state::fetch();

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':')
{
const auto strDriveRoot = GetPathRoot(strDestName);
@@ -2924,7 +2928,7 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
SrcFile.SetPointer(FreeSize-BytesRead,nullptr,FILE_CURRENT))
{
DestFile.Close();
int MsgCode=Message(MSG_WARNING | MSG_ERRORTYPE,
int MsgCode=Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
strDestName
@@ -3027,7 +3031,7 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
else
{
if (!SplitCancelled && !SplitSkipped &&
Message(MSG_WARNING | MSG_ERRORTYPE,
Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(lng::MCopyWriteError),
@@ -3055,7 +3059,6 @@ int ShellCopy::ShellCopyFile(const string& SrcName,const os::fs::find_data &SrcD
}

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

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

Global->CatchError();
switch (Message(MSG_WARNING | MSG_ERRORTYPE,
const auto ErrorState = error_state::fetch();

switch (Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(lng::MCannotGetSecurity),
@@ -3570,8 +3574,9 @@ bool ShellCopy::SetSecurity(const string& FileName, const os::fs::security_descr
if (SkipSecurityErrors)
return true;

Global->CatchError();
switch (Message(MSG_WARNING | MSG_ERRORTYPE,
const auto ErrorState = error_state::fetch();

switch (Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(lng::MCannotSetSecurity),
@@ -42,6 +42,8 @@ class Dialog;
class copy_progress;
class FileFilter;

struct error_state;

enum COPY_CODES: int;
enum ReparsePointTypes: int;
enum class panel_mode;
@@ -57,7 +59,7 @@ class ShellCopy: noncopyable
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 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 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);
@@ -986,8 +986,9 @@ DEL_RESULT ShellDelete::ShellRemoveFile(const string& Name, bool Wipe, int Total
MsgCode = static_cast<operation>(m_SkipMode);
else
{
Global->CatchError();
MsgCode = OperationFailed(strFullName, lng::MError, msg(recycle_bin ? lng::MCannotRecycleFile : lng::MCannotDeleteFile));
const auto ErrorState = error_state::fetch();

MsgCode = OperationFailed(ErrorState, strFullName, lng::MError, msg(recycle_bin ? lng::MCannotRecycleFile : lng::MCannotDeleteFile));
}

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

MsgCode = OperationFailed(ErrorState, Name, lng::MError, msg(recycle_bin? lng::MCannotRecycleFolder : lng::MCannotDeleteFolder));
}

switch (MsgCode)
@@ -1136,11 +1138,12 @@ bool ShellDelete::RemoveToRecycleBin(const string& Name, bool dir, DEL_RESULT& r
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))
{
Global->CatchError();
const auto ErrorState = error_state::fetch();

string qName(strFullName);
QuoteOuterSpace(qName);

int MsgCode = Message(MSG_WARNING | MSG_ERRORTYPE,
int MsgCode = Message(MSG_WARNING, ErrorState,
msg(lng::MError),
{
msg(dir? lng::MCannotRecycleFolder : lng::MCannotRecycleFile),
@@ -139,8 +139,8 @@ int TestFolder(const string& Path)
return TSTFLD_NOTEMPTY;
}

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

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

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

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

0 comments on commit 13d4615

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