[MPR]
[reactos.git] / reactos / dll / win32 / mpr / mpr_ros.diff
index f7cdf9d..349f7ac 100644 (file)
@@ -69,7 +69,158 @@ Index: wnet.c
                          TRACE("NPAddConnection %p\n", provider->addConnection);\r
                          TRACE("NPAddConnection3 %p\n", provider->addConnection3);\r
                          TRACE("NPCancelConnection %p\n", provider->cancelConnection);\r
                          TRACE("NPAddConnection %p\n", provider->addConnection);\r
                          TRACE("NPAddConnection3 %p\n", provider->addConnection3);\r
                          TRACE("NPCancelConnection %p\n", provider->cancelConnection);\r
-@@ -1870,6 +1866,43 @@\r
+@@ -251,6 +247,85 @@\r
+          debugstr_w(provider));\r
+ }\r
\r
++#ifdef __REACTOS__\r
++static void _restoreSavedConnection(HKEY connection, WCHAR * local)\r
++{\r
++    NETRESOURCEW net;\r
++    DWORD type, prov, index, size;\r
++\r
++    net.lpProvider = NULL;\r
++    net.lpRemoteName = NULL;\r
++    net.lpLocalName = NULL;\r
++\r
++    TRACE("Restoring: %S\n", local);\r
++\r
++    size = sizeof(DWORD);\r
++    if (RegQueryValueExW(connection, L"ConnectionType", NULL, &type, (BYTE *)&net.dwType, &size) != ERROR_SUCCESS)\r
++       return;\r
++\r
++    if (type != REG_DWORD || size != sizeof(DWORD))\r
++        return;\r
++\r
++    if (RegQueryValueExW(connection, L"ProviderName", NULL, &type, NULL, &size) != ERROR_SUCCESS)\r
++        return;\r
++\r
++    if (type != REG_SZ)\r
++        return;\r
++\r
++    net.lpProvider = HeapAlloc(GetProcessHeap(), 0, size);\r
++    if (!net.lpProvider)\r
++        return;\r
++\r
++    if (RegQueryValueExW(connection, L"ProviderName", NULL, NULL, (BYTE *)net.lpProvider, &size) != ERROR_SUCCESS)\r
++        goto cleanup;\r
++\r
++    size = sizeof(DWORD);\r
++    if (RegQueryValueExW(connection, L"ProviderType", NULL, &type, (BYTE *)&prov, &size) != ERROR_SUCCESS)\r
++        goto cleanup;\r
++\r
++    if (type != REG_DWORD || size != sizeof(DWORD))\r
++        goto cleanup;\r
++\r
++    index = _findProviderIndexW(net.lpProvider);\r
++    if (index == BAD_PROVIDER_INDEX)\r
++        goto cleanup;\r
++\r
++    if (providerTable->table[index].dwNetType != prov)\r
++        goto cleanup;\r
++\r
++    if (RegQueryValueExW(connection, L"RemotePath", NULL, &type, NULL, &size) != ERROR_SUCCESS)\r
++        goto cleanup;\r
++\r
++    if (type != REG_SZ)\r
++        goto cleanup;\r
++\r
++    net.lpRemoteName = HeapAlloc(GetProcessHeap(), 0, size);\r
++    if (!net.lpRemoteName)\r
++        goto cleanup;\r
++\r
++    if (RegQueryValueExW(connection, L"RemotePath", NULL, NULL, (BYTE *)net.lpRemoteName, &size) != ERROR_SUCCESS)\r
++        goto cleanup;\r
++\r
++    size = strlenW(local);\r
++    net.lpLocalName = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR) + 2 * sizeof(WCHAR));\r
++    if (!net.lpLocalName)\r
++        goto cleanup;\r
++\r
++    strcpyW(net.lpLocalName, local);\r
++    net.lpLocalName[size] = ':';\r
++    net.lpLocalName[size + 1] = 0;\r
++\r
++    TRACE("Attempting connection\n");\r
++\r
++    WNetAddConnection2W(&net, NULL, NULL, 0);\r
++\r
++cleanup:\r
++    HeapFree(GetProcessHeap(), 0, net.lpProvider);\r
++    HeapFree(GetProcessHeap(), 0, net.lpRemoteName);\r
++    HeapFree(GetProcessHeap(), 0, net.lpLocalName);\r
++}\r
++#endif\r
++\r
+ void wnetInit(HINSTANCE hInstDll)\r
+ {\r
+     static const WCHAR providerOrderKey[] = { 'S','y','s','t','e','m','\\',\r
+@@ -329,6 +404,64 @@\r
+         }\r
+         RegCloseKey(hKey);\r
+     }\r
++\r
++#ifdef __REACTOS__\r
++    if (providerTable)\r
++    {\r
++        HKEY user_profile;\r
++\r
++        if (RegOpenCurrentUser(KEY_ALL_ACCESS, &user_profile) == ERROR_SUCCESS)\r
++        {\r
++            HKEY network;\r
++            WCHAR subkey[8] = {'N', 'e', 't', 'w', 'o', 'r', 'k', 0};\r
++\r
++            if (RegOpenKeyExW(user_profile, subkey, 0, KEY_READ, &network) == ERROR_SUCCESS)\r
++            {\r
++                DWORD size, max;\r
++\r
++                TRACE("Enumerating remembered connections\n");\r
++\r
++                if (RegQueryInfoKey(network, NULL, NULL, NULL, &max, &size, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)\r
++                {\r
++                    WCHAR *local;\r
++\r
++                    TRACE("There are %lu connections\n", max);\r
++\r
++                    local = HeapAlloc(GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR));\r
++                    if (local)\r
++                    {\r
++                        DWORD index;\r
++\r
++                        for (index = 0; index < max; ++index)\r
++                        {\r
++                            DWORD len = size + 1;\r
++                            HKEY connection;\r
++\r
++                            TRACE("Trying connection %lu\n", index);\r
++\r
++                            if (RegEnumKeyExW(network, index, local, &len, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)\r
++                                continue;\r
++\r
++                            TRACE("It is %S\n", local);\r
++\r
++                            if (RegOpenKeyExW(network, local, 0, KEY_READ, &connection) != ERROR_SUCCESS)\r
++                                continue;\r
++\r
++                            _restoreSavedConnection(connection, local);\r
++                            RegCloseKey(connection);\r
++                        }\r
++\r
++                        HeapFree(GetProcessHeap(), 0, local);\r
++                    }\r
++                }\r
++\r
++                RegCloseKey(network);\r
++            }\r
++\r
++            RegCloseKey(user_profile);\r
++        }\r
++    }\r
++#endif\r
+ }\r
\r
+ void wnetFree(void)\r
+@@ -1870,6 +2003,43 @@\r
          }\r
      }\r
  \r
          }\r
      }\r
  \r
@@ -113,7 +264,7 @@ Index: wnet.c
      return ret;\r
  }\r
  \r
      return ret;\r
  }\r
  \r
-@@ -2061,6 +2094,37 @@\r
+@@ -2061,6 +2231,37 @@\r
              }\r
          }\r
      }\r
              }\r
          }\r
      }\r
@@ -151,7 +302,7 @@ Index: wnet.c
      return ret;\r
  }\r
  \r
      return ret;\r
  }\r
  \r
-@@ -2188,6 +2252,7 @@\r
+@@ -2188,6 +2389,7 @@\r
  /* find the network connection for a given drive; helper for WNetGetConnection */\r
  static DWORD get_drive_connection( WCHAR letter, LPWSTR remote, LPDWORD size )\r
  {\r
  /* find the network connection for a given drive; helper for WNetGetConnection */\r
  static DWORD get_drive_connection( WCHAR letter, LPWSTR remote, LPDWORD size )\r
  {\r
@@ -159,7 +310,7 @@ Index: wnet.c
      char buffer[1024];\r
      struct mountmgr_unix_drive *data = (struct mountmgr_unix_drive *)buffer;\r
      HANDLE mgr;\r
      char buffer[1024];\r
      struct mountmgr_unix_drive *data = (struct mountmgr_unix_drive *)buffer;\r
      HANDLE mgr;\r
-@@ -2230,6 +2295,32 @@\r
+@@ -2230,6 +2432,32 @@\r
      }\r
      CloseHandle( mgr );\r
      return ret;\r
      }\r
      CloseHandle( mgr );\r
      return ret;\r