This commit is contained in:
DavidXanatos 2023-07-31 21:20:29 +02:00
parent 3e3a66cdc4
commit 156a7a893f
7 changed files with 44 additions and 17 deletions

View File

@ -51,25 +51,26 @@ int CArchive::Open()
if(!theArc.IsOperational())
{
LogError("Couldn't open interface");
return 0; // failed
return ERR_7Z_NO_INTERFACE;
}
if(m_Archive)
{
LogError("archive is already open");
return 0; // fails
return ERR_7Z_ALREADY_OPEN;
}
if(!m_pDevice && !QFile::exists(m_ArchivePath))
{
LogError("archive does not exist");
return 0; // failed
return ERR_7Z_FILE_NOT_EXIST;
}
SArcInfo Info = GetArcInfo(m_ArchivePath);
if(Info.FormatIndex == 0)
return -1; // unsupported format
if (Info.FormatIndex == 0)
return ERR_7Z_UNSUPPORTED_FORMAT;
bool bNeedPassword = false;
for (int i = 0; i <= theArc.GetFormatCount(); i++)
{
CMyComPtr<IInArchive> InArchive;
@ -87,8 +88,8 @@ int CArchive::Open()
InArchive->Close();
if(Ret == S_FALSE)
continue; // not supported
if(Ret == E_ABORT)
LogError(QString("Password required for archive"));
if (Ret == E_ABORT)
bNeedPassword = true;
break; // error
}
@ -97,10 +98,15 @@ int CArchive::Open()
break;
}
if (bNeedPassword) {
LogError(QString("Password required for archive"));
return ERR_7Z_PASSWORD_REQUIRED;
}
if(m_Archive == NULL)
{
LogError("Failed to open archive");
return 0; // failed
return ERR_7Z_OPEN_FAILED;
}
// list archive content
@ -138,7 +144,7 @@ int CArchive::Open()
m_Files.append(File);
}
return 1; // success
return ERR_7Z_OK; // success
}
bool CArchive::Extract(QString Path)
@ -250,6 +256,7 @@ bool CArchive::Update(QMap<int, QIODevice*> *FileList, bool bDelete, int Level)
{
L"s",
L"x",
//L"mt",
L"he"
};
const int kNumProps = sizeof(names) / sizeof(names[0]);
@ -257,6 +264,7 @@ bool CArchive::Update(QMap<int, QIODevice*> *FileList, bool bDelete, int Level)
{
false, // solid mode OFF
(UInt32)Level, // compression level = 9 - ultra
//(UInt32)8, // set number of CPU threads
true // file name encryption (7z only)
};
@ -319,7 +327,7 @@ bool CArchive::Update(QMap<int, QIODevice*> *FileList, bool bDelete, int Level)
QFile::remove(m_ArchivePath);
QFile::rename(m_ArchivePath + ".tmp", m_ArchivePath);
}
return Open();
return Open() == ERR_7Z_OK;
}
return true;
}
@ -431,6 +439,11 @@ void CArchive::FileProperty(int ArcIndex, QString Name, QVariant Value)
}
}
void CArchive::LogError(const QString& Error)
{
qDebug() << Error;
}
#endif
SArcInfo GetArcInfo(const QString &FileName)
@ -500,4 +513,4 @@ SArcInfo GetArcInfo(const QString &FileName)
if(ArcInfo.FormatIndex == 0) // not a known archive
ArcInfo.ArchiveExt.clear();
return ArcInfo;
}
}

View File

@ -8,6 +8,14 @@
#ifdef USE_7Z
#define ERR_7Z_OK 0
#define ERR_7Z_NO_INTERFACE 1
#define ERR_7Z_ALREADY_OPEN 2
#define ERR_7Z_FILE_NOT_EXIST 3
#define ERR_7Z_OPEN_FAILED 4
#define ERR_7Z_PASSWORD_REQUIRED 5
#define ERR_7Z_UNSUPPORTED_FORMAT 6
class MISCHELPERS_EXPORT CArchive
{
public:
@ -50,7 +58,7 @@ protected:
QString GetNextPart(QString FileName);
virtual void LogError(const QString &Error) {}
virtual void LogError(const QString& Error);
friend class CArchiveOpener;
friend class CArchiveExtractor;

View File

@ -286,7 +286,7 @@ bool C7zFileEngineHandler::Open(const QString& ArchivePath)
Close();
CArchive* pArchive = new CArchive(ArchivePath);
if (pArchive->Open() <= 0) {
if (pArchive->Open() != ERR_7Z_OK) {
delete pArchive;
return false;
}

View File

@ -91,7 +91,7 @@ C7zWorker::C7zWorker(const QString &ArchivePath, const QString &WorkingPath, con
if(QFile::exists(ArchivePath))
{
if(!Open())
if(Open() != ERR_7Z_OK)
m_Errors.append("Open Failed");
}
}

View File

@ -489,6 +489,7 @@ void CSandMan::CreateMenus(bool bAdvanced)
m_pNewBox = m_pMenuFile->addAction(CSandMan::GetIcon("NewBox"), tr("Create New Box"), this, SLOT(OnSandBoxAction()));
m_pNewGroup = m_pMenuFile->addAction(CSandMan::GetIcon("Group"), tr("Create Box Group"), this, SLOT(OnSandBoxAction()));
m_pImportBox = m_pMenuFile->addAction(CSandMan::GetIcon("UnPackBox"), tr("Import Box"), this, SLOT(OnSandBoxAction()));
m_pImportBox->setEnabled(CArchive::IsInit());
m_pMenuFile->addSeparator();
m_pRunBoxed = m_pMenuFile->addAction(CSandMan::GetIcon("Run"), tr("Run Sandboxed"), this, SLOT(OnSandBoxAction()));
m_pEmptyAll = m_pMenuFile->addAction(CSandMan::GetIcon("EmptyAll"), tr("Terminate All Processes"), this, SLOT(OnEmptyAll()));
@ -709,6 +710,7 @@ void CSandMan::CreateOldMenus()
m_pNewBox = m_pSandbox->addAction(CSandMan::GetIcon("NewBox"), tr("Create New Sandbox"), this, SLOT(OnSandBoxAction()));
m_pNewGroup = m_pSandbox->addAction(CSandMan::GetIcon("Group"), tr("Create New Group"), this, SLOT(OnSandBoxAction()));
m_pImportBox = m_pSandbox->addAction(CSandMan::GetIcon("UnPackBox"), tr("Import Sandbox"), this, SLOT(OnSandBoxAction()));
m_pImportBox->setEnabled(CArchive::IsInit());
QAction* m_pSetContainer = m_pSandbox->addAction(CSandMan::GetIcon("Advanced"), tr("Set Container Folder"), this, SLOT(OnSettingsAction()));
m_pSetContainer->setData("Sandbox");

View File

@ -227,7 +227,7 @@ void CSandBoxPlus::ExportBoxAsync(const CSbieProgressPtr& pProgress, const QStri
}
SB_STATUS Status = SB_OK;
if (!Archive.Update(&Files, true, theConf->GetInt("Options/ExportCompression", 5))) // 0, 1 - 9
if (!Archive.Update(&Files, true, theConf->GetInt("Options/ExportCompression", 3))) // 0, 1 - 9
Status = SB_ERR((ESbieMsgCodes)SBX_7zCreateFailed);
//if(!Status.IsError() && !pProgress->IsCanceled())
@ -262,7 +262,7 @@ void CSandBoxPlus::ImportBoxAsync(const CSbieProgressPtr& pProgress, const QStri
{
CArchive Archive(ImportPath);
if (Archive.Open() != 1) {
if (Archive.Open() != ERR_7Z_OK) {
pProgress->Finish(SB_ERR((ESbieMsgCodes)SBX_7zOpenFailed));
return;
}

View File

@ -13,6 +13,7 @@
#include "../Views/FileView.h"
#include "../Wizards/NewBoxWizard.h"
#include "../Helpers/WinHelper.h"
#include "../MiscHelpers/Archive/Archive.h"
#include "../Windows/SettingsWindow.h"
#include "qt_windows.h"
@ -151,7 +152,8 @@ void CSbieView::CreateMenu()
m_pNewBox = m_pMenu->addAction(CSandMan::GetIcon("NewBox"), tr("Create New Box"), this, SLOT(OnGroupAction()));
m_pAddGroupe = m_pMenu->addAction(CSandMan::GetIcon("Group"), tr("Create Box Group"), this, SLOT(OnGroupAction()));
m_pImportBox = m_pMenu->addAction(CSandMan::GetIcon("UnPackBox"), tr("Import Box"), this, SLOT(OnGroupAction()));
m_pImportBox->setEnabled(CArchive::IsInit());
m_pMenuBox = new QMenu();
m_pStopAsync = m_pMenuBox->addAction(CSandMan::GetIcon("Stop"), tr("Stop Operations"), this, SLOT(OnSandBoxAction()));
@ -236,6 +238,7 @@ void CSbieView::CreateMenu()
m_pMenuTools = m_pMenuBox->addMenu(CSandMan::GetIcon("Maintenance"), tr("Sandbox Tools"));
m_pMenuDuplicate = m_pMenuTools->addAction(CSandMan::GetIcon("Duplicate"), tr("Duplicate Box Config"), this, SLOT(OnSandBoxAction()));
m_pMenuExport = m_pMenuTools->addAction(CSandMan::GetIcon("PackBox"), tr("Export Box"), this, SLOT(OnSandBoxAction()));
m_pMenuExport->setEnabled(CArchive::IsInit());
m_pMenuRename = m_pMenuBox->addAction(CSandMan::GetIcon("Rename"), tr("Rename Sandbox"), this, SLOT(OnSandBoxAction()));
m_pMenuMoveTo = m_pMenuBox->addMenu(CSandMan::GetIcon("Group"), tr("Move Sandbox"));
@ -333,6 +336,7 @@ void CSbieView::CreateOldMenu()
m_pMenuTools->addSeparator();
m_pMenuDuplicate = m_pMenuTools->addAction(CSandMan::GetIcon("Duplicate"), tr("Duplicate Sandbox Config"), this, SLOT(OnSandBoxAction()));
m_pMenuExport = m_pMenuTools->addAction(CSandMan::GetIcon("PackBox"), tr("Export Sandbox"), this, SLOT(OnSandBoxAction()));
m_pMenuExport->setEnabled(CArchive::IsInit());
m_pMenuTools->addSeparator();
m_pMenuRefresh = m_pMenuTools->addAction(CSandMan::GetIcon("Refresh"), tr("Refresh Info"), this, SLOT(OnSandBoxAction()));