diff --git a/desmume/src/addons/compactFlash.cpp b/desmume/src/addons/compactFlash.cpp
index 46223bf0c..362ad0daa 100644
--- a/desmume/src/addons/compactFlash.cpp
+++ b/desmume/src/addons/compactFlash.cpp
@@ -1,7 +1,4 @@
/* Copyright (C) 2006 yopyop
- yopyop156@ifrance.com
- yopyop156.ifrance.com
-
Copyright (C) 2006 Mic
Copyright (C) 2009 CrazyMax
Copyright (C) 2009 DeSmuME team
diff --git a/desmume/src/addons/expMemory.cpp b/desmume/src/addons/expMemory.cpp
index 9b5ee670d..5826d18aa 100644
--- a/desmume/src/addons/expMemory.cpp
+++ b/desmume/src/addons/expMemory.cpp
@@ -1,8 +1,4 @@
-/* Copyright (C) 2006 yopyop
- yopyop156@ifrance.com
- yopyop156.ifrance.com
-
- Copyright (C) 2009 CrazyMax
+/* Copyright (C) 2009 CrazyMax
Copyright (C) 2009 DeSmuME team
This file is part of DeSmuME
diff --git a/desmume/src/addons/gbagame.cpp b/desmume/src/addons/gbagame.cpp
index 8d3b4d21a..457e1d566 100644
--- a/desmume/src/addons/gbagame.cpp
+++ b/desmume/src/addons/gbagame.cpp
@@ -1,8 +1,4 @@
-/* Copyright (C) 2006 yopyop
- yopyop156@ifrance.com
- yopyop156.ifrance.com
-
- Copyright (C) 2009 CrazyMax
+/* Copyright (C) 2009 CrazyMax
Copyright (C) 2009 DeSmuME team
This file is part of DeSmuME
diff --git a/desmume/src/addons/guitarGrip.cpp b/desmume/src/addons/guitarGrip.cpp
index be629e46d..9000ef8c0 100644
--- a/desmume/src/addons/guitarGrip.cpp
+++ b/desmume/src/addons/guitarGrip.cpp
@@ -1,8 +1,4 @@
-/* Copyright (C) 2006 yopyop
- yopyop156@ifrance.com
- yopyop156.ifrance.com
-
- Copyright (C) 2009 CrazyMax
+/* Copyright (C) 2009 CrazyMax
Copyright (C) 2009 DeSmuME team
This file is part of DeSmuME
diff --git a/desmume/src/addons/none.cpp b/desmume/src/addons/none.cpp
index 1393fbe7e..66015e1cd 100644
--- a/desmume/src/addons/none.cpp
+++ b/desmume/src/addons/none.cpp
@@ -1,8 +1,4 @@
-/* Copyright (C) 2006 yopyop
- yopyop156@ifrance.com
- yopyop156.ifrance.com
-
- Copyright (C) 2009 CrazyMax
+/* Copyright (C) 2009 CrazyMax
Copyright (C) 2009 DeSmuME team
This file is part of DeSmuME
diff --git a/desmume/src/addons/rumblepak.cpp b/desmume/src/addons/rumblepak.cpp
index 6c31fb19c..f8291111c 100644
--- a/desmume/src/addons/rumblepak.cpp
+++ b/desmume/src/addons/rumblepak.cpp
@@ -1,8 +1,4 @@
-/* Copyright (C) 2006 yopyop
- yopyop156@ifrance.com
- yopyop156.ifrance.com
-
- Copyright (C) 2009 CrazyMax
+/* Copyright (C) 2009 CrazyMax
Copyright (C) 2009 DeSmuME team
This file is part of DeSmuME
diff --git a/desmume/src/utils/decrypt/crc.cpp b/desmume/src/utils/decrypt/crc.cpp
index 30f62cf9e..52f3fd37b 100644
--- a/desmume/src/utils/decrypt/crc.cpp
+++ b/desmume/src/utils/decrypt/crc.cpp
@@ -1,5 +1,5 @@
//taken from ndstool
-//http://devkitpro.cvs.sourceforge.net/viewvc/devkitpro/tools/nds/ndstool/source/crc.cpp?revision=1.2
+//http://devkitpro.svn.sourceforge.net/viewvc/devkitpro/trunk/tools/nds/ndstool/source/crc.cpp?revision=1587
/* crc.cpp - this file is part of DeSmuME
*
diff --git a/desmume/src/utils/decrypt/crc.h b/desmume/src/utils/decrypt/crc.h
index 38da26d76..e7ca5779e 100644
--- a/desmume/src/utils/decrypt/crc.h
+++ b/desmume/src/utils/decrypt/crc.h
@@ -1,5 +1,5 @@
//taken from ndstool
-//http://devkitpro.cvs.sourceforge.net/viewvc/devkitpro/tools/nds/ndstool/include/crc.h?revision=1.3
+//http://devkitpro.svn.sourceforge.net/viewvc/devkitpro/trunk/tools/nds/ndstool/include/crc.h?revision=2447
/* crc.h - this file is part of DeSmuME
*
diff --git a/desmume/src/utils/decrypt/decrypt.cpp b/desmume/src/utils/decrypt/decrypt.cpp
index 9a0de58e1..00c83f035 100644
--- a/desmume/src/utils/decrypt/decrypt.cpp
+++ b/desmume/src/utils/decrypt/decrypt.cpp
@@ -1,5 +1,5 @@
//taken from ndstool
-//http://devkitpro.cvs.sourceforge.net/viewvc/devkitpro/tools/nds/ndstool/source/encryption.cpp?revision=1.2
+//http://devkitpro.svn.sourceforge.net/viewvc/devkitpro/trunk/tools/nds/ndstool/source/encryption.cpp?revision=1565
/* decrypt.cpp - this file is part of DeSmuME
*
diff --git a/desmume/src/utils/decrypt/header.cpp b/desmume/src/utils/decrypt/header.cpp
index 484e7e0e8..c64dd7730 100644
--- a/desmume/src/utils/decrypt/header.cpp
+++ b/desmume/src/utils/decrypt/header.cpp
@@ -1,5 +1,5 @@
//taken from ndstool
-//http://devkitpro.cvs.sourceforge.net/viewvc/devkitpro/tools/nds/ndstool/source/header.cpp?revision=1.23
+//http://devkitpro.svn.sourceforge.net/viewvc/devkitpro/trunk/tools/nds/ndstool/source/header.cpp?revision=3063
/* header.cpp - this file is part of DeSmuME
*
diff --git a/desmume/src/utils/decrypt/header.h b/desmume/src/utils/decrypt/header.h
index a8eb9c380..bca8ee524 100644
--- a/desmume/src/utils/decrypt/header.h
+++ b/desmume/src/utils/decrypt/header.h
@@ -1,5 +1,5 @@
//taken from ndstool
-//http://devkitpro.cvs.sourceforge.net/viewvc/devkitpro/tools/nds/ndstool/include/header.h?revision=1.14
+//http://devkitpro.svn.sourceforge.net/viewvc/devkitpro/trunk/tools/nds/ndstool/include/header.h?revision=2447
/* header.h - this file is part of DeSmuME
*
diff --git a/desmume/src/windows/7z/7z-4.64_from_tastools b/desmume/src/windows/7z/7z-4.64_from_tastools
new file mode 100644
index 000000000..e69de29bb
diff --git a/desmume/src/windows/7z/7zip.lib b/desmume/src/windows/7z/7z-vc8-Win32.lib
similarity index 74%
rename from desmume/src/windows/7z/7zip.lib
rename to desmume/src/windows/7z/7z-vc8-Win32.lib
index abcc91a6d..ec3d32ee9 100644
Binary files a/desmume/src/windows/7z/7zip.lib and b/desmume/src/windows/7z/7z-vc8-Win32.lib differ
diff --git a/desmume/src/windows/7z/7zip-x64.lib b/desmume/src/windows/7z/7z-vc8-x64.lib
similarity index 82%
rename from desmume/src/windows/7z/7zip-x64.lib
rename to desmume/src/windows/7z/7z-vc8-x64.lib
index f971840f9..fc6bd7696 100644
Binary files a/desmume/src/windows/7z/7zip-x64.lib and b/desmume/src/windows/7z/7z-vc8-x64.lib differ
diff --git a/desmume/src/windows/7z/7zip.sln b/desmume/src/windows/7z/7zip.sln
deleted file mode 100644
index 510da469c..000000000
--- a/desmume/src/windows/7z/7zip.sln
+++ /dev/null
@@ -1,26 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 9.00
-# Visual Studio 2005
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib7zip", "7zip.vcproj", "{5646C572-A578-49F8-9DA9-3E00A8CBFE3F}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Win32 = Debug|Win32
- Debug|x64 = Debug|x64
- Release|Win32 = Release|Win32
- Release|x64 = Release|x64
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Debug|Win32.ActiveCfg = Debug|Win32
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Debug|Win32.Build.0 = Debug|Win32
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Debug|x64.ActiveCfg = Debug|x64
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Debug|x64.Build.0 = Debug|x64
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Release|Win32.ActiveCfg = Release|Win32
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Release|Win32.Build.0 = Release|Win32
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Release|x64.ActiveCfg = Release|x64
- {5646C572-A578-49F8-9DA9-3E00A8CBFE3F}.Release|x64.Build.0 = Release|x64
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/desmume/src/windows/7z/7zip.vcproj b/desmume/src/windows/7z/7zip.vcproj
deleted file mode 100644
index c83181604..000000000
--- a/desmume/src/windows/7z/7zip.vcproj
+++ /dev/null
@@ -1,6611 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/desmume/src/windows/7z/C/7zCrc.c b/desmume/src/windows/7z/C/7zCrc.c
deleted file mode 100644
index 92c47de0d..000000000
--- a/desmume/src/windows/7z/C/7zCrc.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* 7zCrc.c -- CRC32 calculation
-2008-08-05
-Igor Pavlov
-Public domain */
-
-#include "7zCrc.h"
-
-#define kCrcPoly 0xEDB88320
-UInt32 g_CrcTable[256];
-
-void MY_FAST_CALL CrcGenerateTable(void)
-{
- UInt32 i;
- for (i = 0; i < 256; i++)
- {
- UInt32 r = i;
- int j;
- for (j = 0; j < 8; j++)
- r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
- g_CrcTable[i] = r;
- }
-}
-
-UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
-{
- const Byte *p = (const Byte *)data;
- for (; size > 0 ; size--, p++)
- v = CRC_UPDATE_BYTE(v, *p);
- return v;
-}
-
-UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
-{
- return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;
-}
diff --git a/desmume/src/windows/7z/C/7zCrc.h b/desmume/src/windows/7z/C/7zCrc.h
deleted file mode 100644
index ae230991e..000000000
--- a/desmume/src/windows/7z/C/7zCrc.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* 7zCrc.h -- CRC32 calculation
-2008-03-13
-Igor Pavlov
-Public domain */
-
-#ifndef __7Z_CRC_H
-#define __7Z_CRC_H
-
-#include
-
-#include "Types.h"
-
-extern UInt32 g_CrcTable[];
-
-void MY_FAST_CALL CrcGenerateTable(void);
-
-#define CRC_INIT_VAL 0xFFFFFFFF
-#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)
-#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);
-
-#endif
diff --git a/desmume/src/windows/7z/C/Aes.c b/desmume/src/windows/7z/C/Aes.c
deleted file mode 100644
index 8c185f20b..000000000
--- a/desmume/src/windows/7z/C/Aes.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/* Aes.c -- AES encryption / decryption
-2008-08-05
-Igor Pavlov
-Public domain */
-
-#include "Aes.h"
-#include "CpuArch.h"
-
-static UInt32 T[256 * 4];
-static Byte Sbox[256] = {
- 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
- 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
- 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
- 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
- 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
- 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
- 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
- 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
- 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
- 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
- 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
- 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
- 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
- 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
- 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
- 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16};
-
-static UInt32 D[256 * 4];
-static Byte InvS[256];
-
-static Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
-
-#define xtime(x) ((((x) << 1) ^ (((x) & 0x80) != 0 ? 0x1B : 0)) & 0xFF)
-
-#define Ui32(a0, a1, a2, a3) ((UInt32)(a0) | ((UInt32)(a1) << 8) | ((UInt32)(a2) << 16) | ((UInt32)(a3) << 24))
-
-#define gb0(x) ( (x) & 0xFF)
-#define gb1(x) (((x) >> ( 8)) & 0xFF)
-#define gb2(x) (((x) >> (16)) & 0xFF)
-#define gb3(x) (((x) >> (24)) & 0xFF)
-
-void AesGenTables(void)
-{
- unsigned i;
- for (i = 0; i < 256; i++)
- InvS[Sbox[i]] = (Byte)i;
- for (i = 0; i < 256; i++)
- {
- {
- UInt32 a1 = Sbox[i];
- UInt32 a2 = xtime(a1);
- UInt32 a3 = xtime(a1) ^ a1;
- T[ i] = Ui32(a2, a1, a1, a3);
- T[0x100 + i] = Ui32(a3, a2, a1, a1);
- T[0x200 + i] = Ui32(a1, a3, a2, a1);
- T[0x300 + i] = Ui32(a1, a1, a3, a2);
- }
- {
- UInt32 a1 = InvS[i];
- UInt32 a2 = xtime(a1);
- UInt32 a4 = xtime(a2);
- UInt32 a8 = xtime(a4);
- UInt32 a9 = a8 ^ a1;
- UInt32 aB = a8 ^ a2 ^ a1;
- UInt32 aD = a8 ^ a4 ^ a1;
- UInt32 aE = a8 ^ a4 ^ a2;
- D[ i] = Ui32(aE, a9, aD, aB);
- D[0x100 + i] = Ui32(aB, aE, a9, aD);
- D[0x200 + i] = Ui32(aD, aB, aE, a9);
- D[0x300 + i] = Ui32(a9, aD, aB, aE);
- }
- }
-}
-
-#define HT(i, x, s) (T + (x << 8))[gb ## x(s[(i + x) & 3])]
-#define HT4(m, i, s, p) m[i] = \
- HT(i, 0, s) ^ \
- HT(i, 1, s) ^ \
- HT(i, 2, s) ^ \
- HT(i, 3, s) ^ w[p + i]
-/* such order (2031) in HT16 is for VC6/K8 speed optimization) */
-#define HT16(m, s, p) \
- HT4(m, 2, s, p); \
- HT4(m, 0, s, p); \
- HT4(m, 3, s, p); \
- HT4(m, 1, s, p); \
-
-#define FT(i, x) Sbox[gb ## x(m[(i + x) & 3])]
-#define FT4(i) dest[i] = Ui32(FT(i, 0), FT(i, 1), FT(i, 2), FT(i, 3)) ^ w[i];
-
-#define HD(i, x, s) (D + (x << 8))[gb ## x(s[(i - x) & 3])]
-#define HD4(m, i, s, p) m[i] = \
- HD(i, 0, s) ^ \
- HD(i, 1, s) ^ \
- HD(i, 2, s) ^ \
- HD(i, 3, s) ^ w[p + i];
-/* such order (0231) in HD16 is for VC6/K8 speed optimization) */
-#define HD16(m, s, p) \
- HD4(m, 0, s, p); \
- HD4(m, 2, s, p); \
- HD4(m, 3, s, p); \
- HD4(m, 1, s, p); \
-
-#define FD(i, x) InvS[gb ## x(m[(i - x) & 3])]
-#define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i];
-
-void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize)
-{
- unsigned i, wSize;
- UInt32 *w;
- keySize /= 4;
- p->numRounds2 = keySize / 2 + 3;
-
- wSize = (p->numRounds2 * 2 + 1) * 4;
- w = p->rkey;
-
- for (i = 0; i < keySize; i++, key += 4)
- w[i] = Ui32(key[0], key[1], key[2], key[3]);
-
- for (; i < wSize; i++)
- {
- UInt32 t = w[i - 1];
- unsigned rem = i % keySize;
- if (rem == 0)
- t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]);
- else if (keySize > 6 && rem == 4)
- t = Ui32(Sbox[gb0(t)], Sbox[gb1(t)], Sbox[gb2(t)], Sbox[gb3(t)]);
- w[i] = w[i - keySize] ^ t;
- }
-}
-
-void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize)
-{
- unsigned i, num;
- UInt32 *w;
- Aes_SetKeyEncode(p, key, keySize);
- num = p->numRounds2 * 8 - 4;
- w = p->rkey + 4;
- for (i = 0; i < num; i++)
- {
- UInt32 r = w[i];
- w[i] =
- D[ Sbox[gb0(r)]] ^
- D[0x100 + Sbox[gb1(r)]] ^
- D[0x200 + Sbox[gb2(r)]] ^
- D[0x300 + Sbox[gb3(r)]];
- }
-}
-
-static void AesEncode32(UInt32 *dest, const UInt32 *src, const UInt32 *w, unsigned numRounds2)
-{
- UInt32 s[4];
- UInt32 m[4];
- s[0] = src[0] ^ w[0];
- s[1] = src[1] ^ w[1];
- s[2] = src[2] ^ w[2];
- s[3] = src[3] ^ w[3];
- w += 4;
- for (;;)
- {
- HT16(m, s, 0);
- if (--numRounds2 == 0)
- break;
- HT16(s, m, 4);
- w += 8;
- }
- w += 4;
- FT4(0); FT4(1); FT4(2); FT4(3);
-}
-
-static void AesDecode32(UInt32 *dest, const UInt32 *src, const UInt32 *w, unsigned numRounds2)
-{
- UInt32 s[4];
- UInt32 m[4];
- w += numRounds2 * 8;
- s[0] = src[0] ^ w[0];
- s[1] = src[1] ^ w[1];
- s[2] = src[2] ^ w[2];
- s[3] = src[3] ^ w[3];
- for (;;)
- {
- w -= 8;
- HD16(m, s, 4);
- if (--numRounds2 == 0)
- break;
- HD16(s, m, 0);
- }
- FD4(0); FD4(1); FD4(2); FD4(3);
-}
-
-void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src)
-{
- AesEncode32(dest, src, p->rkey, p->numRounds2);
-}
-
-void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src)
-{
- AesDecode32(dest, src, p->rkey, p->numRounds2);
-}
-
-void AesCbc_Init(CAesCbc *p, const Byte *iv)
-{
- unsigned i;
- for (i = 0; i < 4; i++)
- p->prev[i] = GetUi32(iv + i * 4);
-}
-
-SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size)
-{
- SizeT i;
- if (size == 0)
- return 0;
- if (size < AES_BLOCK_SIZE)
- return AES_BLOCK_SIZE;
- size -= AES_BLOCK_SIZE;
- for (i = 0; i <= size; i += AES_BLOCK_SIZE, data += AES_BLOCK_SIZE)
- {
- p->prev[0] ^= GetUi32(data);
- p->prev[1] ^= GetUi32(data + 4);
- p->prev[2] ^= GetUi32(data + 8);
- p->prev[3] ^= GetUi32(data + 12);
-
- AesEncode32(p->prev, p->prev, p->aes.rkey, p->aes.numRounds2);
-
- SetUi32(data, p->prev[0]);
- SetUi32(data + 4, p->prev[1]);
- SetUi32(data + 8, p->prev[2]);
- SetUi32(data + 12, p->prev[3]);
- }
- return i;
-}
-
-SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size)
-{
- SizeT i;
- UInt32 in[4], out[4];
- if (size == 0)
- return 0;
- if (size < AES_BLOCK_SIZE)
- return AES_BLOCK_SIZE;
- size -= AES_BLOCK_SIZE;
- for (i = 0; i <= size; i += AES_BLOCK_SIZE, data += AES_BLOCK_SIZE)
- {
- in[0] = GetUi32(data);
- in[1] = GetUi32(data + 4);
- in[2] = GetUi32(data + 8);
- in[3] = GetUi32(data + 12);
-
- AesDecode32(out, in, p->aes.rkey, p->aes.numRounds2);
-
- SetUi32(data, p->prev[0] ^ out[0]);
- SetUi32(data + 4, p->prev[1] ^ out[1]);
- SetUi32(data + 8, p->prev[2] ^ out[2]);
- SetUi32(data + 12, p->prev[3] ^ out[3]);
-
- p->prev[0] = in[0];
- p->prev[1] = in[1];
- p->prev[2] = in[2];
- p->prev[3] = in[3];
- }
- return i;
-}
diff --git a/desmume/src/windows/7z/C/Aes.h b/desmume/src/windows/7z/C/Aes.h
deleted file mode 100644
index 98ef0c6ea..000000000
--- a/desmume/src/windows/7z/C/Aes.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Aes.h -- AES encryption / decryption
-2008-08-05
-Igor Pavlov
-Public domain */
-
-#ifndef __AES_H
-#define __AES_H
-
-#include "Types.h"
-
-#define AES_BLOCK_SIZE 16
-
-typedef struct
-{
- unsigned numRounds2; /* = numRounds / 2 */
- UInt32 rkey[(14 + 1) * 4];
-} CAes;
-
-/* Call AesGenTables one time before other AES functions */
-void AesGenTables(void);
-
-/* keySize = 16 or 24 or 32 (bytes) */
-void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
-void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize);
-
-/* Aes_Encode32 and Aes_Decode32 functions work with little-endian words.
- src and dest are pointers to 4 UInt32 words.
- arc and dest can point to same block */
-void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src);
-void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src);
-
-typedef struct
-{
- UInt32 prev[4];
- CAes aes;
-} CAesCbc;
-
-void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
-
-/* AesCbc_Encode and AesCbc_Decode:
- if (res <= size): Filter have converted res bytes
- if (res > size): Filter have not converted anything. And it needs at
- least res = AES_BLOCK_SIZE bytes to convert one block */
-
-SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size);
-SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size);
-
-#endif
diff --git a/desmume/src/windows/7z/C/Alloc.c b/desmume/src/windows/7z/C/Alloc.c
deleted file mode 100644
index bb24a772b..000000000
--- a/desmume/src/windows/7z/C/Alloc.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/* Alloc.c -- Memory allocation functions
-2008-09-24
-Igor Pavlov
-Public domain */
-
-#ifdef _WIN32
-#include
-#endif
-#include
-
-#include "Alloc.h"
-
-/* #define _SZ_ALLOC_DEBUG */
-
-/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
-#ifdef _SZ_ALLOC_DEBUG
-#include
-int g_allocCount = 0;
-int g_allocCountMid = 0;
-int g_allocCountBig = 0;
-#endif
-
-void *MyAlloc(size_t size)
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- {
- void *p = malloc(size);
- fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p);
- return p;
- }
- #else
- return malloc(size);
- #endif
-}
-
-void MyFree(void *address)
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address);
- #endif
- free(address);
-}
-
-#ifdef _WIN32
-
-void *MidAlloc(size_t size)
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
- #endif
- return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void MidFree(void *address)
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
- #endif
- if (address == 0)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#ifndef MEM_LARGE_PAGES
-#undef _7ZIP_LARGE_PAGES
-#endif
-
-#ifdef _7ZIP_LARGE_PAGES
-SIZE_T g_LargePageSize = 0;
-typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
-#endif
-
-void SetLargePageSize()
-{
- #ifdef _7ZIP_LARGE_PAGES
- SIZE_T size = 0;
- GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
- GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
- if (largePageMinimum == 0)
- return;
- size = largePageMinimum();
- if (size == 0 || (size & (size - 1)) != 0)
- return;
- g_LargePageSize = size;
- #endif
-}
-
-
-void *BigAlloc(size_t size)
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
- #endif
-
- #ifdef _7ZIP_LARGE_PAGES
- if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
- {
- void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
- MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
- if (res != 0)
- return res;
- }
- #endif
- return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void BigFree(void *address)
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
- #endif
-
- if (address == 0)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#endif
diff --git a/desmume/src/windows/7z/C/Alloc.h b/desmume/src/windows/7z/C/Alloc.h
deleted file mode 100644
index a396c6b9e..000000000
--- a/desmume/src/windows/7z/C/Alloc.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Alloc.h -- Memory allocation functions
-2008-03-13
-Igor Pavlov
-Public domain */
-
-#ifndef __COMMON_ALLOC_H
-#define __COMMON_ALLOC_H
-
-#include
-
-void *MyAlloc(size_t size);
-void MyFree(void *address);
-
-#ifdef _WIN32
-
-void SetLargePageSize();
-
-void *MidAlloc(size_t size);
-void MidFree(void *address);
-void *BigAlloc(size_t size);
-void BigFree(void *address);
-
-#else
-
-#define MidAlloc(size) MyAlloc(size)
-#define MidFree(address) MyFree(address)
-#define BigAlloc(size) MyAlloc(size)
-#define BigFree(address) MyFree(address)
-
-#endif
-
-#endif
diff --git a/desmume/src/windows/7z/C/Bra.c b/desmume/src/windows/7z/C/Bra.c
deleted file mode 100644
index 3b75f0ccb..000000000
--- a/desmume/src/windows/7z/C/Bra.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Bra.c -- Converters for RISC code
-2008-10-04 : Igor Pavlov : Public domain */
-
-#include "Bra.h"
-
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 4)
- return 0;
- size -= 4;
- ip += 8;
- for (i = 0; i <= size; i += 4)
- {
- if (data[i + 3] == 0xEB)
- {
- UInt32 dest;
- UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
- src <<= 2;
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
- dest >>= 2;
- data[i + 2] = (Byte)(dest >> 16);
- data[i + 1] = (Byte)(dest >> 8);
- data[i + 0] = (Byte)dest;
- }
- }
- return i;
-}
-
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 4)
- return 0;
- size -= 4;
- ip += 4;
- for (i = 0; i <= size; i += 2)
- {
- if ((data[i + 1] & 0xF8) == 0xF0 &&
- (data[i + 3] & 0xF8) == 0xF8)
- {
- UInt32 dest;
- UInt32 src =
- (((UInt32)data[i + 1] & 0x7) << 19) |
- ((UInt32)data[i + 0] << 11) |
- (((UInt32)data[i + 3] & 0x7) << 8) |
- (data[i + 2]);
-
- src <<= 1;
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
- dest >>= 1;
-
- data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
- data[i + 0] = (Byte)(dest >> 11);
- data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
- data[i + 2] = (Byte)dest;
- i += 2;
- }
- }
- return i;
-}
-
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 4)
- return 0;
- size -= 4;
- for (i = 0; i <= size; i += 4)
- {
- if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
- {
- UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
- ((UInt32)data[i + 1] << 16) |
- ((UInt32)data[i + 2] << 8) |
- ((UInt32)data[i + 3] & (~3));
-
- UInt32 dest;
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
- data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
- data[i + 1] = (Byte)(dest >> 16);
- data[i + 2] = (Byte)(dest >> 8);
- data[i + 3] &= 0x3;
- data[i + 3] |= dest;
- }
- }
- return i;
-}
-
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- UInt32 i;
- if (size < 4)
- return 0;
- size -= 4;
- for (i = 0; i <= size; i += 4)
- {
- if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
- data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
- {
- UInt32 src =
- ((UInt32)data[i + 0] << 24) |
- ((UInt32)data[i + 1] << 16) |
- ((UInt32)data[i + 2] << 8) |
- ((UInt32)data[i + 3]);
- UInt32 dest;
-
- src <<= 2;
- if (encoding)
- dest = ip + i + src;
- else
- dest = src - (ip + i);
- dest >>= 2;
-
- dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
-
- data[i + 0] = (Byte)(dest >> 24);
- data[i + 1] = (Byte)(dest >> 16);
- data[i + 2] = (Byte)(dest >> 8);
- data[i + 3] = (Byte)dest;
- }
- }
- return i;
-}
diff --git a/desmume/src/windows/7z/C/Bra.h b/desmume/src/windows/7z/C/Bra.h
deleted file mode 100644
index b9018eb99..000000000
--- a/desmume/src/windows/7z/C/Bra.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Bra.h -- Branch converters for executables
-2008-10-04 : Igor Pavlov : Public domain */
-
-#ifndef __BRA_H
-#define __BRA_H
-
-#include "Types.h"
-
-/*
-These functions convert relative addresses to absolute addresses
-in CALL instructions to increase the compression ratio.
-
- In:
- data - data buffer
- size - size of data
- ip - current virtual Instruction Pinter (IP) value
- state - state variable for x86 converter
- encoding - 0 (for decoding), 1 (for encoding)
-
- Out:
- state - state variable for x86 converter
-
- Returns:
- The number of processed bytes. If you call these functions with multiple calls,
- you must start next call with first byte after block of processed bytes.
-
- Type Endian Alignment LookAhead
-
- x86 little 1 4
- ARMT little 2 2
- ARM little 4 0
- PPC big 4 0
- SPARC big 4 0
- IA64 little 16 0
-
- size must be >= Alignment + LookAhead, if it's not last block.
- If (size < Alignment + LookAhead), converter returns 0.
-
- Example:
-
- UInt32 ip = 0;
- for ()
- {
- ; size must be >= Alignment + LookAhead, if it's not last block
- SizeT processed = Convert(data, size, ip, 1);
- data += processed;
- size -= processed;
- ip += processed;
- }
-*/
-
-#define x86_Convert_Init(state) { state = 0; }
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-
-#endif
diff --git a/desmume/src/windows/7z/C/Bra86.c b/desmume/src/windows/7z/C/Bra86.c
deleted file mode 100644
index c3eda016e..000000000
--- a/desmume/src/windows/7z/C/Bra86.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Bra86.c -- Converter for x86 code (BCJ)
-2008-10-04 : Igor Pavlov : Public domain */
-
-#include "Bra.h"
-
-#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
-
-const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
-const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
-
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
-{
- SizeT bufferPos = 0, prevPosT;
- UInt32 prevMask = *state & 0x7;
- if (size < 5)
- return 0;
- ip += 5;
- prevPosT = (SizeT)0 - 1;
-
- for (;;)
- {
- Byte *p = data + bufferPos;
- Byte *limit = data + size - 4;
- for (; p < limit; p++)
- if ((*p & 0xFE) == 0xE8)
- break;
- bufferPos = (SizeT)(p - data);
- if (p >= limit)
- break;
- prevPosT = bufferPos - prevPosT;
- if (prevPosT > 3)
- prevMask = 0;
- else
- {
- prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
- if (prevMask != 0)
- {
- Byte b = p[4 - kMaskToBitNumber[prevMask]];
- if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
- {
- prevPosT = bufferPos;
- prevMask = ((prevMask << 1) & 0x7) | 1;
- bufferPos++;
- continue;
- }
- }
- }
- prevPosT = bufferPos;
-
- if (Test86MSByte(p[4]))
- {
- UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
- UInt32 dest;
- for (;;)
- {
- Byte b;
- int index;
- if (encoding)
- dest = (ip + (UInt32)bufferPos) + src;
- else
- dest = src - (ip + (UInt32)bufferPos);
- if (prevMask == 0)
- break;
- index = kMaskToBitNumber[prevMask] * 8;
- b = (Byte)((dest >> (24 - index)) & 0xFF);
- if (!Test86MSByte(b))
- break;
- src = dest ^ ((1 << (32 - index)) - 1);
- }
- p[4] = (Byte)((~(((dest >> 24) & 1) - 1)) & 0xFF);
- p[3] = (Byte)((dest >> 16) & 0xFF);
- p[2] = (Byte)((dest >> 8) & 0xFF);
- p[1] = (Byte)(dest & 0xFF);
- bufferPos += 5;
- }
- else
- {
- prevMask = ((prevMask << 1) & 0x7) | 1;
- bufferPos++;
- }
- }
- prevPosT = bufferPos - prevPosT;
- *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
- return bufferPos;
-}
diff --git a/desmume/src/windows/7z/C/BraIA64.c b/desmume/src/windows/7z/C/BraIA64.c
deleted file mode 100644
index f359f16a3..000000000
--- a/desmume/src/windows/7z/C/BraIA64.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* BraIA64.c -- Converter for IA-64 code
-2008-10-04 : Igor Pavlov : Public domain */
-
-#include "Bra.h"
-
-static const Byte kBranchTable[32] =
-{
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 4, 4, 6, 6, 0, 0, 7, 7,
- 4, 4, 0, 0, 4, 4, 0, 0
-};
-
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 16)
- return 0;
- size -= 16;
- for (i = 0; i <= size; i += 16)
- {
- UInt32 instrTemplate = data[i] & 0x1F;
- UInt32 mask = kBranchTable[instrTemplate];
- UInt32 bitPos = 5;
- int slot;
- for (slot = 0; slot < 3; slot++, bitPos += 41)
- {
- UInt32 bytePos, bitRes;
- UInt64 instruction, instNorm;
- int j;
- if (((mask >> slot) & 1) == 0)
- continue;
- bytePos = (bitPos >> 3);
- bitRes = bitPos & 0x7;
- instruction = 0;
- for (j = 0; j < 6; j++)
- instruction += (UInt64)data[i + j + bytePos] << (8 * j);
-
- instNorm = instruction >> bitRes;
- if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
- {
- UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
- UInt32 dest;
- src |= ((UInt32)(instNorm >> 36) & 1) << 20;
-
- src <<= 4;
-
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
-
- dest >>= 4;
-
- instNorm &= ~((UInt64)(0x8FFFFF) << 13);
- instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
- instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
-
- instruction &= (1 << bitRes) - 1;
- instruction |= (instNorm << bitRes);
- for (j = 0; j < 6; j++)
- data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
- }
- }
- }
- return i;
-}
diff --git a/desmume/src/windows/7z/C/BwtSort.c b/desmume/src/windows/7z/C/BwtSort.c
deleted file mode 100644
index d6b545e83..000000000
--- a/desmume/src/windows/7z/C/BwtSort.c
+++ /dev/null
@@ -1,516 +0,0 @@
-/* BwtSort.c -- BWT block sorting
-2008-08-17
-Igor Pavlov
-Public domain */
-
-#include "BwtSort.h"
-#include "Sort.h"
-
-/* #define BLOCK_SORT_USE_HEAP_SORT */
-
-#define NO_INLINE MY_FAST_CALL
-
-/* Don't change it !!! */
-#define kNumHashBytes 2
-#define kNumHashValues (1 << (kNumHashBytes * 8))
-
-/* kNumRefBitsMax must be < (kNumHashBytes * 8) = 16 */
-#define kNumRefBitsMax 12
-
-#define BS_TEMP_SIZE kNumHashValues
-
-#ifdef BLOCK_SORT_EXTERNAL_FLAGS
-
-/* 32 Flags in UInt32 word */
-#define kNumFlagsBits 5
-#define kNumFlagsInWord (1 << kNumFlagsBits)
-#define kFlagsMask (kNumFlagsInWord - 1)
-#define kAllFlags 0xFFFFFFFF
-
-#else
-
-#define kNumBitsMax 20
-#define kIndexMask ((1 << kNumBitsMax) - 1)
-#define kNumExtraBits (32 - kNumBitsMax)
-#define kNumExtra0Bits (kNumExtraBits - 2)
-#define kNumExtra0Mask ((1 << kNumExtra0Bits) - 1)
-
-#define SetFinishedGroupSize(p, size) \
- { *(p) |= ((((size) - 1) & kNumExtra0Mask) << kNumBitsMax); \
- if ((size) > (1 << kNumExtra0Bits)) { \
- *(p) |= 0x40000000; *((p) + 1) |= ((((size) - 1)>> kNumExtra0Bits) << kNumBitsMax); } } \
-
-static void SetGroupSize(UInt32 *p, UInt32 size)
-{
- if (--size == 0)
- return;
- *p |= 0x80000000 | ((size & kNumExtra0Mask) << kNumBitsMax);
- if (size >= (1 << kNumExtra0Bits))
- {
- *p |= 0x40000000;
- p[1] |= ((size >> kNumExtra0Bits) << kNumBitsMax);
- }
-}
-
-#endif
-
-/*
-SortGroup - is recursive Range-Sort function with HeapSort optimization for small blocks
- "range" is not real range. It's only for optimization.
-returns: 1 - if there are groups, 0 - no more groups
-*/
-
-UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 groupOffset, UInt32 groupSize, int NumRefBits, UInt32 *Indices
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- , UInt32 left, UInt32 range
- #endif
- )
-{
- UInt32 *ind2 = Indices + groupOffset;
- UInt32 *Groups;
- if (groupSize <= 1)
- {
- /*
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetFinishedGroupSize(ind2, 1);
- #endif
- */
- return 0;
- }
- Groups = Indices + BlockSize + BS_TEMP_SIZE;
- if (groupSize <= ((UInt32)1 << NumRefBits)
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- && groupSize <= range
- #endif
- )
- {
- UInt32 *temp = Indices + BlockSize;
- UInt32 j;
- UInt32 mask, thereAreGroups, group, cg;
- {
- UInt32 gPrev;
- UInt32 gRes = 0;
- {
- UInt32 sp = ind2[0] + NumSortedBytes;
- if (sp >= BlockSize) sp -= BlockSize;
- gPrev = Groups[sp];
- temp[0] = (gPrev << NumRefBits);
- }
-
- for (j = 1; j < groupSize; j++)
- {
- UInt32 sp = ind2[j] + NumSortedBytes;
- UInt32 g;
- if (sp >= BlockSize) sp -= BlockSize;
- g = Groups[sp];
- temp[j] = (g << NumRefBits) | j;
- gRes |= (gPrev ^ g);
- }
- if (gRes == 0)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2, groupSize);
- #endif
- return 1;
- }
- }
-
- HeapSort(temp, groupSize);
- mask = ((1 << NumRefBits) - 1);
- thereAreGroups = 0;
-
- group = groupOffset;
- cg = (temp[0] >> NumRefBits);
- temp[0] = ind2[temp[0] & mask];
-
- {
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 *Flags = Groups + BlockSize;
- #else
- UInt32 prevGroupStart = 0;
- #endif
-
- for (j = 1; j < groupSize; j++)
- {
- UInt32 val = temp[j];
- UInt32 cgCur = (val >> NumRefBits);
-
- if (cgCur != cg)
- {
- cg = cgCur;
- group = groupOffset + j;
-
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 t = group - 1;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- }
- #else
- SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
- prevGroupStart = j;
- #endif
- }
- else
- thereAreGroups = 1;
- {
- UInt32 ind = ind2[val & mask];
- temp[j] = ind;
- Groups[ind] = group;
- }
- }
-
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
- #endif
- }
-
- for (j = 0; j < groupSize; j++)
- ind2[j] = temp[j];
- return thereAreGroups;
- }
-
- /* Check that all strings are in one group (cannot sort) */
- {
- UInt32 group, j;
- UInt32 sp = ind2[0] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- group = Groups[sp];
- for (j = 1; j < groupSize; j++)
- {
- sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- if (Groups[sp] != group)
- break;
- }
- if (j == groupSize)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2, groupSize);
- #endif
- return 1;
- }
- }
-
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- {
- /* ---------- Range Sort ---------- */
- UInt32 i;
- UInt32 mid;
- for (;;)
- {
- UInt32 j;
- if (range <= 1)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2, groupSize);
- #endif
- return 1;
- }
- mid = left + ((range + 1) >> 1);
- j = groupSize;
- i = 0;
- do
- {
- UInt32 sp = ind2[i] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- if (Groups[sp] >= mid)
- {
- for (j--; j > i; j--)
- {
- sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- if (Groups[sp] < mid)
- {
- UInt32 temp = ind2[i]; ind2[i] = ind2[j]; ind2[j] = temp;
- break;
- }
- }
- if (i >= j)
- break;
- }
- }
- while (++i < j);
- if (i == 0)
- {
- range = range - (mid - left);
- left = mid;
- }
- else if (i == groupSize)
- range = (mid - left);
- else
- break;
- }
-
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 t = (groupOffset + i - 1);
- UInt32 *Flags = Groups + BlockSize;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- }
- #endif
-
- {
- UInt32 j;
- for (j = i; j < groupSize; j++)
- Groups[ind2[j]] = groupOffset + i;
- }
-
- {
- UInt32 res = SortGroup(BlockSize, NumSortedBytes, groupOffset, i, NumRefBits, Indices, left, mid - left);
- return res | SortGroup(BlockSize, NumSortedBytes, groupOffset + i, groupSize - i, NumRefBits, Indices, mid, range - (mid - left));
- }
-
- }
-
- #else
-
- /* ---------- Heap Sort ---------- */
-
- {
- UInt32 j;
- for (j = 0; j < groupSize; j++)
- {
- UInt32 sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- ind2[j] = sp;
- }
-
- HeapSortRef(ind2, Groups, groupSize);
-
- /* Write Flags */
- {
- UInt32 sp = ind2[0];
- UInt32 group = Groups[sp];
-
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 *Flags = Groups + BlockSize;
- #else
- UInt32 prevGroupStart = 0;
- #endif
-
- for (j = 1; j < groupSize; j++)
- {
- sp = ind2[j];
- if (Groups[sp] != group)
- {
- group = Groups[sp];
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 t = groupOffset + j - 1;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- }
- #else
- SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
- prevGroupStart = j;
- #endif
- }
- }
-
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
- #endif
- }
- {
- /* Write new Groups values and Check that there are groups */
- UInt32 thereAreGroups = 0;
- for (j = 0; j < groupSize; j++)
- {
- UInt32 group = groupOffset + j;
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 subGroupSize = ((ind2[j] & ~0xC0000000) >> kNumBitsMax);
- if ((ind2[j] & 0x40000000) != 0)
- subGroupSize += ((ind2[j + 1] >> kNumBitsMax) << kNumExtra0Bits);
- subGroupSize++;
- for (;;)
- {
- UInt32 original = ind2[j];
- UInt32 sp = original & kIndexMask;
- if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
- ind2[j] = sp | (original & ~kIndexMask);
- Groups[sp] = group;
- if (--subGroupSize == 0)
- break;
- j++;
- thereAreGroups = 1;
- }
- #else
- UInt32 *Flags = Groups + BlockSize;
- for (;;)
- {
- UInt32 sp = ind2[j]; if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
- ind2[j] = sp;
- Groups[sp] = group;
- if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0)
- break;
- j++;
- thereAreGroups = 1;
- }
- #endif
- }
- return thereAreGroups;
- }
- }
- #endif
-}
-
-/* conditions: blockSize > 0 */
-UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
-{
- UInt32 *counters = Indices + blockSize;
- UInt32 i;
- UInt32 *Groups;
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 *Flags;
- #endif
-
- /* Radix-Sort for 2 bytes */
- for (i = 0; i < kNumHashValues; i++)
- counters[i] = 0;
- for (i = 0; i < blockSize - 1; i++)
- counters[((UInt32)data[i] << 8) | data[i + 1]]++;
- counters[((UInt32)data[i] << 8) | data[0]]++;
-
- Groups = counters + BS_TEMP_SIZE;
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- Flags = Groups + blockSize;
- {
- UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits;
- for (i = 0; i < numWords; i++)
- Flags[i] = kAllFlags;
- }
- #endif
-
- {
- UInt32 sum = 0;
- for (i = 0; i < kNumHashValues; i++)
- {
- UInt32 groupSize = counters[i];
- if (groupSize > 0)
- {
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 t = sum + groupSize - 1;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- #endif
- sum += groupSize;
- }
- counters[i] = sum - groupSize;
- }
-
- for (i = 0; i < blockSize - 1; i++)
- Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]];
- Groups[i] = counters[((UInt32)data[i] << 8) | data[0]];
-
- for (i = 0; i < blockSize - 1; i++)
- Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i;
- Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
-
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 prev = 0;
- for (i = 0; i < kNumHashValues; i++)
- {
- UInt32 prevGroupSize = counters[i] - prev;
- if (prevGroupSize == 0)
- continue;
- SetGroupSize(Indices + prev, prevGroupSize);
- prev = counters[i];
- }
- }
- #endif
- }
-
- {
- int NumRefBits;
- UInt32 NumSortedBytes;
- for (NumRefBits = 0; ((blockSize - 1) >> NumRefBits) != 0; NumRefBits++);
- NumRefBits = 32 - NumRefBits;
- if (NumRefBits > kNumRefBitsMax)
- NumRefBits = kNumRefBitsMax;
-
- for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 finishedGroupSize = 0;
- #endif
- UInt32 newLimit = 0;
- for (i = 0; i < blockSize;)
- {
- UInt32 groupSize;
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
-
- if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0)
- {
- i++;
- continue;
- }
- for (groupSize = 1;
- (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
- groupSize++);
-
- groupSize++;
-
- #else
-
- groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
- {
- Bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
- if ((Indices[i] & 0x40000000) != 0)
- {
- groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
- Indices[i + 1] &= kIndexMask;
- }
- Indices[i] &= kIndexMask;
- groupSize++;
- if (finishedGroup || groupSize == 1)
- {
- Indices[i - finishedGroupSize] &= kIndexMask;
- if (finishedGroupSize > 1)
- Indices[i - finishedGroupSize + 1] &= kIndexMask;
- {
- UInt32 newGroupSize = groupSize + finishedGroupSize;
- SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize);
- finishedGroupSize = newGroupSize;
- }
- i += groupSize;
- continue;
- }
- finishedGroupSize = 0;
- }
-
- #endif
-
- if (NumSortedBytes >= blockSize)
- {
- UInt32 j;
- for (j = 0; j < groupSize; j++)
- {
- UInt32 t = (i + j);
- /* Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); */
- Groups[Indices[t]] = t;
- }
- }
- else
- if (SortGroup(blockSize, NumSortedBytes, i, groupSize, NumRefBits, Indices
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- , 0, blockSize
- #endif
- ) != 0)
- newLimit = i + groupSize;
- i += groupSize;
- }
- if (newLimit == 0)
- break;
- }
- }
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- for (i = 0; i < blockSize;)
- {
- UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
- if ((Indices[i] & 0x40000000) != 0)
- {
- groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
- Indices[i + 1] &= kIndexMask;
- }
- Indices[i] &= kIndexMask;
- groupSize++;
- i += groupSize;
- }
- #endif
- return Groups[0];
-}
-
diff --git a/desmume/src/windows/7z/C/BwtSort.h b/desmume/src/windows/7z/C/BwtSort.h
deleted file mode 100644
index 84c50339c..000000000
--- a/desmume/src/windows/7z/C/BwtSort.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* BwtSort.h -- BWT block sorting
-2008-03-26
-Igor Pavlov
-Public domain */
-
-#ifndef __BWTSORT_H
-#define __BWTSORT_H
-
-#include "Types.h"
-
-/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M */
-/* #define BLOCK_SORT_EXTERNAL_FLAGS */
-
-#ifdef BLOCK_SORT_EXTERNAL_FLAGS
-#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5))
-#else
-#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) 0
-#endif
-
-#define BLOCK_SORT_BUF_SIZE(blockSize) ((blockSize) * 2 + BLOCK_SORT_EXTERNAL_SIZE(blockSize) + (1 << 16))
-
-UInt32 BlockSort(UInt32 *indices, const Byte *data, UInt32 blockSize);
-
-#endif
diff --git a/desmume/src/windows/7z/C/CpuArch.h b/desmume/src/windows/7z/C/CpuArch.h
deleted file mode 100644
index 006361f2f..000000000
--- a/desmume/src/windows/7z/C/CpuArch.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* CpuArch.h
-2008-08-05
-Igor Pavlov
-Public domain */
-
-#ifndef __CPUARCH_H
-#define __CPUARCH_H
-
-/*
-LITTLE_ENDIAN_UNALIGN means:
- 1) CPU is LITTLE_ENDIAN
- 2) it's allowed to make unaligned memory accesses
-if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
-about these properties of platform.
-*/
-
-#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
-#define LITTLE_ENDIAN_UNALIGN
-#endif
-
-#ifdef LITTLE_ENDIAN_UNALIGN
-
-#define GetUi16(p) (*(const UInt16 *)(p))
-#define GetUi32(p) (*(const UInt32 *)(p))
-#define GetUi64(p) (*(const UInt64 *)(p))
-#define SetUi32(p, d) *(UInt32 *)(p) = (d);
-
-#else
-
-#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
-
-#define GetUi32(p) ( \
- ((const Byte *)(p))[0] | \
- ((UInt32)((const Byte *)(p))[1] << 8) | \
- ((UInt32)((const Byte *)(p))[2] << 16) | \
- ((UInt32)((const Byte *)(p))[3] << 24))
-
-#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
-
-#define SetUi32(p, d) { UInt32 _x_ = (d); \
- ((Byte *)(p))[0] = (Byte)_x_; \
- ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
- ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
- ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
-
-#endif
-
-#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
-
-#pragma intrinsic(_byteswap_ulong)
-#pragma intrinsic(_byteswap_uint64)
-#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
-#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
-
-#else
-
-#define GetBe32(p) ( \
- ((UInt32)((const Byte *)(p))[0] << 24) | \
- ((UInt32)((const Byte *)(p))[1] << 16) | \
- ((UInt32)((const Byte *)(p))[2] << 8) | \
- ((const Byte *)(p))[3] )
-
-#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
-
-#endif
-
-#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
-
-#endif
diff --git a/desmume/src/windows/7z/C/HuffEnc.c b/desmume/src/windows/7z/C/HuffEnc.c
deleted file mode 100644
index 2d31ad596..000000000
--- a/desmume/src/windows/7z/C/HuffEnc.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/* HuffEnc.c -- functions for Huffman encoding
-2008-08-05
-Igor Pavlov
-Public domain */
-
-#include "HuffEnc.h"
-#include "Sort.h"
-
-#define kMaxLen 16
-#define NUM_BITS 10
-#define MASK ((1 << NUM_BITS) - 1)
-
-#define NUM_COUNTERS 64
-
-#define HUFFMAN_SPEED_OPT
-
-void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)
-{
- UInt32 num = 0;
- /* if (maxLen > 10) maxLen = 10; */
- {
- UInt32 i;
-
- #ifdef HUFFMAN_SPEED_OPT
-
- UInt32 counters[NUM_COUNTERS];
- for (i = 0; i < NUM_COUNTERS; i++)
- counters[i] = 0;
- for (i = 0; i < numSymbols; i++)
- {
- UInt32 freq = freqs[i];
- counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;
- }
-
- for (i = 1; i < NUM_COUNTERS; i++)
- {
- UInt32 temp = counters[i];
- counters[i] = num;
- num += temp;
- }
-
- for (i = 0; i < numSymbols; i++)
- {
- UInt32 freq = freqs[i];
- if (freq == 0)
- lens[i] = 0;
- else
- p[counters[((freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1)]++] = i | (freq << NUM_BITS);
- }
- counters[0] = 0;
- HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);
-
- #else
-
- for (i = 0; i < numSymbols; i++)
- {
- UInt32 freq = freqs[i];
- if (freq == 0)
- lens[i] = 0;
- else
- p[num++] = i | (freq << NUM_BITS);
- }
- HeapSort(p, num);
-
- #endif
- }
-
- if (num < 2)
- {
- int minCode = 0;
- int maxCode = 1;
- if (num == 1)
- {
- maxCode = (int)(p[0] & MASK);
- if (maxCode == 0)
- maxCode++;
- }
- p[minCode] = 0;
- p[maxCode] = 1;
- lens[minCode] = lens[maxCode] = 1;
- return;
- }
-
- {
- UInt32 b, e, i;
-
- i = b = e = 0;
- do
- {
- UInt32 n, m, freq;
- n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
- freq = (p[n] & ~MASK);
- p[n] = (p[n] & MASK) | (e << NUM_BITS);
- m = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
- freq += (p[m] & ~MASK);
- p[m] = (p[m] & MASK) | (e << NUM_BITS);
- p[e] = (p[e] & MASK) | freq;
- e++;
- }
- while (num - e > 1);
-
- {
- UInt32 lenCounters[kMaxLen + 1];
- for (i = 0; i <= kMaxLen; i++)
- lenCounters[i] = 0;
-
- p[--e] &= MASK;
- lenCounters[1] = 2;
- while (e > 0)
- {
- UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;
- p[e] = (p[e] & MASK) | (len << NUM_BITS);
- if (len >= maxLen)
- for (len = maxLen - 1; lenCounters[len] == 0; len--);
- lenCounters[len]--;
- lenCounters[len + 1] += 2;
- }
-
- {
- UInt32 len;
- i = 0;
- for (len = maxLen; len != 0; len--)
- {
- UInt32 num;
- for (num = lenCounters[len]; num != 0; num--)
- lens[p[i++] & MASK] = (Byte)len;
- }
- }
-
- {
- UInt32 nextCodes[kMaxLen + 1];
- {
- UInt32 code = 0;
- UInt32 len;
- for (len = 1; len <= kMaxLen; len++)
- nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;
- }
- /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */
-
- {
- UInt32 i;
- for (i = 0; i < numSymbols; i++)
- p[i] = nextCodes[lens[i]]++;
- }
- }
- }
- }
-}
diff --git a/desmume/src/windows/7z/C/HuffEnc.h b/desmume/src/windows/7z/C/HuffEnc.h
deleted file mode 100644
index c0617b33e..000000000
--- a/desmume/src/windows/7z/C/HuffEnc.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* HuffEnc.h -- functions for Huffman encoding
-2008-03-26
-Igor Pavlov
-Public domain */
-
-#ifndef __HUFFENC_H
-#define __HUFFENC_H
-
-#include "Types.h"
-
-/*
-Conditions:
- num <= 1024 = 2 ^ NUM_BITS
- Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)
- maxLen <= 16 = kMaxLen
- Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)
-*/
-
-void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);
-
-#endif
diff --git a/desmume/src/windows/7z/C/LzFind.c b/desmume/src/windows/7z/C/LzFind.c
deleted file mode 100644
index e0ebe6235..000000000
--- a/desmume/src/windows/7z/C/LzFind.c
+++ /dev/null
@@ -1,751 +0,0 @@
-/* LzFind.c -- Match finder for LZ algorithms
-2008-10-04 : Igor Pavlov : Public domain */
-
-#include
-
-#include "LzFind.h"
-#include "LzHash.h"
-
-#define kEmptyHashValue 0
-#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
-#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
-#define kNormalizeMask (~(kNormalizeStepMin - 1))
-#define kMaxHistorySize ((UInt32)3 << 30)
-
-#define kStartMaxLen 3
-
-static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
-{
- if (!p->directInput)
- {
- alloc->Free(alloc, p->bufferBase);
- p->bufferBase = 0;
- }
-}
-
-/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
-
-static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
-{
- UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
- if (p->directInput)
- {
- p->blockSize = blockSize;
- return 1;
- }
- if (p->bufferBase == 0 || p->blockSize != blockSize)
- {
- LzInWindow_Free(p, alloc);
- p->blockSize = blockSize;
- p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
- }
- return (p->bufferBase != 0);
-}
-
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
-Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
-
-UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
-
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
-{
- p->posLimit -= subValue;
- p->pos -= subValue;
- p->streamPos -= subValue;
-}
-
-static void MatchFinder_ReadBlock(CMatchFinder *p)
-{
- if (p->streamEndWasReached || p->result != SZ_OK)
- return;
- for (;;)
- {
- Byte *dest = p->buffer + (p->streamPos - p->pos);
- size_t size = (p->bufferBase + p->blockSize - dest);
- if (size == 0)
- return;
- p->result = p->stream->Read(p->stream, dest, &size);
- if (p->result != SZ_OK)
- return;
- if (size == 0)
- {
- p->streamEndWasReached = 1;
- return;
- }
- p->streamPos += (UInt32)size;
- if (p->streamPos - p->pos > p->keepSizeAfter)
- return;
- }
-}
-
-void MatchFinder_MoveBlock(CMatchFinder *p)
-{
- memmove(p->bufferBase,
- p->buffer - p->keepSizeBefore,
- (size_t)(p->streamPos - p->pos + p->keepSizeBefore));
- p->buffer = p->bufferBase + p->keepSizeBefore;
-}
-
-int MatchFinder_NeedMove(CMatchFinder *p)
-{
- /* if (p->streamEndWasReached) return 0; */
- return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
-}
-
-void MatchFinder_ReadIfRequired(CMatchFinder *p)
-{
- if (p->streamEndWasReached)
- return;
- if (p->keepSizeAfter >= p->streamPos - p->pos)
- MatchFinder_ReadBlock(p);
-}
-
-static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
-{
- if (MatchFinder_NeedMove(p))
- MatchFinder_MoveBlock(p);
- MatchFinder_ReadBlock(p);
-}
-
-static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
-{
- p->cutValue = 32;
- p->btMode = 1;
- p->numHashBytes = 4;
- /* p->skipModeBits = 0; */
- p->directInput = 0;
- p->bigHash = 0;
-}
-
-#define kCrcPoly 0xEDB88320
-
-void MatchFinder_Construct(CMatchFinder *p)
-{
- UInt32 i;
- p->bufferBase = 0;
- p->directInput = 0;
- p->hash = 0;
- MatchFinder_SetDefaultSettings(p);
-
- for (i = 0; i < 256; i++)
- {
- UInt32 r = i;
- int j;
- for (j = 0; j < 8; j++)
- r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
- p->crc[i] = r;
- }
-}
-
-static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->hash);
- p->hash = 0;
-}
-
-void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
-{
- MatchFinder_FreeThisClassMemory(p, alloc);
- LzInWindow_Free(p, alloc);
-}
-
-static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
-{
- size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
- if (sizeInBytes / sizeof(CLzRef) != num)
- return 0;
- return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
-}
-
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAlloc *alloc)
-{
- UInt32 sizeReserv;
- if (historySize > kMaxHistorySize)
- {
- MatchFinder_Free(p, alloc);
- return 0;
- }
- sizeReserv = historySize >> 1;
- if (historySize > ((UInt32)2 << 30))
- sizeReserv = historySize >> 2;
- sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
-
- p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
- p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
- /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
- if (LzInWindow_Create(p, sizeReserv, alloc))
- {
- UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;
- UInt32 hs;
- p->matchMaxLen = matchMaxLen;
- {
- p->fixedHashSize = 0;
- if (p->numHashBytes == 2)
- hs = (1 << 16) - 1;
- else
- {
- hs = historySize - 1;
- hs |= (hs >> 1);
- hs |= (hs >> 2);
- hs |= (hs >> 4);
- hs |= (hs >> 8);
- hs >>= 1;
- /* hs >>= p->skipModeBits; */
- hs |= 0xFFFF; /* don't change it! It's required for Deflate */
- if (hs > (1 << 24))
- {
- if (p->numHashBytes == 3)
- hs = (1 << 24) - 1;
- else
- hs >>= 1;
- }
- }
- p->hashMask = hs;
- hs++;
- if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
- if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
- if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
- hs += p->fixedHashSize;
- }
-
- {
- UInt32 prevSize = p->hashSizeSum + p->numSons;
- UInt32 newSize;
- p->historySize = historySize;
- p->hashSizeSum = hs;
- p->cyclicBufferSize = newCyclicBufferSize;
- p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
- newSize = p->hashSizeSum + p->numSons;
- if (p->hash != 0 && prevSize == newSize)
- return 1;
- MatchFinder_FreeThisClassMemory(p, alloc);
- p->hash = AllocRefs(newSize, alloc);
- if (p->hash != 0)
- {
- p->son = p->hash + p->hashSizeSum;
- return 1;
- }
- }
- }
- MatchFinder_Free(p, alloc);
- return 0;
-}
-
-static void MatchFinder_SetLimits(CMatchFinder *p)
-{
- UInt32 limit = kMaxValForNormalize - p->pos;
- UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
- if (limit2 < limit)
- limit = limit2;
- limit2 = p->streamPos - p->pos;
- if (limit2 <= p->keepSizeAfter)
- {
- if (limit2 > 0)
- limit2 = 1;
- }
- else
- limit2 -= p->keepSizeAfter;
- if (limit2 < limit)
- limit = limit2;
- {
- UInt32 lenLimit = p->streamPos - p->pos;
- if (lenLimit > p->matchMaxLen)
- lenLimit = p->matchMaxLen;
- p->lenLimit = lenLimit;
- }
- p->posLimit = p->pos + limit;
-}
-
-void MatchFinder_Init(CMatchFinder *p)
-{
- UInt32 i;
- for (i = 0; i < p->hashSizeSum; i++)
- p->hash[i] = kEmptyHashValue;
- p->cyclicBufferPos = 0;
- p->buffer = p->bufferBase;
- p->pos = p->streamPos = p->cyclicBufferSize;
- p->result = SZ_OK;
- p->streamEndWasReached = 0;
- MatchFinder_ReadBlock(p);
- MatchFinder_SetLimits(p);
-}
-
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
-{
- return (p->pos - p->historySize - 1) & kNormalizeMask;
-}
-
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
-{
- UInt32 i;
- for (i = 0; i < numItems; i++)
- {
- UInt32 value = items[i];
- if (value <= subValue)
- value = kEmptyHashValue;
- else
- value -= subValue;
- items[i] = value;
- }
-}
-
-static void MatchFinder_Normalize(CMatchFinder *p)
-{
- UInt32 subValue = MatchFinder_GetSubValue(p);
- MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
- MatchFinder_ReduceOffsets(p, subValue);
-}
-
-static void MatchFinder_CheckLimits(CMatchFinder *p)
-{
- if (p->pos == kMaxValForNormalize)
- MatchFinder_Normalize(p);
- if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
- MatchFinder_CheckAndMoveAndRead(p);
- if (p->cyclicBufferPos == p->cyclicBufferSize)
- p->cyclicBufferPos = 0;
- MatchFinder_SetLimits(p);
-}
-
-static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
-{
- son[_cyclicBufferPos] = curMatch;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- return distances;
- {
- const Byte *pb = cur - delta;
- curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
- if (pb[maxLen] == cur[maxLen] && *pb == *cur)
- {
- UInt32 len = 0;
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- *distances++ = maxLen = len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- return distances;
- }
- }
- }
- }
-}
-
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
-{
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- return distances;
- }
- {
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
- if (pb[len] == cur[len])
- {
- if (++len != lenLimit && pb[len] == cur[len])
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- *distances++ = maxLen = len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return distances;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
-}
-
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
-{
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- return;
- }
- {
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
- if (pb[len] == cur[len])
- {
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- {
- if (len == lenLimit)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
-}
-
-#define MOVE_POS \
- ++p->cyclicBufferPos; \
- p->buffer++; \
- if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
-
-#define MOVE_POS_RET MOVE_POS return offset;
-
-static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
-
-#define GET_MATCHES_HEADER2(minLen, ret_op) \
- UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
- lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
- cur = p->buffer;
-
-#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
-#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
-
-#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
-
-#define GET_MATCHES_FOOTER(offset, maxLen) \
- offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
- distances + offset, maxLen) - distances); MOVE_POS_RET;
-
-#define SKIP_FOOTER \
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
-
-static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 offset;
- GET_MATCHES_HEADER(2)
- HASH2_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 1)
-}
-
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 offset;
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 2)
-}
-
-static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 hash2Value, delta2, maxLen, offset;
- GET_MATCHES_HEADER(3)
-
- HASH3_CALC;
-
- delta2 = p->pos - p->hash[hash2Value];
- curMatch = p->hash[kFix3HashSize + hashValue];
-
- p->hash[hash2Value] =
- p->hash[kFix3HashSize + hashValue] = p->pos;
-
-
- maxLen = 2;
- offset = 0;
- if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
- {
- for (; maxLen != lenLimit; maxLen++)
- if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
- break;
- distances[0] = maxLen;
- distances[1] = delta2 - 1;
- offset = 2;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
- GET_MATCHES_FOOTER(offset, maxLen)
-}
-
-static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- delta2 = p->pos - p->hash[ hash2Value];
- delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
- curMatch = p->hash[kFix4HashSize + hashValue];
-
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] =
- p->hash[kFix4HashSize + hashValue] = p->pos;
-
- maxLen = 1;
- offset = 0;
- if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
- {
- distances[0] = maxLen = 2;
- distances[1] = delta2 - 1;
- offset = 2;
- }
- if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
- {
- maxLen = 3;
- distances[offset + 1] = delta3 - 1;
- offset += 2;
- delta2 = delta3;
- }
- if (offset != 0)
- {
- for (; maxLen != lenLimit; maxLen++)
- if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
- break;
- distances[offset - 2] = maxLen;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
- if (maxLen < 3)
- maxLen = 3;
- GET_MATCHES_FOOTER(offset, maxLen)
-}
-
-static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- delta2 = p->pos - p->hash[ hash2Value];
- delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
- curMatch = p->hash[kFix4HashSize + hashValue];
-
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] =
- p->hash[kFix4HashSize + hashValue] = p->pos;
-
- maxLen = 1;
- offset = 0;
- if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
- {
- distances[0] = maxLen = 2;
- distances[1] = delta2 - 1;
- offset = 2;
- }
- if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
- {
- maxLen = 3;
- distances[offset + 1] = delta3 - 1;
- offset += 2;
- delta2 = delta3;
- }
- if (offset != 0)
- {
- for (; maxLen != lenLimit; maxLen++)
- if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
- break;
- distances[offset - 2] = maxLen;
- if (maxLen == lenLimit)
- {
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS_RET;
- }
- }
- if (maxLen < 3)
- maxLen = 3;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances + offset, maxLen) - (distances));
- MOVE_POS_RET
-}
-
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 offset;
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances, 2) - (distances));
- MOVE_POS_RET
-}
-
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(2)
- HASH2_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 hash2Value;
- SKIP_HEADER(3)
- HASH3_CALC;
- curMatch = p->hash[kFix3HashSize + hashValue];
- p->hash[hash2Value] =
- p->hash[kFix3HashSize + hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 hash2Value, hash3Value;
- SKIP_HEADER(4)
- HASH4_CALC;
- curMatch = p->hash[kFix4HashSize + hashValue];
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] = p->pos;
- p->hash[kFix4HashSize + hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 hash2Value, hash3Value;
- SKIP_HEADER(4)
- HASH4_CALC;
- curMatch = p->hash[kFix4HashSize + hashValue];
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] =
- p->hash[kFix4HashSize + hashValue] = p->pos;
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS
- }
- while (--num != 0);
-}
-
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS
- }
- while (--num != 0);
-}
-
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
-{
- vTable->Init = (Mf_Init_Func)MatchFinder_Init;
- vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
- vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
- vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
- if (!p->btMode)
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
- }
- else if (p->numHashBytes == 2)
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
- }
- else if (p->numHashBytes == 3)
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
- }
- else
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
- }
-}
diff --git a/desmume/src/windows/7z/C/LzFind.h b/desmume/src/windows/7z/C/LzFind.h
deleted file mode 100644
index 423d67e0c..000000000
--- a/desmume/src/windows/7z/C/LzFind.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/* LzFind.h -- Match finder for LZ algorithms
-2008-10-04 : Igor Pavlov : Public domain */
-
-#ifndef __LZFIND_H
-#define __LZFIND_H
-
-#include "Types.h"
-
-typedef UInt32 CLzRef;
-
-typedef struct _CMatchFinder
-{
- Byte *buffer;
- UInt32 pos;
- UInt32 posLimit;
- UInt32 streamPos;
- UInt32 lenLimit;
-
- UInt32 cyclicBufferPos;
- UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
-
- UInt32 matchMaxLen;
- CLzRef *hash;
- CLzRef *son;
- UInt32 hashMask;
- UInt32 cutValue;
-
- Byte *bufferBase;
- ISeqInStream *stream;
- int streamEndWasReached;
-
- UInt32 blockSize;
- UInt32 keepSizeBefore;
- UInt32 keepSizeAfter;
-
- UInt32 numHashBytes;
- int directInput;
- int btMode;
- /* int skipModeBits; */
- int bigHash;
- UInt32 historySize;
- UInt32 fixedHashSize;
- UInt32 hashSizeSum;
- UInt32 numSons;
- SRes result;
- UInt32 crc[256];
-} CMatchFinder;
-
-#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
-#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
-
-#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
-
-int MatchFinder_NeedMove(CMatchFinder *p);
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
-void MatchFinder_MoveBlock(CMatchFinder *p);
-void MatchFinder_ReadIfRequired(CMatchFinder *p);
-
-void MatchFinder_Construct(CMatchFinder *p);
-
-/* Conditions:
- historySize <= 3 GB
- keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
-*/
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAlloc *alloc);
-void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
-
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
- UInt32 *distances, UInt32 maxLen);
-
-/*
-Conditions:
- Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
- Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
-*/
-
-typedef void (*Mf_Init_Func)(void *object);
-typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
-typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
-typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
-typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
-typedef void (*Mf_Skip_Func)(void *object, UInt32);
-
-typedef struct _IMatchFinder
-{
- Mf_Init_Func Init;
- Mf_GetIndexByte_Func GetIndexByte;
- Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
- Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
- Mf_GetMatches_Func GetMatches;
- Mf_Skip_Func Skip;
-} IMatchFinder;
-
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
-
-void MatchFinder_Init(CMatchFinder *p);
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
-
-#endif
diff --git a/desmume/src/windows/7z/C/LzFindMt.c b/desmume/src/windows/7z/C/LzFindMt.c
deleted file mode 100644
index 0ef134735..000000000
--- a/desmume/src/windows/7z/C/LzFindMt.c
+++ /dev/null
@@ -1,793 +0,0 @@
-/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
-2008-10-04 : Igor Pavlov : Public domain */
-
-#include "LzHash.h"
-
-#include "LzFindMt.h"
-
-void MtSync_Construct(CMtSync *p)
-{
- p->wasCreated = False;
- p->csWasInitialized = False;
- p->csWasEntered = False;
- Thread_Construct(&p->thread);
- Event_Construct(&p->canStart);
- Event_Construct(&p->wasStarted);
- Event_Construct(&p->wasStopped);
- Semaphore_Construct(&p->freeSemaphore);
- Semaphore_Construct(&p->filledSemaphore);
-}
-
-void MtSync_GetNextBlock(CMtSync *p)
-{
- if (p->needStart)
- {
- p->numProcessedBlocks = 1;
- p->needStart = False;
- p->stopWriting = False;
- p->exit = False;
- Event_Reset(&p->wasStarted);
- Event_Reset(&p->wasStopped);
-
- Event_Set(&p->canStart);
- Event_Wait(&p->wasStarted);
- }
- else
- {
- CriticalSection_Leave(&p->cs);
- p->csWasEntered = False;
- p->numProcessedBlocks++;
- Semaphore_Release1(&p->freeSemaphore);
- }
- Semaphore_Wait(&p->filledSemaphore);
- CriticalSection_Enter(&p->cs);
- p->csWasEntered = True;
-}
-
-/* MtSync_StopWriting must be called if Writing was started */
-
-void MtSync_StopWriting(CMtSync *p)
-{
- UInt32 myNumBlocks = p->numProcessedBlocks;
- if (!Thread_WasCreated(&p->thread) || p->needStart)
- return;
- p->stopWriting = True;
- if (p->csWasEntered)
- {
- CriticalSection_Leave(&p->cs);
- p->csWasEntered = False;
- }
- Semaphore_Release1(&p->freeSemaphore);
-
- Event_Wait(&p->wasStopped);
-
- while (myNumBlocks++ != p->numProcessedBlocks)
- {
- Semaphore_Wait(&p->filledSemaphore);
- Semaphore_Release1(&p->freeSemaphore);
- }
- p->needStart = True;
-}
-
-void MtSync_Destruct(CMtSync *p)
-{
- if (Thread_WasCreated(&p->thread))
- {
- MtSync_StopWriting(p);
- p->exit = True;
- if (p->needStart)
- Event_Set(&p->canStart);
- Thread_Wait(&p->thread);
- Thread_Close(&p->thread);
- }
- if (p->csWasInitialized)
- {
- CriticalSection_Delete(&p->cs);
- p->csWasInitialized = False;
- }
-
- Event_Close(&p->canStart);
- Event_Close(&p->wasStarted);
- Event_Close(&p->wasStopped);
- Semaphore_Close(&p->freeSemaphore);
- Semaphore_Close(&p->filledSemaphore);
-
- p->wasCreated = False;
-}
-
-#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
-
-static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
-{
- if (p->wasCreated)
- return SZ_OK;
-
- RINOK_THREAD(CriticalSection_Init(&p->cs));
- p->csWasInitialized = True;
-
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
-
- RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
- RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
-
- p->needStart = True;
-
- RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));
- p->wasCreated = True;
- return SZ_OK;
-}
-
-static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
-{
- SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);
- if (res != SZ_OK)
- MtSync_Destruct(p);
- return res;
-}
-
-void MtSync_Init(CMtSync *p) { p->needStart = True; }
-
-#define kMtMaxValForNormalize 0xFFFFFFFF
-
-#define DEF_GetHeads2(name, v, action) \
-static void GetHeads ## name(const Byte *p, UInt32 pos, \
-UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \
-{ action; for (; numHeads != 0; numHeads--) { \
-const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } }
-
-#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)
-
-DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )
-DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
-DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
-DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
-DEF_GetHeads(5, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)
-
-void HashThreadFunc(CMatchFinderMt *mt)
-{
- CMtSync *p = &mt->hashSync;
- for (;;)
- {
- UInt32 numProcessedBlocks = 0;
- Event_Wait(&p->canStart);
- Event_Set(&p->wasStarted);
- for (;;)
- {
- if (p->exit)
- return;
- if (p->stopWriting)
- {
- p->numProcessedBlocks = numProcessedBlocks;
- Event_Set(&p->wasStopped);
- break;
- }
-
- {
- CMatchFinder *mf = mt->MatchFinder;
- if (MatchFinder_NeedMove(mf))
- {
- CriticalSection_Enter(&mt->btSync.cs);
- CriticalSection_Enter(&mt->hashSync.cs);
- {
- const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);
- const Byte *afterPtr;
- MatchFinder_MoveBlock(mf);
- afterPtr = MatchFinder_GetPointerToCurrentPos(mf);
- mt->pointerToCurPos -= beforePtr - afterPtr;
- mt->buffer -= beforePtr - afterPtr;
- }
- CriticalSection_Leave(&mt->btSync.cs);
- CriticalSection_Leave(&mt->hashSync.cs);
- continue;
- }
-
- Semaphore_Wait(&p->freeSemaphore);
-
- MatchFinder_ReadIfRequired(mf);
- if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))
- {
- UInt32 subValue = (mf->pos - mf->historySize - 1);
- MatchFinder_ReduceOffsets(mf, subValue);
- MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);
- }
- {
- UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;
- UInt32 num = mf->streamPos - mf->pos;
- heads[0] = 2;
- heads[1] = num;
- if (num >= mf->numHashBytes)
- {
- num = num - mf->numHashBytes + 1;
- if (num > kMtHashBlockSize - 2)
- num = kMtHashBlockSize - 2;
- mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);
- heads[0] += num;
- }
- mf->pos += num;
- mf->buffer += num;
- }
- }
-
- Semaphore_Release1(&p->filledSemaphore);
- }
- }
-}
-
-void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
-{
- MtSync_GetNextBlock(&p->hashSync);
- p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;
- p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];
- p->hashNumAvail = p->hashBuf[p->hashBufPos++];
-}
-
-#define kEmptyHashValue 0
-
-/* #define MFMT_GM_INLINE */
-
-#ifdef MFMT_GM_INLINE
-
-#define NO_INLINE MY_FAST_CALL
-
-Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
- UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)
-{
- do
- {
- UInt32 *distances = _distances + 1;
- UInt32 curMatch = pos - *hash++;
-
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
- UInt32 cutValue = _cutValue;
- UInt32 maxLen = _maxLen;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- break;
- }
- {
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
- if (pb[len] == cur[len])
- {
- if (++len != lenLimit && pb[len] == cur[len])
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- *distances++ = maxLen = len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- break;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
- pos++;
- _cyclicBufferPos++;
- cur++;
- {
- UInt32 num = (UInt32)(distances - _distances);
- *_distances = num - 1;
- _distances += num;
- limit -= num;
- }
- }
- while (limit > 0 && --size != 0);
- *posRes = pos;
- return limit;
-}
-
-#endif
-
-void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
- UInt32 numProcessed = 0;
- UInt32 curPos = 2;
- UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);
- distances[1] = p->hashNumAvail;
- while (curPos < limit)
- {
- if (p->hashBufPos == p->hashBufPosLimit)
- {
- MatchFinderMt_GetNextBlock_Hash(p);
- distances[1] = numProcessed + p->hashNumAvail;
- if (p->hashNumAvail >= p->numHashBytes)
- continue;
- for (; p->hashNumAvail != 0; p->hashNumAvail--)
- distances[curPos++] = 0;
- break;
- }
- {
- UInt32 size = p->hashBufPosLimit - p->hashBufPos;
- UInt32 lenLimit = p->matchMaxLen;
- UInt32 pos = p->pos;
- UInt32 cyclicBufferPos = p->cyclicBufferPos;
- if (lenLimit >= p->hashNumAvail)
- lenLimit = p->hashNumAvail;
- {
- UInt32 size2 = p->hashNumAvail - lenLimit + 1;
- if (size2 < size)
- size = size2;
- size2 = p->cyclicBufferSize - cyclicBufferPos;
- if (size2 < size)
- size = size2;
- }
- #ifndef MFMT_GM_INLINE
- while (curPos < limit && size-- != 0)
- {
- UInt32 *startDistances = distances + curPos;
- UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
- pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
- startDistances + 1, p->numHashBytes - 1) - startDistances);
- *startDistances = num - 1;
- curPos += num;
- cyclicBufferPos++;
- pos++;
- p->buffer++;
- }
- #else
- {
- UInt32 posRes;
- curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
- distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);
- p->hashBufPos += posRes - pos;
- cyclicBufferPos += posRes - pos;
- p->buffer += posRes - pos;
- pos = posRes;
- }
- #endif
-
- numProcessed += pos - p->pos;
- p->hashNumAvail -= pos - p->pos;
- p->pos = pos;
- if (cyclicBufferPos == p->cyclicBufferSize)
- cyclicBufferPos = 0;
- p->cyclicBufferPos = cyclicBufferPos;
- }
- }
- distances[0] = curPos;
-}
-
-void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
-{
- CMtSync *sync = &p->hashSync;
- if (!sync->needStart)
- {
- CriticalSection_Enter(&sync->cs);
- sync->csWasEntered = True;
- }
-
- BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);
-
- if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)
- {
- UInt32 subValue = p->pos - p->cyclicBufferSize;
- MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);
- p->pos -= subValue;
- }
-
- if (!sync->needStart)
- {
- CriticalSection_Leave(&sync->cs);
- sync->csWasEntered = False;
- }
-}
-
-void BtThreadFunc(CMatchFinderMt *mt)
-{
- CMtSync *p = &mt->btSync;
- for (;;)
- {
- UInt32 blockIndex = 0;
- Event_Wait(&p->canStart);
- Event_Set(&p->wasStarted);
- for (;;)
- {
- if (p->exit)
- return;
- if (p->stopWriting)
- {
- p->numProcessedBlocks = blockIndex;
- MtSync_StopWriting(&mt->hashSync);
- Event_Set(&p->wasStopped);
- break;
- }
- Semaphore_Wait(&p->freeSemaphore);
- BtFillBlock(mt, blockIndex++);
- Semaphore_Release1(&p->filledSemaphore);
- }
- }
-}
-
-void MatchFinderMt_Construct(CMatchFinderMt *p)
-{
- p->hashBuf = 0;
- MtSync_Construct(&p->hashSync);
- MtSync_Construct(&p->btSync);
-}
-
-void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->hashBuf);
- p->hashBuf = 0;
-}
-
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
-{
- MtSync_Destruct(&p->hashSync);
- MtSync_Destruct(&p->btSync);
- MatchFinderMt_FreeMem(p, alloc);
-}
-
-#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)
-#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
-
-static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
-static unsigned MY_STD_CALL BtThreadFunc2(void *p)
-{
- Byte allocaDummy[0x180];
- int i = 0;
- for (i = 0; i < 16; i++)
- allocaDummy[i] = (Byte)i;
- BtThreadFunc((CMatchFinderMt *)p);
- return 0;
-}
-
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)
-{
- CMatchFinder *mf = p->MatchFinder;
- p->historySize = historySize;
- if (kMtBtBlockSize <= matchMaxLen * 4)
- return SZ_ERROR_PARAM;
- if (p->hashBuf == 0)
- {
- p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
- if (p->hashBuf == 0)
- return SZ_ERROR_MEM;
- p->btBuf = p->hashBuf + kHashBufferSize;
- }
- keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);
- keepAddBufferAfter += kMtHashBlockSize;
- if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
- return SZ_ERROR_MEM;
-
- RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));
- RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));
- return SZ_OK;
-}
-
-/* Call it after ReleaseStream / SetStream */
-void MatchFinderMt_Init(CMatchFinderMt *p)
-{
- CMatchFinder *mf = p->MatchFinder;
- p->btBufPos = p->btBufPosLimit = 0;
- p->hashBufPos = p->hashBufPosLimit = 0;
- MatchFinder_Init(mf);
- p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);
- p->btNumAvailBytes = 0;
- p->lzPos = p->historySize + 1;
-
- p->hash = mf->hash;
- p->fixedHashSize = mf->fixedHashSize;
- p->crc = mf->crc;
-
- p->son = mf->son;
- p->matchMaxLen = mf->matchMaxLen;
- p->numHashBytes = mf->numHashBytes;
- p->pos = mf->pos;
- p->buffer = mf->buffer;
- p->cyclicBufferPos = mf->cyclicBufferPos;
- p->cyclicBufferSize = mf->cyclicBufferSize;
- p->cutValue = mf->cutValue;
-}
-
-/* ReleaseStream is required to finish multithreading */
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
-{
- MtSync_StopWriting(&p->btSync);
- /* p->MatchFinder->ReleaseStream(); */
-}
-
-void MatchFinderMt_Normalize(CMatchFinderMt *p)
-{
- MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);
- p->lzPos = p->historySize + 1;
-}
-
-void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
-{
- UInt32 blockIndex;
- MtSync_GetNextBlock(&p->btSync);
- blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);
- p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;
- p->btBufPosLimit += p->btBuf[p->btBufPos++];
- p->btNumAvailBytes = p->btBuf[p->btBufPos++];
- if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)
- MatchFinderMt_Normalize(p);
-}
-
-const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
-{
- return p->pointerToCurPos;
-}
-
-#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
-
-UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)
-{
- GET_NEXT_BLOCK_IF_REQUIRED;
- return p->btNumAvailBytes;
-}
-
-Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)
-{
- return p->pointerToCurPos[index];
-}
-
-UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
-{
- UInt32 hash2Value, curMatch2;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
- MT_HASH2_CALC
-
- curMatch2 = hash[hash2Value];
- hash[hash2Value] = lzPos;
-
- if (curMatch2 >= matchMinPos)
- if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
- {
- *distances++ = 2;
- *distances++ = lzPos - curMatch2 - 1;
- }
- return distances;
-}
-
-UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, curMatch2, curMatch3;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
- MT_HASH3_CALC
-
- curMatch2 = hash[ hash2Value];
- curMatch3 = hash[kFix3HashSize + hash3Value];
-
- hash[ hash2Value] =
- hash[kFix3HashSize + hash3Value] =
- lzPos;
-
- if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
- {
- distances[1] = lzPos - curMatch2 - 1;
- if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
- {
- distances[0] = 3;
- return distances + 2;
- }
- distances[0] = 2;
- distances += 2;
- }
- if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
- {
- *distances++ = 3;
- *distances++ = lzPos - curMatch3 - 1;
- }
- return distances;
-}
-
-/*
-UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
- MT_HASH4_CALC
-
- curMatch2 = hash[ hash2Value];
- curMatch3 = hash[kFix3HashSize + hash3Value];
- curMatch4 = hash[kFix4HashSize + hash4Value];
-
- hash[ hash2Value] =
- hash[kFix3HashSize + hash3Value] =
- hash[kFix4HashSize + hash4Value] =
- lzPos;
-
- if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
- {
- distances[1] = lzPos - curMatch2 - 1;
- if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
- {
- distances[0] = (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;
- return distances + 2;
- }
- distances[0] = 2;
- distances += 2;
- }
- if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
- {
- distances[1] = lzPos - curMatch3 - 1;
- if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])
- {
- distances[0] = 4;
- return distances + 2;
- }
- distances[0] = 3;
- distances += 2;
- }
-
- if (curMatch4 >= matchMinPos)
- if (
- cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&
- cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]
- )
- {
- *distances++ = 4;
- *distances++ = lzPos - curMatch4 - 1;
- }
- return distances;
-}
-*/
-
-#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
-
-UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
- const UInt32 *btBuf = p->btBuf + p->btBufPos;
- UInt32 len = *btBuf++;
- p->btBufPos += 1 + len;
- p->btNumAvailBytes--;
- {
- UInt32 i;
- for (i = 0; i < len; i += 2)
- {
- *distances++ = *btBuf++;
- *distances++ = *btBuf++;
- }
- }
- INCREASE_LZ_POS
- return len;
-}
-
-UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
- const UInt32 *btBuf = p->btBuf + p->btBufPos;
- UInt32 len = *btBuf++;
- p->btBufPos += 1 + len;
-
- if (len == 0)
- {
- if (p->btNumAvailBytes-- >= 4)
- len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));
- }
- else
- {
- /* Condition: there are matches in btBuf with length < p->numHashBytes */
- UInt32 *distances2;
- p->btNumAvailBytes--;
- distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);
- do
- {
- *distances2++ = *btBuf++;
- *distances2++ = *btBuf++;
- }
- while ((len -= 2) != 0);
- len = (UInt32)(distances2 - (distances));
- }
- INCREASE_LZ_POS
- return len;
-}
-
-#define SKIP_HEADER2 do { GET_NEXT_BLOCK_IF_REQUIRED
-#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;
-#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);
-
-void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER2 { p->btNumAvailBytes--;
- SKIP_FOOTER
-}
-
-void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER(2)
- UInt32 hash2Value;
- MT_HASH2_CALC
- hash[hash2Value] = p->lzPos;
- SKIP_FOOTER
-}
-
-void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER(3)
- UInt32 hash2Value, hash3Value;
- MT_HASH3_CALC
- hash[kFix3HashSize + hash3Value] =
- hash[ hash2Value] =
- p->lzPos;
- SKIP_FOOTER
-}
-
-/*
-void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER(4)
- UInt32 hash2Value, hash3Value, hash4Value;
- MT_HASH4_CALC
- hash[kFix4HashSize + hash4Value] =
- hash[kFix3HashSize + hash3Value] =
- hash[ hash2Value] =
- p->lzPos;
- SKIP_FOOTER
-}
-*/
-
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
-{
- vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;
- vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;
- vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;
- vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;
- vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;
- switch(p->MatchFinder->numHashBytes)
- {
- case 2:
- p->GetHeadsFunc = GetHeads2;
- p->MixMatchesFunc = (Mf_Mix_Matches)0;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;
- vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;
- break;
- case 3:
- p->GetHeadsFunc = GetHeads3;
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;
- break;
- default:
- /* case 4: */
- p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;
- /* p->GetHeadsFunc = GetHeads4; */
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;
- break;
- /*
- default:
- p->GetHeadsFunc = GetHeads5;
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;
- break;
- */
- }
-}
diff --git a/desmume/src/windows/7z/C/LzFindMt.h b/desmume/src/windows/7z/C/LzFindMt.h
deleted file mode 100644
index b7ead2d47..000000000
--- a/desmume/src/windows/7z/C/LzFindMt.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
-2008-10-04 : Igor Pavlov : Public domain */
-
-#ifndef __LZFINDMT_H
-#define __LZFINDMT_H
-
-#include "Threads.h"
-#include "LzFind.h"
-
-#define kMtHashBlockSize (1 << 13)
-#define kMtHashNumBlocks (1 << 3)
-#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
-
-#define kMtBtBlockSize (1 << 14)
-#define kMtBtNumBlocks (1 << 6)
-#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
-
-typedef struct _CMtSync
-{
- Bool wasCreated;
- Bool needStart;
- Bool exit;
- Bool stopWriting;
-
- CThread thread;
- CAutoResetEvent canStart;
- CAutoResetEvent wasStarted;
- CAutoResetEvent wasStopped;
- CSemaphore freeSemaphore;
- CSemaphore filledSemaphore;
- Bool csWasInitialized;
- Bool csWasEntered;
- CCriticalSection cs;
- UInt32 numProcessedBlocks;
-} CMtSync;
-
-typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
-
-/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
-#define kMtCacheLineDummy 128
-
-typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
- UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
-
-typedef struct _CMatchFinderMt
-{
- /* LZ */
- const Byte *pointerToCurPos;
- UInt32 *btBuf;
- UInt32 btBufPos;
- UInt32 btBufPosLimit;
- UInt32 lzPos;
- UInt32 btNumAvailBytes;
-
- UInt32 *hash;
- UInt32 fixedHashSize;
- UInt32 historySize;
- const UInt32 *crc;
-
- Mf_Mix_Matches MixMatchesFunc;
-
- /* LZ + BT */
- CMtSync btSync;
- Byte btDummy[kMtCacheLineDummy];
-
- /* BT */
- UInt32 *hashBuf;
- UInt32 hashBufPos;
- UInt32 hashBufPosLimit;
- UInt32 hashNumAvail;
-
- CLzRef *son;
- UInt32 matchMaxLen;
- UInt32 numHashBytes;
- UInt32 pos;
- Byte *buffer;
- UInt32 cyclicBufferPos;
- UInt32 cyclicBufferSize; /* it must be historySize + 1 */
- UInt32 cutValue;
-
- /* BT + Hash */
- CMtSync hashSync;
- /* Byte hashDummy[kMtCacheLineDummy]; */
-
- /* Hash */
- Mf_GetHeads GetHeadsFunc;
- CMatchFinder *MatchFinder;
-} CMatchFinderMt;
-
-void MatchFinderMt_Construct(CMatchFinderMt *p);
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
-
-#endif
diff --git a/desmume/src/windows/7z/C/LzHash.h b/desmume/src/windows/7z/C/LzHash.h
deleted file mode 100644
index c92341750..000000000
--- a/desmume/src/windows/7z/C/LzHash.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* LzHash.h -- HASH functions for LZ algorithms
-2008-10-04 : Igor Pavlov : Public domain */
-
-#ifndef __LZHASH_H
-#define __LZHASH_H
-
-#define kHash2Size (1 << 10)
-#define kHash3Size (1 << 16)
-#define kHash4Size (1 << 20)
-
-#define kFix3HashSize (kHash2Size)
-#define kFix4HashSize (kHash2Size + kHash3Size)
-#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
-
-#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
-
-#define HASH3_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
-
-#define HASH4_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
-
-#define HASH5_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
- hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
- hash4Value &= (kHash4Size - 1); }
-
-/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
-#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
-
-
-#define MT_HASH2_CALC \
- hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
-
-#define MT_HASH3_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
-
-#define MT_HASH4_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
-
-#endif
diff --git a/desmume/src/windows/7z/C/LzmaDec.c b/desmume/src/windows/7z/C/LzmaDec.c
deleted file mode 100644
index e40e4286e..000000000
--- a/desmume/src/windows/7z/C/LzmaDec.c
+++ /dev/null
@@ -1,1007 +0,0 @@
-/* LzmaDec.c -- LZMA Decoder
-2008-11-06 : Igor Pavlov : Public domain */
-
-#include "LzmaDec.h"
-
-#include
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-
-#define RC_INIT_SIZE 5
-
-#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
-
-#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
-#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
-#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
-#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
- { UPDATE_0(p); i = (i + i); A0; } else \
- { UPDATE_1(p); i = (i + i) + 1; A1; }
-#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
-
-#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
-#define TREE_DECODE(probs, limit, i) \
- { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
-
-/* #define _LZMA_SIZE_OPT */
-
-#ifdef _LZMA_SIZE_OPT
-#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
-#else
-#define TREE_6_DECODE(probs, i) \
- { i = 1; \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- i -= 0x40; }
-#endif
-
-#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
-
-#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
-#define UPDATE_0_CHECK range = bound;
-#define UPDATE_1_CHECK range -= bound; code -= bound;
-#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
- { UPDATE_0_CHECK; i = (i + i); A0; } else \
- { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
-#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
-#define TREE_DECODE_CHECK(probs, limit, i) \
- { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
-
-
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumMidBits 3
-#define kLenNumMidSymbols (1 << kLenNumMidBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-
-#define LenChoice 0
-#define LenChoice2 (LenChoice + 1)
-#define LenLow (LenChoice2 + 1)
-#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
-#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-
-
-#define kNumStates 12
-#define kNumLitStates 7
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-
-#define kMatchMinLen 2
-#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
-
-#define IsMatch 0
-#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
-#define IsRepG0 (IsRep + kNumStates)
-#define IsRepG1 (IsRepG0 + kNumStates)
-#define IsRepG2 (IsRepG1 + kNumStates)
-#define IsRep0Long (IsRepG2 + kNumStates)
-#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
-#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
-#define LenCoder (Align + kAlignTableSize)
-#define RepLenCoder (LenCoder + kNumLenProbs)
-#define Literal (RepLenCoder + kNumLenProbs)
-
-#define LZMA_BASE_SIZE 1846
-#define LZMA_LIT_SIZE 768
-
-#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
-
-#if Literal != LZMA_BASE_SIZE
-StopCompilingDueBUG
-#endif
-
-static const Byte kLiteralNextStates[kNumStates * 2] =
-{
- 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,
- 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10
-};
-
-#define LZMA_DIC_MIN (1 << 12)
-
-/* First LZMA-symbol is always decoded.
-And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
-Out:
- Result:
- SZ_OK - OK
- SZ_ERROR_DATA - Error
- p->remainLen:
- < kMatchSpecLenStart : normal remain
- = kMatchSpecLenStart : finished
- = kMatchSpecLenStart + 1 : Flush marker
- = kMatchSpecLenStart + 2 : State Init Marker
-*/
-
-static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
-{
- CLzmaProb *probs = p->probs;
-
- unsigned state = p->state;
- UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
- unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
- unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
- unsigned lc = p->prop.lc;
-
- Byte *dic = p->dic;
- SizeT dicBufSize = p->dicBufSize;
- SizeT dicPos = p->dicPos;
-
- UInt32 processedPos = p->processedPos;
- UInt32 checkDicSize = p->checkDicSize;
- unsigned len = 0;
-
- const Byte *buf = p->buf;
- UInt32 range = p->range;
- UInt32 code = p->code;
-
- do
- {
- CLzmaProb *prob;
- UInt32 bound;
- unsigned ttt;
- unsigned posState = processedPos & pbMask;
-
- prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
- IF_BIT_0(prob)
- {
- unsigned symbol;
- UPDATE_0(prob);
- prob = probs + Literal;
- if (checkDicSize != 0 || processedPos != 0)
- prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
- (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
-
- if (state < kNumLitStates)
- {
- symbol = 1;
- do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
- }
- else
- {
- unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
- unsigned offs = 0x100;
- symbol = 1;
- do
- {
- unsigned bit;
- CLzmaProb *probLit;
- matchByte <<= 1;
- bit = (matchByte & offs);
- probLit = prob + offs + bit + symbol;
- GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
- }
- while (symbol < 0x100);
- }
- dic[dicPos++] = (Byte)(symbol & 0xFF);
- processedPos++;
-
- state = kLiteralNextStates[state];
- /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */
- continue;
- }
- else
- {
- UPDATE_1(prob);
- prob = probs + IsRep + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- state += kNumStates;
- prob = probs + LenCoder;
- }
- else
- {
- UPDATE_1(prob);
- if (checkDicSize == 0 && processedPos == 0)
- return SZ_ERROR_DATA;
- prob = probs + IsRepG0 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
- dicPos++;
- processedPos++;
- state = state < kNumLitStates ? 9 : 11;
- continue;
- }
- UPDATE_1(prob);
- }
- else
- {
- UInt32 distance;
- UPDATE_1(prob);
- prob = probs + IsRepG1 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep1;
- }
- else
- {
- UPDATE_1(prob);
- prob = probs + IsRepG2 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep2;
- }
- else
- {
- UPDATE_1(prob);
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- state = state < kNumLitStates ? 8 : 11;
- prob = probs + RepLenCoder;
- }
- {
- unsigned limit, offset;
- CLzmaProb *probLen = prob + LenChoice;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- limit = (1 << kLenNumLowBits);
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenChoice2;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- limit = (1 << kLenNumMidBits);
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- limit = (1 << kLenNumHighBits);
- }
- }
- TREE_DECODE(probLen, limit, len);
- len += offset;
- }
-
- if (state >= kNumStates)
- {
- UInt32 distance;
- prob = probs + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
- TREE_6_DECODE(prob, distance);
- if (distance >= kStartPosModelIndex)
- {
- unsigned posSlot = (unsigned)distance;
- int numDirectBits = (int)(((distance >> 1) - 1));
- distance = (2 | (distance & 1));
- if (posSlot < kEndPosModelIndex)
- {
- distance <<= numDirectBits;
- prob = probs + SpecPos + distance - posSlot - 1;
- {
- UInt32 mask = 1;
- unsigned i = 1;
- do
- {
- GET_BIT2(prob + i, i, ; , distance |= mask);
- mask <<= 1;
- }
- while (--numDirectBits != 0);
- }
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE
- range >>= 1;
-
- {
- UInt32 t;
- code -= range;
- t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
- distance = (distance << 1) + (t + 1);
- code += range & t;
- }
- /*
- distance <<= 1;
- if (code >= range)
- {
- code -= range;
- distance |= 1;
- }
- */
- }
- while (--numDirectBits != 0);
- prob = probs + Align;
- distance <<= kNumAlignBits;
- {
- unsigned i = 1;
- GET_BIT2(prob + i, i, ; , distance |= 1);
- GET_BIT2(prob + i, i, ; , distance |= 2);
- GET_BIT2(prob + i, i, ; , distance |= 4);
- GET_BIT2(prob + i, i, ; , distance |= 8);
- }
- if (distance == (UInt32)0xFFFFFFFF)
- {
- len += kMatchSpecLenStart;
- state -= kNumStates;
- break;
- }
- }
- }
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- rep0 = distance + 1;
- if (checkDicSize == 0)
- {
- if (distance >= processedPos)
- return SZ_ERROR_DATA;
- }
- else if (distance >= checkDicSize)
- return SZ_ERROR_DATA;
- state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
- /* state = kLiteralNextStates[state]; */
- }
-
- len += kMatchMinLen;
-
- if (limit == dicPos)
- return SZ_ERROR_DATA;
- {
- SizeT rem = limit - dicPos;
- unsigned curLen = ((rem < len) ? (unsigned)rem : len);
- SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
-
- processedPos += curLen;
-
- len -= curLen;
- if (pos + curLen <= dicBufSize)
- {
- Byte *dest = dic + dicPos;
- ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
- const Byte *lim = dest + curLen;
- dicPos += curLen;
- do
- *(dest) = (Byte)*(dest + src);
- while (++dest != lim);
- }
- else
- {
- do
- {
- dic[dicPos++] = dic[pos];
- if (++pos == dicBufSize)
- pos = 0;
- }
- while (--curLen != 0);
- }
- }
- }
- }
- while (dicPos < limit && buf < bufLimit);
- NORMALIZE;
- p->buf = buf;
- p->range = range;
- p->code = code;
- p->remainLen = len;
- p->dicPos = dicPos;
- p->processedPos = processedPos;
- p->reps[0] = rep0;
- p->reps[1] = rep1;
- p->reps[2] = rep2;
- p->reps[3] = rep3;
- p->state = state;
-
- return SZ_OK;
-}
-
-static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
-{
- if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
- {
- Byte *dic = p->dic;
- SizeT dicPos = p->dicPos;
- SizeT dicBufSize = p->dicBufSize;
- unsigned len = p->remainLen;
- UInt32 rep0 = p->reps[0];
- if (limit - dicPos < len)
- len = (unsigned)(limit - dicPos);
-
- if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
- p->checkDicSize = p->prop.dicSize;
-
- p->processedPos += len;
- p->remainLen -= len;
- while (len-- != 0)
- {
- dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
- dicPos++;
- }
- p->dicPos = dicPos;
- }
-}
-
-static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
-{
- do
- {
- SizeT limit2 = limit;
- if (p->checkDicSize == 0)
- {
- UInt32 rem = p->prop.dicSize - p->processedPos;
- if (limit - p->dicPos > rem)
- limit2 = p->dicPos + rem;
- }
- RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
- if (p->processedPos >= p->prop.dicSize)
- p->checkDicSize = p->prop.dicSize;
- LzmaDec_WriteRem(p, limit);
- }
- while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
-
- if (p->remainLen > kMatchSpecLenStart)
- {
- p->remainLen = kMatchSpecLenStart;
- }
- return 0;
-}
-
-typedef enum
-{
- DUMMY_ERROR, /* unexpected end of input stream */
- DUMMY_LIT,
- DUMMY_MATCH,
- DUMMY_REP
-} ELzmaDummy;
-
-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
-{
- UInt32 range = p->range;
- UInt32 code = p->code;
- const Byte *bufLimit = buf + inSize;
- CLzmaProb *probs = p->probs;
- unsigned state = p->state;
- ELzmaDummy res;
-
- {
- CLzmaProb *prob;
- UInt32 bound;
- unsigned ttt;
- unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
-
- prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK
-
- /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
-
- prob = probs + Literal;
- if (p->checkDicSize != 0 || p->processedPos != 0)
- prob += (LZMA_LIT_SIZE *
- ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
- (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
-
- if (state < kNumLitStates)
- {
- unsigned symbol = 1;
- do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
- }
- else
- {
- unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
- ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
- unsigned offs = 0x100;
- unsigned symbol = 1;
- do
- {
- unsigned bit;
- CLzmaProb *probLit;
- matchByte <<= 1;
- bit = (matchByte & offs);
- probLit = prob + offs + bit + symbol;
- GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
- }
- while (symbol < 0x100);
- }
- res = DUMMY_LIT;
- }
- else
- {
- unsigned len;
- UPDATE_1_CHECK;
-
- prob = probs + IsRep + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- state = 0;
- prob = probs + LenCoder;
- res = DUMMY_MATCH;
- }
- else
- {
- UPDATE_1_CHECK;
- res = DUMMY_REP;
- prob = probs + IsRepG0 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- NORMALIZE_CHECK;
- return DUMMY_REP;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG1 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG2 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- }
- state = kNumStates;
- prob = probs + RepLenCoder;
- }
- {
- unsigned limit, offset;
- CLzmaProb *probLen = prob + LenChoice;
- IF_BIT_0_CHECK(probLen)
- {
- UPDATE_0_CHECK;
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- limit = 1 << kLenNumLowBits;
- }
- else
- {
- UPDATE_1_CHECK;
- probLen = prob + LenChoice2;
- IF_BIT_0_CHECK(probLen)
- {
- UPDATE_0_CHECK;
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- limit = 1 << kLenNumMidBits;
- }
- else
- {
- UPDATE_1_CHECK;
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- limit = 1 << kLenNumHighBits;
- }
- }
- TREE_DECODE_CHECK(probLen, limit, len);
- len += offset;
- }
-
- if (state < 4)
- {
- unsigned posSlot;
- prob = probs + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits);
- TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
- if (posSlot >= kStartPosModelIndex)
- {
- int numDirectBits = ((posSlot >> 1) - 1);
-
- /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
-
- if (posSlot < kEndPosModelIndex)
- {
- prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE_CHECK
- range >>= 1;
- code -= range & (((code - range) >> 31) - 1);
- /* if (code >= range) code -= range; */
- }
- while (--numDirectBits != 0);
- prob = probs + Align;
- numDirectBits = kNumAlignBits;
- }
- {
- unsigned i = 1;
- do
- {
- GET_BIT_CHECK(prob + i, i);
- }
- while (--numDirectBits != 0);
- }
- }
- }
- }
- }
- NORMALIZE_CHECK;
- return res;
-}
-
-
-static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
-{
- p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
- p->range = 0xFFFFFFFF;
- p->needFlush = 0;
-}
-
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
-{
- p->needFlush = 1;
- p->remainLen = 0;
- p->tempBufSize = 0;
-
- if (initDic)
- {
- p->processedPos = 0;
- p->checkDicSize = 0;
- p->needInitState = 1;
- }
- if (initState)
- p->needInitState = 1;
-}
-
-void LzmaDec_Init(CLzmaDec *p)
-{
- p->dicPos = 0;
- LzmaDec_InitDicAndState(p, True, True);
-}
-
-static void LzmaDec_InitStateReal(CLzmaDec *p)
-{
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
- UInt32 i;
- CLzmaProb *probs = p->probs;
- for (i = 0; i < numProbs; i++)
- probs[i] = kBitModelTotal >> 1;
- p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
- p->state = 0;
- p->needInitState = 0;
-}
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
- ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT inSize = *srcLen;
- (*srcLen) = 0;
- LzmaDec_WriteRem(p, dicLimit);
-
- *status = LZMA_STATUS_NOT_SPECIFIED;
-
- while (p->remainLen != kMatchSpecLenStart)
- {
- int checkEndMarkNow;
-
- if (p->needFlush != 0)
- {
- for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
- p->tempBuf[p->tempBufSize++] = *src++;
- if (p->tempBufSize < RC_INIT_SIZE)
- {
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (p->tempBuf[0] != 0)
- return SZ_ERROR_DATA;
-
- LzmaDec_InitRc(p, p->tempBuf);
- p->tempBufSize = 0;
- }
-
- checkEndMarkNow = 0;
- if (p->dicPos >= dicLimit)
- {
- if (p->remainLen == 0 && p->code == 0)
- {
- *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
- return SZ_OK;
- }
- if (finishMode == LZMA_FINISH_ANY)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_OK;
- }
- if (p->remainLen != 0)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- checkEndMarkNow = 1;
- }
-
- if (p->needInitState)
- LzmaDec_InitStateReal(p);
-
- if (p->tempBufSize == 0)
- {
- SizeT processed;
- const Byte *bufLimit;
- if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- int dummyRes = LzmaDec_TryDummy(p, src, inSize);
- if (dummyRes == DUMMY_ERROR)
- {
- memcpy(p->tempBuf, src, inSize);
- p->tempBufSize = (unsigned)inSize;
- (*srcLen) += inSize;
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- bufLimit = src;
- }
- else
- bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
- p->buf = src;
- if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
- return SZ_ERROR_DATA;
- processed = (SizeT)(p->buf - src);
- (*srcLen) += processed;
- src += processed;
- inSize -= processed;
- }
- else
- {
- unsigned rem = p->tempBufSize, lookAhead = 0;
- while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
- p->tempBuf[rem++] = src[lookAhead++];
- p->tempBufSize = rem;
- if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
- if (dummyRes == DUMMY_ERROR)
- {
- (*srcLen) += lookAhead;
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- }
- p->buf = p->tempBuf;
- if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
- return SZ_ERROR_DATA;
- lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
- (*srcLen) += lookAhead;
- src += lookAhead;
- inSize -= lookAhead;
- p->tempBufSize = 0;
- }
- }
- if (p->code == 0)
- *status = LZMA_STATUS_FINISHED_WITH_MARK;
- return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
-}
-
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT outSize = *destLen;
- SizeT inSize = *srcLen;
- *srcLen = *destLen = 0;
- for (;;)
- {
- SizeT inSizeCur = inSize, outSizeCur, dicPos;
- ELzmaFinishMode curFinishMode;
- SRes res;
- if (p->dicPos == p->dicBufSize)
- p->dicPos = 0;
- dicPos = p->dicPos;
- if (outSize > p->dicBufSize - dicPos)
- {
- outSizeCur = p->dicBufSize;
- curFinishMode = LZMA_FINISH_ANY;
- }
- else
- {
- outSizeCur = dicPos + outSize;
- curFinishMode = finishMode;
- }
-
- res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
- src += inSizeCur;
- inSize -= inSizeCur;
- *srcLen += inSizeCur;
- outSizeCur = p->dicPos - dicPos;
- memcpy(dest, p->dic + dicPos, outSizeCur);
- dest += outSizeCur;
- outSize -= outSizeCur;
- *destLen += outSizeCur;
- if (res != 0)
- return res;
- if (outSizeCur == 0 || outSize == 0)
- return SZ_OK;
- }
-}
-
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->probs);
- p->probs = 0;
-}
-
-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->dic);
- p->dic = 0;
-}
-
-void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
-{
- LzmaDec_FreeProbs(p, alloc);
- LzmaDec_FreeDict(p, alloc);
-}
-
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
-{
- UInt32 dicSize;
- Byte d;
-
- if (size < LZMA_PROPS_SIZE)
- return SZ_ERROR_UNSUPPORTED;
- else
- dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
-
- if (dicSize < LZMA_DIC_MIN)
- dicSize = LZMA_DIC_MIN;
- p->dicSize = dicSize;
-
- d = data[0];
- if (d >= (9 * 5 * 5))
- return SZ_ERROR_UNSUPPORTED;
-
- p->lc = d % 9;
- d /= 9;
- p->pb = d / 5;
- p->lp = d % 5;
-
- return SZ_OK;
-}
-
-static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
-{
- UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
- if (p->probs == 0 || numProbs != p->numProbs)
- {
- LzmaDec_FreeProbs(p, alloc);
- p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
- p->numProbs = numProbs;
- if (p->probs == 0)
- return SZ_ERROR_MEM;
- }
- return SZ_OK;
-}
-
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
-{
- CLzmaProps propNew;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
- p->prop = propNew;
- return SZ_OK;
-}
-
-SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
-{
- CLzmaProps propNew;
- SizeT dicBufSize;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
- dicBufSize = propNew.dicSize;
- if (p->dic == 0 || dicBufSize != p->dicBufSize)
- {
- LzmaDec_FreeDict(p, alloc);
- p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
- if (p->dic == 0)
- {
- LzmaDec_FreeProbs(p, alloc);
- return SZ_ERROR_MEM;
- }
- }
- p->dicBufSize = dicBufSize;
- p->prop = propNew;
- return SZ_OK;
-}
-
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAlloc *alloc)
-{
- CLzmaDec p;
- SRes res;
- SizeT inSize = *srcLen;
- SizeT outSize = *destLen;
- *srcLen = *destLen = 0;
- if (inSize < RC_INIT_SIZE)
- return SZ_ERROR_INPUT_EOF;
-
- LzmaDec_Construct(&p);
- res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
- if (res != 0)
- return res;
- p.dic = dest;
- p.dicBufSize = outSize;
-
- LzmaDec_Init(&p);
-
- *srcLen = inSize;
- res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
-
- if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
- res = SZ_ERROR_INPUT_EOF;
-
- (*destLen) = p.dicPos;
- LzmaDec_FreeProbs(&p, alloc);
- return res;
-}
diff --git a/desmume/src/windows/7z/C/LzmaDec.h b/desmume/src/windows/7z/C/LzmaDec.h
deleted file mode 100644
index ad7d7057a..000000000
--- a/desmume/src/windows/7z/C/LzmaDec.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/* LzmaDec.h -- LZMA Decoder
-2008-10-04 : Igor Pavlov : Public domain */
-
-#ifndef __LZMADEC_H
-#define __LZMADEC_H
-
-#include "Types.h"
-
-/* #define _LZMA_PROB32 */
-/* _LZMA_PROB32 can increase the speed on some CPUs,
- but memory usage for CLzmaDec::probs will be doubled in that case */
-
-#ifdef _LZMA_PROB32
-#define CLzmaProb UInt32
-#else
-#define CLzmaProb UInt16
-#endif
-
-
-/* ---------- LZMA Properties ---------- */
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaProps
-{
- unsigned lc, lp, pb;
- UInt32 dicSize;
-} CLzmaProps;
-
-/* LzmaProps_Decode - decodes properties
-Returns:
- SZ_OK
- SZ_ERROR_UNSUPPORTED - Unsupported properties
-*/
-
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
-
-
-/* ---------- LZMA Decoder state ---------- */
-
-/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
- Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
-
-#define LZMA_REQUIRED_INPUT_MAX 20
-
-typedef struct
-{
- CLzmaProps prop;
- CLzmaProb *probs;
- Byte *dic;
- const Byte *buf;
- UInt32 range, code;
- SizeT dicPos;
- SizeT dicBufSize;
- UInt32 processedPos;
- UInt32 checkDicSize;
- unsigned state;
- UInt32 reps[4];
- unsigned remainLen;
- int needFlush;
- int needInitState;
- UInt32 numProbs;
- unsigned tempBufSize;
- Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
-} CLzmaDec;
-
-#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
-
-void LzmaDec_Init(CLzmaDec *p);
-
-/* There are two types of LZMA streams:
- 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
- 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
-
-typedef enum
-{
- LZMA_FINISH_ANY, /* finish at any point */
- LZMA_FINISH_END /* block must be finished at the end */
-} ELzmaFinishMode;
-
-/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
-
- You must use LZMA_FINISH_END, when you know that current output buffer
- covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
-
- If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
- and output value of destLen will be less than output buffer size limit.
- You can check status result also.
-
- You can use multiple checks to test data integrity after full decompression:
- 1) Check Result and "status" variable.
- 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
- 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
- You must use correct finish mode in that case. */
-
-typedef enum
-{
- LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
- LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
- LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
- LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
-} ELzmaStatus;
-
-/* ELzmaStatus is used only as output value for function call */
-
-
-/* ---------- Interfaces ---------- */
-
-/* There are 3 levels of interfaces:
- 1) Dictionary Interface
- 2) Buffer Interface
- 3) One Call Interface
- You can select any of these interfaces, but don't mix functions from different
- groups for same object. */
-
-
-/* There are two variants to allocate state for Dictionary Interface:
- 1) LzmaDec_Allocate / LzmaDec_Free
- 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
- You can use variant 2, if you set dictionary buffer manually.
- For Buffer Interface you must always use variant 1.
-
-LzmaDec_Allocate* can return:
- SZ_OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
-*/
-
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
-
-SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
-void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
-
-/* ---------- Dictionary Interface ---------- */
-
-/* You can use it, if you want to eliminate the overhead for data copying from
- dictionary to some other external buffer.
- You must work with CLzmaDec variables directly in this interface.
-
- STEPS:
- LzmaDec_Constr()
- LzmaDec_Allocate()
- for (each new stream)
- {
- LzmaDec_Init()
- while (it needs more decompression)
- {
- LzmaDec_DecodeToDic()
- use data from CLzmaDec::dic and update CLzmaDec::dicPos
- }
- }
- LzmaDec_Free()
-*/
-
-/* LzmaDec_DecodeToDic
-
- The decoding to internal dictionary buffer (CLzmaDec::dic).
- You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
-
-finishMode:
- It has meaning only if the decoding reaches output limit (dicLimit).
- LZMA_FINISH_ANY - Decode just dicLimit bytes.
- LZMA_FINISH_END - Stream must be finished after dicLimit.
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_NEEDS_MORE_INPUT
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
-*/
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-
-/* ---------- Buffer Interface ---------- */
-
-/* It's zlib-like interface.
- See LzmaDec_DecodeToDic description for information about STEPS and return results,
- but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
- to work with CLzmaDec variables manually.
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
-*/
-
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-
-/* ---------- One Call Interface ---------- */
-
-/* LzmaDecode
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
-*/
-
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAlloc *alloc);
-
-#endif
diff --git a/desmume/src/windows/7z/C/LzmaEnc.c b/desmume/src/windows/7z/C/LzmaEnc.c
deleted file mode 100644
index a5a82da91..000000000
--- a/desmume/src/windows/7z/C/LzmaEnc.c
+++ /dev/null
@@ -1,2275 +0,0 @@
-/* LzmaEnc.c -- LZMA Encoder
-2008-10-04 : Igor Pavlov : Public domain */
-
-#include
-
-/* #define SHOW_STAT */
-/* #define SHOW_STAT2 */
-
-#if defined(SHOW_STAT) || defined(SHOW_STAT2)
-#include
-#endif
-
-#include "LzmaEnc.h"
-
-#include "LzFind.h"
-#ifdef COMPRESS_MF_MT
-#include "LzFindMt.h"
-#endif
-
-#ifdef SHOW_STAT
-static int ttt = 0;
-#endif
-
-#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)
-
-#define kBlockSize (9 << 10)
-#define kUnpackBlockSize (1 << 18)
-#define kMatchArraySize (1 << 21)
-#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)
-
-#define kNumMaxDirectBits (31)
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-#define kProbInitValue (kBitModelTotal >> 1)
-
-#define kNumMoveReducingBits 4
-#define kNumBitPriceShiftBits 4
-#define kBitPrice (1 << kNumBitPriceShiftBits)
-
-void LzmaEncProps_Init(CLzmaEncProps *p)
-{
- p->level = 5;
- p->dictSize = p->mc = 0;
- p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
- p->writeEndMark = 0;
-}
-
-void LzmaEncProps_Normalize(CLzmaEncProps *p)
-{
- int level = p->level;
- if (level < 0) level = 5;
- p->level = level;
- if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
- if (p->lc < 0) p->lc = 3;
- if (p->lp < 0) p->lp = 0;
- if (p->pb < 0) p->pb = 2;
- if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
- if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
- if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
- if (p->numHashBytes < 0) p->numHashBytes = 4;
- if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
- if (p->numThreads < 0) p->numThreads = ((p->btMode && p->algo) ? 2 : 1);
-}
-
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
-{
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
- return props.dictSize;
-}
-
-/* #define LZMA_LOG_BSR */
-/* Define it for Intel's CPU */
-
-
-#ifdef LZMA_LOG_BSR
-
-#define kDicLogSizeMaxCompress 30
-
-#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
-
-UInt32 GetPosSlot1(UInt32 pos)
-{
- UInt32 res;
- BSR2_RET(pos, res);
- return res;
-}
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
-
-#else
-
-#define kNumLogBits (9 + (int)sizeof(size_t) / 2)
-#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
-
-void LzmaEnc_FastPosInit(Byte *g_FastPos)
-{
- int c = 2, slotFast;
- g_FastPos[0] = 0;
- g_FastPos[1] = 1;
-
- for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)
- {
- UInt32 k = (1 << ((slotFast >> 1) - 1));
- UInt32 j;
- for (j = 0; j < k; j++, c++)
- g_FastPos[c] = (Byte)slotFast;
- }
-}
-
-#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \
- (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
- res = p->g_FastPos[pos >> i] + (i * 2); }
-/*
-#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
- p->g_FastPos[pos >> 6] + 12 : \
- p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
-*/
-
-#define GetPosSlot1(pos) p->g_FastPos[pos]
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }
-
-#endif
-
-
-#define LZMA_NUM_REPS 4
-
-typedef unsigned CState;
-
-typedef struct _COptimal
-{
- UInt32 price;
-
- CState state;
- int prev1IsChar;
- int prev2;
-
- UInt32 posPrev2;
- UInt32 backPrev2;
-
- UInt32 posPrev;
- UInt32 backPrev;
- UInt32 backs[LZMA_NUM_REPS];
-} COptimal;
-
-#define kNumOpts (1 << 12)
-
-#define kNumLenToPosStates 4
-#define kNumPosSlotBits 6
-#define kDicLogSizeMin 0
-#define kDicLogSizeMax 32
-#define kDistTableSizeMax (kDicLogSizeMax * 2)
-
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-#define kAlignMask (kAlignTableSize - 1)
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)
-
-#define kNumFullDistances (1 << (kEndPosModelIndex / 2))
-
-#ifdef _LZMA_PROB32
-#define CLzmaProb UInt32
-#else
-#define CLzmaProb UInt16
-#endif
-
-#define LZMA_PB_MAX 4
-#define LZMA_LC_MAX 8
-#define LZMA_LP_MAX 4
-
-#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
-
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumMidBits 3
-#define kLenNumMidSymbols (1 << kLenNumMidBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-
-#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
-
-#define LZMA_MATCH_LEN_MIN 2
-#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
-
-#define kNumStates 12
-
-typedef struct
-{
- CLzmaProb choice;
- CLzmaProb choice2;
- CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];
- CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];
- CLzmaProb high[kLenNumHighSymbols];
-} CLenEnc;
-
-typedef struct
-{
- CLenEnc p;
- UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
- UInt32 tableSize;
- UInt32 counters[LZMA_NUM_PB_STATES_MAX];
-} CLenPriceEnc;
-
-typedef struct _CRangeEnc
-{
- UInt32 range;
- Byte cache;
- UInt64 low;
- UInt64 cacheSize;
- Byte *buf;
- Byte *bufLim;
- Byte *bufBase;
- ISeqOutStream *outStream;
- UInt64 processed;
- SRes res;
-} CRangeEnc;
-
-typedef struct _CSeqInStreamBuf
-{
- ISeqInStream funcTable;
- const Byte *data;
- SizeT rem;
-} CSeqInStreamBuf;
-
-static SRes MyRead(void *pp, void *data, size_t *size)
-{
- size_t curSize = *size;
- CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;
- if (p->rem < curSize)
- curSize = p->rem;
- memcpy(data, p->data, curSize);
- p->rem -= curSize;
- p->data += curSize;
- *size = curSize;
- return SZ_OK;
-}
-
-typedef struct
-{
- CLzmaProb *litProbs;
-
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
-
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
-
- CLenPriceEnc lenEnc;
- CLenPriceEnc repLenEnc;
-
- UInt32 reps[LZMA_NUM_REPS];
- UInt32 state;
-} CSaveState;
-
-typedef struct _CLzmaEnc
-{
- IMatchFinder matchFinder;
- void *matchFinderObj;
-
- #ifdef COMPRESS_MF_MT
- Bool mtMode;
- CMatchFinderMt matchFinderMt;
- #endif
-
- CMatchFinder matchFinderBase;
-
- #ifdef COMPRESS_MF_MT
- Byte pad[128];
- #endif
-
- UInt32 optimumEndIndex;
- UInt32 optimumCurrentIndex;
-
- UInt32 longestMatchLength;
- UInt32 numPairs;
- UInt32 numAvail;
- COptimal opt[kNumOpts];
-
- #ifndef LZMA_LOG_BSR
- Byte g_FastPos[1 << kNumLogBits];
- #endif
-
- UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
- UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
- UInt32 numFastBytes;
- UInt32 additionalOffset;
- UInt32 reps[LZMA_NUM_REPS];
- UInt32 state;
-
- UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
- UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
- UInt32 alignPrices[kAlignTableSize];
- UInt32 alignPriceCount;
-
- UInt32 distTableSize;
-
- unsigned lc, lp, pb;
- unsigned lpMask, pbMask;
-
- CLzmaProb *litProbs;
-
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
-
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
-
- CLenPriceEnc lenEnc;
- CLenPriceEnc repLenEnc;
-
- unsigned lclp;
-
- Bool fastMode;
-
- CRangeEnc rc;
-
- Bool writeEndMark;
- UInt64 nowPos64;
- UInt32 matchPriceCount;
- Bool finished;
- Bool multiThread;
-
- SRes result;
- UInt32 dictSize;
- UInt32 matchFinderCycles;
-
- ISeqInStream *inStream;
- CSeqInStreamBuf seqBufInStream;
-
- CSaveState saveState;
-} CLzmaEnc;
-
-void LzmaEnc_SaveState(CLzmaEncHandle pp)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CSaveState *dest = &p->saveState;
- int i;
- dest->lenEnc = p->lenEnc;
- dest->repLenEnc = p->repLenEnc;
- dest->state = p->state;
-
- for (i = 0; i < kNumStates; i++)
- {
- memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
- memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
- }
- for (i = 0; i < kNumLenToPosStates; i++)
- memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
- memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
- memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
- memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
- memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
- memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
- memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
- memcpy(dest->reps, p->reps, sizeof(p->reps));
- memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
-}
-
-void LzmaEnc_RestoreState(CLzmaEncHandle pp)
-{
- CLzmaEnc *dest = (CLzmaEnc *)pp;
- const CSaveState *p = &dest->saveState;
- int i;
- dest->lenEnc = p->lenEnc;
- dest->repLenEnc = p->repLenEnc;
- dest->state = p->state;
-
- for (i = 0; i < kNumStates; i++)
- {
- memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
- memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
- }
- for (i = 0; i < kNumLenToPosStates; i++)
- memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
- memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
- memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
- memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
- memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
- memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
- memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
- memcpy(dest->reps, p->reps, sizeof(p->reps));
- memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
-}
-
-SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
-
- if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||
- props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))
- return SZ_ERROR_PARAM;
- p->dictSize = props.dictSize;
- p->matchFinderCycles = props.mc;
- {
- unsigned fb = props.fb;
- if (fb < 5)
- fb = 5;
- if (fb > LZMA_MATCH_LEN_MAX)
- fb = LZMA_MATCH_LEN_MAX;
- p->numFastBytes = fb;
- }
- p->lc = props.lc;
- p->lp = props.lp;
- p->pb = props.pb;
- p->fastMode = (props.algo == 0);
- p->matchFinderBase.btMode = props.btMode;
- {
- UInt32 numHashBytes = 4;
- if (props.btMode)
- {
- if (props.numHashBytes < 2)
- numHashBytes = 2;
- else if (props.numHashBytes < 4)
- numHashBytes = props.numHashBytes;
- }
- p->matchFinderBase.numHashBytes = numHashBytes;
- }
-
- p->matchFinderBase.cutValue = props.mc;
-
- p->writeEndMark = props.writeEndMark;
-
- #ifdef COMPRESS_MF_MT
- /*
- if (newMultiThread != _multiThread)
- {
- ReleaseMatchFinder();
- _multiThread = newMultiThread;
- }
- */
- p->multiThread = (props.numThreads > 1);
- #endif
-
- return SZ_OK;
-}
-
-static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
-static const int kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
-static const int kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
-static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
-
-#define IsCharState(s) ((s) < 7)
-
-#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
-
-#define kInfinityPrice (1 << 30)
-
-static void RangeEnc_Construct(CRangeEnc *p)
-{
- p->outStream = 0;
- p->bufBase = 0;
-}
-
-#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
-
-#define RC_BUF_SIZE (1 << 16)
-static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
-{
- if (p->bufBase == 0)
- {
- p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);
- if (p->bufBase == 0)
- return 0;
- p->bufLim = p->bufBase + RC_BUF_SIZE;
- }
- return 1;
-}
-
-static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->bufBase);
- p->bufBase = 0;
-}
-
-static void RangeEnc_Init(CRangeEnc *p)
-{
- /* Stream.Init(); */
- p->low = 0;
- p->range = 0xFFFFFFFF;
- p->cacheSize = 1;
- p->cache = 0;
-
- p->buf = p->bufBase;
-
- p->processed = 0;
- p->res = SZ_OK;
-}
-
-static void RangeEnc_FlushStream(CRangeEnc *p)
-{
- size_t num;
- if (p->res != SZ_OK)
- return;
- num = p->buf - p->bufBase;
- if (num != p->outStream->Write(p->outStream, p->bufBase, num))
- p->res = SZ_ERROR_WRITE;
- p->processed += num;
- p->buf = p->bufBase;
-}
-
-static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
-{
- if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)
- {
- Byte temp = p->cache;
- do
- {
- Byte *buf = p->buf;
- *buf++ = (Byte)(temp + (Byte)(p->low >> 32));
- p->buf = buf;
- if (buf == p->bufLim)
- RangeEnc_FlushStream(p);
- temp = 0xFF;
- }
- while (--p->cacheSize != 0);
- p->cache = (Byte)((UInt32)p->low >> 24);
- }
- p->cacheSize++;
- p->low = (UInt32)p->low << 8;
-}
-
-static void RangeEnc_FlushData(CRangeEnc *p)
-{
- int i;
- for (i = 0; i < 5; i++)
- RangeEnc_ShiftLow(p);
-}
-
-static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)
-{
- do
- {
- p->range >>= 1;
- p->low += p->range & (0 - ((value >> --numBits) & 1));
- if (p->range < kTopValue)
- {
- p->range <<= 8;
- RangeEnc_ShiftLow(p);
- }
- }
- while (numBits != 0);
-}
-
-static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)
-{
- UInt32 ttt = *prob;
- UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;
- if (symbol == 0)
- {
- p->range = newBound;
- ttt += (kBitModelTotal - ttt) >> kNumMoveBits;
- }
- else
- {
- p->low += newBound;
- p->range -= newBound;
- ttt -= ttt >> kNumMoveBits;
- }
- *prob = (CLzmaProb)ttt;
- if (p->range < kTopValue)
- {
- p->range <<= 8;
- RangeEnc_ShiftLow(p);
- }
-}
-
-static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
-{
- symbol |= 0x100;
- do
- {
- RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
- symbol <<= 1;
- }
- while (symbol < 0x10000);
-}
-
-static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)
-{
- UInt32 offs = 0x100;
- symbol |= 0x100;
- do
- {
- matchByte <<= 1;
- RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
- symbol <<= 1;
- offs &= ~(matchByte ^ symbol);
- }
- while (symbol < 0x10000);
-}
-
-void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
-{
- UInt32 i;
- for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
- {
- const int kCyclesBits = kNumBitPriceShiftBits;
- UInt32 w = i;
- UInt32 bitCount = 0;
- int j;
- for (j = 0; j < kCyclesBits; j++)
- {
- w = w * w;
- bitCount <<= 1;
- while (w >= ((UInt32)1 << 16))
- {
- w >>= 1;
- bitCount++;
- }
- }
- ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
- }
-}
-
-
-#define GET_PRICE(prob, symbol) \
- p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICEa(prob, symbol) \
- ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- symbol |= 0x100;
- do
- {
- price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
- symbol <<= 1;
- }
- while (symbol < 0x10000);
- return price;
-}
-
-static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- UInt32 offs = 0x100;
- symbol |= 0x100;
- do
- {
- matchByte <<= 1;
- price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
- symbol <<= 1;
- offs &= ~(matchByte ^ symbol);
- }
- while (symbol < 0x10000);
- return price;
-}
-
-
-static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
-{
- UInt32 m = 1;
- int i;
- for (i = numBitLevels; i != 0;)
- {
- UInt32 bit;
- i--;
- bit = (symbol >> i) & 1;
- RangeEnc_EncodeBit(rc, probs + m, bit);
- m = (m << 1) | bit;
- }
-}
-
-static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
-{
- UInt32 m = 1;
- int i;
- for (i = 0; i < numBitLevels; i++)
- {
- UInt32 bit = symbol & 1;
- RangeEnc_EncodeBit(rc, probs + m, bit);
- m = (m << 1) | bit;
- symbol >>= 1;
- }
-}
-
-static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- symbol |= (1 << numBitLevels);
- while (symbol != 1)
- {
- price += GET_PRICEa(probs[symbol >> 1], symbol & 1);
- symbol >>= 1;
- }
- return price;
-}
-
-static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- UInt32 m = 1;
- int i;
- for (i = numBitLevels; i != 0; i--)
- {
- UInt32 bit = symbol & 1;
- symbol >>= 1;
- price += GET_PRICEa(probs[m], bit);
- m = (m << 1) | bit;
- }
- return price;
-}
-
-
-static void LenEnc_Init(CLenEnc *p)
-{
- unsigned i;
- p->choice = p->choice2 = kProbInitValue;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)
- p->low[i] = kProbInitValue;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)
- p->mid[i] = kProbInitValue;
- for (i = 0; i < kLenNumHighSymbols; i++)
- p->high[i] = kProbInitValue;
-}
-
-static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)
-{
- if (symbol < kLenNumLowSymbols)
- {
- RangeEnc_EncodeBit(rc, &p->choice, 0);
- RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);
- }
- else
- {
- RangeEnc_EncodeBit(rc, &p->choice, 1);
- if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)
- {
- RangeEnc_EncodeBit(rc, &p->choice2, 0);
- RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);
- }
- else
- {
- RangeEnc_EncodeBit(rc, &p->choice2, 1);
- RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);
- }
- }
-}
-
-static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)
-{
- UInt32 a0 = GET_PRICE_0a(p->choice);
- UInt32 a1 = GET_PRICE_1a(p->choice);
- UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);
- UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);
- UInt32 i = 0;
- for (i = 0; i < kLenNumLowSymbols; i++)
- {
- if (i >= numSymbols)
- return;
- prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);
- }
- for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)
- {
- if (i >= numSymbols)
- return;
- prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);
- }
- for (; i < numSymbols; i++)
- prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);
-}
-
-static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)
-{
- LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);
- p->counters[posState] = p->tableSize;
-}
-
-static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)
-{
- UInt32 posState;
- for (posState = 0; posState < numPosStates; posState++)
- LenPriceEnc_UpdateTable(p, posState, ProbPrices);
-}
-
-static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)
-{
- LenEnc_Encode(&p->p, rc, symbol, posState);
- if (updatePrice)
- if (--p->counters[posState] == 0)
- LenPriceEnc_UpdateTable(p, posState, ProbPrices);
-}
-
-
-
-
-static void MovePos(CLzmaEnc *p, UInt32 num)
-{
- #ifdef SHOW_STAT
- ttt += num;
- printf("\n MovePos %d", num);
- #endif
- if (num != 0)
- {
- p->additionalOffset += num;
- p->matchFinder.Skip(p->matchFinderObj, num);
- }
-}
-
-static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
-{
- UInt32 lenRes = 0, numPairs;
- p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
- numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
- #ifdef SHOW_STAT
- printf("\n i = %d numPairs = %d ", ttt, numPairs / 2);
- ttt++;
- {
- UInt32 i;
- for (i = 0; i < numPairs; i += 2)
- printf("%2d %6d | ", p->matches[i], p->matches[i + 1]);
- }
- #endif
- if (numPairs > 0)
- {
- lenRes = p->matches[numPairs - 2];
- if (lenRes == p->numFastBytes)
- {
- const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- UInt32 distance = p->matches[numPairs - 1] + 1;
- UInt32 numAvail = p->numAvail;
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
- {
- const Byte *pby2 = pby - distance;
- for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);
- }
- }
- }
- p->additionalOffset++;
- *numDistancePairsRes = numPairs;
- return lenRes;
-}
-
-
-#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;
-#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;
-#define IsShortRep(p) ((p)->backPrev == 0)
-
-static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)
-{
- return
- GET_PRICE_0(p->isRepG0[state]) +
- GET_PRICE_0(p->isRep0Long[state][posState]);
-}
-
-static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)
-{
- UInt32 price;
- if (repIndex == 0)
- {
- price = GET_PRICE_0(p->isRepG0[state]);
- price += GET_PRICE_1(p->isRep0Long[state][posState]);
- }
- else
- {
- price = GET_PRICE_1(p->isRepG0[state]);
- if (repIndex == 1)
- price += GET_PRICE_0(p->isRepG1[state]);
- else
- {
- price += GET_PRICE_1(p->isRepG1[state]);
- price += GET_PRICE(p->isRepG2[state], repIndex - 2);
- }
- }
- return price;
-}
-
-static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)
-{
- return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +
- GetPureRepPrice(p, repIndex, state, posState);
-}
-
-static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
-{
- UInt32 posMem = p->opt[cur].posPrev;
- UInt32 backMem = p->opt[cur].backPrev;
- p->optimumEndIndex = cur;
- do
- {
- if (p->opt[cur].prev1IsChar)
- {
- MakeAsChar(&p->opt[posMem])
- p->opt[posMem].posPrev = posMem - 1;
- if (p->opt[cur].prev2)
- {
- p->opt[posMem - 1].prev1IsChar = False;
- p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;
- p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;
- }
- }
- {
- UInt32 posPrev = posMem;
- UInt32 backCur = backMem;
-
- backMem = p->opt[posPrev].backPrev;
- posMem = p->opt[posPrev].posPrev;
-
- p->opt[posPrev].backPrev = backCur;
- p->opt[posPrev].posPrev = cur;
- cur = posPrev;
- }
- }
- while (cur != 0);
- *backRes = p->opt[0].backPrev;
- p->optimumCurrentIndex = p->opt[0].posPrev;
- return p->optimumCurrentIndex;
-}
-
-#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)
-
-static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
-{
- UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;
- UInt32 matchPrice, repMatchPrice, normalMatchPrice;
- UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];
- UInt32 *matches;
- const Byte *data;
- Byte curByte, matchByte;
- if (p->optimumEndIndex != p->optimumCurrentIndex)
- {
- const COptimal *opt = &p->opt[p->optimumCurrentIndex];
- UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;
- *backRes = opt->backPrev;
- p->optimumCurrentIndex = opt->posPrev;
- return lenRes;
- }
- p->optimumCurrentIndex = p->optimumEndIndex = 0;
-
- if (p->additionalOffset == 0)
- mainLen = ReadMatchDistances(p, &numPairs);
- else
- {
- mainLen = p->longestMatchLength;
- numPairs = p->numPairs;
- }
-
- numAvail = p->numAvail;
- if (numAvail < 2)
- {
- *backRes = (UInt32)(-1);
- return 1;
- }
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
-
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- repMaxIndex = 0;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 lenTest;
- const Byte *data2;
- reps[i] = p->reps[i];
- data2 = data - (reps[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- {
- repLens[i] = 0;
- continue;
- }
- for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
- repLens[i] = lenTest;
- if (lenTest > repLens[repMaxIndex])
- repMaxIndex = i;
- }
- if (repLens[repMaxIndex] >= p->numFastBytes)
- {
- UInt32 lenRes;
- *backRes = repMaxIndex;
- lenRes = repLens[repMaxIndex];
- MovePos(p, lenRes - 1);
- return lenRes;
- }
-
- matches = p->matches;
- if (mainLen >= p->numFastBytes)
- {
- *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
- MovePos(p, mainLen - 1);
- return mainLen;
- }
- curByte = *data;
- matchByte = *(data - (reps[0] + 1));
-
- if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)
- {
- *backRes = (UInt32)-1;
- return 1;
- }
-
- p->opt[0].state = (CState)p->state;
-
- posState = (position & p->pbMask);
-
- {
- const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
- (!IsCharState(p->state) ?
- LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, curByte, p->ProbPrices));
- }
-
- MakeAsChar(&p->opt[1]);
-
- matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
- repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
-
- if (matchByte == curByte)
- {
- UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);
- if (shortRepPrice < p->opt[1].price)
- {
- p->opt[1].price = shortRepPrice;
- MakeAsShortRep(&p->opt[1]);
- }
- }
- lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);
-
- if (lenEnd < 2)
- {
- *backRes = p->opt[1].backPrev;
- return 1;
- }
-
- p->opt[1].posPrev = 0;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- p->opt[0].backs[i] = reps[i];
-
- len = lenEnd;
- do
- p->opt[len--].price = kInfinityPrice;
- while (len >= 2);
-
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 repLen = repLens[i];
- UInt32 price;
- if (repLen < 2)
- continue;
- price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);
- do
- {
- UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];
- COptimal *opt = &p->opt[repLen];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = 0;
- opt->backPrev = i;
- opt->prev1IsChar = False;
- }
- }
- while (--repLen >= 2);
- }
-
- normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
-
- len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
- if (len <= mainLen)
- {
- UInt32 offs = 0;
- while (len > matches[offs])
- offs += 2;
- for (; ; len++)
- {
- COptimal *opt;
- UInt32 distance = matches[offs + 1];
-
- UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];
- UInt32 lenToPosState = GetLenToPosState(len);
- if (distance < kNumFullDistances)
- curAndLenPrice += p->distancesPrices[lenToPosState][distance];
- else
- {
- UInt32 slot;
- GetPosSlot2(distance, slot);
- curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];
- }
- opt = &p->opt[len];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = 0;
- opt->backPrev = distance + LZMA_NUM_REPS;
- opt->prev1IsChar = False;
- }
- if (len == matches[offs])
- {
- offs += 2;
- if (offs == numPairs)
- break;
- }
- }
- }
-
- cur = 0;
-
- #ifdef SHOW_STAT2
- if (position >= 0)
- {
- unsigned i;
- printf("\n pos = %4X", position);
- for (i = cur; i <= lenEnd; i++)
- printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price);
- }
- #endif
-
- for (;;)
- {
- UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;
- UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;
- Bool nextIsChar;
- Byte curByte, matchByte;
- const Byte *data;
- COptimal *curOpt;
- COptimal *nextOpt;
-
- cur++;
- if (cur == lenEnd)
- return Backward(p, backRes, cur);
-
- newLen = ReadMatchDistances(p, &numPairs);
- if (newLen >= p->numFastBytes)
- {
- p->numPairs = numPairs;
- p->longestMatchLength = newLen;
- return Backward(p, backRes, cur);
- }
- position++;
- curOpt = &p->opt[cur];
- posPrev = curOpt->posPrev;
- if (curOpt->prev1IsChar)
- {
- posPrev--;
- if (curOpt->prev2)
- {
- state = p->opt[curOpt->posPrev2].state;
- if (curOpt->backPrev2 < LZMA_NUM_REPS)
- state = kRepNextStates[state];
- else
- state = kMatchNextStates[state];
- }
- else
- state = p->opt[posPrev].state;
- state = kLiteralNextStates[state];
- }
- else
- state = p->opt[posPrev].state;
- if (posPrev == cur - 1)
- {
- if (IsShortRep(curOpt))
- state = kShortRepNextStates[state];
- else
- state = kLiteralNextStates[state];
- }
- else
- {
- UInt32 pos;
- const COptimal *prevOpt;
- if (curOpt->prev1IsChar && curOpt->prev2)
- {
- posPrev = curOpt->posPrev2;
- pos = curOpt->backPrev2;
- state = kRepNextStates[state];
- }
- else
- {
- pos = curOpt->backPrev;
- if (pos < LZMA_NUM_REPS)
- state = kRepNextStates[state];
- else
- state = kMatchNextStates[state];
- }
- prevOpt = &p->opt[posPrev];
- if (pos < LZMA_NUM_REPS)
- {
- UInt32 i;
- reps[0] = prevOpt->backs[pos];
- for (i = 1; i <= pos; i++)
- reps[i] = prevOpt->backs[i - 1];
- for (; i < LZMA_NUM_REPS; i++)
- reps[i] = prevOpt->backs[i];
- }
- else
- {
- UInt32 i;
- reps[0] = (pos - LZMA_NUM_REPS);
- for (i = 1; i < LZMA_NUM_REPS; i++)
- reps[i] = prevOpt->backs[i - 1];
- }
- }
- curOpt->state = (CState)state;
-
- curOpt->backs[0] = reps[0];
- curOpt->backs[1] = reps[1];
- curOpt->backs[2] = reps[2];
- curOpt->backs[3] = reps[3];
-
- curPrice = curOpt->price;
- nextIsChar = False;
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- curByte = *data;
- matchByte = *(data - (reps[0] + 1));
-
- posState = (position & p->pbMask);
-
- curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);
- {
- const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- curAnd1Price +=
- (!IsCharState(state) ?
- LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, curByte, p->ProbPrices));
- }
-
- nextOpt = &p->opt[cur + 1];
-
- if (curAnd1Price < nextOpt->price)
- {
- nextOpt->price = curAnd1Price;
- nextOpt->posPrev = cur;
- MakeAsChar(nextOpt);
- nextIsChar = True;
- }
-
- matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
- repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
-
- if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
- {
- UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);
- if (shortRepPrice <= nextOpt->price)
- {
- nextOpt->price = shortRepPrice;
- nextOpt->posPrev = cur;
- MakeAsShortRep(nextOpt);
- nextIsChar = True;
- }
- }
- numAvailFull = p->numAvail;
- {
- UInt32 temp = kNumOpts - 1 - cur;
- if (temp < numAvailFull)
- numAvailFull = temp;
- }
-
- if (numAvailFull < 2)
- continue;
- numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
-
- if (!nextIsChar && matchByte != curByte) /* speed optimization */
- {
- /* try Literal + rep0 */
- UInt32 temp;
- UInt32 lenTest2;
- const Byte *data2 = data - (reps[0] + 1);
- UInt32 limit = p->numFastBytes + 1;
- if (limit > numAvailFull)
- limit = numAvailFull;
-
- for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);
- lenTest2 = temp - 1;
- if (lenTest2 >= 2)
- {
- UInt32 state2 = kLiteralNextStates[state];
- UInt32 posStateNext = (position + 1) & p->pbMask;
- UInt32 nextRepMatchPrice = curAnd1Price +
- GET_PRICE_1(p->isMatch[state2][posStateNext]) +
- GET_PRICE_1(p->isRep[state2]);
- /* for (; lenTest2 >= 2; lenTest2--) */
- {
- UInt32 curAndLenPrice;
- COptimal *opt;
- UInt32 offset = cur + 1 + lenTest2;
- while (lenEnd < offset)
- p->opt[++lenEnd].price = kInfinityPrice;
- curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
- opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur + 1;
- opt->backPrev = 0;
- opt->prev1IsChar = True;
- opt->prev2 = False;
- }
- }
- }
- }
-
- startLen = 2; /* speed optimization */
- {
- UInt32 repIndex;
- for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)
- {
- UInt32 lenTest;
- UInt32 lenTestTemp;
- UInt32 price;
- const Byte *data2 = data - (reps[repIndex] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
- while (lenEnd < cur + lenTest)
- p->opt[++lenEnd].price = kInfinityPrice;
- lenTestTemp = lenTest;
- price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);
- do
- {
- UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];
- COptimal *opt = &p->opt[cur + lenTest];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur;
- opt->backPrev = repIndex;
- opt->prev1IsChar = False;
- }
- }
- while (--lenTest >= 2);
- lenTest = lenTestTemp;
-
- if (repIndex == 0)
- startLen = lenTest + 1;
-
- /* if (_maxMode) */
- {
- UInt32 lenTest2 = lenTest + 1;
- UInt32 limit = lenTest2 + p->numFastBytes;
- UInt32 nextRepMatchPrice;
- if (limit > numAvailFull)
- limit = numAvailFull;
- for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
- lenTest2 -= lenTest + 1;
- if (lenTest2 >= 2)
- {
- UInt32 state2 = kRepNextStates[state];
- UInt32 posStateNext = (position + lenTest) & p->pbMask;
- UInt32 curAndLenCharPrice =
- price + p->repLenEnc.prices[posState][lenTest - 2] +
- GET_PRICE_0(p->isMatch[state2][posStateNext]) +
- LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
- data[lenTest], data2[lenTest], p->ProbPrices);
- state2 = kLiteralNextStates[state2];
- posStateNext = (position + lenTest + 1) & p->pbMask;
- nextRepMatchPrice = curAndLenCharPrice +
- GET_PRICE_1(p->isMatch[state2][posStateNext]) +
- GET_PRICE_1(p->isRep[state2]);
-
- /* for (; lenTest2 >= 2; lenTest2--) */
- {
- UInt32 curAndLenPrice;
- COptimal *opt;
- UInt32 offset = cur + lenTest + 1 + lenTest2;
- while (lenEnd < offset)
- p->opt[++lenEnd].price = kInfinityPrice;
- curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
- opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur + lenTest + 1;
- opt->backPrev = 0;
- opt->prev1IsChar = True;
- opt->prev2 = True;
- opt->posPrev2 = cur;
- opt->backPrev2 = repIndex;
- }
- }
- }
- }
- }
- }
- /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */
- if (newLen > numAvail)
- {
- newLen = numAvail;
- for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);
- matches[numPairs] = newLen;
- numPairs += 2;
- }
- if (newLen >= startLen)
- {
- UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
- UInt32 offs, curBack, posSlot;
- UInt32 lenTest;
- while (lenEnd < cur + newLen)
- p->opt[++lenEnd].price = kInfinityPrice;
-
- offs = 0;
- while (startLen > matches[offs])
- offs += 2;
- curBack = matches[offs + 1];
- GetPosSlot2(curBack, posSlot);
- for (lenTest = /*2*/ startLen; ; lenTest++)
- {
- UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];
- UInt32 lenToPosState = GetLenToPosState(lenTest);
- COptimal *opt;
- if (curBack < kNumFullDistances)
- curAndLenPrice += p->distancesPrices[lenToPosState][curBack];
- else
- curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];
-
- opt = &p->opt[cur + lenTest];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur;
- opt->backPrev = curBack + LZMA_NUM_REPS;
- opt->prev1IsChar = False;
- }
-
- if (/*_maxMode && */lenTest == matches[offs])
- {
- /* Try Match + Literal + Rep0 */
- const Byte *data2 = data - (curBack + 1);
- UInt32 lenTest2 = lenTest + 1;
- UInt32 limit = lenTest2 + p->numFastBytes;
- UInt32 nextRepMatchPrice;
- if (limit > numAvailFull)
- limit = numAvailFull;
- for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
- lenTest2 -= lenTest + 1;
- if (lenTest2 >= 2)
- {
- UInt32 state2 = kMatchNextStates[state];
- UInt32 posStateNext = (position + lenTest) & p->pbMask;
- UInt32 curAndLenCharPrice = curAndLenPrice +
- GET_PRICE_0(p->isMatch[state2][posStateNext]) +
- LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
- data[lenTest], data2[lenTest], p->ProbPrices);
- state2 = kLiteralNextStates[state2];
- posStateNext = (posStateNext + 1) & p->pbMask;
- nextRepMatchPrice = curAndLenCharPrice +
- GET_PRICE_1(p->isMatch[state2][posStateNext]) +
- GET_PRICE_1(p->isRep[state2]);
-
- /* for (; lenTest2 >= 2; lenTest2--) */
- {
- UInt32 offset = cur + lenTest + 1 + lenTest2;
- UInt32 curAndLenPrice;
- COptimal *opt;
- while (lenEnd < offset)
- p->opt[++lenEnd].price = kInfinityPrice;
- curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
- opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur + lenTest + 1;
- opt->backPrev = 0;
- opt->prev1IsChar = True;
- opt->prev2 = True;
- opt->posPrev2 = cur;
- opt->backPrev2 = curBack + LZMA_NUM_REPS;
- }
- }
- }
- offs += 2;
- if (offs == numPairs)
- break;
- curBack = matches[offs + 1];
- if (curBack >= kNumFullDistances)
- GetPosSlot2(curBack, posSlot);
- }
- }
- }
- }
-}
-
-#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))
-
-static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
-{
- UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;
- const Byte *data;
- const UInt32 *matches;
-
- if (p->additionalOffset == 0)
- mainLen = ReadMatchDistances(p, &numPairs);
- else
- {
- mainLen = p->longestMatchLength;
- numPairs = p->numPairs;
- }
-
- numAvail = p->numAvail;
- *backRes = (UInt32)-1;
- if (numAvail < 2)
- return 1;
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
-
- repLen = repIndex = 0;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 len;
- const Byte *data2 = data - (p->reps[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- for (len = 2; len < numAvail && data[len] == data2[len]; len++);
- if (len >= p->numFastBytes)
- {
- *backRes = i;
- MovePos(p, len - 1);
- return len;
- }
- if (len > repLen)
- {
- repIndex = i;
- repLen = len;
- }
- }
-
- matches = p->matches;
- if (mainLen >= p->numFastBytes)
- {
- *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
- MovePos(p, mainLen - 1);
- return mainLen;
- }
-
- mainDist = 0; /* for GCC */
- if (mainLen >= 2)
- {
- mainDist = matches[numPairs - 1];
- while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)
- {
- if (!ChangePair(matches[numPairs - 3], mainDist))
- break;
- numPairs -= 2;
- mainLen = matches[numPairs - 2];
- mainDist = matches[numPairs - 1];
- }
- if (mainLen == 2 && mainDist >= 0x80)
- mainLen = 1;
- }
-
- if (repLen >= 2 && (
- (repLen + 1 >= mainLen) ||
- (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||
- (repLen + 3 >= mainLen && mainDist >= (1 << 15))))
- {
- *backRes = repIndex;
- MovePos(p, repLen - 1);
- return repLen;
- }
-
- if (mainLen < 2 || numAvail <= 2)
- return 1;
-
- p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);
- if (p->longestMatchLength >= 2)
- {
- UInt32 newDistance = matches[p->numPairs - 1];
- if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||
- (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||
- (p->longestMatchLength > mainLen + 1) ||
- (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))
- return 1;
- }
-
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 len, limit;
- const Byte *data2 = data - (p->reps[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- limit = mainLen - 1;
- for (len = 2; len < limit && data[len] == data2[len]; len++);
- if (len >= limit)
- return 1;
- }
- *backRes = mainDist + LZMA_NUM_REPS;
- MovePos(p, mainLen - 2);
- return mainLen;
-}
-
-static void WriteEndMarker(CLzmaEnc *p, UInt32 posState)
-{
- UInt32 len;
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
- p->state = kMatchNextStates[p->state];
- len = LZMA_MATCH_LEN_MIN;
- LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);
- RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);
- RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);
-}
-
-static SRes CheckErrors(CLzmaEnc *p)
-{
- if (p->result != SZ_OK)
- return p->result;
- if (p->rc.res != SZ_OK)
- p->result = SZ_ERROR_WRITE;
- if (p->matchFinderBase.result != SZ_OK)
- p->result = SZ_ERROR_READ;
- if (p->result != SZ_OK)
- p->finished = True;
- return p->result;
-}
-
-static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
-{
- /* ReleaseMFStream(); */
- p->finished = True;
- if (p->writeEndMark)
- WriteEndMarker(p, nowPos & p->pbMask);
- RangeEnc_FlushData(&p->rc);
- RangeEnc_FlushStream(&p->rc);
- return CheckErrors(p);
-}
-
-static void FillAlignPrices(CLzmaEnc *p)
-{
- UInt32 i;
- for (i = 0; i < kAlignTableSize; i++)
- p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
- p->alignPriceCount = 0;
-}
-
-static void FillDistancesPrices(CLzmaEnc *p)
-{
- UInt32 tempPrices[kNumFullDistances];
- UInt32 i, lenToPosState;
- for (i = kStartPosModelIndex; i < kNumFullDistances; i++)
- {
- UInt32 posSlot = GetPosSlot1(i);
- UInt32 footerBits = ((posSlot >> 1) - 1);
- UInt32 base = ((2 | (posSlot & 1)) << footerBits);
- tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);
- }
-
- for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
- {
- UInt32 posSlot;
- const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];
- UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];
- for (posSlot = 0; posSlot < p->distTableSize; posSlot++)
- posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);
- for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)
- posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
-
- {
- UInt32 *distancesPrices = p->distancesPrices[lenToPosState];
- UInt32 i;
- for (i = 0; i < kStartPosModelIndex; i++)
- distancesPrices[i] = posSlotPrices[i];
- for (; i < kNumFullDistances; i++)
- distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];
- }
- }
- p->matchPriceCount = 0;
-}
-
-void LzmaEnc_Construct(CLzmaEnc *p)
-{
- RangeEnc_Construct(&p->rc);
- MatchFinder_Construct(&p->matchFinderBase);
- #ifdef COMPRESS_MF_MT
- MatchFinderMt_Construct(&p->matchFinderMt);
- p->matchFinderMt.MatchFinder = &p->matchFinderBase;
- #endif
-
- {
- CLzmaEncProps props;
- LzmaEncProps_Init(&props);
- LzmaEnc_SetProps(p, &props);
- }
-
- #ifndef LZMA_LOG_BSR
- LzmaEnc_FastPosInit(p->g_FastPos);
- #endif
-
- LzmaEnc_InitPriceTables(p->ProbPrices);
- p->litProbs = 0;
- p->saveState.litProbs = 0;
-}
-
-CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
-{
- void *p;
- p = alloc->Alloc(alloc, sizeof(CLzmaEnc));
- if (p != 0)
- LzmaEnc_Construct((CLzmaEnc *)p);
- return p;
-}
-
-void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->litProbs);
- alloc->Free(alloc, p->saveState.litProbs);
- p->litProbs = 0;
- p->saveState.litProbs = 0;
-}
-
-void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- #ifdef COMPRESS_MF_MT
- MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
- #endif
- MatchFinder_Free(&p->matchFinderBase, allocBig);
- LzmaEnc_FreeLits(p, alloc);
- RangeEnc_Free(&p->rc, alloc);
-}
-
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
- alloc->Free(alloc, p);
-}
-
-static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)
-{
- UInt32 nowPos32, startPos32;
- if (p->inStream != 0)
- {
- p->matchFinderBase.stream = p->inStream;
- p->matchFinder.Init(p->matchFinderObj);
- p->inStream = 0;
- }
-
- if (p->finished)
- return p->result;
- RINOK(CheckErrors(p));
-
- nowPos32 = (UInt32)p->nowPos64;
- startPos32 = nowPos32;
-
- if (p->nowPos64 == 0)
- {
- UInt32 numPairs;
- Byte curByte;
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- return Flush(p, nowPos32);
- ReadMatchDistances(p, &numPairs);
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
- p->state = kLiteralNextStates[p->state];
- curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);
- LitEnc_Encode(&p->rc, p->litProbs, curByte);
- p->additionalOffset--;
- nowPos32++;
- }
-
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
- for (;;)
- {
- UInt32 pos, len, posState;
-
- if (p->fastMode)
- len = GetOptimumFast(p, &pos);
- else
- len = GetOptimum(p, nowPos32, &pos);
-
- #ifdef SHOW_STAT2
- printf("\n pos = %4X, len = %d pos = %d", nowPos32, len, pos);
- #endif
-
- posState = nowPos32 & p->pbMask;
- if (len == 1 && pos == (UInt32)-1)
- {
- Byte curByte;
- CLzmaProb *probs;
- const Byte *data;
-
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
- curByte = *data;
- probs = LIT_PROBS(nowPos32, *(data - 1));
- if (IsCharState(p->state))
- LitEnc_Encode(&p->rc, probs, curByte);
- else
- LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));
- p->state = kLiteralNextStates[p->state];
- }
- else
- {
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
- if (pos < LZMA_NUM_REPS)
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);
- if (pos == 0)
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);
- RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));
- }
- else
- {
- UInt32 distance = p->reps[pos];
- RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);
- if (pos == 1)
- RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);
- else
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);
- RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);
- if (pos == 3)
- p->reps[3] = p->reps[2];
- p->reps[2] = p->reps[1];
- }
- p->reps[1] = p->reps[0];
- p->reps[0] = distance;
- }
- if (len == 1)
- p->state = kShortRepNextStates[p->state];
- else
- {
- LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- p->state = kRepNextStates[p->state];
- }
- }
- else
- {
- UInt32 posSlot;
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
- p->state = kMatchNextStates[p->state];
- LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- pos -= LZMA_NUM_REPS;
- GetPosSlot(pos, posSlot);
- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
-
- if (posSlot >= kStartPosModelIndex)
- {
- UInt32 footerBits = ((posSlot >> 1) - 1);
- UInt32 base = ((2 | (posSlot & 1)) << footerBits);
- UInt32 posReduced = pos - base;
-
- if (posSlot < kEndPosModelIndex)
- RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);
- else
- {
- RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
- RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
- p->alignPriceCount++;
- }
- }
- p->reps[3] = p->reps[2];
- p->reps[2] = p->reps[1];
- p->reps[1] = p->reps[0];
- p->reps[0] = pos;
- p->matchPriceCount++;
- }
- }
- p->additionalOffset -= len;
- nowPos32 += len;
- if (p->additionalOffset == 0)
- {
- UInt32 processed;
- if (!p->fastMode)
- {
- if (p->matchPriceCount >= (1 << 7))
- FillDistancesPrices(p);
- if (p->alignPriceCount >= kAlignTableSize)
- FillAlignPrices(p);
- }
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- break;
- processed = nowPos32 - startPos32;
- if (useLimits)
- {
- if (processed + kNumOpts + 300 >= maxUnpackSize ||
- RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)
- break;
- }
- else if (processed >= (1 << 15))
- {
- p->nowPos64 += nowPos32 - startPos32;
- return CheckErrors(p);
- }
- }
- }
- p->nowPos64 += nowPos32 - startPos32;
- return Flush(p, nowPos32);
-}
-
-#define kBigHashDicLimit ((UInt32)1 << 24)
-
-static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- UInt32 beforeSize = kNumOpts;
- Bool btMode;
- if (!RangeEnc_Alloc(&p->rc, alloc))
- return SZ_ERROR_MEM;
- btMode = (p->matchFinderBase.btMode != 0);
- #ifdef COMPRESS_MF_MT
- p->mtMode = (p->multiThread && !p->fastMode && btMode);
- #endif
-
- {
- unsigned lclp = p->lc + p->lp;
- if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)
- {
- LzmaEnc_FreeLits(p, alloc);
- p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
- p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
- if (p->litProbs == 0 || p->saveState.litProbs == 0)
- {
- LzmaEnc_FreeLits(p, alloc);
- return SZ_ERROR_MEM;
- }
- p->lclp = lclp;
- }
- }
-
- p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);
-
- if (beforeSize + p->dictSize < keepWindowSize)
- beforeSize = keepWindowSize - p->dictSize;
-
- #ifdef COMPRESS_MF_MT
- if (p->mtMode)
- {
- RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));
- p->matchFinderObj = &p->matchFinderMt;
- MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
- }
- else
- #endif
- {
- if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
- return SZ_ERROR_MEM;
- p->matchFinderObj = &p->matchFinderBase;
- MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
- }
- return SZ_OK;
-}
-
-void LzmaEnc_Init(CLzmaEnc *p)
-{
- UInt32 i;
- p->state = 0;
- for (i = 0 ; i < LZMA_NUM_REPS; i++)
- p->reps[i] = 0;
-
- RangeEnc_Init(&p->rc);
-
-
- for (i = 0; i < kNumStates; i++)
- {
- UInt32 j;
- for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
- {
- p->isMatch[i][j] = kProbInitValue;
- p->isRep0Long[i][j] = kProbInitValue;
- }
- p->isRep[i] = kProbInitValue;
- p->isRepG0[i] = kProbInitValue;
- p->isRepG1[i] = kProbInitValue;
- p->isRepG2[i] = kProbInitValue;
- }
-
- {
- UInt32 num = 0x300 << (p->lp + p->lc);
- for (i = 0; i < num; i++)
- p->litProbs[i] = kProbInitValue;
- }
-
- {
- for (i = 0; i < kNumLenToPosStates; i++)
- {
- CLzmaProb *probs = p->posSlotEncoder[i];
- UInt32 j;
- for (j = 0; j < (1 << kNumPosSlotBits); j++)
- probs[j] = kProbInitValue;
- }
- }
- {
- for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)
- p->posEncoders[i] = kProbInitValue;
- }
-
- LenEnc_Init(&p->lenEnc.p);
- LenEnc_Init(&p->repLenEnc.p);
-
- for (i = 0; i < (1 << kNumAlignBits); i++)
- p->posAlignEncoder[i] = kProbInitValue;
-
- p->optimumEndIndex = 0;
- p->optimumCurrentIndex = 0;
- p->additionalOffset = 0;
-
- p->pbMask = (1 << p->pb) - 1;
- p->lpMask = (1 << p->lp) - 1;
-}
-
-void LzmaEnc_InitPrices(CLzmaEnc *p)
-{
- if (!p->fastMode)
- {
- FillDistancesPrices(p);
- FillAlignPrices(p);
- }
-
- p->lenEnc.tableSize =
- p->repLenEnc.tableSize =
- p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
- LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);
- LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
-}
-
-static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- UInt32 i;
- for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)
- if (p->dictSize <= ((UInt32)1 << i))
- break;
- p->distTableSize = i * 2;
-
- p->finished = False;
- p->result = SZ_OK;
- RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));
- LzmaEnc_Init(p);
- LzmaEnc_InitPrices(p);
- p->nowPos64 = 0;
- return SZ_OK;
-}
-
-static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,
- ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- p->inStream = inStream;
- p->rc.outStream = outStream;
- return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
-}
-
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
- ISeqInStream *inStream, UInt32 keepWindowSize,
- ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- p->inStream = inStream;
- return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
-}
-
-static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
-{
- p->seqBufInStream.funcTable.Read = MyRead;
- p->seqBufInStream.data = src;
- p->seqBufInStream.rem = srcLen;
-}
-
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
- UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- LzmaEnc_SetInputBuf(p, src, srcLen);
- p->inStream = &p->seqBufInStream.funcTable;
- return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
-}
-
-void LzmaEnc_Finish(CLzmaEncHandle pp)
-{
- #ifdef COMPRESS_MF_MT
- CLzmaEnc *p = (CLzmaEnc *)pp;
- if (p->mtMode)
- MatchFinderMt_ReleaseStream(&p->matchFinderMt);
- #else
- pp = pp;
- #endif
-}
-
-typedef struct _CSeqOutStreamBuf
-{
- ISeqOutStream funcTable;
- Byte *data;
- SizeT rem;
- Bool overflow;
-} CSeqOutStreamBuf;
-
-static size_t MyWrite(void *pp, const void *data, size_t size)
-{
- CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;
- if (p->rem < size)
- {
- size = p->rem;
- p->overflow = True;
- }
- memcpy(p->data, data, size);
- p->rem -= size;
- p->data += size;
- return size;
-}
-
-
-UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
-}
-
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
-}
-
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
- Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- UInt64 nowPos64;
- SRes res;
- CSeqOutStreamBuf outStream;
-
- outStream.funcTable.Write = MyWrite;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = False;
-
- p->writeEndMark = False;
- p->finished = False;
- p->result = SZ_OK;
-
- if (reInit)
- LzmaEnc_Init(p);
- LzmaEnc_InitPrices(p);
- nowPos64 = p->nowPos64;
- RangeEnc_Init(&p->rc);
- p->rc.outStream = &outStream.funcTable;
-
- res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
-
- *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
- *destLen -= outStream.rem;
- if (outStream.overflow)
- return SZ_ERROR_OUTPUT_EOF;
-
- return res;
-}
-
-SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
- ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- SRes res = SZ_OK;
-
- #ifdef COMPRESS_MF_MT
- Byte allocaDummy[0x300];
- int i = 0;
- for (i = 0; i < 16; i++)
- allocaDummy[i] = (Byte)i;
- #endif
-
- RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));
-
- for (;;)
- {
- res = LzmaEnc_CodeOneBlock(p, False, 0, 0);
- if (res != SZ_OK || p->finished != 0)
- break;
- if (progress != 0)
- {
- res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
- if (res != SZ_OK)
- {
- res = SZ_ERROR_PROGRESS;
- break;
- }
- }
- }
- LzmaEnc_Finish(pp);
- return res;
-}
-
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- int i;
- UInt32 dictSize = p->dictSize;
- if (*size < LZMA_PROPS_SIZE)
- return SZ_ERROR_PARAM;
- *size = LZMA_PROPS_SIZE;
- props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
-
- for (i = 11; i <= 30; i++)
- {
- if (dictSize <= ((UInt32)2 << i))
- {
- dictSize = (2 << i);
- break;
- }
- if (dictSize <= ((UInt32)3 << i))
- {
- dictSize = (3 << i);
- break;
- }
- }
-
- for (i = 0; i < 4; i++)
- props[1 + i] = (Byte)(dictSize >> (8 * i));
- return SZ_OK;
-}
-
-SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- SRes res;
- CLzmaEnc *p = (CLzmaEnc *)pp;
-
- CSeqOutStreamBuf outStream;
-
- LzmaEnc_SetInputBuf(p, src, srcLen);
-
- outStream.funcTable.Write = MyWrite;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = False;
-
- p->writeEndMark = writeEndMark;
- res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,
- progress, alloc, allocBig);
-
- *destLen -= outStream.rem;
- if (outStream.overflow)
- return SZ_ERROR_OUTPUT_EOF;
- return res;
-}
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
- SRes res;
- if (p == 0)
- return SZ_ERROR_MEM;
-
- res = LzmaEnc_SetProps(p, props);
- if (res == SZ_OK)
- {
- res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
- if (res == SZ_OK)
- res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
- writeEndMark, progress, alloc, allocBig);
- }
-
- LzmaEnc_Destroy(p, alloc, allocBig);
- return res;
-}
diff --git a/desmume/src/windows/7z/C/LzmaEnc.h b/desmume/src/windows/7z/C/LzmaEnc.h
deleted file mode 100644
index e3d84fa35..000000000
--- a/desmume/src/windows/7z/C/LzmaEnc.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* LzmaEnc.h -- LZMA Encoder
-2008-10-04 : Igor Pavlov : Public domain */
-
-#ifndef __LZMAENC_H
-#define __LZMAENC_H
-
-#include "Types.h"
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaEncProps
-{
- int level; /* 0 <= level <= 9 */
- UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
- (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
- default = (1 << 24) */
- int lc; /* 0 <= lc <= 8, default = 3 */
- int lp; /* 0 <= lp <= 4, default = 0 */
- int pb; /* 0 <= pb <= 4, default = 2 */
- int algo; /* 0 - fast, 1 - normal, default = 1 */
- int fb; /* 5 <= fb <= 273, default = 32 */
- int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
- int numHashBytes; /* 2, 3 or 4, default = 4 */
- UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
- unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
- int numThreads; /* 1 or 2, default = 2 */
-} CLzmaEncProps;
-
-void LzmaEncProps_Init(CLzmaEncProps *p);
-void LzmaEncProps_Normalize(CLzmaEncProps *p);
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
-
-
-/* ---------- CLzmaEncHandle Interface ---------- */
-
-/* LzmaEnc_* functions can return the following exit codes:
-Returns:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater in props
- SZ_ERROR_WRITE - Write callback error.
- SZ_ERROR_PROGRESS - some break from progress callback
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-typedef void * CLzmaEncHandle;
-
-CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
-SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
-SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-
-/* ---------- One Call Interface ---------- */
-
-/* LzmaEncode
-Return code:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-
-#endif
diff --git a/desmume/src/windows/7z/C/RotateDefs.h b/desmume/src/windows/7z/C/RotateDefs.h
deleted file mode 100644
index 189350d7b..000000000
--- a/desmume/src/windows/7z/C/RotateDefs.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* RotateDefs.h -- Rotate functions
-2008-08-05
-Igor Pavlov
-Public domain */
-
-#ifndef __ROTATEDEFS_H
-#define __ROTATEDEFS_H
-
-#ifdef _MSC_VER
-
-#include
-#define rotlFixed(x, n) _rotl((x), (n))
-#define rotrFixed(x, n) _rotr((x), (n))
-
-#else
-
-#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
-#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
-
-#endif
-
-#endif
diff --git a/desmume/src/windows/7z/C/Sha256.c b/desmume/src/windows/7z/C/Sha256.c
deleted file mode 100644
index 657c2ab92..000000000
--- a/desmume/src/windows/7z/C/Sha256.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/* Crypto/Sha256.c -- SHA-256 Hash function
-2008-11-06 : Igor Pavlov : Public domain
-This code is based on public domain code from Wei Dai's Crypto++ library. */
-
-#include "Sha256.h"
-#include "RotateDefs.h"
-
-/* define it for speed optimization */
-/* #define _SHA256_UNROLL */
-/* #define _SHA256_UNROLL2 */
-
-void Sha256_Init(CSha256 *p)
-{
- p->state[0] = 0x6a09e667;
- p->state[1] = 0xbb67ae85;
- p->state[2] = 0x3c6ef372;
- p->state[3] = 0xa54ff53a;
- p->state[4] = 0x510e527f;
- p->state[5] = 0x9b05688c;
- p->state[6] = 0x1f83d9ab;
- p->state[7] = 0x5be0cd19;
- p->count = 0;
-}
-
-#define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22))
-#define S1(x) (rotrFixed(x, 6) ^ rotrFixed(x,11) ^ rotrFixed(x, 25))
-#define s0(x) (rotrFixed(x, 7) ^ rotrFixed(x,18) ^ (x >> 3))
-#define s1(x) (rotrFixed(x,17) ^ rotrFixed(x,19) ^ (x >> 10))
-
-#define blk0(i) (W[i] = data[i])
-#define blk2(i) (W[i&15] += s1(W[(i-2)&15]) + W[(i-7)&15] + s0(W[(i-15)&15]))
-
-#define Ch(x,y,z) (z^(x&(y^z)))
-#define Maj(x,y,z) ((x&y)|(z&(x|y)))
-
-#define a(i) T[(0-(i))&7]
-#define b(i) T[(1-(i))&7]
-#define c(i) T[(2-(i))&7]
-#define d(i) T[(3-(i))&7]
-#define e(i) T[(4-(i))&7]
-#define f(i) T[(5-(i))&7]
-#define g(i) T[(6-(i))&7]
-#define h(i) T[(7-(i))&7]
-
-
-#ifdef _SHA256_UNROLL2
-
-#define R(a,b,c,d,e,f,g,h, i) h += S1(e) + Ch(e,f,g) + K[i+j] + (j?blk2(i):blk0(i));\
- d += h; h += S0(a) + Maj(a, b, c)
-
-#define RX_8(i) \
- R(a,b,c,d,e,f,g,h, i); \
- R(h,a,b,c,d,e,f,g, i+1); \
- R(g,h,a,b,c,d,e,f, i+2); \
- R(f,g,h,a,b,c,d,e, i+3); \
- R(e,f,g,h,a,b,c,d, i+4); \
- R(d,e,f,g,h,a,b,c, i+5); \
- R(c,d,e,f,g,h,a,b, i+6); \
- R(b,c,d,e,f,g,h,a, i+7)
-
-#else
-
-#define R(i) h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[i+j] + (j?blk2(i):blk0(i));\
- d(i) += h(i); h(i) += S0(a(i)) + Maj(a(i), b(i), c(i))
-
-#ifdef _SHA256_UNROLL
-
-#define RX_8(i) R(i+0); R(i+1); R(i+2); R(i+3); R(i+4); R(i+5); R(i+6); R(i+7);
-
-#endif
-
-#endif
-
-const UInt32 K[64] = {
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
-};
-
-static void Sha256_Transform(UInt32 *state, const UInt32 *data)
-{
- UInt32 W[16];
- unsigned j;
- #ifdef _SHA256_UNROLL2
- UInt32 a,b,c,d,e,f,g,h;
- a = state[0];
- b = state[1];
- c = state[2];
- d = state[3];
- e = state[4];
- f = state[5];
- g = state[6];
- h = state[7];
- #else
- UInt32 T[8];
- for (j = 0; j < 8; j++)
- T[j] = state[j];
- #endif
-
- for (j = 0; j < 64; j += 16)
- {
- #if defined(_SHA256_UNROLL) || defined(_SHA256_UNROLL2)
- RX_8(0); RX_8(8);
- #else
- unsigned i;
- for (i = 0; i < 16; i++) { R(i); }
- #endif
- }
-
- #ifdef _SHA256_UNROLL2
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
- state[4] += e;
- state[5] += f;
- state[6] += g;
- state[7] += h;
- #else
- for (j = 0; j < 8; j++)
- state[j] += T[j];
- #endif
-
- /* Wipe variables */
- /* memset(W, 0, sizeof(W)); */
- /* memset(T, 0, sizeof(T)); */
-}
-
-#undef S0
-#undef S1
-#undef s0
-#undef s1
-
-static void Sha256_WriteByteBlock(CSha256 *p)
-{
- UInt32 data32[16];
- unsigned i;
- for (i = 0; i < 16; i++)
- data32[i] =
- ((UInt32)(p->buffer[i * 4 ]) << 24) +
- ((UInt32)(p->buffer[i * 4 + 1]) << 16) +
- ((UInt32)(p->buffer[i * 4 + 2]) << 8) +
- ((UInt32)(p->buffer[i * 4 + 3]));
- Sha256_Transform(p->state, data32);
-}
-
-void Sha256_Update(CSha256 *p, const Byte *data, size_t size)
-{
- UInt32 curBufferPos = (UInt32)p->count & 0x3F;
- while (size > 0)
- {
- p->buffer[curBufferPos++] = *data++;
- p->count++;
- size--;
- if (curBufferPos == 64)
- {
- curBufferPos = 0;
- Sha256_WriteByteBlock(p);
- }
- }
-}
-
-void Sha256_Final(CSha256 *p, Byte *digest)
-{
- UInt64 lenInBits = (p->count << 3);
- UInt32 curBufferPos = (UInt32)p->count & 0x3F;
- unsigned i;
- p->buffer[curBufferPos++] = 0x80;
- while (curBufferPos != (64 - 8))
- {
- curBufferPos &= 0x3F;
- if (curBufferPos == 0)
- Sha256_WriteByteBlock(p);
- p->buffer[curBufferPos++] = 0;
- }
- for (i = 0; i < 8; i++)
- {
- p->buffer[curBufferPos++] = (Byte)(lenInBits >> 56);
- lenInBits <<= 8;
- }
- Sha256_WriteByteBlock(p);
-
- for (i = 0; i < 8; i++)
- {
- *digest++ = (Byte)((p->state[i] >> 24) & 0xFF);
- *digest++ = (Byte)((p->state[i] >> 16) & 0xFF);
- *digest++ = (Byte)((p->state[i] >> 8) & 0xFF);
- *digest++ = (Byte)((p->state[i]) & 0xFF);
- }
- Sha256_Init(p);
-}
diff --git a/desmume/src/windows/7z/C/Sha256.h b/desmume/src/windows/7z/C/Sha256.h
deleted file mode 100644
index 8703b4a63..000000000
--- a/desmume/src/windows/7z/C/Sha256.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Crypto/Sha256.h -- SHA-256 Hash function
-2008-10-04 : Igor Pavlov : Public domain */
-
-#ifndef __CRYPTO_SHA256_H
-#define __CRYPTO_SHA256_H
-
-#include "Types.h"
-
-#define SHA256_DIGEST_SIZE 32
-
-typedef struct
-{
- UInt32 state[8];
- UInt64 count;
- Byte buffer[64];
-} CSha256;
-
-void Sha256_Init(CSha256 *p);
-void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
-void Sha256_Final(CSha256 *p, Byte *digest);
-
-#endif
diff --git a/desmume/src/windows/7z/C/Sort.c b/desmume/src/windows/7z/C/Sort.c
deleted file mode 100644
index bb20dc348..000000000
--- a/desmume/src/windows/7z/C/Sort.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Sort.c -- Sort functions
-2008-08-17
-Igor Pavlov
-Public domain */
-
-#include "Sort.h"
-
-#define HeapSortDown(p, k, size, temp) \
- { for (;;) { \
- UInt32 s = (k << 1); \
- if (s > size) break; \
- if (s < size && p[s + 1] > p[s]) s++; \
- if (temp >= p[s]) break; \
- p[k] = p[s]; k = s; \
- } p[k] = temp; }
-
-void HeapSort(UInt32 *p, UInt32 size)
-{
- if (size <= 1)
- return;
- p--;
- {
- UInt32 i = size / 2;
- do
- {
- UInt32 temp = p[i];
- UInt32 k = i;
- HeapSortDown(p, k, size, temp)
- }
- while (--i != 0);
- }
- /*
- do
- {
- UInt32 k = 1;
- UInt32 temp = p[size];
- p[size--] = p[1];
- HeapSortDown(p, k, size, temp)
- }
- while (size > 1);
- */
- while (size > 3)
- {
- UInt32 temp = p[size];
- UInt32 k = (p[3] > p[2]) ? 3 : 2;
- p[size--] = p[1];
- p[1] = p[k];
- HeapSortDown(p, k, size, temp)
- }
- {
- UInt32 temp = p[size];
- p[size] = p[1];
- if (size > 2 && p[2] < temp)
- {
- p[1] = p[2];
- p[2] = temp;
- }
- else
- p[1] = temp;
- }
-}
-
-/*
-#define HeapSortRefDown(p, vals, n, size, temp) \
- { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \
- UInt32 s = (k << 1); \
- if (s > size) break; \
- if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \
- if (val >= vals[p[s]]) break; \
- p[k] = p[s]; k = s; \
- } p[k] = temp; }
-
-void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)
-{
- if (size <= 1)
- return;
- p--;
- {
- UInt32 i = size / 2;
- do
- {
- UInt32 temp = p[i];
- HeapSortRefDown(p, vals, i, size, temp);
- }
- while (--i != 0);
- }
- do
- {
- UInt32 temp = p[size];
- p[size--] = p[1];
- HeapSortRefDown(p, vals, 1, size, temp);
- }
- while (size > 1);
-}
-*/
\ No newline at end of file
diff --git a/desmume/src/windows/7z/C/Sort.h b/desmume/src/windows/7z/C/Sort.h
deleted file mode 100644
index cff6c4c32..000000000
--- a/desmume/src/windows/7z/C/Sort.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Sort.h -- Sort functions
-2008-03-19
-Igor Pavlov
-Public domain */
-
-#ifndef __7Z_SORT_H
-#define __7Z_SORT_H
-
-#include "Types.h"
-
-void HeapSort(UInt32 *p, UInt32 size);
-/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */
-
-#endif
diff --git a/desmume/src/windows/7z/C/Threads.c b/desmume/src/windows/7z/C/Threads.c
deleted file mode 100644
index c7d8b0a8a..000000000
--- a/desmume/src/windows/7z/C/Threads.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Threads.c -- multithreading library
-2008-08-05
-Igor Pavlov
-Public domain */
-
-#include "Threads.h"
-#include
-
-static WRes GetError()
-{
- DWORD res = GetLastError();
- return (res) ? (WRes)(res) : 1;
-}
-
-WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }
-WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }
-
-static WRes MyCloseHandle(HANDLE *h)
-{
- if (*h != NULL)
- if (!CloseHandle(*h))
- return GetError();
- *h = NULL;
- return 0;
-}
-
-WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
-{
- unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */
- thread->handle =
- /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */
- (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);
- /* maybe we must use errno here, but probably GetLastError() is also OK. */
- return HandleToWRes(thread->handle);
-}
-
-WRes WaitObject(HANDLE h)
-{
- return (WRes)WaitForSingleObject(h, INFINITE);
-}
-
-WRes Thread_Wait(CThread *thread)
-{
- if (thread->handle == NULL)
- return 1;
- return WaitObject(thread->handle);
-}
-
-WRes Thread_Close(CThread *thread)
-{
- return MyCloseHandle(&thread->handle);
-}
-
-WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
-{
- p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);
- return HandleToWRes(p->handle);
-}
-
-WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
- { return Event_Create(p, TRUE, initialSignaled); }
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
- { return ManualResetEvent_Create(p, 0); }
-
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
- { return Event_Create(p, FALSE, initialSignaled); }
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
- { return AutoResetEvent_Create(p, 0); }
-
-WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }
-WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }
-WRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }
-WRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }
-
-
-WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
-{
- p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);
- return HandleToWRes(p->handle);
-}
-
-WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
-{
- return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
-}
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
-{
- return Semaphore_Release(p, (LONG)releaseCount, NULL);
-}
-WRes Semaphore_Release1(CSemaphore *p)
-{
- return Semaphore_ReleaseN(p, 1);
-}
-
-WRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }
-WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }
-
-WRes CriticalSection_Init(CCriticalSection *p)
-{
- /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */
- __try
- {
- InitializeCriticalSection(p);
- /* InitializeCriticalSectionAndSpinCount(p, 0); */
- }
- __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }
- return 0;
-}
-
diff --git a/desmume/src/windows/7z/C/Threads.h b/desmume/src/windows/7z/C/Threads.h
deleted file mode 100644
index 3d9072946..000000000
--- a/desmume/src/windows/7z/C/Threads.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Threads.h -- multithreading library
-2008-11-22 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_THRESDS_H
-#define __7Z_THRESDS_H
-
-#include "Types.h"
-
-typedef struct _CThread
-{
- HANDLE handle;
-} CThread;
-
-#define Thread_Construct(thread) (thread)->handle = NULL
-#define Thread_WasCreated(thread) ((thread)->handle != NULL)
-
-typedef unsigned THREAD_FUNC_RET_TYPE;
-#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
-#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
-
-WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
-WRes Thread_Wait(CThread *thread);
-WRes Thread_Close(CThread *thread);
-
-typedef struct _CEvent
-{
- HANDLE handle;
-} CEvent;
-
-typedef CEvent CAutoResetEvent;
-typedef CEvent CManualResetEvent;
-
-#define Event_Construct(event) (event)->handle = NULL
-#define Event_IsCreated(event) ((event)->handle != NULL)
-
-WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
-WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
-WRes Event_Set(CEvent *event);
-WRes Event_Reset(CEvent *event);
-WRes Event_Wait(CEvent *event);
-WRes Event_Close(CEvent *event);
-
-
-typedef struct _CSemaphore
-{
- HANDLE handle;
-} CSemaphore;
-
-#define Semaphore_Construct(p) (p)->handle = NULL
-
-WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
-WRes Semaphore_Release1(CSemaphore *p);
-WRes Semaphore_Wait(CSemaphore *p);
-WRes Semaphore_Close(CSemaphore *p);
-
-
-typedef CRITICAL_SECTION CCriticalSection;
-
-WRes CriticalSection_Init(CCriticalSection *p);
-#define CriticalSection_Delete(p) DeleteCriticalSection(p)
-#define CriticalSection_Enter(p) EnterCriticalSection(p)
-#define CriticalSection_Leave(p) LeaveCriticalSection(p)
-
-#endif
-
diff --git a/desmume/src/windows/7z/C/Types.h b/desmume/src/windows/7z/C/Types.h
deleted file mode 100644
index 2638196aa..000000000
--- a/desmume/src/windows/7z/C/Types.h
+++ /dev/null
@@ -1,208 +0,0 @@
-/* Types.h -- Basic types
-2008-11-23 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_TYPES_H
-#define __7Z_TYPES_H
-
-#include
-
-#ifdef _WIN32
-#include
-#endif
-
-#define SZ_OK 0
-
-#define SZ_ERROR_DATA 1
-#define SZ_ERROR_MEM 2
-#define SZ_ERROR_CRC 3
-#define SZ_ERROR_UNSUPPORTED 4
-#define SZ_ERROR_PARAM 5
-#define SZ_ERROR_INPUT_EOF 6
-#define SZ_ERROR_OUTPUT_EOF 7
-#define SZ_ERROR_READ 8
-#define SZ_ERROR_WRITE 9
-#define SZ_ERROR_PROGRESS 10
-#define SZ_ERROR_FAIL 11
-#define SZ_ERROR_THREAD 12
-
-#define SZ_ERROR_ARCHIVE 16
-#define SZ_ERROR_NO_ARCHIVE 17
-
-typedef int SRes;
-
-#ifdef _WIN32
-typedef DWORD WRes;
-#else
-typedef int WRes;
-#endif
-
-#ifndef RINOK
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
-#endif
-
-typedef unsigned char Byte;
-typedef short Int16;
-typedef unsigned short UInt16;
-
-#ifdef _LZMA_UINT32_IS_ULONG
-typedef long Int32;
-typedef unsigned long UInt32;
-#else
-typedef int Int32;
-typedef unsigned int UInt32;
-#endif
-
-#ifdef _SZ_NO_INT_64
-
-/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
- NOTES: Some code will work incorrectly in that case! */
-
-typedef long Int64;
-typedef unsigned long UInt64;
-
-#else
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef __int64 Int64;
-typedef unsigned __int64 UInt64;
-#else
-typedef long long int Int64;
-typedef unsigned long long int UInt64;
-#endif
-
-#endif
-
-#ifdef _LZMA_NO_SYSTEM_SIZE_T
-typedef UInt32 SizeT;
-#else
-typedef size_t SizeT;
-#endif
-
-typedef int Bool;
-#define True 1
-#define False 0
-
-
-#ifdef _MSC_VER
-
-#if _MSC_VER >= 1300
-#define MY_NO_INLINE __declspec(noinline)
-#else
-#define MY_NO_INLINE
-#endif
-
-#define MY_CDECL __cdecl
-#define MY_STD_CALL __stdcall
-#define MY_FAST_CALL MY_NO_INLINE __fastcall
-
-#else
-
-#define MY_CDECL
-#define MY_STD_CALL
-#define MY_FAST_CALL
-
-#endif
-
-
-/* The following interfaces use first parameter as pointer to structure */
-
-typedef struct
-{
- SRes (*Read)(void *p, void *buf, size_t *size);
- /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
- (output(*size) < input(*size)) is allowed */
-} ISeqInStream;
-
-/* it can return SZ_ERROR_INPUT_EOF */
-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
-SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
-
-typedef struct
-{
- size_t (*Write)(void *p, const void *buf, size_t size);
- /* Returns: result - the number of actually written bytes.
- (result < size) means error */
-} ISeqOutStream;
-
-typedef enum
-{
- SZ_SEEK_SET = 0,
- SZ_SEEK_CUR = 1,
- SZ_SEEK_END = 2
-} ESzSeek;
-
-typedef struct
-{
- SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
- SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
-} ISeekInStream;
-
-typedef struct
-{
- SRes (*Look)(void *p, void **buf, size_t *size);
- /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
- (output(*size) > input(*size)) is not allowed
- (output(*size) < input(*size)) is allowed */
- SRes (*Skip)(void *p, size_t offset);
- /* offset must be <= output(*size) of Look */
-
- SRes (*Read)(void *p, void *buf, size_t *size);
- /* reads directly (without buffer). It's same as ISeqInStream::Read */
- SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
-} ILookInStream;
-
-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
-SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
-
-/* reads via ILookInStream::Read */
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
-
-#define LookToRead_BUF_SIZE (1 << 14)
-
-typedef struct
-{
- ILookInStream s;
- ISeekInStream *realStream;
- size_t pos;
- size_t size;
- Byte buf[LookToRead_BUF_SIZE];
-} CLookToRead;
-
-void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
-void LookToRead_Init(CLookToRead *p);
-
-typedef struct
-{
- ISeqInStream s;
- ILookInStream *realStream;
-} CSecToLook;
-
-void SecToLook_CreateVTable(CSecToLook *p);
-
-typedef struct
-{
- ISeqInStream s;
- ILookInStream *realStream;
-} CSecToRead;
-
-void SecToRead_CreateVTable(CSecToRead *p);
-
-typedef struct
-{
- SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
- /* Returns: result. (result != SZ_OK) means break.
- Value (UInt64)(Int64)-1 for size means unknown value. */
-} ICompressProgress;
-
-typedef struct
-{
- void *(*Alloc)(void *p, size_t size);
- void (*Free)(void *p, void *address); /* address can be 0 */
-} ISzAlloc;
-
-#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
-#define IAlloc_Free(p, a) (p)->Free((p), a)
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zCompressionMode.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zCompressionMode.cpp
deleted file mode 100644
index 232c63820..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zCompressionMode.cpp
+++ /dev/null
@@ -1,3 +0,0 @@
-// CompressionMethod.cpp
-
-#include "StdAfx.h"
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zCompressionMode.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zCompressionMode.h
deleted file mode 100644
index 5e986355b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zCompressionMode.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// 7zCompressionMode.h
-
-#ifndef __7Z_COMPRESSION_MODE_H
-#define __7Z_COMPRESSION_MODE_H
-
-#include "../../../Common/MyString.h"
-
-#include "../../../Windows/PropVariant.h"
-
-#include "../../Common/MethodProps.h"
-
-namespace NArchive {
-namespace N7z {
-
-struct CMethodFull: public CMethod
-{
- UInt32 NumInStreams;
- UInt32 NumOutStreams;
- bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
-};
-
-struct CBind
-{
- UInt32 InCoder;
- UInt32 InStream;
- UInt32 OutCoder;
- UInt32 OutStream;
-};
-
-struct CCompressionMethodMode
-{
- CObjectVector Methods;
- CRecordVector Binds;
- #ifdef COMPRESS_MT
- UInt32 NumThreads;
- #endif
- bool PasswordIsDefined;
- UString Password;
-
- bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }
- CCompressionMethodMode(): PasswordIsDefined(false)
- #ifdef COMPRESS_MT
- , NumThreads(1)
- #endif
- {}
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zDecode.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zDecode.cpp
deleted file mode 100644
index 02744c96a..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zDecode.cpp
+++ /dev/null
@@ -1,332 +0,0 @@
-// 7zDecode.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/LockedStream.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamObjects.h"
-
-#include "7zDecode.h"
-
-namespace NArchive {
-namespace N7z {
-
-static void ConvertFolderItemInfoToBindInfo(const CFolder &folder,
- CBindInfoEx &bindInfo)
-{
- bindInfo.Clear();
- int i;
- for (i = 0; i < folder.BindPairs.Size(); i++)
- {
- NCoderMixer::CBindPair bindPair;
- bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;
- bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;
- bindInfo.BindPairs.Add(bindPair);
- }
- UInt32 outStreamIndex = 0;
- for (i = 0; i < folder.Coders.Size(); i++)
- {
- NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
- const CCoderInfo &coderInfo = folder.Coders[i];
- coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;
- coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;
- bindInfo.Coders.Add(coderStreamsInfo);
- bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);
- for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)
- if (folder.FindBindPairForOutStream(outStreamIndex) < 0)
- bindInfo.OutStreams.Add(outStreamIndex);
- }
- for (i = 0; i < folder.PackStreams.Size(); i++)
- bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);
-}
-
-static bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,
- const NCoderMixer::CCoderStreamsInfo &a2)
-{
- return (a1.NumInStreams == a2.NumInStreams) &&
- (a1.NumOutStreams == a2.NumOutStreams);
-}
-
-static bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)
-{
- return (a1.InIndex == a2.InIndex) &&
- (a1.OutIndex == a2.OutIndex);
-}
-
-static bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)
-{
- if (a1.Coders.Size() != a2.Coders.Size())
- return false;
- int i;
- for (i = 0; i < a1.Coders.Size(); i++)
- if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))
- return false;
- if (a1.BindPairs.Size() != a2.BindPairs.Size())
- return false;
- for (i = 0; i < a1.BindPairs.Size(); i++)
- if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))
- return false;
- for (i = 0; i < a1.CoderMethodIDs.Size(); i++)
- if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])
- return false;
- if (a1.InStreams.Size() != a2.InStreams.Size())
- return false;
- if (a1.OutStreams.Size() != a2.OutStreams.Size())
- return false;
- return true;
-}
-
-CDecoder::CDecoder(bool multiThread)
-{
- #ifndef _ST_MODE
- multiThread = true;
- #endif
- _multiThread = multiThread;
- _bindInfoExPrevIsDefined = false;
-}
-
-HRESULT CDecoder::Decode(
- DECL_EXTERNAL_CODECS_LOC_VARS
- IInStream *inStream,
- UInt64 startPos,
- const UInt64 *packSizes,
- const CFolder &folderInfo,
- ISequentialOutStream *outStream,
- ICompressProgressInfo *compressProgress
- #ifndef _NO_CRYPTO
- , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- #ifdef COMPRESS_MT
- , bool mtMode, UInt32 numThreads
- #endif
- )
-{
- if (!folderInfo.CheckStructure())
- return E_NOTIMPL;
- #ifndef _NO_CRYPTO
- passwordIsDefined = false;
- #endif
- CObjectVector< CMyComPtr > inStreams;
-
- CLockedInStream lockedInStream;
- lockedInStream.Init(inStream);
-
- for (int j = 0; j < folderInfo.PackStreams.Size(); j++)
- {
- CLockedSequentialInStreamImp *lockedStreamImpSpec = new
- CLockedSequentialInStreamImp;
- CMyComPtr lockedStreamImp = lockedStreamImpSpec;
- lockedStreamImpSpec->Init(&lockedInStream, startPos);
- startPos += packSizes[j];
-
- CLimitedSequentialInStream *streamSpec = new
- CLimitedSequentialInStream;
- CMyComPtr inStream = streamSpec;
- streamSpec->SetStream(lockedStreamImp);
- streamSpec->Init(packSizes[j]);
- inStreams.Add(inStream);
- }
-
- int numCoders = folderInfo.Coders.Size();
-
- CBindInfoEx bindInfo;
- ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);
- bool createNewCoders;
- if (!_bindInfoExPrevIsDefined)
- createNewCoders = true;
- else
- createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);
- if (createNewCoders)
- {
- int i;
- _decoders.Clear();
- // _decoders2.Clear();
-
- _mixerCoder.Release();
-
- if (_multiThread)
- {
- _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;
- _mixerCoder = _mixerCoderMTSpec;
- _mixerCoderCommon = _mixerCoderMTSpec;
- }
- else
- {
- #ifdef _ST_MODE
- _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;
- _mixerCoder = _mixerCoderSTSpec;
- _mixerCoderCommon = _mixerCoderSTSpec;
- #endif
- }
- RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));
-
- for (i = 0; i < numCoders; i++)
- {
- const CCoderInfo &coderInfo = folderInfo.Coders[i];
-
-
- CMyComPtr decoder;
- CMyComPtr decoder2;
- RINOK(CreateCoder(
- EXTERNAL_CODECS_LOC_VARS
- coderInfo.MethodID, decoder, decoder2, false));
- CMyComPtr decoderUnknown;
- if (coderInfo.IsSimpleCoder())
- {
- if (decoder == 0)
- return E_NOTIMPL;
-
- decoderUnknown = (IUnknown *)decoder;
-
- if (_multiThread)
- _mixerCoderMTSpec->AddCoder(decoder);
- #ifdef _ST_MODE
- else
- _mixerCoderSTSpec->AddCoder(decoder, false);
- #endif
- }
- else
- {
- if (decoder2 == 0)
- return E_NOTIMPL;
- decoderUnknown = (IUnknown *)decoder2;
- if (_multiThread)
- _mixerCoderMTSpec->AddCoder2(decoder2);
- #ifdef _ST_MODE
- else
- _mixerCoderSTSpec->AddCoder2(decoder2, false);
- #endif
- }
- _decoders.Add(decoderUnknown);
- #ifdef EXTERNAL_CODECS
- CMyComPtr setCompressCodecsInfo;
- decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
- if (setCompressCodecsInfo)
- {
- RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));
- }
- #endif
- }
- _bindInfoExPrev = bindInfo;
- _bindInfoExPrevIsDefined = true;
- }
- int i;
- _mixerCoderCommon->ReInit();
-
- UInt32 packStreamIndex = 0, unpackStreamIndex = 0;
- UInt32 coderIndex = 0;
- // UInt32 coder2Index = 0;
-
- for (i = 0; i < numCoders; i++)
- {
- const CCoderInfo &coderInfo = folderInfo.Coders[i];
- CMyComPtr &decoder = _decoders[coderIndex];
-
- {
- CMyComPtr setDecoderProperties;
- decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
- if (setDecoderProperties)
- {
- const CByteBuffer &props = coderInfo.Props;
- size_t size = props.GetCapacity();
- if (size > 0xFFFFFFFF)
- return E_NOTIMPL;
- if (size > 0)
- {
- RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));
- }
- }
- }
-
- #ifdef COMPRESS_MT
- if (mtMode)
- {
- CMyComPtr setCoderMt;
- decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
- if (setCoderMt)
- {
- RINOK(setCoderMt->SetNumberOfThreads(numThreads));
- }
- }
- #endif
-
- #ifndef _NO_CRYPTO
- {
- CMyComPtr cryptoSetPassword;
- decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);
- if (cryptoSetPassword)
- {
- if (getTextPassword == 0)
- return E_FAIL;
- CMyComBSTR passwordBSTR;
- RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));
- CByteBuffer buffer;
- passwordIsDefined = true;
- const UString password(passwordBSTR);
- const UInt32 sizeInBytes = password.Length() * 2;
- buffer.SetCapacity(sizeInBytes);
- for (int i = 0; i < password.Length(); i++)
- {
- wchar_t c = password[i];
- ((Byte *)buffer)[i * 2] = (Byte)c;
- ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
- }
- RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));
- }
- }
- #endif
-
- coderIndex++;
-
- UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;
- UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;
- CRecordVector packSizesPointers;
- CRecordVector unpackSizesPointers;
- packSizesPointers.Reserve(numInStreams);
- unpackSizesPointers.Reserve(numOutStreams);
- UInt32 j;
- for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)
- unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);
-
- for (j = 0; j < numInStreams; j++, packStreamIndex++)
- {
- int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);
- if (bindPairIndex >= 0)
- packSizesPointers.Add(
- &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);
- else
- {
- int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);
- if (index < 0)
- return E_FAIL;
- packSizesPointers.Add(&packSizes[index]);
- }
- }
-
- _mixerCoderCommon->SetCoderInfo(i,
- &packSizesPointers.Front(),
- &unpackSizesPointers.Front());
- }
- UInt32 mainCoder, temp;
- bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);
-
- if (_multiThread)
- _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);
- /*
- else
- _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;
- */
-
- if (numCoders == 0)
- return 0;
- CRecordVector inStreamPointers;
- inStreamPointers.Reserve(inStreams.Size());
- for (i = 0; i < inStreams.Size(); i++)
- inStreamPointers.Add(inStreams[i]);
- ISequentialOutStream *outStreamPointer = outStream;
- return _mixerCoder->Code(&inStreamPointers.Front(), NULL,
- inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zDecode.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zDecode.h
deleted file mode 100644
index aa3904a7c..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zDecode.h
+++ /dev/null
@@ -1,68 +0,0 @@
-// 7zDecode.h
-
-#ifndef __7Z_DECODE_H
-#define __7Z_DECODE_H
-
-#include "../../IStream.h"
-#include "../../IPassword.h"
-
-#include "../Common/CoderMixer2.h"
-#include "../Common/CoderMixer2MT.h"
-#ifdef _ST_MODE
-#include "../Common/CoderMixer2ST.h"
-#endif
-
-#include "../../Common/CreateCoder.h"
-
-#include "7zItem.h"
-
-namespace NArchive {
-namespace N7z {
-
-struct CBindInfoEx: public NCoderMixer::CBindInfo
-{
- CRecordVector CoderMethodIDs;
- void Clear()
- {
- CBindInfo::Clear();
- CoderMethodIDs.Clear();
- }
-};
-
-class CDecoder
-{
- bool _bindInfoExPrevIsDefined;
- CBindInfoEx _bindInfoExPrev;
-
- bool _multiThread;
- #ifdef _ST_MODE
- NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;
- #endif
- NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;
- NCoderMixer::CCoderMixer2 *_mixerCoderCommon;
-
- CMyComPtr _mixerCoder;
- CObjectVector > _decoders;
- // CObjectVector > _decoders2;
-public:
- CDecoder(bool multiThread);
- HRESULT Decode(
- DECL_EXTERNAL_CODECS_LOC_VARS
- IInStream *inStream,
- UInt64 startPos,
- const UInt64 *packSizes,
- const CFolder &folder,
- ISequentialOutStream *outStream,
- ICompressProgressInfo *compressProgress
- #ifndef _NO_CRYPTO
- , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined
- #endif
- #ifdef COMPRESS_MT
- , bool mtMode, UInt32 numThreads
- #endif
- );
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zExtract.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zExtract.cpp
deleted file mode 100644
index dbc1aa522..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zExtract.cpp
+++ /dev/null
@@ -1,273 +0,0 @@
-// 7zExtract.cpp
-
-#include "StdAfx.h"
-
-#include "7zHandler.h"
-#include "7zFolderOutStream.h"
-#include "7zDecode.h"
-// #include "7z1Decode.h"
-
-#include "../../../Common/ComTry.h"
-#include "../../Common/StreamObjects.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/LimitedStreams.h"
-
-namespace NArchive {
-namespace N7z {
-
-struct CExtractFolderInfo
-{
- #ifdef _7Z_VOL
- int VolumeIndex;
- #endif
- CNum FileIndex;
- CNum FolderIndex;
- CBoolVector ExtractStatuses;
- UInt64 UnpackSize;
- CExtractFolderInfo(
- #ifdef _7Z_VOL
- int volumeIndex,
- #endif
- CNum fileIndex, CNum folderIndex):
- #ifdef _7Z_VOL
- VolumeIndex(volumeIndex),
- #endif
- FileIndex(fileIndex),
- FolderIndex(folderIndex),
- UnpackSize(0)
- {
- if (fileIndex != kNumNoIndex)
- {
- ExtractStatuses.Reserve(1);
- ExtractStatuses.Add(true);
- }
- };
-};
-
-STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
- Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)
-{
- COM_TRY_BEGIN
- bool testMode = (testModeSpec != 0);
- CMyComPtr extractCallback = extractCallbackSpec;
- UInt64 importantTotalUnpacked = 0;
-
- bool allFilesMode = (numItems == UInt32(-1));
- if (allFilesMode)
- numItems =
- #ifdef _7Z_VOL
- _refs.Size();
- #else
- _db.Files.Size();
- #endif
-
- if(numItems == 0)
- return S_OK;
-
- /*
- if(_volumes.Size() != 1)
- return E_FAIL;
- const CVolume &volume = _volumes.Front();
- const CArchiveDatabaseEx &_db = volume.Database;
- IInStream *_inStream = volume.Stream;
- */
-
- CObjectVector extractFolderInfoVector;
- for(UInt32 ii = 0; ii < numItems; ii++)
- {
- // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];
- UInt32 ref2Index = allFilesMode ? ii : indices[ii];
- // const CRef2 &ref2 = _refs[ref2Index];
-
- // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)
- {
- #ifdef _7Z_VOL
- // const CRef &ref = ref2.Refs[ri];
- const CRef &ref = _refs[ref2Index];
-
- int volumeIndex = ref.VolumeIndex;
- const CVolume &volume = _volumes[volumeIndex];
- const CArchiveDatabaseEx &db = volume.Database;
- UInt32 fileIndex = ref.ItemIndex;
- #else
- const CArchiveDatabaseEx &db = _db;
- UInt32 fileIndex = ref2Index;
- #endif
-
- CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];
- if (folderIndex == kNumNoIndex)
- {
- extractFolderInfoVector.Add(CExtractFolderInfo(
- #ifdef _7Z_VOL
- volumeIndex,
- #endif
- fileIndex, kNumNoIndex));
- continue;
- }
- if (extractFolderInfoVector.IsEmpty() ||
- folderIndex != extractFolderInfoVector.Back().FolderIndex
- #ifdef _7Z_VOL
- || volumeIndex != extractFolderInfoVector.Back().VolumeIndex
- #endif
- )
- {
- extractFolderInfoVector.Add(CExtractFolderInfo(
- #ifdef _7Z_VOL
- volumeIndex,
- #endif
- kNumNoIndex, folderIndex));
- const CFolder &folderInfo = db.Folders[folderIndex];
- UInt64 unpackSize = folderInfo.GetUnpackSize();
- importantTotalUnpacked += unpackSize;
- extractFolderInfoVector.Back().UnpackSize = unpackSize;
- }
-
- CExtractFolderInfo &efi = extractFolderInfoVector.Back();
-
- // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];
- CNum startIndex = db.FolderStartFileIndex[folderIndex];
- for (CNum index = efi.ExtractStatuses.Size();
- index <= fileIndex - startIndex; index++)
- {
- // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;
- // Count partial_folder_size
- // efi.UnpackSize += unpackSize;
- // importantTotalUnpacked += unpackSize;
- efi.ExtractStatuses.Add(index == fileIndex - startIndex);
- }
- }
- }
-
- extractCallback->SetTotal(importantTotalUnpacked);
-
- CDecoder decoder(
- #ifdef _ST_MODE
- false
- #else
- true
- #endif
- );
- // CDecoder1 decoder;
-
- UInt64 currentTotalPacked = 0;
- UInt64 currentTotalUnpacked = 0;
- UInt64 totalFolderUnpacked;
- UInt64 totalFolderPacked;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr progress = lps;
- lps->Init(extractCallback, false);
-
- for(int i = 0; i < extractFolderInfoVector.Size(); i++,
- currentTotalUnpacked += totalFolderUnpacked,
- currentTotalPacked += totalFolderPacked)
- {
- lps->OutSize = currentTotalUnpacked;
- lps->InSize = currentTotalPacked;
- RINOK(lps->SetCur());
-
- const CExtractFolderInfo &efi = extractFolderInfoVector[i];
- totalFolderUnpacked = efi.UnpackSize;
-
- totalFolderPacked = 0;
-
- CFolderOutStream *folderOutStream = new CFolderOutStream;
- CMyComPtr outStream(folderOutStream);
-
- #ifdef _7Z_VOL
- const CVolume &volume = _volumes[efi.VolumeIndex];
- const CArchiveDatabaseEx &db = volume.Database;
- #else
- const CArchiveDatabaseEx &db = _db;
- #endif
-
- CNum startIndex;
- if (efi.FileIndex != kNumNoIndex)
- startIndex = efi.FileIndex;
- else
- startIndex = db.FolderStartFileIndex[efi.FolderIndex];
-
-
- HRESULT result = folderOutStream->Init(&db,
- #ifdef _7Z_VOL
- volume.StartRef2Index,
- #else
- 0,
- #endif
- startIndex,
- &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);
-
- RINOK(result);
-
- if (efi.FileIndex != kNumNoIndex)
- continue;
-
- CNum folderIndex = efi.FolderIndex;
- const CFolder &folderInfo = db.Folders[folderIndex];
-
- totalFolderPacked = _db.GetFolderFullPackSize(folderIndex);
-
- CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];
- UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);
-
- #ifndef _NO_CRYPTO
- CMyComPtr getTextPassword;
- if (extractCallback)
- extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
- #endif
-
- try
- {
- #ifndef _NO_CRYPTO
- bool passwordIsDefined;
- #endif
-
- HRESULT result = decoder.Decode(
- EXTERNAL_CODECS_VARS
- #ifdef _7Z_VOL
- volume.Stream,
- #else
- _inStream,
- #endif
- folderStartPackPos,
- &db.PackSizes[packStreamIndex],
- folderInfo,
- outStream,
- progress
- #ifndef _NO_CRYPTO
- , getTextPassword, passwordIsDefined
- #endif
- #ifdef COMPRESS_MT
- , true, _numThreads
- #endif
- );
-
- if (result == S_FALSE)
- {
- RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));
- continue;
- }
- if (result == E_NOTIMPL)
- {
- RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
- continue;
- }
- if (result != S_OK)
- return result;
- if (folderOutStream->WasWritingFinished() != S_OK)
- {
- RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));
- continue;
- }
- }
- catch(...)
- {
- RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));
- continue;
- }
- }
- return S_OK;
- COM_TRY_END
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderInStream.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderInStream.cpp
deleted file mode 100644
index 3b11f1686..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderInStream.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-// 7zFolderInStream.cpp
-
-#include "StdAfx.h"
-
-#include "7zFolderInStream.h"
-
-namespace NArchive {
-namespace N7z {
-
-CFolderInStream::CFolderInStream()
-{
- _inStreamWithHashSpec = new CSequentialInStreamWithCRC;
- _inStreamWithHash = _inStreamWithHashSpec;
-}
-
-void CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,
- const UInt32 *fileIndices, UInt32 numFiles)
-{
- _updateCallback = updateCallback;
- _numFiles = numFiles;
- _fileIndex = 0;
- _fileIndices = fileIndices;
- Processed.Clear();
- CRCs.Clear();
- Sizes.Clear();
- _fileIsOpen = false;
- _currentSizeIsDefined = false;
-}
-
-HRESULT CFolderInStream::OpenStream()
-{
- _filePos = 0;
- while (_fileIndex < _numFiles)
- {
- _currentSizeIsDefined = false;
- CMyComPtr stream;
- HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);
- if (result != S_OK && result != S_FALSE)
- return result;
- _fileIndex++;
- _inStreamWithHashSpec->SetStream(stream);
- _inStreamWithHashSpec->Init();
- if (!stream)
- {
- RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
- Sizes.Add(0);
- Processed.Add(result == S_OK);
- AddDigest();
- continue;
- }
- CMyComPtr streamGetSize;
- if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)
- {
- if(streamGetSize)
- {
- _currentSizeIsDefined = true;
- RINOK(streamGetSize->GetSize(&_currentSize));
- }
- }
-
- _fileIsOpen = true;
- return S_OK;
- }
- return S_OK;
-}
-
-void CFolderInStream::AddDigest()
-{
- CRCs.Add(_inStreamWithHashSpec->GetCRC());
-}
-
-HRESULT CFolderInStream::CloseStream()
-{
- RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
- _inStreamWithHashSpec->ReleaseStream();
- _fileIsOpen = false;
- Processed.Add(true);
- Sizes.Add(_filePos);
- AddDigest();
- return S_OK;
-}
-
-STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize = 0;
- while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)
- {
- if (_fileIsOpen)
- {
- UInt32 localProcessedSize;
- RINOK(_inStreamWithHash->Read(
- ((Byte *)data) + realProcessedSize, size, &localProcessedSize));
- if (localProcessedSize == 0)
- {
- RINOK(CloseStream());
- continue;
- }
- realProcessedSize += localProcessedSize;
- _filePos += localProcessedSize;
- size -= localProcessedSize;
- break;
- }
- else
- {
- RINOK(OpenStream());
- }
- }
- if (processedSize != 0)
- *processedSize = realProcessedSize;
- return S_OK;
-}
-
-STDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)
-{
- *value = 0;
- int subStreamIndex = (int)subStream;
- if (subStreamIndex < 0 || subStream > Sizes.Size())
- return E_FAIL;
- if (subStreamIndex < Sizes.Size())
- {
- *value= Sizes[subStreamIndex];
- return S_OK;
- }
- if (!_currentSizeIsDefined)
- return S_FALSE;
- *value = _currentSize;
- return S_OK;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderInStream.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderInStream.h
deleted file mode 100644
index b4df6d62a..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderInStream.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// 7z/FolderInStream.h
-
-#ifndef __7Z_FOLDERINSTREAM_H
-#define __7Z_FOLDERINSTREAM_H
-
-#include "7zItem.h"
-#include "7zHeader.h"
-
-#include "../IArchive.h"
-#include "../Common/InStreamWithCRC.h"
-#include "../../IStream.h"
-#include "../../ICoder.h"
-
-namespace NArchive {
-namespace N7z {
-
-class CFolderInStream:
- public ISequentialInStream,
- public ICompressGetSubStreamSize,
- public CMyUnknownImp
-{
-public:
-
- MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
-
- CFolderInStream();
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-
- STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
-private:
- CSequentialInStreamWithCRC *_inStreamWithHashSpec;
- CMyComPtr _inStreamWithHash;
- CMyComPtr _updateCallback;
-
- bool _currentSizeIsDefined;
- UInt64 _currentSize;
-
- bool _fileIsOpen;
- UInt64 _filePos;
-
- const UInt32 *_fileIndices;
- UInt32 _numFiles;
- UInt32 _fileIndex;
-
- HRESULT OpenStream();
- HRESULT CloseStream();
- void AddDigest();
-public:
- void Init(IArchiveUpdateCallback *updateCallback,
- const UInt32 *fileIndices, UInt32 numFiles);
- CRecordVector Processed;
- CRecordVector CRCs;
- CRecordVector Sizes;
- UInt64 GetFullSize() const
- {
- UInt64 size = 0;
- for (int i = 0; i < Sizes.Size(); i++)
- size += Sizes[i];
- return size;
- }
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderOutStream.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderOutStream.cpp
deleted file mode 100644
index d3a79ee13..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderOutStream.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-// 7zFolderOutStream.cpp
-
-#include "StdAfx.h"
-
-#include "7zFolderOutStream.h"
-
-namespace NArchive {
-namespace N7z {
-
-CFolderOutStream::CFolderOutStream()
-{
- _outStreamWithHashSpec = new COutStreamWithCRC;
- _outStreamWithHash = _outStreamWithHashSpec;
-}
-
-HRESULT CFolderOutStream::Init(
- const CArchiveDatabaseEx *archiveDatabase,
- UInt32 ref2Offset,
- UInt32 startIndex,
- const CBoolVector *extractStatuses,
- IArchiveExtractCallback *extractCallback,
- bool testMode,
- bool checkCrc)
-{
- _archiveDatabase = archiveDatabase;
- _ref2Offset = ref2Offset;
- _startIndex = startIndex;
-
- _extractStatuses = extractStatuses;
- _extractCallback = extractCallback;
- _testMode = testMode;
-
- _checkCrc = checkCrc;
-
- _currentIndex = 0;
- _fileIsOpen = false;
- return WriteEmptyFiles();
-}
-
-HRESULT CFolderOutStream::OpenFile()
-{
- Int32 askMode;
- if((*_extractStatuses)[_currentIndex])
- askMode = _testMode ?
- NArchive::NExtract::NAskMode::kTest :
- NArchive::NExtract::NAskMode::kExtract;
- else
- askMode = NArchive::NExtract::NAskMode::kSkip;
- CMyComPtr realOutStream;
-
- UInt32 index = _startIndex + _currentIndex;
- RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));
-
- _outStreamWithHashSpec->SetStream(realOutStream);
- _outStreamWithHashSpec->Init(_checkCrc);
- if (askMode == NArchive::NExtract::NAskMode::kExtract &&
- (!realOutStream))
- {
- const CFileItem &fi = _archiveDatabase->Files[index];
- if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir)
- askMode = NArchive::NExtract::NAskMode::kSkip;
- }
- return _extractCallback->PrepareOperation(askMode);
-}
-
-HRESULT CFolderOutStream::WriteEmptyFiles()
-{
- for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)
- {
- UInt32 index = _startIndex + _currentIndex;
- const CFileItem &fi = _archiveDatabase->Files[index];
- if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir && fi.Size != 0)
- return S_OK;
- RINOK(OpenFile());
- RINOK(_extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
- _outStreamWithHashSpec->ReleaseStream();
- }
- return S_OK;
-}
-
-STDMETHODIMP CFolderOutStream::Write(const void *data,
- UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize = 0;
- while(_currentIndex < _extractStatuses->Size())
- {
- if (_fileIsOpen)
- {
- UInt32 index = _startIndex + _currentIndex;
- const CFileItem &fi = _archiveDatabase->Files[index];
- UInt64 fileSize = fi.Size;
-
- UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos,
- UInt64(size - realProcessedSize));
-
- UInt32 processedSizeLocal;
- RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize,
- numBytesToWrite, &processedSizeLocal));
-
- _filePos += processedSizeLocal;
- realProcessedSize += processedSizeLocal;
- if (_filePos == fileSize)
- {
- bool digestsAreEqual;
- if (fi.CrcDefined && _checkCrc)
- digestsAreEqual = fi.Crc == _outStreamWithHashSpec->GetCRC();
- else
- digestsAreEqual = true;
-
- RINOK(_extractCallback->SetOperationResult(
- digestsAreEqual ?
- NArchive::NExtract::NOperationResult::kOK :
- NArchive::NExtract::NOperationResult::kCRCError));
- _outStreamWithHashSpec->ReleaseStream();
- _fileIsOpen = false;
- _currentIndex++;
- }
- if (realProcessedSize == size)
- {
- if (processedSize != NULL)
- *processedSize = realProcessedSize;
- return WriteEmptyFiles();
- }
- }
- else
- {
- RINOK(OpenFile());
- _fileIsOpen = true;
- _filePos = 0;
- }
- }
- if (processedSize != NULL)
- *processedSize = size;
- return S_OK;
-}
-
-HRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)
-{
- while(_currentIndex < _extractStatuses->Size())
- {
- if (_fileIsOpen)
- {
- RINOK(_extractCallback->SetOperationResult(resultEOperationResult));
- _outStreamWithHashSpec->ReleaseStream();
- _fileIsOpen = false;
- _currentIndex++;
- }
- else
- {
- RINOK(OpenFile());
- _fileIsOpen = true;
- }
- }
- return S_OK;
-}
-
-HRESULT CFolderOutStream::WasWritingFinished()
-{
- if (_currentIndex == _extractStatuses->Size())
- return S_OK;
- return E_FAIL;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderOutStream.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderOutStream.h
deleted file mode 100644
index d88cde985..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zFolderOutStream.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// 7zFolderOutStream.h
-
-#ifndef __7Z_FOLDEROUTSTREAM_H
-#define __7Z_FOLDEROUTSTREAM_H
-
-#include "7zIn.h"
-
-#include "../../IStream.h"
-#include "../IArchive.h"
-#include "../Common/OutStreamWithCRC.h"
-
-namespace NArchive {
-namespace N7z {
-
-class CFolderOutStream:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- CFolderOutStream();
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-private:
-
- COutStreamWithCRC *_outStreamWithHashSpec;
- CMyComPtr _outStreamWithHash;
- const CArchiveDatabaseEx *_archiveDatabase;
- const CBoolVector *_extractStatuses;
- UInt32 _startIndex;
- UInt32 _ref2Offset;
- int _currentIndex;
- // UInt64 _currentDataPos;
- CMyComPtr _extractCallback;
- bool _testMode;
-
- bool _fileIsOpen;
-
- bool _checkCrc;
- UInt64 _filePos;
-
- HRESULT OpenFile();
- HRESULT WriteEmptyFiles();
-public:
- HRESULT Init(
- const CArchiveDatabaseEx *archiveDatabase,
- UInt32 ref2Offset,
- UInt32 startIndex,
- const CBoolVector *extractStatuses,
- IArchiveExtractCallback *extractCallback,
- bool testMode,
- bool checkCrc);
- HRESULT FlushCorrupted(Int32 resultEOperationResult);
- HRESULT WasWritingFinished();
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHandler.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHandler.cpp
deleted file mode 100644
index c76a106f8..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHandler.cpp
+++ /dev/null
@@ -1,503 +0,0 @@
-// 7zHandler.cpp
-
-#include "StdAfx.h"
-
-extern "C"
-{
- #include "../../../../C/CpuArch.h"
-}
-
-#include "../../../Common/ComTry.h"
-#include "../../../Common/IntToString.h"
-
-#ifdef COMPRESS_MT
-#include "../../../Windows/System.h"
-#endif
-
-#include "../Common/ItemNameUtils.h"
-
-#include "7zHandler.h"
-#include "7zProperties.h"
-
-#ifdef __7Z_SET_PROPERTIES
-#ifdef EXTRACT_ONLY
-#include "../Common/ParseProperties.h"
-#endif
-#endif
-
-using namespace NWindows;
-
-extern UString ConvertMethodIdToString(UInt64 id);
-
-namespace NArchive {
-namespace N7z {
-
-CHandler::CHandler()
-{
- _crcSize = 4;
-
- #ifndef _NO_CRYPTO
- _passwordIsDefined = false;
- #endif
-
- #ifdef EXTRACT_ONLY
- #ifdef COMPRESS_MT
- _numThreads = NSystem::GetNumberOfProcessors();
- #endif
- #else
- Init();
- #endif
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _db.Files.Size();
- return S_OK;
-}
-
-#ifdef _SFX
-
-IMP_IInArchive_ArcProps_NO
-
-STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)
-{
- return E_NOTIMPL;
-}
-
-STDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,
- BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)
-{
- return E_NOTIMPL;
-}
-
-
-#else
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidSolid, VT_BOOL},
- { NULL, kpidNumBlocks, VT_UI4},
- { NULL, kpidPhySize, VT_UI8},
- { NULL, kpidHeadersSize, VT_UI8},
- { NULL, kpidOffset, VT_UI8}
-};
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidMethod:
- {
- UString resString;
- CRecordVector ids;
- int i;
- for (i = 0; i < _db.Folders.Size(); i++)
- {
- const CFolder &f = _db.Folders[i];
- for (int j = f.Coders.Size() - 1; j >= 0; j--)
- ids.AddToUniqueSorted(f.Coders[j].MethodID);
- }
-
- for (i = 0; i < ids.Size(); i++)
- {
- UInt64 id = ids[i];
- UString methodName;
- /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);
- if (methodName.IsEmpty())
- methodName = ConvertMethodIdToString(id);
- if (!resString.IsEmpty())
- resString += L' ';
- resString += methodName;
- }
- prop = resString;
- break;
- }
- case kpidSolid: prop = _db.IsSolid(); break;
- case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;
- case kpidHeadersSize: prop = _db.HeadersSize; break;
- case kpidPhySize: prop = _db.PhySize; break;
- case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-IMP_IInArchive_ArcProps
-
-#endif
-
-static void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)
-{
- UInt64 value;
- if (v.GetItem(index, value))
- {
- FILETIME ft;
- ft.dwLowDateTime = (DWORD)value;
- ft.dwHighDateTime = (DWORD)(value >> 32);
- prop = ft;
- }
-}
-
-#ifndef _SFX
-
-static UString ConvertUInt32ToString(UInt32 value)
-{
- wchar_t buffer[32];
- ConvertUInt64ToString(value, buffer);
- return buffer;
-}
-
-static UString GetStringForSizeValue(UInt32 value)
-{
- for (int i = 31; i >= 0; i--)
- if ((UInt32(1) << i) == value)
- return ConvertUInt32ToString(i);
- UString result;
- if (value % (1 << 20) == 0)
- {
- result += ConvertUInt32ToString(value >> 20);
- result += L"m";
- }
- else if (value % (1 << 10) == 0)
- {
- result += ConvertUInt32ToString(value >> 10);
- result += L"k";
- }
- else
- {
- result += ConvertUInt32ToString(value);
- result += L"b";
- }
- return result;
-}
-
-static const UInt64 k_Copy = 0x0;
-static const UInt64 k_LZMA = 0x030101;
-static const UInt64 k_PPMD = 0x030401;
-
-static wchar_t GetHex(Byte value)
-{
- return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));
-}
-static inline UString GetHex2(Byte value)
-{
- UString result;
- result += GetHex((Byte)(value >> 4));
- result += GetHex((Byte)(value & 0xF));
- return result;
-}
-
-#endif
-
-static const UInt64 k_AES = 0x06F10701;
-
-bool CHandler::IsEncrypted(UInt32 index2) const
-{
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- {
- const CFolder &folderInfo = _db.Folders[folderIndex];
- for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)
- if (folderInfo.Coders[i].MethodID == k_AES)
- return true;
- }
- return false;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NCOM::CPropVariant prop;
-
- /*
- const CRef2 &ref2 = _refs[index];
- if (ref2.Refs.IsEmpty())
- return E_FAIL;
- const CRef &ref = ref2.Refs.Front();
- */
-
- const CFileItem &item = _db.Files[index];
- UInt32 index2 = index;
-
- switch(propID)
- {
- case kpidPath:
- if (!item.Name.IsEmpty())
- prop = NItemName::GetOSName(item.Name);
- break;
- case kpidIsDir: prop = item.IsDir; break;
- case kpidSize:
- {
- prop = item.Size;
- // prop = ref2.Size;
- break;
- }
- case kpidPackSize:
- {
- // prop = ref2.PackSize;
- {
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- {
- if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)
- prop = _db.GetFolderFullPackSize(folderIndex);
- /*
- else
- prop = (UInt64)0;
- */
- }
- else
- prop = (UInt64)0;
- }
- break;
- }
- case kpidPosition: { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }
- case kpidCTime: SetPropFromUInt64Def(_db.CTime, index2, prop); break;
- case kpidATime: SetPropFromUInt64Def(_db.ATime, index2, prop); break;
- case kpidMTime: SetPropFromUInt64Def(_db.MTime, index2, prop); break;
- case kpidAttrib: if (item.AttribDefined) prop = item.Attrib; break;
- case kpidCRC: if (item.CrcDefined) prop = item.Crc; break;
- case kpidEncrypted: prop = IsEncrypted(index2); break;
- case kpidIsAnti: prop = _db.IsItemAnti(index2); break;
- #ifndef _SFX
- case kpidMethod:
- {
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- {
- const CFolder &folderInfo = _db.Folders[folderIndex];
- UString methodsString;
- for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)
- {
- const CCoderInfo &coderInfo = folderInfo.Coders[i];
- if (!methodsString.IsEmpty())
- methodsString += L' ';
-
- {
- UString methodName;
- bool methodIsKnown = FindMethod(
- EXTERNAL_CODECS_VARS
- coderInfo.MethodID, methodName);
-
- if (methodIsKnown)
- {
- methodsString += methodName;
- if (coderInfo.MethodID == k_LZMA)
- {
- if (coderInfo.Props.GetCapacity() >= 5)
- {
- methodsString += L":";
- UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);
- methodsString += GetStringForSizeValue(dicSize);
- }
- }
- else if (coderInfo.MethodID == k_PPMD)
- {
- if (coderInfo.Props.GetCapacity() >= 5)
- {
- Byte order = *(const Byte *)coderInfo.Props;
- methodsString += L":o";
- methodsString += ConvertUInt32ToString(order);
- methodsString += L":mem";
- UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);
- methodsString += GetStringForSizeValue(dicSize);
- }
- }
- else if (coderInfo.MethodID == k_AES)
- {
- if (coderInfo.Props.GetCapacity() >= 1)
- {
- methodsString += L":";
- const Byte *data = (const Byte *)coderInfo.Props;
- Byte firstByte = *data++;
- UInt32 numCyclesPower = firstByte & 0x3F;
- methodsString += ConvertUInt32ToString(numCyclesPower);
- /*
- if ((firstByte & 0xC0) != 0)
- {
- methodsString += L":";
- return S_OK;
- UInt32 saltSize = (firstByte >> 7) & 1;
- UInt32 ivSize = (firstByte >> 6) & 1;
- if (coderInfo.Props.GetCapacity() >= 2)
- {
- Byte secondByte = *data++;
- saltSize += (secondByte >> 4);
- ivSize += (secondByte & 0x0F);
- }
- }
- */
- }
- }
- else
- {
- if (coderInfo.Props.GetCapacity() > 0)
- {
- methodsString += L":[";
- for (size_t bi = 0; bi < coderInfo.Props.GetCapacity(); bi++)
- {
- if (bi > 5 && bi + 1 < coderInfo.Props.GetCapacity())
- {
- methodsString += L"..";
- break;
- }
- else
- methodsString += GetHex2(coderInfo.Props[bi]);
- }
- methodsString += L"]";
- }
- }
- }
- else
- {
- methodsString += ConvertMethodIdToString(coderInfo.MethodID);
- }
- }
- }
- prop = methodsString;
- }
- }
- break;
- case kpidBlock:
- {
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- prop = (UInt32)folderIndex;
- }
- break;
- case kpidPackedSize0:
- case kpidPackedSize1:
- case kpidPackedSize2:
- case kpidPackedSize3:
- case kpidPackedSize4:
- {
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- {
- const CFolder &folderInfo = _db.Folders[folderIndex];
- if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&
- folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))
- {
- prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);
- }
- else
- prop = (UInt64)0;
- }
- else
- prop = (UInt64)0;
- }
- break;
- #endif
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *openArchiveCallback)
-{
- COM_TRY_BEGIN
- Close();
- #ifndef _SFX
- _fileInfoPopIDs.Clear();
- #endif
- try
- {
- CMyComPtr openArchiveCallbackTemp = openArchiveCallback;
-
- #ifndef _NO_CRYPTO
- CMyComPtr getTextPassword;
- if (openArchiveCallback)
- {
- openArchiveCallbackTemp.QueryInterface(
- IID_ICryptoGetTextPassword, &getTextPassword);
- }
- #endif
- CInArchive archive;
- RINOK(archive.Open(stream, maxCheckStartPosition));
- #ifndef _NO_CRYPTO
- _passwordIsDefined = false;
- UString password;
- #endif
- HRESULT result = archive.ReadDatabase(
- EXTERNAL_CODECS_VARS
- _db
- #ifndef _NO_CRYPTO
- , getTextPassword, _passwordIsDefined
- #endif
- );
- RINOK(result);
- _db.Fill();
- _inStream = stream;
- }
- catch(...)
- {
- Close();
- return S_FALSE;
- }
- // _inStream = stream;
- #ifndef _SFX
- FillPopIDs();
- #endif
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- COM_TRY_BEGIN
- _inStream.Release();
- _db.Clear();
- return S_OK;
- COM_TRY_END
-}
-
-#ifdef __7Z_SET_PROPERTIES
-#ifdef EXTRACT_ONLY
-
-STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)
-{
- COM_TRY_BEGIN
- #ifdef COMPRESS_MT
- const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
- _numThreads = numProcessors;
- #endif
-
- for (int i = 0; i < numProperties; i++)
- {
- UString name = names[i];
- name.MakeUpper();
- if (name.IsEmpty())
- return E_INVALIDARG;
- const PROPVARIANT &value = values[i];
- UInt32 number;
- int index = ParseStringToUInt32(name, number);
- if (index == 0)
- {
- if(name.Left(2).CompareNoCase(L"MT") == 0)
- {
- #ifdef COMPRESS_MT
- RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));
- #endif
- continue;
- }
- else
- return E_INVALIDARG;
- }
- }
- return S_OK;
- COM_TRY_END
-}
-
-#endif
-#endif
-
-IMPL_ISetCompressCodecsInfo
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHandler.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHandler.h
deleted file mode 100644
index c04a0f931..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHandler.h
+++ /dev/null
@@ -1,121 +0,0 @@
-// 7z/Handler.h
-
-#ifndef __7Z_HANDLER_H
-#define __7Z_HANDLER_H
-
-#include "../../ICoder.h"
-#include "../IArchive.h"
-#include "7zIn.h"
-
-#include "7zCompressionMode.h"
-
-#include "../../Common/CreateCoder.h"
-
-#ifndef EXTRACT_ONLY
-#include "../Common/HandlerOut.h"
-#endif
-
-namespace NArchive {
-namespace N7z {
-
-#ifndef __7Z_SET_PROPERTIES
-
-#ifdef EXTRACT_ONLY
-#ifdef COMPRESS_MT
-#define __7Z_SET_PROPERTIES
-#endif
-#else
-#define __7Z_SET_PROPERTIES
-#endif
-
-#endif
-
-
-class CHandler:
- #ifndef EXTRACT_ONLY
- public NArchive::COutHandler,
- #endif
- public IInArchive,
- #ifdef __7Z_SET_PROPERTIES
- public ISetProperties,
- #endif
- #ifndef EXTRACT_ONLY
- public IOutArchive,
- #endif
- PUBLIC_ISetCompressCodecsInfo
- public CMyUnknownImp
-{
-public:
- MY_QUERYINTERFACE_BEGIN2(IInArchive)
- #ifdef __7Z_SET_PROPERTIES
- MY_QUERYINTERFACE_ENTRY(ISetProperties)
- #endif
- #ifndef EXTRACT_ONLY
- MY_QUERYINTERFACE_ENTRY(IOutArchive)
- #endif
- QUERY_ENTRY_ISetCompressCodecsInfo
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IInArchive(;)
-
- #ifdef __7Z_SET_PROPERTIES
- STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
- #endif
-
- #ifndef EXTRACT_ONLY
- INTERFACE_IOutArchive(;)
- #endif
-
- DECL_ISetCompressCodecsInfo
-
- CHandler();
-
-private:
- CMyComPtr _inStream;
- NArchive::N7z::CArchiveDatabaseEx _db;
- #ifndef _NO_CRYPTO
- bool _passwordIsDefined;
- #endif
-
- #ifdef EXTRACT_ONLY
-
- #ifdef COMPRESS_MT
- UInt32 _numThreads;
- #endif
-
- UInt32 _crcSize;
-
- #else
-
- CRecordVector _binds;
-
- HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);
-
- HRESULT SetCompressionMethod(CCompressionMethodMode &method,
- CObjectVector &methodsInfo
- #ifdef COMPRESS_MT
- , UInt32 numThreads
- #endif
- );
-
- HRESULT SetCompressionMethod(
- CCompressionMethodMode &method,
- CCompressionMethodMode &headerMethod);
-
- #endif
-
- bool IsEncrypted(UInt32 index2) const;
- #ifndef _SFX
-
- CRecordVector _fileInfoPopIDs;
- void FillPopIDs();
-
- #endif
-
- DECL_EXTERNAL_CODECS_VARS
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHeader.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHeader.cpp
deleted file mode 100644
index c010f3671..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHeader.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// 7z/Header.cpp
-
-#include "StdAfx.h"
-#include "7zHeader.h"
-
-namespace NArchive {
-namespace N7z {
-
-Byte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};
-#ifdef _7Z_VOL
-Byte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};
-#endif
-
-class SignatureInitializer
-{
-public:
- SignatureInitializer()
- {
- kSignature[0]--;
- #ifdef _7Z_VOL
- kFinishSignature[0]--;
- #endif
- };
-} g_SignatureInitializer;
-
-}}
-
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHeader.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHeader.h
deleted file mode 100644
index 57f455b81..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zHeader.h
+++ /dev/null
@@ -1,97 +0,0 @@
-// 7z/7zHeader.h
-
-#ifndef __7Z_HEADER_H
-#define __7Z_HEADER_H
-
-#include "../../../Common/Types.h"
-
-namespace NArchive {
-namespace N7z {
-
-const int kSignatureSize = 6;
-extern Byte kSignature[kSignatureSize];
-
-// #define _7Z_VOL
-// 7z-MultiVolume is not finished yet.
-// It can work already, but I still do not like some
-// things of that new multivolume format.
-// So please keep it commented.
-
-#ifdef _7Z_VOL
-extern Byte kFinishSignature[kSignatureSize];
-#endif
-
-struct CArchiveVersion
-{
- Byte Major;
- Byte Minor;
-};
-
-const Byte kMajorVersion = 0;
-
-struct CStartHeader
-{
- UInt64 NextHeaderOffset;
- UInt64 NextHeaderSize;
- UInt32 NextHeaderCRC;
-};
-
-const UInt32 kStartHeaderSize = 20;
-
-#ifdef _7Z_VOL
-struct CFinishHeader: public CStartHeader
-{
- UInt64 ArchiveStartOffset; // data offset from end if that struct
- UInt64 AdditionalStartBlockSize; // start signature & start header size
-};
-
-const UInt32 kFinishHeaderSize = kStartHeaderSize + 16;
-#endif
-
-namespace NID
-{
- enum EEnum
- {
- kEnd,
-
- kHeader,
-
- kArchiveProperties,
-
- kAdditionalStreamsInfo,
- kMainStreamsInfo,
- kFilesInfo,
-
- kPackInfo,
- kUnpackInfo,
- kSubStreamsInfo,
-
- kSize,
- kCRC,
-
- kFolder,
-
- kCodersUnpackSize,
- kNumUnpackStream,
-
- kEmptyStream,
- kEmptyFile,
- kAnti,
-
- kName,
- kCTime,
- kATime,
- kMTime,
- kWinAttributes,
- kComment,
-
- kEncodedHeader,
-
- kStartPos,
- kDummy
- };
-}
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zIn.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zIn.cpp
deleted file mode 100644
index a9fecf8e1..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zIn.cpp
+++ /dev/null
@@ -1,1260 +0,0 @@
-// 7zIn.cpp
-
-#include "StdAfx.h"
-
-extern "C"
-{
- #include "../../../../C/7zCrc.h"
- #include "../../../../C/CpuArch.h"
-}
-
-#include "../../Common/StreamObjects.h"
-#include "../../Common/StreamUtils.h"
-
-#include "7zDecode.h"
-#include "7zIn.h"
-
-#define Get16(p) GetUi16(p)
-#define Get32(p) GetUi32(p)
-#define Get64(p) GetUi64(p)
-
-// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader
-#ifndef _SFX
-#define FORMAT_7Z_RECOVERY
-#endif
-
-namespace NArchive {
-namespace N7z {
-
-static void BoolVector_Fill_False(CBoolVector &v, int size)
-{
- v.Clear();
- v.Reserve(size);
- for (int i = 0; i < size; i++)
- v.Add(false);
-}
-
-static bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)
-{
- if (index >= (UInt32)v.Size())
- return true;
- bool res = v[index];
- v[index] = true;
- return res;
-}
-
-bool CFolder::CheckStructure() const
-{
- const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it
- const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax
- const int kNumBindsMax = 32;
-
- if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)
- return false;
-
- {
- CBoolVector v;
- BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());
-
- int i;
- for (i = 0; i < BindPairs.Size(); i++)
- if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))
- return false;
- for (i = 0; i < PackStreams.Size(); i++)
- if (BoolVector_GetAndSet(v, PackStreams[i]))
- return false;
-
- BoolVector_Fill_False(v, UnpackSizes.Size());
- for (i = 0; i < BindPairs.Size(); i++)
- if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))
- return false;
- }
-
- UInt32 mask[kMaskSize];
- int i;
- for (i = 0; i < kMaskSize; i++)
- mask[i] = 0;
-
- {
- CIntVector inStreamToCoder, outStreamToCoder;
- for (i = 0; i < Coders.Size(); i++)
- {
- CNum j;
- const CCoderInfo &coder = Coders[i];
- for (j = 0; j < coder.NumInStreams; j++)
- inStreamToCoder.Add(i);
- for (j = 0; j < coder.NumOutStreams; j++)
- outStreamToCoder.Add(i);
- }
-
- for (i = 0; i < BindPairs.Size(); i++)
- {
- const CBindPair &bp = BindPairs[i];
- mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);
- }
- }
-
- for (i = 0; i < kMaskSize; i++)
- for (int j = 0; j < kMaskSize; j++)
- if (((1 << j) & mask[i]) != 0)
- mask[i] |= mask[j];
-
- for (i = 0; i < kMaskSize; i++)
- if (((1 << i) & mask[i]) != 0)
- return false;
-
- return true;
-}
-
-class CInArchiveException {};
-
-static void ThrowException() { throw CInArchiveException(); }
-static inline void ThrowEndOfData() { ThrowException(); }
-static inline void ThrowUnsupported() { ThrowException(); }
-static inline void ThrowIncorrect() { ThrowException(); }
-static inline void ThrowUnsupportedVersion() { ThrowException(); }
-
-/*
-class CInArchiveException
-{
-public:
- enum CCauseType
- {
- kUnsupportedVersion = 0,
- kUnsupported,
- kIncorrect,
- kEndOfData,
- } Cause;
- CInArchiveException(CCauseType cause): Cause(cause) {};
-};
-
-static void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }
-static void ThrowEndOfData() { ThrowException(CInArchiveException::kEndOfData); }
-static void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }
-static void ThrowIncorrect() { ThrowException(CInArchiveException::kIncorrect); }
-static void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }
-*/
-
-class CStreamSwitch
-{
- CInArchive *_archive;
- bool _needRemove;
-public:
- CStreamSwitch(): _needRemove(false) {}
- ~CStreamSwitch() { Remove(); }
- void Remove();
- void Set(CInArchive *archive, const Byte *data, size_t size);
- void Set(CInArchive *archive, const CByteBuffer &byteBuffer);
- void Set(CInArchive *archive, const CObjectVector *dataVector);
-};
-
-void CStreamSwitch::Remove()
-{
- if (_needRemove)
- {
- _archive->DeleteByteStream();
- _needRemove = false;
- }
-}
-
-void CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)
-{
- Remove();
- _archive = archive;
- _archive->AddByteStream(data, size);
- _needRemove = true;
-}
-
-void CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)
-{
- Set(archive, byteBuffer, byteBuffer.GetCapacity());
-}
-
-void CStreamSwitch::Set(CInArchive *archive, const CObjectVector *dataVector)
-{
- Remove();
- Byte external = archive->ReadByte();
- if (external != 0)
- {
- int dataIndex = (int)archive->ReadNum();
- if (dataIndex < 0 || dataIndex >= dataVector->Size())
- ThrowIncorrect();
- Set(archive, (*dataVector)[dataIndex]);
- }
-}
-
-Byte CInByte2::ReadByte()
-{
- if (_pos >= _size)
- ThrowEndOfData();
- return _buffer[_pos++];
-}
-
-void CInByte2::ReadBytes(Byte *data, size_t size)
-{
- if (size > _size - _pos)
- ThrowEndOfData();
- for (size_t i = 0; i < size; i++)
- data[i] = _buffer[_pos++];
-}
-
-void CInByte2::SkeepData(UInt64 size)
-{
- if (size > _size - _pos)
- ThrowEndOfData();
- _pos += (size_t)size;
-}
-
-void CInByte2::SkeepData()
-{
- SkeepData(ReadNumber());
-}
-
-UInt64 CInByte2::ReadNumber()
-{
- if (_pos >= _size)
- ThrowEndOfData();
- Byte firstByte = _buffer[_pos++];
- Byte mask = 0x80;
- UInt64 value = 0;
- for (int i = 0; i < 8; i++)
- {
- if ((firstByte & mask) == 0)
- {
- UInt64 highPart = firstByte & (mask - 1);
- value += (highPart << (i * 8));
- return value;
- }
- if (_pos >= _size)
- ThrowEndOfData();
- value |= ((UInt64)_buffer[_pos++] << (8 * i));
- mask >>= 1;
- }
- return value;
-}
-
-CNum CInByte2::ReadNum()
-{
- UInt64 value = ReadNumber();
- if (value > kNumMax)
- ThrowUnsupported();
- return (CNum)value;
-}
-
-UInt32 CInByte2::ReadUInt32()
-{
- if (_pos + 4 > _size)
- ThrowEndOfData();
- UInt32 res = Get32(_buffer + _pos);
- _pos += 4;
- return res;
-}
-
-UInt64 CInByte2::ReadUInt64()
-{
- if (_pos + 8 > _size)
- ThrowEndOfData();
- UInt64 res = Get64(_buffer + _pos);
- _pos += 8;
- return res;
-}
-
-void CInByte2::ReadString(UString &s)
-{
- const Byte *buf = _buffer + _pos;
- size_t rem = (_size - _pos) / 2 * 2;
- {
- size_t i;
- for (i = 0; i < rem; i += 2)
- if (buf[i] == 0 && buf[i + 1] == 0)
- break;
- if (i == rem)
- ThrowEndOfData();
- rem = i;
- }
- int len = (int)(rem / 2);
- if (len < 0 || (size_t)len * 2 != rem)
- ThrowUnsupported();
- wchar_t *p = s.GetBuffer(len);
- int i;
- for (i = 0; i < len; i++, buf += 2)
- p[i] = (wchar_t)Get16(buf);
- s.ReleaseBuffer(len);
- _pos += rem + 2;
-}
-
-static inline bool TestSignatureCandidate(const Byte *p)
-{
- for (int i = 0; i < kSignatureSize; i++)
- if (p[i] != kSignature[i])
- return false;
- return (p[0x1A] == 0 && p[0x1B] == 0);
-}
-
-HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
-{
- RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));
-
- if (TestSignatureCandidate(_header))
- return S_OK;
-
- CByteBuffer byteBuffer;
- const UInt32 kBufferSize = (1 << 16);
- byteBuffer.SetCapacity(kBufferSize);
- Byte *buffer = byteBuffer;
- UInt32 numPrevBytes = kHeaderSize - 1;
- memcpy(buffer, _header + 1, numPrevBytes);
- UInt64 curTestPos = _arhiveBeginStreamPosition + 1;
- for (;;)
- {
- if (searchHeaderSizeLimit != NULL)
- if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)
- break;
- do
- {
- UInt32 numReadBytes = kBufferSize - numPrevBytes;
- UInt32 processedSize;
- RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
- numPrevBytes += processedSize;
- if (processedSize == 0)
- return S_FALSE;
- }
- while (numPrevBytes < kHeaderSize);
- UInt32 numTests = numPrevBytes - kHeaderSize + 1;
- for (UInt32 pos = 0; pos < numTests; pos++)
- {
- for (; buffer[pos] != '7' && pos < numTests; pos++);
- if (pos == numTests)
- break;
- if (TestSignatureCandidate(buffer + pos))
- {
- memcpy(_header, buffer + pos, kHeaderSize);
- curTestPos += pos;
- _arhiveBeginStreamPosition = curTestPos;
- return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);
- }
- }
- curTestPos += numTests;
- numPrevBytes -= numTests;
- memmove(buffer, buffer + numTests, numPrevBytes);
- }
- return S_FALSE;
-}
-
-// S_FALSE means that file is not archive
-HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
-{
- HeadersSize = 0;
- Close();
- RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))
- RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));
- _stream = stream;
- return S_OK;
-}
-
-void CInArchive::Close()
-{
- _stream.Release();
-}
-
-void CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)
-{
- for (;;)
- {
- if (ReadID() == NID::kEnd)
- break;
- SkeepData();
- }
-}
-
-void CInArchive::GetNextFolderItem(CFolder &folder)
-{
- CNum numCoders = ReadNum();
-
- folder.Coders.Clear();
- folder.Coders.Reserve((int)numCoders);
- CNum numInStreams = 0;
- CNum numOutStreams = 0;
- CNum i;
- for (i = 0; i < numCoders; i++)
- {
- folder.Coders.Add(CCoderInfo());
- CCoderInfo &coder = folder.Coders.Back();
-
- {
- Byte mainByte = ReadByte();
- int idSize = (mainByte & 0xF);
- Byte longID[15];
- ReadBytes(longID, idSize);
- if (idSize > 8)
- ThrowUnsupported();
- UInt64 id = 0;
- for (int j = 0; j < idSize; j++)
- id |= (UInt64)longID[idSize - 1 - j] << (8 * j);
- coder.MethodID = id;
-
- if ((mainByte & 0x10) != 0)
- {
- coder.NumInStreams = ReadNum();
- coder.NumOutStreams = ReadNum();
- }
- else
- {
- coder.NumInStreams = 1;
- coder.NumOutStreams = 1;
- }
- if ((mainByte & 0x20) != 0)
- {
- CNum propsSize = ReadNum();
- coder.Props.SetCapacity((size_t)propsSize);
- ReadBytes((Byte *)coder.Props, (size_t)propsSize);
- }
- if ((mainByte & 0x80) != 0)
- ThrowUnsupported();
- }
- numInStreams += coder.NumInStreams;
- numOutStreams += coder.NumOutStreams;
- }
-
- CNum numBindPairs = numOutStreams - 1;
- folder.BindPairs.Clear();
- folder.BindPairs.Reserve(numBindPairs);
- for (i = 0; i < numBindPairs; i++)
- {
- CBindPair bp;
- bp.InIndex = ReadNum();
- bp.OutIndex = ReadNum();
- folder.BindPairs.Add(bp);
- }
-
- if (numInStreams < numBindPairs)
- ThrowUnsupported();
- CNum numPackStreams = numInStreams - numBindPairs;
- folder.PackStreams.Reserve(numPackStreams);
- if (numPackStreams == 1)
- {
- for (i = 0; i < numInStreams; i++)
- if (folder.FindBindPairForInStream(i) < 0)
- {
- folder.PackStreams.Add(i);
- break;
- }
- if (folder.PackStreams.Size() != 1)
- ThrowUnsupported();
- }
- else
- for (i = 0; i < numPackStreams; i++)
- folder.PackStreams.Add(ReadNum());
-}
-
-void CInArchive::WaitAttribute(UInt64 attribute)
-{
- for (;;)
- {
- UInt64 type = ReadID();
- if (type == attribute)
- return;
- if (type == NID::kEnd)
- ThrowIncorrect();
- SkeepData();
- }
-}
-
-void CInArchive::ReadHashDigests(int numItems,
- CBoolVector &digestsDefined,
- CRecordVector &digests)
-{
- ReadBoolVector2(numItems, digestsDefined);
- digests.Clear();
- digests.Reserve(numItems);
- for (int i = 0; i < numItems; i++)
- {
- UInt32 crc = 0;
- if (digestsDefined[i])
- crc = ReadUInt32();
- digests.Add(crc);
- }
-}
-
-void CInArchive::ReadPackInfo(
- UInt64 &dataOffset,
- CRecordVector &packSizes,
- CBoolVector &packCRCsDefined,
- CRecordVector &packCRCs)
-{
- dataOffset = ReadNumber();
- CNum numPackStreams = ReadNum();
-
- WaitAttribute(NID::kSize);
- packSizes.Clear();
- packSizes.Reserve(numPackStreams);
- for (CNum i = 0; i < numPackStreams; i++)
- packSizes.Add(ReadNumber());
-
- UInt64 type;
- for (;;)
- {
- type = ReadID();
- if (type == NID::kEnd)
- break;
- if (type == NID::kCRC)
- {
- ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);
- continue;
- }
- SkeepData();
- }
- if (packCRCsDefined.IsEmpty())
- {
- BoolVector_Fill_False(packCRCsDefined, numPackStreams);
- packCRCs.Reserve(numPackStreams);
- packCRCs.Clear();
- for (CNum i = 0; i < numPackStreams; i++)
- packCRCs.Add(0);
- }
-}
-
-void CInArchive::ReadUnpackInfo(
- const CObjectVector *dataVector,
- CObjectVector &folders)
-{
- WaitAttribute(NID::kFolder);
- CNum numFolders = ReadNum();
-
- {
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, dataVector);
- folders.Clear();
- folders.Reserve(numFolders);
- for (CNum i = 0; i < numFolders; i++)
- {
- folders.Add(CFolder());
- GetNextFolderItem(folders.Back());
- }
- }
-
- WaitAttribute(NID::kCodersUnpackSize);
-
- CNum i;
- for (i = 0; i < numFolders; i++)
- {
- CFolder &folder = folders[i];
- CNum numOutStreams = folder.GetNumOutStreams();
- folder.UnpackSizes.Reserve(numOutStreams);
- for (CNum j = 0; j < numOutStreams; j++)
- folder.UnpackSizes.Add(ReadNumber());
- }
-
- for (;;)
- {
- UInt64 type = ReadID();
- if (type == NID::kEnd)
- return;
- if (type == NID::kCRC)
- {
- CBoolVector crcsDefined;
- CRecordVector crcs;
- ReadHashDigests(numFolders, crcsDefined, crcs);
- for (i = 0; i < numFolders; i++)
- {
- CFolder &folder = folders[i];
- folder.UnpackCRCDefined = crcsDefined[i];
- folder.UnpackCRC = crcs[i];
- }
- continue;
- }
- SkeepData();
- }
-}
-
-void CInArchive::ReadSubStreamsInfo(
- const CObjectVector &folders,
- CRecordVector &numUnpackStreamsInFolders,
- CRecordVector &unpackSizes,
- CBoolVector &digestsDefined,
- CRecordVector &digests)
-{
- numUnpackStreamsInFolders.Clear();
- numUnpackStreamsInFolders.Reserve(folders.Size());
- UInt64 type;
- for (;;)
- {
- type = ReadID();
- if (type == NID::kNumUnpackStream)
- {
- for (int i = 0; i < folders.Size(); i++)
- numUnpackStreamsInFolders.Add(ReadNum());
- continue;
- }
- if (type == NID::kCRC || type == NID::kSize)
- break;
- if (type == NID::kEnd)
- break;
- SkeepData();
- }
-
- if (numUnpackStreamsInFolders.IsEmpty())
- for (int i = 0; i < folders.Size(); i++)
- numUnpackStreamsInFolders.Add(1);
-
- int i;
- for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)
- {
- // v3.13 incorrectly worked with empty folders
- // v4.07: we check that folder is empty
- CNum numSubstreams = numUnpackStreamsInFolders[i];
- if (numSubstreams == 0)
- continue;
- UInt64 sum = 0;
- for (CNum j = 1; j < numSubstreams; j++)
- if (type == NID::kSize)
- {
- UInt64 size = ReadNumber();
- unpackSizes.Add(size);
- sum += size;
- }
- unpackSizes.Add(folders[i].GetUnpackSize() - sum);
- }
- if (type == NID::kSize)
- type = ReadID();
-
- int numDigests = 0;
- int numDigestsTotal = 0;
- for (i = 0; i < folders.Size(); i++)
- {
- CNum numSubstreams = numUnpackStreamsInFolders[i];
- if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)
- numDigests += numSubstreams;
- numDigestsTotal += numSubstreams;
- }
-
- for (;;)
- {
- if (type == NID::kCRC)
- {
- CBoolVector digestsDefined2;
- CRecordVector digests2;
- ReadHashDigests(numDigests, digestsDefined2, digests2);
- int digestIndex = 0;
- for (i = 0; i < folders.Size(); i++)
- {
- CNum numSubstreams = numUnpackStreamsInFolders[i];
- const CFolder &folder = folders[i];
- if (numSubstreams == 1 && folder.UnpackCRCDefined)
- {
- digestsDefined.Add(true);
- digests.Add(folder.UnpackCRC);
- }
- else
- for (CNum j = 0; j < numSubstreams; j++, digestIndex++)
- {
- digestsDefined.Add(digestsDefined2[digestIndex]);
- digests.Add(digests2[digestIndex]);
- }
- }
- }
- else if (type == NID::kEnd)
- {
- if (digestsDefined.IsEmpty())
- {
- BoolVector_Fill_False(digestsDefined, numDigestsTotal);
- digests.Clear();
- for (int i = 0; i < numDigestsTotal; i++)
- digests.Add(0);
- }
- return;
- }
- else
- SkeepData();
- type = ReadID();
- }
-}
-
-void CInArchive::ReadStreamsInfo(
- const CObjectVector *dataVector,
- UInt64 &dataOffset,
- CRecordVector &packSizes,
- CBoolVector &packCRCsDefined,
- CRecordVector &packCRCs,
- CObjectVector &folders,
- CRecordVector &numUnpackStreamsInFolders,
- CRecordVector &unpackSizes,
- CBoolVector &digestsDefined,
- CRecordVector &digests)
-{
- for (;;)
- {
- UInt64 type = ReadID();
- if (type > ((UInt32)1 << 30))
- ThrowIncorrect();
- switch((UInt32)type)
- {
- case NID::kEnd:
- return;
- case NID::kPackInfo:
- {
- ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);
- break;
- }
- case NID::kUnpackInfo:
- {
- ReadUnpackInfo(dataVector, folders);
- break;
- }
- case NID::kSubStreamsInfo:
- {
- ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,
- unpackSizes, digestsDefined, digests);
- break;
- }
- default:
- ThrowIncorrect();
- }
- }
-}
-
-void CInArchive::ReadBoolVector(int numItems, CBoolVector &v)
-{
- v.Clear();
- v.Reserve(numItems);
- Byte b = 0;
- Byte mask = 0;
- for (int i = 0; i < numItems; i++)
- {
- if (mask == 0)
- {
- b = ReadByte();
- mask = 0x80;
- }
- v.Add((b & mask) != 0);
- mask >>= 1;
- }
-}
-
-void CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)
-{
- Byte allAreDefined = ReadByte();
- if (allAreDefined == 0)
- {
- ReadBoolVector(numItems, v);
- return;
- }
- v.Clear();
- v.Reserve(numItems);
- for (int i = 0; i < numItems; i++)
- v.Add(true);
-}
-
-void CInArchive::ReadUInt64DefVector(const CObjectVector &dataVector,
- CUInt64DefVector &v, int numFiles)
-{
- ReadBoolVector2(numFiles, v.Defined);
-
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, &dataVector);
- v.Values.Reserve(numFiles);
-
- for (int i = 0; i < numFiles; i++)
- {
- UInt64 t = 0;
- if (v.Defined[i])
- t = ReadUInt64();
- v.Values.Add(t);
- }
-}
-
-HRESULT CInArchive::ReadAndDecodePackedStreams(
- DECL_EXTERNAL_CODECS_LOC_VARS
- UInt64 baseOffset,
- UInt64 &dataOffset, CObjectVector &dataVector
- #ifndef _NO_CRYPTO
- , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- )
-{
- CRecordVector packSizes;
- CBoolVector packCRCsDefined;
- CRecordVector packCRCs;
- CObjectVector folders;
-
- CRecordVector numUnpackStreamsInFolders;
- CRecordVector unpackSizes;
- CBoolVector digestsDefined;
- CRecordVector digests;
-
- ReadStreamsInfo(NULL,
- dataOffset,
- packSizes,
- packCRCsDefined,
- packCRCs,
- folders,
- numUnpackStreamsInFolders,
- unpackSizes,
- digestsDefined,
- digests);
-
- // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;
-
- CNum packIndex = 0;
- CDecoder decoder(
- #ifdef _ST_MODE
- false
- #else
- true
- #endif
- );
- UInt64 dataStartPos = baseOffset + dataOffset;
- for (int i = 0; i < folders.Size(); i++)
- {
- const CFolder &folder = folders[i];
- dataVector.Add(CByteBuffer());
- CByteBuffer &data = dataVector.Back();
- UInt64 unpackSize64 = folder.GetUnpackSize();
- size_t unpackSize = (size_t)unpackSize64;
- if (unpackSize != unpackSize64)
- ThrowUnsupported();
- data.SetCapacity(unpackSize);
-
- CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;
- CMyComPtr outStream = outStreamSpec;
- outStreamSpec->Init(data, unpackSize);
-
- HRESULT result = decoder.Decode(
- EXTERNAL_CODECS_LOC_VARS
- _stream, dataStartPos,
- &packSizes[packIndex], folder, outStream, NULL
- #ifndef _NO_CRYPTO
- , getTextPassword, passwordIsDefined
- #endif
- #ifdef COMPRESS_MT
- , false, 1
- #endif
- );
- RINOK(result);
-
- if (folder.UnpackCRCDefined)
- if (CrcCalc(data, unpackSize) != folder.UnpackCRC)
- ThrowIncorrect();
- for (int j = 0; j < folder.PackStreams.Size(); j++)
- {
- UInt64 packSize = packSizes[packIndex++];
- dataStartPos += packSize;
- HeadersSize += packSize;
- }
- }
- return S_OK;
-}
-
-HRESULT CInArchive::ReadHeader(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CArchiveDatabaseEx &db
- #ifndef _NO_CRYPTO
- , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- )
-{
- UInt64 type = ReadID();
-
- if (type == NID::kArchiveProperties)
- {
- ReadArchiveProperties(db.ArchiveInfo);
- type = ReadID();
- }
-
- CObjectVector dataVector;
-
- if (type == NID::kAdditionalStreamsInfo)
- {
- HRESULT result = ReadAndDecodePackedStreams(
- EXTERNAL_CODECS_LOC_VARS
- db.ArchiveInfo.StartPositionAfterHeader,
- db.ArchiveInfo.DataStartPosition2,
- dataVector
- #ifndef _NO_CRYPTO
- , getTextPassword, passwordIsDefined
- #endif
- );
- RINOK(result);
- db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;
- type = ReadID();
- }
-
- CRecordVector unpackSizes;
- CBoolVector digestsDefined;
- CRecordVector digests;
-
- if (type == NID::kMainStreamsInfo)
- {
- ReadStreamsInfo(&dataVector,
- db.ArchiveInfo.DataStartPosition,
- db.PackSizes,
- db.PackCRCsDefined,
- db.PackCRCs,
- db.Folders,
- db.NumUnpackStreamsVector,
- unpackSizes,
- digestsDefined,
- digests);
- db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;
- type = ReadID();
- }
- else
- {
- for (int i = 0; i < db.Folders.Size(); i++)
- {
- db.NumUnpackStreamsVector.Add(1);
- CFolder &folder = db.Folders[i];
- unpackSizes.Add(folder.GetUnpackSize());
- digestsDefined.Add(folder.UnpackCRCDefined);
- digests.Add(folder.UnpackCRC);
- }
- }
-
- db.Files.Clear();
-
- if (type == NID::kEnd)
- return S_OK;
- if (type != NID::kFilesInfo)
- ThrowIncorrect();
-
- CNum numFiles = ReadNum();
- db.Files.Reserve(numFiles);
- CNum i;
- for (i = 0; i < numFiles; i++)
- db.Files.Add(CFileItem());
-
- db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);
- if (!db.PackSizes.IsEmpty())
- db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);
- if (numFiles > 0 && !digests.IsEmpty())
- db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);
-
- CBoolVector emptyStreamVector;
- BoolVector_Fill_False(emptyStreamVector, (int)numFiles);
- CBoolVector emptyFileVector;
- CBoolVector antiFileVector;
- CNum numEmptyStreams = 0;
-
- for (;;)
- {
- UInt64 type = ReadID();
- if (type == NID::kEnd)
- break;
- UInt64 size = ReadNumber();
- size_t ppp = _inByteBack->_pos;
- bool addPropIdToList = true;
- bool isKnownType = true;
- if (type > ((UInt32)1 << 30))
- isKnownType = false;
- else switch((UInt32)type)
- {
- case NID::kName:
- {
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, &dataVector);
- for (int i = 0; i < db.Files.Size(); i++)
- _inByteBack->ReadString(db.Files[i].Name);
- break;
- }
- case NID::kWinAttributes:
- {
- CBoolVector boolVector;
- ReadBoolVector2(db.Files.Size(), boolVector);
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, &dataVector);
- for (i = 0; i < numFiles; i++)
- {
- CFileItem &file = db.Files[i];
- file.AttribDefined = boolVector[i];
- if (file.AttribDefined)
- file.Attrib = ReadUInt32();
- }
- break;
- }
- case NID::kEmptyStream:
- {
- ReadBoolVector(numFiles, emptyStreamVector);
- for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)
- if (emptyStreamVector[i])
- numEmptyStreams++;
-
- BoolVector_Fill_False(emptyFileVector, numEmptyStreams);
- BoolVector_Fill_False(antiFileVector, numEmptyStreams);
-
- break;
- }
- case NID::kEmptyFile: ReadBoolVector(numEmptyStreams, emptyFileVector); break;
- case NID::kAnti: ReadBoolVector(numEmptyStreams, antiFileVector); break;
- case NID::kStartPos: ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;
- case NID::kCTime: ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;
- case NID::kATime: ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;
- case NID::kMTime: ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;
- case NID::kDummy:
- {
- for (UInt64 j = 0; j < size; j++)
- if (ReadByte() != 0)
- ThrowIncorrect();
- addPropIdToList = false;
- break;
- }
- default:
- addPropIdToList = isKnownType = false;
- }
- if (isKnownType)
- {
- if(addPropIdToList)
- db.ArchiveInfo.FileInfoPopIDs.Add(type);
- }
- else
- SkeepData(size);
- bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||
- db.ArchiveInfo.Version.Minor > 2);
- if (checkRecordsSize && _inByteBack->_pos - ppp != size)
- ThrowIncorrect();
- }
-
- CNum emptyFileIndex = 0;
- CNum sizeIndex = 0;
-
- CNum numAntiItems = 0;
- for (i = 0; i < numEmptyStreams; i++)
- if (antiFileVector[i])
- numAntiItems++;
-
- for (i = 0; i < numFiles; i++)
- {
- CFileItem &file = db.Files[i];
- bool isAnti;
- file.HasStream = !emptyStreamVector[i];
- if (file.HasStream)
- {
- file.IsDir = false;
- isAnti = false;
- file.Size = unpackSizes[sizeIndex];
- file.Crc = digests[sizeIndex];
- file.CrcDefined = digestsDefined[sizeIndex];
- sizeIndex++;
- }
- else
- {
- file.IsDir = !emptyFileVector[emptyFileIndex];
- isAnti = antiFileVector[emptyFileIndex];
- emptyFileIndex++;
- file.Size = 0;
- file.CrcDefined = false;
- }
- if (numAntiItems != 0)
- db.IsAnti.Add(isAnti);
- }
- return S_OK;
-}
-
-
-void CArchiveDatabaseEx::FillFolderStartPackStream()
-{
- FolderStartPackStreamIndex.Clear();
- FolderStartPackStreamIndex.Reserve(Folders.Size());
- CNum startPos = 0;
- for (int i = 0; i < Folders.Size(); i++)
- {
- FolderStartPackStreamIndex.Add(startPos);
- startPos += (CNum)Folders[i].PackStreams.Size();
- }
-}
-
-void CArchiveDatabaseEx::FillStartPos()
-{
- PackStreamStartPositions.Clear();
- PackStreamStartPositions.Reserve(PackSizes.Size());
- UInt64 startPos = 0;
- for (int i = 0; i < PackSizes.Size(); i++)
- {
- PackStreamStartPositions.Add(startPos);
- startPos += PackSizes[i];
- }
-}
-
-void CArchiveDatabaseEx::FillFolderStartFileIndex()
-{
- FolderStartFileIndex.Clear();
- FolderStartFileIndex.Reserve(Folders.Size());
- FileIndexToFolderIndexMap.Clear();
- FileIndexToFolderIndexMap.Reserve(Files.Size());
-
- int folderIndex = 0;
- CNum indexInFolder = 0;
- for (int i = 0; i < Files.Size(); i++)
- {
- const CFileItem &file = Files[i];
- bool emptyStream = !file.HasStream;
- if (emptyStream && indexInFolder == 0)
- {
- FileIndexToFolderIndexMap.Add(kNumNoIndex);
- continue;
- }
- if (indexInFolder == 0)
- {
- // v3.13 incorrectly worked with empty folders
- // v4.07: Loop for skipping empty folders
- for (;;)
- {
- if (folderIndex >= Folders.Size())
- ThrowIncorrect();
- FolderStartFileIndex.Add(i); // check it
- if (NumUnpackStreamsVector[folderIndex] != 0)
- break;
- folderIndex++;
- }
- }
- FileIndexToFolderIndexMap.Add(folderIndex);
- if (emptyStream)
- continue;
- indexInFolder++;
- if (indexInFolder >= NumUnpackStreamsVector[folderIndex])
- {
- folderIndex++;
- indexInFolder = 0;
- }
- }
-}
-
-HRESULT CInArchive::ReadDatabase2(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CArchiveDatabaseEx &db
- #ifndef _NO_CRYPTO
- , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- )
-{
- db.Clear();
- db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
-
- db.ArchiveInfo.Version.Major = _header[6];
- db.ArchiveInfo.Version.Minor = _header[7];
-
- if (db.ArchiveInfo.Version.Major != kMajorVersion)
- ThrowUnsupportedVersion();
-
- UInt32 crcFromArchive = Get32(_header + 8);
- UInt64 nextHeaderOffset = Get64(_header + 0xC);
- UInt64 nextHeaderSize = Get64(_header + 0x14);
- UInt32 nextHeaderCRC = Get32(_header + 0x1C);
- UInt32 crc = CrcCalc(_header + 0xC, 20);
-
- #ifdef FORMAT_7Z_RECOVERY
- if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)
- {
- UInt64 cur, cur2;
- RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));
- const int kCheckSize = 500;
- Byte buf[kCheckSize];
- RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));
- int checkSize = kCheckSize;
- if (cur2 - cur < kCheckSize)
- checkSize = (int)(cur2 - cur);
- RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));
-
- RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));
-
- int i;
- for (i = (int)checkSize - 2; i >= 0; i--)
- if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)
- break;
- if (i < 0)
- return S_FALSE;
- nextHeaderSize = checkSize - i;
- nextHeaderOffset = cur2 - cur + i;
- nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);
- RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));
- }
- #endif
-
- #ifdef FORMAT_7Z_RECOVERY
- crcFromArchive = crc;
- #endif
-
- db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;
-
- if (crc != crcFromArchive)
- ThrowIncorrect();
-
- if (nextHeaderSize == 0)
- return S_OK;
-
- if (nextHeaderSize > (UInt64)0xFFFFFFFF)
- return S_FALSE;
-
- RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));
-
- CByteBuffer buffer2;
- buffer2.SetCapacity((size_t)nextHeaderSize);
-
- RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));
- HeadersSize += kHeaderSize + nextHeaderSize;
- db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;
-
- if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)
- ThrowIncorrect();
-
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, buffer2);
-
- CObjectVector dataVector;
-
- UInt64 type = ReadID();
- if (type != NID::kHeader)
- {
- if (type != NID::kEncodedHeader)
- ThrowIncorrect();
- HRESULT result = ReadAndDecodePackedStreams(
- EXTERNAL_CODECS_LOC_VARS
- db.ArchiveInfo.StartPositionAfterHeader,
- db.ArchiveInfo.DataStartPosition2,
- dataVector
- #ifndef _NO_CRYPTO
- , getTextPassword, passwordIsDefined
- #endif
- );
- RINOK(result);
- if (dataVector.Size() == 0)
- return S_OK;
- if (dataVector.Size() > 1)
- ThrowIncorrect();
- streamSwitch.Remove();
- streamSwitch.Set(this, dataVector.Front());
- if (ReadID() != NID::kHeader)
- ThrowIncorrect();
- }
-
- db.HeadersSize = HeadersSize;
-
- return ReadHeader(
- EXTERNAL_CODECS_LOC_VARS
- db
- #ifndef _NO_CRYPTO
- , getTextPassword, passwordIsDefined
- #endif
- );
-}
-
-HRESULT CInArchive::ReadDatabase(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CArchiveDatabaseEx &db
- #ifndef _NO_CRYPTO
- , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- )
-{
- try
- {
- return ReadDatabase2(
- EXTERNAL_CODECS_LOC_VARS db
- #ifndef _NO_CRYPTO
- , getTextPassword, passwordIsDefined
- #endif
- );
- }
- catch(CInArchiveException &) { return S_FALSE; }
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zIn.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zIn.h
deleted file mode 100644
index bfec78564..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zIn.h
+++ /dev/null
@@ -1,245 +0,0 @@
-// 7zIn.h
-
-#ifndef __7Z_IN_H
-#define __7Z_IN_H
-
-#include "../../../Common/MyCom.h"
-
-#include "../../IPassword.h"
-#include "../../IStream.h"
-
-#include "../../Common/CreateCoder.h"
-#include "../../Common/InBuffer.h"
-
-#include "7zItem.h"
-
-namespace NArchive {
-namespace N7z {
-
-struct CInArchiveInfo
-{
- CArchiveVersion Version;
- UInt64 StartPosition;
- UInt64 StartPositionAfterHeader;
- UInt64 DataStartPosition;
- UInt64 DataStartPosition2;
- CRecordVector FileInfoPopIDs;
- void Clear()
- {
- FileInfoPopIDs.Clear();
- }
-};
-
-struct CArchiveDatabaseEx: public CArchiveDatabase
-{
- CInArchiveInfo ArchiveInfo;
- CRecordVector PackStreamStartPositions;
- CRecordVector FolderStartPackStreamIndex;
- CRecordVector FolderStartFileIndex;
- CRecordVector FileIndexToFolderIndexMap;
-
- UInt64 HeadersSize;
- UInt64 PhySize;
-
- void Clear()
- {
- CArchiveDatabase::Clear();
- ArchiveInfo.Clear();
- PackStreamStartPositions.Clear();
- FolderStartPackStreamIndex.Clear();
- FolderStartFileIndex.Clear();
- FileIndexToFolderIndexMap.Clear();
-
- HeadersSize = 0;
- PhySize = 0;
- }
-
- void FillFolderStartPackStream();
- void FillStartPos();
- void FillFolderStartFileIndex();
-
- void Fill()
- {
- FillFolderStartPackStream();
- FillStartPos();
- FillFolderStartFileIndex();
- }
-
- UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
- {
- return ArchiveInfo.DataStartPosition +
- PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];
- }
-
- UInt64 GetFolderFullPackSize(int folderIndex) const
- {
- CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];
- const CFolder &folder = Folders[folderIndex];
- UInt64 size = 0;
- for (int i = 0; i < folder.PackStreams.Size(); i++)
- size += PackSizes[packStreamIndex + i];
- return size;
- }
-
- UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
- {
- return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
- }
-
- UInt64 GetFilePackSize(CNum fileIndex) const
- {
- CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
- if (folderIndex != kNumNoIndex)
- if (FolderStartFileIndex[folderIndex] == fileIndex)
- return GetFolderFullPackSize(folderIndex);
- return 0;
- }
-};
-
-class CInByte2
-{
- const Byte *_buffer;
- size_t _size;
-public:
- size_t _pos;
- void Init(const Byte *buffer, size_t size)
- {
- _buffer = buffer;
- _size = size;
- _pos = 0;
- }
- Byte ReadByte();
- void ReadBytes(Byte *data, size_t size);
- void SkeepData(UInt64 size);
- void SkeepData();
- UInt64 ReadNumber();
- CNum ReadNum();
- UInt32 ReadUInt32();
- UInt64 ReadUInt64();
- void ReadString(UString &s);
-};
-
-class CStreamSwitch;
-
-const UInt32 kHeaderSize = 32;
-
-class CInArchive
-{
- friend class CStreamSwitch;
-
- CMyComPtr _stream;
-
- CObjectVector _inByteVector;
- CInByte2 *_inByteBack;
-
- UInt64 _arhiveBeginStreamPosition;
-
- Byte _header[kHeaderSize];
-
- UInt64 HeadersSize;
-
- void AddByteStream(const Byte *buffer, size_t size)
- {
- _inByteVector.Add(CInByte2());
- _inByteBack = &_inByteVector.Back();
- _inByteBack->Init(buffer, size);
- }
-
- void DeleteByteStream()
- {
- _inByteVector.DeleteBack();
- if (!_inByteVector.IsEmpty())
- _inByteBack = &_inByteVector.Back();
- }
-
-private:
- HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
-
- void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }
- Byte ReadByte() { return _inByteBack->ReadByte(); }
- UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }
- CNum ReadNum() { return _inByteBack->ReadNum(); }
- UInt64 ReadID() { return _inByteBack->ReadNumber(); }
- UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }
- UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }
- void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }
- void SkeepData() { _inByteBack->SkeepData(); }
- void WaitAttribute(UInt64 attribute);
-
- void ReadArchiveProperties(CInArchiveInfo &archiveInfo);
- void GetNextFolderItem(CFolder &itemInfo);
- void ReadHashDigests(int numItems,
- CBoolVector &digestsDefined, CRecordVector &digests);
-
- void ReadPackInfo(
- UInt64 &dataOffset,
- CRecordVector &packSizes,
- CBoolVector &packCRCsDefined,
- CRecordVector &packCRCs);
-
- void ReadUnpackInfo(
- const CObjectVector *dataVector,
- CObjectVector &folders);
-
- void ReadSubStreamsInfo(
- const CObjectVector &folders,
- CRecordVector &numUnpackStreamsInFolders,
- CRecordVector &unpackSizes,
- CBoolVector &digestsDefined,
- CRecordVector &digests);
-
- void ReadStreamsInfo(
- const CObjectVector *dataVector,
- UInt64 &dataOffset,
- CRecordVector &packSizes,
- CBoolVector &packCRCsDefined,
- CRecordVector &packCRCs,
- CObjectVector &folders,
- CRecordVector &numUnpackStreamsInFolders,
- CRecordVector &unpackSizes,
- CBoolVector &digestsDefined,
- CRecordVector &digests);
-
-
- void ReadBoolVector(int numItems, CBoolVector &v);
- void ReadBoolVector2(int numItems, CBoolVector &v);
- void ReadUInt64DefVector(const CObjectVector &dataVector,
- CUInt64DefVector &v, int numFiles);
- HRESULT ReadAndDecodePackedStreams(
- DECL_EXTERNAL_CODECS_LOC_VARS
- UInt64 baseOffset, UInt64 &dataOffset,
- CObjectVector &dataVector
- #ifndef _NO_CRYPTO
- , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- );
- HRESULT ReadHeader(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CArchiveDatabaseEx &db
- #ifndef _NO_CRYPTO
- ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- );
- HRESULT ReadDatabase2(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CArchiveDatabaseEx &db
- #ifndef _NO_CRYPTO
- ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- );
-public:
- HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
- void Close();
-
- HRESULT ReadDatabase(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CArchiveDatabaseEx &db
- #ifndef _NO_CRYPTO
- ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
- #endif
- );
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zItem.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zItem.h
deleted file mode 100644
index 6cc9ccc55..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zItem.h
+++ /dev/null
@@ -1,258 +0,0 @@
-// 7zItem.h
-
-#ifndef __7Z_ITEM_H
-#define __7Z_ITEM_H
-
-#include "../../../Common/Buffer.h"
-#include "../../../Common/MyString.h"
-
-#include "../../Common/MethodId.h"
-
-#include "7zHeader.h"
-
-namespace NArchive {
-namespace N7z {
-
-typedef UInt32 CNum;
-const CNum kNumMax = 0x7FFFFFFF;
-const CNum kNumNoIndex = 0xFFFFFFFF;
-
-struct CCoderInfo
-{
- CMethodId MethodID;
- CByteBuffer Props;
- CNum NumInStreams;
- CNum NumOutStreams;
- bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
-};
-
-struct CBindPair
-{
- CNum InIndex;
- CNum OutIndex;
-};
-
-struct CFolder
-{
- CObjectVector Coders;
- CRecordVector BindPairs;
- CRecordVector PackStreams;
- CRecordVector UnpackSizes;
- UInt32 UnpackCRC;
- bool UnpackCRCDefined;
-
- CFolder(): UnpackCRCDefined(false) {}
-
- UInt64 GetUnpackSize() const // test it
- {
- if (UnpackSizes.IsEmpty())
- return 0;
- for (int i = UnpackSizes.Size() - 1; i >= 0; i--)
- if (FindBindPairForOutStream(i) < 0)
- return UnpackSizes[i];
- throw 1;
- }
-
- CNum GetNumOutStreams() const
- {
- CNum result = 0;
- for (int i = 0; i < Coders.Size(); i++)
- result += Coders[i].NumOutStreams;
- return result;
- }
-
- int FindBindPairForInStream(CNum inStreamIndex) const
- {
- for(int i = 0; i < BindPairs.Size(); i++)
- if (BindPairs[i].InIndex == inStreamIndex)
- return i;
- return -1;
- }
- int FindBindPairForOutStream(CNum outStreamIndex) const
- {
- for(int i = 0; i < BindPairs.Size(); i++)
- if (BindPairs[i].OutIndex == outStreamIndex)
- return i;
- return -1;
- }
- int FindPackStreamArrayIndex(CNum inStreamIndex) const
- {
- for(int i = 0; i < PackStreams.Size(); i++)
- if (PackStreams[i] == inStreamIndex)
- return i;
- return -1;
- }
-
- bool CheckStructure() const;
-};
-
-struct CUInt64DefVector
-{
- CRecordVector Values;
- CRecordVector Defined;
-
- void Clear()
- {
- Values.Clear();
- Defined.Clear();
- }
-
- void ReserveDown()
- {
- Values.ReserveDown();
- Values.ReserveDown();
- }
-
- bool GetItem(int index, UInt64 &value) const
- {
- if (index < Defined.Size() && Defined[index])
- {
- value = Values[index];
- return true;
- }
- value = 0;
- return false;
- }
-
- void SetItem(int index, bool defined, UInt64 value)
- {
- while (index >= Defined.Size())
- Defined.Add(false);
- Defined[index] = defined;
- if (!defined)
- return;
- while (index >= Values.Size())
- Values.Add(0);
- Values[index] = value;
- }
-
- bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }
-};
-
-struct CFileItem
-{
- UInt64 Size;
- UInt32 Attrib;
- UInt32 Crc;
- UString Name;
-
- bool HasStream; // Test it !!! it means that there is
- // stream in some folder. It can be empty stream
- bool IsDir;
- bool CrcDefined;
- bool AttribDefined;
-
- CFileItem():
- HasStream(true),
- IsDir(false),
- CrcDefined(false),
- AttribDefined(false)
- {}
- void SetAttrib(UInt32 attrib)
- {
- AttribDefined = true;
- Attrib = attrib;
- }
-};
-
-struct CFileItem2
-{
- UInt64 CTime;
- UInt64 ATime;
- UInt64 MTime;
- UInt64 StartPos;
- bool CTimeDefined;
- bool ATimeDefined;
- bool MTimeDefined;
- bool StartPosDefined;
- bool IsAnti;
-};
-
-struct CArchiveDatabase
-{
- CRecordVector PackSizes;
- CRecordVector PackCRCsDefined;
- CRecordVector PackCRCs;
- CObjectVector Folders;
- CRecordVector NumUnpackStreamsVector;
- CObjectVector Files;
-
- CUInt64DefVector CTime;
- CUInt64DefVector ATime;
- CUInt64DefVector MTime;
- CUInt64DefVector StartPos;
- CRecordVector IsAnti;
-
- void Clear()
- {
- PackSizes.Clear();
- PackCRCsDefined.Clear();
- PackCRCs.Clear();
- Folders.Clear();
- NumUnpackStreamsVector.Clear();
- Files.Clear();
- CTime.Clear();
- ATime.Clear();
- MTime.Clear();
- StartPos.Clear();
- IsAnti.Clear();
- }
-
- void ReserveDown()
- {
- PackSizes.ReserveDown();
- PackCRCsDefined.ReserveDown();
- PackCRCs.ReserveDown();
- Folders.ReserveDown();
- NumUnpackStreamsVector.ReserveDown();
- Files.ReserveDown();
- CTime.ReserveDown();
- ATime.ReserveDown();
- MTime.ReserveDown();
- StartPos.ReserveDown();
- IsAnti.ReserveDown();
- }
-
- bool IsEmpty() const
- {
- return (PackSizes.IsEmpty() &&
- PackCRCsDefined.IsEmpty() &&
- PackCRCs.IsEmpty() &&
- Folders.IsEmpty() &&
- NumUnpackStreamsVector.IsEmpty() &&
- Files.IsEmpty());
- }
-
- bool CheckNumFiles() const
- {
- int size = Files.Size();
- return (
- CTime.CheckSize(size) &&
- ATime.CheckSize(size) &&
- MTime.CheckSize(size) &&
- StartPos.CheckSize(size) &&
- (size == IsAnti.Size() || IsAnti.Size() == 0));
- }
-
- bool IsSolid() const
- {
- for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)
- if (NumUnpackStreamsVector[i] > 1)
- return true;
- return false;
- }
- bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }
- void SetItemAnti(int index, bool isAnti)
- {
- while (index >= IsAnti.Size())
- IsAnti.Add(false);
- IsAnti[index] = isAnti;
- }
-
- void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;
- void AddFile(const CFileItem &file, const CFileItem2 &file2);
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zProperties.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zProperties.cpp
deleted file mode 100644
index f5ac3b9bf..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zProperties.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-// 7zProperties.cpp
-
-#include "StdAfx.h"
-
-#include "7zProperties.h"
-#include "7zHeader.h"
-#include "7zHandler.h"
-
-// #define _MULTI_PACK
-
-namespace NArchive {
-namespace N7z {
-
-struct CPropMap
-{
- UInt64 FilePropID;
- STATPROPSTG StatPROPSTG;
-};
-
-CPropMap kPropMap[] =
-{
- { NID::kName, NULL, kpidPath, VT_BSTR},
- { NID::kSize, NULL, kpidSize, VT_UI8},
- { NID::kPackInfo, NULL, kpidPackSize, VT_UI8},
-
- #ifdef _MULTI_PACK
- { 100, L"Pack0", kpidPackedSize0, VT_UI8},
- { 101, L"Pack1", kpidPackedSize1, VT_UI8},
- { 102, L"Pack2", kpidPackedSize2, VT_UI8},
- { 103, L"Pack3", kpidPackedSize3, VT_UI8},
- { 104, L"Pack4", kpidPackedSize4, VT_UI8},
- #endif
-
- { NID::kCTime, NULL, kpidCTime, VT_FILETIME},
- { NID::kMTime, NULL, kpidMTime, VT_FILETIME},
- { NID::kATime, NULL, kpidATime, VT_FILETIME},
- { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},
- { NID::kStartPos, NULL, kpidPosition, VT_UI4},
-
- { NID::kCRC, NULL, kpidCRC, VT_UI4},
-
- { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},
-
- #ifndef _SFX
- { 97, NULL, kpidEncrypted, VT_BOOL},
- { 98, NULL, kpidMethod, VT_BSTR},
- { 99, NULL, kpidBlock, VT_UI4}
- #endif
-};
-
-static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
-
-static int FindPropInMap(UInt64 filePropID)
-{
- for (int i = 0; i < kPropMapSize; i++)
- if (kPropMap[i].FilePropID == filePropID)
- return i;
- return -1;
-}
-
-static void CopyOneItem(CRecordVector &src,
- CRecordVector &dest, UInt32 item)
-{
- for (int i = 0; i < src.Size(); i++)
- if (src[i] == item)
- {
- dest.Add(item);
- src.Delete(i);
- return;
- }
-}
-
-static void RemoveOneItem(CRecordVector &src, UInt32 item)
-{
- for (int i = 0; i < src.Size(); i++)
- if (src[i] == item)
- {
- src.Delete(i);
- return;
- }
-}
-
-static void InsertToHead(CRecordVector &dest, UInt32 item)
-{
- for (int i = 0; i < dest.Size(); i++)
- if (dest[i] == item)
- {
- dest.Delete(i);
- break;
- }
- dest.Insert(0, item);
-}
-
-void CHandler::FillPopIDs()
-{
- _fileInfoPopIDs.Clear();
-
- #ifdef _7Z_VOL
- if(_volumes.Size() < 1)
- return;
- const CVolume &volume = _volumes.Front();
- const CArchiveDatabaseEx &_db = volume.Database;
- #endif
-
- CRecordVector fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;
-
- RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
- RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
-
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
- CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
- _fileInfoPopIDs += fileInfoPopIDs;
-
- #ifndef _SFX
- _fileInfoPopIDs.Add(97);
- _fileInfoPopIDs.Add(98);
- _fileInfoPopIDs.Add(99);
- #endif
- #ifdef _MULTI_PACK
- _fileInfoPopIDs.Add(100);
- _fileInfoPopIDs.Add(101);
- _fileInfoPopIDs.Add(102);
- _fileInfoPopIDs.Add(103);
- _fileInfoPopIDs.Add(104);
- #endif
-
- #ifndef _SFX
- InsertToHead(_fileInfoPopIDs, NID::kMTime);
- InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
- InsertToHead(_fileInfoPopIDs, NID::kSize);
- InsertToHead(_fileInfoPopIDs, NID::kName);
- #endif
-}
-
-STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
-{
- *numProperties = _fileInfoPopIDs.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
-{
- if ((int)index >= _fileInfoPopIDs.Size())
- return E_INVALIDARG;
- int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
- if (indexInMap == -1)
- return E_INVALIDARG;
- const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
- *propID = srcItem.propid;
- *varType = srcItem.vt;
- *name = 0;
- return S_OK;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zProperties.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zProperties.h
deleted file mode 100644
index 7b78130ef..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zProperties.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// 7zProperties.h
-
-#ifndef __7Z_PROPERTIES_H
-#define __7Z_PROPERTIES_H
-
-#include "../../PropID.h"
-
-namespace NArchive {
-namespace N7z {
-
-enum
-{
- kpidPackedSize0 = kpidUserDefined,
- kpidPackedSize1,
- kpidPackedSize2,
- kpidPackedSize3,
- kpidPackedSize4
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zRegister.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zRegister.cpp
deleted file mode 100644
index 4450498f0..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zRegister.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// 7zRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "7zHandler.h"
-static IInArchive *CreateArc() { return new NArchive::N7z::CHandler; }
-#ifndef EXTRACT_ONLY
-static IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler; }
-#else
-#define CreateArcOut 0
-#endif
-
-static CArcInfo g_ArcInfo =
- { L"7z", L"7z", 0, 7, {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };
-
-REGISTER_ARC(7z)
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zSpecStream.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zSpecStream.cpp
deleted file mode 100644
index 58f2ec459..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zSpecStream.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// 7zSpecStream.cpp
-
-#include "StdAfx.h"
-
-#include "7zSpecStream.h"
-
-STDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize;
- HRESULT result = _stream->Read(data, size, &realProcessedSize);
- _size += realProcessedSize;
- if (processedSize != 0)
- *processedSize = realProcessedSize;
- return result;
-}
-
-STDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(
- UInt64 subStream, UInt64 *value)
-{
- if (_getSubStreamSize == NULL)
- return E_NOTIMPL;
- return _getSubStreamSize->GetSubStreamSize(subStream, value);
-}
-
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zSpecStream.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zSpecStream.h
deleted file mode 100644
index 0058ac27c..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/7zSpecStream.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// 7zSpecStream.h
-
-#ifndef __7Z_SPEC_STREAM_H
-#define __7Z_SPEC_STREAM_H
-
-#include "../../IStream.h"
-#include "../../ICoder.h"
-#include "../../../Common/MyCom.h"
-
-class CSequentialInStreamSizeCount2:
- public ISequentialInStream,
- public ICompressGetSubStreamSize,
- public CMyUnknownImp
-{
- CMyComPtr _stream;
- CMyComPtr _getSubStreamSize;
- UInt64 _size;
-public:
- void Init(ISequentialInStream *stream)
- {
- _stream = stream;
- _getSubStreamSize = 0;
- _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);
- _size = 0;
- }
- UInt64 GetSize() const { return _size; }
-
- MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-
- STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
-};
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/7z/StdAfx.h b/desmume/src/windows/7z/CPP/7zip/Archive/7z/StdAfx.h
deleted file mode 100644
index a4e617312..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/7z/StdAfx.h
+++ /dev/null
@@ -1,9 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-#include "../../../Common/NewHandler.h"
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/ArchiveExports.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/ArchiveExports.cpp
deleted file mode 100644
index 054f1b081..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/ArchiveExports.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-// ArchiveExports.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/ComTry.h"
-#include "../../Common/Types.h"
-#include "../../Windows/PropVariant.h"
-#include "../Common/RegisterArc.h"
-
-#include "IArchive.h"
-#include "../ICoder.h"
-#include "../IPassword.h"
-
-static const unsigned int kNumArcsMax = 32;
-static unsigned int g_NumArcs = 0;
-static const CArcInfo *g_Arcs[kNumArcsMax];
-void RegisterArc(const CArcInfo *arcInfo)
-{
- if (g_NumArcs < kNumArcsMax)
- g_Arcs[g_NumArcs++] = arcInfo;
-}
-
-DEFINE_GUID(CLSID_CArchiveHandler,
-0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);
-
-#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])
-
-static inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)
-{
- if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)
- value->vt = VT_BSTR;
- return S_OK;
-}
-
-static inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)
-{
- return SetPropString((const char *)&guid, sizeof(GUID), value);
-}
-
-int FindFormatCalssId(const GUID *clsID)
-{
- GUID cls = *clsID;
- CLS_ARC_ID_ITEM(cls) = 0;
- if (cls != CLSID_CArchiveHandler)
- return -1;
- Byte id = CLS_ARC_ID_ITEM(*clsID);
- for (unsigned i = 0; i < g_NumArcs; i++)
- if (g_Arcs[i]->ClassId == id)
- return (int)i;
- return -1;
-}
-
-STDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)
-{
- COM_TRY_BEGIN
- {
- int needIn = (*iid == IID_IInArchive);
- int needOut = (*iid == IID_IOutArchive);
- if (!needIn && !needOut)
- return E_NOINTERFACE;
- int formatIndex = FindFormatCalssId(clsid);
- if (formatIndex < 0)
- return CLASS_E_CLASSNOTAVAILABLE;
-
- const CArcInfo &arc = *g_Arcs[formatIndex];
- if (needIn)
- {
- *outObject = arc.CreateInArchive();
- ((IInArchive *)*outObject)->AddRef();
- }
- else
- {
- if (!arc.CreateOutArchive)
- return CLASS_E_CLASSNOTAVAILABLE;
- *outObject = arc.CreateOutArchive();
- ((IOutArchive *)*outObject)->AddRef();
- }
- }
- COM_TRY_END
- return S_OK;
-}
-
-STDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)
-{
- if (formatIndex >= g_NumArcs)
- return E_INVALIDARG;
- const CArcInfo &arc = *g_Arcs[formatIndex];
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case NArchive::kName:
- prop = arc.Name;
- break;
- case NArchive::kClassID:
- {
- GUID clsId = CLSID_CArchiveHandler;
- CLS_ARC_ID_ITEM(clsId) = arc.ClassId;
- return SetPropGUID(clsId, value);
- }
- case NArchive::kExtension:
- if (arc.Ext != 0)
- prop = arc.Ext;
- break;
- case NArchive::kAddExtension:
- if (arc.AddExt != 0)
- prop = arc.AddExt;
- break;
- case NArchive::kUpdate:
- prop = (bool)(arc.CreateOutArchive != 0);
- break;
- case NArchive::kKeepName:
- prop = arc.KeepName;
- break;
- case NArchive::kStartSignature:
- return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);
- }
- prop.Detach(value);
- return S_OK;
-}
-
-STDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)
-{
- return GetHandlerProperty2(0, propID, value);
-}
-
-STDAPI GetNumberOfFormats(UINT32 *numFormats)
-{
- *numFormats = g_NumArcs;
- return S_OK;
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Handler.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Handler.cpp
deleted file mode 100644
index a797b6ddd..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Handler.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-// BZip2Handler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../../Common/CreateCoder.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamUtils.h"
-
-#include "../Common/DummyOutStream.h"
-
-#include "BZip2Handler.h"
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NBZip2 {
-
-static const CMethodId kMethodId_BZip2 = 0x040202;
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPackSize, VT_UI8}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = 1;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
-{
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPackSize: prop = _item.PackSize; break;
- }
- prop.Detach(value);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- try
- {
- RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_streamStartPosition));
- const int kSignatureSize = 3;
- Byte buffer[kSignatureSize];
- RINOK(ReadStream_FALSE(stream, buffer, kSignatureSize));
- if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h')
- return S_FALSE;
-
- UInt64 endPosition;
- RINOK(stream->Seek(0, STREAM_SEEK_END, &endPosition));
- _item.PackSize = endPosition - _streamStartPosition;
-
- _stream = stream;
- }
- catch(...)
- {
- return S_FALSE;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _stream.Release();
- return S_OK;
-}
-
-
-STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
- Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == UInt32(-1));
- if (!allFilesMode)
- {
- if (numItems == 0)
- return S_OK;
- if (numItems != 1)
- return E_INVALIDARG;
- if (indices[0] != 0)
- return E_INVALIDARG;
- }
-
- bool testMode = (testModeSpec != 0);
-
- extractCallback->SetTotal(_item.PackSize);
-
- UInt64 currentTotalPacked = 0;
-
- RINOK(extractCallback->SetCompleted(¤tTotalPacked));
-
- CMyComPtr realOutStream;
- Int32 askMode;
- askMode = testMode ? NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
-
- RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
-
- if(!testMode && !realOutStream)
- return S_OK;
-
-
- extractCallback->PrepareOperation(askMode);
-
- CMyComPtr decoder;
- HRESULT loadResult = CreateCoder(
- EXTERNAL_CODECS_VARS
- kMethodId_BZip2, decoder, false);
- if (loadResult != S_OK || !decoder)
- {
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
- return S_OK;
- }
-
- #ifdef COMPRESS_MT
- {
- CMyComPtr setCoderMt;
- decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
- if (setCoderMt)
- {
- RINOK(setCoderMt->SetNumberOfThreads(_numThreads));
- }
- }
- #endif
-
- CDummyOutStream *outStreamSpec = new CDummyOutStream;
- CMyComPtr outStream(outStreamSpec);
- outStreamSpec->SetStream(realOutStream);
- outStreamSpec->Init();
-
- realOutStream.Release();
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr progress = lps;
- lps->Init(extractCallback, true);
-
- RINOK(_stream->Seek(_streamStartPosition, STREAM_SEEK_SET, NULL));
-
- HRESULT result = S_OK;
-
- bool firstItem = true;
- for (;;)
- {
- lps->InSize = currentTotalPacked;
- lps->OutSize = outStreamSpec->GetSize();
-
- RINOK(lps->SetCur());
-
- const int kSignatureSize = 3;
- Byte buffer[kSignatureSize];
- size_t processedSize = kSignatureSize;
- RINOK(ReadStream(_stream, buffer, &processedSize));
- if (processedSize != kSignatureSize)
- {
- if (firstItem)
- return E_FAIL;
- break;
- }
- if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h')
- {
- if (firstItem)
- return E_FAIL;
- break;
- }
- firstItem = false;
-
- UInt64 dataStartPos;
- RINOK(_stream->Seek((UInt64)(Int64)(-3), STREAM_SEEK_CUR, &dataStartPos));
-
- result = decoder->Code(_stream, outStream, NULL, NULL, progress);
-
- if (result != S_OK)
- break;
-
- CMyComPtr getInStreamProcessedSize;
- decoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);
- if (!getInStreamProcessedSize)
- break;
- UInt64 packSize;
- RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&packSize));
- UInt64 pos;
- RINOK(_stream->Seek(dataStartPos + packSize, STREAM_SEEK_SET, &pos));
- currentTotalPacked = pos - _streamStartPosition;
- }
- outStream.Release();
-
- Int32 retResult;
- if (result == S_OK)
- retResult = NExtract::NOperationResult::kOK;
- else if (result == S_FALSE)
- retResult = NExtract::NOperationResult::kDataError;
- else
- return result;
- return extractCallback->SetOperationResult(retResult);
-
- COM_TRY_END
-}
-
-IMPL_ISetCompressCodecsInfo
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Handler.h b/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Handler.h
deleted file mode 100644
index 5d9fb1430..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Handler.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// BZip2/Handler.h
-
-#ifndef __BZIP2_HANDLER_H
-#define __BZIP2_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-#include "../../Common/CreateCoder.h"
-#include "BZip2Item.h"
-
-#ifdef COMPRESS_MT
-#include "../../../Windows/System.h"
-#endif
-
-namespace NArchive {
-namespace NBZip2 {
-
-class CHandler:
- public IInArchive,
- public IOutArchive,
- public ISetProperties,
- PUBLIC_ISetCompressCodecsInfo
- public CMyUnknownImp
-{
- CMyComPtr _stream;
- NArchive::NBZip2::CItem _item;
- UInt64 _streamStartPosition;
-
- UInt32 _level;
- UInt32 _dicSize;
- UInt32 _numPasses;
- #ifdef COMPRESS_MT
- UInt32 _numThreads;
- #endif
-
- DECL_EXTERNAL_CODECS_VARS
-
- void InitMethodProperties()
- {
- _level = 5;
- _dicSize =
- _numPasses = 0xFFFFFFFF;
- #ifdef COMPRESS_MT
- _numThreads = NWindows::NSystem::GetNumberOfProcessors();;
- #endif
- }
-
-public:
- MY_QUERYINTERFACE_BEGIN2(IInArchive)
- MY_QUERYINTERFACE_ENTRY(IOutArchive)
- MY_QUERYINTERFACE_ENTRY(ISetProperties)
- QUERY_ENTRY_ISetCompressCodecsInfo
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IInArchive(;)
-#ifndef EXTRACT_ONLY
- INTERFACE_IOutArchive(;)
-
- STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
-#endif
-
- DECL_ISetCompressCodecsInfo
-
- CHandler() { InitMethodProperties(); }
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Item.h b/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Item.h
deleted file mode 100644
index f3fce499a..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/BZip2Item.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Archive/BZip2Item.h
-
-#ifndef __ARCHIVE_BZIP2_ITEM_H
-#define __ARCHIVE_BZIP2_ITEM_H
-
-namespace NArchive {
-namespace NBZip2 {
-
-struct CItem
-{
- UInt64 PackSize;
- UInt64 UnPackSize;
-};
-
-}}
-
-#endif
-
-
-
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/StdAfx.h b/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/StdAfx.h
deleted file mode 100644
index 83fdd22d5..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/StdAfx.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/bz2Register.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/bz2Register.cpp
deleted file mode 100644
index f4a706ed1..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/BZip2/bz2Register.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// BZip2Register.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "BZip2Handler.h"
-static IInArchive *CreateArc() { return new NArchive::NBZip2::CHandler; }
-#ifndef EXTRACT_ONLY
-static IOutArchive *CreateArcOut() { return new NArchive::NBZip2::CHandler; }
-#else
-#define CreateArcOut 0
-#endif
-
-static CArcInfo g_ArcInfo =
- { L"BZip2", L"bz2 bzip2 tbz2 tbz", L"* * .tar .tar", 2, { 'B', 'Z', 'h' }, 3, true, CreateArc, CreateArcOut };
-
-REGISTER_ARC(BZip2)
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2.cpp
deleted file mode 100644
index c4333f234..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-// CoderMixer2.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixer2.h"
-
-namespace NCoderMixer {
-
-CBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):
- _srcBindInfo(srcBindInfo)
-{
- srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);
-
- UInt32 j;
- for (j = 0; j < NumSrcInStreams; j++)
- {
- _srcInToDestOutMap.Add(0);
- DestOutToSrcInMap.Add(0);
- }
- for (j = 0; j < _numSrcOutStreams; j++)
- {
- _srcOutToDestInMap.Add(0);
- _destInToSrcOutMap.Add(0);
- }
-
- UInt32 destInOffset = 0;
- UInt32 destOutOffset = 0;
- UInt32 srcInOffset = NumSrcInStreams;
- UInt32 srcOutOffset = _numSrcOutStreams;
-
- for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)
- {
- const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];
-
- srcInOffset -= srcCoderInfo.NumInStreams;
- srcOutOffset -= srcCoderInfo.NumOutStreams;
-
- UInt32 j;
- for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)
- {
- UInt32 index = srcInOffset + j;
- _srcInToDestOutMap[index] = destOutOffset;
- DestOutToSrcInMap[destOutOffset] = index;
- }
- for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)
- {
- UInt32 index = srcOutOffset + j;
- _srcOutToDestInMap[index] = destInOffset;
- _destInToSrcOutMap[destInOffset] = index;
- }
- }
-}
-
-void CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)
-{
- destBindInfo.Coders.Clear();
- destBindInfo.BindPairs.Clear();
- destBindInfo.InStreams.Clear();
- destBindInfo.OutStreams.Clear();
-
- int i;
- for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)
- {
- const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];
- CCoderStreamsInfo destCoderInfo;
- destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;
- destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;
- destBindInfo.Coders.Add(destCoderInfo);
- }
- for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)
- {
- const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];
- CBindPair destBindPair;
- destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];
- destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];
- destBindInfo.BindPairs.Add(destBindPair);
- }
- for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)
- destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);
- for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)
- destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);
-}
-
-CCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):
- NumInStreams(numInStreams),
- NumOutStreams(numOutStreams)
-{
- InSizes.Reserve(NumInStreams);
- InSizePointers.Reserve(NumInStreams);
- OutSizePointers.Reserve(NumOutStreams);
- OutSizePointers.Reserve(NumOutStreams);
-}
-
-static void SetSizes(const UInt64 **srcSizes, CRecordVector &sizes,
- CRecordVector &sizePointers, UInt32 numItems)
-{
- sizes.Clear();
- sizePointers.Clear();
- for(UInt32 i = 0; i < numItems; i++)
- {
- if (srcSizes == 0 || srcSizes[i] == NULL)
- {
- sizes.Add(0);
- sizePointers.Add(NULL);
- }
- else
- {
- sizes.Add(*srcSizes[i]);
- sizePointers.Add(&sizes.Back());
- }
- }
-}
-
-void CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,
- const UInt64 **outSizes)
-{
- SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);
- SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
-}
-
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2.h
deleted file mode 100644
index b1893b217..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2.h
+++ /dev/null
@@ -1,174 +0,0 @@
-// CoderMixer2.h
-
-#ifndef __CODER_MIXER2_H
-#define __CODER_MIXER2_H
-
-#include "../../../Common/MyVector.h"
-#include "../../../Common/Types.h"
-#include "../../../Common/MyCom.h"
-#include "../../ICoder.h"
-
-namespace NCoderMixer {
-
-struct CBindPair
-{
- UInt32 InIndex;
- UInt32 OutIndex;
-};
-
-struct CCoderStreamsInfo
-{
- UInt32 NumInStreams;
- UInt32 NumOutStreams;
-};
-
-struct CBindInfo
-{
- CRecordVector Coders;
- CRecordVector BindPairs;
- CRecordVector InStreams;
- CRecordVector OutStreams;
-
- void Clear()
- {
- Coders.Clear();
- BindPairs.Clear();
- InStreams.Clear();
- OutStreams.Clear();
- }
-
- /*
- UInt32 GetCoderStartOutStream(UInt32 coderIndex) const
- {
- UInt32 numOutStreams = 0;
- for (UInt32 i = 0; i < coderIndex; i++)
- numOutStreams += Coders[i].NumOutStreams;
- return numOutStreams;
- }
- */
-
-
- void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const
- {
- numInStreams = 0;
- numOutStreams = 0;
- for (int i = 0; i < Coders.Size(); i++)
- {
- const CCoderStreamsInfo &coderStreamsInfo = Coders[i];
- numInStreams += coderStreamsInfo.NumInStreams;
- numOutStreams += coderStreamsInfo.NumOutStreams;
- }
- }
-
- int FindBinderForInStream(UInt32 inStream) const
- {
- for (int i = 0; i < BindPairs.Size(); i++)
- if (BindPairs[i].InIndex == inStream)
- return i;
- return -1;
- }
- int FindBinderForOutStream(UInt32 outStream) const
- {
- for (int i = 0; i < BindPairs.Size(); i++)
- if (BindPairs[i].OutIndex == outStream)
- return i;
- return -1;
- }
-
- UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const
- {
- UInt32 streamIndex = 0;
- for (UInt32 i = 0; i < coderIndex; i++)
- streamIndex += Coders[i].NumInStreams;
- return streamIndex;
- }
-
- UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const
- {
- UInt32 streamIndex = 0;
- for (UInt32 i = 0; i < coderIndex; i++)
- streamIndex += Coders[i].NumOutStreams;
- return streamIndex;
- }
-
-
- void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,
- UInt32 &coderStreamIndex) const
- {
- for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
- {
- UInt32 curSize = Coders[coderIndex].NumInStreams;
- if (streamIndex < curSize)
- {
- coderStreamIndex = streamIndex;
- return;
- }
- streamIndex -= curSize;
- }
- throw 1;
- }
- void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,
- UInt32 &coderStreamIndex) const
- {
- for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
- {
- UInt32 curSize = Coders[coderIndex].NumOutStreams;
- if (streamIndex < curSize)
- {
- coderStreamIndex = streamIndex;
- return;
- }
- streamIndex -= curSize;
- }
- throw 1;
- }
-};
-
-class CBindReverseConverter
-{
- UInt32 _numSrcOutStreams;
- NCoderMixer::CBindInfo _srcBindInfo;
- CRecordVector _srcInToDestOutMap;
- CRecordVector _srcOutToDestInMap;
- CRecordVector _destInToSrcOutMap;
-public:
- UInt32 NumSrcInStreams;
- CRecordVector DestOutToSrcInMap;
-
- CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);
- void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);
-};
-
-struct CCoderInfo2
-{
- CMyComPtr Coder;
- CMyComPtr Coder2;
- UInt32 NumInStreams;
- UInt32 NumOutStreams;
-
- CRecordVector InSizes;
- CRecordVector OutSizes;
- CRecordVector InSizePointers;
- CRecordVector OutSizePointers;
-
- CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);
- void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
-
- HRESULT QueryInterface(REFGUID iid, void** pp) const
- {
- IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;
- return p->QueryInterface(iid, pp);
- }
-};
-
-class CCoderMixer2
-{
-public:
- virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;
- virtual void ReInit() = 0;
- virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;
-};
-
-}
-#endif
-
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2MT.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
deleted file mode 100644
index f3bea728d..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
+++ /dev/null
@@ -1,230 +0,0 @@
-// CoderMixer2MT.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixer2MT.h"
-
-namespace NCoderMixer {
-
-CCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):
- CCoderInfo2(numInStreams, numOutStreams)
-{
- InStreams.Reserve(NumInStreams);
- InStreamPointers.Reserve(NumInStreams);
- OutStreams.Reserve(NumOutStreams);
- OutStreamPointers.Reserve(NumOutStreams);
-}
-
-void CCoder2::Execute() { Code(NULL); }
-
-void CCoder2::Code(ICompressProgressInfo *progress)
-{
- InStreamPointers.Clear();
- OutStreamPointers.Clear();
- UInt32 i;
- for (i = 0; i < NumInStreams; i++)
- {
- if (InSizePointers[i] != NULL)
- InSizePointers[i] = &InSizes[i];
- InStreamPointers.Add((ISequentialInStream *)InStreams[i]);
- }
- for (i = 0; i < NumOutStreams; i++)
- {
- if (OutSizePointers[i] != NULL)
- OutSizePointers[i] = &OutSizes[i];
- OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);
- }
- if (Coder)
- Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],
- InSizePointers[0], OutSizePointers[0], progress);
- else
- Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,
- &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);
- {
- int i;
- for (i = 0; i < InStreams.Size(); i++)
- InStreams[i].Release();
- for (i = 0; i < OutStreams.Size(); i++)
- OutStreams[i].Release();
- }
-}
-
-static void SetSizes(const UInt64 **srcSizes, CRecordVector &sizes,
- CRecordVector &sizePointers, UInt32 numItems)
-{
- sizes.Clear();
- sizePointers.Clear();
- for(UInt32 i = 0; i < numItems; i++)
- {
- if (srcSizes == 0 || srcSizes[i] == NULL)
- {
- sizes.Add(0);
- sizePointers.Add(NULL);
- }
- else
- {
- sizes.Add(*srcSizes[i]);
- sizePointers.Add(&sizes.Back());
- }
- }
-}
-
-
-void CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)
-{
- SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);
- SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
-}
-
-//////////////////////////////////////
-// CCoderMixer2MT
-
-HRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)
-{
- _bindInfo = bindInfo;
- _streamBinders.Clear();
- for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)
- {
- _streamBinders.Add(CStreamBinder());
- RINOK(_streamBinders.Back().CreateEvents());
- }
- return S_OK;
-}
-
-void CCoderMixer2MT::AddCoderCommon()
-{
- const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];
- CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);
- _coders.Add(threadCoderInfo);
-}
-
-void CCoderMixer2MT::AddCoder(ICompressCoder *coder)
-{
- AddCoderCommon();
- _coders.Back().Coder = coder;
-}
-
-void CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)
-{
- AddCoderCommon();
- _coders.Back().Coder2 = coder;
-}
-
-
-void CCoderMixer2MT::ReInit()
-{
- for(int i = 0; i < _streamBinders.Size(); i++)
- _streamBinders[i].ReInit();
-}
-
-
-HRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)
-{
- /*
- if (_coders.Size() != _bindInfo.Coders.Size())
- throw 0;
- */
- int i;
- for(i = 0; i < _coders.Size(); i++)
- {
- CCoder2 &coderInfo = _coders[i];
- const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];
- coderInfo.InStreams.Clear();
- UInt32 j;
- for(j = 0; j < coderStreamsInfo.NumInStreams; j++)
- coderInfo.InStreams.Add(NULL);
- coderInfo.OutStreams.Clear();
- for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)
- coderInfo.OutStreams.Add(NULL);
- }
-
- for(i = 0; i < _bindInfo.BindPairs.Size(); i++)
- {
- const CBindPair &bindPair = _bindInfo.BindPairs[i];
- UInt32 inCoderIndex, inCoderStreamIndex;
- UInt32 outCoderIndex, outCoderStreamIndex;
- _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);
- _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);
-
- _streamBinders[i].CreateStreams(
- &_coders[inCoderIndex].InStreams[inCoderStreamIndex],
- &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);
- }
-
- for(i = 0; i < _bindInfo.InStreams.Size(); i++)
- {
- UInt32 inCoderIndex, inCoderStreamIndex;
- _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);
- _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];
- }
-
- for(i = 0; i < _bindInfo.OutStreams.Size(); i++)
- {
- UInt32 outCoderIndex, outCoderStreamIndex;
- _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);
- _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];
- }
- return S_OK;
-}
-
-HRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)
-{
- for (int i = 0; i < _coders.Size(); i++)
- if (_coders[i].Result == code)
- return code;
- return S_OK;
-}
-
-STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,
- const UInt64 ** /* inSizes */,
- UInt32 numInStreams,
- ISequentialOutStream **outStreams,
- const UInt64 ** /* outSizes */,
- UInt32 numOutStreams,
- ICompressProgressInfo *progress)
-{
- if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||
- numOutStreams != (UInt32)_bindInfo.OutStreams.Size())
- return E_INVALIDARG;
-
- Init(inStreams, outStreams);
-
- int i;
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- {
- RINOK(_coders[i].Create());
- }
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- _coders[i].Start();
-
- _coders[_progressCoderIndex].Code(progress);
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- _coders[i].WaitFinish();
-
- RINOK(ReturnIfError(E_ABORT));
- RINOK(ReturnIfError(E_OUTOFMEMORY));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK && result != E_FAIL && result != S_FALSE)
- return result;
- }
-
- RINOK(ReturnIfError(S_FALSE));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK)
- return result;
- }
- return S_OK;
-}
-
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2MT.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2MT.h
deleted file mode 100644
index acecc390f..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/CoderMixer2MT.h
+++ /dev/null
@@ -1,80 +0,0 @@
-// CoderMixer2MT.h
-
-#ifndef __CODER_MIXER2_MT_H
-#define __CODER_MIXER2_MT_H
-
-#include "CoderMixer2.h"
-#include "../../../Common/MyCom.h"
-#include "../../Common/StreamBinder.h"
-#include "../../Common/VirtThread.h"
-
-namespace NCoderMixer {
-
-struct CCoder2: public CCoderInfo2, public CVirtThread
-{
- HRESULT Result;
- CObjectVector< CMyComPtr > InStreams;
- CObjectVector< CMyComPtr > OutStreams;
- CRecordVector InStreamPointers;
- CRecordVector OutStreamPointers;
-
- CCoder2(UInt32 numInStreams, UInt32 numOutStreams);
- void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
- virtual void Execute();
- void Code(ICompressProgressInfo *progress);
-};
-
-
-/*
- SetBindInfo()
- for each coder
- AddCoder[2]()
- SetProgressIndex(UInt32 coderIndex);
-
- for each file
- {
- ReInit()
- for each coder
- SetCoderInfo
- Code
- }
-*/
-
-class CCoderMixer2MT:
- public ICompressCoder2,
- public CCoderMixer2,
- public CMyUnknownImp
-{
- CBindInfo _bindInfo;
- CObjectVector _streamBinders;
- int _progressCoderIndex;
-
- void AddCoderCommon();
- HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);
- HRESULT ReturnIfError(HRESULT code);
-public:
- CObjectVector _coders;
- MY_UNKNOWN_IMP
-
- STDMETHOD(Code)(ISequentialInStream **inStreams,
- const UInt64 **inSizes,
- UInt32 numInStreams,
- ISequentialOutStream **outStreams,
- const UInt64 **outSizes,
- UInt32 numOutStreams,
- ICompressProgressInfo *progress);
-
- HRESULT SetBindInfo(const CBindInfo &bindInfo);
- void AddCoder(ICompressCoder *coder);
- void AddCoder2(ICompressCoder2 *coder);
- void SetProgressCoderIndex(int coderIndex) { _progressCoderIndex = coderIndex; }
-
- void ReInit();
- void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
- { _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }
- UInt64 GetWriteProcessedSize(UInt32 binderIndex) const
- { return _streamBinders[binderIndex].ProcessedSize; }
-};
-
-}
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/DummyOutStream.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/DummyOutStream.cpp
deleted file mode 100644
index 237e01e59..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/DummyOutStream.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-// DummyOutStream.cpp
-
-#include "StdAfx.h"
-
-#include "DummyOutStream.h"
-
-STDMETHODIMP CDummyOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize;
- HRESULT result;
- if(!_stream)
- {
- realProcessedSize = size;
- result = S_OK;
- }
- else
- result = _stream->Write(data, size, &realProcessedSize);
- _size += realProcessedSize;
- if(processedSize != NULL)
- *processedSize = realProcessedSize;
- return result;
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/DummyOutStream.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/DummyOutStream.h
deleted file mode 100644
index c993bb3dd..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/DummyOutStream.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// DummyOutStream.h
-
-#ifndef __DUMMYOUTSTREAM_H
-#define __DUMMYOUTSTREAM_H
-
-#include "../../IStream.h"
-#include "Common/MyCom.h"
-
-class CDummyOutStream:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
- CMyComPtr _stream;
- UInt64 _size;
-public:
- void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }
- void ReleaseStream() { _stream.Release(); }
- void Init() { _size = 0; }
- MY_UNKNOWN_IMP
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
- UInt64 GetSize() const { return _size; }
-};
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/FindSignature.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/FindSignature.cpp
deleted file mode 100644
index ad04bfcb7..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/FindSignature.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// FindSignature.cpp
-
-#include "StdAfx.h"
-
-#include "Common/Buffer.h"
-
-#include "FindSignature.h"
-
-#include "../../Common/StreamUtils.h"
-
-HRESULT FindSignatureInStream(ISequentialInStream *stream,
- const Byte *signature, unsigned signatureSize,
- const UInt64 *limit, UInt64 &resPos)
-{
- resPos = 0;
- CByteBuffer byteBuffer2;
- byteBuffer2.SetCapacity(signatureSize);
- RINOK(ReadStream_FALSE(stream, byteBuffer2, signatureSize));
-
- if (memcmp(byteBuffer2, signature, signatureSize) == 0)
- return S_OK;
-
- const UInt32 kBufferSize = (1 << 16);
- CByteBuffer byteBuffer;
- byteBuffer.SetCapacity(kBufferSize);
- Byte *buffer = byteBuffer;
- UInt32 numPrevBytes = signatureSize - 1;
- memcpy(buffer, (const Byte *)byteBuffer2 + 1, numPrevBytes);
- resPos = 1;
- for (;;)
- {
- if (limit != NULL)
- if (resPos > *limit)
- return S_FALSE;
- do
- {
- UInt32 numReadBytes = kBufferSize - numPrevBytes;
- UInt32 processedSize;
- RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
- numPrevBytes += processedSize;
- if (processedSize == 0)
- return S_FALSE;
- }
- while (numPrevBytes < signatureSize);
- UInt32 numTests = numPrevBytes - signatureSize + 1;
- for (UInt32 pos = 0; pos < numTests; pos++)
- {
- Byte b = signature[0];
- for (; buffer[pos] != b && pos < numTests; pos++);
- if (pos == numTests)
- break;
- if (memcmp(buffer + pos, signature, signatureSize) == 0)
- {
- resPos += pos;
- return S_OK;
- }
- }
- resPos += numTests;
- numPrevBytes -= numTests;
- memmove(buffer, buffer + numTests, numPrevBytes);
- }
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/FindSignature.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/FindSignature.h
deleted file mode 100644
index f801d9860..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/FindSignature.h
+++ /dev/null
@@ -1,12 +0,0 @@
-// FindSignature.h
-
-#ifndef __FINDSIGNATURE_H
-#define __FINDSIGNATURE_H
-
-#include "../../IStream.h"
-
-HRESULT FindSignatureInStream(ISequentialInStream *stream,
- const Byte *signature, unsigned signatureSize,
- const UInt64 *limit, UInt64 &resPos);
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/InStreamWithCRC.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/InStreamWithCRC.cpp
deleted file mode 100644
index 4b87a43c0..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/InStreamWithCRC.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-// InStreamWithCRC.cpp
-
-#include "StdAfx.h"
-
-#include "InStreamWithCRC.h"
-
-STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize;
- HRESULT result = _stream->Read(data, size, &realProcessedSize);
- _size += realProcessedSize;
- if (size > 0 && realProcessedSize == 0)
- _wasFinished = true;
- _crc = CrcUpdate(_crc, data, realProcessedSize);
- if(processedSize != NULL)
- *processedSize = realProcessedSize;
- return result;
-}
-
-STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize;
- HRESULT result = _stream->Read(data, size, &realProcessedSize);
- if (size > 0 && realProcessedSize == 0)
- _wasFinished = true;
- _size += realProcessedSize;
- _crc = CrcUpdate(_crc, data, realProcessedSize);
- if(processedSize != NULL)
- *processedSize = realProcessedSize;
- return result;
-}
-
-STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
-{
- if (seekOrigin != STREAM_SEEK_SET || offset != 0)
- return E_FAIL;
- _size = 0;
- _crc = CRC_INIT_VAL;
- return _stream->Seek(offset, seekOrigin, newPosition);
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/InStreamWithCRC.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/InStreamWithCRC.h
deleted file mode 100644
index d73f658e3..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/InStreamWithCRC.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// InStreamWithCRC.h
-
-#ifndef __INSTREAMWITHCRC_H
-#define __INSTREAMWITHCRC_H
-
-#include "../../../Common/MyCom.h"
-#include "../../IStream.h"
-
-extern "C"
-{
-#include "../../../../C/7zCrc.h"
-}
-
-class CSequentialInStreamWithCRC:
- public ISequentialInStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-private:
- CMyComPtr _stream;
- UInt64 _size;
- UInt32 _crc;
- bool _wasFinished;
-public:
- void SetStream(ISequentialInStream *stream) { _stream = stream; }
- void Init()
- {
- _size = 0;
- _wasFinished = false;
- _crc = CRC_INIT_VAL;
- }
- void ReleaseStream() { _stream.Release(); }
- UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
- UInt64 GetSize() const { return _size; }
- bool WasFinished() const { return _wasFinished; }
-};
-
-class CInStreamWithCRC:
- public IInStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP1(IInStream)
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
-private:
- CMyComPtr _stream;
- UInt64 _size;
- UInt32 _crc;
- bool _wasFinished;
-public:
- void SetStream(IInStream *stream) { _stream = stream; }
- void Init()
- {
- _size = 0;
- _wasFinished = false;
- _crc = CRC_INIT_VAL;
- }
- void ReleaseStream() { _stream.Release(); }
- UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
- UInt64 GetSize() const { return _size; }
- bool WasFinished() const { return _wasFinished; }
-};
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ItemNameUtils.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/ItemNameUtils.cpp
deleted file mode 100644
index b4fee7c06..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ItemNameUtils.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// Archive/Common/ItemNameUtils.cpp
-
-#include "StdAfx.h"
-
-#include "ItemNameUtils.h"
-
-namespace NArchive {
-namespace NItemName {
-
-static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;
-static const wchar_t kDirDelimiter = L'/';
-
-UString MakeLegalName(const UString &name)
-{
- UString zipName = name;
- zipName.Replace(kOSDirDelimiter, kDirDelimiter);
- return zipName;
-}
-
-UString GetOSName(const UString &name)
-{
- UString newName = name;
- newName.Replace(kDirDelimiter, kOSDirDelimiter);
- return newName;
-}
-
-UString GetOSName2(const UString &name)
-{
- if (name.IsEmpty())
- return UString();
- UString newName = GetOSName(name);
- if (newName[newName.Length() - 1] == kOSDirDelimiter)
- newName.Delete(newName.Length() - 1);
- return newName;
-}
-
-bool HasTailSlash(const AString &name, UINT codePage)
-{
- if (name.IsEmpty())
- return false;
- LPCSTR prev =
- #ifdef _WIN32
- CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);
- #else
- (LPCSTR)(name) + (name.Length() - 1);
- #endif
- return (*prev == '/');
-}
-
-#ifndef _WIN32
-UString WinNameToOSName(const UString &name)
-{
- UString newName = name;
- newName.Replace(L'\\', kOSDirDelimiter);
- return newName;
-}
-#endif
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ItemNameUtils.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/ItemNameUtils.h
deleted file mode 100644
index 8b91d1c68..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ItemNameUtils.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Archive/Common/ItemNameUtils.h
-
-#ifndef __ARCHIVE_ITEMNAMEUTILS_H
-#define __ARCHIVE_ITEMNAMEUTILS_H
-
-#include "../../../Common/MyString.h"
-
-namespace NArchive {
-namespace NItemName {
-
- UString MakeLegalName(const UString &name);
- UString GetOSName(const UString &name);
- UString GetOSName2(const UString &name);
- bool HasTailSlash(const AString &name, UINT codePage);
-
- #ifdef _WIN32
- inline UString WinNameToOSName(const UString &name) { return name; }
- #else
- UString WinNameToOSName(const UString &name);
- #endif
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/MultiStream.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/MultiStream.cpp
deleted file mode 100644
index 33bb91ed8..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/MultiStream.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-// MultiStream.cpp
-
-#include "StdAfx.h"
-
-#include "MultiStream.h"
-
-STDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- if(processedSize != NULL)
- *processedSize = 0;
- while(_streamIndex < Streams.Size() && size > 0)
- {
- CSubStreamInfo &s = Streams[_streamIndex];
- if (_pos == s.Size)
- {
- _streamIndex++;
- _pos = 0;
- continue;
- }
- RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));
- UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));
- UInt32 realProcessed;
- HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);
- data = (void *)((Byte *)data + realProcessed);
- size -= realProcessed;
- if(processedSize != NULL)
- *processedSize += realProcessed;
- _pos += realProcessed;
- _seekPos += realProcessed;
- RINOK(result);
- break;
- }
- return S_OK;
-}
-
-STDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin,
- UInt64 *newPosition)
-{
- UInt64 newPos;
- switch(seekOrigin)
- {
- case STREAM_SEEK_SET:
- newPos = offset;
- break;
- case STREAM_SEEK_CUR:
- newPos = _seekPos + offset;
- break;
- case STREAM_SEEK_END:
- newPos = _totalLength + offset;
- break;
- default:
- return STG_E_INVALIDFUNCTION;
- }
- _seekPos = 0;
- for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)
- {
- UInt64 size = Streams[_streamIndex].Size;
- if (newPos < _seekPos + size)
- {
- _pos = newPos - _seekPos;
- _seekPos += _pos;
- if (newPosition != 0)
- *newPosition = newPos;
- return S_OK;
- }
- _seekPos += size;
- }
- if (newPos == _seekPos)
- {
- if (newPosition != 0)
- *newPosition = newPos;
- return S_OK;
- }
- return E_FAIL;
-}
-
-
-/*
-class COutVolumeStream:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
- int _volIndex;
- UInt64 _volSize;
- UInt64 _curPos;
- CMyComPtr _volumeStream;
- COutArchive _archive;
- CCRC _crc;
-
-public:
- MY_UNKNOWN_IMP
-
- CFileItem _file;
- CUpdateOptions _options;
- CMyComPtr VolumeCallback;
- void Init(IArchiveUpdateCallback2 *volumeCallback,
- const UString &name)
- {
- _file.Name = name;
- _file.IsStartPosDefined = true;
- _file.StartPos = 0;
-
- VolumeCallback = volumeCallback;
- _volIndex = 0;
- _volSize = 0;
- }
-
- HRESULT Flush();
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-};
-
-HRESULT COutVolumeStream::Flush()
-{
- if (_volumeStream)
- {
- _file.UnPackSize = _curPos;
- _file.FileCRC = _crc.GetDigest();
- RINOK(WriteVolumeHeader(_archive, _file, _options));
- _archive.Close();
- _volumeStream.Release();
- _file.StartPos += _file.UnPackSize;
- }
- return S_OK;
-}
-*/
-
-/*
-STDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- if(processedSize != NULL)
- *processedSize = 0;
- while(size > 0)
- {
- if (_streamIndex >= Streams.Size())
- {
- CSubStreamInfo subStream;
- RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));
- RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));
- subStream.Pos = 0;
- Streams.Add(subStream);
- continue;
- }
- CSubStreamInfo &subStream = Streams[_streamIndex];
- if (_offsetPos >= subStream.Size)
- {
- _offsetPos -= subStream.Size;
- _streamIndex++;
- continue;
- }
- if (_offsetPos != subStream.Pos)
- {
- CMyComPtr outStream;
- RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));
- RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));
- subStream.Pos = _offsetPos;
- }
-
- UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);
- UInt32 realProcessed;
- RINOK(subStream.Stream->Write(data, curSize, &realProcessed));
- data = (void *)((Byte *)data + realProcessed);
- size -= realProcessed;
- subStream.Pos += realProcessed;
- _offsetPos += realProcessed;
- _absPos += realProcessed;
- if (_absPos > _length)
- _length = _absPos;
- if(processedSize != NULL)
- *processedSize += realProcessed;
- if (subStream.Pos == subStream.Size)
- {
- _streamIndex++;
- _offsetPos = 0;
- }
- if (realProcessed != curSize && realProcessed == 0)
- return E_FAIL;
- }
- return S_OK;
-}
-
-STDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
-{
- if(seekOrigin >= 3)
- return STG_E_INVALIDFUNCTION;
- switch(seekOrigin)
- {
- case STREAM_SEEK_SET:
- _absPos = offset;
- break;
- case STREAM_SEEK_CUR:
- _absPos += offset;
- break;
- case STREAM_SEEK_END:
- _absPos = _length + offset;
- break;
- }
- _offsetPos = _absPos;
- _streamIndex = 0;
- return S_OK;
-}
-*/
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/MultiStream.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/MultiStream.h
deleted file mode 100644
index 133a06f9f..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/MultiStream.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// MultiStream.h
-
-#ifndef __MULTISTREAM_H
-#define __MULTISTREAM_H
-
-#include "../../../Common/MyCom.h"
-#include "../../../Common/MyVector.h"
-#include "../../Archive/IArchive.h"
-
-class CMultiStream:
- public IInStream,
- public CMyUnknownImp
-{
- int _streamIndex;
- UInt64 _pos;
- UInt64 _seekPos;
- UInt64 _totalLength;
-public:
- struct CSubStreamInfo
- {
- CMyComPtr Stream;
- UInt64 Pos;
- UInt64 Size;
- };
- CObjectVector Streams;
- void Init()
- {
- _streamIndex = 0;
- _pos = 0;
- _seekPos = 0;
- _totalLength = 0;
- for (int i = 0; i < Streams.Size(); i++)
- _totalLength += Streams[i].Size;
- }
-
- MY_UNKNOWN_IMP1(IInStream)
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
-};
-
-/*
-class COutMultiStream:
- public IOutStream,
- public CMyUnknownImp
-{
- int _streamIndex; // required stream
- UInt64 _offsetPos; // offset from start of _streamIndex index
- UInt64 _absPos;
- UInt64 _length;
-
- struct CSubStreamInfo
- {
- CMyComPtr Stream;
- UInt64 Size;
- UInt64 Pos;
- };
- CObjectVector Streams;
-public:
- CMyComPtr VolumeCallback;
- void Init()
- {
- _streamIndex = 0;
- _offsetPos = 0;
- _absPos = 0;
- _length = 0;
- }
-
- MY_UNKNOWN_IMP1(IOutStream)
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
-};
-*/
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp
deleted file mode 100644
index 37b157d1e..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// OutStreamWithCRC.cpp
-
-#include "StdAfx.h"
-
-#include "OutStreamWithCRC.h"
-
-STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize;
- HRESULT result;
- if(!_stream)
- {
- realProcessedSize = size;
- result = S_OK;
- }
- else
- result = _stream->Write(data, size, &realProcessedSize);
- if (_calculate)
- _crc = CrcUpdate(_crc, data, realProcessedSize);
- _size += realProcessedSize;
- if(processedSize != NULL)
- *processedSize = realProcessedSize;
- return result;
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.h
deleted file mode 100644
index 44e5eb24b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/OutStreamWithCRC.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// OutStreamWithCRC.h
-
-#ifndef __OUT_STREAM_WITH_CRC_H
-#define __OUT_STREAM_WITH_CRC_H
-
-#include "../../../Common/MyCom.h"
-#include "../../IStream.h"
-
-extern "C"
-{
-#include "../../../../C/7zCrc.h"
-}
-
-class COutStreamWithCRC:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
- CMyComPtr _stream;
- UInt64 _size;
- UInt32 _crc;
- bool _calculate;
-public:
- MY_UNKNOWN_IMP
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
- void SetStream(ISequentialOutStream *stream) { _stream = stream; }
- void ReleaseStream() { _stream.Release(); }
- void Init(bool calculate = true)
- {
- _size = 0;
- _calculate = calculate;
- _crc = CRC_INIT_VAL;
- }
- void InitCRC() { _crc = CRC_INIT_VAL; }
- UInt64 GetSize() const { return _size; }
- UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
-};
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ParseProperties.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Common/ParseProperties.cpp
deleted file mode 100644
index 5550a23bc..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ParseProperties.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-// ParseProperties.cpp
-
-#include "StdAfx.h"
-
-#include "ParseProperties.h"
-
-#include "Common/StringToInt.h"
-#include "Common/MyCom.h"
-
-HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)
-{
- if (prop.vt == VT_UI4)
- {
- if (!name.IsEmpty())
- return E_INVALIDARG;
- resValue = prop.ulVal;
- }
- else if (prop.vt == VT_EMPTY)
- {
- if(!name.IsEmpty())
- {
- const wchar_t *start = name;
- const wchar_t *end;
- UInt64 v = ConvertStringToUInt64(start, &end);
- if (end - start != name.Length())
- return E_INVALIDARG;
- resValue = (UInt32)v;
- }
- }
- else
- return E_INVALIDARG;
- return S_OK;
-}
-
-static const int kLogarithmicSizeLimit = 32;
-static const wchar_t kByteSymbol = L'B';
-static const wchar_t kKiloByteSymbol = L'K';
-static const wchar_t kMegaByteSymbol = L'M';
-
-HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)
-{
- UString srcString = srcStringSpec;
- srcString.MakeUpper();
-
- const wchar_t *start = srcString;
- const wchar_t *end;
- UInt64 number = ConvertStringToUInt64(start, &end);
- int numDigits = (int)(end - start);
- if (numDigits == 0 || srcString.Length() > numDigits + 1)
- return E_INVALIDARG;
- if (srcString.Length() == numDigits)
- {
- if (number >= kLogarithmicSizeLimit)
- return E_INVALIDARG;
- dicSize = (UInt32)1 << (int)number;
- return S_OK;
- }
- switch (srcString[numDigits])
- {
- case kByteSymbol:
- if (number >= ((UInt64)1 << kLogarithmicSizeLimit))
- return E_INVALIDARG;
- dicSize = (UInt32)number;
- break;
- case kKiloByteSymbol:
- if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))
- return E_INVALIDARG;
- dicSize = (UInt32)(number << 10);
- break;
- case kMegaByteSymbol:
- if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))
- return E_INVALIDARG;
- dicSize = (UInt32)(number << 20);
- break;
- default:
- return E_INVALIDARG;
- }
- return S_OK;
-}
-
-HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)
-{
- if (name.IsEmpty())
- {
- if (prop.vt == VT_UI4)
- {
- UInt32 logDicSize = prop.ulVal;
- if (logDicSize >= 32)
- return E_INVALIDARG;
- resValue = (UInt32)1 << logDicSize;
- return S_OK;
- }
- if (prop.vt == VT_BSTR)
- return ParsePropDictionaryValue(prop.bstrVal, resValue);
- return E_INVALIDARG;
- }
- return ParsePropDictionaryValue(name, resValue);
-}
-
-bool StringToBool(const UString &s, bool &res)
-{
- if (s.IsEmpty() || s.CompareNoCase(L"ON") == 0 || s.Compare(L"+") == 0)
- {
- res = true;
- return true;
- }
- if (s.CompareNoCase(L"OFF") == 0 || s.Compare(L"-") == 0)
- {
- res = false;
- return true;
- }
- return false;
-}
-
-HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)
-{
- switch(value.vt)
- {
- case VT_EMPTY:
- dest = true;
- return S_OK;
- case VT_BOOL:
- dest = (value.boolVal != VARIANT_FALSE);
- return S_OK;
- /*
- case VT_UI4:
- dest = (value.ulVal != 0);
- break;
- */
- case VT_BSTR:
- return StringToBool(value.bstrVal, dest) ? S_OK : E_INVALIDARG;
- }
- return E_INVALIDARG;
-}
-
-int ParseStringToUInt32(const UString &srcString, UInt32 &number)
-{
- const wchar_t *start = srcString;
- const wchar_t *end;
- UInt64 number64 = ConvertStringToUInt64(start, &end);
- if (number64 > 0xFFFFFFFF)
- {
- number = 0;
- return 0;
- }
- number = (UInt32)number64;
- return (int)(end - start);
-}
-
-HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)
-{
- if (name.IsEmpty())
- {
- switch(prop.vt)
- {
- case VT_UI4:
- numThreads = prop.ulVal;
- break;
- default:
- {
- bool val;
- RINOK(SetBoolProperty(val, prop));
- numThreads = (val ? defaultNumThreads : 1);
- break;
- }
- }
- }
- else
- {
- UInt32 number;
- int index = ParseStringToUInt32(name, number);
- if (index != name.Length())
- return E_INVALIDARG;
- numThreads = number;
- }
- return S_OK;
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ParseProperties.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/ParseProperties.h
deleted file mode 100644
index c64fc1ea1..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/ParseProperties.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// ParseProperties.h
-
-#ifndef __PARSEPROPERTIES_H
-#define __PARSEPROPERTIES_H
-
-#include "Common/MyString.h"
-#include "Common/Types.h"
-
-HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);
-HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);
-HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);
-
-bool StringToBool(const UString &s, bool &res);
-HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);
-int ParseStringToUInt32(const UString &srcString, UInt32 &number);
-HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Common/StdAfx.h b/desmume/src/windows/7z/CPP/7zip/Archive/Common/StdAfx.h
deleted file mode 100644
index a4e617312..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Common/StdAfx.h
+++ /dev/null
@@ -1,9 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-#include "../../../Common/NewHandler.h"
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/DllExports2.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/DllExports2.cpp
deleted file mode 100644
index 7f4764654..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/DllExports2.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-// DLLExports.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/MyInitGuid.h"
-#include "../../Common/ComTry.h"
-#include "../../Common/Types.h"
-#include "../../Windows/PropVariant.h"
-#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)
-extern "C"
-{
-#include "../../../C/Alloc.h"
-}
-#endif
-
-#include "IArchive.h"
-#include "../ICoder.h"
-#include "../IPassword.h"
-
-HINSTANCE g_hInstance;
-#ifndef _UNICODE
-#ifdef _WIN32
-bool g_IsNT = false;
-static bool IsItWindowsNT()
-{
- OSVERSIONINFO versionInfo;
- versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
- if (!::GetVersionEx(&versionInfo))
- return false;
- return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
-}
-#endif
-#endif
-
-//desmume 27-jun-09 - dont want this in a static library
-//extern "C"
-//BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
-//{
-// if (dwReason == DLL_PROCESS_ATTACH)
-// {
-// g_hInstance = hInstance;
-// #ifndef _UNICODE
-// #ifdef _WIN32
-// g_IsNT = IsItWindowsNT();
-// #endif
-// #endif
-// }
-// return TRUE;
-//}
-
-DEFINE_GUID(CLSID_CArchiveHandler,
-0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);
-
-static const UInt16 kDecodeId = 0x2790;
-
-DEFINE_GUID(CLSID_CCodec,
-0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
-
-STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);
-STDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);
-
-STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
-{
- // COM_TRY_BEGIN
- *outObject = 0;
- if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)
- {
- return CreateCoder(clsid, iid, outObject);
- }
- else
- {
- return CreateArchiver(clsid, iid, outObject);
- }
- // COM_TRY_END
-}
-
-STDAPI SetLargePageMode()
-{
- #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)
- SetLargePageSize();
- #endif
- return S_OK;
-}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHandler.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHandler.cpp
deleted file mode 100644
index 01a5c9f99..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHandler.cpp
+++ /dev/null
@@ -1,284 +0,0 @@
-// GZipHandler.cpp
-
-#include "StdAfx.h"
-
-#include "GZipHandler.h"
-
-#include "Common/Defs.h"
-#include "Common/StringConvert.h"
-#include "Common/ComTry.h"
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../../ICoder.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/CreateCoder.h"
-#include "../Common/OutStreamWithCRC.h"
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NGZip {
-
-static const CMethodId kMethodId_Deflate = 0x040108;
-
-const wchar_t *kHostOS[] =
-{
- L"FAT",
- L"AMIGA",
- L"VMS",
- L"Unix",
- L"VM_CMS",
- L"Atari", // what if it's a minix filesystem? [cjh]
- L"HPFS", // filesystem used by OS/2 (and NT 3.x)
- L"Mac",
- L"Z_System",
- L"CPM",
- L"TOPS20", // pkzip 2.50 NTFS
- L"NTFS", // filesystem used by Windows NT
- L"QDOS ", // SMS/QDOS
- L"Acorn", // Archimedes Acorn RISC OS
- L"VFAT", // filesystem used by Windows 95, NT
- L"MVS",
- L"BeOS", // hybrid POSIX/database filesystem
- // BeBOX or PowerMac
- L"Tandem",
- L"THEOS"
-};
-
-static const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
-
-static const wchar_t *kUnknownOS = L"Unknown";
-
-/*
-enum // PropID
-{
- kpidExtraIsPresent = kpidUserDefined,
- kpidExtraFlags,
- kpidIsText
-};
-*/
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- // { NULL, kpidMethod, VT_UI1},
- { NULL, kpidHostOS, VT_BSTR},
- { NULL, kpidCRC, VT_UI4}
- // { L"Extra", kpidExtraIsPresent, VT_BOOL}
- // { L"Extra flags", kpidExtraFlags, VT_UI1},
- // { L"Is Text", kpidIsText, VT_BOOL},
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = 1;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPath:
- if (m_Item.NameIsPresent())
- prop = MultiByteToUnicodeString(m_Item.Name, CP_ACP);
- break;
- case kpidMTime:
- {
- FILETIME utcTime;
- if (m_Item.Time != 0)
- {
- NTime::UnixTimeToFileTime((UInt32)m_Item.Time, utcTime);
- prop = utcTime;
- }
- else
- {
- // utcTime.dwLowDateTime = utcTime.dwHighDateTime = 0;
- // prop = utcTime;
- }
- break;
- }
- case kpidSize: prop = UInt64(m_Item.UnPackSize32); break;
- case kpidPackSize: prop = m_PackSize; break;
- case kpidCommented: prop = m_Item.CommentIsPresent(); break;
- case kpidHostOS:
- prop = (m_Item.HostOS < kNumHostOSes) ?
- kHostOS[m_Item.HostOS] : kUnknownOS;
- break;
- case kpidMethod: prop = m_Item.CompressionMethod; break;
- case kpidCRC: prop = m_Item.FileCRC; break;
- /*
- case kpidExtraFlags: prop = m_Item.ExtraFlags; break;
- case kpidIsText: prop = m_Item.IsText(); break;
- case kpidExtraIsPresent: prop = m_Item.ExtraFieldIsPresent(); break;
- */
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- try
- {
- CInArchive archive;
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
- RINOK(archive.ReadHeader(inStream, m_Item));
- m_DataOffset = archive.GetOffset();
- UInt64 newPosition;
- RINOK(inStream->Seek(-8, STREAM_SEEK_END, &newPosition));
- m_PackSize = newPosition - (m_StreamStartPosition + m_DataOffset);
- if (archive.ReadPostHeader(inStream, m_Item) != S_OK)
- return S_FALSE;
- m_Stream = inStream;
- }
- catch(...)
- {
- return S_FALSE;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- m_Stream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
- Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == UInt32(-1));
- if (!allFilesMode)
- {
- if (numItems == 0)
- return S_OK;
- if (numItems != 1)
- return E_INVALIDARG;
- if (indices[0] != 0)
- return E_INVALIDARG;
- }
-
- bool testMode = (_aTestMode != 0);
-
- extractCallback->SetTotal(m_PackSize);
-
- UInt64 currentTotalPacked = 0;
-
- RINOK(extractCallback->SetCompleted(¤tTotalPacked));
- CMyComPtr realOutStream;
- Int32 askMode;
- askMode = testMode ? NArchive::NExtract::NAskMode::kTest :
- NArchive::NExtract::NAskMode::kExtract;
-
- RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
-
- if(!testMode && !realOutStream)
- return S_OK;
-
- extractCallback->PrepareOperation(askMode);
-
- COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
- CMyComPtr outStream(outStreamSpec);
- outStreamSpec->SetStream(realOutStream);
- outStreamSpec->Init();
- realOutStream.Release();
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr progress = lps;
- lps->Init(extractCallback, true);
-
- CMyComPtr deflateDecoder;
- bool firstItem = true;
- RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));
- Int32 opRes;
- for (;;)
- {
- lps->InSize = currentTotalPacked;
- lps->OutSize = outStreamSpec->GetSize();
-
- CInArchive archive;
- CItem item;
- HRESULT result = archive.ReadHeader(m_Stream, item);
- if (result != S_OK)
- {
- if (firstItem)
- return E_FAIL;
- opRes = NArchive::NExtract::NOperationResult::kOK;
- break;
- }
- firstItem = false;
-
- UInt64 dataStartPos;
- RINOK(m_Stream->Seek(0, STREAM_SEEK_CUR, &dataStartPos));
-
- outStreamSpec->InitCRC();
-
- if (item.CompressionMethod != NFileHeader::NCompressionMethod::kDeflate)
- {
- opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
- break;
- }
-
- if (!deflateDecoder)
- {
- RINOK(CreateCoder(
- EXTERNAL_CODECS_VARS
- kMethodId_Deflate, deflateDecoder, false));
- if (!deflateDecoder)
- {
- opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
- break;
- }
- }
- result = deflateDecoder->Code(m_Stream, outStream, NULL, NULL, progress);
- if (result != S_OK)
- {
- if (result != S_FALSE)
- return result;
- opRes = NArchive::NExtract::NOperationResult::kDataError;
- break;
- }
-
- CMyComPtr getInStreamProcessedSize;
- RINOK(deflateDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize,
- &getInStreamProcessedSize));
- UInt64 packSize;
- RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&packSize));
- UInt64 pos;
- RINOK(m_Stream->Seek(dataStartPos + packSize, STREAM_SEEK_SET, &pos));
-
- currentTotalPacked = pos - m_StreamStartPosition;
-
- CItem postItem;
- if (archive.ReadPostHeader(m_Stream, postItem) != S_OK)
- return E_FAIL;
- if((outStreamSpec->GetCRC() != postItem.FileCRC))
- {
- opRes = NArchive::NExtract::NOperationResult::kCRCError;
- break;
- }
- }
- outStream.Release();
- return extractCallback->SetOperationResult(opRes);
- COM_TRY_END
-}
-
-IMPL_ISetCompressCodecsInfo
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHandler.h b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHandler.h
deleted file mode 100644
index 31f5a430f..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHandler.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// GZip/Handler.h
-
-#ifndef __GZIP_HANDLER_H
-#define __GZIP_HANDLER_H
-
-#include "Common/MyCom.h"
-
-#include "../IArchive.h"
-
-#include "../../Common/CreateCoder.h"
-
-#include "GZipIn.h"
-#include "GZipUpdate.h"
-
-namespace NArchive {
-namespace NGZip {
-
-class CHandler:
- public IInArchive,
- public IOutArchive,
- public ISetProperties,
- PUBLIC_ISetCompressCodecsInfo
- public CMyUnknownImp
-{
-public:
- MY_QUERYINTERFACE_BEGIN2(IInArchive)
- MY_QUERYINTERFACE_ENTRY(IOutArchive)
- MY_QUERYINTERFACE_ENTRY(ISetProperties)
- QUERY_ENTRY_ISetCompressCodecsInfo
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IInArchive(;)
-#ifndef EXTRACT_ONLY
- INTERFACE_IOutArchive(;)
-
- STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
-#endif
-
- DECL_ISetCompressCodecsInfo
-
- CHandler() { InitMethodProperties(); }
-
-private:
- NArchive::NGZip::CItem m_Item;
- UInt64 m_StreamStartPosition;
- UInt64 m_DataOffset;
- UInt64 m_PackSize;
- CMyComPtr m_Stream;
- CCompressionMethodMode m_Method;
- UInt32 m_Level;
-
- DECL_EXTERNAL_CODECS_VARS
-
- void InitMethodProperties()
- {
- m_Method.NumMatchFinderCyclesDefined = false;
- m_Level = m_Method.NumPasses = m_Method.NumFastBytes =
- m_Method.NumMatchFinderCycles = m_Method.Algo = 0xFFFFFFFF;
- }
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHeader.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHeader.cpp
deleted file mode 100644
index 508d6bd5b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHeader.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// Archive/GZip/Header.h
-
-#include "StdAfx.h"
-
-#include "GZipHeader.h"
-
-namespace NArchive {
-namespace NGZip {
-
-extern UInt16 kSignature = 0x8B1F + 1;
-
-class CMarkersInitializer
-{
-public:
- CMarkersInitializer()
- { kSignature--; }
-} g_MarkerInitializer;
-
-}}
-
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHeader.h b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHeader.h
deleted file mode 100644
index 3e76ad6d2..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipHeader.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// Archive/GZip/Header.h
-
-#ifndef __ARCHIVE_GZIP_HEADER_H
-#define __ARCHIVE_GZIP_HEADER_H
-
-#include "Common/Types.h"
-
-namespace NArchive {
-namespace NGZip {
-
-extern UInt16 kSignature;
-static const UInt32 kSignatureSize = 2;
-
-namespace NFileHeader
-{
- /*
- struct CBlock
- {
- UInt16 Id;
- Byte CompressionMethod;
- Byte Flags;
- UInt32 Time;
- Byte ExtraFlags;
- Byte HostOS;
- };
- */
-
- namespace NFlags
- {
- const int kDataIsText = 1 << 0;
- const int kHeaderCRCIsPresent = 1 << 1;
- const int kExtraIsPresent = 1 << 2;
- const int kNameIsPresent = 1 << 3;
- const int kComentIsPresent = 1 << 4;
- }
-
- namespace NExtraFlags
- {
- enum EEnum
- {
- kMaximum = 2,
- kFastest = 4
- };
- }
-
- namespace NCompressionMethod
- {
- const Byte kDeflate = 8;
- }
-
- namespace NHostOS
- {
- enum EEnum
- {
- kFAT = 0, // filesystem used by MS-DOS, OS/2, Win32
- // pkzip 2.50 (FAT / VFAT / FAT32 file systems)
- kAMIGA = 1,
- kVMS = 2, // VAX/VMS
- kUnix = 3,
- kVM_CMS = 4,
- kAtari = 5, // what if it's a minix filesystem? [cjh]
- kHPFS = 6, // filesystem used by OS/2 (and NT 3.x)
- kMac = 7,
- kZ_System = 8,
- kCPM = 9,
- kTOPS20 = 10, // pkzip 2.50 NTFS
- kNTFS = 11, // filesystem used by Windows NT
- kQDOS = 12, // SMS/QDOS
- kAcorn = 13, // Archimedes Acorn RISC OS
- kVFAT = 14, // filesystem used by Windows 95, NT
- kMVS = 15,
- kBeOS = 16, // hybrid POSIX/database filesystem
- // BeBOX or PowerMac
- kTandem = 17,
- kTHEOS = 18,
-
- kUnknown = 255
- };
- const int kNumHostSystems = 19;
- }
-}
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipIn.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipIn.cpp
deleted file mode 100644
index b29f10e08..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipIn.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-// Archive/GZipIn.cpp
-
-#include "StdAfx.h"
-
-#include "GZipIn.h"
-
-#include "Common/Defs.h"
-#include "Common/MyCom.h"
-#include "Windows/Defs.h"
-
-#include "../../Common/StreamUtils.h"
-
-extern "C"
-{
- #include "../../../../C/7zCrc.h"
-}
-
-namespace NArchive {
-namespace NGZip {
-
-HRESULT CInArchive::ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size)
-{
- RINOK(ReadStream_FALSE(inStream, data, size));
- m_Position += size;
- return S_OK;
-}
-
-HRESULT CInArchive::ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc)
-{
- RINOK(ReadBytes(inStream, &value, 1));
- crc = CRC_UPDATE_BYTE(crc, value);
- return S_OK;
-}
-
-HRESULT CInArchive::ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc)
-{
- value = 0;
- for (int i = 0; i < 2; i++)
- {
- Byte b;
- RINOK(ReadByte(inStream, b, crc));
- value |= (UInt16(b) << (8 * i));
- }
- return S_OK;
-}
-
-HRESULT CInArchive::ReadUInt32(ISequentialInStream *inStream, UInt32 &value, UInt32 &crc)
-{
- value = 0;
- for (int i = 0; i < 4; i++)
- {
- Byte b;
- RINOK(ReadByte(inStream, b, crc));
- value |= (UInt32(b) << (8 * i));
- }
- return S_OK;
-}
-
-HRESULT CInArchive::ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, UInt32 &crc)
-{
- resString.Empty();
- for (;;)
- {
- Byte c;
- RINOK(ReadByte(inStream, c, crc));
- if (c == 0)
- return S_OK;
- resString += char(c);
- }
-}
-
-HRESULT CInArchive::ReadHeader(ISequentialInStream *inStream, CItem &item)
-{
- item.Clear();
- m_Position = 0;
-
- UInt16 signature;
- UInt32 crc = CRC_INIT_VAL;;
- RINOK(ReadUInt16(inStream, signature, crc));
- if (signature != kSignature)
- return S_FALSE;
-
- RINOK(ReadByte(inStream, item.CompressionMethod, crc));
- RINOK(ReadByte(inStream, item.Flags, crc));
- RINOK(ReadUInt32(inStream, item.Time, crc));
- RINOK(ReadByte(inStream, item.ExtraFlags, crc));
- RINOK(ReadByte(inStream, item.HostOS, crc));
-
- if (item.ExtraFieldIsPresent())
- {
- UInt16 extraSize;
- RINOK(ReadUInt16(inStream, extraSize, crc));
- item.Extra.SetCapacity(extraSize);
- RINOK(ReadBytes(inStream, item.Extra, extraSize));
- crc = CrcUpdate(crc, item.Extra, extraSize);
- }
- if (item.NameIsPresent())
- RINOK(ReadZeroTerminatedString(inStream, item.Name, crc));
- if (item.CommentIsPresent())
- RINOK(ReadZeroTerminatedString(inStream, item.Comment, crc));
- if (item.HeaderCRCIsPresent())
- {
- UInt16 headerCRC;
- UInt32 dummy = 0;
- RINOK(ReadUInt16(inStream, headerCRC, dummy));
- if ((UInt16)CRC_GET_DIGEST(crc) != headerCRC)
- return S_FALSE;
- }
- return S_OK;
-}
-
-HRESULT CInArchive::ReadPostHeader(ISequentialInStream *inStream, CItem &item)
-{
- UInt32 dummy = 0;
- RINOK(ReadUInt32(inStream, item.FileCRC, dummy));
- return ReadUInt32(inStream, item.UnPackSize32, dummy);
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipIn.h b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipIn.h
deleted file mode 100644
index 1204d667c..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipIn.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Archive/GZipIn.h
-
-#ifndef __ARCHIVE_GZIP_IN_H
-#define __ARCHIVE_GZIP_IN_H
-
-#include "GZipHeader.h"
-#include "GZipItem.h"
-#include "../../IStream.h"
-
-namespace NArchive {
-namespace NGZip {
-
-class CInArchive
-{
- UInt64 m_Position;
-
- HRESULT ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size);
- HRESULT ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, UInt32 &crc);
- HRESULT ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc);
- HRESULT ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc);
- HRESULT ReadUInt32(ISequentialInStream *inStream, UInt32 &value, UInt32 &crc);
-public:
- HRESULT ReadHeader(ISequentialInStream *inStream, CItem &item);
- HRESULT ReadPostHeader(ISequentialInStream *inStream, CItem &item);
- UInt64 GetOffset() const { return m_Position; }
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipItem.h b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipItem.h
deleted file mode 100644
index 50eaef8a8..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipItem.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Archive/GZipItem.h
-
-#ifndef __ARCHIVE_GZIP_ITEM_H
-#define __ARCHIVE_GZIP_ITEM_H
-
-#include "Common/Types.h"
-#include "Common/MyString.h"
-#include "Common/Buffer.h"
-
-namespace NArchive {
-namespace NGZip {
-
-class CItem
-{
-private:
- bool TestFlag(Byte flag) const { return ((Flags & flag) != 0); }
-public:
- Byte CompressionMethod;
- Byte Flags;
- UInt32 Time;
- Byte ExtraFlags;
- Byte HostOS;
- UInt32 FileCRC;
- UInt32 UnPackSize32;
-
- AString Name;
- AString Comment;
- CByteBuffer Extra;
-
- bool IsText() const
- { return TestFlag(NFileHeader::NFlags::kDataIsText); }
- bool HeaderCRCIsPresent() const
- { return TestFlag(NFileHeader::NFlags::kHeaderCRCIsPresent); }
- bool ExtraFieldIsPresent() const
- { return TestFlag(NFileHeader::NFlags::kExtraIsPresent); }
- bool NameIsPresent() const
- { return TestFlag(NFileHeader::NFlags::kNameIsPresent); }
- bool CommentIsPresent() const
- { return TestFlag(NFileHeader::NFlags::kComentIsPresent); }
-
- void SetNameIsPresentFlag(bool nameIsPresent)
- {
- if (nameIsPresent)
- Flags |= NFileHeader::NFlags::kNameIsPresent;
- else
- Flags &= (~NFileHeader::NFlags::kNameIsPresent);
- }
-
- void Clear()
- {
- Name.Empty();
- Comment.Empty();;
- Extra.SetCapacity(0);
- }
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipRegister.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipRegister.cpp
deleted file mode 100644
index 0c1065088..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipRegister.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// GZipRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "GZipHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NGZip::CHandler; }
-#ifndef EXTRACT_ONLY
-static IOutArchive *CreateArcOut() { return new NArchive::NGZip::CHandler; }
-#else
-#define CreateArcOut 0
-#endif
-
-static CArcInfo g_ArcInfo =
- { L"GZip", L"gz gzip tgz tpz", L"* * .tar .tar", 0xEF, { 0x1F, 0x8B, 8 }, 3, true, CreateArc, CreateArcOut };
-
-REGISTER_ARC(GZip)
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipUpdate.h b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipUpdate.h
deleted file mode 100644
index 59115ba2d..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/GZipUpdate.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// GZip/Update.h
-
-#ifndef __GZIP_UPDATE_H
-#define __GZIP_UPDATE_H
-
-#include "../IArchive.h"
-
-#include "../../Common/CreateCoder.h"
-
-#ifndef EXTRACT_ONLY
-#include "GZipOut.h"
-#endif
-#include "GZipItem.h"
-
-namespace NArchive {
-namespace NGZip {
-
-struct CCompressionMethodMode
-{
- UInt32 NumPasses;
- UInt32 NumFastBytes;
- UInt32 Algo;
- bool NumMatchFinderCyclesDefined;
- UInt32 NumMatchFinderCycles;
-};
-
-HRESULT UpdateArchive(
- DECL_EXTERNAL_CODECS_LOC_VARS
- IInStream *inStream,
- UInt64 unpackSize,
- ISequentialOutStream *outStream,
- const CItem &newItem,
- const CCompressionMethodMode &compressionMethod,
- int indexInClient,
- IArchiveUpdateCallback *updateCallback);
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/StdAfx.h b/desmume/src/windows/7z/CPP/7zip/Archive/GZip/StdAfx.h
deleted file mode 100644
index 83fdd22d5..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/GZip/StdAfx.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/IArchive.h b/desmume/src/windows/7z/CPP/7zip/Archive/IArchive.h
deleted file mode 100644
index 2ab476324..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/IArchive.h
+++ /dev/null
@@ -1,237 +0,0 @@
-// IArchive.h
-
-#ifndef __IARCHIVE_H
-#define __IARCHIVE_H
-
-#include "../IStream.h"
-#include "../IProgress.h"
-#include "../PropID.h"
-
-#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)
-#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)
-
-namespace NFileTimeType
-{
- enum EEnum
- {
- kWindows,
- kUnix,
- kDOS
- };
-}
-
-namespace NArchive
-{
- enum
- {
- kName = 0,
- kClassID,
- kExtension,
- kAddExtension,
- kUpdate,
- kKeepName,
- kStartSignature,
- kFinishSignature,
- kAssociate
- };
-
- namespace NExtract
- {
- namespace NAskMode
- {
- enum
- {
- kExtract = 0,
- kTest,
- kSkip
- };
- }
- namespace NOperationResult
- {
- enum
- {
- kOK = 0,
- kUnSupportedMethod,
- kDataError,
- kCRCError
- };
- }
- }
- namespace NUpdate
- {
- namespace NOperationResult
- {
- enum
- {
- kOK = 0,
- kError
- };
- }
- }
-}
-
-#define INTERFACE_IArchiveOpenCallback(x) \
- STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \
- STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \
-
-ARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)
-{
- INTERFACE_IArchiveOpenCallback(PURE);
-};
-
-
-#define INTERFACE_IArchiveExtractCallback(x) \
- INTERFACE_IProgress(x) \
- /* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \
- STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode) x; \
- STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \
- STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \
-
-ARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)
-{
- INTERFACE_IArchiveExtractCallback(PURE)
-};
-
-
-#define INTERFACE_IArchiveOpenVolumeCallback(x) \
- STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \
- STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \
-
-ARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)
-{
- INTERFACE_IArchiveOpenVolumeCallback(PURE);
-};
-
-
-ARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)
-{
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;
-};
-
-
-ARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)
-{
- STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;
-};
-
-
-/*
-IInArchive::Extract:
- indices must be sorted
- numItems = 0xFFFFFFFF means "all files"
- testMode != 0 means "test files without writing to outStream"
-*/
-
-#define INTERFACE_IInArchive(x) \
- STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \
- STDMETHOD(Close)() x; \
- STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \
- STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \
- STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \
- STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \
- STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \
- STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \
- STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \
- STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;
-
-ARCHIVE_INTERFACE(IInArchive, 0x60)
-{
- INTERFACE_IInArchive(PURE)
- virtual ~IInArchive() {}
-};
-
-
-#define INTERFACE_IArchiveUpdateCallback(x) \
- INTERFACE_IProgress(x); \
- STDMETHOD(GetUpdateItemInfo)(UInt32 index, \
- Int32 *newData, /*1 - new data, 0 - old data */ \
- Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \
- UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \
- ) x; \
- STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \
- STDMETHOD(SetOperationResult)(Int32 operationResult) x; \
-
-ARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)
-{
- INTERFACE_IArchiveUpdateCallback(PURE);
-};
-
-#define INTERFACE_IArchiveUpdateCallback2(x) \
- INTERFACE_IArchiveUpdateCallback(x) \
- STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \
- STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \
-
-ARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)
-{
- INTERFACE_IArchiveUpdateCallback2(PURE);
-};
-
-
-#ifndef EXTRACT_ONLY
-#define INTERFACE_IOutArchive(x) \
- STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \
- STDMETHOD(GetFileTimeType)(UInt32 *type) x;
-#else
-#define INTERFACE_IOutArchive(x)
-#endif
-
-ARCHIVE_INTERFACE(IOutArchive, 0xA0)
-{
-#ifndef EXTRACT_ONLY
- INTERFACE_IOutArchive(PURE)
-#endif
-};
-
-
-ARCHIVE_INTERFACE(ISetProperties, 0x03)
-{
-#ifndef EXTRACT_ONLY
- STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;
-#endif
-};
-
-
-#define IMP_IInArchive_GetProp(k) \
- (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \
- { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \
- const STATPROPSTG &srcItem = k[index]; \
- *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \
-
-#define IMP_IInArchive_GetProp_WITH_NAME(k) \
- (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \
- { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \
- const STATPROPSTG &srcItem = k[index]; \
- *propID = srcItem.propid; *varType = srcItem.vt; \
- if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \
-
-#define IMP_IInArchive_Props \
- STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \
- { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \
- STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)
-
-#define IMP_IInArchive_Props_WITH_NAME \
- STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \
- { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \
- STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)
-
-
-#define IMP_IInArchive_ArcProps \
- STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
- { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \
- STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)
-
-#define IMP_IInArchive_ArcProps_WITH_NAME \
- STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
- { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \
- STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)
-
-#define IMP_IInArchive_ArcProps_NO \
- STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
- { *numProperties = 0; return S_OK; } \
- STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \
- { return E_NOTIMPL; } \
- STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \
- { value->vt = VT_EMPTY; return S_OK; }
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhCRC.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhCRC.cpp
deleted file mode 100644
index 0afeb7102..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhCRC.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// LzhCRC.cpp
-
-#include "StdAfx.h"
-
-#include "LzhCRC.h"
-
-namespace NArchive {
-namespace NLzh {
-
-static const UInt16 kCRCPoly = 0xA001;
-
-UInt16 CCRC::Table[256];
-
-void CCRC::InitTable()
-{
- for (UInt32 i = 0; i < 256; i++)
- {
- UInt32 r = i;
- for (int j = 0; j < 8; j++)
- if (r & 1)
- r = (r >> 1) ^ kCRCPoly;
- else
- r >>= 1;
- CCRC::Table[i] = (UInt16)r;
- }
-}
-
-class CCRCTableInit
-{
-public:
- CCRCTableInit() { CCRC::InitTable(); }
-} g_CRCTableInit;
-
-void CCRC::Update(const void *data, size_t size)
-{
- UInt16 v = _value;
- const Byte *p = (const Byte *)data;
- for (; size > 0; size--, p++)
- v = (UInt16)(Table[((Byte)(v)) ^ *p] ^ (v >> 8));
- _value = v;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhCRC.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhCRC.h
deleted file mode 100644
index aaa647baf..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhCRC.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// LzhCRC.h
-
-#ifndef __LZH_CRC_H
-#define __LZH_CRC_H
-
-#include
-#include "Common/Types.h"
-
-namespace NArchive {
-namespace NLzh {
-
-class CCRC
-{
- UInt16 _value;
-public:
- static UInt16 Table[256];
- static void InitTable();
-
- CCRC(): _value(0){};
- void Init() { _value = 0; }
- void Update(const void *data, size_t size);
- UInt16 GetDigest() const { return _value; }
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHandler.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHandler.cpp
deleted file mode 100644
index b15ffd1bc..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHandler.cpp
+++ /dev/null
@@ -1,387 +0,0 @@
-// LzhHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Common/Defs.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "LzhHandler.h"
-#include "LzhOutStreamWithCRC.h"
-
-#include "../../ICoder.h"
-
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/ProgressUtils.h"
-
-#include "../../Compress/CopyCoder.h"
-#include "../../Compress/LzhDecoder.h"
-
-#include "../Common/ItemNameUtils.h"
-
-using namespace NWindows;
-using namespace NTime;
-
-namespace NArchive {
-namespace NLzh{
-
-struct COsPair
-{
- Byte Id;
- const wchar_t *Name;
-};
-
-COsPair g_OsPairs[] =
-{
- { 'M', L"MS-DOS" },
- { '2', L"OS/2" },
- { '9', L"OS9" },
- { 'K', L"OS/68K" },
- { '3', L"OS/386" },
- { 'H', L"HUMAN" },
- { 'U', L"UNIX" },
- { 'C', L"CP/M" },
- { 'F', L"FLEX" },
- { 'm', L"Mac" },
- { 'R', L"Runser" },
- { 'T', L"TownsOS" },
- { 'X', L"XOSK" },
- { 'w', L"Windows95" },
- { 'W', L"WindowsNT" },
- { 0, L"MS-DOS" },
- { 'J', L"Java VM" }
-};
-
-const wchar_t *kUnknownOS = L"Unknown";
-
-const int kNumHostOSes = sizeof(g_OsPairs) / sizeof(g_OsPairs[0]);
-
-static const wchar_t *GetOS(Byte osId)
-{
- for (int i = 0; i < kNumHostOSes; i++)
- if (g_OsPairs[i].Id == osId)
- return g_OsPairs[i].Name;
- return kUnknownOS;
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidAttrib, VT_UI4},
-
- // { NULL, kpidCommented, VT_BOOL},
-
- { NULL, kpidCRC, VT_UI4},
-
- { NULL, kpidMethod, VT_UI1},
- { NULL, kpidHostOS, VT_BSTR}
-
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-CHandler::CHandler() {}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _items.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CItemEx &item = _items[index];
- switch(propID)
- {
- case kpidPath:
- {
- UString s = NItemName::WinNameToOSName(MultiByteToUnicodeString(item.GetName(), CP_OEMCP));
- if (!s.IsEmpty())
- {
- if (s[s.Length() - 1] == WCHAR_PATH_SEPARATOR)
- s.Delete(s.Length() - 1);
- prop = s;
- }
- break;
- }
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize: prop = item.Size; break;
- case kpidPackSize: prop = item.PackSize; break;
- case kpidCRC: prop = (UInt32)item.CRC; break;
- case kpidHostOS: prop = GetOS(item.OsId); break;
- case kpidMTime:
- {
- FILETIME utcFileTime;
- UInt32 unixTime;
- if (item.GetUnixTime(unixTime))
- NTime::UnixTimeToFileTime(unixTime, utcFileTime);
- else
- {
- FILETIME localFileTime;
- if (DosTimeToFileTime(item.ModifiedTime, localFileTime))
- {
- if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
- }
- else
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
- }
- prop = utcFileTime;
- break;
- }
- /*
- case kpidAttrib: prop = (UInt32)item.Attributes; break;
- case kpidCommented: prop = item.IsCommented(); break;
- */
- case kpidMethod:
- {
- wchar_t method2[kMethodIdSize + 1];
- method2[kMethodIdSize] = 0;
- for (int i = 0; i < kMethodIdSize; i++)
- method2[i] = item.Method[i];
- prop = method2;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-/*
-class CProgressImp: public CProgressVirt
-{
-public:
- CMyComPtr Callback;
- STDMETHOD(SetCompleted)(const UInt64 *numFiles);
-};
-
-STDMETHODIMP CProgressImp::SetCompleted(const UInt64 *numFiles)
-{
- if (Callback)
- return Callback->SetCompleted(numFiles, NULL);
- return S_OK;
-}
-*/
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- try
- {
- _items.Clear();
- CInArchive archive;
-
- UInt64 endPos = 0;
- bool needSetTotal = true;
-
- if (callback != NULL)
- {
- RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
- RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
- }
-
- RINOK(archive.Open(stream));
- for (;;)
- {
- CItemEx item;
- bool filled;
- HRESULT result = archive.GetNextItem(filled, item);
- if (result == S_FALSE)
- return S_FALSE;
- if (result != S_OK)
- return S_FALSE;
- if (!filled)
- break;
- _items.Add(item);
- archive.Skeep(item.PackSize);
- if (callback != NULL)
- {
- if (needSetTotal)
- {
- RINOK(callback->SetTotal(NULL, &endPos));
- needSetTotal = false;
- }
- if (_items.Size() % 100 == 0)
- {
- UInt64 numFiles = _items.Size();
- UInt64 numBytes = item.DataPosition;
- RINOK(callback->SetCompleted(&numFiles, &numBytes));
- }
- }
- }
- if (_items.IsEmpty())
- return S_FALSE;
-
- _stream = stream;
- }
- catch(...)
- {
- return S_FALSE;
- }
- COM_TRY_END
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _items.Clear();
- _stream.Release();
- return S_OK;
-}
-
-
-
-//////////////////////////////////////
-// CHandler::DecompressItems
-
-STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
- Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool testMode = (testModeSpec != 0);
- UInt64 totalUnPacked = 0, totalPacked = 0;
- bool allFilesMode = (numItems == UInt32(-1));
- if (allFilesMode)
- numItems = _items.Size();
- if(numItems == 0)
- return S_OK;
- UInt32 i;
- for(i = 0; i < numItems; i++)
- {
- const CItemEx &item = _items[allFilesMode ? i : indices[i]];
- totalUnPacked += item.Size;
- totalPacked += item.PackSize;
- }
- extractCallback->SetTotal(totalUnPacked);
-
- UInt64 currentTotalUnPacked = 0, currentTotalPacked = 0;
- UInt64 currentItemUnPacked, currentItemPacked;
-
- NCompress::NLzh::NDecoder::CCoder *lzhDecoderSpec = 0;
- CMyComPtr lzhDecoder;
- CMyComPtr lzh1Decoder;
- CMyComPtr arj2Decoder;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr inStream(streamSpec);
- streamSpec->SetStream(_stream);
-
- for(i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked,
- currentTotalPacked += currentItemPacked)
- {
- currentItemUnPacked = 0;
- currentItemPacked = 0;
-
- lps->InSize = currentTotalPacked;
- lps->OutSize = currentTotalUnPacked;
- RINOK(lps->SetCur());
-
- CMyComPtr realOutStream;
- Int32 askMode;
- askMode = testMode ? NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- const CItemEx &item = _items[index];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- if (item.IsDir())
- {
- // if (!testMode)
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- }
- continue;
- }
-
- if (!testMode && (!realOutStream))
- continue;
-
- RINOK(extractCallback->PrepareOperation(askMode));
- currentItemUnPacked = item.Size;
- currentItemPacked = item.PackSize;
-
- {
- COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
- CMyComPtr outStream(outStreamSpec);
- outStreamSpec->Init(realOutStream);
- realOutStream.Release();
-
- UInt64 pos;
- _stream->Seek(item.DataPosition, STREAM_SEEK_SET, &pos);
-
- streamSpec->Init(item.PackSize);
-
- HRESULT result = S_OK;
- Int32 opRes = NExtract::NOperationResult::kOK;
-
- if (item.IsCopyMethod())
- {
- result = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
- if (result == S_OK && copyCoderSpec->TotalSize != item.PackSize)
- result = S_FALSE;
- }
- else if (item.IsLh4GroupMethod())
- {
- if (!lzhDecoder)
- {
- lzhDecoderSpec = new NCompress::NLzh::NDecoder::CCoder;
- lzhDecoder = lzhDecoderSpec;
- }
- lzhDecoderSpec->SetDictionary(item.GetNumDictBits());
- result = lzhDecoder->Code(inStream, outStream, NULL, ¤tItemUnPacked, progress);
- }
- /*
- else if (item.IsLh1GroupMethod())
- {
- if (!lzh1Decoder)
- {
- lzh1DecoderSpec = new NCompress::NLzh1::NDecoder::CCoder;
- lzh1Decoder = lzh1DecoderSpec;
- }
- lzh1DecoderSpec->SetDictionary(item.GetNumDictBits());
- result = lzh1Decoder->Code(inStream, outStream, NULL, ¤tItemUnPacked, progress);
- }
- */
- else
- opRes = NExtract::NOperationResult::kUnSupportedMethod;
-
- if (opRes == NExtract::NOperationResult::kOK)
- {
- if (result == S_FALSE)
- opRes = NExtract::NOperationResult::kDataError;
- else
- {
- RINOK(result);
- if (outStreamSpec->GetCRC() != item.CRC)
- opRes = NExtract::NOperationResult::kCRCError;
- }
- }
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(opRes));
- }
- }
- return S_OK;
- COM_TRY_END
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHandler.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHandler.h
deleted file mode 100644
index 6d31df534..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHandler.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// LzhHandler.h
-
-#ifndef __LZH_HANDLER_H
-#define __LZH_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-#include "LzhIn.h"
-
-namespace NArchive {
-namespace NLzh {
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP1(IInArchive)
-
- INTERFACE_IInArchive(;)
-
- CHandler();
-private:
- CObjectVector _items;
- CMyComPtr _stream;
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHeader.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHeader.h
deleted file mode 100644
index 1c758a14b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhHeader.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// Archive/Lzh/Header.h
-
-#ifndef __ARCHIVE_LZH_HEADER_H
-#define __ARCHIVE_LZH_HEADER_H
-
-#include "Common/Types.h"
-
-namespace NArchive {
-namespace NLzh {
-
-const int kMethodIdSize = 5;
-
-const Byte kExtIdFileName = 0x01;
-const Byte kExtIdDirName = 0x02;
-const Byte kExtIdUnixTime = 0x54;
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhIn.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhIn.cpp
deleted file mode 100644
index 56b62a943..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhIn.cpp
+++ /dev/null
@@ -1,172 +0,0 @@
-// Archive/LzhIn.cpp
-
-#include "StdAfx.h"
-
-#include "Common/StringConvert.h"
-#include "Common/Buffer.h"
-
-#include "../../Common/StreamUtils.h"
-
-#include "LzhIn.h"
-
-namespace NArchive {
-namespace NLzh {
-
-HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
-{
- size_t realProcessedSize = size;
- RINOK(ReadStream(m_Stream, data, &realProcessedSize));
- processedSize = (UInt32)realProcessedSize;
- m_Position += processedSize;
- return S_OK;
-}
-
-HRESULT CInArchive::CheckReadBytes(void *data, UInt32 size)
-{
- UInt32 processedSize;
- RINOK(ReadBytes(data, size, processedSize));
- return (processedSize == size) ? S_OK: S_FALSE;
-}
-
-HRESULT CInArchive::Open(IInStream *inStream)
-{
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_Position));
- m_Stream = inStream;
- return S_OK;
-}
-
-static const Byte *ReadUInt32(const Byte *p, UInt32 &v)
-{
- v = 0;
- for (int i = 0; i < 4; i++)
- v |= ((UInt32)(*p++) << (i * 8));
- return p;
-}
-
-static const Byte *ReadUInt16(const Byte *p, UInt16 &v)
-{
- v = 0;
- for (int i = 0; i < 2; i++)
- v |= ((UInt16)(*p++) << (i * 8));
- return p;
-}
-
-static const Byte *ReadString(const Byte *p, size_t size, AString &s)
-{
- s.Empty();
- for (size_t i = 0; i < size; i++)
- {
- char c = p[i];
- if (c == 0)
- break;
- s += c;
- }
- return p + size;
-}
-
-static Byte CalcSum(const Byte *data, size_t size)
-{
- Byte sum = 0;
- for (size_t i = 0; i < size; i++)
- sum = (Byte)(sum + data[i]);
- return sum;
-}
-
-HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
-{
- filled = false;
-
- UInt32 processedSize;
- Byte startHeader[2];
- RINOK(ReadBytes(startHeader, 2, processedSize))
- if (processedSize == 0)
- return S_OK;
- if (processedSize == 1)
- return (startHeader[0] == 0) ? S_OK: S_FALSE;
- if (startHeader[0] == 0 && startHeader[1] == 0)
- return S_OK;
-
- Byte header[256];
- const UInt32 kBasicPartSize = 22;
- RINOK(ReadBytes(header, kBasicPartSize, processedSize));
- if (processedSize != kBasicPartSize)
- return (startHeader[0] == 0) ? S_OK: S_FALSE;
-
- const Byte *p = header;
- memmove(item.Method, p, kMethodIdSize);
- if (!item.IsValidMethod())
- return S_OK;
- p += kMethodIdSize;
- p = ReadUInt32(p, item.PackSize);
- p = ReadUInt32(p, item.Size);
- p = ReadUInt32(p, item.ModifiedTime);
- item.Attributes = *p++;
- item.Level = *p++;
- if (item.Level > 2)
- return S_FALSE;
- UInt32 headerSize;
- if (item.Level < 2)
- {
- headerSize = startHeader[0];
- if (headerSize < kBasicPartSize)
- return S_FALSE;
- UInt32 remain = headerSize - kBasicPartSize;
- RINOK(CheckReadBytes(header + kBasicPartSize, remain));
- if (startHeader[1] != CalcSum(header, headerSize))
- return S_FALSE;
- size_t nameLength = *p++;
- if ((p - header) + nameLength + 2 > headerSize)
- return S_FALSE;
- p = ReadString(p, nameLength, item.Name);
- }
- else
- headerSize = startHeader[0] | ((UInt32)startHeader[1] << 8);
- p = ReadUInt16(p, item.CRC);
- if (item.Level != 0)
- {
- if (item.Level == 2)
- {
- RINOK(CheckReadBytes(header + kBasicPartSize, 2));
- }
- if ((size_t)(p - header) + 3 > headerSize)
- return S_FALSE;
- item.OsId = *p++;
- UInt16 nextSize;
- p = ReadUInt16(p, nextSize);
- while (nextSize != 0)
- {
- if (nextSize < 3)
- return S_FALSE;
- if (item.Level == 1)
- {
- if (item.PackSize < nextSize)
- return S_FALSE;
- item.PackSize -= nextSize;
- }
- CExtension ext;
- RINOK(CheckReadBytes(&ext.Type, 1))
- nextSize -= 3;
- ext.Data.SetCapacity(nextSize);
- RINOK(CheckReadBytes((Byte *)ext.Data, nextSize))
- item.Extensions.Add(ext);
- Byte hdr2[2];
- RINOK(CheckReadBytes(hdr2, 2));
- ReadUInt16(hdr2, nextSize);
- }
- }
- item.DataPosition = m_Position;
- filled = true;
- return S_OK;
-}
-
-HRESULT CInArchive::Skeep(UInt64 numBytes)
-{
- UInt64 newPostion;
- RINOK(m_Stream->Seek(numBytes, STREAM_SEEK_CUR, &newPostion));
- m_Position += numBytes;
- if (m_Position != newPostion)
- return E_FAIL;
- return S_OK;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhIn.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhIn.h
deleted file mode 100644
index a8c639801..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhIn.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Archive/LzhIn.h
-
-#ifndef __ARCHIVE_LZHIN_H
-#define __ARCHIVE_LZHIN_H
-
-#include "Common/MyCom.h"
-#include "../../IStream.h"
-
-#include "LzhItem.h"
-
-namespace NArchive {
-namespace NLzh {
-
-class CInArchive
-{
- CMyComPtr m_Stream;
- UInt64 m_Position;
-
- HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
- HRESULT CheckReadBytes(void *data, UInt32 size);
-public:
- HRESULT Open(IInStream *inStream);
- HRESULT GetNextItem(bool &filled, CItemEx &itemInfo);
- HRESULT Skeep(UInt64 numBytes);
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhItem.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhItem.h
deleted file mode 100644
index ca85a5153..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhItem.h
+++ /dev/null
@@ -1,172 +0,0 @@
-// Archive/LzhItem.h
-
-#ifndef __ARCHIVE_LZH_ITEM_H
-#define __ARCHIVE_LZH_ITEM_H
-
-#include "Common/Types.h"
-#include "Common/MyString.h"
-#include "Common/Buffer.h"
-#include "LzhHeader.h"
-
-namespace NArchive {
-namespace NLzh {
-
-struct CExtension
-{
- Byte Type;
- CByteBuffer Data;
- AString GetString() const
- {
- AString s;
- for (size_t i = 0; i < Data.GetCapacity(); i++)
- {
- char c = (char)Data[i];
- if (c == 0)
- break;
- s += c;
- }
- return s;
- }
-};
-
-struct CItem
-{
-public:
- AString Name;
- Byte Method[kMethodIdSize];
- UInt32 PackSize;
- UInt32 Size;
- UInt32 ModifiedTime;
- Byte Attributes;
- Byte Level;
- UInt16 CRC;
- Byte OsId;
- CObjectVector Extensions;
-
- bool IsValidMethod() const { return (Method[0] == '-' && Method[1] == 'l' && Method[4] == '-'); }
- bool IsLhMethod() const {return (IsValidMethod() && Method[2] == 'h'); }
- bool IsDir() const {return (IsLhMethod() && Method[3] == 'd'); }
-
- bool IsCopyMethod() const
- {
- return (IsLhMethod() && Method[3] == '0') ||
- (IsValidMethod() && Method[2] == 'z' && Method[3] == '4');
- }
-
- bool IsLh1GroupMethod() const
- {
- if (!IsLhMethod())
- return false;
- switch(Method[3])
- {
- case '1':
- return true;
- }
- return false;
- }
-
- bool IsLh4GroupMethod() const
- {
- if (!IsLhMethod())
- return false;
- switch(Method[3])
- {
- case '4':
- case '5':
- case '6':
- case '7':
- return true;
- }
- return false;
- }
-
- int GetNumDictBits() const
- {
- if (!IsLhMethod())
- return 0;
- switch(Method[3])
- {
- case '1':
- return 12;
- case '2':
- return 13;
- case '3':
- return 13;
- case '4':
- return 12;
- case '5':
- return 13;
- case '6':
- return 15;
- case '7':
- return 16;
- }
- return 0;
- }
-
- int FindExt(Byte type) const
- {
- for (int i = 0; i < Extensions.Size(); i++)
- if (Extensions[i].Type == type)
- return i;
- return -1;
- }
- bool GetUnixTime(UInt32 &value) const
- {
- int index = FindExt(kExtIdUnixTime);
- if (index < 0)
- {
- if (Level == 2)
- {
- value = ModifiedTime;
- return true;
- }
- return false;
- }
- const Byte *data = (const Byte *)(Extensions[index].Data);
- value = data[0] |
- ((UInt32)data[1] << 8) |
- ((UInt32)data[2] << 16) |
- ((UInt32)data[3] << 24);
- return true;
- }
-
- AString GetDirName() const
- {
- int index = FindExt(kExtIdDirName);
- if (index < 0)
- return AString();
- return Extensions[index].GetString();
- }
-
- AString GetFileName() const
- {
- int index = FindExt(kExtIdFileName);
- if (index < 0)
- return Name;
- return Extensions[index].GetString();
- }
-
- AString GetName() const
- {
- AString dirName = GetDirName();
- dirName.Replace((char)(unsigned char)0xFF, '\\');
- if (!dirName.IsEmpty())
- {
- char c = dirName[dirName.Length() - 1];
- if (c != '\\')
- dirName += '\\';
- }
- return dirName + GetFileName();
- }
-};
-
-class CItemEx: public CItem
-{
-public:
- UInt64 DataPosition;
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.cpp
deleted file mode 100644
index 3cd632aa7..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// LzhOutStreamWithCRC.cpp
-
-#include "StdAfx.h"
-
-#include "LzhOutStreamWithCRC.h"
-
-namespace NArchive {
-namespace NLzh {
-
-STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize;
- HRESULT result;
- if(!_stream)
- {
- realProcessedSize = size;
- result = S_OK;
- }
- else
- result = _stream->Write(data, size, &realProcessedSize);
- _crc.Update(data, realProcessedSize);
- if(processedSize != NULL)
- *processedSize = realProcessedSize;
- return result;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.h
deleted file mode 100644
index eee15d0e2..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhOutStreamWithCRC.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// LzhOutStreamWithCRC.h
-
-#ifndef __LZHOUTSTREAMWITHCRC_H
-#define __LZHOUTSTREAMWITHCRC_H
-
-#include "LzhCRC.h"
-#include "../../../Common/MyCom.h"
-#include "../../IStream.h"
-
-namespace NArchive {
-namespace NLzh {
-
-class COutStreamWithCRC:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-private:
- CCRC _crc;
- CMyComPtr _stream;
-public:
- void Init(ISequentialOutStream *stream)
- {
- _stream = stream;
- _crc.Init();
- }
- void ReleaseStream() { _stream.Release(); }
- UInt32 GetCRC() const { return _crc.GetDigest(); }
- void InitCRC() { _crc.Init(); }
-
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhRegister.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhRegister.cpp
deleted file mode 100644
index b83d2ee6c..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/LzhRegister.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// LzhRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "LzhHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NLzh::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Lzh", L"lzh lha", 0, 6, { '-', 'l' }, 2, false, CreateArc, 0 };
-
-REGISTER_ARC(Lzh)
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/StdAfx.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/StdAfx.h
deleted file mode 100644
index 83fdd22d5..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzh/StdAfx.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp
deleted file mode 100644
index 867bc78ff..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// LzmaArcRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "LzmaHandler.h"
-
-static IInArchive *CreateArc() { return new NArchive::NLzma::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Lzma", L"lzma lzma86", 0, 0xA, {0 }, 0, true, CreateArc, NULL };
-
-REGISTER_ARC(Lzma)
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp
deleted file mode 100644
index 2ab3dbf4b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-// LzmaFiltersDecode.cpp
-
-#include "StdAfx.h"
-
-#include "LzmaFiltersDecode.h"
-
-namespace NArchive {
-namespace NLzma {
-
-static const UInt64 k_LZMA = 0x030101;
-static const UInt64 k_BCJ = 0x03030103;
-
-HRESULT CDecoder::Code(
- DECL_EXTERNAL_CODECS_LOC_VARS
- const CHeader &block,
- ISequentialInStream *inStream, ISequentialOutStream *outStream,
- UInt64 *inProcessedSize, ICompressProgressInfo *progress)
-{
- *inProcessedSize = (UInt64)(Int64)-1;
-
- if (block.FilterMethod > 1)
- return E_NOTIMPL;
-
- if (!_lzmaDecoder)
- {
- RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));
- if (_lzmaDecoder == 0)
- return E_NOTIMPL;
- }
-
- {
- CMyComPtr setDecoderProperties;
- _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
- if (!setDecoderProperties)
- return E_NOTIMPL;
- RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));
- }
-
- bool filteredMode = (block.FilterMethod == 1);
-
- CMyComPtr setOutStream;
-
- if (filteredMode)
- {
- if (!_bcjStream)
- {
- CMyComPtr coder;
- RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));
- if (!coder)
- return E_NOTIMPL;
- coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);
- if (!_bcjStream)
- return E_NOTIMPL;
- }
-
- _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
- if (!setOutStream)
- return E_NOTIMPL;
- RINOK(setOutStream->SetOutStream(outStream));
- outStream = _bcjStream;
- }
-
- const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;
- RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));
-
- if (filteredMode)
- {
- CMyComPtr flush;
- _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);
- if (flush)
- {
- RINOK(flush->Flush());
- }
- RINOK(setOutStream->ReleaseOutStream());
- }
-
- CMyComPtr getInStreamProcessedSize;
- _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);
- if (getInStreamProcessedSize)
- {
- RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));
- }
- return S_OK;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h
deleted file mode 100644
index b966b422a..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// LzmaFiltersDecode.h
-
-#ifndef __LZMA_FILTERS_DECODE_H
-#define __LZMA_FILTERS_DECODE_H
-
-#include "../../Common/CreateCoder.h"
-
-#include "LzmaItem.h"
-
-namespace NArchive {
-namespace NLzma {
-
-class CDecoder
-{
- CMyComPtr _lzmaDecoder;
- CMyComPtr _bcjStream;
-public:
- HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS
- const CHeader &block,
- ISequentialInStream *inStream, ISequentialOutStream *outStream,
- UInt64 *inProcessedSize, ICompressProgressInfo *progress);
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaHandler.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaHandler.cpp
deleted file mode 100644
index 249fd90fa..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaHandler.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-// LzmaHandler.cpp
-
-#include "StdAfx.h"
-
-#include "LzmaHandler.h"
-
-#include "Common/Defs.h"
-#include "Common/StringConvert.h"
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamUtils.h"
-#include "../Common/DummyOutStream.h"
-
-#include "LzmaFiltersDecode.h"
-
-namespace NArchive {
-namespace NLzma {
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMethod, VT_UI1}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = 1;
- return S_OK;
-}
-
-static void ConvertUInt32ToString(UInt32 value, wchar_t *s)
-{
- ConvertUInt64ToString(value, s + MyStringLen(s));
-}
-
-static void DictSizeToString(UInt32 value, wchar_t *s)
-{
- for (int i = 0; i <= 31; i++)
- if ((UInt32(1) << i) == value)
- {
- ConvertUInt32ToString(i, s);
- return;
- }
- wchar_t c = L'b';
- if ((value & ((1 << 20) - 1)) == 0)
- {
- value >>= 20;
- c = L'm';
- }
- else if ((value & ((1 << 10) - 1)) == 0)
- {
- value >>= 10;
- c = L'k';
- }
- ConvertUInt32ToString(value, s);
- int p = MyStringLen(s);
- s[p++] = c;
- s[p++] = L'\0';
-}
-
-static void MyStrCat(wchar_t *d, const wchar_t *s)
-{
- MyStringCopy(d + MyStringLen(d), s);
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- if (index != 0)
- return E_INVALIDARG;
- NWindows::NCOM::CPropVariant propVariant;
- switch(propID)
- {
- case kpidSize:
- if (m_StreamInfo.HasUnpackSize())
- propVariant = (UInt64)m_StreamInfo.UnpackSize;
- break;
- case kpidPackSize:
- propVariant = (UInt64)m_PackSize;
- break;
- case kpidMethod:
- {
- wchar_t s[64];
- s[0] = '\0';
- if (m_StreamInfo.IsThereFilter)
- {
- const wchar_t *f;
- if (m_StreamInfo.FilterMethod == 0)
- f = L"Copy";
- else if (m_StreamInfo.FilterMethod == 1)
- f = L"BCJ";
- else
- f = L"Unknown";
- MyStrCat(s, f);
- MyStrCat(s, L" ");
- }
- MyStrCat(s, L"LZMA:");
- DictSizeToString(m_StreamInfo.GetDicSize(), s);
- propVariant = s;
- break;
- }
- }
- propVariant.Detach(value);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- {
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
-
- HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);
- if (res != S_OK)
- return S_FALSE;
-
- Byte b;
- RINOK(ReadStream_FALSE(inStream, &b, 1));
- if (b != 0)
- return S_FALSE;
-
- UInt64 endPos;
- RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));
- m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();
-
- m_Stream = inStream;
- }
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Close()
-{
- m_Stream.Release();
- return S_OK;
-}
-
-
-STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
- Int32 _aTestMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == UInt32(-1));
- if (!allFilesMode)
- {
- if (numItems == 0)
- return S_OK;
- if (numItems != 1)
- return E_INVALIDARG;
- if (indices[0] != 0)
- return E_INVALIDARG;
- }
-
- bool testMode = (_aTestMode != 0);
-
- RINOK(extractCallback->SetTotal(m_PackSize));
-
- UInt64 currentTotalPacked = 0;
-
- CDummyOutStream *outStreamSpec = new CDummyOutStream;
- CMyComPtr outStream(outStreamSpec);
-
- {
- CMyComPtr realOutStream;
- Int32 askMode = testMode ?
- NArchive::NExtract::NAskMode::kTest :
- NArchive::NExtract::NAskMode::kExtract;
-
- RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
-
- outStreamSpec->SetStream(realOutStream);
- outStreamSpec->Init();
- if(!testMode && !realOutStream)
- return S_OK;
- extractCallback->PrepareOperation(askMode);
- }
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr progress = lps;
- lps->Init(extractCallback, true);
-
- CDecoder decoder;
- RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));
- UInt64 streamPos = m_StreamStartPosition;
- Int32 opRes = NArchive::NExtract::NOperationResult::kOK;
- bool firstItem = true;
- for (;;)
- {
- CHeader st;
- HRESULT result = ReadStreamHeader(m_Stream, st);
- if (result != S_OK)
- {
- if (firstItem)
- return E_FAIL;
- break;
- }
- firstItem = false;
-
- lps->OutSize = outStreamSpec->GetSize();
- lps->InSize = currentTotalPacked;
- RINOK(lps->SetCur());
-
- streamPos += st.GetHeaderSize();
- UInt64 packProcessed;
-
- {
- result = decoder.Code(
- EXTERNAL_CODECS_VARS
- st, m_Stream, outStream, &packProcessed, progress);
- if (result == E_NOTIMPL)
- {
- opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
- break;
- }
- if (result == S_FALSE)
- {
- opRes = NArchive::NExtract::NOperationResult::kDataError;
- break;
- }
- RINOK(result);
- }
-
- if (packProcessed == (UInt64)(Int64)-1)
- break;
- RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));
- currentTotalPacked += packProcessed;
- streamPos += packProcessed;
- }
- outStream.Release();
- return extractCallback->SetOperationResult(opRes);
- COM_TRY_END
-}
-
-IMPL_ISetCompressCodecsInfo
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaHandler.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaHandler.h
deleted file mode 100644
index bbf11a46b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaHandler.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Lzma/Handler.h
-
-#ifndef __GZIP_HANDLER_H
-#define __GZIP_HANDLER_H
-
-#include "Common/MyCom.h"
-
-#include "../IArchive.h"
-#include "../../Common/CreateCoder.h"
-
-#include "LzmaIn.h"
-
-namespace NArchive {
-namespace NLzma {
-
-// const UInt64 k_LZMA = 0x030101;
-
-class CHandler:
- public IInArchive,
- PUBLIC_ISetCompressCodecsInfo
- public CMyUnknownImp
-{
-public:
- MY_QUERYINTERFACE_BEGIN
- MY_QUERYINTERFACE_ENTRY(IInArchive)
- QUERY_ENTRY_ISetCompressCodecsInfo
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- STDMETHOD(Open)(IInStream *inStream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *openArchiveCallback);
- STDMETHOD(Close)();
-
- STDMETHOD(GetNumberOfItems)(UInt32 *numItems);
- STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
- STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback);
-
- STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);
-
- STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);
- STDMETHOD(GetPropertyInfo)(UInt32 index,
- BSTR *name, PROPID *propID, VARTYPE *varType);
-
- STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);
- STDMETHOD(GetArchivePropertyInfo)(UInt32 index,
- BSTR *name, PROPID *propID, VARTYPE *varType);
-
- UString GetMethodString();
-public:
- CHandler() { }
-
-private:
- CHeader m_StreamInfo;
- UInt64 m_StreamStartPosition;
- UInt64 m_PackSize;
-
- CMyComPtr m_Stream;
-
- DECL_EXTERNAL_CODECS_VARS
-
- DECL_ISetCompressCodecsInfo
-
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaIn.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaIn.cpp
deleted file mode 100644
index 7d2475c75..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaIn.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// Archive/LzmaIn.cpp
-
-#include "StdAfx.h"
-
-#include "LzmaIn.h"
-
-#include "../../Common/StreamUtils.h"
-
-namespace NArchive {
-namespace NLzma {
-
-static bool CheckDictSize(const Byte *p)
-{
- UInt32 dicSize = GetUi32(p);
- int i;
- for (i = 1; i <= 30; i++)
- if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))
- return true;
- return false;
-}
-
-HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)
-{
- Byte sig[5 + 9];
- RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));
-
- const Byte kMaxProp0Val = 5 * 5 * 9 - 1;
- if (sig[0] > kMaxProp0Val)
- return S_FALSE;
-
- for (int i = 0; i < 5; i++)
- block.LzmaProps[i] = sig[i];
-
- block.IsThereFilter = false;
- block.FilterMethod = 0;
-
- if (!CheckDictSize(sig + 1))
- {
- if (sig[0] > 1 || sig[1] > kMaxProp0Val)
- return S_FALSE;
- block.IsThereFilter = true;
- block.FilterMethod = sig[0];
- for (int i = 0; i < 5; i++)
- block.LzmaProps[i] = sig[i + 1];
- if (!CheckDictSize(block.LzmaProps + 1))
- return S_FALSE;
- RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));
- }
- UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);
- block.UnpackSize = GetUi64(sig + unpOffset);
- if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))
- return S_FALSE;
- return S_OK;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaIn.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaIn.h
deleted file mode 100644
index 6f5c24c0e..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaIn.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// Archive/LzmaIn.h
-
-#ifndef __ARCHIVE_LZMA_IN_H
-#define __ARCHIVE_LZMA_IN_H
-
-#include "LzmaItem.h"
-#include "../../IStream.h"
-
-namespace NArchive {
-namespace NLzma {
-
-HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaItem.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaItem.h
deleted file mode 100644
index 1bfadf727..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/LzmaItem.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Archive/LzmaItem.h
-
-#ifndef __ARCHIVE_LZMA_ITEM_H
-#define __ARCHIVE_LZMA_ITEM_H
-
-#include "Common/Types.h"
-
-#include "../../../../C/CpuArch.h"
-
-namespace NArchive {
-namespace NLzma {
-
-struct CHeader
-{
- UInt64 UnpackSize;
- bool IsThereFilter;
- Byte FilterMethod;
- Byte LzmaProps[5];
-
- UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }
- bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1); }
- unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/StdAfx.h b/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/StdAfx.h
deleted file mode 100644
index 83fdd22d5..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Lzma/StdAfx.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHandler.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHandler.cpp
deleted file mode 100644
index 3bd17b6db..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHandler.cpp
+++ /dev/null
@@ -1,835 +0,0 @@
-// RarHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../../IPassword.h"
-
-#include "../../Common/CreateCoder.h"
-#include "../../Common/FilterCoder.h"
-#include "../../Common/MethodId.h"
-#include "../../Common/ProgressUtils.h"
-
-#include "../../Compress/CopyCoder.h"
-
-#include "../../Crypto/Rar20Crypto.h"
-#include "../../Crypto/RarAes.h"
-
-#include "../Common/ItemNameUtils.h"
-#include "../Common/OutStreamWithCRC.h"
-
-#include "RarHandler.h"
-
-using namespace NWindows;
-using namespace NTime;
-
-namespace NArchive {
-namespace NRar {
-
-static const wchar_t *kHostOS[] =
-{
- L"MS DOS",
- L"OS/2",
- L"Win32",
- L"Unix",
- L"Mac OS",
- L"BeOS"
-};
-
-static const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
-
-static const wchar_t *kUnknownOS = L"Unknown";
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidCTime, VT_FILETIME},
- { NULL, kpidATime, VT_FILETIME},
- { NULL, kpidAttrib, VT_UI4},
-
- { NULL, kpidEncrypted, VT_BOOL},
- { NULL, kpidSolid, VT_BOOL},
- { NULL, kpidCommented, VT_BOOL},
- { NULL, kpidSplitBefore, VT_BOOL},
- { NULL, kpidSplitAfter, VT_BOOL},
- { NULL, kpidCRC, VT_UI4},
- { NULL, kpidHostOS, VT_BSTR},
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidUnpackVer, VT_UI1}
-};
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidSolid, VT_BOOL},
- { NULL, kpidNumBlocks, VT_UI4},
- // { NULL, kpidEncrypted, VT_BOOL},
- { NULL, kpidIsVolume, VT_BOOL},
- { NULL, kpidNumVolumes, VT_UI4},
- { NULL, kpidPhySize, VT_UI8}
- // { NULL, kpidCommented, VT_BOOL}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-UInt64 CHandler::GetPackSize(int refIndex) const
-{
- const CRefItem &refItem = _refItems[refIndex];
- UInt64 totalPackSize = 0;
- for (int i = 0; i < refItem.NumItems; i++)
- totalPackSize += _items[refItem.ItemIndex + i].PackSize;
- return totalPackSize;
-}
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- // COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidSolid: prop = _archiveInfo.IsSolid(); break;
- // case kpidEncrypted: prop = _archiveInfo.IsEncrypted(); break; // it's for encrypted names.
- case kpidIsVolume: prop = _archiveInfo.IsVolume(); break;
- case kpidNumVolumes: prop = (UInt32)_archives.Size(); break;
- case kpidOffset: if (_archiveInfo.StartPosition != 0) prop = _archiveInfo.StartPosition; break;
- // case kpidCommented: prop = _archiveInfo.IsCommented(); break;
- case kpidNumBlocks:
- {
- UInt32 numBlocks = 0;
- for (int i = 0; i < _refItems.Size(); i++)
- if (!IsSolid(i))
- numBlocks++;
- prop = (UInt32)numBlocks;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- // COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _refItems.Size();
- return S_OK;
-}
-
-static bool RarTimeToFileTime(const CRarTime &rarTime, FILETIME &result)
-{
- if (!DosTimeToFileTime(rarTime.DosTime, result))
- return false;
- UInt64 value = (((UInt64)result.dwHighDateTime) << 32) + result.dwLowDateTime;
- value += (UInt64)rarTime.LowSecond * 10000000;
- value += ((UInt64)rarTime.SubTime[2] << 16) +
- ((UInt64)rarTime.SubTime[1] << 8) +
- ((UInt64)rarTime.SubTime[0]);
- result.dwLowDateTime = (DWORD)value;
- result.dwHighDateTime = DWORD(value >> 32);
- return true;
-}
-
-static void RarTimeToProp(const CRarTime &rarTime, NWindows::NCOM::CPropVariant &prop)
-{
- FILETIME localFileTime, utcFileTime;
- if (RarTimeToFileTime(rarTime, localFileTime))
- {
- if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
- }
- else
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
- prop = utcFileTime;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CRefItem &refItem = _refItems[index];
- const CItemEx &item = _items[refItem.ItemIndex];
- switch(propID)
- {
- case kpidPath:
- {
- UString u;
- if (item.HasUnicodeName() && !item.UnicodeName.IsEmpty())
- u = item.UnicodeName;
- else
- u = MultiByteToUnicodeString(item.Name, CP_OEMCP);
- prop = (const wchar_t *)NItemName::WinNameToOSName(u);
- break;
- }
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize: prop = item.Size; break;
- case kpidPackSize: prop = GetPackSize(index); break;
- case kpidMTime: RarTimeToProp(item.MTime, prop); break;
- case kpidCTime: if (item.CTimeDefined) RarTimeToProp(item.CTime, prop); break;
- case kpidATime: if (item.ATimeDefined) RarTimeToProp(item.ATime, prop); break;
- case kpidAttrib: prop = item.GetWinAttributes(); break;
- case kpidEncrypted: prop = item.IsEncrypted(); break;
- case kpidSolid: prop = IsSolid(index); break;
- case kpidCommented: prop = item.IsCommented(); break;
- case kpidSplitBefore: prop = item.IsSplitBefore(); break;
- case kpidSplitAfter: prop = _items[refItem.ItemIndex + refItem.NumItems - 1].IsSplitAfter(); break;
- case kpidCRC:
- {
- const CItemEx &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
- prop = ((lastItem.IsSplitAfter()) ? item.FileCRC : lastItem.FileCRC);
- break;
- }
- case kpidUnpackVer: prop = item.UnPackVersion; break;
- case kpidMethod:
- {
- UString method;
- if (item.Method >= Byte('0') && item.Method <= Byte('5'))
- {
- method = L"m";
- wchar_t temp[32];
- ConvertUInt64ToString(item.Method - Byte('0'), temp);
- method += temp;
- if (!item.IsDir())
- {
- method += L":";
- ConvertUInt64ToString(16 + item.GetDictSize(), temp);
- method += temp;
- }
- }
- else
- {
- wchar_t temp[32];
- ConvertUInt64ToString(item.Method, temp);
- method += temp;
- }
- prop = method;
- break;
- }
- case kpidHostOS: prop = (item.HostOS < kNumHostOSes) ? (kHostOS[item.HostOS]) : kUnknownOS; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-class CVolumeName
-{
- bool _first;
- bool _newStyle;
- UString _unchangedPart;
- UString _changedPart;
- UString _afterPart;
-public:
- CVolumeName(): _newStyle(true) {};
-
- bool InitName(const UString &name, bool newStyle)
- {
- _first = true;
- _newStyle = newStyle;
- int dotPos = name.ReverseFind('.');
- UString basePart = name;
- if (dotPos >= 0)
- {
- UString ext = name.Mid(dotPos + 1);
- if (ext.CompareNoCase(L"rar") == 0)
- {
- _afterPart = name.Mid(dotPos);
- basePart = name.Left(dotPos);
- }
- else if (ext.CompareNoCase(L"exe") == 0)
- {
- _afterPart = L".rar";
- basePart = name.Left(dotPos);
- }
- else if (!_newStyle)
- {
- if (ext.CompareNoCase(L"000") == 0 || ext.CompareNoCase(L"001") == 0)
- {
- _afterPart.Empty();
- _first = false;
- _changedPart = ext;
- _unchangedPart = name.Left(dotPos + 1);
- return true;
- }
- }
- }
-
- if (!_newStyle)
- {
- _afterPart.Empty();
- _unchangedPart = basePart + UString(L".");
- _changedPart = L"r00";
- return true;
- }
-
- int numLetters = 1;
- if (basePart.Right(numLetters) == L"1" || basePart.Right(numLetters) == L"0")
- {
- while (numLetters < basePart.Length())
- {
- if (basePart[basePart.Length() - numLetters - 1] != '0')
- break;
- numLetters++;
- }
- }
- else
- return false;
- _unchangedPart = basePart.Left(basePart.Length() - numLetters);
- _changedPart = basePart.Right(numLetters);
- return true;
- }
-
- UString GetNextName()
- {
- UString newName;
- if (_newStyle || !_first)
- {
- int i;
- int numLetters = _changedPart.Length();
- for (i = numLetters - 1; i >= 0; i--)
- {
- wchar_t c = _changedPart[i];
- if (c == L'9')
- {
- c = L'0';
- newName = c + newName;
- if (i == 0)
- newName = UString(L'1') + newName;
- continue;
- }
- c++;
- newName = UString(c) + newName;
- i--;
- for (; i >= 0; i--)
- newName = _changedPart[i] + newName;
- break;
- }
- _changedPart = newName;
- }
- _first = false;
- return _unchangedPart + _changedPart + _afterPart;
- }
-};
-
-HRESULT CHandler::Open2(IInStream *stream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *openArchiveCallback)
-{
- {
- CMyComPtr openVolumeCallback;
- CMyComPtr getTextPassword;
- CMyComPtr openArchiveCallbackWrap = openArchiveCallback;
-
- CVolumeName seqName;
-
- UInt64 totalBytes = 0;
- UInt64 curBytes = 0;
-
- if (openArchiveCallback != NULL)
- {
- openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);
- openArchiveCallbackWrap.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
- }
-
- for (;;)
- {
- CMyComPtr inStream;
- if (!_archives.IsEmpty())
- {
- if (!openVolumeCallback)
- break;
-
- if(_archives.Size() == 1)
- {
- if (!_archiveInfo.IsVolume())
- break;
- UString baseName;
- {
- NCOM::CPropVariant prop;
- RINOK(openVolumeCallback->GetProperty(kpidName, &prop));
- if (prop.vt != VT_BSTR)
- break;
- baseName = prop.bstrVal;
- }
- seqName.InitName(baseName, _archiveInfo.HaveNewVolumeName());
- }
-
- UString fullName = seqName.GetNextName();
- HRESULT result = openVolumeCallback->GetStream(fullName, &inStream);
- if (result == S_FALSE)
- break;
- if (result != S_OK)
- return result;
- if (!stream)
- break;
- }
- else
- inStream = stream;
-
- UInt64 endPos = 0;
- if (openArchiveCallback != NULL)
- {
- RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
- RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
- totalBytes += endPos;
- RINOK(openArchiveCallback->SetTotal(NULL, &totalBytes));
- }
-
- NArchive::NRar::CInArchive archive;
- RINOK(archive.Open(inStream, maxCheckStartPosition));
-
- if (_archives.IsEmpty())
- archive.GetArchiveInfo(_archiveInfo);
-
- CItemEx item;
- for (;;)
- {
- HRESULT result = archive.GetNextItem(item, getTextPassword);
- if (result == S_FALSE)
- break;
- RINOK(result);
- if (item.IgnoreItem())
- continue;
-
- bool needAdd = true;
- if (item.IsSplitBefore())
- {
- if (!_refItems.IsEmpty())
- {
- CRefItem &refItem = _refItems.Back();
- refItem.NumItems++;
- needAdd = false;
- }
- }
- if (needAdd)
- {
- CRefItem refItem;
- refItem.ItemIndex = _items.Size();
- refItem.NumItems = 1;
- refItem.VolumeIndex = _archives.Size();
- _refItems.Add(refItem);
- }
- _items.Add(item);
- if (openArchiveCallback != NULL && _items.Size() % 100 == 0)
- {
- UInt64 numFiles = _items.Size();
- UInt64 numBytes = curBytes + item.Position;
- RINOK(openArchiveCallback->SetCompleted(&numFiles, &numBytes));
- }
- }
- curBytes += endPos;
- _archives.Add(archive);
- }
- }
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *openArchiveCallback)
-{
- COM_TRY_BEGIN
- Close();
- try
- {
- HRESULT res = Open2(stream, maxCheckStartPosition, openArchiveCallback);
- if (res != S_OK)
- Close();
- return res;
- }
- catch(const CInArchiveException &) { Close(); return S_FALSE; }
- catch(...) { Close(); throw; }
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- COM_TRY_BEGIN
- _refItems.Clear();
- _items.Clear();
- _archives.Clear();
- return S_OK;
- COM_TRY_END
-}
-
-struct CMethodItem
-{
- Byte RarUnPackVersion;
- CMyComPtr Coder;
-};
-
-
-STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
- Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)
-{
- COM_TRY_BEGIN
- CMyComPtr getTextPassword;
- bool testMode = (_aTestMode != 0);
- CMyComPtr extractCallback = _anExtractCallback;
- UInt64 censoredTotalUnPacked = 0,
- // censoredTotalPacked = 0,
- importantTotalUnPacked = 0;
- // importantTotalPacked = 0;
- bool allFilesMode = (numItems == UInt32(-1));
- if (allFilesMode)
- numItems = _refItems.Size();
- if(numItems == 0)
- return S_OK;
- int lastIndex = 0;
- CRecordVector importantIndexes;
- CRecordVector extractStatuses;
-
- for(UInt32 t = 0; t < numItems; t++)
- {
- int index = allFilesMode ? t : indices[t];
- const CRefItem &refItem = _refItems[index];
- const CItemEx &item = _items[refItem.ItemIndex];
- censoredTotalUnPacked += item.Size;
- // censoredTotalPacked += item.PackSize;
- int j;
- for(j = lastIndex; j <= index; j++)
- // if(!_items[_refItems[j].ItemIndex].IsSolid())
- if(!IsSolid(j))
- lastIndex = j;
- for(j = lastIndex; j <= index; j++)
- {
- const CRefItem &refItem = _refItems[j];
- const CItemEx &item = _items[refItem.ItemIndex];
-
- // const CItemEx &item = _items[j];
-
- importantTotalUnPacked += item.Size;
- // importantTotalPacked += item.PackSize;
- importantIndexes.Add(j);
- extractStatuses.Add(j == index);
- }
- lastIndex = index + 1;
- }
-
- extractCallback->SetTotal(importantTotalUnPacked);
- UInt64 currentImportantTotalUnPacked = 0;
- UInt64 currentImportantTotalPacked = 0;
- UInt64 currentUnPackSize, currentPackSize;
-
- CObjectVector methodItems;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
- CMyComPtr copyCoder = copyCoderSpec;
-
- CFilterCoder *filterStreamSpec = new CFilterCoder;
- CMyComPtr filterStream = filterStreamSpec;
-
- NCrypto::NRar20::CDecoder *rar20CryptoDecoderSpec = NULL;
- CMyComPtr rar20CryptoDecoder;
- NCrypto::NRar29::CDecoder *rar29CryptoDecoderSpec = NULL;
- CMyComPtr rar29CryptoDecoder;
-
- CFolderInStream *folderInStreamSpec = NULL;
- CMyComPtr folderInStream;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr progress = lps;
- lps->Init(extractCallback, false);
-
- bool solidStart = true;
- for(int i = 0; i < importantIndexes.Size(); i++,
- currentImportantTotalUnPacked += currentUnPackSize,
- currentImportantTotalPacked += currentPackSize)
- {
- lps->InSize = currentImportantTotalPacked;
- lps->OutSize = currentImportantTotalUnPacked;
- RINOK(lps->SetCur());
- CMyComPtr realOutStream;
-
- Int32 askMode;
- if(extractStatuses[i])
- askMode = testMode ?
- NArchive::NExtract::NAskMode::kTest :
- NArchive::NExtract::NAskMode::kExtract;
- else
- askMode = NArchive::NExtract::NAskMode::kSkip;
-
- UInt32 index = importantIndexes[i];
-
- const CRefItem &refItem = _refItems[index];
- const CItemEx &item = _items[refItem.ItemIndex];
-
- currentUnPackSize = item.Size;
-
- currentPackSize = GetPackSize(index);
-
- if(item.IgnoreItem())
- continue;
-
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- if (!IsSolid(index))
- solidStart = true;
- if(item.IsDir())
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));
- continue;
- }
-
- bool mustBeProcessedAnywhere = false;
- if(i < importantIndexes.Size() - 1)
- {
- // const CRefItem &nextRefItem = _refItems[importantIndexes[i + 1]];
- // const CItemEx &nextItemInfo = _items[nextRefItem.ItemIndex];
- // mustBeProcessedAnywhere = nextItemInfo.IsSolid();
- mustBeProcessedAnywhere = IsSolid(importantIndexes[i + 1]);
- }
-
- if (!mustBeProcessedAnywhere && !testMode && !realOutStream)
- continue;
-
- if (!realOutStream && !testMode)
- askMode = NArchive::NExtract::NAskMode::kSkip;
-
- RINOK(extractCallback->PrepareOperation(askMode));
-
- COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
- CMyComPtr outStream(outStreamSpec);
- outStreamSpec->SetStream(realOutStream);
- outStreamSpec->Init();
- realOutStream.Release();
-
- /*
- for (int partIndex = 0; partIndex < 1; partIndex++)
- {
- CMyComPtr inStream;
-
- // item redefinition
- const CItemEx &item = _items[refItem.ItemIndex + partIndex];
-
- NArchive::NRar::CInArchive &archive = _archives[refItem.VolumeIndex + partIndex];
-
- inStream.Attach(archive.CreateLimitedStream(item.GetDataPosition(),
- item.PackSize));
- */
- if (!folderInStream)
- {
- folderInStreamSpec = new CFolderInStream;
- folderInStream = folderInStreamSpec;
- }
-
- folderInStreamSpec->Init(&_archives, &_items, refItem);
-
- UInt64 packSize = currentPackSize;
-
- // packedPos += item.PackSize;
- // unpackedPos += 0;
-
- CMyComPtr inStream;
- if (item.IsEncrypted())
- {
- CMyComPtr cryptoSetPassword;
- if (item.UnPackVersion >= 29)
- {
- if (!rar29CryptoDecoder)
- {
- rar29CryptoDecoderSpec = new NCrypto::NRar29::CDecoder;
- rar29CryptoDecoder = rar29CryptoDecoderSpec;
- // RINOK(rar29CryptoDecoder.CoCreateInstance(CLSID_CCryptoRar29Decoder));
- }
- rar29CryptoDecoderSpec->SetRar350Mode(item.UnPackVersion < 36);
- CMyComPtr cryptoProperties;
- RINOK(rar29CryptoDecoder.QueryInterface(IID_ICompressSetDecoderProperties2,
- &cryptoProperties));
- RINOK(cryptoProperties->SetDecoderProperties2(item.Salt, item.HasSalt() ? sizeof(item.Salt) : 0));
- filterStreamSpec->Filter = rar29CryptoDecoder;
- }
- else if (item.UnPackVersion >= 20)
- {
- if (!rar20CryptoDecoder)
- {
- rar20CryptoDecoderSpec = new NCrypto::NRar20::CDecoder;
- rar20CryptoDecoder = rar20CryptoDecoderSpec;
- // RINOK(rar20CryptoDecoder.CoCreateInstance(CLSID_CCryptoRar20Decoder));
- }
- filterStreamSpec->Filter = rar20CryptoDecoder;
- }
- else
- {
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
- continue;
- }
- RINOK(filterStreamSpec->Filter.QueryInterface(IID_ICryptoSetPassword,
- &cryptoSetPassword));
-
- if (!getTextPassword)
- extractCallback.QueryInterface(IID_ICryptoGetTextPassword,
- &getTextPassword);
- if (getTextPassword)
- {
- CMyComBSTR password;
- RINOK(getTextPassword->CryptoGetTextPassword(&password));
- if (item.UnPackVersion >= 29)
- {
- CByteBuffer buffer;
- UString unicodePassword(password);
- const UInt32 sizeInBytes = unicodePassword.Length() * 2;
- buffer.SetCapacity(sizeInBytes);
- for (int i = 0; i < unicodePassword.Length(); i++)
- {
- wchar_t c = unicodePassword[i];
- ((Byte *)buffer)[i * 2] = (Byte)c;
- ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
- }
- RINOK(cryptoSetPassword->CryptoSetPassword(
- (const Byte *)buffer, sizeInBytes));
- }
- else
- {
- AString oemPassword = UnicodeStringToMultiByte(
- (const wchar_t *)password, CP_OEMCP);
- RINOK(cryptoSetPassword->CryptoSetPassword(
- (const Byte *)(const char *)oemPassword, oemPassword.Length()));
- }
- }
- else
- {
- RINOK(cryptoSetPassword->CryptoSetPassword(0, 0));
- }
- filterStreamSpec->SetInStream(folderInStream);
- inStream = filterStream;
- }
- else
- {
- inStream = folderInStream;
- }
- CMyComPtr commonCoder;
- switch(item.Method)
- {
- case '0':
- {
- commonCoder = copyCoder;
- break;
- }
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- {
- /*
- if (item.UnPackVersion >= 29)
- {
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
- continue;
- }
- */
- int m;
- for (m = 0; m < methodItems.Size(); m++)
- if (methodItems[m].RarUnPackVersion == item.UnPackVersion)
- break;
- if (m == methodItems.Size())
- {
- CMethodItem mi;
- mi.RarUnPackVersion = item.UnPackVersion;
-
- mi.Coder.Release();
- if (item.UnPackVersion <= 30)
- {
- UInt32 methodID = 0x040300;
- if (item.UnPackVersion < 20)
- methodID += 1;
- else if (item.UnPackVersion < 29)
- methodID += 2;
- else
- methodID += 3;
- RINOK(CreateCoder(EXTERNAL_CODECS_VARS methodID, mi.Coder, false));
- }
-
- if (mi.Coder == 0)
- {
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
- continue;
- }
-
- m = methodItems.Add(mi);
- }
- CMyComPtr decoder = methodItems[m].Coder;
-
- CMyComPtr compressSetDecoderProperties;
- RINOK(decoder.QueryInterface(IID_ICompressSetDecoderProperties2,
- &compressSetDecoderProperties));
-
- Byte isSolid = (Byte)((IsSolid(index) || item.IsSplitBefore()) ? 1: 0);
- if (solidStart)
- {
- isSolid = false;
- solidStart = false;
- }
-
-
- RINOK(compressSetDecoderProperties->SetDecoderProperties2(&isSolid, 1));
-
- commonCoder = decoder;
- break;
- }
- default:
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod));
- continue;
- }
- HRESULT result = commonCoder->Code(inStream, outStream, &packSize, &item.Size, progress);
- if (item.IsEncrypted())
- filterStreamSpec->ReleaseInStream();
- if (result == S_FALSE)
- {
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kDataError));
- continue;
- }
- if (result != S_OK)
- return result;
-
- /*
- if (refItem.NumItems == 1 &&
- !item.IsSplitBefore() && !item.IsSplitAfter())
- */
- {
- const CItemEx &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
- bool crcOK = outStreamSpec->GetCRC() == lastItem.FileCRC;
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(crcOK ? NArchive::NExtract::NOperationResult::kOK:
- NArchive::NExtract::NOperationResult::kCRCError));
- }
- /*
- else
- {
- bool crcOK = true;
- for (int partIndex = 0; partIndex < refItem.NumItems; partIndex++)
- {
- const CItemEx &item = _items[refItem.ItemIndex + partIndex];
- if (item.FileCRC != folderInStreamSpec->CRCs[partIndex])
- {
- crcOK = false;
- break;
- }
- }
- RINOK(extractCallback->SetOperationResult(crcOK ? NArchive::NExtract::NOperationResult::kOK:
- NArchive::NExtract::NOperationResult::kCRCError));
- }
- */
- }
- return S_OK;
- COM_TRY_END
-}
-
-IMPL_ISetCompressCodecsInfo
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHandler.h b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHandler.h
deleted file mode 100644
index dff8ed322..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHandler.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Rar/Handler.h
-
-#ifndef __RAR_HANDLER_H
-#define __RAR_HANDLER_H
-
-#include "../IArchive.h"
-#include "RarIn.h"
-#include "RarVolumeInStream.h"
-
-#include "../../Common/CreateCoder.h"
-
-namespace NArchive {
-namespace NRar {
-
-class CHandler:
- public IInArchive,
- PUBLIC_ISetCompressCodecsInfo
- public CMyUnknownImp
-{
-public:
- MY_QUERYINTERFACE_BEGIN2(IInArchive)
- QUERY_ENTRY_ISetCompressCodecsInfo
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IInArchive(;)
-
- DECL_ISetCompressCodecsInfo
-
-private:
- CRecordVector _refItems;
- CObjectVector _items;
- CObjectVector _archives;
- NArchive::NRar::CInArchiveInfo _archiveInfo;
-
- DECL_EXTERNAL_CODECS_VARS
-
- UInt64 GetPackSize(int refIndex) const;
- // NArchive::NRar::CInArchive _archive;
-
- bool IsSolid(int refIndex)
- {
- const CItemEx &item = _items[_refItems[refIndex].ItemIndex];
- if (item.UnPackVersion < 20)
- {
- if (_archiveInfo.IsSolid())
- return (refIndex > 0);
- return false;
- }
- return item.IsSolid();
- }
-
- HRESULT Open2(IInStream *stream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *openArchiveCallback);
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHeader.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHeader.cpp
deleted file mode 100644
index 90dc8366f..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHeader.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// Archive/Rar/Headers.cpp
-
-#include "StdAfx.h"
-
-#include "RarHeader.h"
-
-namespace NArchive{
-namespace NRar{
-namespace NHeader{
-
-Byte kMarker[kMarkerSize] = {0x52 + 1, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};
-
-class CMarkerInitializer
-{
-public:
- CMarkerInitializer() { kMarker[0]--; };
-} g_MarkerInitializer;
-
-}}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHeader.h b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHeader.h
deleted file mode 100644
index e5a3e1deb..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarHeader.h
+++ /dev/null
@@ -1,224 +0,0 @@
-// Archive/RarHeader.h
-
-#ifndef __ARCHIVE_RAR_HEADER_H
-#define __ARCHIVE_RAR_HEADER_H
-
-#include "Common/Types.h"
-
-namespace NArchive{
-namespace NRar{
-namespace NHeader{
-
-const int kMarkerSize = 7;
-extern Byte kMarker[kMarkerSize];
-
-const int kArchiveSolid = 0x1;
-
-namespace NBlockType
-{
- enum EBlockType
- {
- kMarker = 0x72,
- kArchiveHeader = 0x73,
- kFileHeader = 0x74,
- kCommentHeader = 0x75,
- kOldAuthenticity = 0x76,
- kSubBlock = 0x77,
- kRecoveryRecord = 0x78,
- kAuthenticity = 0x79,
-
- kEndOfArchive = 0x7B // Is not safe
- };
-}
-
-namespace NArchive
-{
- const UInt16 kVolume = 1;
- const UInt16 kComment = 2;
- const UInt16 kLock = 4;
- const UInt16 kSolid = 8;
- const UInt16 kNewVolName = 0x10; // ('volname.partN.rar')
- const UInt16 kAuthenticity = 0x20;
- const UInt16 kRecovery = 0x40;
- const UInt16 kBlockEncryption = 0x80;
- const UInt16 kFirstVolume = 0x100; // (set only by RAR 3.0 and later)
- const UInt16 kEncryptVer = 0x200; // RAR 3.6 there is EncryptVer Byte in End of MainHeader
-
- const int kHeaderSizeMin = 7;
-
- struct CBlock
- {
- UInt16 CRC;
- Byte Type;
- UInt16 Flags;
- UInt16 Size;
- UInt16 Reserved1;
- UInt32 Reserved2;
- // UInt16 GetRealCRC() const;
- };
-
- const int kArchiveHeaderSize = 13;
-
- const int kBlockHeadersAreEncrypted = 0x80;
-
- struct CHeader360: public CBlock
- {
- Byte EncryptVersion;
- bool IsEncrypted() const { return (Flags & NHeader::NArchive::kBlockEncryption) != 0; }
- bool IsThereEncryptVer() const { return (Flags & NHeader::NArchive::kEncryptVer) != 0; }
- bool IsEncryptOld() const { return (!IsThereEncryptVer() || EncryptVersion < 36); }
- UInt32 GetBaseSize() const { return kArchiveHeaderSize + (IsEncryptOld() ? 0 : 1); }
- };
-}
-
-namespace NFile
-{
- const int kSplitBefore = 1 << 0;
- const int kSplitAfter = 1 << 1;
- const int kEncrypted = 1 << 2;
- const int kComment = 1 << 3;
- const int kSolid = 1 << 4;
-
- const int kDictBitStart = 5;
- const int kNumDictBits = 3;
- const int kDictMask = (1 << kNumDictBits) - 1;
- const int kDictDirectoryValue = 0x7;
-
- const int kSize64Bits = 1 << 8;
- const int kUnicodeName = 1 << 9;
- const int kSalt = 1 << 10;
- const int kOldVersion = 1 << 11;
- const int kExtTime = 1 << 12;
- // const int kExtFlags = 1 << 13;
- // const int kSkipIfUnknown = 1 << 14;
-
- const int kLongBlock = 1 << 15;
-
- /*
- struct CBlock
- {
- // UInt16 HeadCRC;
- // Byte Type;
- // UInt16 Flags;
- // UInt16 HeadSize;
- UInt32 PackSize;
- UInt32 UnPackSize;
- Byte HostOS;
- UInt32 FileCRC;
- UInt32 Time;
- Byte UnPackVersion;
- Byte Method;
- UInt16 NameSize;
- UInt32 Attributes;
- };
- */
-
- /*
- struct CBlock32
- {
- UInt16 HeadCRC;
- Byte Type;
- UInt16 Flags;
- UInt16 HeadSize;
- UInt32 PackSize;
- UInt32 UnPackSize;
- Byte HostOS;
- UInt32 FileCRC;
- UInt32 Time;
- Byte UnPackVersion;
- Byte Method;
- UInt16 NameSize;
- UInt32 Attributes;
- UInt16 GetRealCRC(const void *aName, UInt32 aNameSize,
- bool anExtraDataDefined = false, Byte *anExtraData = 0) const;
- };
- struct CBlock64
- {
- UInt16 HeadCRC;
- Byte Type;
- UInt16 Flags;
- UInt16 HeadSize;
- UInt32 PackSizeLow;
- UInt32 UnPackSizeLow;
- Byte HostOS;
- UInt32 FileCRC;
- UInt32 Time;
- Byte UnPackVersion;
- Byte Method;
- UInt16 NameSize;
- UInt32 Attributes;
- UInt32 PackSizeHigh;
- UInt32 UnPackSizeHigh;
- UInt16 GetRealCRC(const void *aName, UInt32 aNameSize) const;
- };
- */
-
- const int kLabelFileAttribute = 0x08;
- const int kWinFileDirectoryAttributeMask = 0x10;
-
- enum CHostOS
- {
- kHostMSDOS = 0,
- kHostOS2 = 1,
- kHostWin32 = 2,
- kHostUnix = 3,
- kHostMacOS = 4,
- kHostBeOS = 5
- };
-}
-
-namespace NBlock
-{
- const UInt16 kLongBlock = 1 << 15;
- struct CBlock
- {
- UInt16 CRC;
- Byte Type;
- UInt16 Flags;
- UInt16 HeadSize;
- // UInt32 DataSize;
- };
-}
-
-/*
-struct CSubBlock
-{
- UInt16 HeadCRC;
- Byte HeadType;
- UInt16 Flags;
- UInt16 HeadSize;
- UInt32 DataSize;
- UInt16 SubType;
- Byte Level; // Reserved : Must be 0
-};
-
-struct CCommentBlock
-{
- UInt16 HeadCRC;
- Byte HeadType;
- UInt16 Flags;
- UInt16 HeadSize;
- UInt16 UnpSize;
- Byte UnpVer;
- Byte Method;
- UInt16 CommCRC;
-};
-
-
-struct CProtectHeader
-{
- UInt16 HeadCRC;
- Byte HeadType;
- UInt16 Flags;
- UInt16 HeadSize;
- UInt32 DataSize;
- Byte Version;
- UInt16 RecSectors;
- UInt32 TotalBlocks;
- Byte Mark[8];
-};
-*/
-
-}}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarIn.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarIn.cpp
deleted file mode 100644
index f434bce63..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarIn.cpp
+++ /dev/null
@@ -1,513 +0,0 @@
-// Archive/RarIn.cpp
-
-#include "StdAfx.h"
-
-#include "Common/StringConvert.h"
-#include "Common/UTFConvert.h"
-
-#include "RarIn.h"
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/StreamUtils.h"
-
-#include "../Common/FindSignature.h"
-
-extern "C"
-{
- #include "../../../../C/7zCrc.h"
-}
-
-namespace NArchive {
-namespace NRar {
-
-void CInArchive::ThrowExceptionWithCode(
- CInArchiveException::CCauseType cause)
-{
- throw CInArchiveException(cause);
-}
-
-HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit)
-{
- try
- {
- Close();
- HRESULT res = Open2(inStream, searchHeaderSizeLimit);
- if (res == S_OK)
- return res;
- Close();
- return res;
- }
- catch(...) { Close(); throw; }
-}
-
-void CInArchive::Close()
-{
- m_Stream.Release();
-}
-
-
-static inline bool TestMarkerCandidate(const void *aTestBytes)
-{
- for (UInt32 i = 0; i < NHeader::kMarkerSize; i++)
- if (((const Byte *)aTestBytes)[i] != NHeader::kMarker[i])
- return false;
- return true;
-}
-
-HRESULT CInArchive::FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
-{
- RINOK(FindSignatureInStream(stream,
- NHeader::kMarker, NHeader::kMarkerSize,
- searchHeaderSizeLimit, m_ArchiveStartPosition));
- m_Stream = stream;
- m_Position = m_ArchiveStartPosition + NHeader::kMarkerSize;
- return m_Stream->Seek(m_Position, STREAM_SEEK_SET, NULL);
-}
-
-void CInArchive::ThrowUnexpectedEndOfArchiveException()
-{
- ThrowExceptionWithCode(CInArchiveException::kUnexpectedEndOfArchive);
-}
-
-bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
-{
- if (m_CryptoMode)
- {
- const Byte *bufData = (const Byte *)m_DecryptedData;
- UInt32 bufSize = m_DecryptedDataSize;
- UInt32 i;
- for (i = 0; i < size && m_CryptoPos < bufSize; i++)
- ((Byte *)data)[i] = bufData[m_CryptoPos++];
- return (i == size);
- }
- return (ReadStream_FALSE(m_Stream, data, size) == S_OK);
-}
-
-void CInArchive::ReadBytesAndTestResult(void *data, UInt32 size)
-{
- if(!ReadBytesAndTestSize(data,size))
- ThrowUnexpectedEndOfArchiveException();
-}
-
-HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
-{
- size_t realProcessedSize = size;
- HRESULT result = ReadStream(m_Stream, data, &realProcessedSize);
- if (processedSize != NULL)
- *processedSize = (UInt32)realProcessedSize;
- AddToSeekValue(realProcessedSize);
- return result;
-}
-
-static UInt32 CrcUpdateUInt16(UInt32 crc, UInt16 v)
-{
- crc = CRC_UPDATE_BYTE(crc, (Byte)(v & 0xFF));
- crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 8) & 0xFF));
- return crc;
-}
-
-static UInt32 CrcUpdateUInt32(UInt32 crc, UInt32 v)
-{
- crc = CRC_UPDATE_BYTE(crc, (Byte)(v & 0xFF));
- crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 8) & 0xFF));
- crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 16) & 0xFF));
- crc = CRC_UPDATE_BYTE(crc, (Byte)((v >> 24) & 0xFF));
- return crc;
-}
-
-
-HRESULT CInArchive::Open2(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
-{
- m_CryptoMode = false;
- RINOK(stream->Seek(0, STREAM_SEEK_SET, &m_StreamStartPosition));
- m_Position = m_StreamStartPosition;
-
- RINOK(FindAndReadMarker(stream, searchHeaderSizeLimit));
-
- Byte buf[NHeader::NArchive::kArchiveHeaderSize];
- UInt32 processedSize;
- ReadBytes(buf, sizeof(buf), &processedSize);
- if (processedSize != sizeof(buf))
- return S_FALSE;
- m_CurData = buf;
- m_CurPos = 0;
- m_PosLimit = sizeof(buf);
-
- m_ArchiveHeader.CRC = ReadUInt16();
- m_ArchiveHeader.Type = ReadByte();
- m_ArchiveHeader.Flags = ReadUInt16();
- m_ArchiveHeader.Size = ReadUInt16();
- m_ArchiveHeader.Reserved1 = ReadUInt16();
- m_ArchiveHeader.Reserved2 = ReadUInt32();
- m_ArchiveHeader.EncryptVersion = 0;
-
- UInt32 crc = CRC_INIT_VAL;
- crc = CRC_UPDATE_BYTE(crc, m_ArchiveHeader.Type);
- crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Flags);
- crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Size);
- crc = CrcUpdateUInt16(crc, m_ArchiveHeader.Reserved1);
- crc = CrcUpdateUInt32(crc, m_ArchiveHeader.Reserved2);
-
- if (m_ArchiveHeader.IsThereEncryptVer() && m_ArchiveHeader.Size > NHeader::NArchive::kArchiveHeaderSize)
- {
- ReadBytes(&m_ArchiveHeader.EncryptVersion, 1, &processedSize);
- if (processedSize != 1)
- return S_FALSE;
- crc = CRC_UPDATE_BYTE(crc, m_ArchiveHeader.EncryptVersion);
- }
-
- if(m_ArchiveHeader.CRC != (CRC_GET_DIGEST(crc) & 0xFFFF))
- ThrowExceptionWithCode(CInArchiveException::kArchiveHeaderCRCError);
- if (m_ArchiveHeader.Type != NHeader::NBlockType::kArchiveHeader)
- return S_FALSE;
- m_ArchiveCommentPosition = m_Position;
- m_SeekOnArchiveComment = true;
- return S_OK;
-}
-
-void CInArchive::SkipArchiveComment()
-{
- if (!m_SeekOnArchiveComment)
- return;
- AddToSeekValue(m_ArchiveHeader.Size - m_ArchiveHeader.GetBaseSize());
- m_SeekOnArchiveComment = false;
-}
-
-void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const
-{
- archiveInfo.StartPosition = m_ArchiveStartPosition;
- archiveInfo.Flags = m_ArchiveHeader.Flags;
- archiveInfo.CommentPosition = m_ArchiveCommentPosition;
- archiveInfo.CommentSize = (UInt16)(m_ArchiveHeader.Size - NHeader::NArchive::kArchiveHeaderSize);
-}
-
-static void DecodeUnicodeFileName(const char *name, const Byte *encName,
- int encSize, wchar_t *unicodeName, int maxDecSize)
-{
- int encPos = 0;
- int decPos = 0;
- int flagBits = 0;
- Byte flags = 0;
- Byte highByte = encName[encPos++];
- while (encPos < encSize && decPos < maxDecSize)
- {
- if (flagBits == 0)
- {
- flags = encName[encPos++];
- flagBits = 8;
- }
- switch(flags >> 6)
- {
- case 0:
- unicodeName[decPos++] = encName[encPos++];
- break;
- case 1:
- unicodeName[decPos++] = (wchar_t)(encName[encPos++] + (highByte << 8));
- break;
- case 2:
- unicodeName[decPos++] = (wchar_t)(encName[encPos] + (encName[encPos + 1] << 8));
- encPos += 2;
- break;
- case 3:
- {
- int length = encName[encPos++];
- if (length & 0x80)
- {
- Byte correction = encName[encPos++];
- for (length = (length & 0x7f) + 2;
- length > 0 && decPos < maxDecSize; length--, decPos++)
- unicodeName[decPos] = (wchar_t)(((name[decPos] + correction) & 0xff) + (highByte << 8));
- }
- else
- for (length += 2; length > 0 && decPos < maxDecSize; length--, decPos++)
- unicodeName[decPos] = name[decPos];
- }
- break;
- }
- flags <<= 2;
- flagBits -= 2;
- }
- unicodeName[decPos < maxDecSize ? decPos : maxDecSize - 1] = 0;
-}
-
-void CInArchive::ReadName(CItemEx &item, int nameSize)
-{
- item.UnicodeName.Empty();
- if (nameSize > 0)
- {
- m_NameBuffer.EnsureCapacity(nameSize + 1);
- char *buffer = (char *)m_NameBuffer;
-
- for (int i = 0; i < nameSize; i++)
- buffer[i] = ReadByte();
-
- int mainLen;
- for (mainLen = 0; mainLen < nameSize; mainLen++)
- if (buffer[mainLen] == '\0')
- break;
- buffer[mainLen] = '\0';
- item.Name = buffer;
-
- if(item.HasUnicodeName())
- {
- if(mainLen < nameSize)
- {
- int unicodeNameSizeMax = MyMin(nameSize, (0x400));
- _unicodeNameBuffer.EnsureCapacity(unicodeNameSizeMax + 1);
- DecodeUnicodeFileName(buffer, (const Byte *)buffer + mainLen + 1,
- nameSize - (mainLen + 1), _unicodeNameBuffer, unicodeNameSizeMax);
- item.UnicodeName = _unicodeNameBuffer;
- }
- else if (!ConvertUTF8ToUnicode(item.Name, item.UnicodeName))
- item.UnicodeName.Empty();
- }
- }
- else
- item.Name.Empty();
-}
-
-Byte CInArchive::ReadByte()
-{
- if (m_CurPos >= m_PosLimit)
- throw CInArchiveException(CInArchiveException::kIncorrectArchive);
- return m_CurData[m_CurPos++];
-}
-
-UInt16 CInArchive::ReadUInt16()
-{
- UInt16 value = 0;
- for (int i = 0; i < 2; i++)
- {
- Byte b = ReadByte();
- value |= (UInt16(b) << (8 * i));
- }
- return value;
-}
-
-UInt32 CInArchive::ReadUInt32()
-{
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- {
- Byte b = ReadByte();
- value |= (UInt32(b) << (8 * i));
- }
- return value;
-}
-
-void CInArchive::ReadTime(Byte mask, CRarTime &rarTime)
-{
- rarTime.LowSecond = (Byte)(((mask & 4) != 0) ? 1 : 0);
- int numDigits = (mask & 3);
- rarTime.SubTime[0] = rarTime.SubTime[1] = rarTime.SubTime[2] = 0;
- for (int i = 0; i < numDigits; i++)
- rarTime.SubTime[3 - numDigits + i] = ReadByte();
-}
-
-void CInArchive::ReadHeaderReal(CItemEx &item)
-{
- item.Flags = m_BlockHeader.Flags;
- item.PackSize = ReadUInt32();
- item.Size = ReadUInt32();
- item.HostOS = ReadByte();
- item.FileCRC = ReadUInt32();
- item.MTime.DosTime = ReadUInt32();
- item.UnPackVersion = ReadByte();
- item.Method = ReadByte();
- int nameSize = ReadUInt16();
- item.Attrib = ReadUInt32();
-
- item.MTime.LowSecond = 0;
- item.MTime.SubTime[0] =
- item.MTime.SubTime[1] =
- item.MTime.SubTime[2] = 0;
-
- if((item.Flags & NHeader::NFile::kSize64Bits) != 0)
- {
- item.PackSize |= ((UInt64)ReadUInt32() << 32);
- item.Size |= ((UInt64)ReadUInt32() << 32);
- }
-
- ReadName(item, nameSize);
-
- if (item.HasSalt())
- for (int i = 0; i < sizeof(item.Salt); i++)
- item.Salt[i] = ReadByte();
-
- // some rar archives have HasExtTime flag without field.
- if (m_CurPos < m_PosLimit && item.HasExtTime())
- {
- Byte accessMask = (Byte)(ReadByte() >> 4);
- Byte b = ReadByte();
- Byte modifMask = (Byte)(b >> 4);
- Byte createMask = (Byte)(b & 0xF);
- if ((modifMask & 8) != 0)
- ReadTime(modifMask, item.MTime);
- item.CTimeDefined = ((createMask & 8) != 0);
- if (item.CTimeDefined)
- {
- item.CTime.DosTime = ReadUInt32();
- ReadTime(createMask, item.CTime);
- }
- item.ATimeDefined = ((accessMask & 8) != 0);
- if (item.ATimeDefined)
- {
- item.ATime.DosTime = ReadUInt32();
- ReadTime(accessMask, item.ATime);
- }
- }
-
- UInt16 fileHeaderWithNameSize = (UInt16)m_CurPos;
-
- item.Position = m_Position;
- item.MainPartSize = fileHeaderWithNameSize;
- item.CommentSize = (UInt16)(m_BlockHeader.HeadSize - fileHeaderWithNameSize);
-
- if (m_CryptoMode)
- item.AlignSize = (UInt16)((16 - ((m_BlockHeader.HeadSize) & 0xF)) & 0xF);
- else
- item.AlignSize = 0;
- AddToSeekValue(m_BlockHeader.HeadSize);
-}
-
-void CInArchive::AddToSeekValue(UInt64 addValue)
-{
- m_Position += addValue;
-}
-
-HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPassword)
-{
- if (m_SeekOnArchiveComment)
- SkipArchiveComment();
- for (;;)
- {
- if(!SeekInArchive(m_Position))
- return S_FALSE;
- if (!m_CryptoMode && (m_ArchiveHeader.Flags &
- NHeader::NArchive::kBlockHeadersAreEncrypted) != 0)
- {
- m_CryptoMode = false;
- if (getTextPassword == 0)
- return S_FALSE;
- if(!SeekInArchive(m_Position))
- return S_FALSE;
- if (!m_RarAES)
- {
- m_RarAESSpec = new NCrypto::NRar29::CDecoder;
- m_RarAES = m_RarAESSpec;
- }
- m_RarAESSpec->SetRar350Mode(m_ArchiveHeader.IsEncryptOld());
-
- // Salt
- const UInt32 kSaltSize = 8;
- Byte salt[kSaltSize];
- if(!ReadBytesAndTestSize(salt, kSaltSize))
- return S_FALSE;
- m_Position += kSaltSize;
- RINOK(m_RarAESSpec->SetDecoderProperties2(salt, kSaltSize))
- // Password
- CMyComBSTR password;
- RINOK(getTextPassword->CryptoGetTextPassword(&password))
- UString unicodePassword(password);
-
- CByteBuffer buffer;
- const UInt32 sizeInBytes = unicodePassword.Length() * 2;
- buffer.SetCapacity(sizeInBytes);
- for (int i = 0; i < unicodePassword.Length(); i++)
- {
- wchar_t c = unicodePassword[i];
- ((Byte *)buffer)[i * 2] = (Byte)c;
- ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
- }
-
- RINOK(m_RarAESSpec->CryptoSetPassword((const Byte *)buffer, sizeInBytes));
-
- const UInt32 kDecryptedBufferSize = (1 << 12);
- if (m_DecryptedData.GetCapacity() == 0)
- {
- m_DecryptedData.SetCapacity(kDecryptedBufferSize);
- }
- RINOK(m_RarAES->Init());
- size_t decryptedDataSizeT = kDecryptedBufferSize;
- RINOK(ReadStream(m_Stream, (Byte *)m_DecryptedData, &decryptedDataSizeT));
- m_DecryptedDataSize = (UInt32)decryptedDataSizeT;
- m_DecryptedDataSize = m_RarAES->Filter((Byte *)m_DecryptedData, m_DecryptedDataSize);
-
- m_CryptoMode = true;
- m_CryptoPos = 0;
- }
-
- m_FileHeaderData.EnsureCapacity(7);
- if(!ReadBytesAndTestSize((Byte *)m_FileHeaderData, 7))
- return S_FALSE;
-
- m_CurData = (Byte *)m_FileHeaderData;
- m_CurPos = 0;
- m_PosLimit = 7;
- m_BlockHeader.CRC = ReadUInt16();
- m_BlockHeader.Type = ReadByte();
- m_BlockHeader.Flags = ReadUInt16();
- m_BlockHeader.HeadSize = ReadUInt16();
-
- if (m_BlockHeader.HeadSize < 7)
- ThrowExceptionWithCode(CInArchiveException::kIncorrectArchive);
-
- if (m_BlockHeader.Type == NHeader::NBlockType::kEndOfArchive)
- return S_FALSE;
-
- if (m_BlockHeader.Type == NHeader::NBlockType::kFileHeader)
- {
- m_FileHeaderData.EnsureCapacity(m_BlockHeader.HeadSize);
- m_CurData = (Byte *)m_FileHeaderData;
- m_PosLimit = m_BlockHeader.HeadSize;
- ReadBytesAndTestResult(m_CurData + m_CurPos, m_BlockHeader.HeadSize - 7);
- ReadHeaderReal(item);
- if ((CrcCalc(m_CurData + 2,
- m_BlockHeader.HeadSize - item.CommentSize - 2) & 0xFFFF) != m_BlockHeader.CRC)
- ThrowExceptionWithCode(CInArchiveException::kFileHeaderCRCError);
-
- FinishCryptoBlock();
- m_CryptoMode = false;
- SeekInArchive(m_Position); // Move Position to compressed Data;
- AddToSeekValue(item.PackSize); // m_Position points to next header;
- return S_OK;
- }
- if (m_CryptoMode && m_BlockHeader.HeadSize > (1 << 12))
- return E_FAIL; // it's for bad passwords
- if ((m_BlockHeader.Flags & NHeader::NBlock::kLongBlock) != 0)
- {
- m_FileHeaderData.EnsureCapacity(7 + 4);
- m_CurData = (Byte *)m_FileHeaderData;
- ReadBytesAndTestResult(m_CurData + m_CurPos, 4); // test it
- m_PosLimit = 7 + 4;
- UInt32 dataSize = ReadUInt32();
- AddToSeekValue(dataSize);
- if (m_CryptoMode && dataSize > (1 << 27))
- return E_FAIL; // it's for bad passwords
- m_CryptoPos = m_BlockHeader.HeadSize;
- }
- else
- m_CryptoPos = 0;
- AddToSeekValue(m_BlockHeader.HeadSize);
- FinishCryptoBlock();
- m_CryptoMode = false;
- }
-}
-
-bool CInArchive::SeekInArchive(UInt64 position)
-{
- UInt64 newPosition;
- m_Stream->Seek(position, STREAM_SEEK_SET, &newPosition);
- return newPosition == position;
-}
-
-ISequentialInStream* CInArchive::CreateLimitedStream(UInt64 position, UInt64 size)
-{
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr inStream(streamSpec);
- SeekInArchive(position);
- streamSpec->SetStream(m_Stream);
- streamSpec->Init(size);
- return inStream.Detach();
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarIn.h b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarIn.h
deleted file mode 100644
index 500f1134e..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarIn.h
+++ /dev/null
@@ -1,126 +0,0 @@
-// RarIn.h
-
-#ifndef __ARCHIVE_RAR_IN_H
-#define __ARCHIVE_RAR_IN_H
-
-#include "Common/DynamicBuffer.h"
-#include "Common/MyCom.h"
-
-#include "../../ICoder.h"
-#include "../../IStream.h"
-
-#include "../../Common/StreamObjects.h"
-
-#include "../../Crypto/RarAes.h"
-
-#include "RarHeader.h"
-#include "RarItem.h"
-
-namespace NArchive {
-namespace NRar {
-
-class CInArchiveException
-{
-public:
- enum CCauseType
- {
- kUnexpectedEndOfArchive = 0,
- kArchiveHeaderCRCError,
- kFileHeaderCRCError,
- kIncorrectArchive
- }
- Cause;
- CInArchiveException(CCauseType cause) : Cause(cause) {}
-};
-
-class CInArchiveInfo
-{
-public:
- UInt64 StartPosition;
- UInt16 Flags;
- UInt64 CommentPosition;
- UInt16 CommentSize;
- bool IsSolid() const { return (Flags & NHeader::NArchive::kSolid) != 0; }
- bool IsCommented() const { return (Flags & NHeader::NArchive::kComment) != 0; }
- bool IsVolume() const { return (Flags & NHeader::NArchive::kVolume) != 0; }
- bool HaveNewVolumeName() const { return (Flags & NHeader::NArchive::kNewVolName) != 0; }
- bool IsEncrypted() const { return (Flags & NHeader::NArchive::kBlockEncryption) != 0; }
-};
-
-class CInArchive
-{
- CMyComPtr m_Stream;
-
- UInt64 m_StreamStartPosition;
- UInt64 m_Position;
- UInt64 m_ArchiveStartPosition;
-
- NHeader::NArchive::CHeader360 m_ArchiveHeader;
- CDynamicBuffer m_NameBuffer;
- CDynamicBuffer _unicodeNameBuffer;
- bool m_SeekOnArchiveComment;
- UInt64 m_ArchiveCommentPosition;
-
- void ReadName(CItemEx &item, int nameSize);
- void ReadHeaderReal(CItemEx &item);
-
- HRESULT ReadBytes(void *data, UInt32 size, UInt32 *aProcessedSize);
- bool ReadBytesAndTestSize(void *data, UInt32 size);
- void ReadBytesAndTestResult(void *data, UInt32 size);
-
- HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
- HRESULT Open2(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
-
- void ThrowExceptionWithCode(CInArchiveException::CCauseType cause);
- void ThrowUnexpectedEndOfArchiveException();
-
- void AddToSeekValue(UInt64 addValue);
-
-protected:
-
- CDynamicBuffer m_FileHeaderData;
-
- NHeader::NBlock::CBlock m_BlockHeader;
-
- NCrypto::NRar29::CDecoder *m_RarAESSpec;
- CMyComPtr m_RarAES;
-
- Byte *m_CurData; // it must point to start of Rar::Block
- UInt32 m_CurPos;
- UInt32 m_PosLimit;
- Byte ReadByte();
- UInt16 ReadUInt16();
- UInt32 ReadUInt32();
- void ReadTime(Byte mask, CRarTime &rarTime);
-
- CBuffer m_DecryptedData;
- UInt32 m_DecryptedDataSize;
-
- bool m_CryptoMode;
- UInt32 m_CryptoPos;
- void FinishCryptoBlock()
- {
- if (m_CryptoMode)
- while ((m_CryptoPos & 0xF) != 0)
- {
- m_CryptoPos++;
- m_Position++;
- }
- }
-
-public:
- HRESULT Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit);
- void Close();
- HRESULT GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPassword);
-
- void SkipArchiveComment();
-
- void GetArchiveInfo(CInArchiveInfo &archiveInfo) const;
-
- bool SeekInArchive(UInt64 position);
- ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarItem.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarItem.cpp
deleted file mode 100644
index b0963778b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarItem.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-// RarItem.cpp
-
-#include "StdAfx.h"
-
-#include "RarItem.h"
-
-namespace NArchive{
-namespace NRar{
-
-bool CItem::IgnoreItem() const
-{
- switch(HostOS)
- {
- case NHeader::NFile::kHostMSDOS:
- case NHeader::NFile::kHostOS2:
- case NHeader::NFile::kHostWin32:
- return ((Attrib & NHeader::NFile::kLabelFileAttribute) != 0);
- }
- return false;
-}
-
-bool CItem::IsDir() const
-{
- if (GetDictSize() == NHeader::NFile::kDictDirectoryValue)
- return true;
- switch(HostOS)
- {
- case NHeader::NFile::kHostMSDOS:
- case NHeader::NFile::kHostOS2:
- case NHeader::NFile::kHostWin32:
- if ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0)
- return true;
- }
- return false;
-}
-
-UInt32 CItem::GetWinAttributes() const
-{
- UInt32 winAttributes;
- switch(HostOS)
- {
- case NHeader::NFile::kHostMSDOS:
- case NHeader::NFile::kHostOS2:
- case NHeader::NFile::kHostWin32:
- winAttributes = Attrib;
- break;
- default:
- winAttributes = 0; // must be converted from unix value;
- }
- if (IsDir())
- winAttributes |= NHeader::NFile::kWinFileDirectoryAttributeMask;
- return winAttributes;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarItem.h b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarItem.h
deleted file mode 100644
index 515ecd4be..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarItem.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// RarItem.h
-
-#ifndef __ARCHIVE_RAR_ITEM_H
-#define __ARCHIVE_RAR_ITEM_H
-
-#include "Common/Types.h"
-#include "Common/MyString.h"
-
-#include "RarHeader.h"
-
-namespace NArchive{
-namespace NRar{
-
-struct CRarTime
-{
- UInt32 DosTime;
- Byte LowSecond;
- Byte SubTime[3];
-};
-
-struct CItem
-{
- UInt64 Size;
- UInt64 PackSize;
-
- CRarTime CTime;
- CRarTime ATime;
- CRarTime MTime;
-
- UInt32 FileCRC;
- UInt32 Attrib;
-
- UInt16 Flags;
- Byte HostOS;
- Byte UnPackVersion;
- Byte Method;
-
- bool CTimeDefined;
- bool ATimeDefined;
-
- AString Name;
- UString UnicodeName;
-
- Byte Salt[8];
-
- bool IsEncrypted() const { return (Flags & NHeader::NFile::kEncrypted) != 0; }
- bool IsSolid() const { return (Flags & NHeader::NFile::kSolid) != 0; }
- bool IsCommented() const { return (Flags & NHeader::NFile::kComment) != 0; }
- bool IsSplitBefore() const { return (Flags & NHeader::NFile::kSplitBefore) != 0; }
- bool IsSplitAfter() const { return (Flags & NHeader::NFile::kSplitAfter) != 0; }
- bool HasSalt() const { return (Flags & NHeader::NFile::kSalt) != 0; }
- bool HasExtTime() const { return (Flags & NHeader::NFile::kExtTime) != 0; }
- bool HasUnicodeName()const { return (Flags & NHeader::NFile::kUnicodeName) != 0; }
- bool IsOldVersion() const { return (Flags & NHeader::NFile::kOldVersion) != 0; }
-
- UInt32 GetDictSize() const { return (Flags >> NHeader::NFile::kDictBitStart) & NHeader::NFile::kDictMask; }
- bool IsDir() const;
- bool IgnoreItem() const;
- UInt32 GetWinAttributes() const;
-
- CItem(): CTimeDefined(false), ATimeDefined(false) {}
-};
-
-class CItemEx: public CItem
-{
-public:
- UInt64 Position;
- UInt16 MainPartSize;
- UInt16 CommentSize;
- UInt16 AlignSize;
- UInt64 GetFullSize() const { return MainPartSize + CommentSize + AlignSize + PackSize; };
- // DWORD GetHeaderWithCommentSize() const { return MainPartSize + CommentSize; };
- UInt64 GetCommentPosition() const { return Position + MainPartSize; };
- UInt64 GetDataPosition() const { return GetCommentPosition() + CommentSize + AlignSize; };
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarRegister.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarRegister.cpp
deleted file mode 100644
index f7897a607..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarRegister.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// RarRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "RarHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NRar::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Rar", L"rar r00", 0, 3, {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00}, 7, false, CreateArc, 0, };
-
-REGISTER_ARC(Rar)
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp
deleted file mode 100644
index 8b62d9fd9..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-// RarVolumeInStream.cpp
-
-#include "StdAfx.h"
-
-#include "RarVolumeInStream.h"
-
-#include "Windows/Defs.h"
-#include "Common/Defs.h"
-
-extern "C"
-{
- #include "../../../../C/7zCrc.h"
-}
-
-namespace NArchive {
-namespace NRar {
-
-void CFolderInStream::Init(
- CObjectVector *archives,
- const CObjectVector *items,
- const CRefItem &refItem)
-{
- _archives = archives;
- _items = items;
- _refItem = refItem;
- _curIndex = 0;
- CRCs.Clear();
- _fileIsOpen = false;
-}
-
-HRESULT CFolderInStream::OpenStream()
-{
- while (_curIndex < _refItem.NumItems)
- {
- const CItemEx &item = (*_items)[_refItem.ItemIndex + _curIndex];
- _stream.Attach((*_archives)[_refItem.VolumeIndex + _curIndex].
- CreateLimitedStream(item.GetDataPosition(), item.PackSize));
- _curIndex++;
- _fileIsOpen = true;
- _crc = CRC_INIT_VAL;
- return S_OK;
- }
- return S_OK;
-}
-
-HRESULT CFolderInStream::CloseStream()
-{
- CRCs.Add(CRC_GET_DIGEST(_crc));
- _stream.Release();
- _fileIsOpen = false;
- return S_OK;
-}
-
-STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize = 0;
- while ((_curIndex < _refItem.NumItems || _fileIsOpen) && size > 0)
- {
- if (_fileIsOpen)
- {
- UInt32 localProcessedSize;
- RINOK(_stream->Read(
- ((Byte *)data) + realProcessedSize, size, &localProcessedSize));
- _crc = CrcUpdate(_crc, ((Byte *)data) + realProcessedSize, localProcessedSize);
- if (localProcessedSize == 0)
- {
- RINOK(CloseStream());
- continue;
- }
- realProcessedSize += localProcessedSize;
- size -= localProcessedSize;
- break;
- }
- else
- {
- RINOK(OpenStream());
- }
- }
- if (processedSize != 0)
- *processedSize = realProcessedSize;
- return S_OK;
-}
-
-}}
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.h b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.h
deleted file mode 100644
index d175a2c0c..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// RarVolumeInStream.h
-
-#ifndef __RAR_VOLUME_IN_STREAM_H
-#define __RAR_VOLUME_IN_STREAM_H
-
-#include "../../IStream.h"
-#include "RarIn.h"
-
-namespace NArchive {
-namespace NRar {
-
-struct CRefItem
-{
- int VolumeIndex;
- int ItemIndex;
- int NumItems;
-};
-
-class CFolderInStream:
- public ISequentialInStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-
-private:
- CObjectVector *_archives;
- const CObjectVector *_items;
- CRefItem _refItem;
- int _curIndex;
- UInt32 _crc;
- bool _fileIsOpen;
- CMyComPtr _stream;
-
- HRESULT OpenStream();
- HRESULT CloseStream();
-public:
- void Init(CObjectVector *archives,
- const CObjectVector *items,
- const CRefItem &refItem);
-
- CRecordVector CRCs;
-};
-
-}}
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/StdAfx.h b/desmume/src/windows/7z/CPP/7zip/Archive/Rar/StdAfx.h
deleted file mode 100644
index 83fdd22d5..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Rar/StdAfx.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-
-#endif
diff --git a/desmume/src/windows/7z/CPP/7zip/Archive/Split/SplitHandler.cpp b/desmume/src/windows/7z/CPP/7zip/Archive/Split/SplitHandler.cpp
deleted file mode 100644
index 36be6cc3b..000000000
--- a/desmume/src/windows/7z/CPP/7zip/Archive/Split/SplitHandler.cpp
+++ /dev/null
@@ -1,357 +0,0 @@
-// SplitHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Common/Defs.h"
-#include "Common/NewHandler.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../../Common/ProgressUtils.h"
-
-#include "../../Compress/CopyCoder.h"
-
-#include "../Common/ItemNameUtils.h"
-#include "../Common/MultiStream.h"
-
-#include "SplitHandler.h"
-
-using namespace NWindows;
-using namespace NTime;
-
-namespace NArchive {
-namespace NSplit {
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-class CSeqName
-{
-public:
- UString _unchangedPart;
- UString _changedPart;
- bool _splitStyle;
- UString GetNextName()
- {
- UString newName;
- if (_splitStyle)
- {
- int i;
- int numLetters = _changedPart.Length();
- for (i = numLetters - 1; i >= 0; i--)
- {
- wchar_t c = _changedPart[i];
- if (c == 'z')
- {
- c = 'a';
- newName = c + newName;
- continue;
- }
- else if (c == 'Z')
- {
- c = 'A';
- newName = c + newName;
- continue;
- }
- c++;
- if ((c == 'z' || c == 'Z') && i == 0)
- {
- _unchangedPart += c;
- wchar_t newChar = (c == 'z') ? L'a' : L'A';
- newName.Empty();
- numLetters++;
- for (int k = 0; k < numLetters; k++)
- newName += newChar;
- break;
- }
- newName = c + newName;
- i--;
- for (; i >= 0; i--)
- newName = _changedPart[i] + newName;
- break;
- }
- }
- else
- {
- int i;
- int numLetters = _changedPart.Length();
- for (i = numLetters - 1; i >= 0; i--)
- {
- wchar_t c = _changedPart[i];
- if (c == L'9')
- {
- c = L'0';
- newName = c + newName;
- if (i == 0)
- newName = UString(L'1') + newName;
- continue;
- }
- c++;
- newName = c + newName;
- i--;
- for (; i >= 0; i--)
- newName = _changedPart[i] + newName;
- break;
- }
- }
- _changedPart = newName;
- return _unchangedPart + _changedPart;
- }
-};
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback *openArchiveCallback)
-{
- COM_TRY_BEGIN
- Close();
- if (openArchiveCallback == 0)
- return S_FALSE;
- // try
- {
- CMyComPtr openVolumeCallback;
- CMyComPtr openArchiveCallbackWrap = openArchiveCallback;
- if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,
- &openVolumeCallback) != S_OK)
- return S_FALSE;
-
- {
- NCOM::CPropVariant prop;
- RINOK(openVolumeCallback->GetProperty(kpidName, &prop));
- if (prop.vt != VT_BSTR)
- return S_FALSE;
- _name = prop.bstrVal;
- }
-
- int dotPos = _name.ReverseFind('.');
- UString prefix, ext;
- if (dotPos >= 0)
- {
- prefix = _name.Left(dotPos + 1);
- ext = _name.Mid(dotPos + 1);
- }
- else
- ext = _name;
- UString extBig = ext;
- extBig.MakeUpper();
-
- CSeqName seqName;
-
- int numLetters = 2;
- bool splitStyle = false;
- if (extBig.Right(2) == L"AA")
- {
- splitStyle = true;
- while (numLetters < extBig.Length())
- {
- if (extBig[extBig.Length() - numLetters - 1] != 'A')
- break;
- numLetters++;
- }
- }
- else if (ext.Right(2) == L"01")
- {
- while (numLetters < extBig.Length())
- {
- if (extBig[extBig.Length() - numLetters - 1] != '0')
- break;
- numLetters++;
- }
- if (numLetters != ext.Length())
- return S_FALSE;
- }
- else
- return S_FALSE;
-
- _streams.Add(stream);
-
- seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);
- seqName._changedPart = ext.Right(numLetters);
- seqName._splitStyle = splitStyle;
-
- if (prefix.Length() < 1)
- _subName = L"file";
- else
- _subName = prefix.Left(prefix.Length() - 1);
-
- _totalSize = 0;
- UInt64 size;
- {
- NCOM::CPropVariant prop;
- RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));
- if (prop.vt != VT_UI8)
- return E_INVALIDARG;
- size = prop.uhVal.QuadPart;
- }
- _totalSize += size;
- _sizes.Add(size);
-
- if (openArchiveCallback != NULL)
- {
- UInt64 numFiles = _streams.Size();
- RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
- }
-
- for (;;)
- {
- UString fullName = seqName.GetNextName();
- CMyComPtr nextStream;
- HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);
- if (result == S_FALSE)
- break;
- if (result != S_OK)
- return result;
- if (!stream)
- break;
- {
- NCOM::CPropVariant prop;
- RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));
- if (prop.vt != VT_UI8)
- return E_INVALIDARG;
- size = prop.uhVal.QuadPart;
- }
- _totalSize += size;
- _sizes.Add(size);
- _streams.Add(nextStream);
- if (openArchiveCallback != NULL)
- {
- UInt64 numFiles = _streams.Size();
- RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
- }
- }
- }
- /*
- catch(...)
- {
- return S_FALSE;
- }
- */
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _sizes.Clear();
- _streams.Clear();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _streams.IsEmpty() ? 0 : 1;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
-{
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPath:
- prop = _subName;
- break;
- case kpidSize:
- case kpidPackSize:
- prop = _totalSize;
- break;
- }
- prop.Detach(value);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
- Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)
-{
- COM_TRY_BEGIN
-
- if (numItems != UInt32(-1))
- {
- if (numItems != 1)
- return E_INVALIDARG;
- if (indices[0] != 0)
- return E_INVALIDARG;
- }
- bool testMode = (_aTestMode != 0);
- CMyComPtr