PageRenderTime 86ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/libUPnP/patches/0045-platinum-win10-uwp-fixes.patch

https://gitlab.com/cronmod-dev/xbmc
Patch | 259 lines | 241 code | 18 blank | 0 comment | 0 complexity | dee0bb29c32cde334cd182b69aed9a63 MD5 | raw file
  1. From 78d3d7f7abec5e0d76d7efa92b226b5236a7bbea Mon Sep 17 00:00:00 2001
  2. From: Dale Stammen <dalestam@microsoft.com>
  3. Date: Fri, 2 Jun 2017 16:34:58 +0300
  4. Subject: [PATCH] [win10] uwp fixes libUPnP
  5. ---
  6. lib/libUPnP/CMakeLists.txt | 8 ++++--
  7. lib/libUPnP/Neptune/Source/Core/NptConfig.h | 13 ++++++++++
  8. lib/libUPnP/Neptune/Source/Core/NptUtils.cpp | 30 ++++++++++++++++++++++
  9. lib/libUPnP/Neptune/Source/Core/NptUtils.h | 7 +++++
  10. .../Neptune/Source/System/Bsd/NptBsdSockets.cpp | 2 ++
  11. .../Source/System/StdC/NptStdcEnvironment.cpp | 2 +-
  12. .../System/Win32/NptWin32DynamicLibraries.cpp | 4 +++
  13. .../Source/System/Win32/NptWin32MessageQueue.cpp | 3 ++-
  14. .../Source/System/Win32/NptWin32MessageQueue.h | 3 +++
  15. .../Source/System/Win32/NptWin32SerialPort.cpp | 2 ++
  16. 10 files changed, 70 insertions(+), 4 deletions(-)
  17. diff --git a/lib/libUPnP/Neptune/Source/Core/NptConfig.h b/lib/libUPnP/Neptune/Source/Core/NptConfig.h
  18. index d51f67f94e..130d5cc33b 100644
  19. --- a/lib/libUPnP/Neptune/Source/Core/NptConfig.h
  20. +++ b/lib/libUPnP/Neptune/Source/Core/NptConfig.h
  21. @@ -60,6 +60,11 @@
  22. #define NPT_CONFIG_HAVE_GETENV
  23. #define NPT_CONFIG_HAVE_SETENV
  24. #define NPT_CONFIG_HAVE_UNSETENV
  25. +#if defined(TARGET_WINDOWS_STORE)
  26. +#undef NPT_CONFIG_HAVE_GETENV
  27. +#undef NPT_CONFIG_HAVE_SETENV
  28. +#undef NPT_CONFIG_HAVE_UNSETENV
  29. +#endif
  30. #define NPT_CONFIG_HAVE_READDIR_R
  31. #endif /* NPT_CONFIG_HAS_STD_C */
  32. @@ -240,12 +245,20 @@ typedef long NPT_PointerLong;
  33. #define NPT_strncpy(d,s,c) strncpy_s(d,c+1,s,c)
  34. #define NPT_strcpy(d,s) strcpy_s(d,strlen(s)+1,s)
  35. #undef NPT_CONFIG_HAVE_GETENV
  36. +#ifdef TARGET_WINDOWS_STORE
  37. +#undef NPT_CONFIG_HAVE_GETENV
  38. +#undef NPT_CONFIG_HAVE_DUPENV_S
  39. +#undef NPT_CONFIG_HAVE_SETENV
  40. +#undef NPT_CONFIG_HAVE_UNSETENV
  41. +#undef NPT_CONFIG_HAVE_PUTENV_S
  42. +#else
  43. #define NPT_CONFIG_HAVE_DUPENV_S
  44. #define dupenv_s _dupenv_s
  45. #undef NPT_CONFIG_HAVE_SETENV
  46. #undef NPT_CONFIG_HAVE_UNSETENV
  47. #define NPT_CONFIG_HAVE_PUTENV_S
  48. #define putenv_s _putenv_s
  49. +#endif
  50. #else
  51. #undef NPT_CONFIG_HAVE_GMTIME_R
  52. #undef NPT_CONFIG_HAVE_LOCALTIME_R
  53. diff --git a/lib/libUPnP/Neptune/Source/Core/NptUtils.cpp b/lib/libUPnP/Neptune/Source/Core/NptUtils.cpp
  54. index a68a1afeaf..d98710dc12 100644
  55. --- a/lib/libUPnP/Neptune/Source/Core/NptUtils.cpp
  56. +++ b/lib/libUPnP/Neptune/Source/Core/NptUtils.cpp
  57. @@ -44,6 +44,12 @@
  58. #include <limits.h>
  59. #endif
  60. +#ifdef TARGET_WINDOWS_STORE
  61. +#ifndef WIN32_LEAN_AND_MEAN
  62. +#define WIN32_LEAN_AND_MEAN 1
  63. +#endif
  64. +#include <windows.h>
  65. +#endif
  66. /*----------------------------------------------------------------------
  67. | constants
  68. +---------------------------------------------------------------------*/
  69. @@ -925,3 +931,27 @@ NPT_ParseMimeParameters(const char* encoded,
  70. return NPT_SUCCESS;
  71. }
  72. +#ifdef TARGET_WINDOWS_STORE
  73. +std::wstring win32ConvertUtf8ToW(const std::string &text)
  74. +{
  75. + if (text.empty())
  76. + {
  77. + return L"";
  78. + }
  79. +
  80. + int bufSize = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text.c_str(), -1, NULL, 0);
  81. + if (bufSize == 0)
  82. + return L"";
  83. + wchar_t *converted = new wchar_t[bufSize];
  84. + if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text.c_str(), -1, converted, bufSize) != bufSize)
  85. + {
  86. + delete[] converted;
  87. + return L"";
  88. + }
  89. +
  90. + std::wstring Wret(converted);
  91. + delete[] converted;
  92. +
  93. + return Wret;
  94. +}
  95. +#endif
  96. diff --git a/lib/libUPnP/Neptune/Source/Core/NptUtils.h b/lib/libUPnP/Neptune/Source/Core/NptUtils.h
  97. index 3a06d497f4..89b2e29812 100644
  98. --- a/lib/libUPnP/Neptune/Source/Core/NptUtils.h
  99. +++ b/lib/libUPnP/Neptune/Source/Core/NptUtils.h
  100. @@ -54,6 +54,9 @@
  101. #include <stdarg.h>
  102. #endif
  103. +#if defined(TARGET_WINDOWS_STORE)
  104. +#include <string>
  105. +#endif
  106. /*----------------------------------------------------------------------
  107. | macros
  108. +---------------------------------------------------------------------*/
  109. @@ -225,4 +228,8 @@ extern void NPT_SetMemory(void* dest, int c, NPT_Size size);
  110. extern int NPT_MemoryEqual(const void* s1, const void* s2, unsigned long n);
  111. #endif
  112. +#if defined(TARGET_WINDOWS_STORE)
  113. +std::wstring win32ConvertUtf8ToW(const std::string &text);
  114. +#endif
  115. +
  116. #endif // _NPT_UTILS_H_
  117. diff --git a/lib/libUPnP/Neptune/Source/System/Bsd/NptBsdSockets.cpp b/lib/libUPnP/Neptune/Source/System/Bsd/NptBsdSockets.cpp
  118. index ee86dbf4b0..a42dfbfb85 100644
  119. --- a/lib/libUPnP/Neptune/Source/System/Bsd/NptBsdSockets.cpp
  120. +++ b/lib/libUPnP/Neptune/Source/System/Bsd/NptBsdSockets.cpp
  121. @@ -131,6 +131,7 @@ static NPT_WinsockSystem& WinsockInitializer = NPT_WinsockSystem::Initializer;
  122. #undef SetPort
  123. #endif
  124. +#ifndef TARGET_WINDOWS_STORE
  125. #if !defined(EWOULDBLOCK)
  126. #define EWOULDBLOCK WSAEWOULDBLOCK
  127. #endif
  128. @@ -167,6 +168,7 @@ static NPT_WinsockSystem& WinsockInitializer = NPT_WinsockSystem::Initializer;
  129. #if !defined(ENOTCONN)
  130. #define ENOTCONN WSAENOTCONN
  131. #endif
  132. +#endif
  133. #if !defined(EAGAIN)
  134. #define EAGAIN WSAEWOULDBLOCK
  135. #endif
  136. diff --git a/lib/libUPnP/Neptune/Source/System/StdC/NptStdcEnvironment.cpp b/lib/libUPnP/Neptune/Source/System/StdC/NptStdcEnvironment.cpp
  137. index c9f9939d2b..f700b2212b 100644
  138. --- a/lib/libUPnP/Neptune/Source/System/StdC/NptStdcEnvironment.cpp
  139. +++ b/lib/libUPnP/Neptune/Source/System/StdC/NptStdcEnvironment.cpp
  140. @@ -22,7 +22,7 @@
  141. NPT_Result
  142. NPT_Environment::Get(const char* name, NPT_String& value)
  143. {
  144. - char* env;
  145. + char* env = nullptr;
  146. /* default value */
  147. value.SetLength(0);
  148. diff --git a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32DynamicLibraries.cpp b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32DynamicLibraries.cpp
  149. index caaf6d1903..371aaf5ab9 100644
  150. --- a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32DynamicLibraries.cpp
  151. +++ b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32DynamicLibraries.cpp
  152. @@ -97,7 +97,11 @@ NPT_DynamicLibrary::Load(const char* name, NPT_Flags flags, NPT_DynamicLibrary*&
  153. // load the lib
  154. NPT_LOG_FINE_2("loading library %s, flags=%x", name, flags);
  155. +#ifdef TARGET_WINDOWS_STORE
  156. + HMODULE handle = LoadPackagedLibrary(NPT_WIN32_A2W(name), NULL);
  157. +#else
  158. HMODULE handle = LoadLibraryW(NPT_WIN32_A2W(name));
  159. +#endif
  160. if (handle == NULL) {
  161. NPT_LOG_FINE("library not found");
  162. return NPT_FAILURE;
  163. diff --git a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.cpp b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.cpp
  164. index f415b851d5..d5ad0b953c 100644
  165. --- a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.cpp
  166. +++ b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.cpp
  167. @@ -11,7 +11,7 @@
  168. | includes
  169. +---------------------------------------------------------------------*/
  170. #include "NptWin32MessageQueue.h"
  171. -
  172. +#ifndef TARGET_WINDOWS_STORE
  173. /*----------------------------------------------------------------------
  174. | platform adaptation
  175. +---------------------------------------------------------------------*/
  176. @@ -181,3 +181,4 @@ NPT_Win32WindowMessageQueue::HandleMessage(NPT_Message* message,
  177. return result;
  178. }
  179. +#endif // ! TARGET_WINDOWS_STORE
  180. diff --git a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.h b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.h
  181. index a5f846b016..1d84800586 100644
  182. --- a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.h
  183. +++ b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32MessageQueue.h
  184. @@ -10,6 +10,7 @@
  185. #ifndef _NPT_WIN32_MESSAGE_QUEUE_
  186. #define _NPT_WIN32_MESSAGE_QUEUE_
  187. +#ifndef TARGET_WINDOWS_STORE
  188. /*----------------------------------------------------------------------
  189. | includes
  190. +---------------------------------------------------------------------*/
  191. @@ -45,5 +46,7 @@ private:
  192. HINSTANCE m_hInstance;
  193. };
  194. +#endif // ! TARGET_WINDOWS_STORE
  195. +
  196. #endif // _NPT_WIN32_MESSAGE_QUEUE_
  197. --- a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32Queue.cpp
  198. +++ b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32Queue.cpp
  199. @@ -24,7 +24,7 @@
  200. #include "NptDebug.h"
  201. #include "NptLogging.h"
  202. -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
  203. +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP || defined(TARGET_WINDOWS_STORE)
  204. // for XBox, Windows 7 Desktop or earlier
  205. #include "NptWin32Threads.h"
  206. #elif WINAPI_FAMILY == WINAPI_FAMILY_APP
  207. @@ -55,7 +55,7 @@ private:
  208. // members
  209. NPT_Cardinal m_MaxItems;
  210. -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
  211. +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP || defined(TARGET_WINDOWS_STORE)
  212. // for XBox, Windows 7 Desktop or earlier
  213. NPT_Win32CriticalSection m_Mutex;
  214. NPT_Win32Event* m_CanPushCondition;
  215. @@ -76,7 +76,7 @@ private:
  216. NPT_Win32Queue::NPT_Win32Queue(NPT_Cardinal max_items) :
  217. m_MaxItems(max_items)
  218. {
  219. -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
  220. +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP || defined(TARGET_WINDOWS_STORE)
  221. // for XBox, Windows 7 Desktop or earlier
  222. m_CanPushCondition = new NPT_Win32Event(true, true);
  223. m_CanPopCondition = new NPT_Win32Event(true, false);
  224. diff --git a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32SerialPort.cpp b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32SerialPort.cpp
  225. index 9428648bd7..4dfc23a603 100644
  226. --- a/lib/libUPnP/Neptune/Source/System/Win32/NptWin32SerialPort.cpp
  227. +++ b/lib/libUPnP/Neptune/Source/System/Win32/NptWin32SerialPort.cpp
  228. @@ -17,6 +17,7 @@
  229. #include "NptStrings.h"
  230. #include "NptLogging.h"
  231. +#ifndef TARGET_WINDOWS_STORE
  232. /*----------------------------------------------------------------------
  233. | NPT_Win32HandletWrapper
  234. +---------------------------------------------------------------------*/
  235. @@ -338,3 +339,4 @@ NPT_SerialPort::NPT_SerialPort(const char* name)
  236. {
  237. m_Delegate = new NPT_Win32SerialPort(name);
  238. }
  239. +#endif // ! TARGET_WINDOWS_STORE
  240. --
  241. 2.13.2.windows.1