Skip to content
Browse files

Add initial work for installer C++ rewrite

Release build requires WinDDK to link with the system msvcrt.dll.
  • Loading branch information...
1 parent f9926a0 commit b7c1e165544bbee240a6e215f29c09ac981daf21 @poiru poiru committed Mar 18, 2013
Showing with 8,009 additions and 0 deletions.
  1. +97 −0 Installer/Application.cpp
  2. +32 −0 Installer/Application.h
  3. +112 −0 Installer/DialogInstall.cpp
  4. +49 −0 Installer/DialogInstall.h
  5. BIN Installer/Installer.ico
  6. +51 −0 Installer/Installer.rc
  7. +86 −0 Installer/Installer.vcxproj
  8. +170 −0 Installer/Installer.vcxproj.filters
  9. +2 −0 Installer/Resource.h
  10. +19 −0 Installer/StdAfx.cpp
  11. +36 −0 Installer/StdAfx.h
  12. +280 −0 Installer/Util.cpp
  13. +41 −0 Installer/Util.h
  14. +203 −0 Installer/lzma/7z.h
  15. +76 −0 Installer/lzma/7zAlloc.c
  16. +15 −0 Installer/lzma/7zAlloc.h
  17. +36 −0 Installer/lzma/7zBuf.c
  18. +39 −0 Installer/lzma/7zBuf.h
  19. +74 −0 Installer/lzma/7zCrc.c
  20. +25 −0 Installer/lzma/7zCrc.h
  21. +34 −0 Installer/lzma/7zCrcOpt.c
  22. +477 −0 Installer/lzma/7zDec.c
  23. +288 −0 Installer/lzma/7zFile.c
  24. +83 −0 Installer/lzma/7zFile.h
  25. +1,402 −0 Installer/lzma/7zIn.c
  26. +84 −0 Installer/lzma/7zMemInStream.c
  27. +22 −0 Installer/lzma/7zMemInStream.h
  28. +169 −0 Installer/lzma/7zStream.c
  29. +7 −0 Installer/lzma/7zVersion.h
  30. +127 −0 Installer/lzma/Alloc.c
  31. +38 −0 Installer/lzma/Alloc.h
  32. +132 −0 Installer/lzma/Bcj2.c
  33. +38 −0 Installer/lzma/Bcj2.h
  34. +133 −0 Installer/lzma/Bra.c
  35. +68 −0 Installer/lzma/Bra.h
  36. +85 −0 Installer/lzma/Bra86.c
  37. +168 −0 Installer/lzma/CpuArch.c
  38. +155 −0 Installer/lzma/CpuArch.h
  39. +356 −0 Installer/lzma/Lzma2Dec.c
  40. +84 −0 Installer/lzma/Lzma2Dec.h
  41. +999 −0 Installer/lzma/LzmaDec.c
  42. +231 −0 Installer/lzma/LzmaDec.h
  43. +81 −0 Installer/lzma/Ppmd.h
  44. +708 −0 Installer/lzma/Ppmd7.c
  45. +140 −0 Installer/lzma/Ppmd7.h
  46. +187 −0 Installer/lzma/Ppmd7Dec.c
  47. +254 −0 Installer/lzma/Types.h
  48. +4 −0 Rainmeter.props
  49. +6 −0 Rainmeter.sln
  50. +6 −0 RainmeterCPP.sln
View
97 Installer/Application.cpp
@@ -0,0 +1,97 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "StdAfx.h"
+#include "Install.h"
+#include "Resource.h"
+#include "Application.h"
+
+bool IsSupportedPlatform();
+bool IsSupportedCPU();
+
+int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
+{
+ int argCount = 0;
+ LPWSTR* args = CommandLineToArgvW(GetCommandLine(), &argCount);
+ if (args)
+ {
+ for (int i = 1; i < argCount; ++i)
+ {
+ WCHAR* name = &args[i][(args[i][0] == L'/') ? 1 : 0];
+ WCHAR* value = wcschr(name, L':');
+ if (value)
+ {
+ *value = L'\0';
+ ++value;
+ }
+
+ if (wcscmp(name, L"Silent") == 0)
+ {
+ }
+ }
+
+ if (argCount >= 2 && wcscmp(args[1], L"/ElevatedInstall") == 0)
+ {
+ }
+
+ LocalFree(args);
+ }
+
+ InitCommonControls();
+
+ if (!IsSupportedPlatform())
+ {
+ MessageBox(NULL, L"Windows XP SP2 or higher is required to install Rainmeter.", NULL, MB_OK | MB_ICONERROR);
+ return (int)InstallStatus::UnsupportedPlatform;
+ }
+
+ if (!IsSupportedCPU())
+ {
+ MessageBox(NULL, L"A Pentium III or later processor is required to install Rainmeter.", NULL, MB_OK | MB_ICONERROR);
+ return (int)InstallStatus::UnsupportedPlatform;
+ }
+
+ return 0;
+}
+
+bool IsSupportedPlatform()
+{
+ OSVERSIONINFOEX osvi = { sizeof(OSVERSIONINFOEX) };
+ GetVersionEx((OSVERSIONINFO*)&osvi);
+
+ if (osvi.wProductType != VER_NT_WORKSTATION ||
+ (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0))
+ {
+ // 2000 or lower.
+ return false;
+ }
+
+ if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 &&
+ osvi.wServicePackMajor <= (GetSystemMetrics(SM_SERVERR2) == 0 ? 0 : 1))
+ {
+ // XP SP1 or lower, 2003 SP0.
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+bool IsSupportedCPU()
+{
+ return IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
+}
View
32 Installer/Application.h
@@ -0,0 +1,32 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef RM_INSTALLER_APPLICATION_H_
+#define RM_INSTALLER_APPLICATION_H_
+
+enum class InstallStatus
+{
+ Success,
+ Error,
+ UnsupportedPlatform,
+ VcRedist2010Missing,
+ VcRedist2012Missing,
+ DotNetRedistMissing
+};
+
+#endif
View
112 Installer/DialogInstall.cpp
@@ -0,0 +1,112 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "StdAfx.h"
+#include "DialogInstall.h"
+#include "../Common/ControlTemplate.h"
+
+CDialogInstall::CDialogInstall() : CDialog()
+{
+}
+
+CDialogInstall::~CDialogInstall()
+{
+}
+
+CDialogInstall* CDialogInstall::Create()
+{
+ auto dialog = new CDialogInstall();
+
+ dialog->ShowDialogWindow(
+ L"Installer",
+ 0, 0, 350, 210,
+ DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
+ WS_EX_APPWINDOW | WS_EX_CONTROLPARENT,
+ NULL,
+ false);
+
+ return dialog;
+}
+
+INT_PTR CDialogInstall::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ return OnInitDialog(wParam, lParam);
+
+ case WM_ACTIVATE:
+ return OnActivate(wParam, lParam);
+
+ case WM_COMMAND:
+ return OnCommand(wParam, lParam);
+
+ case WM_NOTIFY:
+ return OnNotify(wParam, lParam);
+
+ case WM_CLOSE:
+ {
+ delete this;
+ }
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+WCHAR* GetString(UINT id) { return L"test"; }
+
+INT_PTR CDialogInstall::OnInitDialog(WPARAM wParam, LPARAM lParam)
+{
+ static const ControlTemplate::Control s_Controls[] =
+ {
+ CT_BUTTON(Id_CloseButton, 0,
+ 294, 191, 50, 14,
+ WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 0)
+ };
+
+ CreateControls(s_Controls, _countof(s_Controls), m_Font, GetString);
+
+// HICON hIcon = GetIcon(IDI_APPLICATION);
+// SendMessage(m_Window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
+
+ HWND item = GetControl(Id_CloseButton);
+ SendMessage(m_Window, WM_NEXTDLGCTL, (WPARAM)item, TRUE);
+
+ return TRUE;
+}
+
+INT_PTR CDialogInstall::OnCommand(WPARAM wParam, LPARAM lParam)
+{
+ switch (LOWORD(wParam))
+ {
+ case Id_CloseButton:
+ PostMessage(m_Window, WM_CLOSE, 0, 0);
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+INT_PTR CDialogInstall::OnNotify(WPARAM wParam, LPARAM lParam)
+{
+ return 0;
+}
View
49 Installer/DialogInstall.h
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef RM_INSTALLER_DIALOGINSTALL_H_
+#define RM_INSTALLER_DIALOGINSTALL_H_
+
+#include "../Common/Dialog.h"
+
+class CDialogInstall : public CDialog
+{
+public:
+ CDialogInstall();
+ virtual ~CDialogInstall();
+
+ static CDialogInstall* CDialogInstall::Create();
+
+ static void Open(int tab = 0);
+ static void Open(const WCHAR* name);
+ static void ShowAboutLog();
+
+protected:
+ virtual INT_PTR HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
+ INT_PTR OnInitDialog(WPARAM wParam, LPARAM lParam);
+ INT_PTR OnNotify(WPARAM wParam, LPARAM lParam);
+ INT_PTR OnCommand(WPARAM wParam, LPARAM lParam);
+
+private:
+ enum Id
+ {
+ Id_CloseButton = IDCLOSE
+ };
+};
+
+#endif
View
BIN Installer/Installer.ico
Binary file not shown.
View
51 Installer/Installer.rc
@@ -0,0 +1,51 @@
+#include <windows.h>
+#include "Resource.h"
+#include "../Version.h"
+
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
+#pragma code_page(1252)
+
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION FILEVER
+ PRODUCTVERSION PRODUCTVER
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+{
+ BLOCK "StringFileInfo"
+ {
+ BLOCK "040904E4"
+ {
+ VALUE "FileVersion", STRFILEVER
+ VALUE "LegalCopyright", "© 2013 - All authors"
+ VALUE "OriginalFilename", "Rainmeter-Setup.exe"
+ VALUE "ProductName", "Rainmeter"
+#ifdef _WIN64
+ VALUE "ProductVersion", STRPRODUCTVER " (64-bit)"
+#else
+ VALUE "ProductVersion", STRPRODUCTVER " (32-bit)"
+#endif //_WIN64
+ }
+ }
+ BLOCK "VarFileInfo"
+ {
+ VALUE "Translation", 0x409, 1252
+ }
+}
+
+//
+// Icon
+//
+
+IDI_APPICON ICON "Installer.ico"
+
View
86 Installer/Installer.vcxproj
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{2FCFBFD2-2720-4BDD-B620-4BDD3DBB8D3D}</ProjectGuid>
+ <ConfigurationType>Application</ConfigurationType>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <Import Project="$(SolutionDir)\Rainmeter.props" />
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <AdditionalDependencies>Imagehlp.lib;Wininet.lib;Comctl32.lib;Version.lib;UxTheme.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies Condition="'$(Configuration)'=='Release'">$(WinDDK71Dir)\lib\Crt\i386\msvcrt.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreAllDefaultLibraries Condition="'$(Configuration)'=='Release'">true</IgnoreAllDefaultLibraries>
+ </Link>
+ <Manifest>
+ <AdditionalManifestFiles>..\Application\Application.manifest</AdditionalManifestFiles>
+ </Manifest>
+ <ClCompile>
+ <DisableSpecificWarnings>4800;4996</DisableSpecificWarnings>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\Common\ControlTemplate.cpp" />
+ <ClCompile Include="..\Common\Dialog.cpp" />
+ <ClCompile Include="Application.cpp" />
+ <ClCompile Include="DialogInstall.cpp" />
+ <ClCompile Include="lzma\7zAlloc.c" />
+ <ClCompile Include="lzma\7zBuf.c" />
+ <ClCompile Include="lzma\7zCrc.c" />
+ <ClCompile Include="lzma\7zCrcOpt.c" />
+ <ClCompile Include="lzma\7zDec.c" />
+ <ClCompile Include="lzma\7zFile.c" />
+ <ClCompile Include="lzma\7zIn.c" />
+ <ClCompile Include="lzma\7zMemInStream.c" />
+ <ClCompile Include="lzma\7zStream.c" />
+ <ClCompile Include="lzma\Alloc.c" />
+ <ClCompile Include="lzma\Bcj2.c" />
+ <ClCompile Include="lzma\Bra.c" />
+ <ClCompile Include="lzma\Bra86.c" />
+ <ClCompile Include="lzma\CpuArch.c" />
+ <ClCompile Include="lzma\Lzma2Dec.c" />
+ <ClCompile Include="lzma\LzmaDec.c" />
+ <ClCompile Include="lzma\Ppmd7.c" />
+ <ClCompile Include="lzma\Ppmd7Dec.c" />
+ <ClCompile Include="StdAfx.cpp" />
+ <ClCompile Include="Util.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\Common\ControlTemplate.h" />
+ <ClInclude Include="..\Common\Dialog.h" />
+ <ClInclude Include="Application.h" />
+ <ClInclude Include="DialogInstall.h" />
+ <ClInclude Include="lzma\7z.h" />
+ <ClInclude Include="lzma\7zAlloc.h" />
+ <ClInclude Include="lzma\7zBuf.h" />
+ <ClInclude Include="lzma\7zCrc.h" />
+ <ClInclude Include="lzma\7zFile.h" />
+ <ClInclude Include="lzma\7zMemInStream.h" />
+ <ClInclude Include="lzma\7zVersion.h" />
+ <ClInclude Include="lzma\Alloc.h" />
+ <ClInclude Include="lzma\Bcj2.h" />
+ <ClInclude Include="lzma\Bra.h" />
+ <ClInclude Include="lzma\CpuArch.h" />
+ <ClInclude Include="lzma\Lzma2Dec.h" />
+ <ClInclude Include="lzma\LzmaDec.h" />
+ <ClInclude Include="lzma\Ppmd.h" />
+ <ClInclude Include="lzma\Ppmd7.h" />
+ <ClInclude Include="lzma\Types.h" />
+ <ClInclude Include="StdAfx.h" />
+ <ClInclude Include="Util.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="Installer.rc" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
View
170 Installer/Installer.vcxproj.filters
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{22670730-eb79-4df9-bed9-27fff1350132}</UniqueIdentifier>
+ <Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{774a1827-ac91-40b9-ad18-8a3d68983c64}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{a4963a10-e359-400f-86fa-bdce98dd5dc2}</UniqueIdentifier>
+ <Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
+ </Filter>
+ <Filter Include="lzma">
+ <UniqueIdentifier>{9588f54f-9188-40b7-b750-260f5f514ee5}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Common">
+ <UniqueIdentifier>{f19567fb-ab8f-4193-a3b3-826685cf8db3}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="Application.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="StdAfx.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Util.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\Bcj2.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\Bra.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\Bra86.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\CpuArch.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\Lzma2Dec.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\LzmaDec.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\Ppmd7.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\Ppmd7Dec.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zAlloc.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zBuf.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zCrc.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zCrcOpt.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zDec.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zFile.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zIn.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zMemInStream.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\7zStream.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="lzma\Alloc.c">
+ <Filter>lzma</Filter>
+ </ClCompile>
+ <ClCompile Include="DialogInstall.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\Common\Dialog.cpp">
+ <Filter>Common</Filter>
+ </ClCompile>
+ <ClCompile Include="..\Common\ControlTemplate.cpp">
+ <Filter>Common</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="Util.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="StdAfx.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\Alloc.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\Bcj2.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\Bra.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\CpuArch.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\Lzma2Dec.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\LzmaDec.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\Ppmd.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\Ppmd7.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\Types.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\7z.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\7zAlloc.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\7zBuf.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\7zCrc.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\7zFile.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\7zMemInStream.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="lzma\7zVersion.h">
+ <Filter>lzma</Filter>
+ </ClInclude>
+ <ClInclude Include="DialogInstall.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="..\Common\Dialog.h">
+ <Filter>Common</Filter>
+ </ClInclude>
+ <ClInclude Include="..\Common\ControlTemplate.h">
+ <Filter>Common</Filter>
+ </ClInclude>
+ <ClInclude Include="Application.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="Installer.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+</Project>
View
2 Installer/Resource.h
@@ -0,0 +1,2 @@
+#define IDI_APPICON 101
+#define IDC_STATIC -1
View
19 Installer/StdAfx.cpp
@@ -0,0 +1,19 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "StdAfx.h"
View
36 Installer/StdAfx.h
@@ -0,0 +1,36 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef RM_INSTALLER_STDAFX_H_
+#define RM_INSTALLER_STDAFX_H_
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <windowsx.h>
+#include <commctrl.h>
+#include <shellapi.h>
+#include <shlobj.h>
+#include <shlwapi.h>
+#include <wininet.h>
+
+#include <stdlib.h>
+#include <malloc.h>
+#include <memory.h>
+#include <tchar.h>
+
+#endif
View
280 Installer/Util.cpp
@@ -0,0 +1,280 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "StdAfx.h"
+#include "Util.h"
+
+namespace Util {
+
+//
+// System functions.
+//
+
+bool IsSystem64Bit()
+{
+#ifdef _WIN64
+ return true;
+#else
+ BOOL system64 = FALSE;
+
+ typedef BOOL (WINAPI * FPIsWow64Process)(HANDLE hProcess, BOOL* Wow64Process);
+ auto isWow64Process = (FPIsWow64Process)GetProcAddress(
+ GetModuleHandle(L"kernel32"), "IsWow64Process");
+ if (isWow64Process)
+ {
+ isWow64Process(GetCurrentProcess(), &system64);
+ }
+
+ return system64;
+#endif
+}
+
+//
+// Process functions.
+//
+
+bool IsProcessUserAdmin()
+{
+ BOOL runningAsAdmin = FALSE;
+
+ // Allocate and initialize a SID of the administrators group.
+ PSID adminGroupSid = NULL;
+ SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
+ if (AllocateAndInitializeSid(
+ &NtAuthority,
+ 2,
+ SECURITY_BUILTIN_DOMAIN_RID,
+ DOMAIN_ALIAS_RID_ADMINS,
+ 0, 0, 0, 0, 0, 0,
+ &adminGroupSid))
+ {
+ // Check if the primary access token of the process has the admin group SID.
+ if (!CheckTokenMembership(NULL, adminGroupSid, &runningAsAdmin))
+ {
+ runningAsAdmin = TRUE;
+ }
+
+ FreeSid(adminGroupSid);
+ adminGroupSid = NULL;
+ }
+
+ return runningAsAdmin;
+}
+
+bool CanProcessUserElevate()
+{
+ OSVERSIONINFO osvi = {sizeof(osvi)};
+ GetVersionEx(&osvi);
+ if (osvi.dwMajorVersion >= 6)
+ {
+ // Check if UAC is enabled with Vista and above.
+ BOOL uacEnabled = FALSE;
+
+ // First try with undocumented CheckElevationEnabled function.
+ // See: http://blog.airesoft.co.uk/2011/03/uaceen-nothing-yet/
+ typedef DWORD (WINAPI * FPCheckElevationEnabled)(BOOL* pResult);
+ auto checkElevationEnabled = (FPCheckElevationEnabled)GetProcAddress(
+ GetModuleHandle(L"kernel32"), "CheckElevationEnabled");
+ if (checkElevationEnabled && checkElevationEnabled(&uacEnabled) == ERROR_SUCCESS)
+ {
+ return uacEnabled;
+ }
+ else
+ {
+ // Try checking registry.
+ const WCHAR* subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
+ DWORD data;
+ if (GetRegistryDword(HKEY_LOCAL_MACHINE, subKey, L"EnableLUA", &data) == ERROR_SUCCESS &&
+ data != 0)
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+//
+// File and directory functions.
+//
+
+bool CopyDirectory(const WCHAR* fromPath, const WCHAR* toPath)
+{
+ int fromPathLength = wcslen(fromPath);
+ int toPathLength = wcslen(toPath);
+
+ // SHFileOperation expects double null terminated strings.
+ WCHAR* from = (WCHAR*)malloc((fromPathLength + 2) * sizeof(WCHAR));
+ wcscpy(from, fromPath);
+ from[fromPathLength + 2] = L'\0';
+
+ WCHAR* to = (WCHAR*)malloc((toPathLength + 2) * sizeof(WCHAR));
+ wcscpy(to, toPath);
+ to[toPathLength + 2] = L'\0';
+
+ SHFILEOPSTRUCT fo =
+ {
+ NULL,
+ FO_COPY,
+ from,
+ to,
+ FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION
+ };
+
+ BOOL copied = (SHFileOperation(&fo) == 0);
+
+ free(from);
+ free(to);
+
+ return copied;
+}
+
+bool CreateShortcutFile(const WCHAR* filePath, const WCHAR* targetPath)
+{
+ IShellLink* psl;
+ HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
+ if (SUCCEEDED(hr))
+ {
+ IPersistFile* ppf;
+ hr = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
+ if (SUCCEEDED(hr))
+ {
+ psl->SetPath(filePath);
+ hr = ppf->Save(targetPath, TRUE);
+
+ ppf->Release();
+ }
+
+ psl->Release();
+ }
+
+ return SUCCEEDED(hr);
+}
+
+bool IsDirectoryWritable()
+{
+ return TRUE;
+}
+
+//
+// Registry functions.
+//
+
+bool GetRegistryDword(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, DWORD* data)
+{
+ DWORD type;
+ DWORD dataSize = sizeof(DWORD);
+ return (SHGetValue(rootKey, subKey, value, &type, data, &dataSize) == ERROR_SUCCESS &&
+ type == REG_DWORD);
+}
+
+bool GetRegistryString(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, WCHAR* data, DWORD dataSize)
+{
+ DWORD type;
+ return (SHGetValue(rootKey, subKey, value, &type, data, &dataSize) == ERROR_SUCCESS &&
+ type == REG_SZ);
+}
+
+bool SetRegistryData(DWORD type, HKEY rootKey, const WCHAR* subKey, const WCHAR* value, BYTE* data, DWORD dataSize)
+{
+ BOOL result = FALSE;
+ HKEY regKey;
+ if (RegCreateKeyEx(rootKey, subKey, 0, 0, 0, KEY_SET_VALUE, NULL, &regKey, NULL) == ERROR_SUCCESS)
+ {
+ if (RegSetValueEx(regKey, value, 0, type, data, dataSize) == ERROR_SUCCESS)
+ {
+ result = TRUE;
+ }
+
+ RegCloseKey(regKey);
+ }
+
+ return result;
+}
+
+bool SetRegistryDword(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, DWORD data)
+{
+ return SetRegistryData(REG_DWORD, rootKey, subKey, value, (BYTE*)&data, sizeof(DWORD));
+}
+
+bool SetRegistryString(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, const WCHAR* data)
+{
+ DWORD dataSize = (wcslen(data) + 1) * sizeof(WCHAR);
+ return SetRegistryData(REG_SZ, rootKey, subKey, value, (BYTE*)data, dataSize);
+}
+
+//
+// Misc. functions.
+//
+
+bool DownloadFile(const WCHAR* url, const WCHAR* file)
+{
+ bool result = false;
+ HINTERNET hNet = InternetOpen(L"Mozilla/5.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
+ if (hNet)
+ {
+ HANDLE hFile = CreateFile(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (hFile)
+ {
+ HINTERNET hUrl = InternetOpenUrl(hNet, url, NULL, 0, INTERNET_FLAG_RESYNCHRONIZE, 0);
+ if (hUrl)
+ {
+ const DWORD bufferSize = 8192;
+ BYTE* buffer = (BYTE*)malloc(bufferSize);
+ if (buffer)
+ {
+ DWORD readSize;
+ while (InternetReadFile(hUrl, buffer, bufferSize, &readSize))
+ {
+ if (readSize == 0)
+ {
+ // All data read.
+ result = true;
+ break;
+ }
+
+ DWORD writeSize;
+ if (!WriteFile(hFile, buffer, readSize, &writeSize, NULL) ||
+ readSize != writeSize)
+ {
+ break;
+ }
+ }
+
+ free(buffer);
+ }
+
+ InternetCloseHandle(hUrl);
+ }
+
+ CloseHandle(hFile);
+
+ if (!result)
+ {
+ DeleteFile(file);
+ }
+ }
+
+ InternetCloseHandle(hNet);
+ }
+
+ return result;
+}
+
+} // namespace Util
View
41 Installer/Util.h
@@ -0,0 +1,41 @@
+/*
+ Copyright (C) 2013 Birunthan Mohanathas
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef RM_INSTALLER_UTIL_H_
+#define RM_INSTALLER_UTIL_H_
+
+namespace Util {
+
+bool IsSystem64Bit();
+
+bool IsProcessUserAdmin();
+bool CanProcessUserElevate();
+
+bool CopyDirectory(const WCHAR* fromPath, const WCHAR* toPath);
+bool CreateShortcutFile(const WCHAR* filePath, const WCHAR* targetPath);
+
+bool GetRegistryDword(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, DWORD* data);
+bool GetRegistryString(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, WCHAR* data, DWORD dataSize);
+bool SetRegistryDword(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, DWORD data);
+bool SetRegistryString(HKEY rootKey, const WCHAR* subKey, const WCHAR* value, const WCHAR* data);
+
+bool DownloadFile(const WCHAR* url, const WCHAR* file);
+
+} // namespace Util
+
+#endif
View
203 Installer/lzma/7z.h
@@ -0,0 +1,203 @@
+/* 7z.h -- 7z interface
+2010-03-11 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_H
+#define __7Z_H
+
+#include "7zBuf.h"
+
+EXTERN_C_BEGIN
+
+#define k7zStartHeaderSize 0x20
+#define k7zSignatureSize 6
+extern Byte k7zSignature[k7zSignatureSize];
+#define k7zMajorVersion 0
+
+enum EIdEnum
+{
+ k7zIdEnd,
+ k7zIdHeader,
+ k7zIdArchiveProperties,
+ k7zIdAdditionalStreamsInfo,
+ k7zIdMainStreamsInfo,
+ k7zIdFilesInfo,
+ k7zIdPackInfo,
+ k7zIdUnpackInfo,
+ k7zIdSubStreamsInfo,
+ k7zIdSize,
+ k7zIdCRC,
+ k7zIdFolder,
+ k7zIdCodersUnpackSize,
+ k7zIdNumUnpackStream,
+ k7zIdEmptyStream,
+ k7zIdEmptyFile,
+ k7zIdAnti,
+ k7zIdName,
+ k7zIdCTime,
+ k7zIdATime,
+ k7zIdMTime,
+ k7zIdWinAttributes,
+ k7zIdComment,
+ k7zIdEncodedHeader,
+ k7zIdStartPos,
+ k7zIdDummy
+};
+
+typedef struct
+{
+ UInt32 NumInStreams;
+ UInt32 NumOutStreams;
+ UInt64 MethodID;
+ CBuf Props;
+} CSzCoderInfo;
+
+void SzCoderInfo_Init(CSzCoderInfo *p);
+void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);
+
+typedef struct
+{
+ UInt32 InIndex;
+ UInt32 OutIndex;
+} CSzBindPair;
+
+typedef struct
+{
+ CSzCoderInfo *Coders;
+ CSzBindPair *BindPairs;
+ UInt32 *PackStreams;
+ UInt64 *UnpackSizes;
+ UInt32 NumCoders;
+ UInt32 NumBindPairs;
+ UInt32 NumPackStreams;
+ int UnpackCRCDefined;
+ UInt32 UnpackCRC;
+
+ UInt32 NumUnpackStreams;
+} CSzFolder;
+
+void SzFolder_Init(CSzFolder *p);
+UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
+int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
+UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
+UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
+
+SRes SzFolder_Decode(const CSzFolder *folder, const UInt64 *packSizes,
+ ILookInStream *stream, UInt64 startPos,
+ Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);
+
+typedef struct
+{
+ UInt32 Low;
+ UInt32 High;
+} CNtfsFileTime;
+
+typedef struct
+{
+ CNtfsFileTime MTime;
+ UInt64 Size;
+ UInt32 Crc;
+ UInt32 Attrib;
+ Byte HasStream;
+ Byte IsDir;
+ Byte IsAnti;
+ Byte CrcDefined;
+ Byte MTimeDefined;
+ Byte AttribDefined;
+} CSzFileItem;
+
+void SzFile_Init(CSzFileItem *p);
+
+typedef struct
+{
+ UInt64 *PackSizes;
+ Byte *PackCRCsDefined;
+ UInt32 *PackCRCs;
+ CSzFolder *Folders;
+ CSzFileItem *Files;
+ UInt32 NumPackStreams;
+ UInt32 NumFolders;
+ UInt32 NumFiles;
+} CSzAr;
+
+void SzAr_Init(CSzAr *p);
+void SzAr_Free(CSzAr *p, ISzAlloc *alloc);
+
+
+/*
+ SzExtract extracts file from archive
+
+ *outBuffer must be 0 before first call for each new archive.
+
+ Extracting cache:
+ If you need to decompress more than one file, you can send
+ these values from previous call:
+ *blockIndex,
+ *outBuffer,
+ *outBufferSize
+ You can consider "*outBuffer" as cache of solid block. If your archive is solid,
+ it will increase decompression speed.
+
+ If you use external function, you can declare these 3 cache variables
+ (blockIndex, outBuffer, outBufferSize) as static in that external function.
+
+ Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
+*/
+
+typedef struct
+{
+ CSzAr db;
+
+ UInt64 startPosAfterHeader;
+ UInt64 dataPos;
+
+ UInt32 *FolderStartPackStreamIndex;
+ UInt64 *PackStreamStartPositions;
+ UInt32 *FolderStartFileIndex;
+ UInt32 *FileIndexToFolderIndexMap;
+
+ size_t *FileNameOffsets; /* in 2-byte steps */
+ CBuf FileNames; /* UTF-16-LE */
+} CSzArEx;
+
+void SzArEx_Init(CSzArEx *p);
+void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
+UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
+int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);
+
+/*
+if dest == NULL, the return value specifies the required size of the buffer,
+ in 16-bit characters, including the null-terminating character.
+if dest != NULL, the return value specifies the number of 16-bit characters that
+ are written to the dest, including the null-terminating character. */
+
+size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
+
+SRes SzArEx_Extract(
+ const CSzArEx *db,
+ ILookInStream *inStream,
+ UInt32 fileIndex, /* index of file */
+ UInt32 *blockIndex, /* index of solid block */
+ Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
+ size_t *outBufferSize, /* buffer size for output buffer */
+ size_t *offset, /* offset of stream for required file in *outBuffer */
+ size_t *outSizeProcessed, /* size of file in *outBuffer */
+ ISzAlloc *allocMain,
+ ISzAlloc *allocTemp);
+
+
+/*
+SzArEx_Open Errors:
+SZ_ERROR_NO_ARCHIVE
+SZ_ERROR_ARCHIVE
+SZ_ERROR_UNSUPPORTED
+SZ_ERROR_MEM
+SZ_ERROR_CRC
+SZ_ERROR_INPUT_EOF
+SZ_ERROR_FAIL
+*/
+
+SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
+
+EXTERN_C_END
+
+#endif
View
76 Installer/lzma/7zAlloc.c
@@ -0,0 +1,76 @@
+/* 7zAlloc.c -- Allocation functions
+2010-10-29 : Igor Pavlov : Public domain */
+
+#include "7zAlloc.h"
+
+/* #define _SZ_ALLOC_DEBUG */
+/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
+
+#ifdef _SZ_ALLOC_DEBUG
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#include <stdio.h>
+int g_allocCount = 0;
+int g_allocCountTemp = 0;
+
+#endif
+
+void *SzAlloc(void *p, size_t size)
+{
+ p = p;
+ if (size == 0)
+ return 0;
+ #ifdef _SZ_ALLOC_DEBUG
+ fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount);
+ g_allocCount++;
+ #endif
+ return malloc(size);
+}
+
+void SzFree(void *p, void *address)
+{
+ p = p;
+ #ifdef _SZ_ALLOC_DEBUG
+ if (address != 0)
+ {
+ g_allocCount--;
+ fprintf(stderr, "\nFree; count = %10d", g_allocCount);
+ }
+ #endif
+ free(address);
+}
+
+void *SzAllocTemp(void *p, size_t size)
+{
+ p = p;
+ if (size == 0)
+ return 0;
+ #ifdef _SZ_ALLOC_DEBUG
+ fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTemp);
+ g_allocCountTemp++;
+ #ifdef _WIN32
+ return HeapAlloc(GetProcessHeap(), 0, size);
+ #endif
+ #endif
+ return malloc(size);
+}
+
+void SzFreeTemp(void *p, void *address)
+{
+ p = p;
+ #ifdef _SZ_ALLOC_DEBUG
+ if (address != 0)
+ {
+ g_allocCountTemp--;
+ fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp);
+ }
+ #ifdef _WIN32
+ HeapFree(GetProcessHeap(), 0, address);
+ return;
+ #endif
+ #endif
+ free(address);
+}
View
15 Installer/lzma/7zAlloc.h
@@ -0,0 +1,15 @@
+/* 7zAlloc.h -- Allocation functions
+2010-10-29 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_ALLOC_H
+#define __7Z_ALLOC_H
+
+#include <stdlib.h>
+
+void *SzAlloc(void *p, size_t size);
+void SzFree(void *p, void *address);
+
+void *SzAllocTemp(void *p, size_t size);
+void SzFreeTemp(void *p, void *address);
+
+#endif
View
36 Installer/lzma/7zBuf.c
@@ -0,0 +1,36 @@
+/* 7zBuf.c -- Byte Buffer
+2008-03-28
+Igor Pavlov
+Public domain */
+
+#include "7zBuf.h"
+
+void Buf_Init(CBuf *p)
+{
+ p->data = 0;
+ p->size = 0;
+}
+
+int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
+{
+ p->size = 0;
+ if (size == 0)
+ {
+ p->data = 0;
+ return 1;
+ }
+ p->data = (Byte *)alloc->Alloc(alloc, size);
+ if (p->data != 0)
+ {
+ p->size = size;
+ return 1;
+ }
+ return 0;
+}
+
+void Buf_Free(CBuf *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->data);
+ p->data = 0;
+ p->size = 0;
+}
View
39 Installer/lzma/7zBuf.h
@@ -0,0 +1,39 @@
+/* 7zBuf.h -- Byte Buffer
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_BUF_H
+#define __7Z_BUF_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+ Byte *data;
+ size_t size;
+} CBuf;
+
+void Buf_Init(CBuf *p);
+int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
+void Buf_Free(CBuf *p, ISzAlloc *alloc);
+
+typedef struct
+{
+ Byte *data;
+ size_t size;
+ size_t pos;
+} CDynBuf;
+
+void DynBuf_Construct(CDynBuf *p);
+void DynBuf_SeekToBeg(CDynBuf *p);
+int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);
+void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
View
74 Installer/lzma/7zCrc.c
@@ -0,0 +1,74 @@
+/* 7zCrc.c -- CRC32 calculation
+2009-11-23 : Igor Pavlov : Public domain */
+
+#include "7zCrc.h"
+#include "CpuArch.h"
+
+#define kCrcPoly 0xEDB88320
+
+#ifdef MY_CPU_LE
+#define CRC_NUM_TABLES 8
+#else
+#define CRC_NUM_TABLES 1
+#endif
+
+typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table);
+
+static CRC_FUNC g_CrcUpdate;
+UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
+
+#if CRC_NUM_TABLES == 1
+
+#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+static UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+ const Byte *p = (const Byte *)data;
+ for (; size > 0; size--, p++)
+ v = CRC_UPDATE_BYTE_2(v, *p);
+ return v;
+}
+
+#else
+
+UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
+UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
+
+#endif
+
+UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
+{
+ return g_CrcUpdate(v, data, size, g_CrcTable);
+}
+
+UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
+{
+ return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL;
+}
+
+void MY_FAST_CALL CrcGenerateTable()
+{
+ UInt32 i;
+ for (i = 0; i < 256; i++)
+ {
+ UInt32 r = i;
+ unsigned j;
+ for (j = 0; j < 8; j++)
+ r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
+ g_CrcTable[i] = r;
+ }
+ #if CRC_NUM_TABLES == 1
+ g_CrcUpdate = CrcUpdateT1;
+ #else
+ for (; i < 256 * CRC_NUM_TABLES; i++)
+ {
+ UInt32 r = g_CrcTable[i - 256];
+ g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
+ }
+ g_CrcUpdate = CrcUpdateT4;
+ #ifdef MY_CPU_X86_OR_AMD64
+ if (!CPU_Is_InOrder())
+ g_CrcUpdate = CrcUpdateT8;
+ #endif
+ #endif
+}
View
25 Installer/lzma/7zCrc.h
@@ -0,0 +1,25 @@
+/* 7zCrc.h -- CRC32 calculation
+2009-11-21 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_CRC_H
+#define __7Z_CRC_H
+
+#include "Types.h"
+
+EXTERN_C_BEGIN
+
+extern UInt32 g_CrcTable[];
+
+/* Call CrcGenerateTable one time before other CRC functions */
+void MY_FAST_CALL CrcGenerateTable(void);
+
+#define CRC_INIT_VAL 0xFFFFFFFF
+#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)
+#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
+UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
+
+EXTERN_C_END
+
+#endif
View
34 Installer/lzma/7zCrcOpt.c
@@ -0,0 +1,34 @@
+/* 7zCrcOpt.c -- CRC32 calculation : optimized version
+2009-11-23 : Igor Pavlov : Public domain */
+
+#include "CpuArch.h"
+
+#ifdef MY_CPU_LE
+
+#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+ const Byte *p = (const Byte *)data;
+ for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
+ v = CRC_UPDATE_BYTE_2(v, *p);
+ for (; size >= 4; size -= 4, p += 4)
+ {
+ v ^= *(const UInt32 *)p;
+ v =
+ table[0x300 + (v & 0xFF)] ^
+ table[0x200 + ((v >> 8) & 0xFF)] ^
+ table[0x100 + ((v >> 16) & 0xFF)] ^
+ table[0x000 + ((v >> 24))];
+ }
+ for (; size > 0; size--, p++)
+ v = CRC_UPDATE_BYTE_2(v, *p);
+ return v;
+}
+
+UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+ return CrcUpdateT4(v, data, size, table);
+}
+
+#endif
View
477 Installer/lzma/7zDec.c
@@ -0,0 +1,477 @@
+/* 7zDec.c -- Decoding from 7z folder
+2010-11-02 : Igor Pavlov : Public domain */
+
+#include <string.h>
+
+/* #define _7ZIP_PPMD_SUPPPORT */
+
+#include "7z.h"
+
+#include "Bcj2.h"
+#include "Bra.h"
+#include "CpuArch.h"
+#include "LzmaDec.h"
+#include "Lzma2Dec.h"
+#ifdef _7ZIP_PPMD_SUPPPORT
+#include "Ppmd7.h"
+#endif
+
+#define k_Copy 0
+#define k_LZMA2 0x21
+#define k_LZMA 0x30101
+#define k_BCJ 0x03030103
+#define k_PPC 0x03030205
+#define k_ARM 0x03030501
+#define k_ARMT 0x03030701
+#define k_SPARC 0x03030805
+#define k_BCJ2 0x0303011B
+
+#ifdef _7ZIP_PPMD_SUPPPORT
+
+#define k_PPMD 0x30401
+
+typedef struct
+{
+ IByteIn p;
+ const Byte *cur;
+ const Byte *end;
+ const Byte *begin;
+ UInt64 processed;
+ Bool extra;
+ SRes res;
+ ILookInStream *inStream;
+} CByteInToLook;
+
+static Byte ReadByte(void *pp)
+{
+ CByteInToLook *p = (CByteInToLook *)pp;
+ if (p->cur != p->end)
+ return *p->cur++;
+ if (p->res == SZ_OK)
+ {
+ size_t size = p->cur - p->begin;
+ p->processed += size;
+ p->res = p->inStream->Skip(p->inStream, size);
+ size = (1 << 25);
+ p->res = p->inStream->Look(p->inStream, (const void **)&p->begin, &size);
+ p->cur = p->begin;
+ p->end = p->begin + size;
+ if (size != 0)
+ return *p->cur++;;
+ }
+ p->extra = True;
+ return 0;
+}
+
+static SRes SzDecodePpmd(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,
+ Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)
+{
+ CPpmd7 ppmd;
+ CByteInToLook s;
+ SRes res = SZ_OK;
+
+ s.p.Read = ReadByte;
+ s.inStream = inStream;
+ s.begin = s.end = s.cur = NULL;
+ s.extra = False;
+ s.res = SZ_OK;
+ s.processed = 0;
+
+ if (coder->Props.size != 5)
+ return SZ_ERROR_UNSUPPORTED;
+
+ {
+ unsigned order = coder->Props.data[0];
+ UInt32 memSize = GetUi32(coder->Props.data + 1);
+ if (order < PPMD7_MIN_ORDER ||
+ order > PPMD7_MAX_ORDER ||
+ memSize < PPMD7_MIN_MEM_SIZE ||
+ memSize > PPMD7_MAX_MEM_SIZE)
+ return SZ_ERROR_UNSUPPORTED;
+ Ppmd7_Construct(&ppmd);
+ if (!Ppmd7_Alloc(&ppmd, memSize, allocMain))
+ return SZ_ERROR_MEM;
+ Ppmd7_Init(&ppmd, order);
+ }
+ {
+ CPpmd7z_RangeDec rc;
+ Ppmd7z_RangeDec_CreateVTable(&rc);
+ rc.Stream = &s.p;
+ if (!Ppmd7z_RangeDec_Init(&rc))
+ res = SZ_ERROR_DATA;
+ else if (s.extra)
+ res = (s.res != SZ_OK ? s.res : SZ_ERROR_DATA);
+ else
+ {
+ SizeT i;
+ for (i = 0; i < outSize; i++)
+ {
+ int sym = Ppmd7_DecodeSymbol(&ppmd, &rc.p);
+ if (s.extra || sym < 0)
+ break;
+ outBuffer[i] = (Byte)sym;
+ }
+ if (i != outSize)
+ res = (s.res != SZ_OK ? s.res : SZ_ERROR_DATA);
+ else if (s.processed + (s.cur - s.begin) != inSize || !Ppmd7z_RangeDec_IsFinishedOK(&rc))
+ res = SZ_ERROR_DATA;
+ }
+ }
+ Ppmd7_Free(&ppmd, allocMain);
+ return res;
+}
+
+#endif
+
+static SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,
+ Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)
+{
+ CLzmaDec state;
+ SRes res = SZ_OK;
+
+ LzmaDec_Construct(&state);
+ RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
+ state.dic = outBuffer;
+ state.dicBufSize = outSize;
+ LzmaDec_Init(&state);
+
+ for (;;)
+ {
+ Byte *inBuf = NULL;
+ size_t lookahead = (1 << 18);
+ if (lookahead > inSize)
+ lookahead = (size_t)inSize;
+ res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
+ if (res != SZ_OK)
+ break;
+
+ {
+ SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;
+ ELzmaStatus status;
+ res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
+ lookahead -= inProcessed;
+ inSize -= inProcessed;
+ if (res != SZ_OK)
+ break;
+ if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
+ {
+ if (state.dicBufSize != outSize || lookahead != 0 ||
+ (status != LZMA_STATUS_FINISHED_WITH_MARK &&
+ status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
+ res = SZ_ERROR_DATA;
+ break;
+ }
+ res = inStream->Skip((void *)inStream, inProcessed);
+ if (res != SZ_OK)
+ break;
+ }
+ }
+
+ LzmaDec_FreeProbs(&state, allocMain);
+ return res;
+}
+
+#ifdef _7ZIP_LZMA2_SUPPPORT
+
+static SRes SzDecodeLzma2(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,
+ Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)
+{
+ CLzma2Dec state;
+ SRes res = SZ_OK;
+
+ Lzma2Dec_Construct(&state);
+ if (coder->Props.size != 1)
+ return SZ_ERROR_DATA;
+ RINOK(Lzma2Dec_AllocateProbs(&state, coder->Props.data[0], allocMain));
+ state.decoder.dic = outBuffer;
+ state.decoder.dicBufSize = outSize;
+ Lzma2Dec_Init(&state);
+
+ for (;;)
+ {
+ Byte *inBuf = NULL;
+ size_t lookahead = (1 << 18);
+ if (lookahead > inSize)
+ lookahead = (size_t)inSize;
+ res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
+ if (res != SZ_OK)
+ break;
+
+ {
+ SizeT inProcessed = (SizeT)lookahead, dicPos = state.decoder.dicPos;
+ ELzmaStatus status;
+ res = Lzma2Dec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
+ lookahead -= inProcessed;
+ inSize -= inProcessed;
+ if (res != SZ_OK)
+ break;
+ if (state.decoder.dicPos == state.decoder.dicBufSize || (inProcessed == 0 && dicPos == state.decoder.dicPos))
+ {
+ if (state.decoder.dicBufSize != outSize || lookahead != 0 ||
+ (status != LZMA_STATUS_FINISHED_WITH_MARK))
+ res = SZ_ERROR_DATA;
+ break;
+ }
+ res = inStream->Skip((void *)inStream, inProcessed);
+ if (res != SZ_OK)
+ break;
+ }
+ }
+
+ Lzma2Dec_FreeProbs(&state, allocMain);
+ return res;
+}
+
+#endif
+
+static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)
+{
+ while (inSize > 0)
+ {
+ void *inBuf;
+ size_t curSize = (1 << 18);
+ if (curSize > inSize)
+ curSize = (size_t)inSize;
+ RINOK(inStream->Look((void *)inStream, (const void **)&inBuf, &curSize));
+ if (curSize == 0)
+ return SZ_ERROR_INPUT_EOF;
+ memcpy(outBuffer, inBuf, curSize);
+ outBuffer += curSize;
+ inSize -= curSize;
+ RINOK(inStream->Skip((void *)inStream, curSize));
+ }
+ return SZ_OK;
+}
+
+static Bool IS_MAIN_METHOD(UInt32 m)
+{
+ switch(m)
+ {
+ case k_Copy:
+ case k_LZMA:
+ case k_LZMA2:
+ #ifdef _7ZIP_PPMD_SUPPPORT
+ case k_PPMD:
+ #endif
+ return True;
+ }
+ return False;
+}
+
+static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c)
+{
+ return
+ c->NumInStreams == 1 &&
+ c->NumOutStreams == 1 &&
+ c->MethodID <= (UInt32)0xFFFFFFFF &&
+ IS_MAIN_METHOD((UInt32)c->MethodID);
+}
+
+#define IS_BCJ2(c) ((c)->MethodID == k_BCJ2 && (c)->NumInStreams == 4 && (c)->NumOutStreams == 1)
+
+static SRes CheckSupportedFolder(const CSzFolder *f)
+{
+ if (f->NumCoders < 1 || f->NumCoders > 4)
+ return SZ_ERROR_UNSUPPORTED;
+ if (!IS_SUPPORTED_CODER(&f->Coders[0]))
+ return SZ_ERROR_UNSUPPORTED;
+ if (f->NumCoders == 1)
+ {
+ if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)
+ return SZ_ERROR_UNSUPPORTED;
+ return SZ_OK;
+ }
+ if (f->NumCoders == 2)
+ {
+ CSzCoderInfo *c = &f->Coders[1];
+ if (c->MethodID > (UInt32)0xFFFFFFFF ||
+ c->NumInStreams != 1 ||
+ c->NumOutStreams != 1 ||
+ f->NumPackStreams != 1 ||
+ f->PackStreams[0] != 0 ||
+ f->NumBindPairs != 1 ||
+ f->BindPairs[0].InIndex != 1 ||
+ f->BindPairs[0].OutIndex != 0)
+ return SZ_ERROR_UNSUPPORTED;
+ switch ((UInt32)c->MethodID)
+ {
+ case k_BCJ:
+ case k_ARM:
+ break;
+ default:
+ return SZ_ERROR_UNSUPPORTED;
+ }
+ return SZ_OK;
+ }
+ if (f->NumCoders == 4)
+ {
+ if (!IS_SUPPORTED_CODER(&f->Coders[1]) ||
+ !IS_SUPPORTED_CODER(&f->Coders[2]) ||
+ !IS_BCJ2(&f->Coders[3]))
+ return SZ_ERROR_UNSUPPORTED;
+ if (f->NumPackStreams != 4 ||
+ f->PackStreams[0] != 2 ||
+ f->PackStreams[1] != 6 ||
+ f->PackStreams[2] != 1 ||
+ f->PackStreams[3] != 0 ||
+ f->NumBindPairs != 3 ||
+ f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||
+ f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||
+ f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)
+ return SZ_ERROR_UNSUPPORTED;
+ return SZ_OK;
+ }
+ return SZ_ERROR_UNSUPPORTED;
+}
+
+static UInt64 GetSum(const UInt64 *values, UInt32 index)
+{
+ UInt64 sum = 0;
+ UInt32 i;
+ for (i = 0; i < index; i++)
+ sum += values[i];
+ return sum;
+}
+
+#define CASE_BRA_CONV(isa) case k_ ## isa: isa ## _Convert(outBuffer, outSize, 0, 0); break;
+
+static SRes SzFolder_Decode2(const CSzFolder *folder, const UInt64 *packSizes,
+ ILookInStream *inStream, UInt64 startPos,
+ Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,
+ Byte *tempBuf[])
+{
+ UInt32 ci;
+ SizeT tempSizes[3] = { 0, 0, 0};
+ SizeT tempSize3 = 0;
+ Byte *tempBuf3 = 0;
+
+ RINOK(CheckSupportedFolder(folder));
+
+ for (ci = 0; ci < folder->NumCoders; ci++)
+ {
+ CSzCoderInfo *coder = &folder->Coders[ci];
+
+ if (IS_MAIN_METHOD((UInt32)coder->MethodID))
+ {
+ UInt32 si = 0;
+ UInt64 offset;
+ UInt64 inSize;
+ Byte *outBufCur = outBuffer;
+ SizeT outSizeCur = outSize;
+ if (folder->NumCoders == 4)
+ {
+ UInt32 indices[] = { 3, 2, 0 };
+ UInt64 unpackSize = folder->UnpackSizes[ci];
+ si = indices[ci];
+ if (ci < 2)
+ {
+ Byte *temp;
+ outSizeCur = (SizeT)unpackSize;
+ if (outSizeCur != unpackSize)
+ return SZ_ERROR_MEM;
+ temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);
+ if (temp == 0 && outSizeCur != 0)
+ return SZ_ERROR_MEM;
+ outBufCur = tempBuf[1 - ci] = temp;
+ tempSizes[1 - ci] = outSizeCur;
+ }
+ else if (ci == 2)
+ {
+ if (unpackSize > outSize) /* check it */
+ return SZ_ERROR_PARAM;
+ tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
+ tempSize3 = outSizeCur = (SizeT)unpackSize;
+ }
+ else
+ return SZ_ERROR_UNSUPPORTED;
+ }
+ offset = GetSum(packSizes, si);
+ inSize = packSizes[si];
+ RINOK(LookInStream_SeekTo(inStream, startPos + offset));
+
+ if (coder->MethodID == k_Copy)
+ {
+ if (inSize != outSizeCur) /* check it */
+ return SZ_ERROR_DATA;
+ RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
+ }
+ else if (coder->MethodID == k_LZMA)
+ {
+ RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
+ }
+ else if (coder->MethodID == k_LZMA2)
+ {
+ #ifdef _7ZIP_LZMA2_SUPPPORT
+ RINOK(SzDecodeLzma2(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
+ #else
+ return SZ_ERROR_UNSUPPORTED;
+ #endif
+ }
+ else
+ {
+ #ifdef _7ZIP_PPMD_SUPPPORT
+ RINOK(SzDecodePpmd(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
+ #else
+ return SZ_ERROR_UNSUPPORTED;
+ #endif
+ }
+ }
+ else if (coder->MethodID == k_BCJ2)
+ {
+ UInt64 offset = GetSum(packSizes, 1);
+ UInt64 s3Size = packSizes[1];
+ SRes res;
+ if (ci != 3)
+ return SZ_ERROR_UNSUPPORTED;
+ RINOK(LookInStream_SeekTo(inStream, startPos + offset));
+ tempSizes[2] = (SizeT)s3Size;
+ if (tempSizes[2] != s3Size)
+ return SZ_ERROR_MEM;
+ tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);
+ if (tempBuf[2] == 0 && tempSizes[2] != 0)
+ return SZ_ERROR_MEM;
+ res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
+ RINOK(res)
+
+ res = Bcj2_Decode(
+ tempBuf3, tempSize3,
+ tempBuf[0], tempSizes[0],
+ tempBuf[1], tempSizes[1],
+ tempBuf[2], tempSizes[2],
+ outBuffer, outSize);
+ RINOK(res)
+ }
+ else
+ {
+ if (ci != 1)
+ return SZ_ERROR_UNSUPPORTED;
+ switch(coder->MethodID)
+ {
+ case k_BCJ:
+ {
+ UInt32 state;
+ x86_Convert_Init(state);
+ x86_Convert(outBuffer, outSize, 0, &state, 0);
+ break;
+ }
+ CASE_BRA_CONV(ARM)
+ default:
+ return SZ_ERROR_UNSUPPORTED;
+ }
+ }
+ }
+ return SZ_OK;
+}
+
+SRes SzFolder_Decode(const CSzFolder *folder, const UInt64 *packSizes,
+ ILookInStream *inStream, UInt64 startPos,
+ Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
+{
+ Byte *tempBuf[3] = { 0, 0, 0};
+ int i;
+ SRes res = SzFolder_Decode2(folder, packSizes, inStream, startPos,
+ outBuffer, (SizeT)outSize, allocMain, tempBuf);
+ for (i = 0; i < 3; i++)
+ IAlloc_Free(allocMain, tempBuf[i]);
+ return res;
+}
View
288 Installer/lzma/7zFile.c
@@ -0,0 +1,288 @@
+/* 7zFile.c -- File IO
+2009-11-24 : Igor Pavlov : Public domain */
+
+#include "7zFile.h"
+
+#ifndef USE_WINDOWS_FILE
+
+#ifndef UNDER_CE
+#include <errno.h>
+#endif
+
+#else
+
+/*
+ ReadFile and WriteFile functions in Windows have BUG:
+ If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
+ from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
+ (Insufficient system resources exist to complete the requested service).
+ Probably in some version of Windows there are problems with other sizes:
+ for 32 MB (maybe also for 16 MB).
+ And message can be "Network connection was lost"
+*/
+
+#define kChunkSizeMax (1 << 22)
+
+#endif
+
+void File_Construct(CSzFile *p)
+{
+ #ifdef USE_WINDOWS_FILE
+ p->handle = INVALID_HANDLE_VALUE;
+ #else
+ p->file = NULL;
+ #endif
+}
+
+#ifndef _UNICODE
+
+#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
+static WRes File_Open(CSzFile *p, const char *name, int writeMode)
+{
+ #ifdef USE_WINDOWS_FILE
+ p->handle = CreateFileA(name,
+ writeMode ? GENERIC_WRITE : GENERIC_READ,
+ FILE_SHARE_READ, NULL,
+ writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
+ #else
+ p->file = fopen(name, writeMode ? "wb+" : "rb");
+ return (p->file != 0) ? 0 :
+ #ifdef UNDER_CE
+ 2; /* ENOENT */
+ #else
+ errno;
+ #endif
+ #endif
+}
+
+WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }
+WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }
+#endif
+
+#endif
+
+#ifdef USE_WINDOWS_FILE
+static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode)
+{
+ p->handle = CreateFileW(name,
+ writeMode ? GENERIC_WRITE : GENERIC_READ,
+ FILE_SHARE_READ, NULL,
+ writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
+}
+WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); }
+WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); }
+#endif
+
+WRes File_Close(CSzFile *p)
+{
+ #ifdef USE_WINDOWS_FILE
+ if (p->handle != INVALID_HANDLE_VALUE)
+ {
+ if (!CloseHandle(p->handle))
+ return GetLastError();
+ p->handle = INVALID_HANDLE_VALUE;
+ }
+ #else
+ if (p->file != NULL)
+ {
+ int res = fclose(p->file);
+ if (res != 0)
+ return res;
+ p->file = NULL;
+ }
+ #endif
+ return 0;
+}
+
+WRes File_Read(CSzFile *p, void *data, size_t *size)
+{
+ size_t originalSize = *size;
+ if (originalSize == 0)
+ return 0;
+
+ #ifdef USE_WINDOWS_FILE
+
+ *size = 0;
+ do
+ {
+ DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
+ DWORD processed = 0;
+ BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
+ data = (void *)((Byte *)data + processed);
+ originalSize -= processed;
+ *size += processed;
+ if (!res)
+ return GetLastError();
+ if (processed == 0)
+ break;
+ }
+ while (originalSize > 0);
+ return 0;
+
+ #else
+
+ *size = fread(data, 1, originalSize, p->file);
+ if (*size == originalSize)
+ return 0;
+ return ferror(p->file);
+
+ #endif
+}
+
+WRes File_Write(CSzFile *p, const void *data, size_t *size)
+{
+ size_t originalSize = *size;
+ if (originalSize == 0)
+ return 0;
+
+ #ifdef USE_WINDOWS_FILE
+
+ *size = 0;
+ do
+ {
+ DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
+ DWORD processed = 0;
+ BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
+ data = (void *)((Byte *)data + processed);
+ originalSize -= processed;
+ *size += processed;
+ if (!res)
+ return GetLastError();
+ if (processed == 0)
+ break;
+ }
+ while (originalSize > 0);
+ return 0;
+
+ #else
+
+ *size = fwrite(data, 1, originalSize, p->file);
+ if (*size == originalSize)
+ return 0;
+ return ferror(p->file);
+
+ #endif
+}
+
+WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
+{
+ #ifdef USE_WINDOWS_FILE
+
+ LARGE_INTEGER value;
+ DWORD moveMethod;
+ value.LowPart = (DWORD)*pos;
+ value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */
+ switch (origin)
+ {
+ case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
+ case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
+ case SZ_SEEK_END: moveMethod = FILE_END; break;
+ default: return ERROR_INVALID_PARAMETER;
+ }
+ value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
+ if (value.LowPart == 0xFFFFFFFF)
+ {
+ WRes res = GetLastError();
+ if (res != NO_ERROR)
+ return res;
+ }
+ *pos = ((Int64)value.HighPart << 32) | value.LowPart;
+ return 0;
+
+ #else
+
+ int moveMethod;
+ int res;
+ switch (origin)
+ {
+ case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
+ case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
+ case SZ_SEEK_END: moveMethod = SEEK_END; break;
+ default: return 1;
+ }
+ res = fseek(p->file, (long)*pos, moveMethod);
+ *pos = ftell(p->file);
+ return res;
+
+ #endif
+}
+
+WRes File_GetLength(CSzFile *p, UInt64 *length)
+{
+ #ifdef USE_WINDOWS_FILE
+
+ DWORD sizeHigh;
+ DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
+ if (sizeLow == 0xFFFFFFFF)
+ {
+ DWORD res = GetLastError();
+ if (res != NO_ERROR)
+ return res;
+ }
+ *length = (((UInt64)sizeHigh) << 32) + sizeLow;
+ return 0;
+
+ #else
+
+ long pos = ftell(p->file);
+ int res = fseek(p->file, 0, SEEK_END);
+ *length = ftell(p->file);
+ fseek(p->file, pos, SEEK_SET);
+ return res;
+
+ #endif
+}
+
+
+/* ---------- FileSeqInStream ---------- */
+
+static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
+{
+ CFileSeqInStream *p = (CFileSeqInStream *)pp;
+ return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
+}
+
+void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
+{
+ p->s.Read = FileSeqInStream_Read;
+}
+
+
+/* ---------- FileInStream ---------- */
+
+static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
+{
+ CFileInStream *p = (CFileInStream *)pp;
+ return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
+}
+
+static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
+{
+ CFileInStream *p = (CFileInStream *)pp;
+ return File_Seek(&p->file, pos, origin);
+}
+
+void FileInStream_CreateVTable(CFileInStream *p)
+{
+ p->s.Read = FileInStream_Read;
+ p->s.Seek = FileInStream_Seek;
+}
+
+
+/* ---------- FileOutStream ---------- */
+
+static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
+{
+ CFileOutStream *p = (CFileOutStream *)pp;
+ File_Write(&p->file, data, &size);
+ return size;
+}
+
+void FileOutStream_CreateVTable(CFileOutStream *p)
+{
+ p->s.Write = FileOutStream_Write;
+}
View
83 Installer/lzma/7zFile.h
@@ -0,0 +1,83 @@
+/* 7zFile.h -- File IO
+2009-11-24 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_FILE_H
+#define __7Z_FILE_H
+
+#ifdef _WIN32
+#define USE_WINDOWS_FILE
+#endif
+
+#ifdef USE_WINDOWS_FILE
+#include <windows.h>
+#else
+#include <stdio.h>
+#endif
+
+#include "Types.h"
+
+EXTERN_C_BEGIN
+
+/* ---------- File ---------- */
+
+typedef struct
+{
+ #ifdef USE_WINDOWS_FILE
+ HANDLE handle;
+ #else
+ FILE *file;
+ #endif
+} CSzFile;
+
+void File_Construct(CSzFile *p);
+#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
+WRes InFile_Open(CSzFile *p, const char *name);
+WRes OutFile_Open(CSzFile *p, const char *name);
+#endif
+#ifdef USE_WINDOWS_FILE
+WRes InFile_OpenW(CSzFile *p, const WCHAR *name);
+WRes OutFile_OpenW(CSzFile *p, const WCHAR *name);
+#endif
+WRes File_Close(CSzFile *p);
+
+/* reads max(*size, remain file's size) bytes */
+WRes File_Read(CSzFile *p, void *data, size_t *size);
+
+/* writes *size bytes */
+WRes File_Write(CSzFile *p, const void *data, size_t *size);
+
+WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);
+WRes File_GetLength(CSzFile *p, UInt64 *length);
+
+
+/* ---------- FileInStream ---------- */
+
+typedef struct
+{
+ ISeqInStream s;
+ CSzFile file;
+} CFileSeqInStream;
+
+void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
+
+
+typedef struct
+{
+ ISeekInStream s;
+ CSzFile file;
+} CFileInStream;
+
+void FileInStream_CreateVTable(CFileInStream *p);
+
+
+typedef struct
+{
+ ISeqOutStream s;
+ CSzFile file;
+} CFileOutStream;
+
+void FileOutStream_CreateVTable(CFileOutStream *p);
+
+EXTERN_C_END
+
+#endif
View
1,402 Installer/lzma/7zIn.c
@@ -0,0 +1,1402 @@
+/* 7zIn.c -- 7z Input functions
+2010-10-29 : Igor Pavlov : Public domain */
+
+#include <string.h>
+
+#include "7z.h"
+#include "7zCrc.h"
+#include "CpuArch.h"
+
+Byte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
+
+#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }
+
+#define NUM_FOLDER_CODERS_MAX 32
+#define NUM_CODER_STREAMS_MAX 32
+
+void SzCoderInfo_Init(CSzCoderInfo *p)
+{
+ Buf_Init(&p->Props);
+}
+
+void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)
+{
+ Buf_Free(&p->Props, alloc);
+ SzCoderInfo_Init(p);
+}
+
+void SzFolder_Init(CSzFolder *p)
+{
+ p->Coders = 0;
+ p->BindPairs = 0;
+ p->PackStreams = 0;
+ p->UnpackSizes = 0;
+ p->NumCoders = 0;
+ p->NumBindPairs = 0;
+ p->NumPackStreams = 0;
+ p->UnpackCRCDefined = 0;
+ p->UnpackCRC = 0;
+ p->NumUnpackStreams = 0;
+}
+
+void SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)
+{
+ UInt32 i;
+ if (p->Coders)
+ for (i = 0; i < p->NumCoders; i++)
+ SzCoderInfo_Free(&p->Coders[i], alloc);
+ IAlloc_Free(alloc, p->Coders);
+ IAlloc_Free(alloc, p->BindPairs);
+ IAlloc_Free(alloc, p->PackStreams);
+ IAlloc_Free(alloc, p->UnpackSizes);
+ SzFolder_Init(p);
+}
+
+UInt32 SzFolder_GetNumOutStreams(CSzFolder *p)
+{
+ UInt32 result = 0;
+ UInt32 i;
+ for (i = 0; i < p->NumCoders; i++)
+ result += p->Coders[i].NumOutStreams;
+ return result;
+}
+
+int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)
+{