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
|
// PanelExtract.cpp
#include "StdAfx.h"
#include "Panel.h"
#include "resource.h"
#include "LangUtils.h"
#include "ExtractCallback.h"
#include "Windows/Thread.h"
////////////////////////////////////////////////////////////////
#include "UpdateCallback100.h"
using namespace NWindows;
class CPanelCopyThread: public CProgressThreadVirt
{
HRESULT ProcessVirt();
public:
CMyComPtr<IFolderOperations> FolderOperations;
CRecordVector<UInt32> Indices;
UString DestPath;
CExtractCallbackImp *ExtractCallbackSpec;
CMyComPtr<IFolderOperationsExtractCallback> ExtractCallback;
HRESULT Result;
bool MoveMode;
CPanelCopyThread(): MoveMode(false), Result(E_FAIL) {}
};
HRESULT CPanelCopyThread::ProcessVirt()
{
if (MoveMode)
Result = FolderOperations->MoveTo(&Indices.Front(), Indices.Size(), DestPath, ExtractCallback);
else
Result = FolderOperations->CopyTo(&Indices.Front(), Indices.Size(), DestPath, ExtractCallback);
return Result;
}
HRESULT CPanel::CopyTo(const CRecordVector<UInt32> &indices, const UString &folder,
bool moveMode, bool showErrorMessages, UStringVector *messages,
bool &usePassword, UString &password)
{
CMyComPtr<IFolderOperations> folderOperations;
if (_folder.QueryInterface(IID_IFolderOperations, &folderOperations) != S_OK)
{
UString errorMessage = LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208);
if (showErrorMessages)
MessageBox(errorMessage);
else if (messages != 0)
messages->Add(errorMessage);
return E_FAIL;
}
HRESULT res;
{
CPanelCopyThread extracter;
extracter.ExtractCallbackSpec = new CExtractCallbackImp;
extracter.ExtractCallback = extracter.ExtractCallbackSpec;
extracter.ExtractCallbackSpec->ProgressDialog = &extracter.ProgressDialog;
extracter.ProgressDialog.CompressingMode = false;
UString title = moveMode ?
LangString(IDS_MOVING, 0x03020206):
LangString(IDS_COPYING, 0x03020205);
UString progressWindowTitle = LangString(IDS_APP_TITLE, 0x03000000);
extracter.ProgressDialog.MainWindow = GetParent();
extracter.ProgressDialog.MainTitle = progressWindowTitle;
extracter.ProgressDialog.MainAddTitle = title + L" ";
extracter.ExtractCallbackSpec->OverwriteMode = NExtract::NOverwriteMode::kAskBefore;
extracter.ExtractCallbackSpec->Init();
extracter.Indices = indices;
extracter.DestPath = folder;
extracter.FolderOperations = folderOperations;
extracter.MoveMode = moveMode;
extracter.ExtractCallbackSpec->PasswordIsDefined = usePassword;
extracter.ExtractCallbackSpec->Password = password;
RINOK(extracter.Create(title, GetParent()));
if (messages != 0)
*messages = extracter.ProgressDialog.Sync.Messages;
res = extracter.Result;
if (res == S_OK && extracter.ExtractCallbackSpec->IsOK())
{
usePassword = extracter.ExtractCallbackSpec->PasswordIsDefined;
password = extracter.ExtractCallbackSpec->Password;
}
}
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;
void Process()
{
try
{
CProgressCloser closer(ProgressDialog);
Result = FolderOperations->CopyFrom(
FolderPrefix,
&FileNamePointers.Front(),
FileNamePointers.Size(),
UpdateCallback);
}
catch(...) { Result = E_FAIL; }
}
static THREAD_FUNC_DECL MyThreadFunction(void *param)
{
((CThreadUpdate *)param)->Process();
return 0;
}
};
HRESULT CPanel::CopyFrom(const UString &folderPrefix, const UStringVector &filePaths,
bool showErrorMessages, UStringVector *messages)
{
CMyComPtr<IFolderOperations> folderOperations;
_folder.QueryInterface(IID_IFolderOperations, &folderOperations);
HRESULT res;
if (!folderOperations)
res = E_NOINTERFACE;
else
{
CThreadUpdate updater;
updater.UpdateCallbackSpec = new CUpdateCallback100Imp;
updater.UpdateCallback = updater.UpdateCallbackSpec;
updater.UpdateCallbackSpec->ProgressDialog = &updater.ProgressDialog;
UString title = LangString(IDS_COPYING, 0x03020205);
UString progressWindowTitle = LangString(IDS_APP_TITLE, 0x03000000);
updater.ProgressDialog.MainWindow = GetParent();
updater.ProgressDialog.MainTitle = progressWindowTitle;
updater.ProgressDialog.MainAddTitle = title + UString(L" ");
updater.UpdateCallbackSpec->Init(false, L"");
updater.FolderOperations = folderOperations;
updater.FolderPrefix = folderPrefix;
updater.FileNames.Reserve(filePaths.Size());
int i;
for(i = 0; i < filePaths.Size(); i++)
updater.FileNames.Add(filePaths[i]);
updater.FileNamePointers.Reserve(updater.FileNames.Size());
for(i = 0; i < updater.FileNames.Size(); i++)
updater.FileNamePointers.Add(updater.FileNames[i]);
NWindows::CThread thread;
RINOK(thread.Create(CThreadUpdate::MyThreadFunction, &updater));
updater.ProgressDialog.Create(title, thread, GetParent());
if (messages != 0)
*messages = updater.ProgressDialog.Sync.Messages;
res = updater.Result;
}
if (res == E_NOINTERFACE)
{
UString errorMessage = LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208);
if (showErrorMessages)
MessageBox(errorMessage);
else if (messages != 0)
messages->Add(errorMessage);
return E_ABORT;
}
RefreshTitleAlways();
return res;
}
void CPanel::CopyFromNoAsk(const UStringVector &filePaths)
{
CDisableTimerProcessing disableTimerProcessing(*this);
CSelectedState srcSelState;
SaveSelectedState(srcSelState);
HRESULT result = CopyFrom(L"", filePaths, true, 0);
if (result != S_OK)
{
disableTimerProcessing.Restore();
// For Password:
SetFocusToList();
if (result != E_ABORT)
MessageBoxError(result);
return;
}
RefreshListCtrl(srcSelState);
disableTimerProcessing.Restore();
SetFocusToList();
}
void CPanel::CopyFromAsk(const UStringVector &filePaths)
{
UString title = LangString(IDS_CONFIRM_FILE_COPY, 0x03020222);
UString message = LangString(IDS_WANT_TO_COPY_FILES, 0x03020223);
message += L"\n\'";
message += _currentFolderPrefix;
message += L"\' ?";
int res = ::MessageBoxW(*(this), message, title, MB_YESNOCANCEL | MB_ICONQUESTION);
if (res != IDYES)
return;
CopyFromNoAsk(filePaths);
}
|