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:
Diffstat (limited to 'CPP/7zip/Bundles/SFXWin/Main.cpp')
-rwxr-xr-xCPP/7zip/Bundles/SFXWin/Main.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/CPP/7zip/Bundles/SFXWin/Main.cpp b/CPP/7zip/Bundles/SFXWin/Main.cpp
new file mode 100755
index 00000000..166d58cb
--- /dev/null
+++ b/CPP/7zip/Bundles/SFXWin/Main.cpp
@@ -0,0 +1,115 @@
+// Main.cpp
+
+#include "StdAfx.h"
+
+#include <initguid.h>
+
+#include "Common/StringConvert.h"
+#include "Common/CommandLineParser.h"
+
+#include "Windows/FileDir.h"
+#include "Windows/FileName.h"
+#include "Windows/DLL.h"
+
+#include "../../ICoder.h"
+#include "../../IPassword.h"
+#include "../../Archive/IArchive.h"
+#include "../../UI/Common/Extract.h"
+#include "../../UI/Explorer/MyMessages.h"
+#include "../../UI/GUI/ExtractGUI.h"
+
+HINSTANCE g_hInstance;
+#ifndef _UNICODE
+bool g_IsNT = false;
+static inline bool IsItWindowsNT()
+{
+ OSVERSIONINFO versionInfo;
+ versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
+ if (!::GetVersionEx(&versionInfo))
+ return false;
+ return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
+}
+#endif
+
+int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */)
+{
+ g_hInstance = (HINSTANCE)hInstance;
+ #ifndef _UNICODE
+ g_IsNT = IsItWindowsNT();
+ #endif
+
+ UString password;
+ bool assumeYes = false;
+ bool outputFolderDefined = false;
+ UString outputFolder;
+ UStringVector subStrings;
+ NCommandLineParser::SplitCommandLine(GetCommandLineW(), subStrings);
+ for (int i = 1; i < subStrings.Size(); i++)
+ {
+ const UString &s = subStrings[i];
+ if (s.CompareNoCase(L"-y") == 0)
+ assumeYes = true;
+ else if (s.Left(2).CompareNoCase(L"-o") == 0)
+ {
+ outputFolder = s.Mid(2);
+ NWindows::NFile::NName::NormalizeDirPathPrefix(outputFolder);
+ outputFolderDefined = !outputFolder.IsEmpty();
+ }
+ else if (s.Left(2).CompareNoCase(L"-p") == 0)
+ {
+ password = s.Mid(2);
+ }
+ }
+
+ UString path;
+ NWindows::NDLL::MyGetModuleFileName(g_hInstance, path);
+
+ UString fullPath;
+ int fileNamePartStartIndex;
+ if (!NWindows::NFile::NDirectory::MyGetFullPathName(path, fullPath, fileNamePartStartIndex))
+ {
+ MyMessageBox(L"Error 1329484");
+ return 1;
+ }
+
+ COpenCallbackGUI openCallback;
+
+ openCallback.PasswordIsDefined = !password.IsEmpty();
+ openCallback.Password = password;
+
+ CExtractCallbackImp *ecs = new CExtractCallbackImp;
+ CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
+ ecs->Init();
+ ecs->PasswordIsDefined = !password.IsEmpty();
+ ecs->Password = password;
+
+ CExtractOptions eo;
+ eo.OutputDir = outputFolderDefined ? outputFolder :
+ fullPath.Left(fileNamePartStartIndex);
+ eo.YesToAll = assumeYes;
+ eo.OverwriteMode = assumeYes ?
+ NExtract::NOverwriteMode::kWithoutPrompt :
+ NExtract::NOverwriteMode::kAskBefore;
+ eo.PathMode = NExtract::NPathMode::kFullPathnames;
+ eo.TestMode = false;
+
+ UStringVector v1, v2;
+ v1.Add(fullPath);
+ v2.Add(fullPath);
+ NWildcard::CCensorNode wildcardCensor;
+ wildcardCensor.AddItem(true, L"*", true, true, true);
+
+ HRESULT result = ExtractGUI(v1, v2,
+ wildcardCensor, eo, (assumeYes ? false: true), &openCallback, ecs);
+
+ /*
+ HRESULT result = ExtractArchive(NULL, path, assumeYes, !assumeYes,
+ outputFolderDefined ? outputFolder :
+ fullPath.Left(fileNamePartStartIndex));
+ */
+ if (result == S_FALSE)
+ MyMessageBox(L"Archive is not supported");
+ else if (result != S_OK && result != E_ABORT)
+ ShowErrorMessage(0, result);
+ return 0;
+}