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>2007-01-20 03:00:00 +0300
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:49 +0300
commitd9666cf046a8453b33b3e2fbf4d82295a9f87df3 (patch)
treec722ed19b844b53042aec0c1d7d2f8381140a5ed /CPP/7zip/UI/Far/PluginDelete.cpp
parent804edc5756fede54dbb1aefda6d39d306111938d (diff)
4.44 beta
Diffstat (limited to 'CPP/7zip/UI/Far/PluginDelete.cpp')
-rwxr-xr-xCPP/7zip/UI/Far/PluginDelete.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/CPP/7zip/UI/Far/PluginDelete.cpp b/CPP/7zip/UI/Far/PluginDelete.cpp
new file mode 100755
index 00000000..6a969c15
--- /dev/null
+++ b/CPP/7zip/UI/Far/PluginDelete.cpp
@@ -0,0 +1,169 @@
+// PluginDelete.cpp
+
+#include "StdAfx.h"
+
+#include <stdio.h>
+
+#include "Plugin.h"
+#include "Messages.h"
+#include "UpdateCallback100.h"
+
+#include "Windows/FileDir.h"
+
+#include "../../Common/FileStreams.h"
+
+#include "Common/StringConvert.h"
+
+#include "../Common/ZipRegistry.h"
+#include "../Common/WorkDir.h"
+
+using namespace NFar;
+using namespace NWindows;
+using namespace NFile;
+using namespace NDirectory;
+
+static LPCWSTR kTempArchivePrefix = L"7zA";
+
+int CPlugin::DeleteFiles(PluginPanelItem *panelItems, int numItems,
+ int opMode)
+{
+ if (numItems == 0)
+ return FALSE;
+ /*
+ if (!m_ArchiverInfo.UpdateEnabled)
+ {
+ g_StartupInfo.ShowMessage(NMessageID::kUpdateNotSupportedForThisArchive);
+ return FALSE;
+ }
+ */
+ if ((opMode & OPM_SILENT) == 0)
+ {
+ const char *msgItems[]=
+ {
+ g_StartupInfo.GetMsgString(NMessageID::kDeleteTitle),
+ g_StartupInfo.GetMsgString(NMessageID::kDeleteFiles),
+ g_StartupInfo.GetMsgString(NMessageID::kDeleteDelete),
+ g_StartupInfo.GetMsgString(NMessageID::kDeleteCancel)
+ };
+ char msg[1024];
+ if (numItems == 1)
+ {
+ sprintf(msg, g_StartupInfo.GetMsgString(NMessageID::kDeleteFile),
+ panelItems[0].FindData.cFileName);
+ msgItems[1] = msg;
+ }
+ else if (numItems > 1)
+ {
+ sprintf(msg, g_StartupInfo.GetMsgString(NMessageID::kDeleteNumberOfFiles),
+ numItems);
+ msgItems[1] = msg;
+ }
+ if (g_StartupInfo.ShowMessage(FMSG_WARNING, NULL, msgItems,
+ sizeof(msgItems) / sizeof(msgItems[0]), 2) != 0)
+ return (FALSE);
+ }
+
+ CScreenRestorer screenRestorer;
+ CProgressBox progressBox;
+ CProgressBox *progressBoxPointer = NULL;
+ if ((opMode & OPM_SILENT) == 0 && (opMode & OPM_FIND ) == 0)
+ {
+ screenRestorer.Save();
+
+ progressBoxPointer = &progressBox;
+ progressBox.Init(g_StartupInfo.GetMsgString(NMessageID::kWaitTitle),
+ g_StartupInfo.GetMsgString(NMessageID::kDeleting), 1 << 17);
+ }
+
+ NWorkDir::CInfo workDirInfo;
+ ReadWorkDirInfo(workDirInfo);
+
+ UString workDir = GetWorkDir(workDirInfo, m_FileName);
+ CreateComplexDirectory(workDir);
+
+ CTempFileW tempFile;
+ UString tempFileName;
+ if (tempFile.Create(workDir, kTempArchivePrefix, tempFileName) == 0)
+ return FALSE;
+
+
+ CRecordVector<UINT32> indices;
+ indices.Reserve(numItems);
+ for(int i = 0; i < numItems; i++)
+ indices.Add(panelItems[i].UserData);
+
+ ////////////////////////////
+ // Save _folder;
+
+ UStringVector pathVector;
+ GetPathParts(pathVector);
+
+ CMyComPtr<IOutFolderArchive> outArchive;
+ HRESULT result = m_ArchiveHandler.QueryInterface(
+ IID_IOutFolderArchive, &outArchive);
+ if(result != S_OK)
+ {
+ g_StartupInfo.ShowMessage(NMessageID::kUpdateNotSupportedForThisArchive);
+ return FALSE;
+ }
+ outArchive->SetFolder(_folder);
+
+ CUpdateCallback100Imp *updateCallbackSpec = new CUpdateCallback100Imp;
+ CMyComPtr<IFolderArchiveUpdateCallback> updateCallback(updateCallbackSpec );
+
+ updateCallbackSpec->Init(m_ArchiveHandler, &progressBox);
+
+
+ result = outArchive->DeleteItems(
+ tempFileName,
+ &indices.Front(), indices.Size(),
+ updateCallback);
+ updateCallback.Release();
+ outArchive.Release();
+
+ if (result != S_OK)
+ {
+ ShowErrorMessage(result);
+ return FALSE;
+ }
+
+ _folder.Release();
+ m_ArchiveHandler->Close();
+
+ if (!DeleteFileAlways(m_FileName))
+ {
+ ShowLastErrorMessage();
+ return FALSE;
+ }
+
+ tempFile.DisableDeleting();
+ if (!MyMoveFile(tempFileName, m_FileName))
+ {
+ ShowLastErrorMessage();
+ return FALSE;
+ }
+
+ result = m_ArchiveHandler->ReOpen(NULL);
+ if (result != S_OK)
+ {
+ ShowErrorMessage(result);
+ return FALSE;
+ }
+
+
+ ////////////////////////////
+ // Restore _folder;
+
+ m_ArchiveHandler->BindToRootFolder(&_folder);
+ for (i = 0; i < pathVector.Size(); i++)
+ {
+ CMyComPtr<IFolderFolder> newFolder;
+ _folder->BindToFolder(pathVector[i], &newFolder);
+ if(!newFolder )
+ break;
+ _folder = newFolder;
+ }
+ GetCurrentDir();
+
+ return(TRUE);
+}