1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
|
/// PanelCopy.cpp
#include "StdAfx.h"
#include "../Common/ZipRegistry.h"
#include "../GUI/HashGUI.h"
#include "FSFolder.h"
#include "ExtractCallback.h"
#include "LangUtils.h"
#include "Panel.h"
#include "UpdateCallback100.h"
#include "resource.h"
class CPanelCopyThread: public CProgressThreadVirt
{
bool ResultsWereShown;
bool NeedShowRes;
HRESULT ProcessVirt() Z7_override;
virtual void ProcessWasFinished_GuiVirt() Z7_override;
public:
const CCopyToOptions *options;
const UStringVector *CopyFrom_Paths;
CMyComPtr<IFolderOperations> FolderOperations;
CRecordVector<UInt32> Indices;
CExtractCallbackImp *ExtractCallbackSpec;
CMyComPtr<IFolderOperationsExtractCallback> ExtractCallback;
CHashBundle Hash;
// UString FirstFilePath;
// HRESULT Result2;
void ShowFinalResults(HWND hwnd);
CPanelCopyThread():
ResultsWereShown(false),
NeedShowRes(false),
CopyFrom_Paths(NULL)
// , Result2(E_FAIL)
{}
};
void CPanelCopyThread::ShowFinalResults(HWND hwnd)
{
if (NeedShowRes)
if (!ResultsWereShown)
{
ResultsWereShown = true;
ShowHashResults(Hash, hwnd);
}
}
void CPanelCopyThread::ProcessWasFinished_GuiVirt()
{
ShowFinalResults(*this);
}
HRESULT CPanelCopyThread::ProcessVirt()
{
/*
CMyComPtr<IFolderSetReplaceAltStreamCharsMode> iReplace;
FolderOperations.QueryInterface(IID_IFolderSetReplaceAltStreamCharsMode, &iReplace);
if (iReplace)
{
RINOK(iReplace->SetReplaceAltStreamCharsMode(ReplaceAltStreamChars ? 1 : 0));
}
*/
HRESULT result2;
if (FolderOperations)
{
{
CMyComPtr<IFolderSetZoneIdMode> setZoneMode;
FolderOperations.QueryInterface(IID_IFolderSetZoneIdMode, &setZoneMode);
if (setZoneMode)
{
RINOK(setZoneMode->SetZoneIdMode(options->ZoneIdMode))
}
}
{
CMyComPtr<IFolderSetZoneIdFile> setZoneFile;
FolderOperations.QueryInterface(IID_IFolderSetZoneIdFile, &setZoneFile);
if (setZoneFile)
{
RINOK(setZoneFile->SetZoneIdFile(options->ZoneBuf, (UInt32)options->ZoneBuf.Size()))
}
}
}
if (CopyFrom_Paths)
{
result2 = NFsFolder::CopyFileSystemItems(
*CopyFrom_Paths,
us2fs(options->folder),
options->moveMode,
(IFolderOperationsExtractCallback *)ExtractCallbackSpec);
}
else if (options->testMode)
{
CMyComPtr<IArchiveFolder> archiveFolder;
FolderOperations.QueryInterface(IID_IArchiveFolder, &archiveFolder);
if (!archiveFolder)
return E_NOTIMPL;
CMyComPtr<IFolderArchiveExtractCallback> extractCallback2;
RINOK(ExtractCallback.QueryInterface(IID_IFolderArchiveExtractCallback, &extractCallback2))
NExtract::NPathMode::EEnum pathMode =
NExtract::NPathMode::kCurPaths;
// NExtract::NPathMode::kFullPathnames;
result2 = archiveFolder->Extract(Indices.ConstData(), Indices.Size(),
BoolToInt(options->includeAltStreams),
BoolToInt(options->replaceAltStreamChars),
pathMode, NExtract::NOverwriteMode::kAsk,
options->folder, BoolToInt(true), extractCallback2);
}
else
result2 = FolderOperations->CopyTo(
BoolToInt(options->moveMode),
Indices.ConstData(), Indices.Size(),
BoolToInt(options->includeAltStreams),
BoolToInt(options->replaceAltStreamChars),
options->folder, ExtractCallback);
if (result2 == S_OK && !ExtractCallbackSpec->ThereAreMessageErrors)
{
if (!options->hashMethods.IsEmpty())
NeedShowRes = true;
else if (options->testMode)
{
CProgressMessageBoxPair &pair = GetMessagePair(false); // GetMessagePair(ExtractCallbackSpec->Hash.NumErrors != 0);
AddHashBundleRes(pair.Message, Hash);
}
}
return result2;
}
/*
#ifdef Z7_EXTERNAL_CODECS
static void ThrowException_if_Error(HRESULT res)
{
if (res != S_OK)
throw CSystemException(res);
}
#endif
*/
void CPanel::Get_ZoneId_Stream_from_ParentFolders(CByteBuffer &buf)
{
// we suppose that ZoneId of top parent has priority over ZoneId from childs.
FOR_VECTOR (i, _parentFolders)
{
// _parentFolders[0] = is top level archive
// _parentFolders[1 ... ].isVirtual == true is possible
// if extracted size meets size conditions derived from g_RAM_Size.
const CFolderLink &fl = _parentFolders[i];
if (fl.IsVirtual)
{
if (fl.ZoneBuf.Size() != 0)
{
buf = fl.ZoneBuf;
return;
}
}
else if (!fl.FilePath.IsEmpty())
{
ReadZoneFile_Of_BaseFile(fl.FilePath, buf);
if (buf.Size() != 0)
return;
}
}
}
HRESULT CPanel::CopyTo(CCopyToOptions &options,
const CRecordVector<UInt32> &indices,
UStringVector *messages,
bool &usePassword, UString &password,
const UStringVector *filePaths)
{
if (options.NeedRegistryZone && !options.testMode)
{
CContextMenuInfo ci;
ci.Load();
if (ci.WriteZone != (UInt32)(Int32)-1)
options.ZoneIdMode = (NExtract::NZoneIdMode::EEnum)(int)(Int32)ci.WriteZone;
}
if (options.ZoneBuf.Size() == 0
&& options.ZoneIdMode != NExtract::NZoneIdMode::kNone)
Get_ZoneId_Stream_from_ParentFolders(options.ZoneBuf);
if (IsHashFolder())
{
if (!options.testMode)
return E_NOTIMPL;
}
if (!filePaths)
if (!_folderOperations)
{
const UString errorMessage = LangString(IDS_OPERATION_IS_NOT_SUPPORTED);
if (options.showErrorMessages)
MessageBox_Error(errorMessage);
else if (messages)
messages->Add(errorMessage);
return E_FAIL;
}
HRESULT res = S_OK;
{
/*
#ifdef Z7_EXTERNAL_CODECS
CExternalCodecs g_ExternalCodecs;
#endif
*/
/* extracter.Hash uses g_ExternalCodecs
extracter must be declared after g_ExternalCodecs for correct destructor order !!! */
CPanelCopyThread extracter;
extracter.ExtractCallbackSpec = new CExtractCallbackImp;
extracter.ExtractCallback = extracter.ExtractCallbackSpec;
extracter.ExtractCallbackSpec->Src_Is_IO_FS_Folder =
IsFSFolder() || IsAltStreamsFolder();
// options.src_Is_IO_FS_Folder;
extracter.options = &options;
extracter.ExtractCallbackSpec->ProgressDialog = &extracter;
extracter.CompressingMode = false;
extracter.ExtractCallbackSpec->StreamMode = options.streamMode;
if (indices.Size() == 1)
{
extracter.Hash.FirstFileName = GetItemRelPath(indices[0]);
extracter.Hash.MainName = extracter.Hash.FirstFileName;
}
if (options.VirtFileSystemSpec)
{
extracter.ExtractCallbackSpec->VirtFileSystem = options.VirtFileSystemSpec;
extracter.ExtractCallbackSpec->VirtFileSystemSpec = options.VirtFileSystemSpec;
}
extracter.ExtractCallbackSpec->ProcessAltStreams = options.includeAltStreams;
if (!options.hashMethods.IsEmpty())
{
/* this code is used when we call CRC calculation for files in side archive
But new code uses global codecs so we don't need to call LoadGlobalCodecs again */
/*
#ifdef Z7_EXTERNAL_CODECS
ThrowException_if_Error(LoadGlobalCodecs());
#endif
*/
extracter.Hash.SetMethods(EXTERNAL_CODECS_VARS_G options.hashMethods);
extracter.ExtractCallbackSpec->SetHashMethods(&extracter.Hash);
}
else if (options.testMode)
{
extracter.ExtractCallbackSpec->SetHashCalc(&extracter.Hash);
}
// extracter.Hash.Init();
UString title;
{
UInt32 titleID = IDS_COPYING;
if (options.moveMode)
titleID = IDS_MOVING;
else if (!options.hashMethods.IsEmpty() && options.streamMode)
{
titleID = IDS_CHECKSUM_CALCULATING;
if (options.hashMethods.Size() == 1)
{
const UString &s = options.hashMethods[0];
if (s != L"*")
title = s;
}
}
else if (options.testMode)
titleID = IDS_PROGRESS_TESTING;
if (title.IsEmpty())
title = LangString(titleID);
}
const UString progressWindowTitle ("7-Zip"); // LangString(IDS_APP_TITLE);
extracter.MainWindow = GetParent();
extracter.MainTitle = progressWindowTitle;
extracter.MainAddTitle = title + L' ';
extracter.ExtractCallbackSpec->OverwriteMode = NExtract::NOverwriteMode::kAsk;
extracter.ExtractCallbackSpec->Init();
extracter.CopyFrom_Paths = filePaths;
if (!filePaths)
{
extracter.Indices = indices;
extracter.FolderOperations = _folderOperations;
}
extracter.ExtractCallbackSpec->PasswordIsDefined = usePassword;
extracter.ExtractCallbackSpec->Password = password;
RINOK(extracter.Create(title, GetParent()))
if (messages)
*messages = extracter.Sync.Messages;
// res = extracter.Result2;
res = extracter.Result;
if (res == S_OK && extracter.ExtractCallbackSpec->IsOK())
{
usePassword = extracter.ExtractCallbackSpec->PasswordIsDefined;
password = extracter.ExtractCallbackSpec->Password;
}
extracter.ShowFinalResults(_window);
}
RefreshTitleAlways();
return res;
}
struct CThreadUpdate
{
CMyComPtr<IFolderOperations> FolderOperations;
UString FolderPrefix;
UStringVector FileNames;
CRecordVector<const wchar_t *> FileNamePointers;
CProgressDialog ProgressDialog;
CMyComPtr<IFolderArchiveUpdateCallback> UpdateCallback;
CUpdateCallback100Imp *UpdateCallbackSpec;
HRESULT Result;
bool MoveMode;
void Process()
{
try
{
CProgressCloser closer(ProgressDialog);
Result = FolderOperations->CopyFrom(
MoveMode,
FolderPrefix,
FileNamePointers.ConstData(),
FileNamePointers.Size(),
UpdateCallback);
}
catch(...) { Result = E_FAIL; }
}
static THREAD_FUNC_DECL MyThreadFunction(void *param)
{
((CThreadUpdate *)param)->Process();
return 0;
}
};
HRESULT CPanel::CopyFrom(bool moveMode, const UString &folderPrefix, const UStringVector &filePaths,
bool showErrorMessages, UStringVector *messages)
{
if (IsHashFolder())
{
if (moveMode)
return E_NOTIMPL;
}
// CDisableNotify disableNotify(*this);
HRESULT res;
if (!_folderOperations)
res = E_NOINTERFACE;
else
{
CThreadUpdate updater;
updater.MoveMode = moveMode;
updater.UpdateCallbackSpec = new CUpdateCallback100Imp;
updater.UpdateCallback = updater.UpdateCallbackSpec;
updater.UpdateCallbackSpec->Init();
updater.UpdateCallbackSpec->ProgressDialog = &updater.ProgressDialog;
const UString title = LangString(IDS_COPYING);
const UString progressWindowTitle ("7-Zip"); // LangString(IDS_APP_TITLE);
updater.ProgressDialog.MainWindow = GetParent();
updater.ProgressDialog.MainTitle = progressWindowTitle;
updater.ProgressDialog.MainAddTitle = title + L' ';
{
if (!_parentFolders.IsEmpty())
{
const CFolderLink &fl = _parentFolders.Back();
updater.UpdateCallbackSpec->PasswordIsDefined = fl.UsePassword;
updater.UpdateCallbackSpec->Password = fl.Password;
}
}
updater.FolderOperations = _folderOperations;
updater.FolderPrefix = folderPrefix;
updater.FileNames.ClearAndReserve(filePaths.Size());
unsigned i;
for (i = 0; i < filePaths.Size(); i++)
updater.FileNames.AddInReserved(filePaths[i]);
updater.FileNamePointers.ClearAndReserve(updater.FileNames.Size());
for (i = 0; i < updater.FileNames.Size(); i++)
updater.FileNamePointers.AddInReserved(updater.FileNames[i]);
{
NWindows::CThread thread;
const WRes wres = thread.Create(CThreadUpdate::MyThreadFunction, &updater);
if (wres != 0)
return HRESULT_FROM_WIN32(wres);
updater.ProgressDialog.Create(title, thread, GetParent());
}
if (messages)
*messages = updater.ProgressDialog.Sync.Messages;
res = updater.Result;
}
if (res == E_NOINTERFACE)
{
const UString errorMessage = LangString(IDS_OPERATION_IS_NOT_SUPPORTED);
if (showErrorMessages)
MessageBox_Error(errorMessage);
else if (messages)
messages->Add(errorMessage);
return E_ABORT;
}
RefreshTitleAlways();
return res;
}
void CPanel::CopyFromNoAsk(bool moveMode, const UStringVector &filePaths)
{
CDisableTimerProcessing disableTimerProcessing(*this);
CSelectedState srcSelState;
SaveSelectedState(srcSelState);
CDisableNotify disableNotify(*this);
const HRESULT result = CopyFrom(moveMode, L"", filePaths, true, NULL);
if (result != S_OK)
{
disableNotify.Restore();
// For Password:
SetFocusToList();
if (result != E_ABORT)
MessageBox_Error_HRESULT(result);
return;
}
RefreshListCtrl(srcSelState);
disableNotify.Restore();
SetFocusToList();
}
|