Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2009-08-17 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:16:00 +0300
commitc99f3ebdd639c2adb03d8b44001b10af18516504 (patch)
tree92aaf34e5edbd7287c3f55037190da75ab0a8000 /CPP/7zip/UI/FileManager/PanelCrc.cpp
parent829409452d85cd6dd9dfc9151f109d6e13a2bb1c (diff)
9.06 beta
Diffstat (limited to 'CPP/7zip/UI/FileManager/PanelCrc.cpp')
-rwxr-xr-xCPP/7zip/UI/FileManager/PanelCrc.cpp437
1 files changed, 187 insertions, 250 deletions
diff --git a/CPP/7zip/UI/FileManager/PanelCrc.cpp b/CPP/7zip/UI/FileManager/PanelCrc.cpp
index aaa645cf..6b00a9b5 100755
--- a/CPP/7zip/UI/FileManager/PanelCrc.cpp
+++ b/CPP/7zip/UI/FileManager/PanelCrc.cpp
@@ -3,19 +3,15 @@
#include "StdAfx.h"
#include "../../../../C/7zCrc.h"
-#include "../../../../C/Alloc.h"
#include "../../../../C/Sha256.h"
#include "Common/IntToString.h"
-#include "Windows/Error.h"
#include "Windows/FileFind.h"
#include "Windows/FileIO.h"
#include "Windows/FileName.h"
-#include "Windows/Thread.h"
#include "OverwriteDialogRes.h"
-#include "ProgressDialog2.h"
#include "App.h"
#include "FormatUtils.h"
@@ -27,7 +23,6 @@
using namespace NWindows;
using namespace NFile;
-using namespace NName;
static const UInt32 kBufSize = (1 << 15);
@@ -40,7 +35,7 @@ struct CDirEnumerator
CObjectVector<NFind::CEnumeratorW> Enumerators;
UStringVector Prefixes;
int Index;
- bool GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UString &fullPath, DWORD &errorCode);
+ HRESULT GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UString &fullPath);
void Init();
CDirEnumerator(): FlatMode(false) {};
@@ -53,7 +48,13 @@ void CDirEnumerator::Init()
Index = 0;
}
-bool CDirEnumerator::GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UString &resPath, DWORD &errorCode)
+static HRESULT GetNormalizedError()
+{
+ HRESULT errorCode = GetLastError();
+ return (errorCode == 0) ? E_FAIL : errorCode;
+}
+
+HRESULT CDirEnumerator::GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UString &resPath)
{
filled = false;
for (;;)
@@ -61,7 +62,7 @@ bool CDirEnumerator::GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UStr
if (Enumerators.IsEmpty())
{
if (Index >= FileNames.Size())
- return true;
+ return S_OK;
const UString &path = FileNames[Index];
int pos = path.ReverseFind(WCHAR_PATH_SEPARATOR);
resPath.Empty();
@@ -80,9 +81,9 @@ bool CDirEnumerator::GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UStr
#endif
if (!fileInfo.Find(BasePrefix + path))
{
- errorCode = ::GetLastError();
+ WRes errorCode = GetNormalizedError();
resPath = path;
- return false;
+ return errorCode;
}
Index++;
break;
@@ -90,9 +91,9 @@ bool CDirEnumerator::GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UStr
bool found;
if (!Enumerators.Back().Next(fileInfo, found))
{
- errorCode = ::GetLastError();
+ HRESULT errorCode = GetNormalizedError();
resPath = Prefixes.Back();
- return false;
+ return errorCode;
}
if (found)
{
@@ -105,36 +106,26 @@ bool CDirEnumerator::GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UStr
resPath += fileInfo.Name;
if (!FlatMode && fileInfo.IsDir())
{
- UString prefix = resPath + (UString)(wchar_t)kDirDelimiter;
- Enumerators.Add(NFind::CEnumeratorW(BasePrefix + prefix + (UString)(wchar_t)kAnyStringWildcard));
+ UString prefix = resPath + WCHAR_PATH_SEPARATOR;
+ Enumerators.Add(NFind::CEnumeratorW(BasePrefix + prefix + (UString)(wchar_t)NName::kAnyStringWildcard));
Prefixes.Add(prefix);
}
filled = true;
- return true;
+ return S_OK;
}
-struct CThreadCrc
+static void ConvertByteToHex(unsigned value, wchar_t *s)
{
- class CMyBuffer
+ for (int i = 0; i < 2; i++)
{
- void *_data;
- public:
- CMyBuffer(): _data(0) {}
- operator void *() { return _data; }
- bool Allocate(size_t size)
- {
- if (_data != 0)
- return false;
- _data = ::MidAlloc(size);
- return _data != 0;
- }
- ~CMyBuffer() { ::MidFree(_data); }
- };
-
- CProgressDialog *ProgressDialog;
+ unsigned t = value & 0xF;
+ value >>= 4;
+ s[1 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));
+ }
+}
- CDirEnumerator DirEnumerator;
-
+class CThreadCrc: public CProgressThreadVirt
+{
UInt64 NumFilesScan;
UInt64 NumFiles;
UInt64 NumFolders;
@@ -143,155 +134,176 @@ struct CThreadCrc
Byte Sha256Sum[SHA256_DIGEST_SIZE];
UInt32 DataNameCrcSum;
- HRESULT Result;
- DWORD ErrorCode;
- UString ErrorPath;
- UString Error;
- bool ThereIsError;
+ UString GetResultMessage() const;
+ HRESULT ProcessVirt();
+public:
+ CDirEnumerator Enumerator;
+
+};
+
+UString CThreadCrc::GetResultMessage() const
+{
+ UString s;
+ wchar_t sz[32];
+
+ s += LangString(IDS_FILES_COLON, 0x02000320);
+ s += L' ';
+ ConvertUInt64ToString(NumFiles, sz);
+ s += sz;
+ s += L'\n';
+
+ s += LangString(IDS_FOLDERS_COLON, 0x02000321);
+ s += L' ';
+ ConvertUInt64ToString(NumFolders, sz);
+ s += sz;
+ s += L'\n';
- void Process2()
+ s += LangString(IDS_SIZE_COLON, 0x02000322);
+ s += L' ';
+ ConvertUInt64ToString(DataSize, sz);
+ s += MyFormatNew(IDS_FILE_SIZE, 0x02000982, sz);
+ s += L'\n';
+
+ s += LangString(IDS_CHECKSUM_CRC_DATA, 0x03020721);
+ s += L' ';
+ ConvertUInt32ToHex(DataCrcSum, sz);
+ s += sz;
+ s += L'\n';
+
+ s += LangString(IDS_CHECKSUM_CRC_DATA_NAMES, 0x03020722);
+ s += L' ';
+ ConvertUInt32ToHex(DataNameCrcSum, sz);
+ s += sz;
+ s += L'\n';
+
+ if (NumFiles == 1 && NumFilesScan == 1)
{
- DataSize = NumFolders = NumFiles = NumFilesScan = DataCrcSum = DataNameCrcSum = 0;
- memset(Sha256Sum, 0, SHA256_DIGEST_SIZE);
- ProgressDialog->WaitCreating();
-
- CMyBuffer bufferObject;
- if (!bufferObject.Allocate(kBufSize))
+ s += L"SHA-256: ";
+ for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
{
- Error = L"Can not allocate memory";
- ThereIsError = true;
- return;
+ wchar_t s2[4];
+ ConvertByteToHex(Sha256Sum[i], s2);
+ s2[2] = 0;
+ s += s2;
}
- Byte *buffer = (Byte *)(void *)bufferObject;
-
- UInt64 totalSize = 0;
-
- DirEnumerator.Init();
+ }
+ return s;
+}
- UString scanningStr = LangString(IDS_SCANNING, 0x03020800);
- scanningStr += L" ";
+HRESULT CThreadCrc::ProcessVirt()
+{
+ DataSize = NumFolders = NumFiles = NumFilesScan = DataCrcSum = DataNameCrcSum = 0;
+ memset(Sha256Sum, 0, SHA256_DIGEST_SIZE);
+ // ProgressDialog.WaitCreating();
+
+ CMyBuffer bufferObject;
+ if (!bufferObject.Allocate(kBufSize))
+ return E_OUTOFMEMORY;
+ Byte *buffer = (Byte *)(void *)bufferObject;
+
+ UInt64 totalSize = 0;
+
+ Enumerator.Init();
+
+ UString scanningStr = LangString(IDS_SCANNING, 0x03020800);
+ scanningStr += L' ';
+
+ CProgressSync &sync = ProgressDialog.Sync;
- for (;;)
+ for (;;)
+ {
+ NFind::CFileInfoW fileInfo;
+ bool filled;
+ UString resPath;
+ HRESULT errorCode = Enumerator.GetNextFile(fileInfo, filled, resPath);
+ if (errorCode != 0)
{
- NFile::NFind::CFileInfoW fileInfo;
- bool filled;
- UString resPath;
- if (!DirEnumerator.GetNextFile(fileInfo, filled, resPath, ErrorCode))
- {
- ThereIsError = true;
- ErrorPath = resPath;
- return;
- }
- if (!filled)
- break;
- if (!fileInfo.IsDir())
- {
- totalSize += fileInfo.Size;
- NumFilesScan++;
- }
- ProgressDialog->ProgressSynch.SetCurrentFileName(scanningStr + resPath);
- ProgressDialog->ProgressSynch.SetProgress(totalSize, 0);
- Result = ProgressDialog->ProgressSynch.SetPosAndCheckPaused(0);
- if (Result != S_OK)
- return;
+ ErrorPath1 = resPath;
+ return errorCode;
}
- ProgressDialog->ProgressSynch.SetNumFilesTotal(NumFilesScan);
- ProgressDialog->ProgressSynch.SetProgress(totalSize, 0);
-
- DirEnumerator.Init();
-
- for (;;)
+ if (!filled)
+ break;
+ if (!fileInfo.IsDir())
+ {
+ totalSize += fileInfo.Size;
+ NumFilesScan++;
+ }
+ sync.SetCurrentFileName(scanningStr + resPath);
+ sync.SetProgress(totalSize, 0);
+ RINOK(sync.SetPosAndCheckPaused(0));
+ }
+ sync.SetNumFilesTotal(NumFilesScan);
+ sync.SetProgress(totalSize, 0);
+
+ Enumerator.Init();
+
+ for (;;)
+ {
+ NFind::CFileInfoW fileInfo;
+ bool filled;
+ UString resPath;
+ HRESULT errorCode = Enumerator.GetNextFile(fileInfo, filled, resPath);
+ if (errorCode != 0)
{
- NFile::NFind::CFileInfoW fileInfo;
- bool filled;
- UString resPath;
- if (!DirEnumerator.GetNextFile(fileInfo, filled, resPath, ErrorCode))
+ ErrorPath1 = resPath;
+ return errorCode;
+ }
+ if (!filled)
+ break;
+
+ UInt32 crc = CRC_INIT_VAL;
+ CSha256 sha256;
+ Sha256_Init(&sha256);
+
+ if (fileInfo.IsDir())
+ NumFolders++;
+ else
+ {
+ NIO::CInFile inFile;
+ if (!inFile.Open(Enumerator.BasePrefix + resPath))
{
- ThereIsError = true;
- ErrorPath = resPath;
- return;
+ errorCode = GetNormalizedError();
+ ErrorPath1 = resPath;
+ return errorCode;
}
- if (!filled)
- break;
-
- UInt32 crc = CRC_INIT_VAL;
- CSha256 sha256;
- Sha256_Init(&sha256);
-
- if (fileInfo.IsDir())
- NumFolders++;
- else
+ sync.SetCurrentFileName(resPath);
+ sync.SetNumFilesCur(NumFiles);
+ NumFiles++;
+ for (;;)
{
- NFile::NIO::CInFile inFile;
- if (!inFile.Open(DirEnumerator.BasePrefix + resPath))
+ UInt32 processedSize;
+ if (!inFile.Read(buffer, kBufSize, processedSize))
{
- ErrorCode = ::GetLastError();
- ThereIsError = true;
- ErrorPath = resPath;
- return;
+ errorCode = GetNormalizedError();
+ ErrorPath1 = resPath;
+ return errorCode;
}
- ProgressDialog->ProgressSynch.SetCurrentFileName(resPath);
- ProgressDialog->ProgressSynch.SetNumFilesCur(NumFiles);
- NumFiles++;
- for (;;)
- {
- UInt32 processedSize;
- if (!inFile.Read(buffer, kBufSize, processedSize))
- {
- ErrorCode = ::GetLastError();
- ThereIsError = true;
- ErrorPath = resPath;
- return;
- }
- if (processedSize == 0)
- break;
- crc = CrcUpdate(crc, buffer, processedSize);
- if (NumFilesScan == 1)
- Sha256_Update(&sha256, buffer, processedSize);
-
- DataSize += processedSize;
- Result = ProgressDialog->ProgressSynch.SetPosAndCheckPaused(DataSize);
- if (Result != S_OK)
- return;
- }
- DataCrcSum += CRC_GET_DIGEST(crc);
+ if (processedSize == 0)
+ break;
+ crc = CrcUpdate(crc, buffer, processedSize);
if (NumFilesScan == 1)
- Sha256_Final(&sha256, Sha256Sum);
- }
- for (int i = 0; i < resPath.Length(); i++)
- {
- wchar_t c = resPath[i];
- crc = CRC_UPDATE_BYTE(crc, ((Byte)(c & 0xFF)));
- crc = CRC_UPDATE_BYTE(crc, ((Byte)((c >> 8) & 0xFF)));
+ Sha256_Update(&sha256, buffer, processedSize);
+
+ DataSize += processedSize;
+ RINOK(sync.SetPosAndCheckPaused(DataSize));
}
- DataNameCrcSum += CRC_GET_DIGEST(crc);
- Result = ProgressDialog->ProgressSynch.SetPosAndCheckPaused(DataSize);
- if (Result != S_OK)
- return;
+ DataCrcSum += CRC_GET_DIGEST(crc);
+ if (NumFilesScan == 1)
+ Sha256_Final(&sha256, Sha256Sum);
}
+ for (int i = 0; i < resPath.Length(); i++)
+ {
+ wchar_t c = resPath[i];
+ crc = CRC_UPDATE_BYTE(crc, ((Byte)(c & 0xFF)));
+ crc = CRC_UPDATE_BYTE(crc, ((Byte)((c >> 8) & 0xFF)));
+ }
+ DataNameCrcSum += CRC_GET_DIGEST(crc);
+ RINOK(sync.SetPosAndCheckPaused(DataSize));
}
- DWORD Process()
- {
- try { Process2(); }
- catch(...) { Error = L"Error"; ThereIsError = true;}
- ProgressDialog->MyClose();
- return 0;
- }
-
- static THREAD_FUNC_DECL MyThreadFunction(void *param)
- {
- return ((CThreadCrc *)param)->Process();
- }
-};
-
-static void ConvertByteToHex(unsigned value, wchar_t *s)
-{
- for (int i = 0; i < 2; i++)
- {
- unsigned t = value & 0xF;
- value >>= 4;
- s[1 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));
- }
+ sync.SetNumFilesCur(NumFiles);
+ OkMessage = GetResultMessage();
+ OkMessageTitle = LangString(IDS_CHECKSUM_INFORMATION, 0x03020720);
+ return S_OK;
}
void CApp::CalculateCrc()
@@ -308,98 +320,23 @@ void CApp::CalculateCrc()
if (indices.IsEmpty())
return;
- CThreadCrc combiner;
+ {
+ CThreadCrc t;
for (int i = 0; i < indices.Size(); i++)
- combiner.DirEnumerator.FileNames.Add(srcPanel.GetItemRelPath(indices[i]));
- combiner.DirEnumerator.BasePrefix = srcPanel.GetFsPath();
- combiner.DirEnumerator.FlatMode = GetFlatMode();
+ t.Enumerator.FileNames.Add(srcPanel.GetItemRelPath(indices[i]));
+ t.Enumerator.BasePrefix = srcPanel.GetFsPath();
+ t.Enumerator.FlatMode = GetFlatMode();
- {
- CProgressDialog progressDialog;
- combiner.ProgressDialog = &progressDialog;
- combiner.ErrorCode = 0;
- combiner.Result = S_OK;
- combiner.ThereIsError = false;
+ t.ProgressDialog.ShowCompressionInfo = false;
- UString progressWindowTitle = LangString(IDS_APP_TITLE, 0x03000000);
UString title = LangString(IDS_CHECKSUM_CALCULATING, 0x03020710);
- progressDialog.MainWindow = _window;
- progressDialog.MainTitle = progressWindowTitle;
- progressDialog.MainAddTitle = title + UString(L" ");
+ t.ProgressDialog.MainWindow = _window;
+ t.ProgressDialog.MainTitle = LangString(IDS_APP_TITLE, 0x03000000);
+ t.ProgressDialog.MainAddTitle = title + UString(L' ');
- NWindows::CThread thread;
- if (thread.Create(CThreadCrc::MyThreadFunction, &combiner) != S_OK)
+ if (t.Create(title, _window) != S_OK)
return;
- progressDialog.Create(title, _window);
-
- if (combiner.Result != S_OK)
- {
- if (combiner.Result != E_ABORT)
- srcPanel.MessageBoxError(combiner.Result);
- }
- else if (combiner.ThereIsError)
- {
- if (combiner.Error.IsEmpty())
- {
- UString message = combiner.DirEnumerator.BasePrefix + combiner.ErrorPath;
- message += L"\n";
- message += NError::MyFormatMessageW(combiner.ErrorCode);
- srcPanel.MessageBoxMyError(message);
- }
- else
- srcPanel.MessageBoxMyError(combiner.Error);
- }
- else
- {
- UString s;
- {
- wchar_t sz[32];
-
- s += LangString(IDS_FILES_COLON, 0x02000320);
- s += L" ";
- ConvertUInt64ToString(combiner.NumFiles, sz);
- s += sz;
- s += L"\n";
-
- s += LangString(IDS_FOLDERS_COLON, 0x02000321);
- s += L" ";
- ConvertUInt64ToString(combiner.NumFolders, sz);
- s += sz;
- s += L"\n";
-
- s += LangString(IDS_SIZE_COLON, 0x02000322);
- s += L" ";
- ConvertUInt64ToString(combiner.DataSize, sz);
- s += MyFormatNew(IDS_FILE_SIZE, 0x02000982, sz);;
- s += L"\n";
-
- s += LangString(IDS_CHECKSUM_CRC_DATA, 0x03020721);
- s += L" ";
- ConvertUInt32ToHex(combiner.DataCrcSum, sz);
- s += sz;
- s += L"\n";
-
- s += LangString(IDS_CHECKSUM_CRC_DATA_NAMES, 0x03020722);
- s += L" ";
- ConvertUInt32ToHex(combiner.DataNameCrcSum, sz);
- s += sz;
- s += L"\n";
-
- if (combiner.NumFiles == 1 && combiner.NumFilesScan == 1)
- {
- s += L"SHA-256: ";
- for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
- {
- wchar_t s2[4];
- ConvertByteToHex(combiner.Sha256Sum[i], s2);
- s2[2] = 0;
- s += s2;
- }
- }
- }
- srcPanel.MessageBoxInfo(s, LangString(IDS_CHECKSUM_INFORMATION, 0x03020720));
- }
}
RefreshTitleAlways();
}