summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2015-01-11 08:10:25 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2015-01-11 08:10:25 +0100
commit6a23c2f3b766cf4fc7028628f76b5ff9396383f0 (patch)
treea01e16637118ae0c80f337119898bdf18f081e24 /3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp
parent45ac9b351e0076c371de4c7453f59567b27b1cb6 (diff)
Added full lzma sdk source (nw)
Diffstat (limited to '3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp b/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp
new file mode 100644
index 00000000000..1ecb5b54066
--- /dev/null
+++ b/3rdparty/lzma/CPP/7zip/UI/Common/WorkDir.cpp
@@ -0,0 +1,91 @@
+// WorkDir.cpp
+
+#include "StdAfx.h"
+
+#include "Common/StringConvert.h"
+#include "Common/Wildcard.h"
+
+#include "Windows/FileName.h"
+
+#include "WorkDir.h"
+
+using namespace NWindows;
+using namespace NFile;
+using namespace NDirectory;
+
+FString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const FString &path, FString &fileName)
+{
+ NWorkDir::NMode::EEnum mode = workDirInfo.Mode;
+ #ifndef UNDER_CE
+ if (workDirInfo.ForRemovableOnly)
+ {
+ mode = NWorkDir::NMode::kCurrent;
+ FString prefix = path.Left(3);
+ if (prefix[1] == FTEXT(':') && prefix[2] == FTEXT('\\'))
+ {
+ UINT driveType = GetDriveType(GetSystemString(prefix, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP));
+ if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)
+ mode = workDirInfo.Mode;
+ }
+ /*
+ CParsedPath parsedPath;
+ parsedPath.ParsePath(archiveName);
+ UINT driveType = GetDriveType(parsedPath.Prefix);
+ if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))
+ mode = NZipSettings::NWorkDir::NMode::kCurrent;
+ */
+ }
+ #endif
+ int pos = path.ReverseFind(FCHAR_PATH_SEPARATOR) + 1;
+ fileName = path.Mid(pos);
+ switch (mode)
+ {
+ case NWorkDir::NMode::kCurrent:
+ {
+ return path.Left(pos);;
+ }
+ case NWorkDir::NMode::kSpecified:
+ {
+ FString tempDir = workDirInfo.Path;
+ NName::NormalizeDirPathPrefix(tempDir);
+ return tempDir;
+ }
+ default:
+ {
+ FString tempDir;
+ if (!MyGetTempPath(tempDir))
+ throw 141717;
+ return tempDir;
+ }
+ }
+}
+
+HRESULT CWorkDirTempFile::CreateTempFile(const FString &originalPath)
+{
+ NWorkDir::CInfo workDirInfo;
+ workDirInfo.Load();
+ FString namePart;
+ FString workDir = GetWorkDir(workDirInfo, originalPath, namePart);
+ CreateComplexDirectory(workDir);
+ CTempFile tempFile;
+ _outStreamSpec = new COutFileStream;
+ OutStream = _outStreamSpec;
+ if (!_tempFile.Create(workDir + namePart, &_outStreamSpec->File))
+ {
+ DWORD error = GetLastError();
+ return error ? error : E_FAIL;
+ }
+ _originalPath = originalPath;
+ return S_OK;
+}
+
+HRESULT CWorkDirTempFile::MoveToOriginal(bool deleteOriginal)
+{
+ OutStream.Release();
+ if (!_tempFile.MoveTo(_originalPath, deleteOriginal))
+ {
+ DWORD error = GetLastError();
+ return error ? error : E_FAIL;
+ }
+ return S_OK;
+}