Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / core / src / fxcrt / fx_extension.cpp
index e7272cf..330c675 100644 (file)
@@ -1,7 +1,7 @@
 // Copyright 2014 PDFium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include "../../include/fxcrt/fx_ext.h"
 #else
 #include <ctime>
 #endif
-FX_HFILE FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator)
+FX_HFILE FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode)
 {
-    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
     if (pFA && !pFA->Open(fileName, dwMode)) {
-        pFA->Release(pAllocator);
+        pFA->Release();
         return NULL;
     }
     return (FX_HFILE)pFA;
 }
-FX_HFILE FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator)
+FX_HFILE FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode)
 {
-    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
     if (pFA && !pFA->Open(fileName, dwMode)) {
-        pFA->Release(pAllocator);
+        pFA->Release();
         return NULL;
     }
     return (FX_HFILE)pFA;
 }
-void FX_File_Close(FX_HFILE hFile, IFX_Allocator* pAllocator)
+void FX_File_Close(FX_HFILE hFile)
 {
     FXSYS_assert(hFile != NULL);
     ((IFXCRT_FileAccess*)hFile)->Close();
-    ((IFXCRT_FileAccess*)hFile)->Release(pAllocator);
+    ((IFXCRT_FileAccess*)hFile)->Release();
 }
 FX_FILESIZE FX_File_GetSize(FX_HFILE hFile)
 {
@@ -80,69 +80,65 @@ FX_BOOL FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile)
     FXSYS_assert(hFile != NULL);
     return ((IFXCRT_FileAccess*)hFile)->Truncate(szFile);
 }
-IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator)
-{
-    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+IFX_FileAccess* FX_CreateDefaultFileAccess(FX_WSTR wsPath)\r
+{\r
+       if (wsPath.GetLength() == 0)\r
+               return NULL;\r
+\r
+       CFX_CRTFileAccess* pFA = NULL;\r
+       pFA = FX_NEW CFX_CRTFileAccess;\r
+       if (NULL == pFA) return NULL;\r
+\r
+       pFA->Init(wsPath);\r
+       return pFA;\r
+}\r
+IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes)
+{
+    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
     if (!pFA) {
         return NULL;
     }
     if (!pFA->Open(filename, dwModes)) {
-        pFA->Release(pAllocator);
+        pFA->Release();
         return NULL;
     }
-    if (pAllocator) {
-        return FX_NewAtAllocator(pAllocator) CFX_CRTFileStream(pFA, pAllocator);
-    } else {
-        return FX_NEW CFX_CRTFileStream(pFA, pAllocator);
-    }
+    return FX_NEW CFX_CRTFileStream(pFA);
 }
-IFX_FileStream* FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator)
+IFX_FileStream* FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes)
 {
-    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(pAllocator);
+    IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create();
     if (!pFA) {
         return NULL;
     }
     if (!pFA->Open(filename, dwModes)) {
-        pFA->Release(pAllocator);
+        pFA->Release();
         return NULL;
     }
-    if (pAllocator) {
-        return FX_NewAtAllocator(pAllocator) CFX_CRTFileStream(pFA, pAllocator);
-    } else {
-        return FX_NEW CFX_CRTFileStream(pFA, pAllocator);
-    }
+    return FX_NEW CFX_CRTFileStream(pFA);
 }
-IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename, IFX_Allocator* pAllocator)
+IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename)
 {
-    return FX_CreateFileStream(filename, FX_FILEMODE_Truncate, pAllocator);
+    return FX_CreateFileStream(filename, FX_FILEMODE_Truncate);
 }
-IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename, IFX_Allocator* pAllocator)
+IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename)
 {
-    return FX_CreateFileStream(filename, FX_FILEMODE_Truncate, pAllocator);
+    return FX_CreateFileStream(filename, FX_FILEMODE_Truncate);
 }
-IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename, IFX_Allocator* pAllocator)
+IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename)
 {
-    return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly, pAllocator);
+    return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
 }
-IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename, IFX_Allocator* pAllocator)
+IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename)
 {
-    return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly, pAllocator);
+    return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
 }
-IFX_MemoryStream* FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t dwSize, FX_BOOL bTakeOver, IFX_Allocator* pAllocator)
+IFX_MemoryStream* FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t dwSize, FX_BOOL bTakeOver)
 {
-    if (pAllocator) {
-        return FX_NewAtAllocator(pAllocator)CFX_MemoryStream(pBuffer, dwSize, bTakeOver, pAllocator);
-    } else {
-        return FX_NEW CFX_MemoryStream(pBuffer, dwSize, bTakeOver, NULL);
-    }
+    return FX_NEW CFX_MemoryStream(pBuffer, dwSize, bTakeOver);
 }
-IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive, IFX_Allocator* pAllocator)
+IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive)
 {
-    if (pAllocator) {
-        return FX_NewAtAllocator(pAllocator)CFX_MemoryStream(bConsecutive, pAllocator);
-    } else {
-        return FX_NEW CFX_MemoryStream(bConsecutive, NULL);
-    }
+    return FX_NEW CFX_MemoryStream(bConsecutive);
 }
 #ifdef __cplusplus
 extern "C" {
@@ -399,3 +395,40 @@ void FX_Random_GenerateCrypto(FX_LPDWORD pBuffer, FX_INT32 iCount)
 #ifdef __cplusplus
 }
 #endif
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+void FX_GUID_CreateV4(FX_LPGUID pGUID)\r
+{\r
+#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || _FX_OS_ == _FX_WIN64_)\r
+#ifdef _FX_WINAPI_PARTITION_DESKTOP_\r
+    if (!FX_GenerateCryptoRandom((FX_LPDWORD)pGUID, 4)) {\r
+        FX_Random_GenerateMT((FX_LPDWORD)pGUID, 4);\r
+    }\r
+#else\r
+    FX_Random_GenerateMT((FX_LPDWORD)pGUID, 4);\r
+#endif\r
+#else\r
+    FX_Random_GenerateMT((FX_LPDWORD)pGUID, 4);\r
+#endif\r
+    FX_BYTE &b = ((FX_LPBYTE)pGUID)[6];\r
+    b = (b & 0x0F) | 0x40;\r
+}\r
+FX_LPCSTR gs_FX_pHexChars = "0123456789ABCDEF";\r
+void FX_GUID_ToString(FX_LPCGUID pGUID, CFX_ByteString &bsStr, FX_BOOL bSeparator)\r
+{\r
+    FX_LPSTR pBuf = bsStr.GetBuffer(40);\r
+    FX_BYTE b;\r
+    for (FX_INT32 i = 0; i < 16; i ++) {\r
+        b = ((FX_LPCBYTE)pGUID)[i];\r
+        *pBuf ++ = gs_FX_pHexChars[b >> 4];\r
+        *pBuf ++ = gs_FX_pHexChars[b & 0x0F];\r
+        if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {\r
+            *pBuf ++ = L'-';\r
+        }\r
+    }\r
+    bsStr.ReleaseBuffer(bSeparator ? 36 : 32);\r
+}\r
+#ifdef __cplusplus\r
+}\r
+#endif\r